<!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][15133] </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=15133">15133</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-10-09 15:48:24 -0500 (Fri, 09 Oct 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>fix att-xfer...AGAIN</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_bridgec">freeswitch/trunk/src/switch_ivr_bridge.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 (15132 => 15133)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_channel.h        2009-10-09 19:29:30 UTC (rev 15132)
+++ freeswitch/trunk/src/include/switch_channel.h        2009-10-09 20:48:24 UTC (rev 15133)
</span><span class="lines">@@ -262,6 +262,9 @@
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(void) switch_channel_variable_last(switch_channel_t *channel);
</span><span class="cx">
</span><ins>+
+SWITCH_DECLARE(switch_status_t) switch_channel_caller_extension_masquerade(switch_channel_t *orig_channel, switch_channel_t *new_channel, uint32_t offset);
+
</ins><span class="cx"> /*!
</span><span class="cx"> \brief Assign a caller extension to a given channel
</span><span class="cx"> \param channel channel to assign extension to
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15132 => 15133)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-10-09 19:29:30 UTC (rev 15132)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-10-09 20:48:24 UTC (rev 15133)
</span><span class="lines">@@ -4272,10 +4272,8 @@
</span><span class="cx">                                                         switch_channel_set_variable(channel_b, SWITCH_HOLDING_UUID_VARIABLE, br_a);
</span><span class="cx">                                                         switch_channel_set_flag(channel_b, CF_XFER_ZOMBIE);
</span><span class="cx">                                                         switch_channel_set_flag(channel_b, CF_TRANSFER);
</span><del>-
-                                                        //switch_channel_set_variable(channel_b, "park_timeout", "2");
-                                                        //switch_channel_set_state(channel_b, CS_PARK);
</del><span class="cx">                                                         
</span><ins>+                                                        
</ins><span class="cx">                                                         if ((a_session = switch_core_session_locate(br_a))) {
</span><span class="cx">                                                                 const char *moh = profile->hold_music;
</span><span class="cx">                                                                 switch_channel_t *a_channel = switch_core_session_get_channel(a_session);
</span><span class="lines">@@ -4307,8 +4305,8 @@
</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 (0 && b_tech_pvt) {
</del><ins>+                                                                
+                                                                if (1 && 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></pre></div>
<a id="freeswitchtrunksrcswitch_channelc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_channel.c (15132 => 15133)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_channel.c        2009-10-09 19:29:30 UTC (rev 15132)
+++ freeswitch/trunk/src/switch_channel.c        2009-10-09 20:48:24 UTC (rev 15133)
</span><span class="lines">@@ -1664,6 +1664,72 @@
</span><span class="cx">         switch_mutex_unlock(channel->state_mutex);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+SWITCH_DECLARE(switch_status_t) switch_channel_caller_extension_masquerade(switch_channel_t *orig_channel, switch_channel_t *new_channel, uint32_t offset)
+{
+        switch_caller_profile_t *caller_profile;
+        switch_caller_extension_t *extension = NULL, *orig_extension = NULL;
+        switch_caller_application_t *ap;
+        switch_status_t status = SWITCH_STATUS_FALSE;
+        switch_event_header_t *hi = NULL;
+        const char *no_copy = switch_channel_get_variable(orig_channel, "attended_transfer_no_copy");
+        char *dup;
+        int i, argc = 0;
+        char *argv[128];
+
+        if (no_copy) {
+                dup = switch_core_session_strdup(new_channel->session, no_copy);
+                argc = switch_separate_string(dup, ',', argv, (sizeof(argv) / sizeof(argv[0])));
+        }
+
+
+        switch_mutex_lock(orig_channel->profile_mutex);
+        switch_mutex_lock(new_channel->profile_mutex);
+        
+        
+        caller_profile = switch_caller_profile_clone(new_channel->session, new_channel->caller_profile);
+        switch_assert(caller_profile);
+        extension = switch_caller_extension_new(new_channel->session, caller_profile->destination_number, caller_profile->destination_number);
+        orig_extension = switch_channel_get_caller_extension(orig_channel);
+        
+        
+        if (extension && orig_extension) {
+                for(ap = orig_extension->current_application; ap && offset > 0; offset--) {
+                        ap = ap->next;
+                }
+                
+                for (; ap; ap = ap->next) {
+                        switch_caller_extension_add_application(new_channel->session, extension, ap->application_name, ap->application_data);
+                }
+                
+                caller_profile->destination_number = switch_core_strdup(caller_profile->pool, orig_channel->caller_profile->destination_number);
+                switch_channel_set_caller_profile(new_channel, caller_profile);
+                switch_channel_set_caller_extension(new_channel, extension);
+
+                for (hi = orig_channel->variables->headers; hi; hi = hi->next) {
+                        int ok = 1;
+                        for (i = 0; i < argc; i++) {
+                                if (!strcasecmp(argv[i], hi->name)) {
+                                        ok = 0;
+                                        break;
+                                }
+                        }
+                        
+                        if (!ok) continue;
+
+                        switch_channel_set_variable(new_channel, hi->name, hi->value);
+                }
+
+                status = SWITCH_STATUS_SUCCESS;
+        }
+
+
+        switch_mutex_unlock(new_channel->profile_mutex);
+        switch_mutex_unlock(orig_channel->profile_mutex);
+
+
+        return status;
+}
+
</ins><span class="cx"> SWITCH_DECLARE(void) switch_channel_set_caller_extension(switch_channel_t *channel, switch_caller_extension_t *caller_extension)
</span><span class="cx"> {
</span><span class="cx">         switch_assert(channel != NULL);
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_ivr_bridgec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_ivr_bridge.c (15132 => 15133)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_ivr_bridge.c        2009-10-09 19:29:30 UTC (rev 15132)
+++ freeswitch/trunk/src/switch_ivr_bridge.c        2009-10-09 20:48:24 UTC (rev 15133)
</span><span class="lines">@@ -569,7 +569,8 @@
</span><span class="cx">         } else if (state < CS_HANGUP && (var = switch_channel_get_variable(channel, SWITCH_TRANSFER_AFTER_BRIDGE_VARIABLE))) {
</span><span class="cx">                 transfer_after_bridge(session, var);
</span><span class="cx">         } else {
</span><del>-                if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) && bd && !bd->clean_exit
</del><ins>+                if (!switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_REDIRECT) &&
+                        !switch_channel_test_flag(channel, CF_XFER_ZOMBIE) && bd && !bd->clean_exit
</ins><span class="cx">                         && state != CS_PARK && state != CS_ROUTING && !switch_channel_test_flag(channel, CF_INNER_BRIDGE)) {
</span><span class="cx">                         switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
</span><span class="cx">                 }
</span><span class="lines">@@ -1082,8 +1083,8 @@
</span><span class="cx">
</span><span class="cx">         state = switch_channel_get_state(caller_channel);
</span><span class="cx">         
</span><del>-        if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !switch_channel_test_flag(caller_channel, CF_REDIRECT)
-                && !a_leg->clean_exit && !inner_bridge) {
</del><ins>+        if (!switch_channel_test_flag(caller_channel, CF_TRANSFER) && !switch_channel_test_flag(caller_channel, CF_REDIRECT) &&
+                !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE) && !a_leg->clean_exit && !inner_bridge) {
</ins><span class="cx">                 if ((state != CS_EXECUTE && state != CS_SOFT_EXECUTE && state != CS_PARK && state != CS_ROUTING) ||
</span><span class="cx">                         (switch_channel_test_flag(peer_channel, CF_ANSWERED) && state < CS_HANGUP)) {
</span><span class="cx">                         if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_PARK_AFTER_BRIDGE_VARIABLE))) {
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_ivr_originatec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_ivr_originate.c (15132 => 15133)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_ivr_originate.c        2009-10-09 19:29:30 UTC (rev 15132)
+++ freeswitch/trunk/src/switch_ivr_originate.c        2009-10-09 20:48:24 UTC (rev 15133)
</span><span class="lines">@@ -2078,6 +2078,9 @@
</span><span class="cx">                                         if (switch_channel_media_ready(caller_channel)) {
</span><span class="cx">                                                 tstatus = switch_core_session_read_frame(oglobals.session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
</span><span class="cx">                                                 if (!SWITCH_READ_ACCEPTABLE(tstatus)) {
</span><ins>+                                                        if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
+                                                                continue;
+                                                        }
</ins><span class="cx">                                                         break;
</span><span class="cx">                                                 }
</span><span class="cx">                                         } else {
</span><span class="lines">@@ -2133,6 +2136,9 @@
</span><span class="cx">                                                 }
</span><span class="cx">                                                 
</span><span class="cx">                                                 if (switch_core_session_write_frame(oglobals.session, &write_frame, SWITCH_IO_FLAG_NONE, 0) != SWITCH_STATUS_SUCCESS) {
</span><ins>+                                                        if (switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
+                                                                continue;
+                                                        }
</ins><span class="cx">                                                         break;
</span><span class="cx">                                                 }
</span><span class="cx">                                         }
</span><span class="lines">@@ -2156,7 +2162,7 @@
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="cx">                         
</span><del>-                        if (caller_channel && !switch_channel_ready(caller_channel)) {
</del><ins>+                        if (caller_channel && !switch_channel_ready(caller_channel) && !switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) {
</ins><span class="cx">                                 oglobals.idx = IDX_CANCEL;
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="lines">@@ -2206,7 +2212,7 @@
</span><span class="cx">                                         const char *context = switch_channel_get_variable(peer_channel, "context");
</span><span class="cx">                                         const char *dialplan = switch_channel_get_variable(peer_channel, "dialplan");
</span><span class="cx">                                         switch_core_session_t *holding_session;
</span><del>-
</del><ins>+                                        
</ins><span class="cx">                                         if (caller_channel) {
</span><span class="cx">                                                 if (switch_strlen_zero(context)) {
</span><span class="cx">                                                         context = switch_channel_get_variable(caller_channel, "context");
</span><span class="lines">@@ -2225,7 +2231,21 @@
</span><span class="cx">                                         }
</span><span class="cx">
</span><span class="cx">                                         if ((holding_session = switch_core_session_locate(holding))) {
</span><del>-                                                switch_ivr_session_transfer(holding_session, dest, dialplan, context);
</del><ins>+                                                switch_channel_t *holding_channel = switch_core_session_get_channel(holding_session);
+                                                switch_status_t mstatus = SWITCH_STATUS_FALSE;
+                                                
+                                                if (caller_channel) {
+                                                        if ((mstatus = switch_channel_caller_extension_masquerade(caller_channel, holding_channel, 1)) == SWITCH_STATUS_SUCCESS) {
+                                                                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);
+                                                        }
+                                                }
+
+                                                if (mstatus != SWITCH_STATUS_SUCCESS) {
+                                                        switch_ivr_session_transfer(holding_session, dest, dialplan, context);
+                                                }
+
</ins><span class="cx">                                                 switch_core_session_rwunlock(holding_session);
</span><span class="cx">                                                 holding = NULL;
</span><span class="cx">                                                 holding_session = NULL;
</span><span class="lines">@@ -2233,6 +2253,7 @@
</span><span class="cx">
</span><span class="cx">                                         switch_channel_hangup(peer_channel, SWITCH_CAUSE_ATTENDED_TRANSFER);
</span><span class="cx">                                         switch_core_session_rwunlock(peer_session);
</span><ins>+                                        force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER;
</ins><span class="cx">                                 } else {
</span><span class="cx">                                         if (peer_channel && switch_channel_ready(peer_channel)) {
</span><span class="cx">                                                 force_reason = SWITCH_CAUSE_ATTENDED_TRANSFER;
</span><span class="lines">@@ -2273,9 +2294,7 @@
</span><span class="cx">                                 if (i != oglobals.idx) {
</span><span class="cx">                                         holding = NULL;
</span><span class="cx">
</span><del>-                                        if (force_reason != SWITCH_CAUSE_NONE) {
-                                                reason = force_reason;
-                                        } else if (oglobals.idx == IDX_TIMEOUT || to) {
</del><ins>+                                        if (oglobals.idx == IDX_TIMEOUT || to) {
</ins><span class="cx">                                                 reason = SWITCH_CAUSE_NO_ANSWER;
</span><span class="cx">                                         } else {
</span><span class="cx">                                                 if (oglobals.idx == IDX_CANCEL) {
</span><span class="lines">@@ -2437,6 +2456,8 @@
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session), SWITCH_LOG_DEBUG,
</span><span class="cx">                                                                          "Originate Cancelled by originator termination Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause));
</span><span class="cx">
</span><ins>+                                } else if (oglobals.idx == IDX_TIMEOUT) {
+                                        *cause = SWITCH_CAUSE_NO_ANSWER;
</ins><span class="cx">                                 } else {
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(oglobals.session), SWITCH_LOG_DEBUG,
</span><span class="cx">                                                                          "Originate Resulted in Error Cause: %d [%s]\n", *cause, switch_channel_cause2str(*cause));
</span><span class="lines">@@ -2561,6 +2582,10 @@
</span><span class="cx">                 switch_channel_clear_flag(caller_channel, CF_XFER_ZOMBIE);
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        if (force_reason != SWITCH_CAUSE_NONE) {
+                *cause = force_reason;
+        }
+
</ins><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>