diff src/context.cpp @ 249:15bf4f68a0b2

Add dnswl support
author Carl Byington <carl@five-ten-sg.com>
date Sun, 08 Apr 2012 11:42:59 -0700
parents ef97c7cd4a6e
children d6d5c50b9278
line wrap: on
line diff
--- a/src/context.cpp	Fri Jan 06 22:07:45 2012 -0800
+++ b/src/context.cpp	Sun Apr 08 11:42:59 2012 -0700
@@ -32,6 +32,8 @@
 const char *token_default;
 const char *token_dnsbl;
 const char *token_dnsbll;
+const char *token_dnswl;
+const char *token_dnswll;
 const char *token_envfrom;
 const char *token_envto;
 const char *token_filter;
@@ -597,6 +599,20 @@
 }
 
 
+DNSWL::DNSWL(const char *n, const char *s, const int l) {
+    name    = n;
+    suffix  = s;
+    level   = l;
+}
+
+
+bool DNSWL::operator==(const DNSWL &rhs) {
+    return (strcmp(name,    rhs.name)    == 0) &&
+           (strcmp(suffix,  rhs.suffix)  == 0) &&
+           (level == rhs.level);
+}
+
+
 CONFIG::CONFIG() {
     reference_count    = 0;
     generation         = 0;
@@ -919,6 +935,14 @@
 }
 
 
+DNSWLP CONTEXT::find_dnswl(const char *name) {
+    dnswlp_map::iterator i = dnswl_names.find(name);
+    if (i != dnswl_names.end()) return (*i).second;
+    if (parent) return parent->find_dnswl(name);
+    return NULL;
+}
+
+
 const char* CONTEXT::get_content_suffix() {
     if (!content_suffix && parent) return parent->get_content_suffix();
     return content_suffix;
@@ -972,6 +996,12 @@
 }
 
 
+dnswlp_list& CONTEXT::get_dnswl_list() {
+    if (dnswl_list.empty() && parent) return parent->get_dnswl_list();
+    return dnswl_list;
+}
+
+
 bool CONTEXT::acceptable_content(recorder &memory, int score, int bulk, string& msg) {
     if (spamassassin_limit && (score > spamassassin_limit)) {
         char buf[maxlen];
@@ -1012,6 +1042,13 @@
         printf("%s     dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message);
     }
 
+    for (dnswlp_map::iterator i=dnswl_names.begin(); i!=dnswl_names.end(); i++) {
+        const char *n = (*i).first;
+        DNSWL &d = *(*i).second;
+        printf("%s     dnswl %s %s %d; \n", indent, n, d.suffix, d.level);
+    }
+
+    {
     dnsblp_list dl = get_dnsbl_list();
     if (!dl.empty()) {
         printf("%s     dnsbl_list", indent);
@@ -1020,7 +1057,18 @@
             printf(" %s", d.name);
         }
         printf("; \n");
+    }}
+
+    {
+    dnswlp_list dl = get_dnswl_list();
+    if (!dl.empty()) {
+        printf("%s     dnswl_list", indent);
+        for (dnswlp_list::iterator i=dl.begin(); i!=dl.end(); i++) {
+            DNSWL &d = *(*i);
+            printf(" %s", d.name);
     }
+        printf("; \n");
+    }}
 
     if (content_filtering) {
         printf("%s     content on { \n", indent);
@@ -1222,6 +1270,26 @@
 
 ////////////////////////////////////////////////
 //
+bool parse_dnswl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
+bool parse_dnswl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
+    const char *name = tok.next();
+    const char *suf  = tok.next();
+    const int   lev  = tok.nextint();
+    if (!tsa(tok, token_semi)) return false;
+    DNSWLP dnsnew = new DNSWL(name, suf, lev);
+    DNSWLP dnsold = me.find_dnswl(name);
+    if (dnsold && (*dnsold == *dnsnew)) {
+        // duplicate redefinition, ignore it
+        delete dnsnew;
+        return true;
+    }
+    me.add_dnswl(name, dnsnew);
+    return true;
+}
+
+
+////////////////////////////////////////////////
+//
 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
     while (true) {
@@ -1243,6 +1311,27 @@
 
 ////////////////////////////////////////////////
 //
+bool parse_dnswll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
+bool parse_dnswll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
+    while (true) {
+        const char *have = tok.next();
+        if (!have) break;
+        if (have == token_semi) break;
+        DNSWLP dns = me.find_dnswl(have);
+        if (dns) {
+            me.add_dnswl(dns);
+        }
+        else {
+            tok.token_error("dnswl name", have);
+            return false;
+        }
+    }
+    return true;
+}
+
+
+////////////////////////////////////////////////
+//
 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
     const char *setting = tok.next();
@@ -1650,6 +1739,12 @@
         else if (have == token_dnsbll) {
             if (!parse_dnsbll(tok, dc, *con)) return false;
         }
+        else if (have == token_dnswl) {
+            if (!parse_dnswl(tok, dc, *con)) return false;
+        }
+        else if (have == token_dnswll) {
+            if (!parse_dnswll(tok, dc, *con)) return false;
+        }
         else if (have == token_content) {
             if (!parse_content(tok, dc, *con)) return false;
         }
@@ -1736,6 +1831,8 @@
     token_default       = register_string("default");
     token_dnsbl         = register_string("dnsbl");
     token_dnsbll        = register_string("dnsbl_list");
+    token_dnswl         = register_string("dnswl");
+    token_dnswll        = register_string("dnswl_list");
     token_envfrom       = register_string("env_from");
     token_envto         = register_string("env_to");
     token_filter        = register_string("filter");