<!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][15455] </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=15455">15455</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-11-12 16:21:30 -0600 (Thu, 12 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>add switch_ivr_enterprise_originate optional new dimension to originate strings every element in :_: separated list in originate strings will fire in a dedicated thread and can contain their own {} and , and | lists</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_ivrh">freeswitch/trunk/src/include/switch_ivr.h</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_utilsh">freeswitch/trunk/src/include/switch_utils.h</a></li>
<li><a href="#freeswitchtrunksrcswitch_ivr_originatec">freeswitch/trunk/src/switch_ivr_originate.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_utilsc">freeswitch/trunk/src/switch_utils.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeswitch_ivrh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_ivr.h (15454 => 15455)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_ivr.h        2009-11-12 20:59:04 UTC (rev 15454)
+++ freeswitch/trunk/src/include/switch_ivr.h        2009-11-12 22:21:30 UTC (rev 15455)
</span><span class="lines">@@ -409,6 +409,19 @@
</span><span class="cx">                                                                                                          switch_originate_flag_t flags
</span><span class="cx">                                                                                                          );
</span><span class="cx"> 
</span><ins>+SWITCH_DECLARE(switch_status_t) switch_ivr_enterprise_originate(switch_core_session_t *session,
+                                                                                                                                switch_core_session_t **bleg,
+                                                                                                                                switch_call_cause_t *cause,
+                                                                                                                                const char *bridgeto,
+                                                                                                                                uint32_t timelimit_sec,
+                                                                                                                                const switch_state_handler_table_t *table,
+                                                                                                                                const char *cid_name_override,
+                                                                                                                                const char *cid_num_override,
+                                                                                                                                switch_caller_profile_t *caller_profile_override, 
+                                                                                                                                switch_event_t *ovars,
+                                                                                                                                switch_originate_flag_t flags
+                                                                                                                                );
+
</ins><span class="cx"> SWITCH_DECLARE(void) switch_ivr_bridge_display(switch_core_session_t *session, switch_core_session_t *peer_session);
</span><span class="cx"> 
</span><span class="cx"> /*!
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_utilsh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_utils.h (15454 => 15455)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_utils.h        2009-11-12 20:59:04 UTC (rev 15454)
+++ freeswitch/trunk/src/include/switch_utils.h        2009-11-12 22:21:30 UTC (rev 15455)
</span><span class="lines">@@ -517,6 +517,7 @@
</span><span class="cx">   \return the number of elements added to the array
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(unsigned int) switch_separate_string(char *buf, char delim, char **array, unsigned int arraylen);
</span><ins>+SWITCH_DECLARE(unsigned int) switch_separate_string_string(char *buf, char *delim, char **array, unsigned int arraylen);
</ins><span class="cx"> 
</span><span class="cx"> SWITCH_DECLARE(switch_bool_t) switch_is_number(const char *str);
</span><span class="cx"> SWITCH_DECLARE(char *) switch_strip_spaces(const char *str);
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_ivr_originatec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_ivr_originate.c (15454 => 15455)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_ivr_originate.c        2009-11-12 20:59:04 UTC (rev 15454)
+++ freeswitch/trunk/src/switch_ivr_originate.c        2009-11-12 22:21:30 UTC (rev 15455)
</span><span class="lines">@@ -1134,14 +1134,188 @@
</span><span class="cx">  
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#define OSEP &quot;:_:&quot;
+#define MAX_PEERS 128
</ins><span class="cx"> 
</span><ins>+typedef struct {
+        switch_core_session_t *session;
+        switch_core_session_t *bleg;
+        switch_call_cause_t cause;
+        const char *bridgeto;
+        uint32_t timelimit_sec;
+        const switch_state_handler_table_t *table;
+        const char *cid_name_override;
+        const char *cid_num_override;
+        switch_caller_profile_t *caller_profile_override; 
+        switch_event_t *ovars;
+        switch_originate_flag_t flags;
+        switch_status_t status;
+        int done;
+        switch_thread_t *thread;
+} enterprise_originate_handle_t;
+
+
+static void *SWITCH_THREAD_FUNC enterprise_originate_thread(switch_thread_t *thread, void *obj)
+{
+        enterprise_originate_handle_t *handle = (enterprise_originate_handle_t *) obj;
+        
+        handle-&gt;done = 0;
+        handle-&gt;status = switch_ivr_originate(NULL, &amp;handle-&gt;bleg, &amp;handle-&gt;cause, 
+                                                                                  handle-&gt;bridgeto, handle-&gt;timelimit_sec,
+                                                                                  handle-&gt;table,
+                                                                                  handle-&gt;cid_name_override,
+                                                                                  handle-&gt;cid_num_override,
+                                                                                  handle-&gt;caller_profile_override,
+                                                                                  handle-&gt;ovars,
+                                                                                  handle-&gt;flags
+                                                                                  );
+
+
+        handle-&gt;done = 1;
+        
+        return NULL;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_enterprise_originate(switch_core_session_t *session,
+                                                                                                                   switch_core_session_t **bleg,
+                                                                                                                   switch_call_cause_t *cause,
+                                                                                                                   const char *bridgeto,
+                                                                                                                   uint32_t timelimit_sec,
+                                                                                                                   const switch_state_handler_table_t *table,
+                                                                                                                   const char *cid_name_override,
+                                                                                                                   const char *cid_num_override,
+                                                                                                                   switch_caller_profile_t *caller_profile_override, 
+                                                                                                                   switch_event_t *ovars,
+                                                                                                                   switch_originate_flag_t flags
+                                                                                                                   )
+{
+        int x_argc;
+        char *x_argv[MAX_PEERS] = { 0 };
+        enterprise_originate_handle_t *hp = NULL, handles[MAX_PEERS] = { { 0 } };
+        int i;
+        switch_caller_profile_t *cp = NULL;
+        switch_channel_t *channel = NULL;
+        char *data;
+        switch_status_t status = SWITCH_STATUS_FALSE;
+        switch_threadattr_t *thd_attr = NULL;
+        int running = 0;
+        switch_status_t tstatus = SWITCH_STATUS_FALSE;
+        switch_memory_pool_t *pool;
+        switch_event_header_t *hi = NULL;
+
+        switch_core_new_memory_pool(&amp;pool);
+
+        if (zstr(bridgeto)) {
+                *cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                switch_goto_status(SWITCH_STATUS_FALSE, end);
+        }
+
+        data = switch_core_strdup(pool, bridgeto);
+
+        if (!(x_argc = switch_separate_string_string(data, OSEP, x_argv, MAX_PEERS))) {
+                *cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
+                switch_goto_status(SWITCH_STATUS_FALSE, end);
+        }
+
+        if (session) {
+                channel = switch_core_session_get_channel(session);
+                cp = switch_channel_get_caller_profile(channel);
+        }
+
+        switch_threadattr_create(&amp;thd_attr, pool);
+        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+
+        for(i = 0; i &lt; x_argc; i++) {
+                handles[i].session = session;
+                handles[i].bleg = NULL;
+                handles[i].cause = 0;
+                handles[i].bridgeto = x_argv[i];
+                handles[i].timelimit_sec = timelimit_sec;
+                handles[i].table = table;
+                handles[i].cid_name_override = cid_name_override;
+                handles[i].cid_num_override = cid_num_override;
+                handles[i].caller_profile_override = cp;
+
+                if (channel) {
+                        switch_channel_get_variables(channel, &amp;handles[i].ovars);
+                } else {
+                        switch_event_create_plain(&amp;handles[i].ovars, SWITCH_EVENT_CHANNEL_DATA);
+                }
+
+                if (ovars) {
+                        for (hi = ovars-&gt;headers; hi; hi = hi-&gt;next) {
+                                switch_event_add_header_string(handles[i].ovars, SWITCH_STACK_BOTTOM, hi-&gt;name, hi-&gt;value);
+                        }
+                }
+
+                handles[i].flags = flags;
+                switch_thread_create(&amp;handles[i].thread, thd_attr, enterprise_originate_thread, &amp;handles[i], pool);
+        }
+
+        for(;;) {
+                running = 0;
+
+                for(i = 0; i &lt; x_argc; i++) {
+                        if (handles[i].done == 0) {
+                                running++;
+                        } else if (handles[i].done == 1) {
+                                if (handles[i].status == SWITCH_STATUS_SUCCESS) {
+                                        hp = &amp;handles[i];
+                                        goto done;
+                                } else {
+                                        handles[i].done = 2;
+                                }
+                        }
+                        switch_cond_next();
+                }
+
+                if (!running) {
+                        break;
+                }
+        }
+
+ done:
+
+        for(i = 0; i &lt; x_argc; i++) {
+                if (hp &amp;&amp; hp == &amp;handles[i]) {
+                        continue;
+                }
+                if (handles[i].bleg) {
+                        switch_channel_hangup(switch_core_session_get_channel(handles[i].bleg), SWITCH_CAUSE_LOSE_RACE);
+                        switch_core_session_rwunlock(handles[i].bleg);
+                }
+
+                handles[i].cause = SWITCH_CAUSE_LOSE_RACE;
+                switch_thread_join(&amp;tstatus, handles[i].thread);
+                switch_event_destroy(&amp;handles[i].ovars);
+        }
+        
+
+        if (hp) {
+                *cause = hp-&gt;cause;
+                status = hp-&gt;status;
+                *bleg = hp-&gt;bleg;
+                switch_thread_join(&amp;tstatus, hp-&gt;thread);
+                switch_event_destroy(&amp;hp-&gt;ovars);
+        }
+
+
+
+ end:
+
+        switch_core_destroy_memory_pool(&amp;pool);
+
+        return status;
+
+}
+
</ins><span class="cx"> #define peer_eligible(_peer) (_peer &amp;&amp; !(switch_channel_test_flag(_peer, CF_TRANSFER) || \
</span><span class="cx">                                                                                  switch_channel_test_flag(_peer, CF_REDIRECT) || \
</span><span class="cx">                                                                                  switch_channel_test_flag(_peer, CF_BRIDGED) || \
</span><span class="cx">                                                                                  switch_channel_get_state(_peer) == CS_RESET || \
</span><span class="cx">                                                                                  !switch_channel_test_flag(_peer, CF_ORIGINATING)))
</span><span class="cx"> 
</span><del>-#define MAX_PEERS 128
</del><ins>+
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *session,
</span><span class="cx">                                                                                                          switch_core_session_t **bleg,
</span><span class="cx">                                                                                                          switch_call_cause_t *cause,
</span><span class="lines">@@ -1195,6 +1369,13 @@
</span><span class="cx">         const char *holding = NULL;
</span><span class="cx">         const char *export_vars = NULL;
</span><span class="cx"> 
</span><ins>+
+        if (strstr(bridgeto, OSEP)) {
+                return switch_ivr_enterprise_originate(session, bleg, cause, bridgeto, timelimit_sec, table, cid_name_override, cid_num_override,
+                                                                                  caller_profile_override, ovars, flags);
+        }
+
+
</ins><span class="cx">         oglobals.ringback_ok = 1;
</span><span class="cx"> 
</span><span class="cx">         if (session) {
</span><span class="lines">@@ -1240,8 +1421,6 @@
</span><span class="cx">         oglobals.idx = IDX_NADA;
</span><span class="cx">         oglobals.early_ok = 1;
</span><span class="cx"> 
</span><del>-
-
</del><span class="cx">         *bleg = NULL;
</span><span class="cx"> 
</span><span class="cx">         switch_zmalloc(write_frame.data, SWITCH_RECOMMENDED_BUFFER_SIZE);
</span><span class="lines">@@ -2088,7 +2267,8 @@
</span><span class="cx">                                 oglobals.ringback_ok = 0;
</span><span class="cx">                         }
</span><span class="cx">                         
</span><del>-                        while ((!caller_channel || switch_channel_ready(caller_channel) || switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE)) &amp;&amp; 
</del><ins>+                        *cause = 0;
+                        while (*cause == 0 &amp;&amp; ((!caller_channel || switch_channel_ready(caller_channel) || switch_channel_test_flag(caller_channel, CF_XFER_ZOMBIE))) &amp;&amp; 
</ins><span class="cx">                                    check_channel_status(&amp;oglobals, originate_status, and_argc)) {
</span><span class="cx">                                 time_t elapsed = switch_epoch_time_now(NULL) - start;
</span><span class="cx">                                 
</span><span class="lines">@@ -2252,6 +2432,10 @@
</span><span class="cx">                                 
</span><span class="cx">                         }
</span><span class="cx"> 
</span><ins>+                        if (*cause) {
+                                force_reason = *cause;
+                        }
+
</ins><span class="cx">                   notready:
</span><span class="cx"> 
</span><span class="cx">                         if (caller_channel) {
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_utilsc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_utils.c (15454 => 15455)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_utils.c        2009-11-12 20:59:04 UTC (rev 15454)
+++ freeswitch/trunk/src/switch_utils.c        2009-11-12 22:21:30 UTC (rev 15455)
</span><span class="lines">@@ -1589,6 +1589,25 @@
</span><span class="cx">         return start;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+SWITCH_DECLARE(unsigned int) switch_separate_string_string(char *buf, char *delim, char **array, unsigned int arraylen)
+{
+        unsigned int count = 0;
+        char *d;
+        size_t dlen = strlen(delim);
+        
+        array[count++] = buf;
+
+        while (count &lt; arraylen &amp;&amp; array[count-1]) {
+                if ((d = strstr(array[count-1], delim))) {
+                        *d = '\0';
+                        d += dlen;
+                        array[count++] = d;
+                } else break;
+        }
+
+        return count;
+}
+
</ins><span class="cx"> /* Separate a string using a delimiter that is not a space */
</span><span class="cx"> static unsigned int separate_string_char_delim(char *buf, char delim, char **array, unsigned int arraylen)
</span><span class="cx"> {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>