main.c.patch   [plain text]


--- /tmp/jabberd-2.1.24.1/sm/main.c	2008-04-27 02:57:18.000000000 -0700
+++ ./jabberd2/sm/main.c	2009-05-26 13:09:55.000000000 -0700
@@ -30,6 +30,8 @@
 
 static sig_atomic_t sm_shutdown = 0;
 static sig_atomic_t sm_logrotate = 0;
+static sig_atomic_t sm_sighup = 0;
+
 static sm_t sm = NULL;
 static char* config_file;
 
@@ -41,24 +43,7 @@ static void _sm_signal(int signum)
 
 static void _sm_signal_hup(int signum)
 {
-    config_t conf;
-
-    log_write(sm->log, LOG_NOTICE, "HUP handled. reloading modules...");
-
-    sm_logrotate = 1;
-
-    /* reload dynamic modules */
-    conf = config_new();
-    if (conf && config_load(conf, config_file) == 0) {
-        config_free(sm->config);
-        sm->config = conf;
-        /*_sm_config_expand(sm);*/ /* we want to reload modules only */
-    } else {
-        log_write(sm->log, LOG_WARNING, "couldn't reload config (%s)", config_file);
-        if (conf) config_free(conf);
-    }
-    mm_free(sm->mm);
-    sm->mm = mm_new(sm);
+    sm_sighup = 1;
 }
 
 /** store the process id */
@@ -93,6 +78,7 @@ static void _sm_pidfile(sm_t sm) {
 static void _sm_config_expand(sm_t sm)
 {
     char *str;
+    config_elem_t elem;
 
     sm->id = config_get_one(sm->config, "id", 0);
     if(sm->id == NULL)
@@ -113,6 +99,8 @@ static void _sm_config_expand(sm_t sm)
 
     sm->router_pemfile = config_get_one(sm->config, "router.pemfile", 0);
 
+    sm->router_private_key_password = config_get_one(sm->config, "router.private_key_password", 0);
+
     sm->retry_init = j_atoi(config_get_one(sm->config, "router.retry.init", 0), 3);
     sm->retry_lost = j_atoi(config_get_one(sm->config, "router.retry.lost", 0), 3);
     if((sm->retry_sleep = j_atoi(config_get_one(sm->config, "router.retry.sleep", 0), 2)) < 1)
@@ -135,6 +123,19 @@ static void _sm_config_expand(sm_t sm)
             sm->log_ident = "jabberd/sm";
     } else if(sm->log_type == log_FILE)
         sm->log_ident = config_get_one(sm->config, "log.file", 0);
+        
+    elem = config_get(sm->config, "storage.limits.queries");
+    if(elem != NULL)
+    {
+        sm->query_rate_total = j_atoi(elem->values[0], 0);
+        if(sm->query_rate_total != 0)
+        {
+            sm->query_rate_seconds = j_atoi(j_attr((const char **) elem->attrs[0], "seconds"), 5);
+            sm->query_rate_wait = j_atoi(j_attr((const char **) elem->attrs[0], "throttle"), 60);
+        }
+    }
+    sm->masq_sender_replacement = config_get_one(sm->config, "aci.masq_sender_replacement", 0);
+    sm->apple_notification_component_addr = config_get_one(sm->config, "apple_notification_component_addr", 0);
 }
 
 static int _sm_router_connect(sm_t sm) {
@@ -306,17 +307,19 @@ JABBER_MAIN("jabberd2sm", "Jabber 2 Sess
 
     sm->users = xhash_new(401);
 
+    sm->query_rates = xhash_new(101);
+    
     sm->sx_env = sx_env_new();
 
 #ifdef HAVE_SSL
     if(sm->router_pemfile != NULL) {
-        sm->sx_ssl = sx_env_plugin(sm->sx_env, sx_ssl_init, sm->router_pemfile, NULL, NULL);
+        sm->sx_ssl = sx_env_plugin(sm->sx_env, sx_ssl_init, sm->router_pemfile, NULL, NULL, sm->router_private_key_password);
         if(sm->sx_ssl == NULL) {
             log_write(sm->log, LOG_ERR, "failed to load SSL pemfile, SSL disabled");
             sm->router_pemfile = NULL;
         }
     }
-#endif
+#endif // HAVE_SSL
 
     /* get sasl online */
     sm->sx_sasl = sx_env_plugin(sm->sx_env, sx_sasl_init, "xmpp", NULL, NULL);
@@ -333,6 +336,31 @@ JABBER_MAIN("jabberd2sm", "Jabber 2 Sess
     while(!sm_shutdown) {
         mio_run(sm->mio, 5);
 
+        if (sm_sighup) {
+            config_t conf;
+            log_write(sm->log, LOG_NOTICE, "HUP handled. reloading modules...");
+
+            sm_logrotate = 1;
+
+            // Reload any selected config items
+            conf = config_new();
+            if (conf && config_load(conf, config_file) == 0) {
+                // Apple FIXME: config_free here results in memory corruption and causes the logging of arbitrary
+                //     data.  Disabling module reloading until we can fix this.
+                //config_free(sm->config);
+                //sm->config = conf;
+                sm->apple_notification_component_addr = config_get_one(conf, "apple_notification_component_addr", 0);
+                config_free(conf);
+            } else {
+                log_write(sm->log, LOG_WARNING, "couldn't reload config (%s)", config_file);
+                if (conf) config_free(conf);
+            }
+            //mm_free(sm->mm);
+            //sm->mm = mm_new(sm);
+
+            sm_sighup = 0;
+        }
+
         if(sm_logrotate) {
             log_write(sm->log, LOG_NOTICE, "reopening log ...");
             log_free(sm->log);
@@ -394,6 +422,7 @@ JABBER_MAIN("jabberd2sm", "Jabber 2 Sess
     xhash_free(sm->xmlns);
     xhash_free(sm->xmlns_refcount);
     xhash_free(sm->users);
+    xhash_free(sm->query_rates);
 
     sx_free(sm->router);