<!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, "debug-presence")) {
</span><span class="cx">                                 mod_sofia_globals.debug_presence = atoi(val);
</span><ins>+                        } else if (!strcasecmp(var, "debug-sla")) {
+                                mod_sofia_globals.debug_sla = atoi(val);
</ins><span class="cx">                         } else if (!strcasecmp(var, "auto-restart")) {
</span><span class="cx">                                 mod_sofia_globals.auto_restart = switch_true(val);
</span><span class="cx">                         } else if (!strcasecmp(var, "rewrite-multicasted-fs-path")) {
</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->pres_type = PRES_TYPE_FULL;
</span><ins>+                                                        sofia_set_pflag(profile, PFLAG_MULTIREG);
</ins><span class="cx">                                                         profile->sla_contact = switch_core_sprintf(profile->pool, "sla-agent");
</span><span class="cx">                                                 }
</span><span class="cx">                                         } else if (!strcasecmp(var, "disable-srv")) {
</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 && 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), &network_port);
</span><span class="cx">
</span><span class="cx">                 switch_channel_set_variable(channel, "sip_reply_host", 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 && sip->sip_call_info) {
+                                char *p;
+                                call_info = sip_header_as_string(nua_handle_home(nh), (void *) sip->sip_call_info);
+                                if ((p = strchr(call_info, ';'))) {
+                                        switch_channel_set_variable(channel, "presence_call_info", p+1);
+                                }
+                        } else if ((status == 180 || status == 183 || status == 200)) {
+                                char buf[128] = "";
+                                char *sql;
+                                char *state = "active";
+
+                                if (status != 200) {
+                                        state = "progressing";
+                                }
+
+                                if (sip &&
+                                        sip->sip_from && sip->sip_from->a_url && sip->sip_from->a_url->url_user && sip->sip_from->a_url->url_host &&
+                                        sip->sip_to && sip->sip_to->a_url && sip->sip_to->a_url->url_user && sip->sip_to->a_url->url_host) {
+                                        sql = switch_mprintf("select 'appearance-index=1' from sip_subscriptions where hostname='%q' and event='call-info' and "
+                                                                                 "sub_to_user='%q' and sub_to_host='%q'",
+                                                                                 mod_sofia_globals.hostname, sip->sip_to->a_url->url_user, sip->sip_from->a_url->url_host);
+                                        sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, buf, sizeof(buf));
+                                
+                                        if (mod_sofia_globals.debug_sla > 1) {
+                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "QUERY SQL %s [%s]\n", sql, buf);
+                                        }
+                                        free(sql);
+
+                                        if (!zstr(buf)) {
+                                                sql = switch_mprintf("update sip_dialogs set call_info='%q',call_info_state='%q' "
+                                                                                         "where uuid='%q'", buf, state,
+                                                                                         switch_core_session_get_uuid(session));
+
+                                                if (mod_sofia_globals.debug_sla > 1) {
+                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "QUERY SQL %s\n", sql);
+                                                }
+                                        
+                                                sofia_glue_actually_execute_sql(profile, sql, profile->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, "Missing contact header in redirect request\n");
</span><del>-                                return;
</del><ins>+                                goto end;
</ins><span class="cx">                         }
</span><span class="cx">
</span><del>-                        if (sip->sip_call_info) {
-                                call_info = sip_header_as_string(profile->home, (void *) sip->sip_call_info);
-                                switch_channel_set_variable(channel, "presence_call_info", 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, "presence_data");
</span><span class="cx">                                         const char *presence_id = switch_channel_get_variable(channel, "presence_id");
</span><span class="cx">                                         char *full_contact = "";
</span><del>-                                        
</del><ins>+                                        char *p = NULL;
+
</ins><span class="cx">                                         if (sip->sip_contact) {
</span><span class="cx">                                                 full_contact = sip_header_as_string(nua_handle_home(tech_pvt->nh), (void *) sip->sip_contact);
</span><span class="cx">                                         }
</span><del>-                                        
</del><ins>+
+                                        if (call_info && (p = strchr(call_info, ';'))) {
+                                                p++;
+                                        }
</ins><span class="cx">                                         sql = switch_mprintf("insert into sip_dialogs "
</span><span class="cx">                                                                                  "(call_id,uuid,sip_to_user,sip_to_host,sip_from_user,sip_from_host,contact_user,"
</span><span class="cx">                                                                                  "contact_host,state,direction,user_agent,profile_name,hostname,contact,presence_id,presence_data,call_info) "
</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, "outbound", user_agent,
</span><span class="cx">                                                                                  profile->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, &sql, SWITCH_TRUE);
</span><span class="cx">
</span><del>-                                }
-                                
-                                if (call_info) {
-                                        su_free(profile->home, call_info);
-                                }
-
</del><ins>+                                }                                
</ins><span class="cx">                         } else if (status == 200 && (profile->pres_type)) {
</span><span class="cx">                                 char *sql = NULL;
</span><span class="cx">                                 const char *presence_data = switch_channel_get_variable(channel, "presence_data");
</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 && (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] = "";
</span><span class="cx">                 char *str;
</span><ins>+                char *p = NULL;
</ins><span class="cx">
</span><ins>+
</ins><span class="cx">                 if (sip->sip_to && sip->sip_to->a_url) {
</span><ins>+                        if ((p = strchr(call_info_str, ';'))) {
+                                p++;
+                        }
+
</ins><span class="cx">                         sql = switch_mprintf("select call_id from sip_dialogs where call_info='%q' and sip_from_user='%q' and sip_from_host='%q'",
</span><del>-                                                                 call_info_str, sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
</del><ins>+                                                                 switch_str_nil(p), sip->sip_to->a_url->url_user, sip->sip_to->a_url->url_host);
</ins><span class="cx">                         
</span><span class="cx">                         if ((str = sofia_glue_execute_sql2str(profile, profile->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, "presence_call_info", 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 &&
</span><span class="cx">                                                                 (!b_tech_pvt || !sofia_test_flag(b_tech_pvt, TFLAG_SIP_HOLD)) &&
</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, "conference:%s@sla+flags{mintwo}", uuid);
</del><ins>+                                                                char *ext = switch_core_session_sprintf(b_session, "answer,conference:%s@sla+flags{mintwo}", 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, "inline", NULL);
</span><span class="lines">@@ -6117,13 +6172,18 @@
</span><span class="cx">                         const char *presence_data = switch_channel_get_variable(channel, "presence_data");
</span><span class="cx">                         const char *presence_id = switch_channel_get_variable(channel, "presence_id");
</span><span class="cx">                         char *full_contact = "";
</span><ins>+                        char *p = NULL;
</ins><span class="cx">
</span><ins>+
</ins><span class="cx">                         if (sip->sip_contact) {
</span><span class="cx">                                 full_contact = sip_header_as_string(nua_handle_home(tech_pvt->nh), (void *) sip->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, "presence_call_info", call_info_str);
</del><ins>+                                if ((p = strchr(call_info_str, ';'))) {
+                                        p++;
+                                        switch_channel_set_variable(channel, "presence_call_info", 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, "confirmed", "inbound", user_agent,
</span><span class="cx">                                                                  profile->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"> " contact VARCHAR(255),\n"
</span><span class="cx"> " presence_id VARCHAR(255),\n"
</span><span class="cx"> " presence_data VARCHAR(255),\n"
</span><del>- " call_info VARCHAR(255)\n"
</del><ins>+ " call_info VARCHAR(255),\n"
+ " call_info_state VARCHAR(255)\n"
</ins><span class="cx">                 ");\n";
</span><span class="cx">
</span><span class="cx">         char sub_sql[] =
</span><span class="lines">@@ -3917,6 +3918,7 @@
</span><span class="cx">                         "create index sd_hostname on sip_dialogs (hostname)",
</span><span class="cx">                         "create index sd_presence_data on sip_dialogs (presence_data)",
</span><span class="cx">                         "create index sd_call_info on sip_dialogs (call_info)",
</span><ins>+                        "create index sd_call_info on sip_dialogs (call_info_state)",
</ins><span class="cx">                         "create index sp_hostname on sip_presence (hostname)",
</span><span class="cx">                         "create index sa_nonce on sip_authentication (nonce)",
</span><span class="cx">                         "create index sa_hostname on sip_authentication (hostname)",
</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("delete from sip_dialogs where hostname='%q' and call_info like '%%'", mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info_state like '%%'", 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, "DROP TABLE sip_dialogs", NULL);
</span><span class="lines">@@ -4053,7 +4055,7 @@
</span><span class="cx">                 switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_subscriptions", sub_sql);
</span><span class="cx">                 free(test_sql);
</span><span class="cx">
</span><del>-                test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info like '%%'", mod_sofia_globals.hostname);
</del><ins>+                test_sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and call_info_state like '%%'", mod_sofia_globals.hostname);
</ins><span class="cx">                 switch_core_db_test_reactive(db, test_sql, "DROP TABLE sip_dialogs", 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, "create index if not exists sd_presence_id on sip_dialogs (presence_id)", NULL, NULL, NULL);
</span><span class="cx">                 switch_core_db_exec(db, "create index if not exists sd_presence_data on sip_dialogs (presence_data)", NULL, NULL, NULL);
</span><span class="cx">                 switch_core_db_exec(db, "create index if not exists sd_call_info on sip_dialogs (call_info)", NULL, NULL, NULL);
</span><ins>+                switch_core_db_exec(db, "create index if not exists sd_call_info on sip_dialogs (call_info_state)", NULL, NULL, NULL);
</ins><span class="cx">
</span><span class="cx">                 switch_core_db_exec(db, "create index if not exists sp_hostname on sip_presence (hostname)", 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 "mod_sofia.h"
</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("select sip_subscriptions.call_id,sip_subscriptions.expires,'%q',3, sip_dialogs.state,sip_dialogs.call_info, "
-                                                                 "sip_subscriptions.sub_to_host,'%q',event "
-                                                                 "from sip_subscriptions left join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
-                                                                 "and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
-                                                                 "where sip_subscriptions.hostname='%q' "
-                                                                 "and sub_to_user='%q' and sub_to_host='%q' "
-                                                                 "and (event='call-info' or event='line-seize') and sip_dialogs.call_info='%q'",
-                                                                 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 > 1) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
</del><ins>+#if 0
+                        if (mod_sofia_globals.debug_sla > 1) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n");
+                                DUMP_EVENT(event);
</ins><span class="cx">                         }
</span><del>-                        sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_callback, profile);
-                        switch_safe_free(sql);
</del><ins>+#endif
+                        
+                        sql = switch_mprintf("update sip_dialogs set call_info_state='%q' where hostname='%q' and sip_dialogs.sip_from_user='%q' "
+                                                                 "and sip_dialogs.sip_from_host='%q' and call_info='%q'",
+                                                                 call_info_state,
+                                                                 mod_sofia_globals.hostname,
+                                                                 euser, host, call_info);
</ins><span class="cx">
</span><del>-
-
-                        sql = switch_mprintf("select sip_subscriptions.call_id,sip_subscriptions.expires,'',3, sip_dialogs.state,sip_dialogs.call_info, "
-                                                                 "sip_subscriptions.sub_to_host,'',event "
-                                                                 "from sip_subscriptions inner join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
-                                                                 "and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
-                                                                 "where sip_subscriptions.hostname='%q' "
-                                                                 "and sub_to_user='%q' and sub_to_host='%q' "
-                                                                 "and event='call-info' and sip_dialogs.call_info!='%q'",
-                                                                 mod_sofia_globals.hostname,
-                                                                 euser,
-                                                                 host,
-                                                                 call_info
-                                                                 );
-                        
-                        if (mod_sofia_globals.debug_presence > 1) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"PRES SQL %s\n", sql);
</del><ins>+                        if (mod_sofia_globals.debug_sla > 1) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "STATE SQL %s\n", sql);
</ins><span class="cx">                         }
</span><del>-
-                        sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_callback, profile);
</del><ins>+                        sofia_glue_actually_execute_sql(profile, sql, profile->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">                                                          "select sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
</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] = "";
+        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] = "", expires_str[128] = "";        
</span><span class="cx">         time_t exptime = 3600;
</span><del>-        int on = atoi(onoff);
-        char buf[512] = "";
-        const char *r_state = "idle";
-        int i;
</del><ins>+        nua_handle_t *nh;
</ins><span class="cx">
</span><del>-        if (mod_sofia_globals.debug_presence > 1) {
</del><ins>+        if (mod_sofia_globals.debug_sla > 1) {
</ins><span class="cx">                 for(i = 0; i < argc; i++) {
</span><del>-                        printf("COL [%s]=[%s]\n", columnNames[i], argv[i]);
</del><ins>+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"SLA3: %d [%s]=[%s]\n", i, columnNames[i], argv[i]);
</ins><span class="cx">                 }
</span><del>-                printf("\non=%d\n\n", on);
</del><span class="cx">         }
</span><span class="cx">
</span><del>-        if (on >= 2 && argc >= 7) {
-                state = argv[4];
-                call_info = argv[5];
-                host = argv[6];
-                call_info_state = argv[7];
-                if (argc > 8) event = argv[8];
-        } else {
-                call_info = header;
-        }
-        
-        if (zstr(event)) {
-                event = "call-info";
-        }
</del><ins>+        switch_snprintf(key, sizeof(key), "%s%s", user, host);
+        data = switch_core_hash_find(sh->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), "terminated;reason=noresource");
</span><span class="cx">         }
</span><del>-
</del><ins>+        
</ins><span class="cx">         switch_snprintf(expires_str, sizeof(expires_str), "%u", (unsigned)exptime);
</span><span class="cx">
</span><del>-        if (zstr(call_info)) {
-                call_info = header;
</del><ins>+        data = switch_core_hash_find(sh->hash, key);
+
+        if (data) {
+                tmp = switch_core_sprintf(sh->pool, "%s,<sip:%s>;appearance-index=*;appearance-state=idle", data, host);
+        } else {
+                tmp = switch_core_sprintf(sh->pool, "<sip:%s>;appearance-index=*;appearance-state=idle", host);
</ins><span class="cx">         }
</span><ins>+        
+        if (!strcasecmp(event, "line-seize") && (nh = nua_handle_by_call_id(sh->profile->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 = "active";
-                } else {
-                        r_state = "idle";
</del><ins>+                if ((hack = (char *)switch_stristr("=seized", tmp))) {
+                        switch_snprintf(hack, 7, "=idle ");
</ins><span class="cx">                 }
</span><del>-        } else if (on) {
-                r_state = "seized";
</del><ins>+                nua_notify(nh,
+                                 SIPTAG_EXPIRES_STR("0"),
+                                 SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"),
+                                 SIPTAG_EVENT_STR("line-seize"),
+                                 SIPTAG_CALL_INFO_STR(tmp),
+                                 TAG_END());
+                return 0;
</ins><span class="cx">         }
</span><span class="cx">         
</span><ins>+        if (!strcasecmp(event, "call-info") && (nh = nua_handle_by_call_id(sh->profile->nua, call_id))) {
+                nua_notify(nh,
+                                 TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
+                                 SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
+                                 SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
</ins><span class="cx">
</span><del>-        if (zstr(call_info)) {
-                switch_snprintf(buf, sizeof(buf), "<sip:%s>;apperance-index=*", host);
-                call_info = buf;
</del><span class="cx">         }
</span><del>-        
-        if (mod_sofia_globals.debug_presence > 1) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "[%s][%s][%s][%s]\n", event, call_info, call_id, r_state);
-        }
</del><span class="cx">
</span><del>-        if (!strcasecmp(event, "line-seize") && (nh = nua_handle_by_call_id(profile->nua, call_id))) {
-                if (strcasecmp(r_state, "seized")) {
-                        char *new_header = switch_mprintf("%s;appearance-state=%s", call_info, r_state);
-                        nua_notify(nh,
-                                         SIPTAG_EXPIRES_STR("0"),
-                                         SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"),
-                                         SIPTAG_EVENT_STR("line-seize"), 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] = "";
+        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 > 1) {
+                for(i = 0; i < argc; i++) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"SLA2: %d [%s]=[%s]\n", 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 && call_id && call_info && (nh = nua_handle_by_call_id(profile->nua, call_id))) {
-                char *new_header = switch_mprintf("%s;appearance-state=%s", call_info, r_state);
-                
-                nua_notify(nh,
-                                 TAG_IF(*expires_str, SIPTAG_EXPIRES_STR(expires_str)),
-                                 SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-                                 SIPTAG_EVENT_STR("call-info"), 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 = "idle";
</ins><span class="cx">         }
</span><ins>+
+        switch_snprintf(key, sizeof(key), "%s%s", user, host);
</ins><span class="cx">         
</span><ins>+        data = switch_core_hash_find(sh->hash, key);
+        
+        if (data) {
+                tmp = switch_core_sprintf(sh->pool, "%s,<sip:%s>;%s;appearance-state=%s", data, host, info, state);
+        } else {
+                tmp = switch_core_sprintf(sh->pool, "<sip:%s>;%s;appearance-state=%s", host, info, state);
+        }
</ins><span class="cx">
</span><ins>+        switch_core_hash_insert(sh->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(&pool);
+        sh = switch_core_alloc(pool, sizeof(*sh));
+        sh->pool = pool;
+        switch_core_hash_init(&sh->hash, sh->pool);
+                        
+        sql = switch_mprintf("select sip_from_user,sip_from_host,call_info,call_info_state from sip_dialogs "
+                                                 "where hostname='%q' "
+                                                 "and sip_from_user='%q' and sip_from_host='%q' ",
+                                                 mod_sofia_globals.hostname,
+                                                 to_user,
+                                                 to_host
+                                                 );
+
+
+        if (mod_sofia_globals.debug_sla > 1) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
+        }
+        sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_gather_state_callback, sh);
+        switch_safe_free(sql);
+
+        
+        if (unseize) {
+                sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event "
+                                                         "from sip_subscriptions "
+                                                         "where hostname='%q' "
+                                                         "and sub_to_user='%q' and sub_to_host='%q' "
+                                                         "and (event='call-info' or event='line-seize')",
+                                                         mod_sofia_globals.hostname,
+                                                         to_user,
+                                                         to_host
+                                                         );
+        } else {
+                sql = switch_mprintf("select call_id,expires,sub_to_user,sub_to_host,event "
+                                                         "from sip_subscriptions "
+                                                         "where hostname='%q' "
+                                                         "and sub_to_user='%q' and sub_to_host='%q' "
+                                                         "and (event='call-info')",
+                                                         mod_sofia_globals.hostname,
+                                                         to_user,
+                                                         to_host
+                                                         );
+        }
+
+
+        if (mod_sofia_globals.debug_sla > 1) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
+        }
+        sh->profile = profile;
+        sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, broadsoft_sla_notify_callback, sh);
+        switch_safe_free(sql);
+        sh = NULL;
+        switch_core_destroy_memory_pool(&pool);
+
+
+
+        if (clear) {
+                sql = switch_mprintf("delete from sip_dialogs where sip_from_user='%q' and sip_from_host='%q' and call_info_state='seized'",
+                                                         to_user,
+                                                         to_host
+                                                         );
+
+
+                if (mod_sofia_globals.debug_sla > 1) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql);
+                }
+                sofia_glue_execute_sql(profile, &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(&sevent, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                                 switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "proto", protocol);
</span><span class="cx">                                 switch_event_add_header_string(sevent, SWITCH_STACK_BOTTOM, "login", profile->name);
</span><span class="lines">@@ -1831,7 +1897,8 @@
</span><span class="cx">
</span><span class="cx">                 switch_mutex_lock(profile->ireg_mutex);
</span><span class="cx">                 switch_assert(sql != NULL);
</span><del>-                sofia_glue_execute_sql(profile, &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("terminated");
</span><span class="lines">@@ -1843,7 +1910,7 @@
</span><span class="cx">                                 switch_snprintf(accept + strlen(accept), sizeof(accept) - strlen(accept), "%s%s ", ap->ac_type, ap->ac_next ? "," : "");
</span><span class="cx">                                 ap = ap->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->name,mod_sofia_globals.hostname, network_port, network_ip);
</span><span class="cx">                                                                 
</span><del>-                        if (mod_sofia_globals.debug_presence > 0) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n", profile->name, from_user, from_host, to_user, to_host);
</del><ins>+                        switch_assert(sql != NULL);
+
+                        if (mod_sofia_globals.debug_presence > 0 || mod_sofia_globals.debug_sla > 0) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s SUBSCRIBE %s@%s %s@%s\n%s\n",
+                                                                 profile->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, &sql, SWITCH_TRUE);
</del><span class="cx">
</span><ins>+                        sofia_glue_actually_execute_sql(profile, sql, profile->ireg_mutex);
+                        switch_safe_free(sql);
+                        
</ins><span class="cx">                         sstr = switch_mprintf("active;expires=%ld", 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->sip_call_info) {
</span><span class="cx">                                 full_call_info = sip_header_as_string(profile->home, (void *) sip->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("0"),
-                                         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("0"),
+                                                 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, "line-seize")) {
-                                if (full_call_info) {
-                                        sql = switch_mprintf("select call_id,expires,'%q',0 from sip_subscriptions where hostname='%q' "
</del><ins>+                                if (!strcasecmp(event, "line-seize")) {
+                                        sync_sla(profile, to_user, to_host, SWITCH_FALSE, SWITCH_TRUE);
+
+#if 0
+                                
+                                        
+                                        sql = switch_mprintf("select call_id,expires,'%q',0,sub_to_host from sip_subscriptions where hostname='%q' "
</ins><span class="cx">                                                                                  "and sub_to_user='%q' and sub_to_host='%q' "
</span><del>-                                                                                 "and event='call-info' and contact != '%q'",
-                                                                                 full_call_info,
</del><ins>+                                                                                 "and event='call-info' ",
+                                                                                 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 > 1) {
</del><ins>+                                        if (mod_sofia_globals.debug_sla > 1) {
</ins><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "UNSEIZE SQL %s\n", 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->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, "line-seize")) {
</span><span class="cx">                                 char *full_call_info = NULL;
</span><del>-
</del><ins>+                                char *p;
+                                
</ins><span class="cx">                                 if (sip->sip_call_info) {
</span><span class="cx">                                         full_call_info = sip_header_as_string(profile->home, (void *) sip->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("line-seize"), 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("line-seize"),
+                                                         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("select sip_subscriptions.call_id,sip_subscriptions.expires,'%q',4, sip_dialogs.state,sip_dialogs.call_info, "
-                                                                                 "sip_subscriptions.sub_to_host,'','call-info' "
-                                                                                 "from sip_subscriptions left join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
-                                                                                 "and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
-                                                                                 "where sip_subscriptions.hostname='%q' "
-                                                                                 "and sub_to_user='%q' and sub_to_host='%q' "
-                                                                                 "and event='call-info'and sip_subscriptions.contact != '%q'",
-                                                                                 full_call_info,
-                                                                                 mod_sofia_globals.hostname,
</del><ins>+
+                                        sql = switch_mprintf("insert into sip_dialogs (sip_from_user,sip_from_host,call_info,call_info_state,hostname) "
+                                                                                 "values ('%q','%q','%q','seized','%q')",
</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 > 1) {
</del><ins>+
+                                        if (mod_sofia_globals.debug_sla > 1) {
</ins><span class="cx">                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SEIZE SQL %s\n", sql);
</span><span class="cx">                                         }
</span><ins>+                                        sofia_glue_actually_execute_sql(profile, sql, profile->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->ireg_mutex, sql, broadsoft_sla_callback, profile);
-                                        switch_safe_free(sql);
</del><span class="cx">                                         su_free(profile->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, "call-info")) {
</span><del>-
-#if 0
-                                int x = 0;
-                                for (x = 1; x < 5; x++) {
-                                        char tmp[128] = "";
-                                        
-                                        switch_snprintf(tmp, sizeof(tmp), "<sip:%s>;apperance-index=%d;appearance-state=idle", to_host, x);
-                                        nua_notify(nh,
-                                                         SIPTAG_EXPIRES_STR(exp_delta_str),
-                                                         SIPTAG_SUBSCRIPTION_STATE_STR(sstr),
-                                                         SIPTAG_EVENT_STR("call-info"), SIPTAG_CALL_INFO_STR(tmp), TAG_END());
-                                }
-#endif
-
-                                        
-
-                                sql = switch_mprintf("select sip_subscriptions.call_id,sip_subscriptions.expires,'',2, sip_dialogs.state,sip_dialogs.call_info, "
-                                                                         "sip_subscriptions.sub_to_host "
-                                                                         "from sip_subscriptions inner join sip_dialogs on sip_subscriptions.sub_to_user=sip_dialogs.sip_from_user "
-                                                                         "and sip_subscriptions.sub_to_host=sip_dialogs.sip_from_host "
-                                                                         "where sip_subscriptions.hostname='%q' "
-                                                                         "and sub_to_user='%q' and sub_to_host='%q' "
-                                                                         "and event='call-info' and sip_subscriptions.contact != '%q'",
-                                                                         mod_sofia_globals.hostname,
-                                                                         to_user,
-                                                                         to_host,
-                                                                         contact_str
-                                                                         );
-
-                                if (mod_sofia_globals.debug_presence > 1) {
-                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CALL-INFO SQL %s\n", sql);
-                                }
-                                sofia_glue_execute_sql_callback(profile, profile->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("application/notice"),
-                                 SIPTAG_PAYLOAD_STR("Note: Come to ClueCon http://www.cluecon.com\n\n"), TAG_END());
-#endif
-
</del><span class="cx">                 switch_safe_free(sstr);
</span><span class="cx">
</span><span class="cx">                 if (!strcasecmp(event, "message-summary")) {                
</span><span class="cx">                         if ((sql = switch_mprintf(
</span><span class="cx">                                                                          "select proto,sip_user,'%q',sub_to_user,sub_to_host,event,contact,call_id,full_from,"
</span><span class="cx">                                                                          "full_via,expires,user_agent,accept,profile_name,network_ip"
</span><del>-                                                                         " from sip_subscriptions where event='message-summary' and sip_user='%q' and (sip_host='%q' or presence_hosts like '%%%q%%')",
</del><ins>+                                                                         " from sip_subscriptions where event='message-summary' and sip_user='%q' "
+                                                                         "and (sip_host='%q' or presence_hosts like '%%%q%%')",
</ins><span class="cx">                                                                          to_host, to_user, to_host, to_host))) {
</span><span class="cx">                                 sofia_glue_execute_sql_callback(profile, profile->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 = "alerting";
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><ins>+
</ins><span class="cx">                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-info-state", call_info_state);
</span><span class="cx">                         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "presence-call-info", 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, "presence_call_info", NULL);
+                }
+
</ins><span class="cx">                 switch_mutex_lock(channel->state_mutex);
</span><span class="cx">                 last_state = channel->state;
</span><span class="cx">                 channel->state = CS_HANGUP;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>