commit 659ec2d: [Project] Reorganize ragel

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Feb 7 15:14:06 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-02-05 16:00:37 +0000
URL: https://github.com/rspamd/rspamd/commit/659ec2d02a354f9132f3a02d27b0b60aa156c551

[Project] Reorganize ragel

---
 src/ragel/smtp_base.rl      | 39 ++++++++++++++++++++++++++++++++
 src/ragel/smtp_ip_parser.rl | 55 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/src/ragel/smtp_base.rl b/src/ragel/smtp_base.rl
new file mode 100644
index 000000000..c9cc91061
--- /dev/null
+++ b/src/ragel/smtp_base.rl
@@ -0,0 +1,39 @@
+%%{
+  machine smtp_base;
+
+  # Base SMTP definitions
+  # Dependencies: none
+  # Required actions: none
+
+  WSP             =   " ";
+  CRLF            =   "\r\n" | ("\r" [^\n]) | ([^\r] "\n");
+  DQUOTE = '"';
+
+  # Printable US-ASCII characters not including specials
+  atext = alpha | digit | "!" | "#" | "$" | "%" | "&" |
+          "'" | "*" | "+" | "_" | "/" | "=" | "?" | "^" |
+          "-" | "`" | "{" | "|" | "}" | "~";
+  # Printable US-ASCII characters not including "[", "]", or "\"
+  dtext = 33..90 | 94..126;
+  # Printable US-ASCII characters not including  "(", ")", or "\"
+  ctext = 33..39 | 42..91 | 93..126;
+
+  dcontent       = 33..90 | 94..126;
+  Let_dig        = alpha | digit;
+  Ldh_str        = ( alpha | digit | "_" | "-" )* Let_dig;
+
+  quoted_pairSMTP  = "\\" 32..126;
+  qtextSMTP      = 32..33 | 35..91 | 93..126;
+  Atom           = atext+;
+  Dot_string     = Atom ("."  Atom)*;
+  dot_atom_text  = atext+ ("." atext+)*;
+  #FWS            =   ((WSP* CRLF)? WSP+);
+  FWS            = WSP+; # We work with unfolded headers, so we can simplify machine
+
+  sub_domain     = Let_dig Ldh_str?;
+  Domain = sub_domain ("." sub_domain)*;
+  Atdomain = "@" Domain;
+  Adl = Atdomain ( "," Atdomain )*;
+
+  Standardized_tag = Ldh_str;
+}%%
\ No newline at end of file
diff --git a/src/ragel/smtp_ip_parser.rl b/src/ragel/smtp_ip_parser.rl
new file mode 100644
index 000000000..36d9746a5
--- /dev/null
+++ b/src/ragel/smtp_ip_parser.rl
@@ -0,0 +1,55 @@
+%%{
+
+  machine smtp_ip_parser;
+
+  action IP6_start {
+    in_v6 = 1;
+    ip_start = p;
+  }
+  action IP6_end {
+    in_v6 = 0;
+    ip_end = p;
+  }
+  action IP4_start {
+    if (!in_v6) {
+      ip_start = p;
+    }
+  }
+  action IP4_end {
+    if (!in_v6) {
+      ip_end = p;
+    }
+  }
+
+  action Domain_addr_start {}
+  action Domain_addr_end {}
+
+  include smtp_base "smtp_base.rl";
+  include smtp_ip "smtp_ip.rl";
+
+  main := address_literal | non_conformant_address_literal;
+}%%
+
+#include "smtp_parsers.h"
+#include "util.h"
+#include "addr.h"
+
+%% write data;
+
+rspamd_inet_addr_t *
+rspamd_parse_smtp_ip (const char *data, size_t len, rspamd_mempool_t *pool)
+{
+  const char *p = data, *pe = data + len, *eof = data + len;
+  const char *ip_start = NULL, *ip_end = NULL;
+  gboolean in_v6 = FALSE;
+  gint cs = 0;
+
+  %% write init;
+  %% write exec;
+
+  if (ip_start && ip_end && ip_end > ip_start) {
+    return rspamd_parse_inet_address_pool (ip_start, ip_end - ip_start, pool);
+  }
+
+  return NULL;
+}
\ No newline at end of file


More information about the Commits mailing list