<!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][16223] </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=16223">16223</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2010-01-08 18:34:17 -0600 (Fri, 08 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>tweak sla presence code</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>
</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 (16222 => 16223)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2010-01-08 22:51:16 UTC (rev 16222)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2010-01-09 00:34:17 UTC (rev 16223)
</span><span class="lines">@@ -365,7 +365,7 @@
</span><span class="cx">         if (session &amp;&amp; tech_pvt-&gt;profile-&gt;pres_type) {
</span><span class="cx">                 char *sql = switch_mprintf(&quot;delete from sip_dialogs where call_id='%q'&quot;, tech_pvt-&gt;call_id);
</span><span class="cx">                 switch_assert(sql);
</span><del>-                sofia_glue_execute_sql(tech_pvt-&gt;profile, &amp;sql, SWITCH_TRUE);
</del><ins>+                sofia_glue_execute_sql_now(tech_pvt-&gt;profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         if (tech_pvt-&gt;kick &amp;&amp; (a_session = switch_core_session_locate(tech_pvt-&gt;kick))) {
</span><span class="lines">@@ -1215,7 +1215,7 @@
</span><span class="cx">                                                                          &quot;where uuid='%s';\n&quot;, switch_str_nil(presence_id), switch_str_nil(presence_data), 
</span><span class="cx">                                                                          switch_core_session_get_uuid(session));
</span><span class="cx">                                 switch_assert(sql);
</span><del>-                                sofia_glue_execute_sql(tech_pvt-&gt;profile, &amp;sql, SWITCH_TRUE);
</del><ins>+                                sofia_glue_execute_sql_now(tech_pvt-&gt;profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">                         }
</span><span class="cx"> 
</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 (16222 => 16223)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-01-08 22:51:16 UTC (rev 16222)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-01-09 00:34:17 UTC (rev 16223)
</span><span class="lines">@@ -188,6 +188,7 @@
</span><span class="cx">         PFLAG_UUID_AS_CALLID,
</span><span class="cx">         PFLAG_SCROOGE,
</span><span class="cx">         PFLAG_MANAGE_SHARED_APPEARANCE,
</span><ins>+        PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO,
</ins><span class="cx">         PFLAG_DISABLE_SRV,
</span><span class="cx">         PFLAG_DISABLE_NAPTR,
</span><span class="cx">         PFLAG_AUTOFLUSH,
</span><span class="lines">@@ -790,6 +791,7 @@
</span><span class="cx"> void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
</span><span class="cx"> void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
</span><span class="cx"> void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
</span><ins>+void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
</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></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (16222 => 16223)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-01-08 22:51:16 UTC (rev 16222)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-01-09 00:34:17 UTC (rev 16223)
</span><span class="lines">@@ -2774,7 +2774,10 @@
</span><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE);
</span><span class="cx">                                                         profile-&gt;pres_type = PRES_TYPE_FULL;
</span><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MULTIREG);
</span><ins>+
+                                                } else if (!strcasecmp(val, &quot;sylantro&quot;)) {
</ins><span class="cx">                                                         profile-&gt;sla_contact = switch_core_sprintf(profile-&gt;pool, &quot;sla-agent&quot;);
</span><ins>+                                                        sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO);
</ins><span class="cx">                                                 }
</span><span class="cx">                                         } else if (!strcasecmp(var, &quot;disable-srv&quot;)) {
</span><span class="cx">                                                 if (switch_true(val)) {
</span><span class="lines">@@ -3428,7 +3431,7 @@
</span><span class="cx">                                 if (sip &amp;&amp; 
</span><span class="cx">                                         sip-&gt;sip_from &amp;&amp; sip-&gt;sip_from-&gt;a_url &amp;&amp; sip-&gt;sip_from-&gt;a_url-&gt;url_user &amp;&amp; sip-&gt;sip_from-&gt;a_url-&gt;url_host &amp;&amp;
</span><span class="cx">                                         sip-&gt;sip_to &amp;&amp; sip-&gt;sip_to-&gt;a_url &amp;&amp; sip-&gt;sip_to-&gt;a_url-&gt;url_user &amp;&amp; sip-&gt;sip_to-&gt;a_url-&gt;url_host) {
</span><del>-                                        sql = switch_mprintf(&quot;select 'appearance-index=1' from sip_subscriptions where hostname='%q' and event='call-info' and &quot;
</del><ins>+                                        sql = switch_mprintf(&quot;select 'appearance-index=1' from sip_subscriptions where expires &gt; -1 &amp;&amp; hostname='%q' and event='call-info' and &quot;
</ins><span class="cx">                                                                                  &quot;sub_to_user='%q' and sub_to_host='%q'&quot;, 
</span><span class="cx">                                                                                  mod_sofia_globals.hostname, sip-&gt;sip_to-&gt;a_url-&gt;url_user, sip-&gt;sip_from-&gt;a_url-&gt;url_host);
</span><span class="cx">                                         sofia_glue_execute_sql2str(profile, profile-&gt;ireg_mutex, sql, buf, sizeof(buf));
</span><span class="lines">@@ -3447,8 +3450,7 @@
</span><span class="cx">                                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;QUERY SQL %s\n&quot;, sql);
</span><span class="cx">                                                 }
</span><span class="cx">                                         
</span><del>-                                                sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
-                                                switch_safe_free(sql);
</del><ins>+                                                sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="lines">@@ -3729,7 +3731,8 @@
</span><span class="cx">                                         
</span><span class="cx">                                         switch_assert(sql);
</span><span class="cx"> 
</span><del>-                                        sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</del><ins>+                                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
+                                        switch_safe_free(sql);
</ins><span class="cx"> 
</span><span class="cx">                                 }                                
</span><span class="cx">                         } else if (status == 200 &amp;&amp; (profile-&gt;pres_type)) {
</span><span class="lines">@@ -3741,7 +3744,7 @@
</span><span class="cx">                                                                          &quot;where uuid='%s';\n&quot;, astate, switch_str_nil(presence_id), switch_str_nil(presence_data), 
</span><span class="cx">                                                                          switch_core_session_get_uuid(session));
</span><span class="cx">                                 switch_assert(sql);
</span><del>-                                sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</del><ins>+                                sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -6200,8 +6203,9 @@
</span><span class="cx"> 
</span><span class="cx">                         switch_assert(sql);
</span><span class="cx">                         
</span><del>-                        sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
-
</del><ins>+                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
+                        switch_safe_free(sql);
+                        
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if (is_nat) {
</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 (16222 => 16223)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2010-01-08 22:51:16 UTC (rev 16222)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2010-01-09 00:34:17 UTC (rev 16223)
</span><span class="lines">@@ -3831,8 +3831,9 @@
</span><span class="cx">         &quot;   contact         VARCHAR(255),\n&quot;
</span><span class="cx">         &quot;   presence_id     VARCHAR(255),\n&quot;
</span><span class="cx">         &quot;   presence_data   VARCHAR(255),\n&quot;
</span><del>-        &quot;   call_info  VARCHAR(255),\n&quot;
-        &quot;   call_info_state  VARCHAR(255)\n&quot;
</del><ins>+        &quot;   call_info       VARCHAR(255),\n&quot;
+        &quot;   call_info_state VARCHAR(255),\n&quot;
+        &quot;   expires         INTEGER default 0\n&quot;
</ins><span class="cx">                 &quot;);\n&quot;;
</span><span class="cx"> 
</span><span class="cx">         char sub_sql[] =
</span><span class="lines">@@ -3918,7 +3919,8 @@
</span><span class="cx">                         &quot;create index sd_hostname on sip_dialogs (hostname)&quot;,
</span><span class="cx">                         &quot;create index sd_presence_data on sip_dialogs (presence_data)&quot;,
</span><span class="cx">                         &quot;create index sd_call_info on sip_dialogs (call_info)&quot;,
</span><del>-                        &quot;create index sd_call_info on sip_dialogs (call_info_state)&quot;,
</del><ins>+                        &quot;create index sd_call_info_state on sip_dialogs (call_info_state)&quot;,
+                        &quot;create index sd_expires on sip_dialogs (expires)&quot;,
</ins><span class="cx">                         &quot;create index sp_hostname on sip_presence (hostname)&quot;,
</span><span class="cx">                         &quot;create index sa_nonce on sip_authentication (nonce)&quot;,
</span><span class="cx">                         &quot;create index sa_hostname on sip_authentication (hostname)&quot;,
</span><span class="lines">@@ -3988,7 +3990,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_dialogs where hostname='%q' and call_info_state like '%%'&quot;, mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_dialogs where hostname='%q' and expires &gt; 0&quot;, mod_sofia_globals.hostname);
</ins><span class="cx"> 
</span><span class="cx">                 if (switch_odbc_handle_exec(odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
</span><span class="cx">                         switch_odbc_handle_exec(odbc_dbh, &quot;DROP TABLE sip_dialogs&quot;, NULL);
</span><span class="lines">@@ -4055,7 +4057,7 @@
</span><span class="cx">                 switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_subscriptions&quot;, sub_sql);
</span><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><del>-                test_sql = switch_mprintf(&quot;delete from sip_dialogs where hostname='%q' and call_info_state like '%%'&quot;, mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_dialogs where hostname='%q' and expires &gt; 0&quot;, mod_sofia_globals.hostname);
</ins><span class="cx">                 switch_core_db_test_reactive(db, test_sql, &quot;DROP TABLE sip_dialogs&quot;, dialog_sql);
</span><span class="cx">                 free(test_sql);
</span><span class="cx"> 
</span><span class="lines">@@ -4133,7 +4135,8 @@
</span><span class="cx">                 switch_core_db_exec(db, &quot;create index if not exists sd_presence_id on sip_dialogs (presence_id)&quot;, NULL, NULL, NULL);
</span><span class="cx">                 switch_core_db_exec(db, &quot;create index if not exists sd_presence_data on sip_dialogs (presence_data)&quot;, NULL, NULL, NULL);
</span><span class="cx">                 switch_core_db_exec(db, &quot;create index if not exists sd_call_info on sip_dialogs (call_info)&quot;, NULL, NULL, NULL);
</span><del>-                switch_core_db_exec(db, &quot;create index if not exists sd_call_info on sip_dialogs (call_info_state)&quot;, NULL, NULL, NULL);
</del><ins>+                switch_core_db_exec(db, &quot;create index if not exists sd_call_info_state on sip_dialogs (call_info_state)&quot;, NULL, NULL, NULL);
+                switch_core_db_exec(db, &quot;create index if not exists sd_expires on sip_dialogs (expires)&quot;, NULL, NULL, NULL);
</ins><span class="cx"> 
</span><span class="cx">                 switch_core_db_exec(db, &quot;create index if not exists sp_hostname on sip_presence (hostname)&quot;, NULL, NULL, NULL);
</span><span class="cx"> 
</span><span class="lines">@@ -4189,7 +4192,16 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
+{
+        sofia_glue_actually_execute_sql(profile, *sqlp, profile-&gt;ireg_mutex);
+        if (sql_already_dynamic) {
+                switch_safe_free(*sqlp);
+        }
+        *sqlp = NULL;
+}
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> switch_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
</span><span class="cx"> {
</span><span class="cx">         switch_cache_db_connection_options_t options = { {0} };
</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 (16222 => 16223)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c        2010-01-08 22:51:16 UTC (rev 16222)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c        2010-01-09 00:34:17 UTC (rev 16223)
</span><span class="lines">@@ -194,7 +194,7 @@
</span><span class="cx">         if ((sql = switch_mprintf(
</span><span class="cx">                                                           &quot;select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,&quot;
</span><span class="cx">                                                           &quot;full_via,expires,user_agent,accept,profile_name,network_ip&quot;
</span><del>-                                                          &quot;,-1,'unavailable','unavailable' from sip_subscriptions where event='presence' and hostname='%q'&quot;, 
</del><ins>+                                                          &quot;,-1,'unavailable','unavailable' from sip_subscriptions where expires &gt; -1 and event='presence' and hostname='%q'&quot;, 
</ins><span class="cx">                                                           mod_sofia_globals.hostname))) {
</span><span class="cx">                 switch_mutex_lock(mod_sofia_globals.hash_mutex);
</span><span class="cx">                 for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) {
</span><span class="lines">@@ -227,7 +227,8 @@
</span><span class="cx"> 
</span><span class="cx">         if (sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex,
</span><span class="cx">                                                                                 &quot;select sub_to_user,sub_to_host,'Online','unknown',proto from sip_subscriptions &quot;
</span><del>-                                                                                &quot;where proto='ext' or proto='user' or proto='conf'&quot;, sofia_presence_resub_callback, &amp;h) != SWITCH_TRUE) {
</del><ins>+                                                                                &quot;where expires &gt; -1 and proto='ext' or proto='user' or proto='conf'&quot;, 
+                                                                                sofia_presence_resub_callback, &amp;h) != SWITCH_TRUE) {
</ins><span class="cx">                 return;
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="lines">@@ -341,13 +342,13 @@
</span><span class="cx">         if (for_everyone) {
</span><span class="cx">                 sql = switch_mprintf(&quot;select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,&quot;
</span><span class="cx">                                                          &quot;full_via,expires,user_agent,accept,profile_name,network_ip&quot;
</span><del>-                                                         &quot;,'%q','%q' from sip_subscriptions where event='message-summary' &quot;
</del><ins>+                                                         &quot;,'%q','%q' from sip_subscriptions where expires &gt; -1 and event='message-summary' &quot;
</ins><span class="cx">                                                          &quot;and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%')&quot;,
</span><span class="cx">                                                          stream.data, host, user, host, host);
</span><span class="cx">         } else if (sub_call_id) {
</span><span class="cx">                 sql = switch_mprintf(&quot;select proto,sip_user,sip_host,sub_to_user,sub_to_host,event,contact,call_id,full_from,&quot;
</span><span class="cx">                                                          &quot;full_via,expires,user_agent,accept,profile_name,network_ip&quot;
</span><del>-                                                         &quot;,'%q','%q' from sip_subscriptions where event='message-summary' &quot;
</del><ins>+                                                         &quot;,'%q','%q' from sip_subscriptions where expires &gt; -1 and event='message-summary' &quot;
</ins><span class="cx">                                                          &quot;and sub_to_user='%q' and (sub_to_host='%q' or presence_hosts like '%%%q%%' and call_id='%q')&quot;,
</span><span class="cx">                                                          stream.data, host, user, host, host, sub_call_id);
</span><span class="cx">         }
</span><span class="lines">@@ -442,7 +443,7 @@
</span><span class="cx">                                                                  &quot;from sip_subscriptions left join sip_presence on &quot;
</span><span class="cx">                                                                  &quot;(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and &quot;
</span><span class="cx">                                                                  &quot;sip_subscriptions.profile_name=sip_presence.profile_name) &quot;
</span><del>-                                                                 &quot;where sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'&quot;, 
</del><ins>+                                                                 &quot;where sip_subscriptions.expires &gt; -1 and sip_subscriptions.event='presence' and sip_subscriptions.full_from like '%%%q%%'&quot;, 
</ins><span class="cx">                                                                  switch_str_nil(status), switch_str_nil(rpid), from);
</span><span class="cx">                 } else {
</span><span class="cx">                         sql = switch_mprintf(
</span><span class="lines">@@ -455,7 +456,7 @@
</span><span class="cx">                                                                  &quot;from sip_subscriptions left join sip_presence on &quot;
</span><span class="cx">                                                                  &quot;(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and &quot;
</span><span class="cx">                                                                  &quot;sip_subscriptions.profile_name=sip_presence.profile_name) &quot;
</span><del>-                                                                 &quot;where sip_subscriptions.event='presence'&quot;, switch_str_nil(status), switch_str_nil(rpid));
</del><ins>+                                                                 &quot;where sip_subscriptions.expires &gt; -1 and sip_subscriptions.event='presence'&quot;, switch_str_nil(status), switch_str_nil(rpid));
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 switch_assert(sql != NULL);
</span><span class="lines">@@ -615,9 +616,12 @@
</span><span class="cx">                         if (mod_sofia_globals.debug_sla &gt; 1) {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;STATE SQL %s\n&quot;, sql);
</span><span class="cx">                         }
</span><del>-                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
-                        switch_safe_free(sql);
</del><ins>+                        sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">                         
</span><ins>+                        if (mod_sofia_globals.debug_sla &gt; 1) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;PROCESS PRESENCE EVENT\n&quot;);
+                        }
+
</ins><span class="cx">                         sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE);
</span><span class="cx">                 }
</span><span class="cx">                 
</span><span class="lines">@@ -634,7 +638,7 @@
</span><span class="cx">                                                          &quot;left join sip_presence on &quot;
</span><span class="cx">                                                          &quot;(sip_subscriptions.sub_to_user=sip_presence.sip_user and sip_subscriptions.sub_to_host=sip_presence.sip_host and &quot;
</span><span class="cx">                                                          &quot;sip_subscriptions.profile_name=sip_presence.profile_name) &quot;
</span><del>-                                                         &quot;where (event='%q' or event='%q') and sub_to_user='%q' &quot;
</del><ins>+                                                         &quot;where sip_subscriptions.expires &gt; -1 and (event='%q' or event='%q') and sub_to_user='%q' &quot;
</ins><span class="cx">                                                          &quot;and (sub_to_host='%q' or presence_hosts like '%%%q%%') &quot;
</span><span class="cx">                                                          &quot;and (sip_subscriptions.profile_name = '%q' or sip_subscriptions.presence_hosts != sip_subscriptions.sub_to_host)&quot;,
</span><span class="cx">                                                          switch_str_nil(status), switch_str_nil(rpid), host, event_type, alt_event_type, euser, host, host, profile-&gt;name))) {
</span><span class="lines">@@ -1591,7 +1595,7 @@
</span><span class="cx">         if (unseize) {
</span><span class="cx">                 sql = switch_mprintf(&quot;select call_id,expires,sub_to_user,sub_to_host,event &quot;
</span><span class="cx">                                                          &quot;from sip_subscriptions &quot;
</span><del>-                                                         &quot;where hostname='%q' &quot;
</del><ins>+                                                         &quot;where expires &gt; -1 and hostname='%q' &quot;
</ins><span class="cx">                                                          &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
</span><span class="cx">                                                          &quot;and (event='call-info' or event='line-seize')&quot;,
</span><span class="cx">                                                          mod_sofia_globals.hostname,
</span><span class="lines">@@ -1601,7 +1605,7 @@
</span><span class="cx">         } else {
</span><span class="cx">                 sql = switch_mprintf(&quot;select call_id,expires,sub_to_user,sub_to_host,event &quot;
</span><span class="cx">                                                          &quot;from sip_subscriptions &quot;
</span><del>-                                                         &quot;where hostname='%q' &quot;
</del><ins>+                                                         &quot;where expires &gt; -1 and hostname='%q' &quot;
</ins><span class="cx">                                                          &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
</span><span class="cx">                                                          &quot;and (event='call-info')&quot;,
</span><span class="cx">                                                          mod_sofia_globals.hostname,
</span><span class="lines">@@ -1632,7 +1636,7 @@
</span><span class="cx">                 if (mod_sofia_globals.debug_sla &gt; 1) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;CLEAR SQL %s\n&quot;, sql);
</span><span class="cx">                 }
</span><del>-                sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</del><ins>+                sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> }
</span><span class="lines">@@ -1881,9 +1885,7 @@
</span><span class="cx">                 switch_snprintf(exp_delta_str, sizeof(exp_delta_str), &quot;%ld&quot;, exp_delta);
</span><span class="cx">                 
</span><span class="cx">                 if (sofia_test_pflag(profile, PFLAG_MULTIREG)) {
</span><del>-                        //sql = switch_mprintf(&quot;delete from sip_subscriptions where call_id='%q' or (contact='%q' and event='%q')&quot;, call_id, contact_str, event);
-
-                        sql = switch_mprintf(&quot;delete from sip_subscriptions where call_id='%q' &quot;
</del><ins>+                        sql = switch_mprintf(&quot;update sip_subscriptions set expires=-1 where call_id='%q' &quot;
</ins><span class="cx">                                                                  &quot;or (proto='%q' and sip_user='%q' and sip_host='%q' &quot;
</span><span class="cx">                                                                  &quot;and sub_to_user='%q' and sub_to_host='%q' and event='%q' and hostname='%q' &quot;
</span><span class="cx">                                                                  &quot;and contact='%q')&quot;,
</span><span class="lines">@@ -1891,7 +1893,7 @@
</span><span class="cx">                                                                  contact_str);
</span><span class="cx"> 
</span><span class="cx">                 } else {
</span><del>-                        sql = switch_mprintf(&quot;delete from sip_subscriptions where &quot;
</del><ins>+                        sql = switch_mprintf(&quot;update sip_subscriptions set expires=-1 where &quot;
</ins><span class="cx">                                                                  &quot;proto='%q' and sip_user='%q' and sip_host='%q' and sub_to_user='%q' and sub_to_host='%q' and event='%q' and hostname='%q'&quot;,
</span><span class="cx">                                                                  proto, from_user, from_host, to_user, to_host, event, mod_sofia_globals.hostname);
</span><span class="cx">                 }
</span><span class="lines">@@ -1930,7 +1932,7 @@
</span><span class="cx">                                                                  proto, from_user, from_host, to_user, to_host, profile-&gt;presence_hosts ? profile-&gt;presence_hosts : to_host, 
</span><span class="cx">                                                                  event, contact_str, call_id, full_from, full_via, 
</span><span class="cx">                                                                  //sofia_test_pflag(profile, PFLAG_MULTIREG) ? switch_epoch_time_now(NULL) + exp_delta : exp_delta * -1,
</span><del>-                                                                 (long)switch_epoch_time_now(NULL) + exp_delta,
</del><ins>+                                                                 (long)switch_epoch_time_now(NULL) + (exp_delta * 2),
</ins><span class="cx">                                                                  full_agent, accept, profile-&gt;name,mod_sofia_globals.hostname, network_port, network_ip);
</span><span class="cx">                                                                  
</span><span class="cx">                         switch_assert(sql != NULL);
</span><span class="lines">@@ -1941,9 +1943,7 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
-                        switch_safe_free(sql);
-                        
</del><ins>+                        sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
</ins><span class="cx">                         sstr = switch_mprintf(&quot;active;expires=%ld&quot;, exp_delta);
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="lines">@@ -1991,16 +1991,16 @@
</span><span class="cx"> 
</span><span class="cx">                         if (nh &amp;&amp; nh-&gt;nh_ds &amp;&amp; nh-&gt;nh_ds-&gt;ds_usage) {
</span><span class="cx">                                 //nua_dialog_usage_set_refresh_range(nh-&gt;nh_ds-&gt;ds_usage, exp_delta + SUB_OVERLAP, exp_delta + SUB_OVERLAP);
</span><del>-                                nua_dialog_usage_set_refresh_range(nh-&gt;nh_ds-&gt;ds_usage, exp_delta, exp_delta);
</del><ins>+                                nua_dialog_usage_set_refresh_range(nh-&gt;nh_ds-&gt;ds_usage, exp_delta * 2, exp_delta * 2);
</ins><span class="cx">                         }
</span><del>-
</del><ins>+                        
</ins><span class="cx">                         nua_respond(nh, SIP_202_ACCEPTED,
</span><span class="cx">                                                 SIPTAG_CONTACT_STR(contactstr),
</span><span class="cx">                                                 NUTAG_WITH_THIS(nua), 
</span><span class="cx">                                                 SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
</span><span class="cx">                                                 SIPTAG_EXPIRES_STR(exp_delta_str),
</span><span class="cx">                                                 TAG_IF(sticky, NUTAG_PROXY(sticky)), TAG_END());
</span><del>-
</del><ins>+                        
</ins><span class="cx">                         switch_safe_free(sticky);
</span><span class="cx">                         
</span><span class="cx">                 }
</span><span class="lines">@@ -2027,7 +2027,22 @@
</span><span class="cx"> 
</span><span class="cx">                         
</span><span class="cx">                                 if (!strcasecmp(event, &quot;line-seize&quot;)) {
</span><del>-                                        sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_TRUE);
</del><ins>+                                        if (mod_sofia_globals.debug_sla &gt; 1) {
+                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;CANCEL LINE SEIZE\n&quot;);
+                                        }
+
+                                        sql = switch_mprintf(&quot;delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'&quot;,
+                                                                                 to_user,
+                                                                                 to_host
+                                                                                 );
+
+                                        
+                                        if (mod_sofia_globals.debug_sla &gt; 1) {
+                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;CLEAR SQL %s\n&quot;, sql);
+                                        }
+                                        sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
+
+                                        sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
</ins><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 su_free(profile-&gt;home, full_call_info);
</span><span class="lines">@@ -2063,36 +2078,29 @@
</span><span class="cx">                                         if (mod_sofia_globals.debug_sla &gt; 1) {
</span><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;CLEAR SQL %s\n&quot;, sql);
</span><span class="cx">                                         }
</span><del>-                                        sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
-
-                                        sql = switch_mprintf(&quot;insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname) &quot;
-                                                                                 &quot;values ('%q','%q','%q','seized','%q')&quot;,
</del><ins>+                                        sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
+                                        
+                                        sql = switch_mprintf(&quot;insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname,expires) &quot;
+                                                                                 &quot;values ('%q','%q','%q','seized','%q',%ld)&quot;,
</ins><span class="cx">                                                                                  to_user,
</span><span class="cx">                                                                                  to_host,
</span><span class="cx">                                                                                  switch_str_nil(p),
</span><del>-                                                                                 mod_sofia_globals.hostname
</del><ins>+                                                                                 mod_sofia_globals.hostname,
+                                                                                 switch_epoch_time_now(NULL) + exp_delta
</ins><span class="cx">                                                                                  );
</span><span class="cx"> 
</span><span class="cx">                                         if (mod_sofia_globals.debug_sla &gt; 1) {
</span><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;SEIZE SQL %s\n&quot;, sql);
</span><span class="cx">                                         }
</span><del>-                                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
-                                        switch_safe_free(sql);
-                                        sync_sla(profile, to_user, to_host, SWITCH_TRUE, SWITCH_FALSE);
</del><ins>+                                        sofia_glue_execute_sql_now(profile, &amp;sql, SWITCH_TRUE);
+                                        sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
</ins><span class="cx"> 
</span><span class="cx">                                         su_free(profile-&gt;home, full_call_info);
</span><span class="cx">                                 }
</span><del>-                        }
-
-                                
-
-                        if (!strcasecmp(event, &quot;call-info&quot;)) {
</del><ins>+                        } else if (!strcasecmp(event, &quot;call-info&quot;)) {
</ins><span class="cx">                                 sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
</span><span class="cx">                         }
</span><del>-
</del><span class="cx">                 }
</span><del>-                
-                
</del><span class="cx"> 
</span><span class="cx">                 sent_reply++;
</span><span class="cx"> 
</span><span class="lines">@@ -2102,7 +2110,7 @@
</span><span class="cx">                         if ((sql = switch_mprintf(
</span><span class="cx">                                                                           &quot;select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,&quot;
</span><span class="cx">                                                                           &quot;full_via,expires,user_agent,accept,profile_name,network_ip&quot;
</span><del>-                                                                          &quot; from sip_subscriptions where event='message-summary' and sip_user='%q' &quot;
</del><ins>+                                                                          &quot; from sip_subscriptions where expires &gt; -1 and event='message-summary' and sip_user='%q' &quot;
</ins><span class="cx">                                                                           &quot;and (sip_host='%q' or presence_hosts like '%%%q%%')&quot;, 
</span><span class="cx">                                                                           to_host, to_user, to_host, to_host))) {
</span><span class="cx">                                 sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, sofia_presence_sub_reg_callback, profile);
</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 (16222 => 16223)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2010-01-08 22:51:16 UTC (rev 16222)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2010-01-09 00:34:17 UTC (rev 16223)
</span><span class="lines">@@ -610,24 +610,35 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">         if (now) {
</span><del>-                switch_snprintf(sql, sizeof(sql), &quot;select call_id from sip_subscriptions where expires &gt; 0 and expires &lt;= %ld and hostname='%s'&quot;, 
</del><ins>+                switch_snprintf(sql, sizeof(sql), &quot;select call_id from sip_subscriptions where (expires = -1 or (expires &gt; 0 and expires &lt;= %ld)) and hostname='%s'&quot;, 
</ins><span class="cx">                                                 (long) now, mod_sofia_globals.hostname);
</span><span class="cx">         } else {
</span><del>-                switch_snprintf(sql, sizeof(sql), &quot;select call_id from sip_subscriptions where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</del><ins>+                switch_snprintf(sql, sizeof(sql), &quot;select call_id from sip_subscriptions where expires &gt;= -1 and hostname='%s'&quot;, 
+                                                mod_sofia_globals.hostname);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         sofia_glue_execute_sql_callback(profile, NULL, sql, sofia_sub_del_callback, profile);
</span><span class="cx"> 
</span><span class="cx">         if (now) {
</span><del>-                switch_snprintf(sql, sizeof(sql), &quot;delete from sip_subscriptions where expires &gt; 0 and expires &lt;= %ld and hostname='%s'&quot;, 
</del><ins>+                switch_snprintf(sql, sizeof(sql), &quot;delete from sip_subscriptions where (expires = -1 or (expires &gt; 0 and expires &lt;= %ld)) and hostname='%s'&quot;, 
</ins><span class="cx">                                                 (long) now, mod_sofia_globals.hostname);
</span><span class="cx">         } else {
</span><del>-                switch_snprintf(sql, sizeof(sql), &quot;delete from sip_subscriptions where expires &gt; 0 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</del><ins>+                switch_snprintf(sql, sizeof(sql), &quot;delete from sip_subscriptions where expires &gt;= -1 and hostname='%s'&quot;, mod_sofia_globals.hostname);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         sofia_glue_actually_execute_sql(profile, sql, NULL);
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+        if (now) {
+                switch_snprintf(sql, sizeof(sql), &quot;delete from sip_dialogs where (expires = -1 or (expires &gt; 0 and expires &lt;= %ld)) and hostname='%s'&quot;, 
+                                                (long) now, mod_sofia_globals.hostname);
+        } else {
+                switch_snprintf(sql, sizeof(sql), &quot;delete from sip_dialogs where expires &gt;= -1 and hostname='%s'&quot;, mod_sofia_globals.hostname);
+        }
+
+        sofia_glue_actually_execute_sql(profile, sql, NULL);
+
+
</ins><span class="cx">         if (now &amp;&amp; sofia_test_pflag(profile, PFLAG_NAT_OPTIONS_PING)) {
</span><span class="cx">                 switch_snprintf(sql, sizeof(sql), &quot;select call_id,sip_user,sip_host,contact,status,rpid,&quot;
</span><span class="cx">                                                 &quot;expires,user_agent,server_user,server_host,profile_name&quot;
</span><span class="lines">@@ -1268,7 +1279,7 @@
</span><span class="cx">                         switch_event_fire(&amp;s_event);
</span><span class="cx">                 }
</span><span class="cx">                 
</span><del>-                if (*contact_str &amp;&amp; sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE) &amp;&amp; sofia_sla_supported(sip)) {
</del><ins>+                if (*contact_str &amp;&amp; sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE_SYLANTRO)) {
</ins><span class="cx">                         sofia_sla_handle_register(nua, profile, sip, exptime, contact_str);
</span><span class="cx">                 }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>