<h1>Project "FreeSWITCH Source" received a push.</h1>
<h2>branch: master updated</h2>
<pre>
via: bcb2262fdc48b36bd2e6bfe45adcbaecd1d091ee (commit)
from: f0a31e1bfff2d49d97bc0ee83627c426fa311bfc (commit)
</pre>= COMMIT LOG ===========================================================
<div class="highlight"><pre>committer: Daniel Swarbrick
comments:
major factor of pgsql field handling
<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 427bf2d..4fec817 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">@@ -16,10 +16,25 @@</span>
<!-- This is like the info app but after the call is hung up -->
<!--<param name="debug" value="true"/>-->
<span style="color: #A00000">-</span>
<span style="color: #A00000">- <param name="default-template" value="example"/></span>
</settings>
<span style="color: #A00000">- <templates></span>
<span style="color: #A00000">- <template name="example">"${local_ip_v4}","${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${answer_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}","${accountcode}","${read_codec}","${write_codec}","${sip_hangup_disposition}","${ani}"</template></span>
<span style="color: #A00000">- </templates></span>
<span style="color: #00A000">+ <schema></span>
<span style="color: #00A000">+ <field var="local_ip_v4"/></span>
<span style="color: #00A000">+ <field var="caller_id_name"/></span>
<span style="color: #00A000">+ <field var="caller_id_number"/></span>
<span style="color: #00A000">+ <field var="destination_number"/></span>
<span style="color: #00A000">+ <field var="context"/></span>
<span style="color: #00A000">+ <field var="start_stamp"/></span>
<span style="color: #00A000">+ <field var="answer_stamp"/></span>
<span style="color: #00A000">+ <field var="end_stamp"/></span>
<span style="color: #00A000">+ <field var="duration" quote="false"/></span>
<span style="color: #00A000">+ <field var="billsec" quote="false"/></span>
<span style="color: #00A000">+ <field var="hangup_cause"/></span>
<span style="color: #00A000">+ <field var="uuid"/></span>
<span style="color: #00A000">+ <field var="bleg_uuid"/></span>
<span style="color: #00A000">+ <field var="accountcode"/></span>
<span style="color: #00A000">+ <field var="read_codec"/></span>
<span style="color: #00A000">+ <field var="write_codec"/></span>
<span style="color: #00A000">+ <!-- <field var="sip_hangup_disposition"/> --></span>
<span style="color: #00A000">+ <!-- <field var="ani"/> --></span>
<span style="color: #00A000">+ </schema></span>
</configuration>
<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 1ec56bd..51194f4 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">@@ -59,28 +59,34 @@ typedef struct {</span>
        switch_mutex_t *mutex;
} cdr_fd_t;
<span style="color: #A00000">-const char *default_template =</span>
<span style="color: #A00000">-        "\"${local_ip_v4}\",\"${caller_id_name}\",\"${caller_id_number}\",\"${destination_number}\",\"${context}\",\"${start_stamp}\","</span>
<span style="color: #A00000">-        "\"${answer_stamp}\",\"${end_stamp}\",\"${duration}\",\"${billsec}\",\"${hangup_cause}\",\"${uuid}\",\"${bleg_uuid}\",\"${accountcode}\","</span>
<span style="color: #A00000">-        "\"${read_codec}\",\"${write_codec}\"";</span>
<span style="color: #00A000">+typedef struct {</span>
<span style="color: #00A000">+        char *col_name;</span>
<span style="color: #00A000">+        char *var_name;</span>
<span style="color: #00A000">+        switch_bool_t quote;</span>
<span style="color: #00A000">+        switch_bool_t not_null;</span>
<span style="color: #00A000">+} cdr_field_t;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+typedef struct {</span>
<span style="color: #00A000">+        char *columns;</span>
<span style="color: #00A000">+        cdr_field_t fields[1];</span>
<span style="color: #00A000">+} db_schema_t;</span>
static struct {
        switch_memory_pool_t *pool;
        switch_hash_t *fd_hash;
<span style="color: #A00000">-        switch_hash_t *template_hash;</span>
        int shutdown;
        char *db_info;
        char *db_table;
<span style="color: #00A000">+        db_schema_t *db_schema;</span>
        PGconn *db_connection;
<span style="color: #00A000">+        switch_mutex_t *db_mutex;</span>
        int db_online;
        cdr_leg_t legs;
        char *spool_dir;
        spool_format_t spool_format;
        int rotate;
        int debug;
<span style="color: #A00000">-        char *default_template;</span>
<span style="color: #A00000">-        switch_mutex_t *db_mutex;</span>
<span style="color: #A00000">-} globals = { 0 };</span>
<span style="color: #00A000">+} globals;</span>
static switch_xml_config_enum_item_t config_opt_cdr_leg_enum[] = {
{"a", CDR_LEG_A},
<span style="color: #800080; font-weight: bold">@@ -110,7 +116,6 @@ static switch_xml_config_item_t config_settings[] = {</span>
        /* key, type, flags, ptr, default_value, data, syntax, helptext */
        SWITCH_CONFIG_ITEM_STRING_STRDUP("db-info", CONFIG_RELOADABLE, &globals.db_info, "dbname=cdr", NULL, NULL),
        SWITCH_CONFIG_ITEM_STRING_STRDUP("db-table", CONFIG_RELOADABLE, &globals.db_table, "cdr", NULL, NULL),
<span style="color: #A00000">-        SWITCH_CONFIG_ITEM_STRING_STRDUP("default-template", CONFIG_RELOADABLE, &globals.default_template, "default", NULL, NULL),</span>
        SWITCH_CONFIG_ITEM("legs", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.legs, (void *) CDR_LEG_A, &config_opt_cdr_leg_enum, "a|b|ab", NULL),
        SWITCH_CONFIG_ITEM("spool-format", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.spool_format, (void *) SPOOL_FORMAT_CSV, &config_opt_spool_format_enum, "csv|sql", "Disk spool format to use if SQL insert fails."),
        SWITCH_CONFIG_ITEM("rotate-on-hup", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.rotate, SWITCH_FALSE, NULL, NULL, NULL),
<span style="color: #800080; font-weight: bold">@@ -239,135 +244,13 @@ static void spool_cdr(const char *path, const char *log_line)</span>
        switch_safe_free(log_line_lf);
}
<span style="color: #A00000">-static switch_status_t insert_cdr(const char * const template, const char * const cdr)</span>
<span style="color: #00A000">+static switch_status_t insert_cdr(const char *values)</span>
{
<span style="color: #A00000">-        char *columns, *values;</span>
<span style="color: #A00000">-        char *p, *q;</span>
<span style="color: #A00000">-        unsigned vlen;</span>
<span style="color: #A00000">-        char *nullValues, *temp, *tp;</span>
<span style="color: #A00000">-        int nullCounter = 0, charCounter = 0;</span>
        char *sql = NULL, *path = NULL;
        PGresult *res;
<span style="color: #A00000">-        if (!template || !*template || !cdr || !*cdr) {</span>
<span style="color: #A00000">-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Bad parameter\n");</span>
<span style="color: #A00000">-                return SWITCH_STATUS_FALSE;</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        /* Build comma-separated list of field names by dropping $ { } ; chars */</span>
<span style="color: #A00000">-        switch_strdup(columns, template);</span>
<span style="color: #A00000">-        for (p = columns, q = columns; *p; ++p) {</span>
<span style="color: #A00000">-                switch (*p) {</span>
<span style="color: #A00000">-                        case '$': case '"': case '{': case '}': case ';':</span>
<span style="color: #A00000">-                                break;</span>
<span style="color: #A00000">-                        default:</span>
<span style="color: #A00000">-                                *q++ = *p;</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-        *q = '\0';</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        /*</span>
<span style="color: #A00000">-         * In the expanded vars, replace double quotes (") with single quotes (')</span>
<span style="color: #A00000">-         * for correct PostgreSQL syntax, and replace semi-colon with space to</span>
<span style="color: #A00000">-         * prevent SQL injection attacks</span>
<span style="color: #A00000">-         */</span>
<span style="color: #A00000">-        switch_strdup(values, cdr);</span>
<span style="color: #A00000">-        for (p = values; *p; ++p) {</span>
<span style="color: #A00000">-                switch(*p) {</span>
<span style="color: #A00000">-                        case '"':</span>
<span style="color: #A00000">-                                *p = '\'';</span>
<span style="color: #A00000">-                                break;</span>
<span style="color: #A00000">-                        case ';':</span>
<span style="color: #A00000">-                                *p = ' ';</span>
<span style="color: #A00000">-                                break;</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-        vlen = p - values;</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        /*</span>
<span style="color: #A00000">-         * Patch for changing empty strings ('') in the expanded variables to</span>
<span style="color: #A00000">-         * PostgreSQL null</span>
<span style="color: #A00000">-         */</span>
<span style="color: #A00000">-        for (p = values; *p; ++p) {</span>
<span style="color: #A00000">-                if (*p == ',') {</span>
<span style="color: #A00000">-                        if (charCounter == 0) {</span>
<span style="color: #A00000">-                                nullCounter++;</span>
<span style="color: #A00000">-                        }</span>
<span style="color: #A00000">-                        charCounter = 0;</span>
<span style="color: #A00000">-                } else if (*p != ' ' && *p != '\'') {</span>
<span style="color: #A00000">-                        charCounter++;</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (charCounter == 0) {</span>
<span style="color: #A00000">-                nullCounter++;</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        nullCounter *= 4;</span>
<span style="color: #A00000">-        vlen += nullCounter;</span>
<span style="color: #A00000">-        switch_zmalloc(nullValues, strlen(values) + nullCounter + 1);</span>
<span style="color: #A00000">-        charCounter = 0;</span>
<span style="color: #A00000">-        temp = nullValues;</span>
<span style="color: #A00000">-        tp = nullValues;</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        for (p = values; *p; ++tp, ++p) {</span>
<span style="color: #A00000">-                if (*p == ',') {</span>
<span style="color: #A00000">-                        if (charCounter == 0) {</span>
<span style="color: #A00000">-                                temp++;</span>
<span style="color: #A00000">-                                *temp = 'n';</span>
<span style="color: #A00000">-                                temp++;</span>
<span style="color: #A00000">-                                if (temp == tp) tp++;</span>
<span style="color: #A00000">-                                *temp = 'u';</span>
<span style="color: #A00000">-                                temp++;</span>
<span style="color: #A00000">-                                if (temp == tp) tp++;</span>
<span style="color: #A00000">-                                *temp = 'l';</span>
<span style="color: #A00000">-                                temp++;</span>
<span style="color: #A00000">-                                if (temp == tp) tp++;</span>
<span style="color: #A00000">-                                *temp = 'l';</span>
<span style="color: #A00000">-                                temp++;</span>
<span style="color: #A00000">-                                while (temp != tp) {</span>
<span style="color: #A00000">-                                        *temp = ' ';</span>
<span style="color: #A00000">-                                        temp++;</span>
<span style="color: #A00000">-                                }</span>
<span style="color: #A00000">-                        }</span>
<span style="color: #A00000">-                        charCounter = 0;</span>
<span style="color: #A00000">-                        temp = tp;</span>
<span style="color: #A00000">-                } else if (*p != ' ' && *p != '\'') {</span>
<span style="color: #A00000">-                        charCounter++;</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-                *tp = *p;</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (charCounter == 0) {</span>
<span style="color: #A00000">-                temp++;</span>
<span style="color: #A00000">-                *temp = 'n';</span>
<span style="color: #A00000">-                temp++;</span>
<span style="color: #A00000">-                if (temp == tp) tp++;</span>
<span style="color: #A00000">-                *temp = 'u';</span>
<span style="color: #A00000">-                temp++;</span>
<span style="color: #A00000">-                if (temp == tp) tp++;</span>
<span style="color: #A00000">-                *temp = 'l';</span>
<span style="color: #A00000">-                temp++;</span>
<span style="color: #A00000">-                if (temp == tp) tp++;</span>
<span style="color: #A00000">-                *temp = 'l';</span>
<span style="color: #A00000">-                temp++;</span>
<span style="color: #A00000">-                while (temp != tp) {</span>
<span style="color: #A00000">-                        *temp = ' ';</span>
<span style="color: #A00000">-                        temp++;</span>
<span style="color: #A00000">-                }</span>
<span style="color: #A00000">-        }</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        charCounter = 0;</span>
<span style="color: #A00000">-        temp = tp;</span>
<span style="color: #A00000">-        *tp = 0;</span>
<span style="color: #A00000">-        tp = values;</span>
<span style="color: #A00000">-        values = nullValues;</span>
<span style="color: #A00000">-        switch_safe_free(tp);</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);", globals.db_table, columns, values);</span>
<span style="color: #00A000">+        sql = switch_mprintf("INSERT INTO %s (%s) VALUES (%s);", globals.db_table, globals.db_schema->columns, values);</span>
        assert(sql);
<span style="color: #A00000">-        switch_safe_free(columns);</span>
<span style="color: #A00000">-        switch_safe_free(values);</span>
        if (globals.debug) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Query: \"%s\"\n", sql);
<span style="color: #800080; font-weight: bold">@@ -415,7 +298,7 @@ static switch_status_t insert_cdr(const char * const template, const char * cons</span>
        } else {
                path = switch_mprintf("%s%scdr-spool.csv", globals.spool_dir, SWITCH_PATH_SEPARATOR);
                assert(path);
<span style="color: #A00000">-                spool_cdr(path, cdr);</span>
<span style="color: #00A000">+                spool_cdr(path, values);</span>
        }
        switch_safe_free(path);
<span style="color: #800080; font-weight: bold">@@ -428,8 +311,10 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)</span>
{
        switch_channel_t *channel = switch_core_session_get_channel(session);
        switch_status_t status = SWITCH_STATUS_SUCCESS;
<span style="color: #A00000">-        const char *template_str = NULL;</span>
<span style="color: #A00000">-        char *expanded_vars = NULL;</span>
<span style="color: #00A000">+        char *values = NULL, *tmp = NULL, *pq_var = NULL;</span>
<span style="color: #00A000">+        const char *var = NULL;</span>
<span style="color: #00A000">+        cdr_field_t *cdr_field = NULL;</span>
<span style="color: #00A000">+        switch_size_t len, offset;</span>
        if (globals.shutdown) {
                return SWITCH_STATUS_SUCCESS;
<span style="color: #800080; font-weight: bold">@@ -465,24 +350,40 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)</span>
                }
        }
<span style="color: #A00000">-        template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);</span>
<span style="color: #00A000">+        switch_zmalloc(values, 1);</span>
<span style="color: #00A000">+        offset = 0;</span>
<span style="color: #A00000">-        if (!template_str) {</span>
<span style="color: #A00000">-                template_str = default_template;</span>
<span style="color: #A00000">-        }</span>
<span style="color: #00A000">+        for (cdr_field = globals.db_schema->fields; cdr_field->var_name; cdr_field++) {</span>
<span style="color: #00A000">+                if ((var = switch_channel_get_variable(channel, cdr_field->var_name))) {</span>
<span style="color: #00A000">+                        /* Allocate sufficient buffer for PQescapeString */</span>
<span style="color: #00A000">+                        len = strlen(var);</span>
<span style="color: #00A000">+                        tmp = switch_core_session_alloc(session, len * 2 + 1);</span>
<span style="color: #00A000">+                        PQescapeString(tmp, var, len);</span>
<span style="color: #00A000">+                        var = tmp;</span>
<span style="color: #00A000">+                }</span>
<span style="color: #A00000">-        expanded_vars = switch_channel_expand_variables(channel, template_str);</span>
<span style="color: #00A000">+                if (cdr_field->quote) {</span>
<span style="color: #00A000">+                        if ((cdr_field->not_null == SWITCH_FALSE) && zstr(var)) {</span>
<span style="color: #00A000">+                                pq_var = switch_mprintf("null,", var);</span>
<span style="color: #00A000">+                        } else {</span>
<span style="color: #00A000">+                                pq_var = switch_mprintf("'%s',", var);</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+                } else {</span>
<span style="color: #00A000">+                        pq_var = switch_mprintf("%s,", var);</span>
<span style="color: #00A000">+                }</span>
<span style="color: #A00000">-        if (!expanded_vars) {</span>
<span style="color: #A00000">-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error expanding CDR variables.\n");</span>
<span style="color: #A00000">-                return SWITCH_STATUS_FALSE;</span>
<span style="color: #00A000">+                /* Resize values buffer to accomodate next var */</span>
<span style="color: #00A000">+                len = strlen(pq_var);</span>
<span style="color: #00A000">+                tmp = realloc(values, offset + len);</span>
<span style="color: #00A000">+                values = tmp;</span>
<span style="color: #00A000">+                memcpy(values + offset, pq_var, len);</span>
<span style="color: #00A000">+                switch_safe_free(pq_var);</span>
<span style="color: #00A000">+                offset += len;</span>
        }
<span style="color: #00A000">+        *(values + --offset) = '\0';</span>
<span style="color: #A00000">-        insert_cdr(template_str, expanded_vars);</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (expanded_vars != template_str) {</span>
<span style="color: #A00000">-                switch_safe_free(expanded_vars);</span>
<span style="color: #A00000">-        }</span>
<span style="color: #00A000">+        insert_cdr(values);</span>
<span style="color: #00A000">+        switch_safe_free(values);</span>
        return status;
}
<span style="color: #800080; font-weight: bold">@@ -532,9 +433,13 @@ static switch_state_handler_table_t state_handlers = {</span>
static switch_status_t load_config(switch_memory_pool_t *pool)
{
<span style="color: #A00000">-        char *cf = "cdr_pg_csv.conf";</span>
<span style="color: #A00000">-        switch_xml_t cfg, xml, settings, param;</span>
        switch_status_t status = SWITCH_STATUS_SUCCESS;
<span style="color: #00A000">+        char *cf = "cdr_pg_csv.conf", *ptr;</span>
<span style="color: #00A000">+        switch_xml_t cfg, xml, schema, field;</span>
<span style="color: #00A000">+        const char *attr;</span>
<span style="color: #00A000">+        int num_fields = 0;</span>
<span style="color: #00A000">+        switch_size_t len = 0;</span>
<span style="color: #00A000">+        cdr_field_t *cdr_field;</span>
        if (globals.db_online) {
                PQfinish(globals.db_connection);
<span style="color: #800080; font-weight: bold">@@ -544,32 +449,69 @@ static switch_status_t load_config(switch_memory_pool_t *pool)</span>
        memset(&globals, 0, sizeof(globals));
        switch_core_hash_init(&globals.fd_hash, pool);
<span style="color: #A00000">-        switch_core_hash_init(&globals.template_hash, pool);</span>
        switch_mutex_init(&globals.db_mutex, SWITCH_MUTEX_NESTED, pool);
        globals.pool = pool;
<span style="color: #A00000">-        switch_core_hash_insert(globals.template_hash, "default", default_template);</span>
<span style="color: #A00000">-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding default template.\n");</span>
<span style="color: #A00000">-        globals.legs = CDR_LEG_A;</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-        if (switch_xml_config_parse_module_settings("cdr_pg_csv.conf", SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {</span>
<span style="color: #00A000">+        if (switch_xml_config_parse_module_settings(cf, SWITCH_FALSE, config_settings) != SWITCH_STATUS_SUCCESS) {</span>
                return SWITCH_STATUS_FALSE;
        }
        if ((xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
<span style="color: #A00000">-                if ((settings = switch_xml_child(cfg, "templates"))) {</span>
<span style="color: #A00000">-                        for (param = switch_xml_child(settings, "template"); param; param = param->next) {</span>
<span style="color: #A00000">-                                char *var = (char *) switch_xml_attr(param, "name");</span>
<span style="color: #A00000">-                                if (var) {</span>
<span style="color: #A00000">-                                        char *tpl;</span>
<span style="color: #A00000">-                                        tpl = switch_core_strdup(pool, param->txt);</span>
<span style="color: #A00000">-</span>
<span style="color: #A00000">-                                        switch_core_hash_insert(globals.template_hash, var, tpl);</span>
<span style="color: #A00000">-                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Adding template %s.\n", var);</span>
<span style="color: #00A000">+                if ((schema = switch_xml_child(cfg, "schema"))) {</span>
<span style="color: #00A000">+                        /* Count fields in schema so we can calculate required buffer size */</span>
<span style="color: #00A000">+                        for (field = switch_xml_child(schema, "field"); field; field = field->next) {</span>
<span style="color: #00A000">+                                if (switch_xml_attr(field, "var")) {</span>
<span style="color: #00A000">+                                        num_fields++;</span>
                                }
                        }
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                        globals.db_schema = switch_core_alloc(pool, (num_fields + 1) * sizeof(cdr_field_t));</span>
<span style="color: #00A000">+                        cdr_field = globals.db_schema->fields;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                        for (field = switch_xml_child(schema, "field"); field; field = field->next) {</span>
<span style="color: #00A000">+                                if ((attr = switch_xml_attr(field, "var"))) {</span>
<span style="color: #00A000">+                                        cdr_field->var_name = switch_core_strdup(pool, attr);</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                        /* Assume SQL column name is the same as FreeSWITCH channel var name, unless specified otherwise */</span>
<span style="color: #00A000">+                                        if ((attr = switch_xml_attr(field, "column"))) {</span>
<span style="color: #00A000">+                                                cdr_field->col_name = switch_core_strdup(pool, attr);</span>
<span style="color: #00A000">+                                        } else {</span>
<span style="color: #00A000">+                                                cdr_field->col_name = switch_core_strdup(pool, cdr_field->var_name);</span>
<span style="color: #00A000">+                                        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                        /* Assume all fields should be quoted (treated as strings), unless specified otherwise */</span>
<span style="color: #00A000">+                                        if ((attr = switch_xml_attr(field, "quote")) && !strncmp(attr, "false", 5)) {</span>
<span style="color: #00A000">+                                                cdr_field->quote = SWITCH_FALSE;</span>
<span style="color: #00A000">+                                        } else {</span>
<span style="color: #00A000">+                                                cdr_field->quote = SWITCH_TRUE;</span>
<span style="color: #00A000">+                                        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                        /* Assume all fields allow SQL nulls, unless specified otherwise */</span>
<span style="color: #00A000">+                                        if ((attr = switch_xml_attr(field, "not-null")) && !strncmp(attr, "true", 4)) {</span>
<span style="color: #00A000">+                                                cdr_field->not_null = SWITCH_TRUE;</span>
<span style="color: #00A000">+                                        } else {</span>
<span style="color: #00A000">+                                                cdr_field->not_null = SWITCH_FALSE;</span>
<span style="color: #00A000">+                                        }</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                                        len += strlen(cdr_field->col_name) + 1;</span>
<span style="color: #00A000">+                                        cdr_field++;</span>
<span style="color: #00A000">+                                }</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+                        cdr_field->var_name = 0;</span>
<span style="color: #00A000">+</span>
<span style="color: #00A000">+                        globals.db_schema->columns = switch_core_alloc(pool, len);</span>
<span style="color: #00A000">+                        ptr = globals.db_schema->columns;</span>
<span style="color: #00A000">+                        for (cdr_field = globals.db_schema->fields; cdr_field->col_name; cdr_field++) {</span>
<span style="color: #00A000">+                                len = strlen(cdr_field->col_name);</span>
<span style="color: #00A000">+                                memcpy(ptr, cdr_field->col_name, len);</span>
<span style="color: #00A000">+                                ptr += len;</span>
<span style="color: #00A000">+                                *ptr = ',';</span>
<span style="color: #00A000">+                                ptr++;</span>
<span style="color: #00A000">+                        }</span>
<span style="color: #00A000">+                        *--ptr = '\0';</span>
                }
<span style="color: #00A000">+</span>
                switch_xml_free(xml);
        }
<span style="color: #800080; font-weight: bold">@@ -596,7 +538,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_pg_csv_load)</span>
        switch_core_add_state_handler(&state_handlers);
        *module_interface = switch_loadable_module_create_module_interface(pool, modname);
<span style="color: #A00000">-</span>
        return status;
}
</pre></div>
========================================================================<pre>
Summary of changes:
conf/autoload_configs/cdr_pg_csv.conf.xml | 25 ++-
.../event_handlers/mod_cdr_pg_csv/mod_cdr_pg_csv.c | 275 ++++++++------------
2 files changed, 128 insertions(+), 172 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>