diff --git a/channels/chan_sip.c b/channels/chan_sip.c index c5f22111123d037fc54a6a02d0acedd59853893d..1856c9af2ae09492cc62d833081de7bf253974bb 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2175,12 +2175,20 @@ static int sip_sendtext(struct ast_channel *ast, const char *text) return 0; } -/*! \brief Update peer object in realtime storage */ +/*! \brief Update peer object in realtime storage + If the Asterisk system name is set in asterisk.conf, we will use + that name and store that in the "regserver" field in the sippeers + table to facilitate multi-server setups. +*/ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, int expirey) { char port[10]; char ipaddr[20]; char regseconds[20]; + + char *sysname = ast_config_AST_SYSTEM_NAME; + char *syslabel = NULL; + time_t nowtime = time(NULL) + expirey; const char *fc = fullcontact ? "fullcontact" : NULL; @@ -2188,9 +2196,14 @@ static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr); snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port)); + if (ast_strlen_zero(sysname)) /* No system name, disable this */ + sysname = NULL; + else + syslabel = "regserver"; + ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, "port", port, "regseconds", regseconds, - "username", username, fc, fullcontact, NULL); /* note fc _can_ be NULL */ + "username", username, fc, fullcontact, syslabel, sysname, NULL); /* note fc _can_ be NULL */ } /*! \brief Automatically add peer extension to dial plan */ @@ -7141,7 +7154,7 @@ static void destroy_association(struct sip_peer *peer) { if (!ast_test_flag(&global_flags[1], SIP_PAGE2_IGNOREREGEXPIRE)) { if (ast_test_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT)) - ast_update_realtime("sippeers", "name", peer->name, "fullcontact", "", "ipaddr", "", "port", "", "regseconds", "0", "username", "", NULL); + ast_update_realtime("sippeers", "name", peer->name, "fullcontact", "", "ipaddr", "", "port", "", "regseconds", "0", "username", "", "regserver", "", NULL); else ast_db_del("SIP/Registry", peer->name); } diff --git a/doc/extconfig.txt b/doc/extconfig.txt index c52eb4796f5460ed12629497747d0b40fa814c0c..0a95997cec453547a031d57a21db29011e443b73 100644 --- a/doc/extconfig.txt +++ b/doc/extconfig.txt @@ -54,6 +54,12 @@ A SIP table would look more like this: in order to store appropriate parameters required for SIP. +In addition to this, if you add a field named "regserver" to the +SIP peers table and have the system name set in asterisk.conf, +Asterisk will store the system name that the user registered on in +the database. This can be used to direct calls to go through the server +that holds the registration (for NAT traversal purposes). + A Voicemail table would look more like this: +----------+---------+----------+----------+-----------+---------------+ diff --git a/doc/realtime.txt b/doc/realtime.txt index 6f5271d31627637130fa536b8745514eb4130bcf..bdcf505135c981b3b6256be3e80ff837d04f1053 100644 --- a/doc/realtime.txt +++ b/doc/realtime.txt @@ -49,9 +49,8 @@ voicemail notification and NAT keepalives for these peers. Other than that, most of the functionality works the same way for realtime friends as for the ones in static configuration. -There is some work to create a solution for Realtime SIP devices that -loads from database and stays in memory for the duration of a call or -a registration, but that work is not integrated into Asterisk yet. +With caching, the device stays in memory for a specified time. More +information about this is to be found in the sip.conf sample file. * New function in the dial plan: The Realtime Switch ---------------------------------------------------- @@ -94,8 +93,11 @@ driver. Defined well-known family names are: * sippeers, sipusers SIP peers and users -* iaxfriends IAX2 peers +* iaxpeers, iaxusers IAX2 peers and users * voicemail Voicemail accounts +* queues Queues +* queue_members Queue members +* extensions Realtime extensions (switch) There is documentation of the SQL database in the file doc/extconfig.txt in your Asterisk source code tree.