aboutsummaryrefslogtreecommitdiffstats
path: root/src/libserver
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-07 09:18:09 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-07 09:18:09 +0000
commit8a22018b6e16ab471adf1e24f38d72968e637d52 (patch)
treeb031620dc5d4d0620c2425112fcd698fc1070c2e /src/libserver
parentfc9338984d86334d76d6618944201349e13bbc49 (diff)
downloadrspamd-8a22018b6e16ab471adf1e24f38d72968e637d52.tar.gz
rspamd-8a22018b6e16ab471adf1e24f38d72968e637d52.zip
Add routine to convert string to re_class type
Diffstat (limited to 'src/libserver')
-rw-r--r--src/libserver/re_cache.c35
-rw-r--r--src/libserver/re_cache.h8
2 files changed, 41 insertions, 2 deletions
diff --git a/src/libserver/re_cache.c b/src/libserver/re_cache.c
index f1ee7157d..3f86fd9c8 100644
--- a/src/libserver/re_cache.c
+++ b/src/libserver/re_cache.c
@@ -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;
diff --git a/src/libserver/re_cache.h b/src/libserver/re_cache.h
index c4ec3b2cf..65a8bd392 100644
--- a/src/libserver/re_cache.h
+++ b/src/libserver/re_cache.h
@@ -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