<h1>Project "FreeSWITCH Source" received a push.</h1>

<h2>branch: master updated</h2>
<pre>
       via: bab7a2392f955facbb91d0f30512682e2b38773e (commit)
      from: 12c13e115b96e9e036bd65655c1f12a72a83510e (commit)


</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Daniel Swarbrick
comments: 
refactor config parsing

<span style="color: #000080; font-weight: bold">diff --git a/conf/autoload_configs/cdr_pg_csv.conf.xml b/conf/autoload_configs/cdr_pg_csv.conf.xml</span>
<span style="color: #000080; font-weight: bold">index 2f2efa9..427bf2d 100644</span>
<span style="color: #A00000">--- a/conf/autoload_configs/cdr_pg_csv.conf.xml</span>
<span style="color: #00A000">+++ b/conf/autoload_configs/cdr_pg_csv.conf.xml</span>
<span style="color: #800080; font-weight: bold">@@ -1,19 +1,23 @@</span>
 &lt;configuration name=&quot;cdr_pg_csv.conf&quot; description=&quot;CDR PG CSV Format&quot;&gt;
   &lt;settings&gt;
<span style="color: #A00000">-    &lt;!-- Log a-leg (a), b-leg (b) or both (ab) --&gt;</span>
<span style="color: #A00000">-    &lt;param name=&quot;legs&quot; value=&quot;a&quot;/&gt;</span>
     &lt;!-- See parameters for PQconnectdb() at http://www.postgresql.org/docs/8.4/static/libpq-connect.html --&gt;
     &lt;param name=&quot;db-info&quot; value=&quot;host=localhost dbname=cdr connect_timeout=10&quot; /&gt;
     &lt;!-- CDR table name --&gt;
     &lt;!--&lt;param name=&quot;db-table&quot; value=&quot;cdr&quot;/&gt;--&gt;
<span style="color: #A00000">-    &lt;param name=&quot;default-template&quot; value=&quot;example&quot;/&gt;</span>
<span style="color: #A00000">-    &lt;!-- &#39;cdr-pg-csv&#39; will always be appended to log-base --&gt;</span>
<span style="color: #A00000">-    &lt;!--&lt;param name=&quot;log-base&quot; value=&quot;/var/log&quot;/&gt;--&gt;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    &lt;!-- Log a-leg (a), b-leg (b) or both (ab) --&gt;</span>
<span style="color: #00A000">+    &lt;param name=&quot;legs&quot; value=&quot;a&quot;/&gt;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    &lt;!-- Directory in which to spool failed SQL inserts --&gt;</span>
<span style="color: #00A000">+    &lt;!-- &lt;param name=&quot;spool-dir&quot; value=&quot;$${base_dir}/log/cdr-pg-csv&quot;/&gt; --&gt;</span>
     &lt;!-- Disk spool format if DB connection/insert fails - csv (default) or sql --&gt;
     &lt;param name=&quot;spool-format&quot; value=&quot;csv&quot;/&gt;
     &lt;param name=&quot;rotate-on-hup&quot; value=&quot;true&quot;/&gt;
<span style="color: #00A000">+</span>
     &lt;!-- This is like the info app but after the call is hung up --&gt;
     &lt;!--&lt;param name=&quot;debug&quot; value=&quot;true&quot;/&gt;--&gt;
<span style="color: #00A000">+</span>
<span style="color: #00A000">+    &lt;param name=&quot;default-template&quot; value=&quot;example&quot;/&gt;</span>
   &lt;/settings&gt;
   &lt;templates&gt;
     &lt;template name=&quot;example&quot;&gt;&quot;${local_ip_v4}&quot;,&quot;${caller_id_name}&quot;,&quot;${caller_id_number}&quot;,&quot;${destination_number}&quot;,&quot;${context}&quot;,&quot;${start_stamp}&quot;,&quot;${answer_stamp}&quot;,&quot;${end_stamp}&quot;,&quot;${duration}&quot;,&quot;${billsec}&quot;,&quot;${hangup_cause}&quot;,&quot;${uuid}&quot;,&quot;${bleg_uuid}&quot;,&quot;${accountcode}&quot;,&quot;${read_codec}&quot;,&quot;${write_codec}&quot;,&quot;${sip_hangup_disposition}&quot;,&quot;${ani}&quot;&lt;/template&gt;
<span style="color: #000080; font-weight: bold">diff --git a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c</span>
<span style="color: #000080; font-weight: bold">index 5227161..1ec56bd 100644</span>
<span style="color: #A00000">--- a/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c</span>
<span style="color: #00A000">+++ b/src/mod/event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c</span>
<span style="color: #800080; font-weight: bold">@@ -37,18 +37,27 @@</span>
 #include &lt;switch.h&gt;
 #include &lt;libpq-fe.h&gt;
 
<span style="color: #00A000">+SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_pg_csv_load);</span>
<span style="color: #00A000">+SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_pg_csv_shutdown);</span>
<span style="color: #00A000">+SWITCH_MODULE_DEFINITION(mod_cdr_pg_csv, mod_cdr_pg_csv_load, mod_cdr_pg_csv_shutdown, NULL);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+</span>
 typedef enum {
         CDR_LEG_A = (1 &lt;&lt; 0),
         CDR_LEG_B = (1 &lt;&lt; 1)
 } cdr_leg_t;
 
<span style="color: #A00000">-struct cdr_fd {</span>
<span style="color: #00A000">+typedef enum {</span>
<span style="color: #00A000">+        SPOOL_FORMAT_CSV,</span>
<span style="color: #00A000">+        SPOOL_FORMAT_SQL</span>
<span style="color: #00A000">+} spool_format_t;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+typedef struct {</span>
         int fd;
         char *path;
         int64_t bytes;
         switch_mutex_t *mutex;
<span style="color: #A00000">-};</span>
<span style="color: #A00000">-typedef struct cdr_fd cdr_fd_t;</span>
<span style="color: #00A000">+} cdr_fd_t;</span>
 
 const char *default_template =
         &quot;\&quot;${local_ip_v4}\&quot;,\&quot;${caller_id_name}\&quot;,\&quot;${caller_id_number}\&quot;,\&quot;${destination_number}\&quot;,\&quot;${context}\&quot;,\&quot;${start_stamp}\&quot;,&quot;
<span style="color: #800080; font-weight: bold">@@ -59,23 +68,59 @@ static struct {</span>
         switch_memory_pool_t *pool;
         switch_hash_t *fd_hash;
         switch_hash_t *template_hash;
<span style="color: #A00000">-        char *log_dir;</span>
<span style="color: #A00000">-        char *default_template;</span>
         int shutdown;
<span style="color: #A00000">-        int rotate;</span>
<span style="color: #A00000">-        int debug;</span>
<span style="color: #A00000">-        cdr_leg_t legs;</span>
         char *db_info;
         char *db_table;
<span style="color: #A00000">-        char *spool_format;</span>
         PGconn *db_connection;
         int db_online;
<span style="color: #00A000">+        cdr_leg_t legs;</span>
<span style="color: #00A000">+        char *spool_dir;</span>
<span style="color: #00A000">+        spool_format_t spool_format;</span>
<span style="color: #00A000">+        int rotate;</span>
<span style="color: #00A000">+        int debug;</span>
<span style="color: #00A000">+        char *default_template;</span>
         switch_mutex_t *db_mutex;
 } globals = { 0 };
 
<span style="color: #A00000">-SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_pg_csv_load);</span>
<span style="color: #A00000">-SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_pg_csv_shutdown);</span>
<span style="color: #A00000">-SWITCH_MODULE_DEFINITION(mod_cdr_pg_csv, mod_cdr_pg_csv_load, mod_cdr_pg_csv_shutdown, NULL);</span>
<span style="color: #00A000">+static switch_xml_config_enum_item_t config_opt_cdr_leg_enum[] = {</span>
<span style="color: #00A000">+        {&quot;a&quot;, CDR_LEG_A},</span>
<span style="color: #00A000">+        {&quot;b&quot;, CDR_LEG_B},</span>
<span style="color: #00A000">+        {&quot;ab&quot;, CDR_LEG_A | CDR_LEG_B},</span>
<span style="color: #00A000">+        {NULL, 0}</span>
<span style="color: #00A000">+};</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+static switch_xml_config_enum_item_t config_opt_spool_format_enum[] = {</span>
<span style="color: #00A000">+        {&quot;csv&quot;, SPOOL_FORMAT_CSV},</span>
<span style="color: #00A000">+        {&quot;sql&quot;, SPOOL_FORMAT_SQL},</span>
<span style="color: #00A000">+        {NULL, 0}</span>
<span style="color: #00A000">+};</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+static switch_status_t config_validate_spool_dir(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed)</span>
<span style="color: #00A000">+{</span>
<span style="color: #00A000">+        if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD)) {</span>
<span style="color: #00A000">+                if (zstr(newvalue)) {</span>
<span style="color: #00A000">+                        globals.spool_dir = switch_core_sprintf(globals.pool, &quot;%s%scdr-pg-csv&quot;, SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);</span>
<span style="color: #00A000">+                }</span>
<span style="color: #00A000">+        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        return SWITCH_STATUS_SUCCESS;</span>
<span style="color: #00A000">+}</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+static switch_xml_config_item_t config_settings[] = {</span>
<span style="color: #00A000">+        /* key, type, flags, ptr, default_value, data, syntax, helptext */</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM_STRING_STRDUP(&quot;db-info&quot;, CONFIG_RELOADABLE, &amp;globals.db_info, &quot;dbname=cdr&quot;, NULL, NULL),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM_STRING_STRDUP(&quot;db-table&quot;, CONFIG_RELOADABLE, &amp;globals.db_table, &quot;cdr&quot;, NULL, NULL),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM_STRING_STRDUP(&quot;default-template&quot;, CONFIG_RELOADABLE, &amp;globals.default_template, &quot;default&quot;, NULL, NULL),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM(&quot;legs&quot;, SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &amp;globals.legs, (void *) CDR_LEG_A, &amp;config_opt_cdr_leg_enum, &quot;a|b|ab&quot;, NULL),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM(&quot;spool-format&quot;, SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &amp;globals.spool_format, (void *) SPOOL_FORMAT_CSV, &amp;config_opt_spool_format_enum, &quot;csv|sql&quot;, &quot;Disk spool format to use if SQL insert fails.&quot;),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM(&quot;rotate-on-hup&quot;, SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &amp;globals.rotate, SWITCH_FALSE, NULL, NULL, NULL),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM(&quot;debug&quot;, SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &amp;globals.debug, SWITCH_FALSE, NULL, NULL, NULL),</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+        /* key, type, flags, ptr, defaultvalue, function, functiondata, syntax, helptext */</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM_CALLBACK(&quot;spool-dir&quot;, SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &amp;globals.spool_dir, NULL, config_validate_spool_dir, NULL, NULL, NULL),</span>
<span style="color: #00A000">+        SWITCH_CONFIG_ITEM_END()</span>
<span style="color: #00A000">+};</span>
<span style="color: #00A000">+</span>
 
 static off_t fd_size(int fd)
 {
<span style="color: #800080; font-weight: bold">@@ -363,12 +408,12 @@ static switch_status_t insert_cdr(const char * const template, const char * cons</span>
         switch_mutex_unlock(globals.db_mutex);
 
         /* SQL INSERT failed for whatever reason. Spool the attempted query to disk */
<span style="color: #A00000">-        if (!strcasecmp(globals.spool_format, &quot;sql&quot;)) {</span>
<span style="color: #A00000">-                path = switch_mprintf(&quot;%s%scdr-spool.sql&quot;, globals.log_dir, SWITCH_PATH_SEPARATOR);</span>
<span style="color: #00A000">+        if (globals.spool_format == SPOOL_FORMAT_SQL) {</span>
<span style="color: #00A000">+                path = switch_mprintf(&quot;%s%scdr-spool.sql&quot;, globals.spool_dir, SWITCH_PATH_SEPARATOR);</span>
                 assert(path);
                 spool_cdr(path, sql);
         } else {
<span style="color: #A00000">-                path = switch_mprintf(&quot;%s%scdr-spool.csv&quot;, globals.log_dir, SWITCH_PATH_SEPARATOR);</span>
<span style="color: #00A000">+                path = switch_mprintf(&quot;%s%scdr-spool.csv&quot;, globals.spool_dir, SWITCH_PATH_SEPARATOR);</span>
                 assert(path);
                 spool_cdr(path, cdr);
         }
<span style="color: #800080; font-weight: bold">@@ -402,8 +447,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)</span>
                 }
         }
 
<span style="color: #A00000">-        if (switch_dir_make_recursive(globals.log_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #A00000">-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error creating %s\n&quot;, globals.log_dir);</span>
<span style="color: #00A000">+        if (switch_dir_make_recursive(globals.spool_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error creating %s\n&quot;, globals.spool_dir);</span>
                 return SWITCH_STATUS_FALSE;
         }
 
<span style="color: #800080; font-weight: bold">@@ -485,7 +530,6 @@ static switch_state_handler_table_t state_handlers = {</span>
 };
 
 
<span style="color: #A00000">-</span>
 static switch_status_t load_config(switch_memory_pool_t *pool)
 {
         char *cf = &quot;cdr_pg_csv.conf&quot;;
<span style="color: #800080; font-weight: bold">@@ -509,40 +553,11 @@ static switch_status_t load_config(switch_memory_pool_t *pool)</span>
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, &quot;Adding default template.\n&quot;);
         globals.legs = CDR_LEG_A;
 
<span style="color: #A00000">-        if ((xml = switch_xml_open_cfg(cf, &amp;cfg, NULL))) {</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-                if ((settings = switch_xml_child(cfg, &quot;settings&quot;))) {</span>
<span style="color: #A00000">-                        for (param = switch_xml_child(settings, &quot;param&quot;); param; param = param-&gt;next) {</span>
<span style="color: #A00000">-                                char *var = (char *) switch_xml_attr_soft(param, &quot;name&quot;);</span>
<span style="color: #A00000">-                                char *val = (char *) switch_xml_attr_soft(param, &quot;value&quot;);</span>
<span style="color: #A00000">-                                if (!strcasecmp(var, &quot;debug&quot;)) {</span>
<span style="color: #A00000">-                                        globals.debug = switch_true(val);</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;legs&quot;)) {</span>
<span style="color: #A00000">-                                        globals.legs = 0;</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-                                        if (strchr(val, &#39;a&#39;)) {</span>
<span style="color: #A00000">-                                                globals.legs |= CDR_LEG_A;</span>
<span style="color: #A00000">-                                        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-                                        if (strchr(val, &#39;b&#39;)) {</span>
<span style="color: #A00000">-                                                globals.legs |= CDR_LEG_B;</span>
<span style="color: #A00000">-                                        }</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;log-base&quot;)) {</span>
<span style="color: #A00000">-                                        globals.log_dir = switch_core_sprintf(pool, &quot;%s%scdr-pg-csv&quot;, val, SWITCH_PATH_SEPARATOR);</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;rotate-on-hup&quot;)) {</span>
<span style="color: #A00000">-                                        globals.rotate = switch_true(val);</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;db-info&quot;)) {</span>
<span style="color: #A00000">-                                        globals.db_info = switch_core_strdup(pool, val);</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;db-table&quot;) || !strcasecmp(var, &quot;g-table&quot;)) {</span>
<span style="color: #A00000">-                                        globals.db_table = switch_core_strdup(pool, val);</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;default-template&quot;)) {</span>
<span style="color: #A00000">-                                        globals.default_template = switch_core_strdup(pool, val);</span>
<span style="color: #A00000">-                                } else if (!strcasecmp(var, &quot;spool-format&quot;)) {</span>
<span style="color: #A00000">-                                        globals.spool_format = switch_core_strdup(pool, val);</span>
<span style="color: #A00000">-                                }</span>
<span style="color: #A00000">-                        }</span>
<span style="color: #A00000">-                }</span>
<span style="color: #00A000">+        if (switch_xml_config_parse_module_settings(&quot;cdr_pg_csv.conf&quot;, SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                return SWITCH_STATUS_FALSE;</span>
<span style="color: #00A000">+        }</span>
 
<span style="color: #00A000">+        if ((xml = switch_xml_open_cfg(cf, &amp;cfg, NULL))) {</span>
                 if ((settings = switch_xml_child(cfg, &quot;templates&quot;))) {
                         for (param = switch_xml_child(settings, &quot;template&quot;); param; param = param-&gt;next) {
                                 char *var = (char *) switch_xml_attr(param, &quot;name&quot;);
<span style="color: #800080; font-weight: bold">@@ -558,26 +573,6 @@ static switch_status_t load_config(switch_memory_pool_t *pool)</span>
                 switch_xml_free(xml);
         }
 
<span style="color: #A00000">-        if (!globals.log_dir) {</span>
<span style="color: #A00000">-                globals.log_dir = switch_core_sprintf(pool, &quot;%s%scdr-pg-csv&quot;, SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (zstr(globals.db_info)) {</span>
<span style="color: #A00000">-                globals.db_info = switch_core_strdup(pool, &quot;dbname=cdr&quot;);</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (zstr(globals.db_table)) {</span>
<span style="color: #A00000">-                globals.db_table = switch_core_strdup(pool, &quot;cdr&quot;);</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (zstr(globals.default_template)) {</span>
<span style="color: #A00000">-                globals.default_template = switch_core_strdup(pool, &quot;default&quot;);</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (zstr(globals.spool_format)) {</span>
<span style="color: #A00000">-                globals.spool_format = switch_core_strdup(pool, &quot;csv&quot;);</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
         return status;
 }
 
<span style="color: #800080; font-weight: bold">@@ -588,8 +583,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_pg_csv_load)</span>
 
         load_config(pool);
 
<span style="color: #A00000">-        if ((status = switch_dir_make_recursive(globals.log_dir, SWITCH_DEFAULT_DIR_PERMS, pool)) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #A00000">-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error creating %s\n&quot;, globals.log_dir);</span>
<span style="color: #00A000">+        if ((status = switch_dir_make_recursive(globals.spool_dir, SWITCH_DEFAULT_DIR_PERMS, pool)) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error creating %s\n&quot;, globals.spool_dir);</span>
                 return status;
         }
 
</pre></div>
========================================================================<pre>

Summary of changes:
 conf/autoload_configs/cdr_pg_csv.conf.xml          |   14 ++-
 .../event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c |  141 ++++++++++----------
 2 files changed, 77 insertions(+), 78 deletions(-)
</pre>
<p>this email was generated because of /git/your-repo.git/hooks/post-receive by the file /git-core/contrib/hooks/post-receive-email<br />
For more info, see <a href="http://blog.chomperstomp.com/?p=630">http://blog.chomperstomp.com/?p=630</a>
-- <br />
FreeSWITCH Source</p>