<!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][16194] </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=16194">16194</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2010-01-07 00:09:35 -0600 (Thu, 07 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>share and share alike, only nothing is alike in sip =/</pre>

<h3>Modified Paths</h3>
<ul>
<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="#freeswitchtrunksrcswitch_channelc">freeswitch/trunk/src/switch_channel.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (16193 => 16194)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-01-07 05:22:02 UTC (rev 16193)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-01-07 06:09:35 UTC (rev 16194)
</span><span class="lines">@@ -283,6 +283,7 @@
</span><span class="cx">         int guess_mask;
</span><span class="cx">         char guess_mask_str[16];
</span><span class="cx">         int debug_presence;
</span><ins>+        int debug_sla;
</ins><span class="cx">         int auto_restart;
</span><span class="cx">         int auto_nat;
</span><span class="cx">         int tracelevel;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (16193 => 16194)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-01-07 05:22:02 UTC (rev 16193)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-01-07 06:09:35 UTC (rev 16194)
</span><span class="lines">@@ -2413,6 +2413,8 @@
</span><span class="cx">                                 su_log_set_level(NULL, atoi(val));
</span><span class="cx">                         } else if (!strcasecmp(var, &quot;debug-presence&quot;)) {
</span><span class="cx">                                 mod_sofia_globals.debug_presence = atoi(val);
</span><ins>+                        } else if (!strcasecmp(var, &quot;debug-sla&quot;)) {
+                                mod_sofia_globals.debug_sla = atoi(val);
</ins><span class="cx">                         } else if (!strcasecmp(var, &quot;auto-restart&quot;)) {
</span><span class="cx">                                 mod_sofia_globals.auto_restart = switch_true(val);
</span><span class="cx">                         } else if (!strcasecmp(var, &quot;rewrite-multicasted-fs-path&quot;)) {
</span><span class="lines">@@ -2771,6 +2773,7 @@
</span><span class="cx">                                                 if (switch_true(val)) {
</span><span class="cx">                                                         sofia_set_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE);
</span><span class="cx">                                                         profile-&gt;pres_type = PRES_TYPE_FULL;
</span><ins>+                                                        sofia_set_pflag(profile, PFLAG_MULTIREG);
</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 class="lines">@@ -3384,6 +3387,8 @@
</span><span class="cx">                                                                           nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
</span><span class="cx">                                                                           tagi_t tags[])
</span><span class="cx"> {
</span><ins>+        char *call_info = NULL;
+
</ins><span class="cx">         if (sip &amp;&amp; session) {
</span><span class="cx">                 switch_channel_t *channel = switch_core_session_get_channel(session);
</span><span class="cx">                 const char *uuid;
</span><span class="lines">@@ -3392,9 +3397,7 @@
</span><span class="cx">                 char network_ip[80];
</span><span class="cx">                 int network_port = 0;
</span><span class="cx">                 switch_caller_profile_t *caller_profile = NULL;
</span><del>-                char *call_info = NULL;
</del><span class="cx"> 
</span><del>-
</del><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">                 switch_channel_set_variable(channel, &quot;sip_reply_host&quot;, network_ip);
</span><span class="lines">@@ -3406,6 +3409,51 @@
</span><span class="cx"> 
</span><span class="cx">                 switch_channel_clear_flag(channel, CF_REQ_MEDIA);
</span><span class="cx"> 
</span><ins>+                if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) {
+                        if (channel &amp;&amp; sip-&gt;sip_call_info) {
+                                char *p;
+                                call_info = sip_header_as_string(nua_handle_home(nh), (void *) sip-&gt;sip_call_info);
+                                if ((p = strchr(call_info, ';'))) {
+                                        switch_channel_set_variable(channel, &quot;presence_call_info&quot;, p+1);
+                                }
+                        } else if ((status == 180 || status == 183 || status == 200)) {
+                                char buf[128] = &quot;&quot;;
+                                char *sql;
+                                char *state = &quot;active&quot;;
+
+                                if (status != 200) {
+                                        state = &quot;progressing&quot;;
+                                }
+
+                                if (sip &amp;&amp; 
+                                        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;
+                                        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) {
+                                        sql = switch_mprintf(&quot;select 'appearance-index=1' from sip_subscriptions where hostname='%q' and event='call-info' and &quot;
+                                                                                 &quot;sub_to_user='%q' and sub_to_host='%q'&quot;, 
+                                                                                 mod_sofia_globals.hostname, sip-&gt;sip_to-&gt;a_url-&gt;url_user, sip-&gt;sip_from-&gt;a_url-&gt;url_host);
+                                        sofia_glue_execute_sql2str(profile, profile-&gt;ireg_mutex, sql, buf, sizeof(buf));
+                                
+                                        if (mod_sofia_globals.debug_sla &gt; 1) {
+                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;QUERY SQL %s [%s]\n&quot;, sql, buf);
+                                        }
+                                        free(sql);
+
+                                        if (!zstr(buf)) {
+                                                sql = switch_mprintf(&quot;update sip_dialogs set call_info='%q',call_info_state='%q' &quot;
+                                                                                         &quot;where uuid='%q'&quot;, buf, state, 
+                                                                                         switch_core_session_get_uuid(session));
+
+                                                if (mod_sofia_globals.debug_sla &gt; 1) {
+                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;QUERY SQL %s\n&quot;, sql);
+                                                }
+                                        
+                                                sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
+                                                switch_safe_free(sql);
+                                        }
+                                }
+                        }
+                }
+
</ins><span class="cx">                 if ((status == 180 || status == 183 || status == 200)) { 
</span><span class="cx">                         const char *x_freeswitch_support;
</span><span class="cx"> 
</span><span class="lines">@@ -3443,14 +3491,9 @@
</span><span class="cx">                         
</span><span class="cx">                         if (!p_contact) {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, &quot;Missing contact header in redirect request\n&quot;);
</span><del>-                                return;
</del><ins>+                                goto end;
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        if (sip-&gt;sip_call_info) {
-                                call_info = sip_header_as_string(profile-&gt;home, (void *) sip-&gt;sip_call_info);
-                                switch_channel_set_variable(channel, &quot;presence_call_info&quot;, call_info);
-                        }
-
</del><span class="cx">                         if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
</span><span class="cx">                                 switch_xml_t root = NULL, domain = NULL;
</span><span class="cx">                                 switch_core_session_t *a_session;
</span><span class="lines">@@ -3579,7 +3622,7 @@
</span><span class="cx">                 if (switch_channel_test_flag(channel, CF_PROXY_MODE) || switch_channel_test_flag(channel, CF_PROXY_MEDIA)) {
</span><span class="cx"> 
</span><span class="cx">                         if (!sofia_test_flag(tech_pvt, TFLAG_SENT_UPDATE)) {
</span><del>-                                return;
</del><ins>+                                goto end;
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         sofia_clear_flag_locked(tech_pvt, TFLAG_SENT_UPDATE);
</span><span class="lines">@@ -3610,7 +3653,7 @@
</span><span class="cx">                                 switch_core_session_queue_message(other_session, msg);
</span><span class="cx">                                 switch_core_session_rwunlock(other_session);
</span><span class="cx">                         }
</span><del>-                        return;
</del><ins>+                        goto end;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ((status == 180 || status == 183 || status == 200)) {
</span><span class="lines">@@ -3664,11 +3707,15 @@
</span><span class="cx">                                         const char *presence_data = switch_channel_get_variable(channel, &quot;presence_data&quot;);
</span><span class="cx">                                         const char *presence_id = switch_channel_get_variable(channel, &quot;presence_id&quot;);
</span><span class="cx">                                         char *full_contact = &quot;&quot;;
</span><del>-                                        
</del><ins>+                                        char *p = NULL;
+
</ins><span class="cx">                                         if (sip-&gt;sip_contact) {
</span><span class="cx">                                                 full_contact = sip_header_as_string(nua_handle_home(tech_pvt-&gt;nh), (void *) sip-&gt;sip_contact);
</span><span class="cx">                                         }
</span><del>-                                        
</del><ins>+
+                                        if (call_info &amp;&amp; (p = strchr(call_info, ';'))) {
+                                                p++;
+                                        }
</ins><span class="cx">                                         sql = switch_mprintf(&quot;insert into sip_dialogs &quot;
</span><span class="cx">                                                                                  &quot;(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user,&quot;
</span><span class="cx">                                                                                  &quot;contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info) &quot;
</span><span class="lines">@@ -3678,18 +3725,13 @@
</span><span class="cx">                                                                                  to_user, to_host, from_user, from_host, contact_user, 
</span><span class="cx">                                                                                  contact_host, astate, &quot;outbound&quot;, user_agent,
</span><span class="cx">                                                                                  profile-&gt;name, mod_sofia_globals.hostname, switch_str_nil(full_contact),
</span><del>-                                                                                 switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(call_info));
</del><ins>+                                                                                 switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
</ins><span class="cx">                                         
</span><span class="cx">                                         switch_assert(sql);
</span><span class="cx"> 
</span><span class="cx">                                         sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</span><span class="cx"> 
</span><del>-                                }
-                                
-                                if (call_info) {
-                                        su_free(profile-&gt;home, call_info);
-                                }
-
</del><ins>+                                }                                
</ins><span class="cx">                         } else if (status == 200 &amp;&amp; (profile-&gt;pres_type)) {
</span><span class="cx">                                 char *sql = NULL;
</span><span class="cx">                                 const char *presence_data = switch_channel_get_variable(channel, &quot;presence_data&quot;);
</span><span class="lines">@@ -3705,6 +3747,12 @@
</span><span class="cx"> 
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+ end:
+
+        if (call_info) {
+                su_free(nua_handle_home(nh), call_info);
+        }
+
</ins><span class="cx">         if (!session &amp;&amp; (status == 180 || status == 183 || status == 200)) {
</span><span class="cx">                 /* nevermind */
</span><span class="cx">                 nua_handle_bind(nh, NULL);
</span><span class="lines">@@ -5891,10 +5939,16 @@
</span><span class="cx">                 char *sql;
</span><span class="cx">                 char cid[512] = &quot;&quot;;
</span><span class="cx">                 char *str;
</span><ins>+                char *p = NULL;
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">                 if (sip-&gt;sip_to &amp;&amp; sip-&gt;sip_to-&gt;a_url) {
</span><ins>+                        if ((p = strchr(call_info_str, ';'))) {
+                                p++;
+                        }
+
</ins><span class="cx">                         sql = switch_mprintf(&quot;select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q'&quot;, 
</span><del>-                                                                 call_info_str, sip-&gt;sip_to-&gt;a_url-&gt;url_user, sip-&gt;sip_to-&gt;a_url-&gt;url_host);
</del><ins>+                                                                 switch_str_nil(p), sip-&gt;sip_to-&gt;a_url-&gt;url_user, sip-&gt;sip_to-&gt;a_url-&gt;url_host);
</ins><span class="cx">                         
</span><span class="cx">                         if ((str = sofia_glue_execute_sql2str(profile, profile-&gt;ireg_mutex, sql, cid, sizeof(cid)))) {
</span><span class="cx">                                 bnh = nua_handle_by_call_id(nua, str);
</span><span class="lines">@@ -5930,6 +5984,7 @@
</span><span class="cx">                                         }
</span><span class="cx"> 
</span><span class="cx">                                         if ((uuid = switch_channel_get_variable(b_channel, SWITCH_SIGNAL_BOND_VARIABLE))) {
</span><ins>+                                                switch_channel_set_variable(b_channel, &quot;presence_call_info&quot;, NULL);
</ins><span class="cx">                                                 one_leg = 0;
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 uuid = switch_core_session_get_uuid(b_session);
</span><span class="lines">@@ -5952,7 +6007,7 @@
</span><span class="cx">                                                         if (!one_leg &amp;&amp; 
</span><span class="cx">                                                                 (!b_tech_pvt || !sofia_test_flag(b_tech_pvt, TFLAG_SIP_HOLD)) &amp;&amp; 
</span><span class="cx">                                                                 (!c_tech_pvt || !sofia_test_flag(c_tech_pvt, TFLAG_SIP_HOLD))) {
</span><del>-                                                                char *ext = switch_core_session_sprintf(b_session, &quot;conference:%s@sla+flags{mintwo}&quot;, uuid);
</del><ins>+                                                                char *ext = switch_core_session_sprintf(b_session, &quot;answer,conference:%s@sla+flags{mintwo}&quot;, uuid);
</ins><span class="cx">                                                                 
</span><span class="cx">                                                                 switch_channel_set_flag(c_channel, CF_REDIRECT);
</span><span class="cx">                                                                 switch_ivr_session_transfer(b_session, ext, &quot;inline&quot;, NULL);
</span><span class="lines">@@ -6117,13 +6172,18 @@
</span><span class="cx">                         const char *presence_data = switch_channel_get_variable(channel, &quot;presence_data&quot;);
</span><span class="cx">                         const char *presence_id = switch_channel_get_variable(channel, &quot;presence_id&quot;);
</span><span class="cx">                         char *full_contact = &quot;&quot;;
</span><ins>+                        char *p = NULL;
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">                         if (sip-&gt;sip_contact) {
</span><span class="cx">                                 full_contact = sip_header_as_string(nua_handle_home(tech_pvt-&gt;nh), (void *) sip-&gt;sip_contact);
</span><span class="cx">                         }
</span><span class="cx">                         
</span><span class="cx">                         if (call_info_str) {
</span><del>-                                switch_channel_set_variable(channel, &quot;presence_call_info&quot;, call_info_str);
</del><ins>+                                if ((p = strchr(call_info_str, ';'))) {
+                                        p++;
+                                        switch_channel_set_variable(channel, &quot;presence_call_info&quot;, p);
+                                }
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -6136,7 +6196,7 @@
</span><span class="cx">                                                                  to_user, to_host, dialog_from_user, dialog_from_host, 
</span><span class="cx">                                                                  contact_user, contact_host, &quot;confirmed&quot;, &quot;inbound&quot;, user_agent,
</span><span class="cx">                                                                  profile-&gt;name, mod_sofia_globals.hostname, switch_str_nil(full_contact), 
</span><del>-                                                                 switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(call_info_str));
</del><ins>+                                                                 switch_str_nil(presence_id), switch_str_nil(presence_data), switch_str_nil(p));
</ins><span class="cx"> 
</span><span class="cx">                         switch_assert(sql);
</span><span class="cx">                         
</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 (16193 => 16194)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2010-01-07 05:22:02 UTC (rev 16193)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2010-01-07 06:09:35 UTC (rev 16194)
</span><span class="lines">@@ -3831,7 +3831,8 @@
</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;
</del><ins>+        &quot;   call_info  VARCHAR(255),\n&quot;
+        &quot;   call_info_state  VARCHAR(255)\n&quot;
</ins><span class="cx">                 &quot;);\n&quot;;
</span><span class="cx"> 
</span><span class="cx">         char sub_sql[] =
</span><span class="lines">@@ -3917,6 +3918,7 @@
</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><ins>+                        &quot;create index sd_call_info on sip_dialogs (call_info_state)&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">@@ -3986,7 +3988,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 like '%%'&quot;, mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_dialogs where hostname='%q' and call_info_state like '%%'&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">@@ -4053,7 +4055,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 like '%%'&quot;, mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf(&quot;delete from sip_dialogs where hostname='%q' and call_info_state like '%%'&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">@@ -4131,6 +4133,7 @@
</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><ins>+                switch_core_db_exec(db, &quot;create index if not exists sd_call_info on sip_dialogs (call_info_state)&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></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_presencec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (16193 => 16194)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c        2010-01-07 05:22:02 UTC (rev 16193)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c        2010-01-07 06:09:35 UTC (rev 16194)
</span><span class="lines">@@ -35,13 +35,21 @@
</span><span class="cx"> #include &quot;mod_sofia.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #define SUB_OVERLAP 300
</span><ins>+struct state_helper {
+        switch_hash_t *hash;
+        sofia_profile_t *profile;
+        switch_memory_pool_t *pool;
+};
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames);
</span><span class="cx"> static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char **columnNames);
</span><span class="cx"> static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames);
</span><span class="cx"> static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames);
</span><span class="cx"> static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
</span><del>-static int broadsoft_sla_callback(void *pArg, int argc, char **argv, char **columnNames);
</del><ins>+static int broadsoft_sla_gather_state_callback(void *pArg, int argc, char **argv, char **columnNames);
+static int broadsoft_sla_notify_callback(void *pArg, int argc, char **argv, char **columnNames);
+static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *to_host, switch_bool_t clear, switch_bool_t unseize);
</ins><span class="cx"> 
</span><span class="cx"> struct resub_helper {
</span><span class="cx">         sofia_profile_t *profile;
</span><span class="lines">@@ -589,52 +597,30 @@
</span><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if (call_info) {
</span><del>-                        sql = switch_mprintf(&quot;select sip_subscriptions.call_id,sip_subscriptions.expires,'%q',3, sip_dialogs.state,sip_dialogs.call_info, &quot;
-                                                                 &quot;sip_subscriptions.sub_to_host,'%q',event &quot;
-                                                                 &quot;from sip_subscriptions left join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user &quot;
-                                                                 &quot;and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host &quot;
-                                                                 &quot;where sip_subscriptions.hostname='%q' &quot;
-                                                                 &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
-                                                                 &quot;and (event='call-info' or event='line-seize') and sip_dialogs.call_info='%q'&quot;,
-                                                                 call_info,
-                                                                 call_info_state,
-                                                                 mod_sofia_globals.hostname,
-                                                                 euser,
-                                                                 host,
-                                                                 call_info
-                                                                 );
</del><span class="cx">                         
</span><del>-                        if (mod_sofia_globals.debug_presence &gt; 1) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;PRES SQL %s\n&quot;, sql);
</del><ins>+#if 0
+                        if (mod_sofia_globals.debug_sla &gt; 1) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;SLA EVENT:\n&quot;);
+                                DUMP_EVENT(event);
</ins><span class="cx">                         }
</span><del>-                        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, broadsoft_sla_callback, profile);
-                        switch_safe_free(sql);
</del><ins>+#endif
+                        
+                        sql = switch_mprintf(&quot;update sip_dialogs set call_info_state='%q' where hostname='%q' and sip_dialogs.sip_from_user='%q' &quot;
+                                                                 &quot;and sip_dialogs.sip_from_host='%q' and call_info='%q'&quot;, 
+                                                                 call_info_state, 
+                                                                 mod_sofia_globals.hostname,
+                                                                 euser, host, call_info);
</ins><span class="cx"> 
</span><del>-
-
-                        sql = switch_mprintf(&quot;select sip_subscriptions.call_id,sip_subscriptions.expires,'',3, sip_dialogs.state,sip_dialogs.call_info, &quot;
-                                                                 &quot;sip_subscriptions.sub_to_host,'',event &quot;
-                                                                 &quot;from sip_subscriptions inner join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user &quot;
-                                                                 &quot;and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host &quot;
-                                                                 &quot;where sip_subscriptions.hostname='%q' &quot;
-                                                                 &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
-                                                                 &quot;and event='call-info' and sip_dialogs.call_info!='%q'&quot;,
-                                                                 mod_sofia_globals.hostname,
-                                                                 euser,
-                                                                 host,
-                                                                 call_info
-                                                                 );
-                        
-                        if (mod_sofia_globals.debug_presence &gt; 1) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,&quot;PRES SQL %s\n&quot;, sql);
</del><ins>+                        if (mod_sofia_globals.debug_sla &gt; 1) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;STATE SQL %s\n&quot;, sql);
</ins><span class="cx">                         }
</span><del>-
-                        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, broadsoft_sla_callback, profile);
</del><ins>+                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
</ins><span class="cx">                         switch_safe_free(sql);
</span><del>-
</del><ins>+                        
+                        sync_sla(profile, euser, host, SWITCH_TRUE, SWITCH_TRUE);
</ins><span class="cx">                 }
</span><ins>+                
</ins><span class="cx"> 
</span><del>-
</del><span class="cx">                 if ((sql = switch_mprintf(
</span><span class="cx">                                                          
</span><span class="cx">                                                          &quot;select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,&quot;
</span><span class="lines">@@ -1463,46 +1449,29 @@
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static int broadsoft_sla_callback(void *pArg, int argc, char **argv, char **columnNames)
</del><ins>+static int broadsoft_sla_notify_callback(void *pArg, int argc, char **argv, char **columnNames)
</ins><span class="cx"> {
</span><ins>+        struct state_helper *sh = (struct state_helper *) pArg;
+        char key[256] = &quot;&quot;;
+        char *data = NULL, *tmp;
</ins><span class="cx">         char *call_id = argv[0];
</span><span class="cx">         char *expires = argv[1];
</span><del>-        char *header = argv[2];
-        char *onoff = argv[3];
-        char *state = NULL;
-        char *call_info = NULL;
-        char *call_info_state = NULL;
-        char *event = NULL;
-        char *host = NULL;
-        sofia_profile_t *profile = (sofia_profile_t *) pArg;
-        nua_handle_t *nh;
</del><ins>+        char *user = argv[2];
+        char *host = argv[3];
+        char *event = argv[4];
+        int i;
</ins><span class="cx">         char sstr[128] = &quot;&quot;, expires_str[128] = &quot;&quot;;        
</span><span class="cx">         time_t exptime = 3600;
</span><del>-        int on = atoi(onoff);
-        char buf[512] = &quot;&quot;;
-        const char *r_state = &quot;idle&quot;;
-        int i;
</del><ins>+        nua_handle_t *nh;
</ins><span class="cx"> 
</span><del>-        if (mod_sofia_globals.debug_presence &gt; 1) {
</del><ins>+        if (mod_sofia_globals.debug_sla &gt; 1) {
</ins><span class="cx">                 for(i = 0; i &lt; argc; i++) {
</span><del>-                        printf(&quot;COL [%s]=[%s]\n&quot;, columnNames[i], argv[i]);
</del><ins>+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,&quot;SLA3: %d [%s]=[%s]\n&quot;, i, columnNames[i], argv[i]);
</ins><span class="cx">                 }
</span><del>-                printf(&quot;\non=%d\n\n&quot;, on);
</del><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (on &gt;= 2 &amp;&amp; argc &gt;= 7) {
-                state = argv[4];
-                call_info = argv[5];
-                host = argv[6];
-                call_info_state = argv[7];
-                if (argc &gt; 8) event = argv[8];
-        } else {
-                call_info = header;
-        }
-        
-        if (zstr(event)) {
-                event = &quot;call-info&quot;;
-        }
</del><ins>+        switch_snprintf(key, sizeof(key), &quot;%s%s&quot;, user, host);
+        data = switch_core_hash_find(sh-&gt;hash, key);
</ins><span class="cx"> 
</span><span class="cx">         if (expires) {
</span><span class="cx">                 long tmp = atol(expires);
</span><span class="lines">@@ -1514,63 +1483,160 @@
</span><span class="cx">         } else {
</span><span class="cx">                 switch_snprintf(sstr, sizeof(sstr), &quot;terminated;reason=noresource&quot;);
</span><span class="cx">         }
</span><del>-
</del><ins>+        
</ins><span class="cx">         switch_snprintf(expires_str, sizeof(expires_str), &quot;%u&quot;, (unsigned)exptime);
</span><span class="cx"> 
</span><del>-        if (zstr(call_info)) {
-                call_info = header;
</del><ins>+        data = switch_core_hash_find(sh-&gt;hash, key);
+
+        if (data) {
+                tmp = switch_core_sprintf(sh-&gt;pool, &quot;%s,&lt;sip:%s&gt;;appearance-index=*;appearance-state=idle&quot;, data, host);
+        } else {
+                tmp = switch_core_sprintf(sh-&gt;pool, &quot;&lt;sip:%s&gt;;appearance-index=*;appearance-state=idle&quot;, host);
</ins><span class="cx">         }
</span><ins>+        
+        if (!strcasecmp(event, &quot;line-seize&quot;) &amp;&amp; (nh = nua_handle_by_call_id(sh-&gt;profile-&gt;nua, call_id))) {
+                char *hack;
</ins><span class="cx"> 
</span><del>-        if (on == 3) {
-                if (!zstr(call_info_state)) {
-                        r_state = call_info_state;
-                } else if (!zstr(argv[4])) {
-                        r_state = &quot;active&quot;;
-                } else {
-                        r_state = &quot;idle&quot;;
</del><ins>+                if ((hack = (char *)switch_stristr(&quot;=seized&quot;, tmp))) {
+                        switch_snprintf(hack, 7, &quot;=idle  &quot;);
</ins><span class="cx">                 }
</span><del>-        } else if (on) {
-                r_state = &quot;seized&quot;;
</del><ins>+                nua_notify(nh,
+                                   SIPTAG_EXPIRES_STR(&quot;0&quot;),
+                                   SIPTAG_SUBSCRIPTION_STATE_STR(&quot;terminated;reason=noresource&quot;),
+                                   SIPTAG_EVENT_STR(&quot;line-seize&quot;), 
+                                   SIPTAG_CALL_INFO_STR(tmp), 
+                                   TAG_END());
+                return 0;
</ins><span class="cx">         }
</span><span class="cx">         
</span><ins>+        if (!strcasecmp(event, &quot;call-info&quot;) &amp;&amp; (nh = nua_handle_by_call_id(sh-&gt;profile-&gt;nua, call_id))) {
+                nua_notify(nh,
+                                   TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
+                                   SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
+                                   SIPTAG_EVENT_STR(&quot;call-info&quot;), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
</ins><span class="cx"> 
</span><del>-        if (zstr(call_info)) {
-                switch_snprintf(buf, sizeof(buf), &quot;&lt;sip:%s&gt;;apperance-index=*&quot;, host);
-                call_info = buf;
</del><span class="cx">         }
</span><del>-        
-        if (mod_sofia_globals.debug_presence &gt; 1) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;[%s][%s][%s][%s]\n&quot;, event, call_info, call_id, r_state);
-        }
</del><span class="cx"> 
</span><del>-        if (!strcasecmp(event, &quot;line-seize&quot;) &amp;&amp; (nh = nua_handle_by_call_id(profile-&gt;nua, call_id))) {
-                if (strcasecmp(r_state, &quot;seized&quot;)) {
-                        char *new_header = switch_mprintf(&quot;%s;appearance-state=%s&quot;, call_info, r_state);
-                        nua_notify(nh,
-                                           SIPTAG_EXPIRES_STR(&quot;0&quot;),
-                                           SIPTAG_SUBSCRIPTION_STATE_STR(&quot;terminated;reason=noresource&quot;),
-                                           SIPTAG_EVENT_STR(&quot;line-seize&quot;), SIPTAG_CALL_INFO_STR(new_header), TAG_END());
-                        switch_safe_free(new_header);
</del><ins>+        return 0;
+}
</ins><span class="cx"> 
</span><ins>+static int broadsoft_sla_gather_state_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+        struct state_helper *sh = (struct state_helper *) pArg;
+        char key[256] = &quot;&quot;;
+        char *data = NULL, *tmp;
+        char *user = argv[0];
+        char *host = argv[1];
+        char *info = argv[2];
+        char *state = argv[3];
+        int i;
+
+        if (mod_sofia_globals.debug_sla &gt; 1) {
+                for(i = 0; i &lt; argc; i++) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,&quot;SLA2: %d [%s]=[%s]\n&quot;, i, columnNames[i], argv[i]);
</ins><span class="cx">                 }
</span><del>-                        return 0;
</del><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if (profile &amp;&amp; call_id &amp;&amp; call_info &amp;&amp; (nh = nua_handle_by_call_id(profile-&gt;nua, call_id))) {
-                char *new_header = switch_mprintf(&quot;%s;appearance-state=%s&quot;, call_info, r_state);
-                
-                nua_notify(nh,
-                                   TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
-                                   SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-                                   SIPTAG_EVENT_STR(&quot;call-info&quot;), SIPTAG_CALL_INFO_STR(new_header), TAG_END());
</del><ins>+        if (zstr(info)) {
+                return 0;
+        }
</ins><span class="cx"> 
</span><del>-                switch_safe_free(new_header);
</del><ins>+        if (zstr(state)) {
+                state = &quot;idle&quot;;
</ins><span class="cx">         }
</span><ins>+
+        switch_snprintf(key, sizeof(key), &quot;%s%s&quot;, user, host);
</ins><span class="cx">         
</span><ins>+        data = switch_core_hash_find(sh-&gt;hash, key);
+        
+        if (data) {
+                tmp = switch_core_sprintf(sh-&gt;pool, &quot;%s,&lt;sip:%s&gt;;%s;appearance-state=%s&quot;, data, host, info, state);
+        } else {
+                tmp = switch_core_sprintf(sh-&gt;pool, &quot;&lt;sip:%s&gt;;%s;appearance-state=%s&quot;, host, info, state);
+        }
</ins><span class="cx"> 
</span><ins>+        switch_core_hash_insert(sh-&gt;hash, key, tmp);
+        
</ins><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static void sync_sla(sofia_profile_t *profile, const char *to_user, const char *to_host, switch_bool_t clear, switch_bool_t unseize)
+{
+        struct state_helper *sh;
+        switch_memory_pool_t *pool;
+        char *sql;
+
+        switch_core_new_memory_pool(&amp;pool);
+        sh = switch_core_alloc(pool, sizeof(*sh));
+        sh-&gt;pool = pool;
+        switch_core_hash_init(&amp;sh-&gt;hash, sh-&gt;pool);
+                        
+        sql = switch_mprintf(&quot;select sip_from_user,sip_from_host,call_info,call_info_state from sip_dialogs &quot;
+                                                 &quot;where hostname='%q' &quot;
+                                                 &quot;and sip_from_user='%q' and sip_from_host='%q' &quot;,
+                                                 mod_sofia_globals.hostname,
+                                                 to_user,
+                                                 to_host
+                                                 );
+
+
+        if (mod_sofia_globals.debug_sla &gt; 1) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;PRES SQL %s\n&quot;, sql);
+        }
+        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, broadsoft_sla_gather_state_callback, sh);
+        switch_safe_free(sql);
+
+        
+        if (unseize) {
+                sql = switch_mprintf(&quot;select call_id,expires,sub_to_user,sub_to_host,event &quot;
+                                                         &quot;from sip_subscriptions &quot;
+                                                         &quot;where hostname='%q' &quot;
+                                                         &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
+                                                         &quot;and (event='call-info' or event='line-seize')&quot;,
+                                                         mod_sofia_globals.hostname,
+                                                         to_user,
+                                                         to_host
+                                                         );
+        } else {
+                sql = switch_mprintf(&quot;select call_id,expires,sub_to_user,sub_to_host,event &quot;
+                                                         &quot;from sip_subscriptions &quot;
+                                                         &quot;where hostname='%q' &quot;
+                                                         &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
+                                                         &quot;and (event='call-info')&quot;,
+                                                         mod_sofia_globals.hostname,
+                                                         to_user,
+                                                         to_host
+                                                         );
+        }
+
+
+        if (mod_sofia_globals.debug_sla &gt; 1) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;PRES SQL %s\n&quot;, sql);
+        }
+        sh-&gt;profile = profile;
+        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, broadsoft_sla_notify_callback, sh);
+        switch_safe_free(sql);
+        sh = NULL;
+        switch_core_destroy_memory_pool(&amp;pool);
+
+
+
+        if (clear) {
+                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(profile, &amp;sql, SWITCH_TRUE);
+        }
+
+}
+
+
</ins><span class="cx"> void sofia_presence_handle_sip_i_subscribe(int status,
</span><span class="cx">                                                                                    char const *phrase,
</span><span class="cx">                                                                                    nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip,
</span><span class="lines">@@ -1758,7 +1824,7 @@
</span><span class="cx">                         if ((p = strchr(protocol, '+'))) {
</span><span class="cx">                                 *p = '\0';
</span><span class="cx">                         }
</span><del>-
</del><ins>+                        
</ins><span class="cx">                         if (switch_event_create(&amp;sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                                 switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, &quot;proto&quot;, protocol);
</span><span class="cx">                                 switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, &quot;login&quot;, profile-&gt;name);
</span><span class="lines">@@ -1831,7 +1897,8 @@
</span><span class="cx"> 
</span><span class="cx">                 switch_mutex_lock(profile-&gt;ireg_mutex);
</span><span class="cx">                 switch_assert(sql != NULL);
</span><del>-                sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</del><ins>+                sofia_glue_actually_execute_sql(profile, sql, NULL);
+                switch_safe_free(sql);
</ins><span class="cx"> 
</span><span class="cx">                 if (sub_state == nua_substate_terminated) {
</span><span class="cx">                         sstr = switch_mprintf(&quot;terminated&quot;);
</span><span class="lines">@@ -1843,7 +1910,7 @@
</span><span class="cx">                                 switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), &quot;%s%s &quot;, ap-&gt;ac_type, ap-&gt;ac_next ? &quot;,&quot; : &quot;&quot;);
</span><span class="cx">                                 ap = ap-&gt;ac_next;
</span><span class="cx">                         }
</span><del>-
</del><ins>+                        
</ins><span class="cx">                         /* negative in exptime means keep bumping up sub time to avoid a snafu where every device has it's own rules about subscriptions
</span><span class="cx">                            that somehow barely resemble the RFC not that I blame them because the RFC MAY be amibiguous and SHOULD be deleted.
</span><span class="cx">                            So to avoid the problem we keep resetting the expiration date of the subscription so it never expires.
</span><span class="lines">@@ -1865,13 +1932,17 @@
</span><span class="cx">                                                                  (long)switch_epoch_time_now(NULL) + exp_delta,
</span><span class="cx">                                                                  full_agent, accept, profile-&gt;name,mod_sofia_globals.hostname, network_port, network_ip);
</span><span class="cx">                                                                  
</span><del>-                        if (mod_sofia_globals.debug_presence &gt; 0) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;%s SUBSCRIBE %s@%s %s@%s\n&quot;, profile-&gt;name, from_user, from_host, to_user, to_host);
</del><ins>+                        switch_assert(sql != NULL);
+
+                        if (mod_sofia_globals.debug_presence &gt; 0 || mod_sofia_globals.debug_sla &gt; 0) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;%s SUBSCRIBE %s@%s %s@%s\n%s\n&quot;, 
+                                                                  profile-&gt;name, from_user, from_host, to_user, to_host, sql);
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><del>-                        switch_assert(sql != NULL);
-                        sofia_glue_execute_sql(profile, &amp;sql, SWITCH_TRUE);
</del><span class="cx"> 
</span><ins>+                        sofia_glue_actually_execute_sql(profile, sql, profile-&gt;ireg_mutex);
+                        switch_safe_free(sql);
+                        
</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">@@ -1939,79 +2010,82 @@
</span><span class="cx">                 
</span><span class="cx">                 if (sub_state == nua_substate_terminated) {
</span><span class="cx">                         char *full_call_info = NULL;
</span><ins>+                        char *p = NULL;
</ins><span class="cx"> 
</span><span class="cx">                         if (sip-&gt;sip_call_info) {
</span><span class="cx">                                 full_call_info = sip_header_as_string(profile-&gt;home, (void *) sip-&gt;sip_call_info);
</span><del>-                        }
</del><ins>+                                if ((p = strchr(full_call_info, ';'))) {
+                                        p++;
+                                }
</ins><span class="cx"> 
</span><del>-                        nua_notify(nh,
-                                           SIPTAG_EXPIRES_STR(&quot;0&quot;),
-                                           SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-                                           TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)),
-                                           TAG_END());
</del><ins>+                                nua_notify(nh,
+                                                   SIPTAG_EXPIRES_STR(&quot;0&quot;),
+                                                   SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
+                                                   TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)),
+                                                   TAG_END());
</ins><span class="cx"> 
</span><span class="cx">                         
</span><del>-                        if (!strcasecmp(event, &quot;line-seize&quot;)) {
-                                if (full_call_info) {
-                                        sql = switch_mprintf(&quot;select call_id,expires,'%q',0 from sip_subscriptions where hostname='%q' &quot;
</del><ins>+                                if (!strcasecmp(event, &quot;line-seize&quot;)) {
+                                        sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_TRUE);
+
+#if 0
+                                
+                                        
+                                        sql = switch_mprintf(&quot;select call_id,expires,'%q',0,sub_to_host from sip_subscriptions where hostname='%q' &quot;
</ins><span class="cx">                                                                                  &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
</span><del>-                                                                                 &quot;and event='call-info' and contact != '%q'&quot;,
-                                                                                 full_call_info,
</del><ins>+                                                                                 &quot;and event='call-info' &quot;,
+                                                                                 switch_str_nil(p),
</ins><span class="cx">                                                                                  mod_sofia_globals.hostname,
</span><span class="cx">                                                                                  to_user,
</span><del>-                                                                                 to_host,
-                                                                                 contact_str
</del><ins>+                                                                                 to_host
</ins><span class="cx">                                                                                  );
</span><del>-                                        if (mod_sofia_globals.debug_presence &gt; 1) {
</del><ins>+                                        if (mod_sofia_globals.debug_sla &gt; 1) {
</ins><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;UNSEIZE SQL %s\n&quot;, sql);
</span><span class="cx">                                         }
</span><span class="cx"> 
</span><span class="cx">                                         sofia_glue_execute_sql_callback(profile, NULL, sql, broadsoft_sla_callback, profile);
</span><span class="cx">                                         switch_safe_free(sql);
</span><ins>+#endif
</ins><span class="cx">                                 }
</span><del>-                        }
-                                
-                        if (full_call_info) {
</del><ins>+                
</ins><span class="cx">                                 su_free(profile-&gt;home, full_call_info);
</span><ins>+
</ins><span class="cx">                         }
</span><del>-                                
</del><span class="cx"> 
</span><del>-
</del><span class="cx">                 } else {
</span><span class="cx">                         if (!strcasecmp(event, &quot;line-seize&quot;)) {
</span><span class="cx">                                 char *full_call_info = NULL;
</span><del>-
</del><ins>+                                char *p;
+                                
</ins><span class="cx">                                 if (sip-&gt;sip_call_info) {
</span><span class="cx">                                         full_call_info = sip_header_as_string(profile-&gt;home, (void *) sip-&gt;sip_call_info);
</span><del>-                                }
-                                
</del><ins>+                                        if ((p = strchr(full_call_info, ';'))) {
+                                                p++;
+                                        }
</ins><span class="cx"> 
</span><del>-                                nua_notify(nh,
-                                                   SIPTAG_EXPIRES_STR(exp_delta_str),
-                                                   SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-                                                   SIPTAG_EVENT_STR(&quot;line-seize&quot;), SIPTAG_CALL_INFO_STR(full_call_info), TAG_END());
</del><ins>+                                        nua_notify(nh,
+                                                           SIPTAG_EXPIRES_STR(exp_delta_str),
+                                                           SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
+                                                           SIPTAG_EVENT_STR(&quot;line-seize&quot;), 
+                                                           TAG_IF(full_call_info, SIPTAG_CALL_INFO_STR(full_call_info)),
+                                                           TAG_END());
</ins><span class="cx"> 
</span><del>-                                if (full_call_info) {
-                                        sql = switch_mprintf(&quot;select sip_subscriptions.call_id,sip_subscriptions.expires,'%q',4, sip_dialogs.state,sip_dialogs.call_info, &quot;
-                                                                                 &quot;sip_subscriptions.sub_to_host,'','call-info' &quot;
-                                                                                 &quot;from sip_subscriptions left join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user &quot;
-                                                                                 &quot;and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host &quot;
-                                                                                 &quot;where sip_subscriptions.hostname='%q' &quot;
-                                                                                 &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
-                                                                                 &quot;and event='call-info'and sip_subscriptions.contact != '%q'&quot;,
-                                                                                 full_call_info,
-                                                                                 mod_sofia_globals.hostname,
</del><ins>+
+                                        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;,
</ins><span class="cx">                                                                                  to_user,
</span><span class="cx">                                                                                  to_host,
</span><del>-                                                                                 contact_str
</del><ins>+                                                                                 switch_str_nil(p),
+                                                                                 mod_sofia_globals.hostname
</ins><span class="cx">                                                                                  );
</span><del>-                        
-                                        if (mod_sofia_globals.debug_presence &gt; 1) {
</del><ins>+
+                                        if (mod_sofia_globals.debug_sla &gt; 1) {
</ins><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;SEIZE SQL %s\n&quot;, sql);
</span><span class="cx">                                         }
</span><ins>+                                        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);
</ins><span class="cx"> 
</span><del>-                                        sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, broadsoft_sla_callback, profile);
-                                        switch_safe_free(sql);
</del><span class="cx">                                         su_free(profile-&gt;home, full_call_info);
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="lines">@@ -2019,40 +2093,7 @@
</span><span class="cx">                                 
</span><span class="cx"> 
</span><span class="cx">                         if (!strcasecmp(event, &quot;call-info&quot;)) {
</span><del>-
-#if 0
-                                int x = 0;
-                                for (x = 1; x &lt; 5; x++) {
-                                        char tmp[128] = &quot;&quot;;
-                                        
-                                        switch_snprintf(tmp, sizeof(tmp), &quot;&lt;sip:%s&gt;;apperance-index=%d;appearance-state=idle&quot;, to_host, x);
-                                        nua_notify(nh,
-                                                           SIPTAG_EXPIRES_STR(exp_delta_str),
-                                                           SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-                                                           SIPTAG_EVENT_STR(&quot;call-info&quot;), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
-                                }
-#endif
-
-                                        
-
-                                sql = switch_mprintf(&quot;select sip_subscriptions.call_id,sip_subscriptions.expires,'',2, sip_dialogs.state,sip_dialogs.call_info, &quot;
-                                                                         &quot;sip_subscriptions.sub_to_host &quot;
-                                                                         &quot;from sip_subscriptions inner join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user &quot;
-                                                                         &quot;and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host &quot;
-                                                                         &quot;where sip_subscriptions.hostname='%q' &quot;
-                                                                         &quot;and sub_to_user='%q' and sub_to_host='%q' &quot;
-                                                                         &quot;and event='call-info' and sip_subscriptions.contact != '%q'&quot;,
-                                                                         mod_sofia_globals.hostname,
-                                                                         to_user,
-                                                                         to_host,
-                                                                         contact_str
-                                                                         );
-
-                                if (mod_sofia_globals.debug_presence &gt; 1) {
-                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;CALL-INFO SQL %s\n&quot;, sql);
-                                }
-                                sofia_glue_execute_sql_callback(profile, profile-&gt;ireg_mutex, sql, broadsoft_sla_callback, profile);
-                                switch_safe_free(sql);
</del><ins>+                                sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_FALSE);
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                 }
</span><span class="lines">@@ -2061,21 +2102,14 @@
</span><span class="cx"> 
</span><span class="cx">                 sent_reply++;
</span><span class="cx"> 
</span><del>-#if 0
-                nua_notify(nh,
-                                   SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),
-                                   SIPTAG_EXPIRES_STR(exp_delta_str),
-                                   SIPTAG_CONTENT_TYPE_STR(&quot;application/notice&quot;),
-                                   SIPTAG_PAYLOAD_STR(&quot;Note: Come to ClueCon http://www.cluecon.com\n\n&quot;), TAG_END());
-#endif
-
</del><span class="cx">                 switch_safe_free(sstr);
</span><span class="cx"> 
</span><span class="cx">                 if (!strcasecmp(event, &quot;message-summary&quot;)) {                
</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' and (sip_host='%q' or presence_hosts like '%%%q%%')&quot;, 
</del><ins>+                                                                          &quot; from sip_subscriptions where event='message-summary' and sip_user='%q' &quot;
+                                                                          &quot;and (sip_host='%q' or presence_hosts like '%%%q%%')&quot;, 
</ins><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 class="cx">                                 
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_channelc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_channel.c (16193 => 16194)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_channel.c        2010-01-07 05:22:02 UTC (rev 16193)
+++ freeswitch/trunk/src/switch_channel.c        2010-01-07 06:09:35 UTC (rev 16194)
</span><span class="lines">@@ -512,6 +512,7 @@
</span><span class="cx">                                         call_info_state = &quot;alerting&quot;;
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><ins>+
</ins><span class="cx">                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;presence-call-info-state&quot;, call_info_state);
</span><span class="cx">                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, &quot;presence-call-info&quot;, call_info);
</span><span class="cx">                 }
</span><span class="lines">@@ -1920,6 +1921,10 @@
</span><span class="cx">                 switch_channel_state_t last_state;
</span><span class="cx">                 switch_event_t *event;
</span><span class="cx"> 
</span><ins>+                if (hangup_cause == SWITCH_CAUSE_LOSE_RACE) {
+                        switch_channel_set_variable(channel, &quot;presence_call_info&quot;, NULL);
+                }
+
</ins><span class="cx">                 switch_mutex_lock(channel-&gt;state_mutex);
</span><span class="cx">                 last_state = channel-&gt;state;
</span><span class="cx">                 channel-&gt;state = CS_HANGUP;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>