<!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][14989] </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=14989">14989</a></dd>
<dt>Author</dt> <dd>mochouinard</dd>
<dt>Date</dt> <dd>2009-09-25 16:18:09 -0500 (Fri, 25 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>mod_fifo: allow to call outbound member on on-the-fly fifo, also add a settings params to delete or keep all dynamic fifo entry (<a href="http://jira.freeswitch.org/browse/MODAPP-332">MODAPP-332</a>)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkconfautoload_configsfifoconfxml">freeswitch/trunk/conf/autoload_configs/fifo.conf.xml</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_fifomod_fifoc">freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkconfautoload_configsfifoconfxml"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/conf/autoload_configs/fifo.conf.xml (14988 => 14989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/conf/autoload_configs/fifo.conf.xml        2009-09-25 20:16:18 UTC (rev 14988)
+++ freeswitch/trunk/conf/autoload_configs/fifo.conf.xml        2009-09-25 21:18:09 UTC (rev 14989)
</span><span class="lines">@@ -1,4 +1,7 @@
</span><span class="cx"> <configuration name="fifo.conf" description="FIFO Configuration">
</span><ins>+ <settings>
+ <param name="delete-all-outbound-member-on-startup" value="false"/>
+ </settings>
</ins><span class="cx"> <fifos>
</span><span class="cx"> <fifo name="cool_fifo@$${domain}" importance="0">
</span><span class="cx"> <!--<member timeout="60" simo="1" lag="20">{member_wait=nowait}user/1005@$${domain}</member>-->
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_fifomod_fifoc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c (14988 => 14989)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c        2009-09-25 20:16:18 UTC (rev 14988)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c        2009-09-25 21:18:09 UTC (rev 14989)
</span><span class="lines">@@ -59,6 +59,23 @@
</span><span class="cx">
</span><span class="cx"> typedef struct fifo_node fifo_node_t;
</span><span class="cx">
</span><ins>+struct callback {
+        char *buf;
+        size_t len;
+        int matches;
+};
+typedef struct callback callback_t;
+
+static int sql2str_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+        callback_t *cbt = (callback_t *) pArg;
+
+        switch_copy_string(cbt->buf, argv[0], cbt->len);
+        cbt->matches++;
+        return 0;
+}
+
+
</ins><span class="cx"> static switch_status_t on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
</span><span class="cx"> {
</span><span class="cx">         switch_core_session_t *bleg = (switch_core_session_t *) buf;
</span><span class="lines">@@ -349,11 +366,14 @@
</span><span class="cx">         return ret;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static fifo_node_t *create_node(const char *name, uint32_t importance)
</del><ins>+static fifo_node_t *create_node(const char *name, uint32_t importance, switch_mutex_t *mutex)
</ins><span class="cx"> {
</span><span class="cx">         fifo_node_t *node;
</span><span class="cx">         int x = 0;
</span><span class="cx">         switch_memory_pool_t *pool;
</span><ins>+        char outbound_count[80] = "";
+        callback_t cbt = { 0 };
+        char *sql = NULL;
</ins><span class="cx">
</span><span class="cx">         if (!globals.running) {
</span><span class="cx">                 return NULL;
</span><span class="lines">@@ -373,7 +393,17 @@
</span><span class="cx">         switch_core_hash_init(&node->consumer_hash, node->pool);
</span><span class="cx">         switch_thread_rwlock_create(&node->rwlock, node->pool);
</span><span class="cx">         switch_mutex_init(&node->mutex, SWITCH_MUTEX_NESTED, node->pool);
</span><ins>+        cbt.buf = outbound_count;
+        cbt.len = sizeof(outbound_count);
+        sql = switch_mprintf("select count(*) from fifo_outbound where fifo_name = '%q'", name);
+        fifo_execute_sql_callback(mutex, sql, sql2str_callback, &cbt);
+        if (atoi(outbound_count) > 0) {
+                node->has_outbound = 1;
+        }
+        switch_safe_free(sql);
+
</ins><span class="cx">         node->importance = importance;
</span><ins>+
</ins><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">         switch_core_hash_insert(globals.fifo_hash, name, node);
</span><span class="cx">         switch_mutex_unlock(globals.mutex);
</span><span class="lines">@@ -560,20 +590,22 @@
</span><span class="cx">                 switch_mutex_lock(globals.mutex);
</span><span class="cx">                 for (hi = switch_hash_first(NULL, globals.fifo_hash); hi; hi = switch_hash_next(hi)) {
</span><span class="cx">                         switch_hash_this(hi, &var, NULL, &val);
</span><del>-                        if ((node = (fifo_node_t *) val) && node->has_outbound && node->ready) {
</del><ins>+                        if ((node = (fifo_node_t *) val)) {
+                        if (node->has_outbound && node->ready) {
</ins><span class="cx">                                 switch_mutex_lock(node->mutex);
</span><span class="cx">                                 ppl_waiting = node_consumer_wait_count(node);
</span><span class="cx">                                 consumer_total = node->consumer_count;
</span><span class="cx">                                 idle_consumers = node_idle_consumers(node);
</span><span class="cx">
</span><del>-                                //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                                //"%s waiting %d consumer_total %d idle_consumers %d ring_consumers\n", node->name, ppl_waiting, consumer_total, idle_consumers, node->ring_consumer_count);
</del><ins>+                                /* switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+                                "%s waiting %d consumer_total %d idle_consumers %d ring_consumers %d\n", node->name, ppl_waiting, consumer_total, idle_consumers, node->ring_consumer_count); */
</ins><span class="cx">                 
</span><span class="cx">                                 if ((ppl_waiting - node->ring_consumer_count > 0)&& (!consumer_total || !idle_consumers)) {
</span><span class="cx">                                         find_consumers(node);
</span><span class="cx">                                 }
</span><span class="cx">                                 switch_mutex_unlock(node->mutex);
</span><span class="cx">                         }
</span><ins>+                        }
</ins><span class="cx">                 }
</span><span class="cx">                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">
</span><span class="lines">@@ -678,7 +710,8 @@
</span><span class="cx">
</span><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">         if (!(node = switch_core_hash_find(globals.fifo_hash, node_name))) {
</span><del>-                node = create_node(node_name, 0);
</del><ins>+                node = create_node(node_name, 0, globals.sql_mutex);
+                node->ready = 1;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         send_presence(node);
</span><span class="lines">@@ -700,7 +733,7 @@
</span><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">
</span><span class="cx">         if (!(node = switch_core_hash_find(globals.fifo_hash, node_name))) {
</span><del>-                node = create_node(node_name, 0);
</del><ins>+                node = create_node(node_name, 0, globals.sql_mutex);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         switch_mutex_unlock(globals.mutex);
</span><span class="lines">@@ -839,7 +872,8 @@
</span><span class="cx">
</span><span class="cx">                 
</span><span class="cx">                 if (!(node = switch_core_hash_find(globals.fifo_hash, nlist[i]))) {
</span><del>-                        node = create_node(nlist[i], importance);
</del><ins>+                        node = create_node(nlist[i], importance, globals.sql_mutex);
+                        node->ready = 1;
</ins><span class="cx">                 }
</span><span class="cx">                 node_list[node_count++] = node;
</span><span class="cx">         }
</span><span class="lines">@@ -1846,6 +1880,7 @@
</span><span class="cx">         switch_core_db_t *db;
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_SUCCESS;        
</span><span class="cx">         char *sql;
</span><ins>+        switch_bool_t delete_all_outbound_member_on_startup = SWITCH_FALSE;
</ins><span class="cx">
</span><span class="cx">         gethostname(globals.hostname, sizeof(globals.hostname));
</span><span class="cx">
</span><span class="lines">@@ -1874,11 +1909,12 @@
</span><span class="cx">                                 } else {
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
</span><span class="cx">                                 }
</span><ins>+                        } else if (!strcasecmp(var, "delete-all-outbound-member-on-startup")) {
+                                delete_all_outbound_member_on_startup = switch_true(val);
</ins><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><del>-
</del><span class="cx">         if (switch_strlen_zero(globals.odbc_dsn) || switch_strlen_zero(odbc_user) || switch_strlen_zero(odbc_pass)) {
</span><span class="cx">                 globals.dbname = "fifo";
</span><span class="cx">         }
</span><span class="lines">@@ -1903,7 +1939,7 @@
</span><span class="cx">                 }
</span><span class="cx">         } else {
</span><span class="cx">                 if ((db = switch_core_db_open_file(globals.dbname))) {
</span><del>-                        switch_core_db_test_reactive(db, "delete from fifo_outbound", NULL, (char *)outbound_sql);
</del><ins>+                        switch_core_db_test_reactive(db, "delete from fifo_outbound where static = 1", NULL, (char *)outbound_sql);
</ins><span class="cx">                 } else {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
</span><span class="cx">                         status = SWITCH_STATUS_FALSE;
</span><span class="lines">@@ -1926,7 +1962,7 @@
</span><span class="cx">                 switch_mutex_unlock(globals.mutex);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (del_all) {
</del><ins>+        if ((reload && del_all) || (!reload && delete_all_outbound_member_on_startup) ) {
</ins><span class="cx">                 sql = switch_mprintf("delete from fifo_outbound where hostname='%q'", globals.hostname);
</span><span class="cx">         } else {
</span><span class="cx">                 sql = switch_mprintf("delete from fifo_outbound where static=1 and hostname='%q'", globals.hostname);
</span><span class="lines">@@ -1962,7 +1998,7 @@
</span><span class="cx">
</span><span class="cx">                         switch_mutex_lock(globals.mutex);
</span><span class="cx">                         if (!(node = switch_core_hash_find(globals.fifo_hash, name))) {
</span><del>-                                node = create_node(name, imp);
</del><ins>+                                node = create_node(name, imp, globals.sql_mutex);
</ins><span class="cx">                         }
</span><span class="cx">                         switch_mutex_unlock(globals.mutex);
</span><span class="cx">                         
</span><span class="lines">@@ -2086,7 +2122,8 @@
</span><span class="cx">         
</span><span class="cx">         switch_mutex_lock(globals.mutex);
</span><span class="cx">         if (!(node = switch_core_hash_find(globals.fifo_hash, fifo_name))) {
</span><del>-                node = create_node(fifo_name, 0);
</del><ins>+                node = create_node(fifo_name, 0, globals.sql_mutex);
+                node->ready = 1;
</ins><span class="cx">         }
</span><span class="cx">         switch_mutex_unlock(globals.mutex);
</span><span class="cx">
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>