diff src/context.cpp @ 270:f92f24950bd3 stable-6-0-35

Use mozilla prefix list for tld checking, Enable surbl/uribl/dbl rhs lists
author Carl Byington <carl@five-ten-sg.com>
date Mon, 09 Sep 2013 15:15:53 -0700
parents f941563c2a95
children a99b6c1f5f67
line wrap: on
line diff
--- a/src/context.cpp	Wed May 22 11:34:37 2013 -0700
+++ b/src/context.cpp	Mon Sep 09 15:15:53 2013 -0700
@@ -1,6 +1,6 @@
 /*
 
-Copyright (c) 2007 Carl Byington - 510 Software Group, released under
+Copyright (c) 2013 Carl Byington - 510 Software Group, released under
 the GPL version 3 or any later version at your choice available at
 http://www.gnu.org/licenses/gpl-3.0.txt
 
@@ -20,9 +20,10 @@
 #include <unistd.h>
 #include <climits>
 
+const char *token_asterisk;
 const char *token_autowhite;
+const char *token_bang;
 const char *token_black;
-const char *token_cctld;
 const char *token_content;
 const char *token_context;
 const char *token_dccbulk;
@@ -52,6 +53,7 @@
 const char *token_ok;
 const char *token_ok2;
 const char *token_on;
+const char *token_period;
 const char *token_rate;
 const char *token_rbrace;
 const char *token_require;
@@ -916,6 +918,14 @@
 }
 
 
+void CONTEXT::add_tld(const char *tld) {
+    int n = strlen(tld);
+         if ((n > 1) && (tld[0] == '*') && (tld[1] == '.')) content_tldwilds.insert(tld+1);
+    else if ((n > 0) && (tld[0] == '!'))                    content_tldnots.insert(tld+1);
+    else                                                    content_tlds.insert(tld);
+}
+
+
 CONTEXTP CONTEXT::find_context(const char *from) {
     context_map::iterator i = env_from_context.find(from);
     if (i != env_from_context.end()) return (*i).second;        // found user@domain key
@@ -993,17 +1003,24 @@
 }
 
 
-string_set& CONTEXT::get_content_cctlds() {
-    if (content_cctlds.empty() && parent) return parent->get_content_cctlds();
-    return content_cctlds;
-}
-
 string_set& CONTEXT::get_content_tlds() {
     if (content_tlds.empty() && parent) return parent->get_content_tlds();
     return content_tlds;
 }
 
 
+string_set& CONTEXT::get_content_tldwilds() {
+    if (content_tldwilds.empty() && parent) return parent->get_content_tldwilds();
+    return content_tldwilds;
+}
+
+
+string_set& CONTEXT::get_content_tldnots() {
+    if (content_tldnots.empty() && parent) return parent->get_content_tldnots();
+    return content_tldnots;
+}
+
+
 string_set& CONTEXT::get_html_tags() {
     if (html_tags.empty() && parent) return parent->get_html_tags();
     return html_tags;
@@ -1104,20 +1121,18 @@
             }
             printf("%s         }; \n", indent);
         }
-        if (!content_cctlds.empty()) {
-            printf("%s         cctld { \n", indent);
-            printf("%s             ", indent);
-            for (string_set::iterator i=content_cctlds.begin(); i!=content_cctlds.end(); i++) {
-                printf("%s; ", *i);
-            }
-            printf("\n%s         }; \n", indent);
-        }
-        if (!content_tlds.empty()) {
+        if (!content_tlds.empty() || !content_tldwilds.empty() || !content_tldnots.empty()) {
             printf("%s         tld { \n", indent);
             printf("%s             ", indent);
             for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) {
                 printf("%s; ", *i);
             }
+            for (string_set::iterator i=content_tldwilds.begin(); i!=content_tldwilds.end(); i++) {
+                printf("*%s; ", *i);
+            }
+            for (string_set::iterator i=content_tldnots.begin(); i!=content_tldnots.end(); i++) {
+                printf("!%s; ", *i);
+            }
             printf("\n%s         }; \n", indent);
         }
         if (!html_tags.empty()) {
@@ -1416,17 +1431,28 @@
                 const char *have = tok.next();
                 if (!have) break;
                 if (have == token_rbrace) break;  // done
-                me.add_tld(have);
-            }
-            if (!tsa(tok, token_semi)) return false;
-        }
-        else if (have == token_cctld) {
-            if (!tsa(tok, token_lbrace)) return false;
-            while (true) {
-                const char *have = tok.next();
+                if (have == token_bang) {
+                    have = tok.next();
                 if (!have) break;
                 if (have == token_rbrace) break;  // done
-                me.add_cctld(have);
+                    char buf[200];
+                    snprintf(buf, sizeof(buf), "!%s", have);
+                    me.add_tld(register_string(buf));           // leading !
+                }
+                else if (have == token_asterisk) {
+                    have = tok.next();
+                    if (!have) break;
+                    if (have == token_rbrace) break;  // done
+                    if (have == token_period) {
+                        have = tok.next();
+                        if (!have) break;
+                        if (have == token_rbrace) break;  // done
+                        char buf[200];
+                        snprintf(buf, sizeof(buf), "*.%s", have);
+                        me.add_tld(register_string(buf));           // leading *.
+                    }
+                }
+                else me.add_tld(have);
             }
             if (!tsa(tok, token_semi)) return false;
         }
@@ -1864,9 +1890,10 @@
 // init the tokens
 //
 void token_init() {
+    token_asterisk      = register_string("*");
     token_autowhite     = register_string("autowhite");
+    token_bang          = register_string("!");
     token_black         = register_string("black");
-    token_cctld         = register_string("cctld");
     token_content       = register_string("content");
     token_context       = register_string("context");
     token_dccbulk       = register_string("dcc_bulk_threshold");
@@ -1896,6 +1923,7 @@
     token_ok            = register_string("ok");
     token_ok2           = register_string("ok2");
     token_on            = register_string("on");
+    token_period        = register_string(".");
     token_rate          = register_string("rate_limit");
     token_rbrace        = register_string("}");
     token_require       = register_string("require_match");