diff src/dnsbl.cpp @ 29:4dfdf33f1db0 stable-2-4

add syslog msg freeing memory, use bare tld names without leading period
author carl
date Thu, 27 May 2004 16:17:48 -0700
parents 33e1e3910506
children fc7f8f3ea90f
line wrap: on
line diff
--- a/src/dnsbl.cpp	Thu May 27 10:08:51 2004 -0700
+++ b/src/dnsbl.cpp	Thu May 27 16:17:48 2004 -0700
@@ -118,6 +118,7 @@
     // the only mutable stuff once it has been loaded from the config file
     int         reference_count;    // protected by the global config_mutex
     // all the rest is constant after loading from the config file
+    int         generation;
     time_t      load_time;
     string_list config_files;
     dnsblp_map  dnsbls;
@@ -138,6 +139,7 @@
 };
 CONFIG::CONFIG() {
     reference_count    = 0;
+    generation         = 0;
     load_time          = 0;
     content_suffix     = NULL;
     content_message    = NULL;
@@ -168,6 +170,7 @@
 static bool loader_run   = true;    // used to stop the config loader thread
 static string_set all_strings;      // owns all the strings, only modified by the config loader thread
 static CONFIG * config = NULL;      // protected by the config_mutex
+static int  generation = 0;         // protected by the config_mutex
 
 static pthread_mutex_t  config_mutex;
 static pthread_mutex_t  syslog_mutex;
@@ -493,21 +496,21 @@
         int lim = priv.pc->host_limit;
         if ((count > lim) && (lim > 0)) return reject_host;
         host = *i;
+        ip   = protected_dns_interface(host, true);
         if (debug_syslog) {
             char buf[200];
-            snprintf(buf, sizeof(buf), "looking for host %s", host);
+            if (ip) {
+                char adr[sizeof "255.255.255.255"];
+                adr[0] = '\0';
+                inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
+                snprintf(buf, sizeof(buf), "host %s found at %s", host, adr);
+            }
+            else {
+                snprintf(buf, sizeof(buf), "host %s not found", host);
+            }
             my_syslog(buf);
         }
-        ip  = protected_dns_interface(host, true);
         if (ip) {
-        //  if (debug_syslog) {
-        //      char adr[sizeof "255.255.255.255"];
-        //      adr[0] = '\0';
-        //      inet_ntop(AF_INET, (const u_char *)&ip, adr, sizeof(adr));
-        //      char buf[200];
-        //      snprintf(buf, sizeof(buf), "found host %s at %s", host, adr);
-        //      my_syslog(buf);
-        //  }
             status st = check_single(ip, dc.content_suffix);
             if (st == reject) return st;
         }
@@ -877,11 +880,9 @@
             bool processed = false;
             switch (commands[cmd]) {
                 case tld: {
-                    char *tld = strtok(NULL, delim);
+                    char *tld = next_token(delim);
                     if (!tld) break;                            // no tld value
-                    char buf[200];
-                    snprintf(buf, sizeof(buf), ".%s", tld);
-                    dc.tlds.insert(register_string(buf));       // leading .
+                    dc.tlds.insert(tld);
                     processed = true;
                     } break;
 
@@ -1066,8 +1067,13 @@
 //
 static CONFIG* new_conf();
 static CONFIG* new_conf() {
-    my_syslog("loading new configuration");
     CONFIG *newc = new CONFIG;
+    pthread_mutex_lock(&config_mutex);
+        newc->generation = generation++;
+    pthread_mutex_unlock(&config_mutex);
+    char buf[200];
+    snprintf(buf, sizeof(buf), "loading configuration generation %d", newc->generation);
+    my_syslog(buf);
     load_conf(*newc, "dnsbl.conf");
     newc->load_time = time(NULL);
     return newc;
@@ -1109,6 +1115,9 @@
         for (configp_set::iterator i=old_configs.begin(); i!=old_configs.end(); ) {
             CONFIG *old = *i;
             if (!old->reference_count) {
+                char buf[200];
+                snprintf(buf, sizeof(buf), "freeing memory for old configuration generation %d", old->generation);
+                my_syslog(buf);
                 delete old; // destructor does all the work
                 old_configs.erase(i++);
             }