Any suggestions on implementing SMTP protocol in Ragel?
Ross Thomas
halfacan... at gmail.com
Mon May 12 22:17:27 UTC 2008
To reduce the scope of my question a little, here is the general
structure I have so far:
main := (
start: (
helo @copy_helo @resp_250 -> wait_mail |
mail @resp_503 -> start |
vrfy @resp_503 -> start |
...
wait_mail: (
helo @resp_250 -> wait_mail |
mail @copy_mail @resp_250 -> wait_rcpt |
vrfy @resp_252 -> wait_mail |
...
);
Each "helo", "mail", "vrfy" etc. machine corresponds to the SMTP
command of the same name. They are defined as:
helo = (("HELO"i | "EHLO"i) " " %sarg graph+ %earg eol);
mail = ( "MAIL"i " FROM:<" %sarg path* %earg ">" eol);
vrfy = ( "VRFY"i " " %sarg graph+ %earg eol);
...
So the idea is that the top-level state chart handles logical flow and
knows which commands are valid in which states, and calls the
appropriate actions. The tokenizing is done "inline", as it were.
Does this strike anyone as a particularly foolish approach? Is there a
better way?
-Ross
On Sun, May 11, 2008 at 11:57 AM, Ross Thomas <halfacan... at gmail.com> wrote:
>
> While hacking up a parser for SMTP (in an unprecedentedly small amount
> of time, naturally :)) it occurred to me that given Ragel's ability to
> mix regular expressions with state charts I could make the same
> machine double-up as an SMTP protocol handler too. At least, I think I
> could. Because a significant portion of my work involves the client/
> server model this is an aspect of Ragel I'd very much like to explore
> in more detail...
>
> I've browsed around on the list and read Zed's post on state charts
> but still don't have a totally clear idea on how this might be
> implemented. Can anyone out there with more Ragel experience point me
> in the right direction?
>
> -Ross
More information about the ragel-users
mailing list