diff src/context.cpp @ 76:81f1e400e8ab

start coding on new config syntax
author carl
date Sat, 16 Jul 2005 13:47:19 -0700
parents 1142e46be550
children 8487650c98ee
line wrap: on
line diff
--- a/src/context.cpp	Wed Jul 13 23:04:14 2005 -0700
+++ b/src/context.cpp	Sat Jul 16 13:47:19 2005 -0700
@@ -61,6 +61,7 @@
 
 
 CONFIG::~CONFIG() {
+    if (debug_syslog) my_syslog("config::~config destructor");
     for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) {
         CONTEXT *c = *i;
         delete c;
@@ -81,6 +82,20 @@
     context_map::iterator i = env_to.find(to);
     if (i != env_to.end()) {
         CONTEXTP c = (*i).second;
+        int       s = strlen(to);
+        bool     at = s && (to[s-1] == '@');
+        if (at && con->is_parent(c->get_parent())) {
+            if (debug_syslog) {
+                char oldname[maxlen];
+                char newname[maxlen];
+                char *oldn = c->get_full_name(oldname, maxlen);
+                char *newn = con->get_full_name(newname, maxlen);
+                char buf[maxlen*3];
+                snprintf(buf, maxlen*3, "both %s and %s claim envelope to %s, the first one wins", oldn, newn, to);
+                my_syslog(buf);
+            }
+            return;     // don't take over user@ entries from your ancestors children
+        }
         if ((c != con) && (c != con->get_parent())) {
             char oldname[maxlen];
             char newname[maxlen];
@@ -145,6 +160,12 @@
 
 
 CONTEXT::~CONTEXT() {
+    if (debug_syslog) {
+        char buf[maxlen];
+        char msg[maxlen];
+        snprintf(msg, maxlen, "context::~context %s destructor", get_full_name(buf,maxlen));
+        my_syslog(msg);
+    }
     for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
         DNSBLP d = (*i).second;
         // delete the underlying DNSBL objects.
@@ -153,6 +174,13 @@
 }
 
 
+bool CONTEXT::is_parent(CONTEXTP p) {
+    if (p == parent) return true;
+    if (!parent) return false;
+    return parent->is_parent(p);
+}
+
+
 char *CONTEXT::get_full_name(char *buffer, int size) {
     if (!parent) return name;
     char buf[maxlen];
@@ -174,23 +202,27 @@
 
 
 char *CONTEXT::find_from(char *from) {
+    char *rc = token_inherit;
     string_map::iterator i = env_from.find(from);
-    if (i != env_from.end()) return (*i).second;        // found user@domain.tld key
+    if (i != env_from.end()) rc = (*i).second;  // found user@domain.tld key
+    else {
     char *x = strchr(from, '@');
     if (x) {
         x++;
         i = env_from.find(x);
-        if (i != env_from.end()) return (*i).second;    // found domain.tld key
+            if (i != env_from.end()) rc = (*i).second;  // found domain.tld key
+            else {
         char y = *x;
         *x = '\0';
         i = env_from.find(from);
         *x = y;
-        if (i != env_from.end()) return (*i).second;      // found user@ key
+                if (i != env_from.end()) rc = (*i).second;  // found user@ key
+            }
+        }
     }
-    if ((env_from_default == token_inherit) && parent) {
-        return parent->find_from(from);
-    }
-    return (env_from_default == token_inherit) ? token_unknown : env_from_default;
+    if (rc == token_inherit) rc = env_from_default;
+    if ((rc == token_inherit) && parent) return parent->find_from(from);
+    return (rc == token_inherit) ? token_unknown : rc;
 }
 
 
@@ -227,6 +259,42 @@
 }
 
 
+char* CONTEXT::get_content_suffix() {
+    if (!content_suffix && parent) return parent->get_content_suffix();
+    return content_suffix;
+}
+
+
+char* CONTEXT::get_content_message() {
+    if (!content_message && parent) return parent->get_content_message();
+    return content_message;
+}
+
+
+string_set& CONTEXT::get_content_host_ignore() {
+    if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore();
+    return content_host_ignore;
+}
+
+
+string_set& CONTEXT::get_content_tlds() {
+    if (content_tlds.empty() && parent) return parent->get_content_tlds();
+    return content_tlds;
+}
+
+
+string_set& CONTEXT::get_html_tags() {
+    if (html_tags.empty() && parent) return parent->get_html_tags();
+    return html_tags;
+}
+
+
+dnsblp_list& CONTEXT::get_dnsbl_list() {
+    if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list();
+    return dnsbl_list;
+}
+
+
 bool CONTEXT::acceptable_content(recorder &memory, char *&msg) {
     if (memory.excessive_bad_tags(tag_limit)) {
         msg = tag_limit_message;
@@ -427,7 +495,6 @@
 //
 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
-    bool topdefault = (!me.get_parent()) && (!dc.default_context);
     char *setting = tok.next();
     if (setting == token_on) {
         me.set_content_filtering(true);
@@ -446,25 +513,18 @@
         if (have == token_filter) {
             char *suffix = tok.next();
             char *messag = tok.next();
-            if (topdefault) {
                 me.set_content_suffix(suffix);
                 me.set_content_message(messag);
-            }
             if (!tsa(tok, token_semi)) return false;
-            if (!topdefault) tok.token_error("content filters may only be speciried in the top default context");
         }
         else if (have == token_ignore) {
             if (!tsa(tok, token_lbrace)) return false;
             while (true) {
                 if (!have) break;
                 char *have = tok.next();
-                if (have == token_rbrace) {
-                    break;  // done
-                }
-                else {
+                if (have == token_rbrace) break;  // done
                     me.add_ignore(have);
                 }
-            }
             if (!tsa(tok, token_semi)) return false;
         }
         else if (have == token_tld) {
@@ -472,15 +532,10 @@
             while (true) {
                 char *have = tok.next();
                 if (!have) break;
-                if (have == token_rbrace) {
-                    break;  // done
-                }
-                else {
-                    if (topdefault) me.add_tld(have);
-                }
+                if (have == token_rbrace) break;  // done
+                me.add_tld(have);
             }
             if (!tsa(tok, token_semi)) return false;
-            if (!topdefault) tok.token_error("tld values may only be specified in the top default context");
         }
         else if (have == token_html_limit) {
             have = tok.next();
@@ -507,11 +562,10 @@
                     break;  // done
                 }
                 else {
-                    if (topdefault) me.add_tag(have);
+                    me.add_tag(have);
                 }
             }
             if (!tsa(tok, token_semi)) return false;
-            if (!topdefault) tok.token_error("html tags may only be specified in the top default context");
         }
         else if (have == token_host_limit) {
             have = tok.next();