[asterisk-dev] Making some changes to chan_sip and would like some feedback

Alejandro Kauffmann akauffma at prodigy.net.mx
Thu May 11 19:29:48 MST 2006


We are working on some changes and thought this was a good time for a sanity
check.  What we have done so far works in preliminary testing.  We moved
sip.conf to a sip directory under /etc/asterisk and currently only store
globals in the file.  We then generate a separate <extension>.conf file for
each extension.  We modified chan_sip.c so that:

"sip reload" reloads sip.conf and all <extension>.conf files in the sip
directory
"sip reload <extension>" only reloads the corresponding <extension>.conf
file

A "sip reload <extension>" followed by a "sip show peer <extension>"
reflects any changes we make to <extension>.conf.  We are still stuck with
loosing all sip information if you type an invalid entry for <extension> and
have to do a "sip reload" to restore everything.

Sanity check:

Is there any reason why we have to reload ALL sip information any time we
make a change to one extension, or would a single sip.conf (for globals) and
x number of <extension>.conf files still work as intended?  Any performance
or other type of gotchas?

This is what we have done so far.  Any and all feedback is appreciated.

Alex

--- chan_sip.c  2006-04-07 09:16:41.000000000 -0500
+++ /usr/src/asterisk-1.2.7.1/channels/chan_sip.c       2006-05-11
18:06:06.000000000 -0500
@@ -141,7 +141,7 @@

 static const char desc[] = "Session Initiation Protocol (SIP)";
 static const char channeltype[] = "SIP";
-static const char config[] = "sip.conf";
+char *config;
 static const char notify_config[] = "sip_notify.conf";

 #define RTP    1
@@ -9139,7 +9139,9 @@

 static char sip_reload_usage[] =
 "Usage: sip reload\n"
-"       Reloads SIP configuration from sip.conf\n";
+"      Reloads ALL SIP configuration from sip/*\n"
+"      sip reload <extension>\n"
+"       Reloads SIP configuration from <extension>.conf\n";

 static char show_subscriptions_usage[] =
 "Usage: sip show subscriptions\n"
@@ -12311,9 +12313,33 @@
        struct ast_flags dummy;
        int auto_sip_domains = 0;
        struct sockaddr_in old_bindaddr = bindaddr;
+       FILE *pFile;

-       cfg = ast_config_load(config);
-
+       if(!config) {
+               ast_verbose(" Reloading 'sip/*'\n");
+                cfg = ast_config_load("sip/*");
+       }
+       else {
+               char sip_dir[] = "sip/";
+               char sip_ext[] = ".conf";
+               config = strcat(sip_dir,config);
+               config = strcat(config,sip_ext);
+
+               char config_dir[] = "/etc/asterisk/";
+               char *config_file;
+               config_file = strcat(config_dir,config);
+               ast_log(LOG_NOTICE, "Config %s\n",config);
+               pFile = fopen(config_file,"r");
+               if(pFile) {
+                        ast_verbose(" Reloading '%s'\n", config);
+                       cfg = ast_config_load(config);
+                       fclose(pFile);
+               }
+               else {
+                       ast_verbose(" Unable to load config\n");
+                       return -1;
+               }
+       }
        /* We *must* have a config file otherwise stop immediately */
        if (!cfg) {
                ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
@@ -13038,7 +13064,9 @@
 static int sip_do_reload(void)
 {
        clear_realm_authentication(authl);
-       clear_sip_domains();
+       if(!config) {
+               clear_sip_domains();
+       }
        authl = NULL;

        /* First, destroy all outstanding registry calls */
@@ -13077,6 +13105,9 @@
        } else
                sip_reloading = 1;
        ast_mutex_unlock(&sip_reload_lock);
+       if(argv) {
+               config = argv[2];
+       }
        restart_monitor();

        return 0;




More information about the asterisk-dev mailing list