<!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][15201] </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=15201">15201</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-10-22 17:11:28 -0500 (Thu, 22 Oct 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Let's go Camping!
Call Campon (part of bridge app)
Variables:
campon=[true|false]
campon_retries=<number of call attempts>
campon_timeout=<duration of each call attempt>
campon_sleep=<seconds to sleep between retries>
campon_fallback_exten=<extension to transfer to on failure>
campon_fallback_dialplan=<dialplan>
campon_fallback_context=<context>
campon_hold_music=<alternate music></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_typesh">freeswitch/trunk/src/include/switch_types.h</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_dptoolsmod_dptoolsc">freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.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_typesh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_types.h (15200 => 15201)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_types.h        2009-10-22 20:55:12 UTC (rev 15200)
+++ freeswitch/trunk/src/include/switch_types.h        2009-10-22 22:11:28 UTC (rev 15201)
</span><span class="lines">@@ -917,6 +917,8 @@
</span><span class="cx">         CF_XFER_ZOMBIE,
</span><span class="cx">         CF_MEDIA_ACK,
</span><span class="cx">         CF_THREAD_SLEEPING,
</span><ins>+        CF_DISABLE_RINGBACK,
+        CF_NOT_READY,
</ins><span class="cx">         /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
</span><span class="cx">         CF_FLAG_MAX
</span><span class="cx"> } switch_channel_flag_t;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_dptoolsmod_dptoolsc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (15200 => 15201)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c        2009-10-22 20:55:12 UTC (rev 15200)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c        2009-10-22 22:11:28 UTC (rev 15201)
</span><span class="lines">@@ -2054,13 +2054,47 @@
</span><span class="cx"> /*                                                                Bridge Functions                                                                */
</span><span class="cx"> /********************************************************************************/
</span><span class="cx">
</span><ins>+struct camping_stake {
+        switch_core_session_t *session;
+        int running;
+        const char *moh;
+};
+
+static void *SWITCH_THREAD_FUNC camp_music_thread(switch_thread_t *thread, void *obj)
+{
+        struct camping_stake *stake = (struct camping_stake *) obj;
+        switch_core_session_t *session = stake->session;
+        switch_channel_t *channel = switch_core_session_get_channel(stake->session);
+        const char *moh = stake->moh;
+
+        switch_core_session_read_lock(session);
+        while(stake->running && switch_channel_ready(channel)) {
+                if (!strcasecmp(moh, "silence")) {
+                        switch_ivr_collect_digits_callback(session, NULL, 0, 0);
+                } else {
+                        switch_ivr_play_file(session, NULL, stake->moh, NULL);
+                }
+        }
+        switch_core_session_rwunlock(session);
+
+        return NULL;
+}
+
</ins><span class="cx"> SWITCH_STANDARD_APP(audio_bridge_function)
</span><span class="cx"> {
</span><span class="cx">         switch_channel_t *caller_channel = switch_core_session_get_channel(session);
</span><span class="cx">         switch_core_session_t *peer_session = NULL;
</span><del>-        const char *continue_on_fail = NULL, *failure_causes = NULL;
</del><ins>+        const char *continue_on_fail = NULL, *failure_causes = NULL,
+                *v_campon = NULL, *v_campon_retries, *v_campon_sleep, *v_campon_timeout, *v_campon_fallback_exten = NULL;
</ins><span class="cx">         switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
</span><del>-
</del><ins>+        int campon_retries = 100, campon_timeout = 10, campon_sleep = 10, tmp, do_xfer = 0, camping = 0, fail = 0, thread_started = 0;
+        struct camping_stake stake = { 0 };
+        const char *moh = NULL;
+        switch_thread_t *thread = NULL;
+        switch_threadattr_t *thd_attr = NULL;
+        char *camp_data = NULL;
+        switch_status_t status;
+        
</ins><span class="cx">         if (switch_strlen_zero(data)) {
</span><span class="cx">                 return;
</span><span class="cx">         }
</span><span class="lines">@@ -2068,7 +2102,133 @@
</span><span class="cx">         continue_on_fail = switch_channel_get_variable(caller_channel, "continue_on_fail");
</span><span class="cx">         failure_causes = switch_channel_get_variable(caller_channel, "failure_causes");
</span><span class="cx">
</span><del>-        if (switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE) != SWITCH_STATUS_SUCCESS) {
</del><ins>+        if ((v_campon = switch_channel_get_variable(caller_channel, "campon")) && switch_true(v_campon)) {
+                const char *cid_name = NULL;
+                const char *cid_number = NULL;
+                
+                if (!(cid_name = switch_channel_get_variable(caller_channel, "effective_caller_id_name"))) {
+                        cid_name = switch_channel_get_variable(caller_channel, "caller_id_name");
+                }
+
+                if (!(cid_number = switch_channel_get_variable(caller_channel, "effective_caller_id_number"))) {
+                        cid_number = switch_channel_get_variable(caller_channel, "caller_id_number");
+                }
+
+                if (cid_name && !cid_number) {
+                        cid_number = cid_name;
+                }
+
+                if (cid_number && !cid_name) {
+                        cid_name = cid_number;
+                }
+
+                v_campon_retries = switch_channel_get_variable(caller_channel, "campon_retries");
+                v_campon_timeout = switch_channel_get_variable(caller_channel, "campon_timeout");
+                v_campon_sleep = switch_channel_get_variable(caller_channel, "campon_sleep");
+                v_campon_fallback_exten = switch_channel_get_variable(caller_channel, "campon_fallback_exten");
+                
+                if (v_campon_retries) {
+                        if ((tmp = atoi(v_campon_retries)) > 0) {
+                                campon_retries = tmp;
+                        }
+                }
+
+                if (v_campon_timeout) {
+                        if ((tmp = atoi(v_campon_timeout)) > 0) {
+                                campon_timeout = tmp;
+                        }
+                }
+
+                if (v_campon_sleep) {
+                        if ((tmp = atoi(v_campon_sleep)) > 0) {
+                                campon_sleep = tmp;
+                        }
+                }
+
+                switch_channel_answer(caller_channel);
+                camping = 1;
+
+                if (cid_name && cid_number) {
+                        camp_data = switch_core_session_sprintf(session, "{origination_caller_id_name='%s',origination_caller_id_number='%s'}%s",
+                                                                                                        cid_name, cid_number, data);
+                } else {
+                        camp_data = (char *)data;
+                }
+
+                if (!(moh = switch_channel_get_variable(caller_channel, "hold_music"))) {
+                        moh = switch_channel_get_variable(caller_channel, "campon_hold_music");
+                }
+
+                do {
+                        fail = 0;
+                        status = switch_ivr_originate(NULL, &peer_session, &cause, camp_data, campon_timeout, NULL, NULL, NULL, NULL, NULL, SOF_NONE);
+                        
+                        if (!switch_channel_ready(caller_channel)) {
+                                fail = 1;
+                                break;
+                        }
+                        
+                        if (status == SWITCH_STATUS_SUCCESS) {
+                                camping = 0;
+                                break;
+                        } else {
+                                fail = 1;
+                        }
+                        
+                        if (camping) {
+                                
+                                if (!thread_started && fail && moh && !switch_channel_test_flag(caller_channel, CF_PROXY_MODE) &&
+                                        !switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) &&
+                                        !switch_true(switch_channel_get_variable(caller_channel, "bypass_media"))) {
+                                        switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session));
+                                        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+                                        stake.running = 1;
+                                        stake.moh = moh;
+                                        stake.session = session;
+                                        switch_thread_create(&thread, thd_attr, camp_music_thread, &stake, switch_core_session_get_pool(session));
+                                        thread_started = 1;
+                                }
+
+
+                                if (--campon_retries <= 0) {
+                                        camping = 0;
+                                        do_xfer = 1;
+                                        break;
+                                }
+
+                                if (fail) {
+                                        int64_t wait = campon_sleep * 1000000;
+                                        
+                                        while(wait > 0 && switch_channel_ready(caller_channel)) {
+                                                switch_yield(100000);
+                                                wait -= 100000;
+                                        }
+                                }
+                        }
+                } while (camping);
+                
+                if (thread) {
+                        stake.running = 0;
+                        switch_channel_set_flag(caller_channel, CF_NOT_READY);
+                        switch_thread_join(&status, thread);
+                        switch_channel_clear_flag(caller_channel, CF_NOT_READY);
+                }
+                
+                if (do_xfer && !switch_strlen_zero(v_campon_fallback_exten)) {
+                        switch_ivr_session_transfer(session,
+                                                                                v_campon_fallback_exten,
+                                                                                switch_channel_get_variable(caller_channel, "campon_fallback_dialplan"),
+                                                                                switch_channel_get_variable(caller_channel, "campon_fallback_context"));
+                        return;
+                }
+
+        } else {
+                if ((status = switch_ivr_originate(session, &peer_session, &cause, data, 0, NULL, NULL, NULL, NULL, NULL, SOF_NONE)) != SWITCH_STATUS_SUCCESS) {
+                        fail = 1;
+                }
+        }
+
+        if (fail) {
</ins><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Originate Failed. Cause: %s\n", switch_channel_cause2str(cause));
</span><span class="cx">
</span><span class="cx">                 /*
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_channelc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_channel.c (15200 => 15201)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_channel.c        2009-10-22 20:55:12 UTC (rev 15200)
+++ freeswitch/trunk/src/switch_channel.c        2009-10-22 22:11:28 UTC (rev 15201)
</span><span class="lines">@@ -1080,7 +1080,7 @@
</span><span class="cx">         ret = 0;
</span><span class="cx">
</span><span class="cx">         if (!channel->hangup_cause && channel->state > CS_ROUTING && channel->state < CS_HANGUP && channel->state != CS_RESET &&
</span><del>-                !switch_channel_test_flag(channel, CF_TRANSFER)) {
</del><ins>+                !switch_channel_test_flag(channel, CF_TRANSFER) && !switch_channel_test_flag(channel, CF_NOT_READY)) {
</ins><span class="cx">                 ret++;
</span><span class="cx">         }
</span><span class="cx">
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_ivr_originatec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_ivr_originate.c (15200 => 15201)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_ivr_originate.c        2009-10-22 20:55:12 UTC (rev 15200)
+++ freeswitch/trunk/src/switch_ivr_originate.c        2009-10-22 22:11:28 UTC (rev 15201)
</span><span class="lines">@@ -395,6 +395,12 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 if (switch_channel_test_flag(originate_status[i].peer_channel, CF_EARLY_MEDIA)) {
</span><ins>+                        if (oglobals->ignore_early_media == 2 && len == 1 && caller_channel && !oglobals->ignore_ring_ready) {
+                                switch_channel_pass_callee_id(originate_status[0].peer_channel, caller_channel);
+                                switch_channel_ring_ready(caller_channel);
+                                oglobals->sent_ring = 1;
+                        }
+
</ins><span class="cx">                         if (!originate_status[i].early_media) {
</span><span class="cx">                                 originate_status[i].early_media = 1;
</span><span class="cx">                                 if (oglobals->early_ok) {
</span><span class="lines">@@ -765,6 +771,10 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">                 
</span><ins>+                if (switch_channel_test_flag(caller_channel, CF_DISABLE_RINGBACK)) {
+                        ringback_data = NULL;
+                }
+
</ins><span class="cx">                 if (ringback_data) {
</span><span class="cx">                         char *tmp_data = NULL;
</span><span class="cx">
</span><span class="lines">@@ -1301,9 +1311,14 @@
</span><span class="cx">                 *oglobals.file = '\0';
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if ((var_val = switch_event_get_header(var_event, "ignore_early_media")) && switch_true(var_val)) {
-                oglobals.early_ok = 0;
-                oglobals.ignore_early_media = 1;
</del><ins>+        if ((var_val = switch_event_get_header(var_event, "ignore_early_media"))) {
+                if (switch_true(var_val)) {
+                        oglobals.early_ok = 0;
+                        oglobals.ignore_early_media = 1;
+                } else if (!strcmp(var_val, "ring_ready")) {
+                        oglobals.early_ok = 0;
+                        oglobals.ignore_early_media = 2;
+                }
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ((var_val = switch_event_get_header(var_event, "originate_continue_on_timeout")) && switch_true(var_val)) {
</span><span class="lines">@@ -1855,7 +1870,8 @@
</span><span class="cx">                 endfor1:
</span><span class="cx">
</span><span class="cx">                         if (caller_channel) {
</span><del>-                                if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) || switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA)) {
</del><ins>+                                if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE) ||
+                                        switch_channel_test_flag(caller_channel, CF_PROXY_MEDIA) || switch_channel_test_flag(caller_channel, CF_DISABLE_RINGBACK)) {
</ins><span class="cx">                                         ringback_data = NULL;
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>