<!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][16132] </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=16132">16132</a></dd>
<dt>Author</dt> <dd>jmesquita</dd>
<dt>Date</dt> <dd>2010-01-03 22:31:29 -0600 (Sun, 03 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>mod_qsettings working retrieving settings from QSettings and expanding templates. Lets go draw the preferences window now.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonefshostcpp">freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp</a></li>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonemod_qsettingsmod_qsettingscpp">freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp</a></li>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhonemod_qsettingsmod_qsettingsh">freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h</a></li>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhoneresourcesqrc">freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#freeswitchtrunkcontribjmesquitaFSPhoneconfevent_socketconfxml">freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunkcontribjmesquitaFSPhoneconfevent_socketconfxml"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml (0 => 16132)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml                                (rev 0)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/conf/event_socket.conf.xml        2010-01-04 04:31:29 UTC (rev 16132)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+&lt;configuration name=&quot;event_socket.conf&quot; description=&quot;Socket Client&quot;&gt;
+          &lt;settings&gt;
+                &lt;param name=&quot;nat-map&quot; value=&quot;false&quot;/&gt;
+                &lt;param name=&quot;listen-ip&quot; value=&quot;127.0.0.1&quot;/&gt;
+                &lt;param name=&quot;listen-port&quot; value=&quot;8021&quot;/&gt;
+                &lt;param name=&quot;password&quot; value=&quot;ClueCon&quot;/&gt;
+          &lt;/settings&gt;
+&lt;/configuration&gt;
</ins></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhonefshostcpp"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp (16131 => 16132)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp        2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp        2010-01-04 04:31:29 UTC (rev 16132)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx">     if (!conf_dir.exists(&quot;.fsphone&quot;))
</span><span class="cx">     {
</span><span class="cx">         conf_dir.mkpath(&quot;.fsphone/conf/accounts&quot;);
</span><ins>+        conf_dir.mkpath(&quot;.fsphone/templates&quot;);
</ins><span class="cx">         QFile rootXML(&quot;:/confs/freeswitch.xml&quot;);
</span><span class="cx">         QString dest = QString(&quot;%1/.fsphone/conf/freeswitch.xml&quot;).arg(conf_dir.absolutePath());
</span><span class="cx">         rootXML.copy(dest);
</span><span class="lines">@@ -120,14 +121,15 @@
</span><span class="cx"> 
</span><span class="cx">     if (switch_event_bind(&quot;FSHost&quot;, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, eventHandlerCallback, NULL) != SWITCH_STATUS_SUCCESS) {
</span><span class="cx">             switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Couldn't bind!\n&quot;);
</span><del>-            printf(&quot;Something went really wrong while binding to events...&quot;);
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     /* Load our QSettings module */
</span><span class="cx">     if (switch_loadable_module_build_dynamic(&quot;mod_qsettings&quot;,mod_qsettings_load,NULL,mod_qsettings_shutdown,SWITCH_FALSE) != SWITCH_STATUS_SUCCESS)
</span><span class="cx">     {
</span><del>-        printf(&quot;Something went wrong when loading our QSettings module\n&quot;);
</del><ins>+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Couldn't load mod_qsettings\n&quot;);
</ins><span class="cx">     }
</span><ins>+    QString res;
+    sendCmd(&quot;load&quot;, &quot;mod_event_socket&quot;, &amp;res);
</ins><span class="cx">     emit ready();
</span><span class="cx">     /* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set
</span><span class="cx">      * If its false, it initializes the libedit for the console, then does the same thing
</span></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhonemod_qsettingsmod_qsettingscpp"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp (16131 => 16132)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp        2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.cpp        2010-01-04 04:31:29 UTC (rev 16132)
</span><span class="lines">@@ -31,93 +31,119 @@
</span><span class="cx">  *
</span><span class="cx">  */
</span><span class="cx"> #include &lt;QString&gt;
</span><ins>+#include &lt;QtGui&gt;
+#include &lt;QDir&gt;
</ins><span class="cx"> #include &quot;mod_qsettings/mod_qsettings.h&quot;
</span><span class="cx"> 
</span><del>-struct xml_binding {
-        QString *bindings;
-};
-typedef struct xml_binding xml_binding_t;
-
-
</del><span class="cx"> static struct {
</span><span class="cx">     switch_memory_pool_t* pool;
</span><span class="cx"> } globals;
</span><span class="cx"> 
</span><ins>+switch_xml_t XMLBinding::getConfigXML(QString tmpl)
+{
+    switch_event_t *e;
+    switch_event_create_plain(&amp;e, SWITCH_EVENT_REQUEST_PARAMS);
+    switch_assert(e);
</ins><span class="cx"> 
</span><ins>+    QFile tmplFile(QString(&quot;%1/templates/%2.xml&quot;).arg(QApplication::applicationDirPath(),tmpl));
</ins><span class="cx"> 
</span><ins>+    if (!tmplFile.exists()) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
+                          &quot;Template %s.xml, doesn't exist on directory, falling back to embedded template.\n&quot;,
+                          tmpl.toAscii().constData());
+        tmplFile.setFileName(QString(&quot;:/confs/%1.xml&quot;).arg(tmpl));
+        return NULL;
+    }
+
+    if (tmplFile.open(QIODevice::ReadOnly | QIODevice::Text))
+    {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Template %s could not be read.!\n&quot;, tmpl.toAscii().constData());
+        return NULL;
+    }
+
+    /* Open template file and expand all strings based on QSettings */
+    QString tmplContents(tmplFile.readAll());
+    tmplFile.close();
+    _settings-&gt;beginGroup(&quot;FreeSIWTCH/conf&quot;);
+    _settings-&gt;beginGroup(tmpl);
+    foreach(QString k, _settings-&gt;childKeys())
+    {
+        switch_event_add_header_string(e, SWITCH_STACK_BOTTOM, k.toAscii().constData(), _settings-&gt;value(k).toByteArray().constData());
+    }
+
+    char *res = switch_event_expand_headers(e, tmplContents.toAscii().constData());
+    switch_safe_free(e);
+    return switch_xml_parse_str(res, strlen(res));
+}
+
</ins><span class="cx"> static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
</span><del>-                                                                  void *user_data)
</del><ins>+                                  void *user_data)
</ins><span class="cx"> {
</span><del>-        xml_binding_t *binding = (xml_binding_t *) user_data;
</del><ins>+    XMLBinding *binding = (XMLBinding *) user_data;
</ins><span class="cx"> 
</span><del>-        if (!binding) {
-                return NULL;
-        }
-        /* All we have to do here is check the section requested and maybe use a
-           templating system to provide the corresponding xml */
</del><ins>+    if (!binding) {
+        return NULL;
+    }
</ins><span class="cx"> 
</span><del>-        return NULL;
</del><ins>+    return binding-&gt;getConfigXML(key_value);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static switch_status_t do_config(void)
</span><span class="cx"> {
</span><del>-        char *cf = &quot;qsettings.conf&quot;;
-        switch_xml_t cfg, xml, bindings_tag;
-        xml_binding_t *binding = NULL;
</del><ins>+    char *cf = &quot;qsettings.conf&quot;;
+    switch_xml_t cfg, xml, bindings_tag;
+    XMLBinding *binding = NULL;
</ins><span class="cx"> 
</span><del>-        if (!(xml = switch_xml_open_cfg(cf, &amp;cfg, NULL))) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;open of %s failed\n&quot;, cf);
-                return SWITCH_STATUS_TERM;
-        }
</del><ins>+    if (!(xml = switch_xml_open_cfg(cf, &amp;cfg, NULL))) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;open of %s failed\n&quot;, cf);
+        return SWITCH_STATUS_TERM;
+    }
</ins><span class="cx"> 
</span><del>-        if (!(bindings_tag = switch_xml_child(cfg, &quot;bindings&quot;))) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Missing &lt;bindings&gt; tag!\n&quot;);
-                switch_xml_free(xml);
-                return SWITCH_STATUS_FALSE;
-        }
</del><ins>+    if (!(bindings_tag = switch_xml_child(cfg, &quot;bindings&quot;))) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Missing &lt;bindings&gt; tag!\n&quot;);
+        switch_xml_free(xml);
+        return SWITCH_STATUS_FALSE;
+    }
</ins><span class="cx"> 
</span><del>-        QString *bind_mask = new QString(switch_xml_attr_soft(bindings_tag, &quot;value&quot;));
</del><ins>+    QString bind_mask = switch_xml_attr_soft(bindings_tag, &quot;value&quot;);
+    if (!bind_mask.isEmpty())
+    {
+        binding = new XMLBinding(bind_mask);
+    }
</ins><span class="cx"> 
</span><del>-        binding = new xml_binding_t();
</del><ins>+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Binding XML Fetch Function [%s]\n&quot;,
+                      binding-&gt;getBinding().isEmpty() ? &quot;all&quot; : binding-&gt;getBinding().toAscii().constData());
+    switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding-&gt;getBinding().toAscii().constData()), binding);
+    binding = NULL;
</ins><span class="cx"> 
</span><del>-        if (!bind_mask-&gt;isEmpty()) {
-                binding-&gt;bindings = bind_mask;
-        }
-
-
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Binding XML Fetch Function [%s]\n&quot;,
-                          binding-&gt;bindings-&gt;isEmpty() ? &quot;all&quot; : binding-&gt;bindings-&gt;toAscii().constData());
-        switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding-&gt;bindings-&gt;toAscii().constData()), binding);
-        binding = NULL;
-
-        switch_xml_free(xml);
-        return SWITCH_STATUS_SUCCESS;
</del><ins>+    switch_xml_free(xml);
+    return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SWITCH_MODULE_LOAD_FUNCTION(mod_qsettings_load)
</span><span class="cx"> {
</span><del>-        /*switch_api_interface_t *qsettings_api_interface;*/
</del><ins>+    /*switch_api_interface_t *qsettings_api_interface;*/
</ins><span class="cx"> 
</span><del>-        /* connect my internal structure to the blank pointer passed to me */
-        *module_interface = switch_loadable_module_create_module_interface(pool, &quot;mod_qsettings&quot;);
</del><ins>+    /* connect my internal structure to the blank pointer passed to me */
+    *module_interface = switch_loadable_module_create_module_interface(pool, &quot;mod_qsettings&quot;);
</ins><span class="cx"> 
</span><del>-        memset(&amp;globals,0,sizeof(globals));
-        globals.pool = pool;
</del><ins>+    memset(&amp;globals,0,sizeof(globals));
+    globals.pool = pool;
</ins><span class="cx"> 
</span><del>-        if (do_config() == SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Sucessfully configured.\n&quot;);
-        } else {
-                return SWITCH_STATUS_FALSE;
-        }
</del><ins>+    if (do_config() == SWITCH_STATUS_SUCCESS) {
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;Sucessfully configured.\n&quot;);
+    } else {
+        return SWITCH_STATUS_FALSE;
+    }
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;We loaded mod_qsettings.\n&quot;);
-        /* indicate that the module should continue to be loaded */
-        return SWITCH_STATUS_SUCCESS;
</del><ins>+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, &quot;We loaded mod_qsettings.\n&quot;);
+    /* indicate that the module should continue to be loaded */
+    return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_qsettings_shutdown)
</span><span class="cx"> {
</span><del>-        switch_xml_unbind_search_function_ptr(xml_url_fetch);
-        return SWITCH_STATUS_SUCCESS;
</del><ins>+    switch_xml_unbind_search_function_ptr(xml_url_fetch);
+    return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhonemod_qsettingsmod_qsettingsh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h (16131 => 16132)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h        2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mod_qsettings/mod_qsettings.h        2010-01-04 04:31:29 UTC (rev 16132)
</span><span class="lines">@@ -30,9 +30,22 @@
</span><span class="cx"> #ifndef MOD_QSETTINGS_H
</span><span class="cx"> #define MOD_QSETTINGS_H
</span><span class="cx"> 
</span><ins>+#include &lt;QString&gt;
+#include &lt;QSettings&gt;
</ins><span class="cx"> #include &lt;switch.h&gt;
</span><span class="cx"> 
</span><span class="cx"> SWITCH_MODULE_LOAD_FUNCTION(mod_qsettings_load);
</span><span class="cx"> SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_qsettings_shutdown);
</span><span class="cx"> 
</span><ins>+class XMLBinding
+{
+public:
+    XMLBinding(QString binding) : _binding(binding), _settings(new QSettings) {}
+    QString getBinding(void) { return _binding; }
+    switch_xml_t getConfigXML(QString);
+private:
+    QString _binding;
+    QSettings* _settings;
+};
+
</ins><span class="cx"> #endif // MOD_QSETTINGS_H
</span></span></pre></div>
<a id="freeswitchtrunkcontribjmesquitaFSPhoneresourcesqrc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc (16131 => 16132)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc        2010-01-03 23:36:24 UTC (rev 16131)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/resources.qrc        2010-01-04 04:31:29 UTC (rev 16132)
</span><span class="lines">@@ -5,5 +5,6 @@
</span><span class="cx">     &lt;qresource prefix=&quot;/confs&quot;&gt;
</span><span class="cx">         &lt;file alias=&quot;freeswitch.xml&quot;&gt;conf/freeswitch.xml&lt;/file&gt;
</span><span class="cx">         &lt;file alias=&quot;example.xml&quot;&gt;conf/accounts/example.xml&lt;/file&gt;
</span><ins>+        &lt;file alias=&quot;event_socket.conf.xml&quot;&gt;conf/event_socket.conf.xml&lt;/file&gt;
</ins><span class="cx">     &lt;/qresource&gt;
</span><span class="cx"> &lt;/RCC&gt;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>