Separate IAX and SIP tables for users/peers
authorMark Spencer <markster@digium.com>
Thu, 10 Feb 2005 21:14:11 +0000 (21:14 +0000)
committerMark Spencer <markster@digium.com>
Thu, 10 Feb 2005 21:14:11 +0000 (21:14 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5004 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c
channels/chan_sip.c
config.c
configs/extconfig.conf.sample

index 7f80d47..4375507 100755 (executable)
@@ -2197,7 +2197,7 @@ static struct iax2_peer *realtime_peer(const char *peername)
        struct iax2_peer *peer=NULL;
        time_t regseconds, nowtime;
        int dynamic=0;
-       var = ast_load_realtime("iaxfriends", "name", peername, NULL);
+       var = ast_load_realtime("iaxpeers", "name", peername, NULL);
        if (var) {
                /* Make sure it's not a user only... */
                peer = build_peer(peername, var, ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
@@ -2259,7 +2259,7 @@ static struct iax2_user *realtime_user(const char *username)
        struct ast_variable *var;
        struct ast_variable *tmp;
        struct iax2_user *user=NULL;
-       var = ast_load_realtime("iaxfriends", "name", username, NULL);
+       var = ast_load_realtime("iaxusers", "name", username, NULL);
        if (var) {
                /* Make sure it's not a user only... */
                user = build_user(username, var, !ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS));
@@ -2304,7 +2304,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin)
        snprintf(regseconds, sizeof(regseconds), "%ld", nowtime);
        ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
        snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-       ast_update_realtime("iaxfriends", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, NULL);
+       ast_update_realtime("iaxpeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, NULL);
 }
 
 
index d575adc..a8ab007 100755 (executable)
@@ -1076,7 +1076,7 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin,
        snprintf(regseconds, sizeof(regseconds), "%ld", nowtime);
        ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr);
        snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-       ast_update_realtime("sipfriends", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, "username", username, NULL);
+       ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, "username", username, NULL);
 }
 
 static void register_peer_exten(struct sip_peer *peer, int onoff)
@@ -1133,12 +1133,12 @@ static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *
        struct ast_variable *tmp;
 
        if (peername) 
-               var = ast_load_realtime("sipfriends", "name", peername, NULL);
+               var = ast_load_realtime("sippeers", "name", peername, NULL);
        else if (sin) {
                char iabuf[80];
 
                ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr);
-               var = ast_load_realtime("sipfriends", "ipaddr", iabuf, NULL);
+               var = ast_load_realtime("sippeers", "ipaddr", iabuf, NULL);
        } else
                return NULL;
 
@@ -1218,7 +1218,7 @@ static struct sip_user *realtime_user(const char *username)
        struct ast_variable *tmp;
        struct sip_user *user = NULL;
 
-       var = ast_load_realtime("sipfriends", "name", username, NULL);
+       var = ast_load_realtime("sipusers", "name", username, NULL);
 
        if (!var)
                return NULL;
index d35f385..32a0591 100755 (executable)
--- a/config.c
+++ b/config.c
@@ -751,12 +751,47 @@ static void clear_config_maps(void)
        ast_mutex_unlock(&config_lock);
 }
 
+static int append_mapping(char *name, char *driver, char *database, char *table)
+{
+       struct ast_config_map *map;
+       int length;
+
+       length = sizeof(*map);
+       length += strlen(name) + 1;
+       length += strlen(driver) + 1;
+       length += strlen(database) + 1;
+       if (table)
+               length += strlen(table) + 1;
+       map = malloc(length);
+
+       if (!map)
+               return -1;
+
+       memset(map, 0, length);
+       map->name = map->stuff;
+       strcpy(map->name, name);
+       map->driver = map->name + strlen(map->name) + 1;
+       strcpy(map->driver, driver);
+       map->database = map->driver + strlen(map->driver) + 1;
+       strcpy(map->database, database);
+       if (table) {
+               map->table = map->database + strlen(map->database) + 1;
+               strcpy(map->table, table);
+       }
+       map->next = config_maps;
+
+       if (option_verbose > 1)
+               ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",
+                           map->name, map->driver, map->database, map->table ? map->table : map->name);
+
+       config_maps = map;
+       return 0;
+}
+
 void read_config_maps(void) 
 {
        struct ast_config *config;
        struct ast_variable *v;
-       struct ast_config_map *map;
-       int length;
        char *driver, *table, *database, *stringp;
 
        clear_config_maps();
@@ -780,36 +815,16 @@ void read_config_maps(void)
 
                if (!driver || !database)
                        continue;
-
-               length = sizeof(*map);
-               length += strlen(v->name) + 1;
-               length += strlen(driver) + 1;
-               length += strlen(database) + 1;
-               if (table)
-                       length += strlen(table) + 1;
-               map = malloc(length);
-
-               if (!map)
-                       continue;
-
-               memset(map, 0, length);
-               map->name = map->stuff;
-               strcpy(map->name, v->name);
-               map->driver = map->name + strlen(map->name) + 1;
-               strcpy(map->driver, driver);
-               map->database = map->driver + strlen(map->driver) + 1;
-               strcpy(map->database, database);
-               if (table) {
-                       map->table = map->database + strlen(map->database) + 1;
-                       strcpy(map->table, table);
-               }
-               map->next = config_maps;
-
-               if (option_verbose > 1)
-                       ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",
-                                   map->name, map->driver, map->database, map->table ? map->table : map->name);
-
-               config_maps = map;
+               if (!strcasecmp(v->name, "sipfriends")) {
+                       ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sipusers and sippeers, though they can point to the same table.\n");
+                       append_mapping("sipusers", driver, database, table ? table : "sipfriends");
+                       append_mapping("sippeers", driver, database, table ? table : "sipfriends");
+               } else if (!strcasecmp(v->name, "iaxfriends")) {
+                       ast_log(LOG_WARNING, "The 'iaxfriends' table is obsolete, update your config to use iaxusers and iaxpeers, though they can point to the same table.\n");
+                       append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
+                       append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
+               } else 
+                       append_mapping(v->name, driver, database, table);
        }
                
        ast_config_destroy(config);
index bf9f83c..c4b058a 100755 (executable)
 ; the family if the table is not specified
 ;
 ;example => odbc,asterisk,alttable
-;iaxfriends => odbc,asterisk
-;sipfriends => odbc,asterisk
+;iaxusers => odbc,asterisk
+;iaxpeers => odbc,asterisk
+;sipusers => odbc,asterisk
+;sippeers => odbc,asterisk
 ;voicemail => odbc,asterisk
 ;extensions => odbc,asterisk