<!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][17292] </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=17292">17292</a></dd>
<dt>Author</dt> <dd>moy</dd>
<dt>Date</dt> <dd>2010-04-14 17:00:16 -0500 (Wed, 14 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>implemented freetdm config nodes and ss7 initial configuration</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunklibsfreetdmmod_freetdmmod_freetdmc">freeswitch/trunk/libs/freetdm/mod_freetdm/mod_freetdm.c</a></li>
<li><a href="#freeswitchtrunklibsfreetdmsrcftdm_configc">freeswitch/trunk/libs/freetdm/src/ftdm_config.c</a></li>
<li><a href="#freeswitchtrunklibsfreetdmsrcincludefreetdmh">freeswitch/trunk/libs/freetdm/src/include/freetdm.h</a></li>
<li><a href="#freeswitchtrunklibsfreetdmsrcincludeftdm_typesh">freeswitch/trunk/libs/freetdm/src/include/ftdm_types.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunklibsfreetdmmod_freetdmmod_freetdmc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/freetdm/mod_freetdm/mod_freetdm.c (17291 => 17292)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/freetdm/mod_freetdm/mod_freetdm.c        2010-04-14 22:00:16 UTC (rev 17291)
+++ freeswitch/trunk/libs/freetdm/mod_freetdm/mod_freetdm.c        2010-04-14 22:00:16 UTC (rev 17292)
</span><span class="lines">@@ -2032,9 +2032,133 @@
</span><span class="cx">         
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+/* create ftdm_conf_node_t tree based on a fixed pattern XML configuration list 
+ * last 2 args are for limited aka dumb recursivity
+ * */
+static int add_config_list_nodes(switch_xml_t swnode, ftdm_conf_node_t *rootnode, 
+                const char *list_name, const char *list_element_name, 
+                const char *sub_list_name, const char *sub_list_element_name)
+{
+        char *var, *val;
+        switch_xml_t list;
+        switch_xml_t element;
+        switch_xml_t param;
+
+        ftdm_conf_node_t *n_list;
+        ftdm_conf_node_t *n_element;
+
+        list = switch_xml_child(swnode, list_name);
+        if (!list) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;no list %s found\n&quot;, list_name);
+                return -1;
+        }
+
+        if ((FTDM_SUCCESS != ftdm_conf_node_create(list_name, &amp;n_list, rootnode))) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;failed to create %s node\n&quot;, list_name);
+                return -1;
+        }
+
+        for (element = switch_xml_child(list, list_element_name); element; element = element-&gt;next) {
+                char *element_name = (char *) switch_xml_attr(element, &quot;name&quot;);
+
+                if (!element_name) {
+                        continue;
+                }
+
+                if ((FTDM_SUCCESS != ftdm_conf_node_create(list_element_name, &amp;n_element, n_list))) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;failed to create %s node for %s\n&quot;, list_element_name, element_name);
+                        return -1;
+                }
+                ftdm_conf_node_add_param(n_element, &quot;name&quot;, element_name);
+
+                for (param = switch_xml_child(element, &quot;param&quot;); param; param = param-&gt;next) {
+                        var = (char *) switch_xml_attr_soft(param, &quot;name&quot;);
+                        val = (char *) switch_xml_attr_soft(param, &quot;value&quot;);
+                        ftdm_conf_node_add_param(n_element, var, val);
+                }
+
+                if (sub_list_name &amp;&amp; sub_list_element_name) {
+                        if (add_config_list_nodes(element, n_element, sub_list_name, sub_list_element_name, NULL, NULL)) {
+                                return -1;
+                        }
+                }
+        }
+
+        return 0;
+}
+
</ins><span class="cx"> static ftdm_conf_node_t *get_ss7_config_node(switch_xml_t cfg, const char *confname)
</span><span class="cx"> {
</span><del>-        return NULL;
</del><ins>+        switch_xml_t signode, ss7configs, isup;
+        ftdm_conf_node_t *rootnode;
+
+        /* try to find the conf in the hash first */
+        rootnode = switch_core_hash_find(globals.ss7_configs, confname);
+        if (rootnode) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;ss7 config %s was found in the hash already\n&quot;, confname);
+                return rootnode;
+        }
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;not found %s config in hash, searching in xml ...\n&quot;, confname);
+
+        signode = switch_xml_child(cfg, &quot;signaling_configs&quot;);
+        if (!signode) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;not found 'signaling_configs' XML config section\n&quot;);
+                return NULL;
+        }
+
+        ss7configs = switch_xml_child(signode, &quot;sngss7_configs&quot;);
+        if (!ss7configs) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;not found 'sngss7_configs' XML config section\n&quot;);
+                return NULL;
+        }
+
+        /* search the isup config */
+        for (isup = switch_xml_child(ss7configs, &quot;sng_isup&quot;); isup; isup = isup-&gt;next) {
+                char *name = (char *) switch_xml_attr(isup, &quot;name&quot;);
+                if (!name) {
+                        continue;
+                }
+                if (!strcasecmp(name, confname)) {
+                        break;
+                }
+        }
+
+        if (!isup) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;not found '%s' sng_isup XML config section\n&quot;, confname);
+                return NULL;
+        }
+
+        /* found our XML chunk, create the root node */
+        if ((FTDM_SUCCESS != ftdm_conf_node_create(&quot;sng_isup&quot;, &amp;rootnode, NULL))) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;failed to create root node for sng_isup config %s\n&quot;, confname);
+                return NULL;
+        }
+
+        /* add mtp linksets */
+        if (add_config_list_nodes(isup, rootnode, &quot;mtp_linksets&quot;, &quot;mtp_linkset&quot;, &quot;mtp_links&quot;, &quot;mtp_link&quot;)) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;failed to process mtp_linksets for sng_isup config %s\n&quot;, confname);
+                ftdm_conf_node_destroy(rootnode);
+                return NULL;
+        }
+
+        /* add mtp routes */
+        if (add_config_list_nodes(isup, rootnode, &quot;mtp_routes&quot;, &quot;mtp_route&quot;, NULL, NULL)) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;failed to process mtp_routes for sng_isup config %s\n&quot;, confname);
+                ftdm_conf_node_destroy(rootnode);
+                return NULL;
+        }
+
+        /* add isup interfaces */
+        if (add_config_list_nodes(isup, rootnode, &quot;isup_interfaces&quot;, &quot;isup_interface&quot;, NULL, NULL)) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;failed to process isup_interfaces for sng_isup config %s\n&quot;, confname);
+                ftdm_conf_node_destroy(rootnode);
+                return NULL;
+        }
+
+        switch_core_hash_insert(globals.ss7_configs, confname, rootnode);
+
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;Added SS7 node configuration %s\n&quot;, confname);
+        return rootnode;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static switch_status_t load_config(void)
</span><span class="lines">@@ -2079,10 +2203,14 @@
</span><span class="cx">                         char *configname = (char *) switch_xml_attr(myspan, &quot;config&quot;);
</span><span class="cx">                         ftdm_span_t *span = NULL;
</span><span class="cx">                         uint32_t span_id = 0;
</span><del>-                        if (!name || !configname || !id) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;ss7 span missing required param 'id' or 'name' or 'config', skipping ...\n&quot;);
</del><ins>+                        if (!name &amp;&amp; !id) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;ss7 span missing required attribute 'id' or 'name', skipping ...\n&quot;);
</ins><span class="cx">                                 continue;
</span><span class="cx">                         }
</span><ins>+                        if (!configname) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;ss7 span missing required attribute, skipping ...\n&quot;);
+                                continue;
+                        }
</ins><span class="cx">                         if (name) {
</span><span class="cx">                                 zstatus = ftdm_span_find_by_name(name, &amp;span);
</span><span class="cx">                         } else {
</span><span class="lines">@@ -2106,13 +2234,19 @@
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         ss7confnode = get_ss7_config_node(cfg, configname);
</span><del>-
-                        if (ftdm_configure_span(&quot;ss7&quot;, span, on_ss7_signal, 
-                                                                   &quot;confnode&quot;, ss7confnode,
-                                                                   TAG_END) != FTDM_SUCCESS) {
-                                ftdm_log(FTDM_LOG_ERROR, &quot;Error configuring ss7 FreeTDM span %d\n&quot;, span_id);
</del><ins>+                        if (!ss7confnode) {
+                                ftdm_log(FTDM_LOG_ERROR, &quot;Error finding ss7config '%s' for FreeTDM span id: %s\n&quot;, configname, switch_str_nil(id));
</ins><span class="cx">                                 continue;
</span><span class="cx">                         }
</span><ins>+
+                        if (0) {
+                                if (ftdm_configure_span(&quot;ss7&quot;, span, on_ss7_signal,
+                                                                           &quot;confnode&quot;, ss7confnode,
+                                                                           TAG_END) != FTDM_SUCCESS) {
+                                        ftdm_log(FTDM_LOG_ERROR, &quot;Error configuring ss7 FreeTDM span %d\n&quot;, span_id);
+                                        continue;
+                                }
+                        }
</ins><span class="cx">                         ftdm_log(FTDM_LOG_DEBUG, &quot;Configured ss7 FreeTDM span %d with config node %s\n&quot;, span_id, configname);
</span><span class="cx">                 }
</span><span class="cx">         }
</span></span></pre></div>
<a id="freeswitchtrunklibsfreetdmsrcftdm_configc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/freetdm/src/ftdm_config.c (17291 => 17292)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/freetdm/src/ftdm_config.c        2010-04-14 22:00:16 UTC (rev 17291)
+++ freeswitch/trunk/libs/freetdm/src/ftdm_config.c        2010-04-14 22:00:16 UTC (rev 17292)
</span><span class="lines">@@ -29,6 +29,10 @@
</span><span class="cx">  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
</span><span class="cx">  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
</span><span class="cx">  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><ins>+ *
+ * Contributors: 
+ *
+ * Moises Silva &lt;moy@sangoma.com&gt;
</ins><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> #include &quot;freetdm.h&quot;
</span><span class="lines">@@ -239,6 +243,82 @@
</span><span class="cx">         return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#define PARAMETERS_CHUNK_SIZE 20
+FT_DECLARE(ftdm_status_t) ftdm_conf_node_create(const char *name, ftdm_conf_node_t **node, ftdm_conf_node_t *parent)
+{
+        ftdm_conf_node_t *newnode;
+        ftdm_conf_node_t *sibling = NULL;
+
+        ftdm_assert_return(name != NULL, FTDM_FAIL, &quot;null node name&quot;);
+
+        newnode = ftdm_calloc(1, sizeof(**node));
+        if (!newnode) {
+                return FTDM_MEMERR;
+        }
+
+        strncpy(newnode-&gt;name, name, sizeof(newnode-&gt;name)-1);        
+        newnode-&gt;name[sizeof(newnode-&gt;name)-1] = 0;
+
+        newnode-&gt;parameters = ftdm_calloc(PARAMETERS_CHUNK_SIZE, sizeof(*newnode-&gt;parameters));
+        if (!newnode-&gt;parameters) {
+                ftdm_safe_free(newnode);
+                return FTDM_MEMERR;
+        }
+        newnode-&gt;t_parameters = PARAMETERS_CHUNK_SIZE;
+
+        if (parent) {
+                /* store who my parent is */
+                newnode-&gt;parent = parent;
+                /* save any siblings */
+                sibling = parent-&gt;child;
+                /* as a newborn I am first */
+                parent-&gt;child = newnode;
+                if (sibling) {
+                        /* store a pointer to my next sibling */
+                        newnode-&gt;next = sibling;
+                }
+        }
+
+        *node = newnode;
+
+        return FTDM_SUCCESS;
+}
+
+FT_DECLARE(ftdm_status_t) ftdm_conf_node_add_param(ftdm_conf_node_t *node, const char *param, const char *val)
+{
+        void *newparameters;
+
+        ftdm_assert_return(param != NULL, FTDM_FAIL, &quot;param is null&quot;);
+        ftdm_assert_return(val != NULL, FTDM_FAIL, &quot;val is null&quot;);
+
+        if (node-&gt;n_parameters == node-&gt;t_parameters) {
+                newparameters = ftdm_realloc(node-&gt;parameters, (node-&gt;t_parameters + PARAMETERS_CHUNK_SIZE) * sizeof(*node-&gt;parameters));
+                if (!newparameters) {
+                        return FTDM_MEMERR;
+                }
+                node-&gt;parameters = newparameters;
+                node-&gt;t_parameters = node-&gt;n_parameters + PARAMETERS_CHUNK_SIZE;
+        }
+        node-&gt;parameters[node-&gt;n_parameters].var = param;
+        node-&gt;parameters[node-&gt;n_parameters].val = val;
+        node-&gt;n_parameters++;
+        return FTDM_SUCCESS;
+}
+
+FT_DECLARE(ftdm_status_t) ftdm_conf_node_destroy(ftdm_conf_node_t *node)
+{
+        ftdm_conf_node_t *curr = NULL;
+        ftdm_conf_node_t *child = node-&gt;child;
+        while (child) {
+                curr = child;
+                child = curr-&gt;next;
+                ftdm_conf_node_destroy(curr);
+        }
+        ftdm_free(node-&gt;parameters);
+        ftdm_free(node);
+        return FTDM_SUCCESS;
+}
+
</ins><span class="cx"> /* For Emacs:
</span><span class="cx">  * Local Variables:
</span><span class="cx">  * mode:c
</span></span></pre></div>
<a id="freeswitchtrunklibsfreetdmsrcincludefreetdmh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/freetdm/src/include/freetdm.h (17291 => 17292)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/freetdm/src/include/freetdm.h        2010-04-14 22:00:16 UTC (rev 17291)
+++ freeswitch/trunk/libs/freetdm/src/include/freetdm.h        2010-04-14 22:00:16 UTC (rev 17292)
</span><span class="lines">@@ -827,6 +827,9 @@
</span><span class="cx"> FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap);
</span><span class="cx"> FT_DECLARE(ftdm_status_t) ftdm_channel_set_caller_data(ftdm_channel_t *ftdmchan, ftdm_caller_data_t *caller_data);
</span><span class="cx"> FT_DECLARE(void) ftdm_cpu_monitor_disable(void);
</span><ins>+FT_DECLARE(ftdm_status_t) ftdm_conf_node_create(const char *name, ftdm_conf_node_t **node, ftdm_conf_node_t *parent);
+FT_DECLARE(ftdm_status_t) ftdm_conf_node_add_param(ftdm_conf_node_t *node, const char *param, const char *val);
+FT_DECLARE(ftdm_status_t) ftdm_conf_node_destroy(ftdm_conf_node_t *node);
</ins><span class="cx"> 
</span><span class="cx"> FIO_CODEC_FUNCTION(fio_slin2ulaw);
</span><span class="cx"> FIO_CODEC_FUNCTION(fio_ulaw2slin);
</span></span></pre></div>
<a id="freeswitchtrunklibsfreetdmsrcincludeftdm_typesh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/libs/freetdm/src/include/ftdm_types.h (17291 => 17292)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/libs/freetdm/src/include/ftdm_types.h        2010-04-14 22:00:16 UTC (rev 17291)
+++ freeswitch/trunk/libs/freetdm/src/include/ftdm_types.h        2010-04-14 22:00:16 UTC (rev 17292)
</span><span class="lines">@@ -572,12 +572,28 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;ftdm_dso.h&quot;
</span><span class="cx"> 
</span><ins>+#define FTDM_NODE_NAME_SIZE 50
</ins><span class="cx"> typedef struct ftdm_conf_node_s {
</span><del>-        char name[255];
-        ftdm_conf_parameter_t attr[10];
-        ftdm_conf_parameter_t settings[100];
-        struct ftdm_conf_node_t *childs;
-        struct ftdm_config_node_s *next;
</del><ins>+        /* node name */
+        char name[FTDM_NODE_NAME_SIZE];
+
+        /* total slots for parameters */
+        unsigned int t_parameters;
+
+        /* current number of parameters */
+        unsigned int n_parameters;
+
+        /* array of parameters */
+        ftdm_conf_parameter_t *parameters;
+
+        /* first node child */
+        struct ftdm_conf_node_s *child;
+
+        /* next node sibling */
+        struct ftdm_conf_node_s *next;
+
+        /* my parent if any */
+        struct ftdm_conf_node_s *parent;
</ins><span class="cx"> } ftdm_conf_node_t;
</span><span class="cx"> 
</span><span class="cx"> typedef struct {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>