<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][15441] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=15441">15441</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-11-11 21:52:07 -0600 (Wed, 11 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>solve problem from <a href="http://jira.freeswitch.org/browse/MODENDP-258">MODENDP-258</a> with an alternate approach, and make send-message-query-on-register=first-only and sql-in-transactions=true the defaults</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_presencec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_regc">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_slac">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -2042,7 +2042,7 @@
</span><span class="cx">                                                                                  profile-&gt;name);
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><del>-                                sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, show_reg_callback, &amp;cb);
</del><ins>+                                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, show_reg_callback, &amp;cb);
</ins><span class="cx">                                 switch_safe_free(sql);
</span><span class="cx"> 
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
</span><span class="lines">@@ -2263,7 +2263,7 @@
</span><span class="cx">                                                                                  profile-&gt;name);
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><del>-                                sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, show_reg_callback_xml, &amp;cb);
</del><ins>+                                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, show_reg_callback_xml, &amp;cb);
</ins><span class="cx">                                 switch_safe_free(sql);
</span><span class="cx"> 
</span><span class="cx">                                 stream-&gt;write_function(stream, &quot;  &lt;/registrations&gt;\n&quot;);
</span><span class="lines">@@ -2653,7 +2653,7 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         switch_assert(sql);
</span><del>-                        sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, contact_callback, &amp;cb);
</del><ins>+                        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, contact_callback, &amp;cb);
</ins><span class="cx">                         switch_safe_free(sql);
</span><span class="cx">                         reply = (char *) mystream.data;
</span><span class="cx">                         if (!zstr(reply) &amp;&amp; end_of(reply) == ',') {
</span><span class="lines">@@ -3365,7 +3365,7 @@
</span><span class="cx">                                 
</span><span class="cx"> 
</span><span class="cx">                                 switch_mutex_lock(profile-&gt;ireg_mutex);
</span><del>-                                sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, notify_callback, profile);
</del><ins>+                                sofia_glue_execute_sql_callback(profile, NULL, sql, notify_callback, profile);
</ins><span class="cx">                                 switch_mutex_unlock(profile-&gt;ireg_mutex);
</span><span class="cx">                                 sofia_glue_release_profile(profile);
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -475,7 +475,8 @@
</span><span class="cx">         sofia_gateway_t *gateways;
</span><span class="cx">         su_home_t *home;
</span><span class="cx">         switch_hash_t *chat_hash;
</span><del>-        switch_core_db_t *master_db;
</del><ins>+        switch_hash_t *db_hash;
+        //switch_core_db_t *master_db;
</ins><span class="cx">         switch_thread_rwlock_t *rwlock;
</span><span class="cx">         switch_mutex_t *flag_mutex;
</span><span class="cx">         uint32_t inuse;
</span><span class="lines">@@ -670,6 +671,11 @@
</span><span class="cx">         char *route_uri;
</span><span class="cx"> } sofia_destination_t;
</span><span class="cx"> 
</span><ins>+typedef struct {
+        switch_core_db_t *db;
+        time_t last_used;
+} sofia_cache_db_handle_t;
+
</ins><span class="cx"> #define sofia_test_pflag(obj, flag) ((obj)-&gt;pflags[flag] ? 1 : 0)
</span><span class="cx"> #define sofia_set_pflag(obj, flag) (obj)-&gt;pflags[flag] = 1
</span><span class="cx"> #define sofia_set_pflag_locked(obj, flag) assert(obj-&gt;flag_mutex != NULL);\
</span><span class="lines">@@ -747,7 +753,7 @@
</span><span class="cx"> void sofia_reg_auth_challenge(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_regtype_t regtype, const char *realm, int stale);
</span><span class="cx"> auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization, 
</span><span class="cx">                                                                 sip_t const *sip, const char *regstr, char *np, size_t nplen, char *ip, switch_event_t **v_event, 
</span><del>-                                                                long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params);
</del><ins>+                                                                long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count);
</ins><span class="cx">                                                                 
</span><span class="cx"> 
</span><span class="cx"> void sofia_reg_handle_sip_r_challenge(int status,
</span><span class="lines">@@ -773,7 +779,7 @@
</span><span class="cx">                                          nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]);
</span><span class="cx"> 
</span><span class="cx"> void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
</span><del>-void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex);
</del><ins>+void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
</ins><span class="cx"> void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot);
</span><span class="cx"> void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now);
</span><span class="cx"> void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now);
</span><span class="lines">@@ -795,7 +801,6 @@
</span><span class="cx"> int sofia_glue_init_sql(sofia_profile_t *profile);
</span><span class="cx"> char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only, const char *params);
</span><span class="cx"> switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
</span><del>-                                                                                          switch_bool_t master,
</del><span class="cx">                                                                                           switch_mutex_t *mutex,
</span><span class="cx">                                                                                           char *sql,
</span><span class="cx">                                                                                           switch_core_db_callback_func_t callback,
</span><span class="lines">@@ -925,3 +930,4 @@
</span><span class="cx"> void sofia_info_send_sipfrag(switch_core_session_t *aleg, switch_core_session_t *bleg);
</span><span class="cx"> void sofia_update_callee_id(switch_core_session_t *session, sofia_profile_t *profile, sip_t const *sip, switch_bool_t send);
</span><span class="cx"> void sofia_send_callee_id(switch_core_session_t *session, const char *name, const char *number);
</span><ins>+int sofia_sla_supported(sip_t const *sip);
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -591,7 +591,7 @@
</span><span class="cx">                         sofia_glue_get_addr(nua_current_request(nua), network_ip,  sizeof(network_ip), NULL);
</span><span class="cx">                         auth_res = sofia_reg_parse_auth(profile, authorization, sip,
</span><span class="cx">                                                                                         (char *) sip-&gt;sip_request-&gt;rq_method_name, tech_pvt-&gt;key, strlen(tech_pvt-&gt;key), network_ip, NULL, 0,
</span><del>-                                                                                        REG_INVITE, NULL, NULL);
</del><ins>+                                                                                        REG_INVITE, NULL, NULL, NULL);
</ins><span class="cx">                 }
</span><span class="cx">                 
</span><span class="cx">                 if (auth_res != AUTH_OK) {
</span><span class="lines">@@ -943,7 +943,7 @@
</span><span class="cx">                                 sprintf(sqlbuf + len, &quot;commit;\n&quot;);
</span><span class="cx"> 
</span><span class="cx">                                 //printf(&quot;TRANS:\n%s\n&quot;, sqlbuf);
</span><del>-                                sofia_glue_actually_execute_sql(profile, SWITCH_TRUE, sqlbuf, NULL);
</del><ins>+                                sofia_glue_actually_execute_sql(profile, sqlbuf, NULL);
</ins><span class="cx">                                 switch_mutex_unlock(profile-&gt;ireg_mutex);
</span><span class="cx">                                 loop_count = 0;
</span><span class="cx">                         }
</span><span class="lines">@@ -951,7 +951,7 @@
</span><span class="cx">                         if (qsize) {
</span><span class="cx">                                 switch_mutex_lock(profile-&gt;ireg_mutex);
</span><span class="cx">                                 while (switch_queue_trypop(profile-&gt;sql_queue, &amp;pop) == SWITCH_STATUS_SUCCESS &amp;&amp; pop) {
</span><del>-                                        sofia_glue_actually_execute_sql(profile, SWITCH_TRUE, (char *) pop, NULL);
</del><ins>+                                        sofia_glue_actually_execute_sql(profile, (char *) pop, NULL);
</ins><span class="cx">                                         free(pop);
</span><span class="cx">                                 }
</span><span class="cx">                                 switch_mutex_unlock(profile-&gt;ireg_mutex);
</span><span class="lines">@@ -978,7 +978,7 @@
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_lock(profile-&gt;ireg_mutex);
</span><span class="cx">         while (switch_queue_trypop(profile-&gt;sql_queue, &amp;pop) == SWITCH_STATUS_SUCCESS &amp;&amp; pop) {
</span><del>-                sofia_glue_actually_execute_sql(profile, SWITCH_TRUE, (char *) pop, NULL);
</del><ins>+                sofia_glue_actually_execute_sql(profile, (char *) pop, NULL);
</ins><span class="cx">                 free(pop);
</span><span class="cx">         }
</span><span class="cx">         switch_mutex_unlock(profile-&gt;ireg_mutex);
</span><span class="lines">@@ -1098,6 +1098,7 @@
</span><span class="cx">                                    NUTAG_APPL_METHOD(&quot;NOTIFY&quot;),
</span><span class="cx">                                    NUTAG_APPL_METHOD(&quot;INFO&quot;),
</span><span class="cx">                                    NUTAG_APPL_METHOD(&quot;ACK&quot;),
</span><ins>+                                   NUTAG_APPL_METHOD(&quot;SUBSCRIBE&quot;),
</ins><span class="cx"> #ifdef MANUAL_BYE
</span><span class="cx">                                    NUTAG_APPL_METHOD(&quot;BYE&quot;),
</span><span class="cx"> #endif
</span><span class="lines">@@ -1267,6 +1268,7 @@
</span><span class="cx"> 
</span><span class="cx">         sofia_glue_del_profile(profile);
</span><span class="cx">         switch_core_hash_destroy(&amp;profile-&gt;chat_hash);
</span><ins>+        switch_core_hash_destroy(&amp;profile-&gt;db_hash);
</ins><span class="cx"> 
</span><span class="cx">         switch_thread_rwlock_unlock(profile-&gt;rwlock);
</span><span class="cx">         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;Write unlock %s\n&quot;, profile-&gt;name);
</span><span class="lines">@@ -1864,6 +1866,7 @@
</span><span class="cx">                                                 if (switch_true(val)) {
</span><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</span><span class="cx">                                                 } else if (!strcasecmp(val, &quot;first-only&quot;)) {
</span><ins>+                                                        sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</ins><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
</span><span class="cx">                                                 } else {
</span><span class="cx">                                                         sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</span><span class="lines">@@ -2387,6 +2390,7 @@
</span><span class="cx"> 
</span><span class="cx">                                 profile-&gt;dbname = switch_core_strdup(profile-&gt;pool, url);
</span><span class="cx">                                 switch_core_hash_init(&amp;profile-&gt;chat_hash, profile-&gt;pool);
</span><ins>+                                switch_core_hash_init(&amp;profile-&gt;db_hash, profile-&gt;pool);
</ins><span class="cx">                                 switch_thread_rwlock_create(&amp;profile-&gt;rwlock, profile-&gt;pool);
</span><span class="cx">                                 switch_mutex_init(&amp;profile-&gt;flag_mutex, SWITCH_MUTEX_NESTED, profile-&gt;pool);
</span><span class="cx">                                 profile-&gt;dtmf_duration = 100;
</span><span class="lines">@@ -2397,10 +2401,11 @@
</span><span class="cx">                                 sofia_set_pflag(profile, PFLAG_DISABLE_100REL);
</span><span class="cx">                                 profile-&gt;auto_restart = 1;
</span><span class="cx">                                 sofia_set_pflag(profile, PFLAG_AUTOFIX_TIMING);
</span><del>-                                sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</del><span class="cx">                                 sofia_set_pflag(profile, PFLAG_RTP_AUTOFLUSH_DURING_BRIDGE);
</span><span class="cx">                                 profile-&gt;contact_user = SOFIA_DEFAULT_CONTACT_USER;
</span><span class="cx">                                 sofia_set_pflag(profile, PFLAG_PASS_CALLEE_ID);
</span><ins>+                                sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
+                                sofia_set_pflag(profile, PFLAG_SQL_IN_TRANS);
</ins><span class="cx"> 
</span><span class="cx">                                 for (param = switch_xml_child(settings, &quot;param&quot;); param; param = param-&gt;next) {
</span><span class="cx">                                         char *var = (char *) switch_xml_attr_soft(param, &quot;name&quot;);
</span><span class="lines">@@ -2479,6 +2484,7 @@
</span><span class="cx">                                                 if (switch_true(val)) {
</span><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</span><span class="cx">                                                 } else if (!strcasecmp(val, &quot;first-only&quot;)) {
</span><ins>+                                                        sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</ins><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER);
</span><span class="cx">                                                 } else {
</span><span class="cx">                                                         sofia_clear_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER);
</span><span class="lines">@@ -2653,6 +2659,7 @@
</span><span class="cx">                                         } else if (!strcasecmp(var, &quot;manage-shared-appearance&quot;)) {
</span><span class="cx">                                                 if (switch_true(val)) {
</span><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE);
</span><ins>+                                                        profile-&gt;pres_type = PRES_TYPE_FULL;
</ins><span class="cx">                                                         profile-&gt;sla_contact = switch_core_sprintf(profile-&gt;pool, &quot;sla-agent&quot;);
</span><span class="cx">                                                 }
</span><span class="cx">                                         } else if (!strcasecmp(var, &quot;disable-srv&quot;)) {
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -3609,6 +3609,7 @@
</span><span class="cx"> int sofia_glue_init_sql(sofia_profile_t *profile)
</span><span class="cx"> {
</span><span class="cx">         char *test_sql = NULL;
</span><ins>+        switch_core_db_t *db = NULL;
</ins><span class="cx"> 
</span><span class="cx">         char reg_sql[] =
</span><span class="cx">                 &quot;CREATE TABLE sip_registrations (\n&quot;
</span><span class="lines">@@ -3780,7 +3781,8 @@
</span><span class="cx">                 
</span><span class="cx">                 test_sql = switch_mprintf(&quot;delete from sip_registrations where (contact like '%%TCP%%' &quot;
</span><span class="cx">                                                                   &quot;or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' &quot;
</span><del>-                                                                  &quot;and network_ip!='-1' and network_port!='-1' and sip_username != '-1' and mwi_user != '-1' and mwi_host != '-1'&quot;, 
</del><ins>+                                                                  &quot;and network_ip like '%%' and network_port like '%%' and sip_username &quot;
+                                                                  &quot;like '%%' and mwi_user  like '%%' and mwi_host like '%%'&quot;, 
</ins><span class="cx">                                                                   mod_sofia_globals.hostname);
</span><span class="cx"> 
</span><span class="cx">                 if (switch_odbc_handle_exec(profile-&gt;master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="lines">@@ -3790,7 +3792,8 @@
</span><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_subscriptions where hostname='%q' and network_ip!='-1' and network_port!='-1'&quot;, mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_subscriptions where hostname='%q' and network_ip like '%%' and network_port like '%%'&quot;, 
+                                                                  mod_sofia_globals.hostname);
</ins><span class="cx"> 
</span><span class="cx">                 if (switch_odbc_handle_exec(profile-&gt;master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                         switch_odbc_handle_exec(profile-&gt;master_odbc, &quot;DROP TABLE sip_subscriptions&quot;, NULL);
</span><span class="lines">@@ -3813,7 +3816,7 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 free(test_sql);
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_authentication where hostname='%q' and last_nc &gt;= 0&quot;, mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_authentication where hostname='%q' or last_nc &gt;= 0&quot;, mod_sofia_globals.hostname);
</ins><span class="cx"> 
</span><span class="cx">                 if (switch_odbc_handle_exec(profile-&gt;master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                         switch_odbc_handle_exec(profile-&gt;master_odbc, &quot;DROP TABLE sip_authentication&quot;, NULL);
</span><span class="lines">@@ -3821,7 +3824,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_subscriptions where contact_str='' or hostname='%q' and network_ip!='-1'&quot;,
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_subscriptions where contact_str='' or hostname='%q' and network_ip like '%%'&quot;,
</ins><span class="cx">                                                                   mod_sofia_globals.hostname);
</span><span class="cx">                 if (switch_odbc_handle_exec(profile-&gt;master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                         switch_odbc_handle_exec(profile-&gt;master_odbc, &quot;DROP TABLE sip_shared_appearance_subscriptions&quot;, NULL);
</span><span class="lines">@@ -3830,7 +3833,7 @@
</span><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_dialogs where contact_str='' or hostname='%q' and network_ip!='-1'&quot;,
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_dialogs where contact_str='' or hostname='%q' and network_ip like '%%'&quot;,
</ins><span class="cx">                                                                   mod_sofia_globals.hostname);
</span><span class="cx">                 if (switch_odbc_handle_exec(profile-&gt;master_odbc, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                         switch_odbc_handle_exec(profile-&gt;master_odbc, &quot;DROP TABLE sip_shared_appearance_dialogs&quot;, NULL);
</span><span class="lines">@@ -3847,111 +3850,119 @@
</span><span class="cx">         } else if (profile-&gt;odbc_dsn) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;ODBC IS NOT AVAILABLE!\n&quot;);
</span><span class="cx">         } else {
</span><del>-                if (!(profile-&gt;master_db = switch_core_db_open_file(profile-&gt;dbname))) {
</del><ins>+                if (!(db = switch_core_db_open_file(profile-&gt;dbname))) {
</ins><span class="cx">                         return 0;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 test_sql = switch_mprintf(&quot;delete from sip_registrations where (contact like '%%TCP%%' &quot;
</span><span class="cx">                                                                   &quot;or status like '%%TCP%%' or status like '%%TLS%%') and hostname='%q' &quot;
</span><del>-                                                                  &quot;and network_ip!='-1' and network_port!='-1' and sip_username != '-1' and mwi_user != '-1' and mwi_host != '-1'&quot;,
</del><ins>+                                                                  &quot;and network_ip like '%%' and network_port like '%%' and sip_username &quot;
+                                                                  &quot;like '%%' and mwi_user like '%%' and mwi_host like '%%'&quot;,
</ins><span class="cx">                                                                   mod_sofia_globals.hostname);
</span><span class="cx">                 
</span><del>-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_registrations&quot;, reg_sql);
</del><ins>+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_registrations&quot;, reg_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_subscriptions where hostname='%q' and network_ip!='-1' and network_port!='-1'&quot;, mod_sofia_globals.hostname);
-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_subscriptions&quot;, sub_sql);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_subscriptions where hostname='%q' and network_ip like '%%' or network_port like '%%'&quot;, 
+                                                                  mod_sofia_globals.hostname);
+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_subscriptions&quot;, sub_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="cx">                 test_sql = switch_mprintf(&quot;delete from sip_dialogs where hostname='%q' and contact like '%%'&quot;, mod_sofia_globals.hostname);
</span><del>-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_dialogs&quot;, dialog_sql);
</del><ins>+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_dialogs&quot;, dialog_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="cx">                 test_sql = switch_mprintf(&quot;delete from sip_presence where hostname='%q'&quot;, mod_sofia_globals.hostname);
</span><del>-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_presence&quot;, pres_sql);
</del><ins>+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_presence&quot;, pres_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_authentication where hostname='%q' and last_nc &gt;= 0&quot;, mod_sofia_globals.hostname);
-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_authentication&quot;, auth_sql);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_authentication where hostname='%q' or last_nc &gt;= 0&quot;, mod_sofia_globals.hostname);
+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_authentication&quot;, auth_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="cx">                 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_subscriptions where contact_str = '' or hostname='%q' and network_ip!='-1'&quot;,
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_subscriptions where contact_str = '' or hostname='%q' and network_ip like '%%'&quot;,
</ins><span class="cx">                                                                   mod_sofia_globals.hostname);
</span><del>-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_shared_appearance_subscriptions&quot;, shared_appearance_sql);
</del><ins>+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_shared_appearance_subscriptions&quot;, shared_appearance_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="cx">                 test_sql = switch_mprintf(&quot;delete from sip_shared_appearance_dialogs where contact_str = '' or hostname='%q'&quot;, mod_sofia_globals.hostname);
</span><del>-                switch_core_db_test_reactive(profile-&gt;master_db, test_sql, &quot;DROP TABLE sip_shared_appearance_dialogs&quot;, shared_appearance_dialogs_sql);
</del><ins>+                switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_shared_appearance_dialogs&quot;, shared_appearance_dialogs_sql);
</ins><span class="cx">                 free(test_sql);
</span><span class="cx">                 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssa_hostname on sip_shared_appearance_subscriptions (hostname)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssa_hostname on sip_shared_appearance_subscriptions (hostname)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssa_subscriber on sip_shared_appearance_subscriptions (subscriber)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssa_subscriber on sip_shared_appearance_subscriptions (subscriber)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssa_profile_name on sip_shared_appearance_subscriptions (profile_name)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssa_aor on sip_shared_appearance_subscriptions (aor)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssa_aor on sip_shared_appearance_subscriptions (aor)&quot;, NULL, NULL, NULL);
</ins><span class="cx">                 
</span><span class="cx"> 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssd_profile_name on sip_shared_appearance_dialogs (profile_name)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssd_profile_name on sip_shared_appearance_dialogs (profile_name)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssd_hostname on sip_shared_appearance_dialogs (hostname)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssd_hostname on sip_shared_appearance_dialogs (hostname)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssd_hostname on sip_shared_appearance_dialogs (network_ip)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssd_hostname on sip_shared_appearance_dialogs (network_ip)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssd_contact_str on sip_shared_appearance_dialogs (contact_str)&quot;,  
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssd_contact_str on sip_shared_appearance_dialogs (contact_str)&quot;,  
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssd_call_id on sip_shared_appearance_dialogs (call_id)&quot;,  
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssd_call_id on sip_shared_appearance_dialogs (call_id)&quot;,  
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ssd_expires on sip_shared_appearance_dialogs (expires)&quot;, 
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ssd_expires on sip_shared_appearance_dialogs (expires)&quot;, 
</ins><span class="cx">                                                         NULL, NULL, NULL);
</span><span class="cx">                 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_call_id on sip_registrations (call_id)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_sip_user on sip_registrations (sip_user)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_sip_host on sip_registrations (sip_host)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_profile_name on sip_registrations (profile_name)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_presence_hosts on sip_registrations (presence_hosts)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_contact on sip_registrations (contact)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_expires on sip_registrations (expires)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_hostname on sip_registrations (hostname)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_status on sip_registrations (status)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_network_ip on sip_registrations (network_ip)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_network_port on sip_registrations (network_port)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_sip_username on sip_registrations (sip_username)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sr_sip_realm on sip_registrations (sip_realm)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists sr_call_id on sip_registrations (call_id)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_sip_user on sip_registrations (sip_user)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_sip_host on sip_registrations (sip_host)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_profile_name on sip_registrations (profile_name)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_presence_hosts on sip_registrations (presence_hosts)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_contact on sip_registrations (contact)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_expires on sip_registrations (expires)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_hostname on sip_registrations (hostname)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_status on sip_registrations (status)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_network_ip on sip_registrations (network_ip)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_network_port on sip_registrations (network_port)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_sip_username on sip_registrations (sip_username)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sr_sip_realm on sip_registrations (sip_realm)&quot;, NULL, NULL, NULL);
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_call_id on sip_subscriptions (call_id)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_hostname on sip_subscriptions (hostname)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_hostname on sip_subscriptions (network_ip)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_sip_user on sip_subscriptions (sip_user)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_sip_host on sip_subscriptions (sip_host)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_presence_hosts on sip_subscriptions (presence_hosts)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_event on sip_subscriptions (event)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_proto on sip_subscriptions (proto)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_sub_to_user on sip_subscriptions (sub_to_user)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists ss_sub_to_host on sip_subscriptions (sub_to_host)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists ss_call_id on sip_subscriptions (call_id)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_hostname on sip_subscriptions (hostname)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_hostname on sip_subscriptions (network_ip)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_sip_user on sip_subscriptions (sip_user)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_sip_host on sip_subscriptions (sip_host)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_presence_hosts on sip_subscriptions (presence_hosts)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_event on sip_subscriptions (event)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_proto on sip_subscriptions (proto)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_sub_to_user on sip_subscriptions (sub_to_user)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists ss_sub_to_host on sip_subscriptions (sub_to_host)&quot;, NULL, NULL, NULL);
</ins><span class="cx"> 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sd_uuid on sip_dialogs (uuid)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sd_hostname on sip_dialogs (hostname)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sd_hostname on sip_dialogs (contact)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sd_hostname on sip_dialogs (presence_id)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sd_hostname on sip_dialogs (presence_data)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists sd_uuid on sip_dialogs (uuid)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sd_hostname on sip_dialogs (hostname)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sd_hostname on sip_dialogs (contact)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sd_hostname on sip_dialogs (presence_id)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sd_hostname on sip_dialogs (presence_data)&quot;, NULL, NULL, NULL);
</ins><span class="cx"> 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sp_hostname on sip_presence (hostname)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists sp_hostname on sip_presence (hostname)&quot;, NULL, NULL, NULL);
</ins><span class="cx"> 
</span><del>-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sa_nonce on sip_authentication (nonce)&quot;, NULL, NULL, NULL);
-                switch_core_db_exec(profile-&gt;master_db, &quot;create index if not exists sa_hostname on sip_authentication (hostname)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists sa_nonce on sip_authentication (nonce)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sa_hostname on sip_authentication (hostname)&quot;, NULL, NULL, NULL);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (switch_odbc_available() &amp;&amp; profile-&gt;odbc_dsn) {
</span><span class="cx">                 return profile-&gt;master_odbc ? 1 : 0;
</span><span class="cx">         }
</span><ins>+        
+        if (db) {
+                switch_core_db_close(db);
+                return 1;
+        } else {
+                return 0;
+        }
</ins><span class="cx"> 
</span><del>-        return profile-&gt;master_db ? 1 : 0;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void sofia_glue_sql_close(sofia_profile_t *profile)
</span><span class="lines">@@ -3959,8 +3970,25 @@
</span><span class="cx">         if (switch_odbc_available() &amp;&amp; profile-&gt;master_odbc) {
</span><span class="cx">                 switch_odbc_handle_destroy(&amp;profile-&gt;master_odbc);
</span><span class="cx">         } else {
</span><del>-                switch_core_db_close(profile-&gt;master_db);
-                profile-&gt;master_db = NULL;
</del><ins>+                switch_hash_index_t *hi;
+                const void *var;
+                void *val;
+                sofia_cache_db_handle_t *dbh = NULL;
+
+                switch_mutex_lock(profile-&gt;ireg_mutex);
+        top:
+        for (hi = switch_hash_first(NULL, profile-&gt;db_hash); hi; hi = switch_hash_next(hi)) {
+                        switch_hash_this(hi, &amp;var, NULL, &amp;val);
+            if ((dbh = (sofia_cache_db_handle_t *) val)) {
+                                switch_core_db_close(dbh-&gt;db);
+                                dbh-&gt;db = NULL;
+                                switch_core_hash_delete(profile-&gt;db_hash, (char *)var);
+
+                                goto top;
+                        }
+                }
+                switch_mutex_unlock(profile-&gt;ireg_mutex);
+
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -3988,7 +4016,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (status != SWITCH_STATUS_SUCCESS) {
</span><del>-                sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile-&gt;ireg_mutex);
</del><ins>+                sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_safe_free(d_sql);
</span><span class="lines">@@ -3998,8 +4026,34 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex)
</del><ins>+switch_core_db_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
</ins><span class="cx"> {
</span><ins>+        switch_thread_id_t self = switch_thread_self();
+        char thread_str[256] = &quot;&quot;;
+        switch_core_db_t *db = NULL;
+        sofia_cache_db_handle_t *dbh = NULL;
+
+        snprintf(thread_str, sizeof(thread_str) - 1, &quot;%lu&quot;, (unsigned long)(intptr_t)self);
+
+        switch_mutex_lock(profile-&gt;ireg_mutex);
+        if ((dbh = switch_core_hash_find(profile-&gt;db_hash, thread_str))) {
+                db = dbh-&gt;db;
+        } else {
+                dbh = switch_core_alloc(profile-&gt;pool, sizeof(*dbh));
+                dbh-&gt;db = switch_core_db_open_file(profile-&gt;dbname);
+                dbh-&gt;last_used = switch_epoch_time_now(NULL);
+                switch_core_hash_insert(profile-&gt;db_hash, thread_str, dbh);
+                db = dbh-&gt;db;
+        }
+        switch_mutex_unlock(profile-&gt;ireg_mutex);
+
+        return db;
+}
+
+
+
+void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex)
+{
</ins><span class="cx">         switch_core_db_t *db;
</span><span class="cx"> 
</span><span class="cx">         if (mutex) {
</span><span class="lines">@@ -4022,24 +4076,18 @@
</span><span class="cx">         } else {
</span><span class="cx">                 char *errmsg;
</span><span class="cx"> 
</span><del>-                if (master) {
-                        db = profile-&gt;master_db;
-                } else {
-                        if (!(db = switch_core_db_open_file(profile-&gt;dbname))) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB %s\n&quot;, profile-&gt;dbname);
-                                goto end;
-                        }
</del><ins>+                
+                if (!(db = sofia_glue_get_db_handle(profile))) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB %s\n&quot;, profile-&gt;dbname);
+                        goto end;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 switch_core_db_exec(db, sql, NULL, NULL, &amp;errmsg);
</span><ins>+
</ins><span class="cx">                 if (errmsg) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;SQL ERR [%s]\n%s\n&quot;, errmsg, sql);
</span><span class="cx">                         switch_core_db_free(errmsg);
</span><span class="cx">                 }
</span><del>-
-                if (!master) {
-                        switch_core_db_close(db);
-                }
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">   end:
</span><span class="lines">@@ -4049,7 +4097,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
</span><del>-                                                                                          switch_bool_t master, switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
</del><ins>+                                                                                          switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
</ins><span class="cx"> {
</span><span class="cx">         switch_bool_t ret = SWITCH_FALSE;
</span><span class="cx">         switch_core_db_t *db;
</span><span class="lines">@@ -4066,25 +4114,18 @@
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;ODBC IS NOT AVAILABLE!\n&quot;);
</span><span class="cx">         } else {
</span><span class="cx"> 
</span><del>-                if (master) {
-                        db = profile-&gt;master_db;
-                } else {
-                        if (!(db = switch_core_db_open_file(profile-&gt;dbname))) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB %s\n&quot;, profile-&gt;dbname);
-                                goto end;
-                        }
</del><ins>+                if (!(db = sofia_glue_get_db_handle(profile))) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB %s\n&quot;, profile-&gt;dbname);
+                        goto end;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx">                 switch_core_db_exec(db, sql, callback, pdata, &amp;errmsg);
</span><span class="cx"> 
</span><span class="cx">                 if (errmsg) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;SQL ERR: [%s] %s\n&quot;, sql, errmsg);
</span><span class="cx">                         free(errmsg);
</span><span class="cx">                 }
</span><del>-
-                if (!master &amp;&amp; db) {
-                        switch_core_db_close(db);
-                }
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">   end:
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_presencec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -190,7 +190,7 @@
</span><span class="cx">                         }
</span><span class="cx">                         helper.profile = profile;
</span><span class="cx">                         helper.event = NULL;
</span><del>-                        if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_presence_sub_callback, &amp;helper) != SWITCH_TRUE) {
</del><ins>+                        if (sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_sub_callback, &amp;helper) != SWITCH_TRUE) {
</ins><span class="cx">                                 continue;
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="lines">@@ -202,13 +202,13 @@
</span><span class="cx"> void sofia_presence_establish_presence(sofia_profile_t *profile)
</span><span class="cx"> {
</span><span class="cx"> 
</span><del>-        if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex,
</del><ins>+        if (sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex,
</ins><span class="cx">                                                                                 &quot;select sip_user,sip_host,'Registered','unknown','' from sip_registrations&quot;,
</span><span class="cx">                                                                                 sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
</span><span class="cx">                 return;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex,
</del><ins>+        if (sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex,
</ins><span class="cx">                                                                                 &quot;select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions &quot;
</span><span class="cx">                                                                                 &quot;where proto='ext' or proto='user' or proto='conf'&quot;, sofia_presence_resub_callback, profile) != SWITCH_TRUE) {
</span><span class="cx">                 return;
</span><span class="lines">@@ -337,7 +337,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (sql) {
</span><del>-                sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_presence_mwi_callback, &amp;h);
</del><ins>+                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_mwi_callback, &amp;h);
</ins><span class="cx">                 free(sql);
</span><span class="cx">                 sql = NULL;
</span><span class="cx">                 
</span><span class="lines">@@ -355,7 +355,7 @@
</span><span class="cx"> 
</span><span class="cx">         if (sql) {
</span><span class="cx">                 switch_assert(sql != NULL);
</span><del>-                sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_presence_mwi_callback2, &amp;h);
</del><ins>+                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_mwi_callback2, &amp;h);
</ins><span class="cx">                 free(sql);
</span><span class="cx">                 sql = NULL;
</span><span class="cx">         }
</span><span class="lines">@@ -456,7 +456,7 @@
</span><span class="cx">                         }
</span><span class="cx">                         helper.profile = profile;
</span><span class="cx">                         helper.event = NULL;
</span><del>-                        sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_presence_sub_callback, &amp;helper);
</del><ins>+                        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_sub_callback, &amp;helper);
</ins><span class="cx">                 }
</span><span class="cx">                 switch_mutex_unlock(mod_sofia_globals.hash_mutex);
</span><span class="cx">                 free(sql);
</span><span class="lines">@@ -534,7 +534,7 @@
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;%s DUMP PRESENCE_PROBE_SQL:\n%s\n&quot;, profile-&gt;name, sql);
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><del>-                                sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_presence_resub_callback, profile);
</del><ins>+                                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_resub_callback, profile);
</ins><span class="cx">                                 if (mod_sofia_globals.debug_presence &gt; 0) {
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;%s END_PRESENCE_PROBE_SQL\n\n&quot;, profile-&gt;name);
</span><span class="cx">                                 }
</span><span class="lines">@@ -573,7 +573,6 @@
</span><span class="cx">                         }
</span><span class="cx">                         continue;
</span><span class="cx">                 }
</span><del>-                
</del><span class="cx"> 
</span><span class="cx">                 if ((sql = switch_mprintf(
</span><span class="cx">                                                          
</span><span class="lines">@@ -615,7 +614,7 @@
</span><span class="cx">                                 free(buf);
</span><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        sofia_glue_execute_sql_callback(profile, SWITCH_FALSE,
</del><ins>+                        sofia_glue_execute_sql_callback(profile,
</ins><span class="cx">                                                                                         NULL, sql, sofia_presence_sub_callback, &amp;helper);
</span><span class="cx"> 
</span><span class="cx">                         if (mod_sofia_globals.debug_presence &gt; 0) {
</span><span class="lines">@@ -1764,7 +1763,7 @@
</span><span class="cx">                                                                   &quot;full_via,expires,user_agent,accept,profile_name,network_ip&quot;
</span><span class="cx">                                                                   &quot; from sip_subscriptions where sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')&quot;, 
</span><span class="cx">                                                                   to_host, to_user, to_host, to_host))) {
</span><del>-                        sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
</del><ins>+                        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
</ins><span class="cx">                         
</span><span class="cx">                         switch_safe_free(sql);
</span><span class="cx">                 }
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_regc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -521,7 +521,7 @@
</span><span class="cx">         switch_safe_free(sqlextra);
</span><span class="cx">         
</span><span class="cx">         switch_mutex_lock(profile-&gt;ireg_mutex);
</span><del>-        sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, profile);
</del><ins>+        sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile);
</ins><span class="cx">         switch_mutex_unlock(profile-&gt;ireg_mutex);
</span><span class="cx">         switch_safe_free(sql);
</span><span class="cx">         
</span><span class="lines">@@ -543,11 +543,6 @@
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB %s\n&quot;, profile-&gt;dbname);
</span><span class="cx">                         return;
</span><span class="cx">                 }
</span><del>-        } else {
-                if (!profile-&gt;master_db) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Opening DB %s\n&quot;, profile-&gt;dbname);
-                        return;
-                }
</del><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_lock(profile-&gt;ireg_mutex);
</span><span class="lines">@@ -562,7 +557,7 @@
</span><span class="cx">                                                 &quot;,%d from sip_registrations where expires &gt; 0&quot;, reboot);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, profile);
</del><ins>+        sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_del_callback, profile);
</ins><span class="cx">         if (now) {
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_registrations where expires &gt; 0 and expires &lt;= %ld and hostname='%s'&quot;, 
</span><span class="cx">                                                 (long) now, mod_sofia_globals.hostname);
</span><span class="lines">@@ -570,7 +565,7 @@
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_registrations where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
</del><ins>+        sofia_glue_actually_execute_sql(profile, sql, NULL);
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -579,12 +574,12 @@
</span><span class="cx">                                                 &quot;and profile_name='%s' and expires &lt;= %ld&quot;, 
</span><span class="cx">                                                 mod_sofia_globals.hostname, profile-&gt;name, (long) now);
</span><span class="cx">         
</span><del>-                sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_sla_dialog_del_callback, profile);
</del><ins>+                sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sla_dialog_del_callback, profile);
</ins><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_registrations where expires &gt; 0 and hostname='%s' and expires &lt;= %ld&quot;, 
</span><span class="cx">                                                 mod_sofia_globals.hostname, (long) now);
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-                sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
</del><ins>+                sofia_glue_actually_execute_sql(profile, sql, NULL);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -595,7 +590,7 @@
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_presence where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
</del><ins>+        sofia_glue_actually_execute_sql(profile, sql, NULL);
</ins><span class="cx"> 
</span><span class="cx">         if (now) {
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_authentication where expires &gt; 0 and expires &lt;= %ld and hostname='%s'&quot;, 
</span><span class="lines">@@ -604,7 +599,7 @@
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_authentication where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
</del><ins>+        sofia_glue_actually_execute_sql(profile, sql, NULL);
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -615,7 +610,7 @@
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;select call_id from sip_subscriptions where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_sub_del_callback, profile);
</del><ins>+        sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile);
</ins><span class="cx"> 
</span><span class="cx">         if (now) {
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_subscriptions where expires &gt; 0 and expires &lt;= %ld and hostname='%s'&quot;, 
</span><span class="lines">@@ -624,7 +619,7 @@
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;delete from sip_subscriptions where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
</del><ins>+        sofia_glue_actually_execute_sql(profile, sql, NULL);
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (now &amp;&amp; sofia_test_pflag(profile, PFLAG_NAT_OPTIONS_PING)) {
</span><span class="lines">@@ -633,7 +628,7 @@
</span><span class="cx">                                                 &quot; from sip_registrations where (status like '%%AUTO-NAT%%' &quot;
</span><span class="cx">                                                 &quot;or status like '%%UDP-NAT%%') and hostname='%s'&quot;, mod_sofia_globals.hostname);
</span><span class="cx"> 
</span><del>-                sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_nat_callback, profile);
</del><ins>+                sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_nat_callback, profile);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_unlock(profile-&gt;ireg_mutex);
</span><span class="lines">@@ -661,7 +656,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-        sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_reg_find_callback, &amp;cbt);
</del><ins>+        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_reg_find_callback, &amp;cbt);
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (cbt.matches) {
</span><span class="lines">@@ -686,9 +681,10 @@
</span><span class="cx">                                                  switch_epoch_time_now(NULL) + (profile-&gt;nonce_ttl ? profile-&gt;nonce_ttl : DEFAULT_NONCE_TTL), 
</span><span class="cx">                                                  profile-&gt;name, mod_sofia_globals.hostname);
</span><span class="cx">         switch_assert(sql != NULL);
</span><del>-        sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile-&gt;ireg_mutex);
</del><ins>+        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
</ins><span class="cx">         switch_safe_free(sql);
</span><span class="cx"> 
</span><ins>+        //auth_str = switch_mprintf(&quot;Digest realm=\&quot;%q\&quot;, nonce=\&quot;%q\&quot;,%s algorithm=MD5, qop=\&quot;auth\&quot;&quot;, realm, uuid_str, stale ? &quot; stale=true,&quot; : &quot;&quot;);
</ins><span class="cx">         auth_str = switch_mprintf(&quot;Digest realm=\&quot;%q\&quot;, nonce=\&quot;%q\&quot;,%s algorithm=MD5, qop=\&quot;auth\&quot;&quot;, realm, uuid_str, stale ? &quot; stale=\&quot;true\&quot;,&quot; : &quot;&quot;);
</span><span class="cx"> 
</span><span class="cx">         if (regtype == REG_REGISTER) {
</span><span class="lines">@@ -741,6 +737,7 @@
</span><span class="cx">         char *path_val = NULL;
</span><span class="cx">         switch_event_t *auth_params = NULL;
</span><span class="cx">         int r = 0;
</span><ins>+        long reg_count = 0;
</ins><span class="cx"> 
</span><span class="cx">         /* all callers must confirm that sip, sip-&gt;sip_request and sip-&gt;sip_contact are not NULL */
</span><span class="cx">         switch_assert(sip != NULL &amp;&amp; sip-&gt;sip_contact != NULL &amp;&amp; sip-&gt;sip_request != NULL);
</span><span class="lines">@@ -896,7 +893,7 @@
</span><span class="cx">         if (authorization) {
</span><span class="cx">                 char *v_contact_str;
</span><span class="cx">                 if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, sip-&gt;sip_request-&gt;rq_method_name,
</span><del>-                                                                                         key, keylen, network_ip, v_event, exptime, regtype, to_user, &amp;auth_params)) == AUTH_STALE) {
</del><ins>+                                                                                         key, keylen, network_ip, v_event, exptime, regtype, to_user, &amp;auth_params, &amp;reg_count)) == AUTH_STALE) {
</ins><span class="cx">                         stale = 1;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -1131,16 +1128,21 @@
</span><span class="cx">                         switch_event_fire(&amp;event);
</span><span class="cx">                 }
</span><span class="cx"> #else
</span><del>-                if (switch_event_create(&amp;event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
-                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;proto&quot;, &quot;sip&quot;);
-                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;login&quot;, profile-&gt;url);
-                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;rpid&quot;, rpid);
-                        switch_event_add_header(event, SWITCH_STACK_BOTTOM, &quot;from&quot;, &quot;%s@%s&quot;, to_user, reg_host);
-                        switch_event_add_header(event, SWITCH_STACK_BOTTOM, &quot;to&quot;, &quot;%s@%s&quot;, to_user, reg_host);
-                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;status&quot;, &quot;Registered&quot;);
-                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;event_subtype&quot;, &quot;probe&quot;);
-                        switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;event_type&quot;, &quot;presence&quot;);
-                        switch_event_fire(&amp;event);
</del><ins>+
+                if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) || 
+                        (reg_count == 1 &amp;&amp; sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) {
+
+                        if (switch_event_create(&amp;event, SWITCH_EVENT_PRESENCE_PROBE) == SWITCH_STATUS_SUCCESS) {
+                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;proto&quot;, &quot;sip&quot;);
+                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;login&quot;, profile-&gt;url);
+                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;rpid&quot;, rpid);
+                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, &quot;from&quot;, &quot;%s@%s&quot;, to_user, reg_host);
+                                switch_event_add_header(event, SWITCH_STACK_BOTTOM, &quot;to&quot;, &quot;%s@%s&quot;, to_user, reg_host);
+                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;status&quot;, &quot;Registered&quot;);
+                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;event_subtype&quot;, &quot;probe&quot;);
+                                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;event_type&quot;, &quot;presence&quot;);
+                                switch_event_fire(&amp;event);
+                        }
</ins><span class="cx">                 }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -1213,28 +1215,15 @@
</span><span class="cx">         if (regtype == REG_REGISTER) {
</span><span class="cx">                 char exp_param[128] = &quot;&quot;;
</span><span class="cx">                 char date[80] = &quot;&quot;;
</span><del>-                long nc_long = 0;                
-                
</del><ins>+
</ins><span class="cx">                 s_event = NULL;
</span><span class="cx"> 
</span><span class="cx">                 if (exptime) {
</span><span class="cx">                         switch_snprintf(exp_param, sizeof(exp_param), &quot;expires=%ld&quot;, exptime);
</span><span class="cx">                         sip_contact_add_param(nua_handle_home(nh), sip-&gt;sip_contact, exp_param);
</span><span class="cx">                         
</span><del>-                        if (auth_params &amp;&amp; sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER)) {
-                                const char *nc = NULL;
-
-                                if ((nc = switch_event_get_header(auth_params, &quot;sip_auth_nc&quot;))) {
-                                        nc_long = strtoul(nc, 0, 16);
-                                } else {
-                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, 
-                                                                          &quot;No nonce count, cannot determine if this was the first register, sending notify implicitly.\n&quot;);
-                                        nc_long = 1;
-                                }
-                        }
-                        
</del><span class="cx">                         if (sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_REGISTER) || 
</span><del>-                                (nc_long == 1 &amp;&amp; sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) {
</del><ins>+                                (reg_count == 1 &amp;&amp; sofia_test_pflag(profile, PFLAG_MESSAGE_QUERY_ON_FIRST_REGISTER))) {
</ins><span class="cx">                                 if (switch_event_create(&amp;s_event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                                         switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, &quot;Message-Account&quot;, &quot;sip:%s@%s&quot;, mwi_user, mwi_host);
</span><span class="cx">                                         switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, &quot;VM-Sofia-Profile&quot;, profile-&gt;name);
</span><span class="lines">@@ -1263,13 +1252,9 @@
</span><span class="cx">                 if (s_event) {
</span><span class="cx">                         switch_event_fire(&amp;s_event);
</span><span class="cx">                 }
</span><del>-
-                if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
-                        char *full_contact = sip_header_as_string(nua_handle_home(nh), (void *) sip-&gt;sip_contact);
-                        if (full_contact &amp;&amp; switch_stristr(&quot;SUBSCRIBE&quot;, full_contact)) {
-                                sofia_sla_handle_register(nua, profile, sip, exptime, full_contact);
-                                su_free(nua_handle_home(nh), full_contact);
-                        }
</del><ins>+                
+                if (contact_str &amp;&amp; sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE) &amp;&amp; sofia_sla_supported(sip)) {
+                        sofia_sla_handle_register(nua, profile, sip, exptime, contact_str);
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 switch_goto_int(r, 1, end);
</span><span class="lines">@@ -1594,6 +1579,20 @@
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+typedef struct {
+        char *nonce;
+        switch_size_t nplen;
+        int last_nc;
+} nonce_cb_t;
+
+static int sofia_reg_nonce_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+        nonce_cb_t *cb = (nonce_cb_t *) pArg;
+        switch_copy_string(cb-&gt;nonce, argv[0], cb-&gt;nplen);
+        cb-&gt;last_nc = zstr(argv[1]) ? 0 : atoi(argv[1]);
+        return 0;
+}
+
</ins><span class="cx"> auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, 
</span><span class="cx">                                                                 sip_authorization_t const *authorization, 
</span><span class="cx">                                                                 sip_t const *sip, 
</span><span class="lines">@@ -1606,7 +1605,8 @@
</span><span class="cx">                                                                 sofia_regtype_t 
</span><span class="cx">                                                                 regtype, 
</span><span class="cx">                                                                 const char *to_user,
</span><del>-                                                                switch_event_t **auth_params)
</del><ins>+                                                                switch_event_t **auth_params,
+                                                                long *reg_count)
</ins><span class="cx"> {
</span><span class="cx">         int indexnum;
</span><span class="cx">         const char *cur;
</span><span class="lines">@@ -1626,6 +1626,7 @@
</span><span class="cx">         char *domain_name = NULL;
</span><span class="cx">         switch_event_t *params = NULL;
</span><span class="cx">         const char *auth_acl = NULL;
</span><ins>+        long ncl = 0;
</ins><span class="cx"> 
</span><span class="cx">         username = realm = nonce = uri = qop = cnonce = nc = response = NULL;
</span><span class="cx"> 
</span><span class="lines">@@ -1684,20 +1685,35 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (zstr(np)) {
</span><ins>+                nonce_cb_t cb = { 0 };
+                long nc_long = 0;
</ins><span class="cx">                 first = 1;
</span><ins>+                
</ins><span class="cx">                 if (nc) {
</span><del>-                        sql = switch_mprintf(&quot;select nonce from sip_authentication where nonce='%q' and last_nc &lt; %lu&quot;, nonce, strtoul(nc, 0, 16));
</del><ins>+                        nc_long = strtoul(nc, 0, 16);
+                        sql = switch_mprintf(&quot;select nonce,last_nc from sip_authentication where nonce='%q' and last_nc &lt; %lu&quot;, nonce, nc_long);
</ins><span class="cx">                 } else {
</span><span class="cx">                         sql = switch_mprintf(&quot;select nonce from sip_authentication where nonce='%q'&quot;, nonce);
</span><span class="cx">                 }
</span><span class="cx"> 
</span><ins>+                cb.nonce = np;
+                cb.nplen = nplen;
+                
</ins><span class="cx">                 switch_assert(sql != NULL);
</span><del>-                if (!sofia_glue_execute_sql2str(profile, profile-&gt;ireg_mutex, sql, np, nplen)) {
-                        free(sql);
</del><ins>+                sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_reg_nonce_callback, &amp;cb);
+                free(sql);
+
+                //if (!sofia_glue_execute_sql2str(profile, profile-&gt;ireg_mutex, sql, np, nplen)) {
+                if (zstr(np)) {
+                        sql = switch_mprintf(&quot;delete from sip_authentication where nonce='%q'&quot;, nonce);
+                        sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">                         ret = AUTH_STALE;
</span><span class="cx">                         goto end;
</span><span class="cx">                 }
</span><del>-                free(sql);
</del><ins>+
+                if (reg_count) {
+                        *reg_count = cb.last_nc + 1;
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         switch_event_create(&amp;params, SWITCH_EVENT_REQUEST_PARAMS);
</span><span class="lines">@@ -2082,6 +2098,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (nc &amp;&amp; cnonce &amp;&amp; qop) {
</span><ins>+                ncl = strtoul(nc, 0, 16);
</ins><span class="cx"> 
</span><span class="cx"> #if defined(_WIN32) &amp;&amp; !defined(_WIN64)
</span><span class="cx"> #define        LL_FMT &quot;ll&quot;
</span><span class="lines">@@ -2089,10 +2106,10 @@
</span><span class="cx"> #define        LL_FMT &quot;l&quot;
</span><span class="cx"> #endif
</span><span class="cx">                 sql = switch_mprintf(&quot;update sip_authentication set expires='%&quot;LL_FMT&quot;u',last_nc=%lu where nonce='%s'&quot;, 
</span><del>-                                                         switch_epoch_time_now(NULL) + (profile-&gt;nonce_ttl ? profile-&gt;nonce_ttl : exptime + 10), strtoul(nc, 0, 16), nonce);
</del><ins>+                                                         switch_epoch_time_now(NULL) + (profile-&gt;nonce_ttl ? profile-&gt;nonce_ttl : exptime + 10), ncl, nonce);
</ins><span class="cx"> 
</span><span class="cx">                 switch_assert(sql != NULL);
</span><del>-                sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, profile-&gt;ireg_mutex);
</del><ins>+                sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
</ins><span class="cx">                 switch_safe_free(sql);
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -2112,6 +2129,18 @@
</span><span class="cx">         switch_safe_free(nc);
</span><span class="cx">         switch_safe_free(response);
</span><span class="cx"> 
</span><ins>+        if (reg_count &amp;&amp; !*reg_count) {
+                if (ret == AUTH_OK) {
+                        if (ncl) {
+                                *reg_count = ncl;
+                        } else {
+                                *reg_count = 1;
+                        }
+                } else {
+                        *reg_count = 0;
+                }
+        }
+
</ins><span class="cx">         return ret;
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_slac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c (15440 => 15441)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c        2009-11-12 03:48:07 UTC (rev 15440)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c        2009-11-12 03:52:07 UTC (rev 15441)
</span><span class="lines">@@ -49,6 +49,25 @@
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+int sofia_sla_supported(sip_t const *sip)
+{
+        if (sip &amp;&amp; sip-&gt;sip_user_agent &amp;&amp; sip-&gt;sip_user_agent-&gt;g_string) {
+                const char *ua = sip-&gt;sip_user_agent-&gt;g_string;
+
+                if (switch_stristr(&quot;polycom&quot;, ua)) {
+                        return 1;
+                }
+
+                if (switch_stristr(&quot;snom&quot;, ua)) {
+                        return 1;
+                }
+
+        }
+
+        return 0;
+}
+
+
</ins><span class="cx"> void sofia_sla_handle_register(nua_t *nua, sofia_profile_t *profile, sip_t const *sip, long exptime, const char *full_contact)
</span><span class="cx"> {
</span><span class="cx">         nua_handle_t *nh = NULL;
</span><span class="lines">@@ -60,12 +79,15 @@
</span><span class="cx">         sofia_transport_t transport = sofia_glue_url2transport(sip-&gt;sip_contact-&gt;m_url);
</span><span class="cx">         char network_ip[80];
</span><span class="cx">         int network_port = 0;
</span><ins>+        sofia_destination_t *dst;
+        char *route_uri = NULL;
+        char port_str[25] = &quot;&quot;;
</ins><span class="cx"> 
</span><span class="cx">         sofia_glue_get_addr(nua_current_request(nua), network_ip,  sizeof(network_ip), &amp;network_port);
</span><span class="cx"> 
</span><span class="cx">         sql = switch_mprintf(&quot;select call_id from sip_shared_appearance_dialogs where hostname='%q' and profile_name='%q' and contact_str='%q'&quot;, 
</span><span class="cx">                                                  mod_sofia_globals.hostname, profile-&gt;name, contact_str);
</span><del>-        sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, get_call_id_callback, &amp;sh);
</del><ins>+        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, get_call_id_callback, &amp;sh);
</ins><span class="cx"> 
</span><span class="cx">         free(sql);
</span><span class="cx">         
</span><span class="lines">@@ -85,21 +107,35 @@
</span><span class="cx">         nua_handle_bind(nh, &amp;mod_sofia_globals.keep_private);
</span><span class="cx"> 
</span><span class="cx">         switch_snprintf(exp_str, sizeof(exp_str), &quot;%ld&quot;, exptime + 30);
</span><ins>+
+        switch_snprintf(port_str, sizeof(port_str), &quot;:%ld&quot;, sofia_glue_transport_has_tls(transport) ? profile-&gt;tls_sip_port : profile-&gt;sip_port);
+
</ins><span class="cx">         if (sofia_glue_check_nat(profile, network_ip)) { 
</span><del>-                switch_snprintf(my_contact, sizeof(my_contact), &quot;&lt;sip:%s@%s;transport=%s&gt;;expires=%s&quot;, profile-&gt;sla_contact, 
-                                                profile-&gt;extsipip, sofia_glue_transport2str(transport), exp_str);
</del><ins>+                switch_snprintf(my_contact, sizeof(my_contact), &quot;&lt;sip:%s@%s%s;transport=%s&gt;;expires=%s&quot;, profile-&gt;sla_contact, 
+                                                profile-&gt;extsipip, port_str, sofia_glue_transport2str(transport), exp_str);
</ins><span class="cx">         } else {
</span><del>-                switch_snprintf(my_contact, sizeof(my_contact), &quot;&lt;sip:%s@%s;transport=%s&gt;;expires=%s&quot;, profile-&gt;sla_contact, 
-                                                profile-&gt;sipip, sofia_glue_transport2str(transport), exp_str);
</del><ins>+                switch_snprintf(my_contact, sizeof(my_contact), &quot;&lt;sip:%s@%s%s;transport=%s&gt;;expires=%s&quot;, profile-&gt;sla_contact, 
+                                                profile-&gt;sipip, port_str, sofia_glue_transport2str(transport), exp_str);
</ins><span class="cx">         }
</span><ins>+
+        dst = sofia_glue_get_destination((char*) full_contact);
+
+        if(dst-&gt;route_uri) {
+                route_uri = sofia_glue_strip_uri(dst-&gt;route_uri);
+        }
+
</ins><span class="cx">         nua_subscribe(nh,
</span><ins>+                                  TAG_IF(dst-&gt;route_uri, NUTAG_PROXY(route_uri)), TAG_IF(dst-&gt;route, SIPTAG_ROUTE_STR(dst-&gt;route)),
</ins><span class="cx">                                   SIPTAG_TO(sip-&gt;sip_to),
</span><span class="cx">                                   SIPTAG_FROM(sip-&gt;sip_to),
</span><span class="cx">                                   SIPTAG_CONTACT_STR(my_contact),
</span><span class="cx">                                   SIPTAG_EXPIRES_STR(exp_str),
</span><del>-                                  SIPTAG_EVENT_STR(&quot;dialog;sla&quot;),        /* some phones want ;include-session-description too? */
</del><ins>+                                  SIPTAG_EVENT_STR(&quot;dialog;sla;include-session-description&quot;),
+                                  SIPTAG_ACCEPT_STR(&quot;application/dialog-info+xml&quot;),
</ins><span class="cx">                                   TAG_NULL());
</span><span class="cx"> 
</span><ins>+        sofia_glue_free_destination(dst);
+
</ins><span class="cx">         free(contact_str);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -119,6 +155,7 @@
</span><span class="cx">         char network_ip[80];
</span><span class="cx">         int network_port = 0;
</span><span class="cx">         sofia_transport_t transport = sofia_glue_url2transport(sip-&gt;sip_contact-&gt;m_url);
</span><ins>+        char *pl;
</ins><span class="cx"> 
</span><span class="cx">         sofia_glue_get_addr(nua_current_request(nua), network_ip,  sizeof(network_ip), &amp;network_port);
</span><span class="cx">         /*
</span><span class="lines">@@ -194,6 +231,21 @@
</span><span class="cx">                                 /*  sofia_presence says something about needing TAG_IF(sticky, NUTAG_PROXY(sticky)) for NAT stuff? */
</span><span class="cx">                                 TAG_END());
</span><span class="cx"> 
</span><ins>+
+        
+        pl = switch_mprintf(&quot;&lt;?xml version=\&quot;1.0\&quot;?&gt;\n&quot;
+                                                &quot;&lt;dialog-info xmlns=\&quot;urn:ietf:params:xml:ns:dialog-info\&quot; &quot;
+                                                &quot;version=\&quot;0\&quot; state=\&quot;full\&quot; entity=\&quot;%s\&quot;&gt;&lt;/dialog-info&gt;\n&quot;, aor);
+        
+        nua_notify(nh,
+                           SIPTAG_SUBSCRIPTION_STATE_STR(&quot;active;expires=300&quot;), /* XXX MTK FIXME - this is totally fake calculation */
+                           TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
+                           SIPTAG_CONTENT_TYPE_STR(&quot;application/dialog-info+xml&quot;),        /* could've just kept the type from the payload */
+                           SIPTAG_PAYLOAD_STR(pl),
+                           TAG_END());
+        
+        
+
</ins><span class="cx">         switch_safe_free(aor);
</span><span class="cx">         switch_safe_free(subscriber);
</span><span class="cx">         switch_safe_free(route_uri);
</span><span class="lines">@@ -295,7 +347,7 @@
</span><span class="cx">                 helper.payload = sip-&gt;sip_payload-&gt;pl_data;         /* could just send the WHOLE payload. you'd get the type that way. */
</span><span class="cx"> 
</span><span class="cx">                 /* which mutex if any is correct to hold in this callback? XXX MTK FIXME */
</span><del>-                sofia_glue_execute_sql_callback(profile, SWITCH_FALSE, profile-&gt;ireg_mutex, sql, sofia_sla_sub_callback, &amp;helper);
</del><ins>+                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_sla_sub_callback, &amp;helper);
</ins><span class="cx"> 
</span><span class="cx">                 switch_safe_free(sql);
</span><span class="cx">                 switch_safe_free(aor);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>