<!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][15134] </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=15134">15134</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-10-09 17:28:31 -0500 (Fri, 09 Oct 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>cleanup more on att-xfer</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_channelh">freeswitch/trunk/src/include/switch_channel.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_channelc">freeswitch/trunk/src/switch_channel.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_ivr_originatec">freeswitch/trunk/src/switch_ivr_originate.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeswitch_channelh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_channel.h (15133 => 15134)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_channel.h        2009-10-09 20:48:24 UTC (rev 15133)
+++ freeswitch/trunk/src/include/switch_channel.h        2009-10-09 22:28:31 UTC (rev 15134)
</span><span class="lines">@@ -263,6 +263,8 @@
</span><span class="cx"> SWITCH_DECLARE(void) switch_channel_variable_last(switch_channel_t *channel);
</span><span class="cx">
</span><span class="cx">
</span><ins>+SWITCH_DECLARE(void) switch_channel_restart(switch_channel_t *channel);
+
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_channel_caller_extension_masquerade(switch_channel_t *orig_channel, switch_channel_t *new_channel, uint32_t offset);
</span><span class="cx">
</span><span class="cx"> /*!
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15133 => 15134)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-10-09 20:48:24 UTC (rev 15133)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-10-09 22:28:31 UTC (rev 15134)
</span><span class="lines">@@ -4146,6 +4146,34 @@
</span><span class="cx">
</span><span class="cx"> /*---------------------------------------*/
</span><span class="cx">
</span><ins>+static switch_status_t xfer_hanguphook(switch_core_session_t *session)
+{
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        switch_channel_state_t state = switch_channel_get_state(channel);
+
+        if (state == CS_HANGUP) {
+                switch_core_session_t *ksession;
+                const char *uuid = switch_channel_get_variable(channel, "att_xfer_kill_uuid");
+                
+                if (uuid && (ksession = switch_core_session_force_locate(uuid))) {
+                        switch_channel_t *kchannel = switch_core_session_get_channel(ksession);
+                        
+                        switch_channel_clear_flag(kchannel, CF_XFER_ZOMBIE);
+                        switch_channel_clear_flag(kchannel, CF_TRANSFER);
+                        if (switch_channel_up(kchannel)) {
+                                switch_channel_hangup(kchannel, SWITCH_CAUSE_NORMAL_CLEARING);
+                        }
+
+                        switch_core_session_rwunlock(ksession);
+                }
+
+                switch_core_event_hook_remove_state_change(session, xfer_hanguphook);
+
+        }
+
+        return SWITCH_STATUS_SUCCESS;
+}
+
</ins><span class="cx"> void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, switch_core_session_t *session, sip_t const *sip, tagi_t tags[])
</span><span class="cx"> {
</span><span class="cx">         /* Incoming refer */
</span><span class="lines">@@ -4279,34 +4307,31 @@
</span><span class="cx">                                                                 switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
</span><span class="cx">                                                                 const char *tmp;
</span><span class="cx">
</span><ins>+                                                                switch_core_event_hook_add_state_change(a_session, xfer_hanguphook);
+                                                                switch_channel_set_variable(a_channel, "att_xfer_kill_uuid", switch_core_session_get_uuid(b_session));
+
</ins><span class="cx">                                                                 if ((tmp = switch_channel_get_variable(a_channel, SWITCH_HOLD_MUSIC_VARIABLE))) {
</span><span class="cx">                                                                         moh = tmp;
</span><span class="cx">                                                                 }
</span><del>-
</del><ins>+                                                                
</ins><span class="cx">                                                                 if (!strcasecmp(moh, "silence")) {
</span><span class="cx">                                                                         moh = NULL;
</span><span class="cx">                                                                 }
</span><span class="cx">                                                                 
</span><del>-                                                                //switch_channel_set_variable(a_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true");
-                                                                
</del><span class="cx">                                                                 if (moh) {
</span><span class="cx">                                                                         char *xdest;
</span><del>-                                                                        //switch_channel_set_variable_printf(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE,
-                                                                        //                                                         "'endless_playback:%s,park':inline", moh);
</del><span class="cx">                                                                         xdest = switch_core_session_sprintf(a_session, "endless_playback:%s,park", moh);
</span><span class="cx">                                                                         switch_ivr_session_transfer(a_session, xdest, "inline", NULL);
</span><span class="cx">                                                                 } else {
</span><del>-                                                                        //switch_channel_set_variable(a_channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE, "park:inline");
</del><span class="cx">                                                                         switch_ivr_session_transfer(a_session, "park", "inline", NULL);
</span><span class="cx">                                                                 }
</span><del>-                                                                //switch_channel_set_variable_printf(a_channel, "park_command", "moh");
</del><ins>+                                                                
</ins><span class="cx">                                                                 switch_core_session_rwunlock(a_session);
</span><span class="cx">
</span><span class="cx">                                                                 nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag"),
</span><span class="cx">                                                                                  NUTAG_SUBSTATE(nua_substate_terminated), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK"), SIPTAG_EVENT_STR(etmp), TAG_END());
</span><span class="cx">
</span><del>-                                                                
-                                                                if (1 && b_tech_pvt) {
</del><ins>+                                                                if (b_tech_pvt) {
</ins><span class="cx">                                                                         sofia_set_flag_locked(b_tech_pvt, TFLAG_BYE);
</span><span class="cx">                                                                         nua_bye(b_tech_pvt->nh,
</span><span class="cx">                                                                                         SIPTAG_REASON_STR("Q.850;cause=16;text=\"normal_clearing\""),
</span><span class="lines">@@ -4319,11 +4344,6 @@
</span><span class="cx">                                                                                  SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden"), SIPTAG_EVENT_STR(etmp), TAG_END());
</span><span class="cx">                                                         }
</span><span class="cx">
</span><del>-                                                        
-                                                        //switch_channel_set_variable(channel_b, "park_timeout", "2");
-                                                        //switch_channel_set_state(channel_b, CS_PARK);
-                                                        
-                                                                                        
</del><span class="cx">                                                 } else if (br_a && br_b) {
</span><span class="cx">                                                         switch_core_session_t *tmp = NULL;
</span><span class="cx">                                                         
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_channelc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_channel.c (15133 => 15134)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_channel.c        2009-10-09 20:48:24 UTC (rev 15133)
+++ freeswitch/trunk/src/switch_channel.c        2009-10-09 22:28:31 UTC (rev 15134)
</span><span class="lines">@@ -1664,6 +1664,22 @@
</span><span class="cx">         switch_mutex_unlock(channel->state_mutex);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+SWITCH_DECLARE(void) switch_channel_restart(switch_channel_t *channel)
+{
+        switch_channel_set_state(channel, CS_RESET);
+        switch_channel_wait_for_state_timeout(channel, CS_RESET, 5000);
+        switch_channel_set_state(channel, CS_EXECUTE);
+}
+
+/* XXX This is a somewhat simple operation. Were essentially taking the extension that one channel
+ was executing and generating a new extension for another channel that starts out where the
+ original one left off with an optional forward offset. Since all we are really doing is
+ copying a few basic pool-allocated structures from one channel to another there really is
+ not much to worry about here in terms of threading since we use read-write locks.
+ While the features are nice, they only really are needed in one specific crazy attended
+ transfer scenario where one channel was in the middle of calling a particular extension
+ when it was rudely cut off by a transfer key press. XXX */
+
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_channel_caller_extension_masquerade(switch_channel_t *orig_channel, switch_channel_t *new_channel, uint32_t offset)
</span><span class="cx"> {
</span><span class="cx">         switch_caller_profile_t *caller_profile;
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_ivr_originatec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_ivr_originate.c (15133 => 15134)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_ivr_originate.c        2009-10-09 20:48:24 UTC (rev 15133)
+++ freeswitch/trunk/src/switch_ivr_originate.c        2009-10-09 22:28:31 UTC (rev 15134)
</span><span class="lines">@@ -2204,13 +2204,21 @@
</span><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><del>-
</del><ins>+                                
</ins><span class="cx">                         end_search:
</span><span class="cx">
</span><del>-                                if (peer_channel && (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL)) {
-                                        const char *dest = switch_channel_get_variable(peer_channel, "destination_number");
-                                        const char *context = switch_channel_get_variable(peer_channel, "context");
-                                        const char *dialplan = switch_channel_get_variable(peer_channel, "dialplan");
</del><ins>+                                if (peer_channel && switch_channel_down(peer_channel)) {
+                                        switch_core_session_rwunlock(peer_session);
+                                        peer_session = NULL;
+                                        peer_channel = NULL;
+
+                                }
+                                
+                                if (oglobals.idx == IDX_TIMEOUT || to || oglobals.idx == IDX_KEY_CANCEL || oglobals.idx == IDX_CANCEL ||
+                                        (!peer_session && oglobals.idx == IDX_NADA)) {
+                                        const char *dest = NULL;
+                                        const char *context = NULL;
+                                        const char *dialplan = NULL;
</ins><span class="cx">                                         switch_core_session_t *holding_session;
</span><span class="cx">                                         
</span><span class="cx">                                         if (caller_channel) {
</span><span class="lines">@@ -2236,14 +2244,21 @@
</span><span class="cx">                                                 
</span><span class="cx">                                                 if (caller_channel) {
</span><span class="cx">                                                         if ((mstatus = switch_channel_caller_extension_masquerade(caller_channel, holding_channel, 1)) == SWITCH_STATUS_SUCCESS) {
</span><del>-                                                                switch_channel_set_state(holding_channel, CS_RESET);
-                                                                switch_channel_wait_for_state_timeout(holding_channel, CS_RESET, 5000);
-                                                                switch_channel_set_state(holding_channel, CS_EXECUTE);
</del><ins>+                                                                switch_channel_restart(holding_channel);
</ins><span class="cx">                                                         }
</span><span class="cx">                                                 }
</span><span class="cx">
</span><span class="cx">                                                 if (mstatus != SWITCH_STATUS_SUCCESS) {
</span><del>-                                                        switch_ivr_session_transfer(holding_session, dest, dialplan, context);
</del><ins>+                                                        if (peer_channel) {
+                                                                dest = switch_channel_get_variable(peer_channel, "destination_number");
+                                                                context = switch_channel_get_variable(peer_channel, "context");
+                                                                dialplan = switch_channel_get_variable(peer_channel, "dialplan");
+                                                        } else if (caller_channel) {
+                                                                dest = switch_channel_get_variable(caller_channel, "destination_number");
+                                                        }
+                                                        if (dest) {
+                                                                switch_ivr_session_transfer(holding_session, dest, dialplan, context);
+                                                        }
</ins><span class="cx">                                                 }
</span><span class="cx">
</span><span class="cx">                                                 switch_core_session_rwunlock(holding_session);
</span><span class="lines">@@ -2251,8 +2266,10 @@
</span><span class="cx">                                                 holding_session = NULL;
</span><span class="cx">                                         }
</span><span class="cx">
</span><del>-                                        switch_channel_hangup(peer_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
-                                        switch_core_session_rwunlock(peer_session);
</del><ins>+                                        if (peer_channel) {
+                                                switch_channel_hangup(peer_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
+                                                switch_core_session_rwunlock(peer_session);
+                                        }
</ins><span class="cx">                                         force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER;
</span><span class="cx">                                 } else {
</span><span class="cx">                                         if (peer_channel && switch_channel_ready(peer_channel)) {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>