]> source.dussan.org Git - rspamd.git/commitdiff
Add routine to convert string to re_class type
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Dec 2015 09:18:09 +0000 (09:18 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 7 Dec 2015 09:18:09 +0000 (09:18 +0000)
src/libserver/re_cache.c
src/libserver/re_cache.h
src/lua/lua_config.c
src/lua/lua_task.c

index f1ee7157d3f99e19300d964e598a31749dec7d2c..3f86fd9c84f46bd98422458926bca56de8744713 100644 (file)
@@ -415,6 +415,10 @@ rspamd_re_cache_exec_re (struct rspamd_task *task,
                debug_task ("checking rawbody regexp: %s -> %d",
                                rspamd_regexp_get_pattern (re), ret);
                break;
+       case RSPAMD_RE_MAX:
+               msg_err_task ("regexp of class invalid has been called: %s",
+                               rspamd_regexp_get_pattern (re));
+               break;
        }
 
        setbit (rt->checked, re_id);
@@ -526,7 +530,7 @@ rspamd_re_cache_type_to_string (enum rspamd_re_type type)
                ret = "raw header";
                break;
        case RSPAMD_RE_ALLHEADER:
-               ret = "raw header";
+               ret = "all headers";
                break;
        case RSPAMD_RE_MIME:
                ret = "part";
@@ -537,6 +541,35 @@ rspamd_re_cache_type_to_string (enum rspamd_re_type type)
        case RSPAMD_RE_URL:
                ret = "url";
                break;
+       case RSPAMD_RE_MAX:
+               ret = "invalid class";
+               break;
+       }
+
+       return ret;
+}
+
+enum rspamd_re_type
+rspamd_re_cache_type_from_string (const char *str)
+{
+       enum rspamd_re_type ret = RSPAMD_RE_MAX;
+
+       if (str != NULL) {
+               if (strcmp (str, "header") == 0) {
+                       ret = RSPAMD_RE_HEADER;
+               }
+               else if (strcmp (str, "rawheader") == 0) {
+                       ret = RSPAMD_RE_RAWHEADER;
+               }
+               else if (strcmp (str, "mime") == 0) {
+                       ret = RSPAMD_RE_MIME;
+               }
+               else if (strcmp (str, "body") == 0) {
+                       ret = RSPAMD_RE_BODY;
+               }
+               else if (strcmp (str, "url") == 0) {
+                       ret = RSPAMD_RE_URL;
+               }
        }
 
        return ret;
index c4ec3b2cf6c98930f4da24742badf07a228a6bd3..65a8bd392f613dd7897eb17ffe785efb212b607a 100644 (file)
@@ -37,7 +37,8 @@ enum rspamd_re_type {
        RSPAMD_RE_ALLHEADER,
        RSPAMD_RE_MIME,
        RSPAMD_RE_URL,
-       RSPAMD_RE_BODY
+       RSPAMD_RE_BODY,
+       RSPAMD_RE_MAX
 };
 
 /**
@@ -120,4 +121,9 @@ guint rspamd_re_cache_set_limit (struct rspamd_re_cache *cache, guint limit);
  */
 const gchar * rspamd_re_cache_type_to_string (enum rspamd_re_type type);
 
+/**
+ * Convert re type string to the type enum
+ */
+enum rspamd_re_type rspamd_re_cache_type_from_string (const char *str);
+
 #endif
index d495d0c9ec3b03e3781a5ff2868de9d8b5c1ea6f..b574cba59a9b0980bf35e694454283ba7b55644f 100644 (file)
@@ -1588,21 +1588,7 @@ lua_config_register_regexp (lua_State *L)
                        }
                }
                else {
-                       if (strcmp (type_str, "header") == 0) {
-                               type = RSPAMD_RE_HEADER;
-                       }
-                       else if (strcmp (type_str, "rawheader") == 0) {
-                               type = RSPAMD_RE_RAWHEADER;
-                       }
-                       else if (strcmp (type_str, "mime") == 0) {
-                               type = RSPAMD_RE_MIME;
-                       }
-                       else if (strcmp (type_str, "body") == 0) {
-                               type = RSPAMD_RE_BODY;
-                       }
-                       else if (strcmp (type_str, "url") == 0) {
-                               type = RSPAMD_RE_URL;
-                       }
+                       type = rspamd_re_cache_type_from_string (type_str);
 
                        if ((type == RSPAMD_RE_HEADER || type == RSPAMD_RE_RAWHEADER)
                                        && header_str == NULL) {
index 037337fa86ae3e99b0d4dffd3c4d2b13b10c33e6..8246d921b3ddf6faf7bd4d0ec9967db0695306c6 100644 (file)
@@ -2038,21 +2038,7 @@ lua_task_process_regexp (lua_State *L)
                        }
                }
                else {
-                       if (strcmp (type_str, "header") == 0) {
-                               type = RSPAMD_RE_HEADER;
-                       }
-                       else if (strcmp (type_str, "rawheader") == 0) {
-                               type = RSPAMD_RE_RAWHEADER;
-                       }
-                       else if (strcmp (type_str, "mime") == 0) {
-                               type = RSPAMD_RE_MIME;
-                       }
-                       else if (strcmp (type_str, "body") == 0) {
-                               type = RSPAMD_RE_BODY;
-                       }
-                       else if (strcmp (type_str, "url") == 0) {
-                               type = RSPAMD_RE_URL;
-                       }
+                       type = rspamd_re_cache_type_from_string (type_str);
 
                        if ((type == RSPAMD_RE_HEADER || type == RSPAMD_RE_RAWHEADER)
                                        && header_str == NULL) {