[asterisk-commits] file: branch file/bridging r164080 - in /team/file/bridging: ./ apps/ cdr/ ch...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Dec 13 16:16:05 CST 2008


Author: file
Date: Sat Dec 13 16:16:04 2008
New Revision: 164080

URL: http://svn.digium.com/view/asterisk?view=rev&rev=164080
Log:
Merged revisions 163991,164028,164054 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r163991 | tilghman | 2008-12-13 04:36:35 -0400 (Sat, 13 Dec 2008) | 1 line
  
  Merge ast_str_opaque branch (discontinue usage of ast_str internals)
........
  r164028 | mvanbaak | 2008-12-13 09:26:13 -0400 (Sat, 13 Dec 2008) | 2 lines
  
  nuke another use of the ast_str internals.
........
  r164054 | seanbright | 2008-12-13 14:25:58 -0400 (Sat, 13 Dec 2008) | 1 line
  
  Use ast_str_strlen() instead of recalculating the string length.
........

Added:
    team/file/bridging/main/strings.c
      - copied unchanged from r164054, trunk/main/strings.c
Modified:
    team/file/bridging/   (props changed)
    team/file/bridging/apps/app_chanisavail.c
    team/file/bridging/apps/app_dumpchan.c
    team/file/bridging/apps/app_externalivr.c
    team/file/bridging/apps/app_followme.c
    team/file/bridging/apps/app_meetme.c
    team/file/bridging/apps/app_queue.c
    team/file/bridging/apps/app_voicemail.c
    team/file/bridging/cdr/cdr_adaptive_odbc.c
    team/file/bridging/cdr/cdr_manager.c
    team/file/bridging/cdr/cdr_pgsql.c
    team/file/bridging/cdr/cdr_sqlite3_custom.c
    team/file/bridging/channels/chan_dahdi.c
    team/file/bridging/channels/chan_sip.c
    team/file/bridging/channels/iax2-parser.c
    team/file/bridging/configure
    team/file/bridging/funcs/func_curl.c
    team/file/bridging/funcs/func_odbc.c
    team/file/bridging/funcs/func_realtime.c
    team/file/bridging/funcs/func_strings.c
    team/file/bridging/include/asterisk/app.h
    team/file/bridging/include/asterisk/cdr.h
    team/file/bridging/include/asterisk/pbx.h
    team/file/bridging/include/asterisk/strings.h
    team/file/bridging/include/asterisk/tcptls.h
    team/file/bridging/include/asterisk/threadstorage.h
    team/file/bridging/main/Makefile
    team/file/bridging/main/app.c
    team/file/bridging/main/asterisk.c
    team/file/bridging/main/cdr.c
    team/file/bridging/main/cli.c
    team/file/bridging/main/config.c
    team/file/bridging/main/http.c
    team/file/bridging/main/logger.c
    team/file/bridging/main/manager.c
    team/file/bridging/main/pbx.c
    team/file/bridging/main/tcptls.c
    team/file/bridging/main/translate.c
    team/file/bridging/main/utils.c
    team/file/bridging/main/xmldoc.c
    team/file/bridging/res/res_agi.c
    team/file/bridging/res/res_clialiases.c
    team/file/bridging/res/res_config_curl.c
    team/file/bridging/res/res_config_ldap.c
    team/file/bridging/res/res_config_odbc.c
    team/file/bridging/res/res_config_pgsql.c
    team/file/bridging/res/res_config_sqlite.c
    team/file/bridging/res/res_http_post.c
    team/file/bridging/res/snmp/agent.c
    team/file/bridging/utils/Makefile
    team/file/bridging/utils/check_expr.c
    team/file/bridging/utils/hashtest.c
    team/file/bridging/utils/hashtest2.c
    team/file/bridging/utils/refcounter.c

Propchange: team/file/bridging/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/file/bridging/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat Dec 13 16:16:04 2008
@@ -1,1 +1,1 @@
-/trunk:1-163956
+/trunk:1-164079

Modified: team/file/bridging/apps/app_chanisavail.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_chanisavail.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_chanisavail.c (original)
+++ team/file/bridging/apps/app_chanisavail.c Sat Dec 13 16:16:04 2008
@@ -160,13 +160,13 @@
 				status = inuse = ast_device_state(trychan);
 			}
 			if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
-					ast_str_append(&tmp_availchan, 0, "%s%s", tmp_availchan->used ? "&" : "", tempchan->name);
+					ast_str_append(&tmp_availchan, 0, "%s%s", ast_str_strlen(tmp_availchan) ? "&" : "", tempchan->name);
 					
 					snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
-					ast_str_append(&tmp_availorig, 0, "%s%s", tmp_availorig->used ? "&" : "", tmp);
+					ast_str_append(&tmp_availorig, 0, "%s%s", ast_str_strlen(tmp_availorig) ? "&" : "", tmp);
 
 					snprintf(tmp, sizeof(tmp), "%d", status);
-					ast_str_append(&tmp_availstat, 0, "%s%s", tmp_availstat->used ? "&" : "", tmp);
+					ast_str_append(&tmp_availstat, 0, "%s%s", ast_str_strlen(tmp_availstat) ? "&" : "", tmp);
 
 					ast_hangup(tempchan);
 					tempchan = NULL;
@@ -176,16 +176,16 @@
 					}
 			} else {
 				snprintf(tmp, sizeof(tmp), "%d", status);
-				ast_str_append(&tmp_availstat, 0, "%s%s", tmp_availstat->used ? "&" : "", tmp);
+				ast_str_append(&tmp_availstat, 0, "%s%s", ast_str_strlen(tmp_availstat) ? "&" : "", tmp);
 			}
 			cur = rest;
 		} while (cur);
 	}
 
-	pbx_builtin_setvar_helper(chan, "AVAILCHAN", tmp_availchan->str);
+	pbx_builtin_setvar_helper(chan, "AVAILCHAN", ast_str_buffer(tmp_availchan));
 	/* Store the originally used channel too */
-	pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp_availorig->str);
-	pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp_availstat->str);
+	pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ast_str_buffer(tmp_availorig));
+	pbx_builtin_setvar_helper(chan, "AVAILSTATUS", ast_str_buffer(tmp_availstat));
 
 	return 0;
 }

Modified: team/file/bridging/apps/app_dumpchan.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_dumpchan.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_dumpchan.c (original)
+++ team/file/bridging/apps/app_dumpchan.c Sat Dec 13 16:16:04 2008
@@ -35,6 +35,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/module.h"
 #include "asterisk/channel.h"
+#include "asterisk/app.h"
 
 /*** DOCUMENTATION
 	<application name="DumpChan" language="en_US">
@@ -148,7 +149,7 @@
 
 static int dumpchan_exec(struct ast_channel *chan, void *data)
 {
-	struct ast_str *vars = ast_str_alloca(BUFSIZ * 4); /* XXX very large! */
+	struct ast_str *vars = ast_str_thread_get(&global_app_buf, 16);
 	char info[1024];
 	int level = 0;
 	static char *line = "================================================================================";
@@ -156,10 +157,11 @@
 	if (!ast_strlen_zero(data))
 		level = atoi(data);
 
-	pbx_builtin_serialize_variables(chan, &vars);
-	serialize_showchan(chan, info, sizeof(info));
-	if (option_verbose >= level)
-		ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, vars->str, line);
+	if (option_verbose >= level) {
+		serialize_showchan(chan, info, sizeof(info));
+		pbx_builtin_serialize_variables(chan, &vars);
+		ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n", chan->name, line, info, ast_str_buffer(vars), line);
+	}
 
 	return 0;
 }

Modified: team/file/bridging/apps/app_externalivr.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_externalivr.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_externalivr.c (original)
+++ team/file/bridging/apps/app_externalivr.c Sat Dec 13 16:16:04 2008
@@ -122,8 +122,8 @@
 		ast_str_append(&tmp, 0, ",%s", data);
 	}
 
-	fprintf(handle, "%s\n", tmp->str);
-	ast_debug(1, "sent '%s'\n", tmp->str);
+	fprintf(handle, "%s\n", ast_str_buffer(tmp));
+	ast_debug(1, "sent '%s'\n", ast_str_buffer(tmp));
 }
 
 static void *gen_alloc(struct ast_channel *chan, void *params)
@@ -276,7 +276,7 @@
 
 		ast_str_append(&newstring, 0, "%s=%s,", variable, value);
 		ast_channel_unlock(chan);
-		ast_copy_string(outbuf, newstring->str, outbuflen);
+		ast_copy_string(outbuf, ast_str_buffer(newstring), outbuflen);
 	}
 }
 
@@ -659,7 +659,8 @@
  				continue;
   
 			if (input[0] == 'P') {
- 				send_eivr_event(eivr_events, 'P', args->str, chan);
+				struct ast_str *tmp = (struct ast_str *) args;
+ 				send_eivr_event(eivr_events, 'P', ast_str_buffer(tmp), chan);
 			} else if ( input[0] == 'T' ) {
 				ast_chan_log(LOG_WARNING, chan, "Answering channel if needed and starting generator\n");
 				if (chan->_state != AST_STATE_UP) {

Modified: team/file/bridging/apps/app_followme.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_followme.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_followme.c (original)
+++ team/file/bridging/apps/app_followme.c Sat Dec 13 16:16:04 2008
@@ -960,9 +960,8 @@
 		}
 		/* This one has to exist; it was part of the query */
 		ordstr = ast_variable_retrieve(cfg, catg, "ordinal");
-		ast_str_make_space(&str, strlen(numstr) + 1);
-		ast_copy_string(str->str, numstr, str->len);
-		if ((cur = create_followme_number(str->str, timeout, atoi(ordstr)))) {
+		ast_str_set(&str, 0, "%s", numstr);
+		if ((cur = create_followme_number(ast_str_buffer(str), timeout, atoi(ordstr)))) {
 			AST_LIST_INSERT_TAIL(&new->numbers, cur, entry);
 		}
 	}

Modified: team/file/bridging/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_meetme.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_meetme.c (original)
+++ team/file/bridging/apps/app_meetme.c Sat Dec 13 16:16:04 2008
@@ -1260,7 +1260,7 @@
 			min = ((now - cnf->start) % 3600) / 60;
 			sec = (now - cnf->start) % 60;
 			if (!concise) {
-				ast_cli(a->fd, MC_DATA_FORMAT, cnf->confno, cnf->users, cmdline->str, hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
+				ast_cli(a->fd, MC_DATA_FORMAT, cnf->confno, cnf->users, ast_str_buffer(cmdline), hr, min, sec, cnf->isdynamic ? "Dynamic" : "Static", cnf->locked ? "Yes" : "No");
 			} else {
 				ast_cli(a->fd, "%s!%d!%d!%02d:%02d:%02d!%d!%d\n",
 					cnf->confno,
@@ -1345,9 +1345,9 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	ast_debug(1, "Cmdline: %s\n", cmdline->str);
-
-	admin_exec(NULL, cmdline->str);
+	ast_debug(1, "Cmdline: %s\n", ast_str_buffer(cmdline));
+
+	admin_exec(NULL, ast_str_buffer(cmdline));
 	ast_free(cmdline);
 
 	return CLI_SUCCESS;
@@ -1435,9 +1435,9 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	ast_debug(1, "Cmdline: %s\n", cmdline->str);
-
-	admin_exec(NULL, cmdline->str);
+	ast_debug(1, "Cmdline: %s\n", ast_str_buffer(cmdline));
+
+	admin_exec(NULL, ast_str_buffer(cmdline));
 	ast_free(cmdline);
 
 	return CLI_SUCCESS;
@@ -4615,7 +4615,7 @@
 	ast_set_flag(&conf_flags, 
 		CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
 	answer_trunk_chan(trunk_ref->chan);
-	conf = build_conf(conf_name->str, "", "", 0, 0, 1, trunk_ref->chan);
+	conf = build_conf(ast_str_buffer(conf_name), "", "", 0, 0, 1, trunk_ref->chan);
 	if (conf) {
 		conf_run(trunk_ref->chan, conf, conf_flags.flags, NULL);
 		dispose_conf(conf);
@@ -4625,7 +4625,7 @@
 	if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations) &&
 		trunk_ref->state != SLA_TRUNK_STATE_ONHOLD_BYME) {
 		ast_str_append(&conf_name, 0, ",K");
-		admin_exec(NULL, conf_name->str);
+		admin_exec(NULL, ast_str_buffer(conf_name));
 		trunk_ref->trunk->hold_stations = 0;
 		sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, ALL_TRUNK_REFS, NULL);
 	}

Modified: team/file/bridging/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_queue.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_queue.c (original)
+++ team/file/bridging/apps/app_queue.c Sat Dec 13 16:16:04 2008
@@ -2284,7 +2284,7 @@
 /*! \brief convert "\n" to "\nVariable: " ready for manager to use */
 static char *vars2manager(struct ast_channel *chan, char *vars, size_t len)
 {
-	struct ast_str *buf = ast_str_alloca(len + 1);
+	struct ast_str *buf = ast_str_thread_get(&global_app_buf, len + 1);
 	char *tmp;
 
 	if (pbx_builtin_serialize_variables(chan, &buf)) {
@@ -2292,7 +2292,7 @@
 
 		/* convert "\n" to "\nVariable: " */
 		strcpy(vars, "Variable: ");
-		tmp = buf->str;
+		tmp = ast_str_buffer(buf);
 
 		for (i = 0, j = 10; (i < len - 1) && (j < len - 1); i++, j++) {
 			vars[j] = tmp[i];
@@ -2601,12 +2601,12 @@
 	if (qe->parent->randomperiodicannounce) {
 		qe->last_periodic_announce_sound = ((unsigned long) ast_random()) % qe->parent->numperiodicannounce;
 	} else if (qe->last_periodic_announce_sound >= qe->parent->numperiodicannounce || 
-		ast_strlen_zero(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]->str)) {
+		ast_str_strlen(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]) == 0) {
 		qe->last_periodic_announce_sound = 0;
 	}
 	
 	/* play the announcement */
-	res = play_file(qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]->str);
+	res = play_file(qe->chan, ast_str_buffer(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]));
 
 	if ((res > 0 && !valid_exit(qe, res)) || res < 0)
 		res = 0;
@@ -5734,7 +5734,7 @@
 		ast_str_append(&out, 0, ") in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds",
 			int2strat(q->strategy), q->holdtime, q->weight,
 			q->callscompleted, q->callsabandoned,sl,q->servicelevel);
-		do_print(s, fd, out->str);
+		do_print(s, fd, ast_str_buffer(out));
 		if (!ao2_container_count(q->members))
 			do_print(s, fd, "   No Members");
 		else {
@@ -5759,7 +5759,7 @@
 						mem->calls, (long) (time(NULL) - mem->lastcall));
 				else
 					ast_str_append(&out, 0, " has taken no calls yet");
-				do_print(s, fd, out->str);
+				do_print(s, fd, ast_str_buffer(out));
 				ao2_ref(mem, -1);
 			}
 		}
@@ -5774,7 +5774,7 @@
 				ast_str_set(&out, 0, "      %d. %s (wait: %ld:%2.2ld, prio: %d)",
 					pos++, qe->chan->name, (long) (now - qe->start) / 60,
 					(long) (now - qe->start) % 60, qe->prio);
-				do_print(s, fd, out->str);
+				do_print(s, fd, ast_str_buffer(out));
 			}
 		}
 		do_print(s, fd, "");	/* blank line between entries */
@@ -5795,7 +5795,7 @@
 			ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
 		else
 			ast_str_set(&out, 0, "No queues.");
-		do_print(s, fd, out->str);
+		do_print(s, fd, ast_str_buffer(out));
 	}
 	return CLI_SUCCESS;
 }

Modified: team/file/bridging/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/apps/app_voicemail.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/apps/app_voicemail.c (original)
+++ team/file/bridging/apps/app_voicemail.c Sat Dec 13 16:16:04 2008
@@ -10196,12 +10196,12 @@
 	AST_LIST_UNLOCK(&zones);
 }
 
-static char *substitute_escapes(const char *value)
-{
-	char *current, *result;
+static const char *substitute_escapes(const char *value)
+{
+	char *current;
 
 	/* Add 16 for fudge factor */
-	struct ast_str *str = ast_str_create(strlen(value) + 16);
+	struct ast_str *str = ast_str_thread_get(&global_app_buf, strlen(value) + 16);
 
 	/* Substitute strings \r, \n, and \t into the appropriate characters */
 	for (current = (char *) value; *current; current++) {
@@ -10235,10 +10235,7 @@
 		}
 	}
 
-	result = ast_strdup(str->str);
-	ast_free(str);
-
-	return result;
+	return ast_str_buffer(str);
 }
 
 static int load_config(int reload)
@@ -10858,13 +10855,13 @@
 			emailsubject = ast_strdup(val);
 		}
 		if ((val = ast_variable_retrieve(cfg, "general", "emailbody"))) {
-			emailbody = substitute_escapes(val);
+			emailbody = ast_strdup(substitute_escapes(val));
 		}
 		if ((val = ast_variable_retrieve(cfg, "general", "pagersubject"))) {
 			pagersubject = ast_strdup(val);
 		}
 		if ((val = ast_variable_retrieve(cfg, "general", "pagerbody"))) {
-			pagerbody = substitute_escapes(val);
+			pagerbody = ast_strdup(substitute_escapes(val));
 		}
 		AST_LIST_UNLOCK(&users);
 		ast_config_destroy(cfg);

Modified: team/file/bridging/cdr/cdr_adaptive_odbc.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/cdr/cdr_adaptive_odbc.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/cdr/cdr_adaptive_odbc.c (original)
+++ team/file/bridging/cdr/cdr_adaptive_odbc.c Sat Dec 13 16:16:04 2008
@@ -317,8 +317,8 @@
 #define LENGTHEN_BUF1(size)														\
 			do {																\
 				/* Lengthen buffer, if necessary */								\
-				if (sql->used + size + 1 > sql->len) {                          \
-					if (ast_str_make_space(&sql, ((sql->len + size + 1) / 512 + 1) * 512) != 0) { \
+				if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) {       \
+					if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 1) / 512 + 1) * 512) != 0) { \
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
 						ast_free(sql);											\
 						ast_free(sql2);											\
@@ -330,8 +330,8 @@
 
 #define LENGTHEN_BUF2(size)														\
 			do {																\
-				if (sql2->used + size + 1 > sql2->len) {                        \
-					if (ast_str_make_space(&sql2, ((sql2->len + size + 3) / 512 + 1) * 512) != 0) { \
+				if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) {     \
+					if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) { \
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR '%s:%s' failed.\n", tableptr->connection, tableptr->table); \
 						ast_free(sql);											\
 						ast_free(sql2);											\
@@ -368,12 +368,13 @@
 	}
 
 	AST_LIST_TRAVERSE(&odbc_tables, tableptr, list) {
+		int first = 1;
 		ast_str_set(&sql, 0, "INSERT INTO %s (", tableptr->table);
 		ast_str_set(&sql2, 0, " VALUES (");
 
 		/* No need to check the connection now; we'll handle any failure in prepare_and_execute */
 		if (!(obj = ast_odbc_request_obj(tableptr->connection, 0))) {
-			ast_log(LOG_WARNING, "cdr_adaptive_odbc: Unable to retrieve database handle for '%s:%s'.  CDR failed: %s\n", tableptr->connection, tableptr->table, sql->str);
+			ast_log(LOG_WARNING, "cdr_adaptive_odbc: Unable to retrieve database handle for '%s:%s'.  CDR failed: %s\n", tableptr->connection, tableptr->table, ast_str_buffer(sql));
 			continue;
 		}
 
@@ -442,11 +443,11 @@
 						}
 					}
 
-					ast_str_append(&sql, 0, "%s,", entry->name);
+					ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 					LENGTHEN_BUF2(strlen(colptr));
 
 					/* Encode value, with escaping */
-					ast_str_append(&sql2, 0, "'");
+					ast_str_append(&sql2, 0, "%s'", first ? "" : ",");
 					for (tmp = colptr; *tmp; tmp++) {
 						if (*tmp == '\'') {
 							ast_str_append(&sql2, 0, "''");
@@ -456,7 +457,7 @@
 							ast_str_append(&sql2, 0, "%c", *tmp);
 						}
 					}
-					ast_str_append(&sql2, 0, "',");
+					ast_str_append(&sql2, 0, "'");
 					break;
 				case SQL_TYPE_DATE:
 					{
@@ -469,16 +470,16 @@
 							(month == 2 && year % 4 == 0 && day > 29) ||
 							(month == 2 && year % 4 != 0 && day > 28)) {
 							ast_log(LOG_WARNING, "CDR variable %s is not a valid date ('%s').\n", entry->name, colptr);
-							break;
+							continue;
 						}
 
 						if (year > 0 && year < 100) {
 							year += 2000;
 						}
 
-						ast_str_append(&sql, 0, "%s,", entry->name);
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(17);
-						ast_str_append(&sql2, 0, "{ d '%04d-%02d-%02d' },", year, month, day);
+						ast_str_append(&sql2, 0, "%s{ d '%04d-%02d-%02d' }", first ? "" : ",", year, month, day);
 					}
 					break;
 				case SQL_TYPE_TIME:
@@ -488,12 +489,12 @@
 
 						if ((count != 2 && count != 3) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
 							ast_log(LOG_WARNING, "CDR variable %s is not a valid time ('%s').\n", entry->name, colptr);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(15);
-						ast_str_append(&sql2, 0, "{ t '%02d:%02d:%02d' },", hour, minute, second);
+						ast_str_append(&sql2, 0, "%s{ t '%02d:%02d:%02d' }", first ? "" : ",", hour, minute, second);
 					}
 					break;
 				case SQL_TYPE_TIMESTAMP:
@@ -511,16 +512,16 @@
 							(month == 2 && year % 4 != 0 && day > 28) ||
 							hour > 23 || minute > 59 || second > 59 || hour < 0 || minute < 0 || second < 0) {
 							ast_log(LOG_WARNING, "CDR variable %s is not a valid timestamp ('%s').\n", entry->name, colptr);
-							break;
+							continue;
 						}
 
 						if (year > 0 && year < 100) {
 							year += 2000;
 						}
 
-						ast_str_append(&sql, 0, "%s,", entry->name);
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(26);
-						ast_str_append(&sql2, 0, "{ ts '%04d-%02d-%02d %02d:%02d:%02d' },", year, month, day, hour, minute, second);
+						ast_str_append(&sql2, 0, "%s{ ts '%04d-%02d-%02d %02d:%02d:%02d' }", first ? "" : ",", year, month, day, hour, minute, second);
 					}
 					break;
 				case SQL_INTEGER:
@@ -528,12 +529,12 @@
 						int integer = 0;
 						if (sscanf(colptr, "%d", &integer) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(12);
-						ast_str_append(&sql2, 0, "%d,", integer);
+						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
 					}
 					break;
 				case SQL_BIGINT:
@@ -541,12 +542,12 @@
 						long long integer = 0;
 						if (sscanf(colptr, "%lld", &integer) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(24);
-						ast_str_append(&sql2, 0, "%lld,", integer);
+						ast_str_append(&sql2, 0, "%s%lld", first ? "" : ",", integer);
 					}
 					break;
 				case SQL_SMALLINT:
@@ -554,12 +555,12 @@
 						short integer = 0;
 						if (sscanf(colptr, "%hd", &integer) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(6);
-						ast_str_append(&sql2, 0, "%d,", integer);
+						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
 					}
 					break;
 				case SQL_TINYINT:
@@ -567,12 +568,12 @@
 						char integer = 0;
 						if (sscanf(colptr, "%hhd", &integer) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(4);
-						ast_str_append(&sql2, 0, "%d,", integer);
+						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
 					}
 					break;
 				case SQL_BIT:
@@ -580,14 +581,14 @@
 						char integer = 0;
 						if (sscanf(colptr, "%hhd", &integer) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an integer.\n", entry->name);
-							break;
+							continue;
 						}
 						if (integer != 0)
 							integer = 1;
 
-						ast_str_append(&sql, 0, "%s,", entry->name);
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(2);
-						ast_str_append(&sql2, 0, "%d,", integer);
+						ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", integer);
 					}
 					break;
 				case SQL_NUMERIC:
@@ -596,12 +597,12 @@
 						double number = 0.0;
 						if (sscanf(colptr, "%lf", &number) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an numeric type.\n", entry->name);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(entry->decimals);
-						ast_str_append(&sql2, 0, "%*.*lf,", entry->decimals, entry->radix, number);
+						ast_str_append(&sql2, 0, "%s%*.*lf", first ? "" : ",", entry->decimals, entry->radix, number);
 					}
 					break;
 				case SQL_FLOAT:
@@ -611,35 +612,37 @@
 						double number = 0.0;
 						if (sscanf(colptr, "%lf", &number) != 1) {
 							ast_log(LOG_WARNING, "CDR variable %s is not an numeric type.\n", entry->name);
-							break;
-						}
-
-						ast_str_append(&sql, 0, "%s,", entry->name);
+							continue;
+						}
+
+						ast_str_append(&sql, 0, "%s%s", first ? "" : ",", entry->name);
 						LENGTHEN_BUF2(entry->decimals);
-						ast_str_append(&sql2, 0, "%lf,", number);
+						ast_str_append(&sql2, 0, "%s%lf", first ? "" : ",", number);
 					}
 					break;
 				default:
 					ast_log(LOG_WARNING, "Column type %d (field '%s:%s:%s') is unsupported at this time.\n", entry->type, tableptr->connection, tableptr->table, entry->name);
+					continue;
 				}
+				first = 0;
 			}
 		}
 
 		/* Concatenate the two constructed buffers */
-		LENGTHEN_BUF1(sql2->used);
-		sql->str[sql->used - 1] = ')';
-		sql2->str[sql2->used - 1] = ')';
-		ast_str_append(&sql, 0, "%s", sql2->str);
-
-		ast_verb(11, "[%s]\n", sql->str);
-
-		stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, sql->str);
+		LENGTHEN_BUF1(ast_str_strlen(sql2));
+		ast_str_append(&sql, 0, ")");
+		ast_str_append(&sql2, 0, ")");
+		ast_str_append(&sql, 0, "%s", ast_str_buffer(sql2));
+
+		ast_verb(11, "[%s]\n", ast_str_buffer(sql));
+
+		stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, ast_str_buffer(sql));
 		if (stmt) {
 			SQLRowCount(stmt, &rows);
 			SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 		}
 		if (rows == 0) {
-			ast_log(LOG_WARNING, "cdr_adaptive_odbc: Insert failed on '%s:%s'.  CDR failed: %s\n", tableptr->connection, tableptr->table, sql->str);
+			ast_log(LOG_WARNING, "cdr_adaptive_odbc: Insert failed on '%s:%s'.  CDR failed: %s\n", tableptr->connection, tableptr->table, ast_str_buffer(sql));
 		}
 early_release:
 		ast_odbc_release_obj(obj);
@@ -647,11 +650,11 @@
 	AST_RWLIST_UNLOCK(&odbc_tables);
 
 	/* Next time, just allocate buffers that are that big to start with. */
-	if (sql->used > maxsize) {
-		maxsize = sql->used;
-	}
-	if (sql2->used > maxsize2) {
-		maxsize2 = sql2->used;
+	if (ast_str_strlen(sql) > maxsize) {
+		maxsize = ast_str_strlen(sql);
+	}
+	if (ast_str_strlen(sql2) > maxsize2) {
+		maxsize2 = ast_str_strlen(sql2);
 	}
 
 	ast_free(sql);

Modified: team/file/bridging/cdr/cdr_manager.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/cdr/cdr_manager.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/cdr/cdr_manager.c (original)
+++ team/file/bridging/cdr/cdr_manager.c Sat Dec 13 16:16:04 2008
@@ -95,7 +95,7 @@
 			v = ast_variable_browse(cfg, cat);
 			while (v) {
 				if (customfields && !ast_strlen_zero(v->name) && !ast_strlen_zero(v->value)) {
-					if( (customfields->used + strlen(v->value) + strlen(v->name) + 14) < customfields->len) {
+					if ((ast_str_strlen(customfields) + strlen(v->value) + strlen(v->name) + 14) < ast_str_size(customfields)) {
 						ast_str_append(&customfields, -1, "%s: ${CDR(%s)}\r\n", v->value, v->name);
 						ast_log(LOG_NOTICE, "Added mapping %s: ${CDR(%s)}\n", v->value, v->name);
 					} else {
@@ -145,10 +145,10 @@
 
 	buf[0] = 0;
 	/* Custom fields handling */
-	if (customfields != NULL && customfields->used > 0) {
+	if (customfields != NULL && ast_str_strlen(customfields)) {
 		memset(&dummy, 0, sizeof(dummy));
 		dummy.cdr = cdr;
-		pbx_substitute_variables_helper(&dummy, customfields->str, buf, sizeof(buf) - 1);
+		pbx_substitute_variables_helper(&dummy, ast_str_buffer(customfields), buf, sizeof(buf) - 1);
 	}
 
 	manager_event(EVENT_FLAG_CDR, "Cdr",

Modified: team/file/bridging/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/file/bridging/cdr/cdr_pgsql.c?view=diff&rev=164080&r1=164079&r2=164080
==============================================================================
--- team/file/bridging/cdr/cdr_pgsql.c (original)
+++ team/file/bridging/cdr/cdr_pgsql.c Sat Dec 13 16:16:04 2008
@@ -73,31 +73,31 @@
 
 static AST_RWLIST_HEAD_STATIC(psql_columns, columns);
 
-#define LENGTHEN_BUF1(size)														\
-			do {																\
-				/* Lengthen buffer, if necessary */								\
-				if (sql->used + size + 1 > sql->len) {	\
-					if (ast_str_make_space(&sql, ((sql->len + size + 1) / 512 + 1) * 512) != 0) {	\
+#define LENGTHEN_BUF1(size)                                               \
+			do {                                                          \
+				/* Lengthen buffer, if necessary */                       \
+				if (ast_str_strlen(sql) + size + 1 > ast_str_size(sql)) { \
+					if (ast_str_make_space(&sql, ((ast_str_size(sql) + size + 3) / 512 + 1) * 512) != 0) {	\
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR failed.\n"); \
-						ast_free(sql);											\
-						ast_free(sql2);											\
-						AST_RWLIST_UNLOCK(&psql_columns);						\
-						return -1;												\
-					}															\
-				}																\
+						ast_free(sql);                                    \
+						ast_free(sql2);                                   \
+						AST_RWLIST_UNLOCK(&psql_columns);                 \
+						return -1;                                        \
+					}                                                     \
+				}                                                         \
 			} while (0)
 
-#define LENGTHEN_BUF2(size)														\
-			do {																\
-				if (sql2->used + size + 1 > sql2->len) {				\
-					if (ast_str_make_space(&sql2, ((sql2->len + size + 3) / 512 + 1) * 512) != 0) {	\
+#define LENGTHEN_BUF2(size)                               \
+			do {                                          \
+				if (ast_str_strlen(sql2) + size + 1 > ast_str_size(sql2)) {  \
+					if (ast_str_make_space(&sql2, ((ast_str_size(sql2) + size + 3) / 512 + 1) * 512) != 0) {	\
 						ast_log(LOG_ERROR, "Unable to allocate sufficient memory.  Insert CDR failed.\n");	\
-						ast_free(sql);											\
-						ast_free(sql2);											\
-						AST_RWLIST_UNLOCK(&psql_columns);						\
-						return -1;												\
-					}															\
-				}																\
+						ast_free(sql);                    \
+						ast_free(sql2);                   \
+						AST_RWLIST_UNLOCK(&psql_columns); \
+						return -1;                        \
+					}                                     \
+				}                                         \
 			} while (0)
 
 static int pgsql_log(struct ast_cdr *cdr)
@@ -125,7 +125,8 @@
 		struct columns *cur;
 		struct ast_str *sql = ast_str_create(maxsize), *sql2 = ast_str_create(maxsize2);
 		char buf[257], escapebuf[513], *value;
-
+		int first = 1;
+  
 		if (!sql || !sql2) {
 			if (sql) {
 				ast_free(sql);
@@ -150,85 +151,86 @@
 				if (cur->notnull && !cur->hasdefault) {
 					/* Field is NOT NULL (but no default), must include it anyway */
 					LENGTHEN_BUF1(strlen(cur->name) + 2);
-					ast_str_append(&sql, 0, "\"%s\",", cur->name);
+					ast_str_append(&sql, 0, "%s\"%s\"", first ? "" : ",", cur->name);
 					LENGTHEN_BUF2(3);
-					ast_str_append(&sql2, 0, "'',");
+					ast_str_append(&sql2, 0, "%s''", first ? "" : ",");
+					first = 0;
 				}
 				continue;
 			}
 
 			LENGTHEN_BUF1(strlen(cur->name) + 2);
-			ast_str_append(&sql, 0, "\"%s\",", cur->name);
+			ast_str_append(&sql, 0, "%s\"%s\"", first ? "" : ",", cur->name);
 
 			if (strcmp(cur->name, "start") == 0 || strcmp(cur->name, "calldate") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
-					LENGTHEN_BUF2(12);
-					ast_str_append(&sql2, 0, "%ld", cdr->start.tv_sec);
+					LENGTHEN_BUF2(13);
+					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", cdr->start.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
-					LENGTHEN_BUF2(30);
-					ast_str_append(&sql2, 0, "%f", (double)cdr->start.tv_sec + (double)cdr->start.tv_usec / 1000000.0);
+					LENGTHEN_BUF2(31);
+					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->start.tv_sec + (double)cdr->start.tv_usec / 1000000.0);
 				} else {
 					/* char, hopefully */
-					LENGTHEN_BUF2(30);
+					LENGTHEN_BUF2(31);
 					ast_localtime(&cdr->start, &tm, NULL);
 					ast_strftime(buf, sizeof(buf), DATE_FORMAT, &tm);
-					ast_str_append(&sql2, 0, "%s", buf);
+					ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", buf);
 				}
 			} else if (strcmp(cur->name, "answer") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
-					LENGTHEN_BUF2(12);
-					ast_str_append(&sql2, 0, "%ld", cdr->answer.tv_sec);
+					LENGTHEN_BUF2(13);
+					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", cdr->answer.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
-					LENGTHEN_BUF2(30);
-					ast_str_append(&sql2, 0, "%f", (double)cdr->answer.tv_sec + (double)cdr->answer.tv_usec / 1000000.0);
+					LENGTHEN_BUF2(31);
+					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->answer.tv_sec + (double)cdr->answer.tv_usec / 1000000.0);
 				} else {
 					/* char, hopefully */
-					LENGTHEN_BUF2(30);
+					LENGTHEN_BUF2(31);
 					ast_localtime(&cdr->start, &tm, NULL);
 					ast_strftime(buf, sizeof(buf), DATE_FORMAT, &tm);
-					ast_str_append(&sql2, 0, "%s", buf);
+					ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", buf);
 				}
 			} else if (strcmp(cur->name, "end") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
-					LENGTHEN_BUF2(12);
-					ast_str_append(&sql2, 0, "%ld", cdr->end.tv_sec);
+					LENGTHEN_BUF2(13);
+					ast_str_append(&sql2, 0, "%s%ld", first ? "" : ",", cdr->end.tv_sec);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
-					LENGTHEN_BUF2(30);
-					ast_str_append(&sql2, 0, "%f", (double)cdr->end.tv_sec + (double)cdr->end.tv_usec / 1000000.0);
+					LENGTHEN_BUF2(31);
+					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->end.tv_sec + (double)cdr->end.tv_usec / 1000000.0);
 				} else {
 					/* char, hopefully */
-					LENGTHEN_BUF2(30);
+					LENGTHEN_BUF2(31);
 					ast_localtime(&cdr->end, &tm, NULL);
 					ast_strftime(buf, sizeof(buf), DATE_FORMAT, &tm);
-					ast_str_append(&sql2, 0, "%s", buf);
+					ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", buf);
 				}
 			} else if (strcmp(cur->name, "duration") == 0 || strcmp(cur->name, "billsec") == 0) {
 				if (cur->type[0] == 'i') {
 					/* Get integer, no need to escape anything */
 					ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
-					LENGTHEN_BUF2(12);
-					ast_str_append(&sql2, 0, "%s", value);
+					LENGTHEN_BUF2(13);
+					ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", value);
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					struct timeval *when = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
-					LENGTHEN_BUF2(30);
-					ast_str_append(&sql2, 0, "%f", (double)cdr->end.tv_sec - when->tv_sec + cdr->end.tv_usec / 1000000.0 - when->tv_usec / 1000000.0);
+					LENGTHEN_BUF2(31);
+					ast_str_append(&sql2, 0, "%s%f", first ? "" : ",", (double)cdr->end.tv_sec - when->tv_sec + cdr->end.tv_usec / 1000000.0 - when->tv_usec / 1000000.0);
 				} else {
 					/* Char field, probably */
 					struct timeval *when = cur->name[0] == 'd' ? &cdr->start : &cdr->answer;
-					LENGTHEN_BUF2(30);
-					ast_str_append(&sql2, 0, "'%f'", (double)cdr->end.tv_sec - when->tv_sec + cdr->end.tv_usec / 1000000.0 - when->tv_usec / 1000000.0);
+					LENGTHEN_BUF2(31);
+					ast_str_append(&sql2, 0, "%s'%f'", first ? "" : ",", (double)cdr->end.tv_sec - when->tv_sec + cdr->end.tv_usec / 1000000.0 - when->tv_usec / 1000000.0);
 				}
 			} else if (strcmp(cur->name, "disposition") == 0 || strcmp(cur->name, "amaflags") == 0) {
 				if (strncmp(cur->type, "int", 3) == 0) {
 					/* Integer, no need to escape anything */
 					ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 1);
-					LENGTHEN_BUF2(12);
-					ast_str_append(&sql2, 0, "%s", value);
+					LENGTHEN_BUF2(13);
+					ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", value);
 				} else {
 					/* Although this is a char field, there are no special characters in the values for these fields */
 					ast_cdr_getvar(cdr, cur->name, &value, buf, sizeof(buf), 0, 0);
-					LENGTHEN_BUF2(30);
-					ast_str_append(&sql2, 0, "'%s'", value);
+					LENGTHEN_BUF2(31);
+					ast_str_append(&sql2, 0, "%s'%s'", first ? "" : ",", value);
 				}
 			} else {
 				/* Arbitrary field, could be anything */
@@ -236,20 +238,20 @@
 				if (strncmp(cur->type, "int", 3) == 0) {
 					long long whatever;
 					if (value && sscanf(value, "%lld", &whatever) == 1) {
-						LENGTHEN_BUF2(25);
-						ast_str_append(&sql2, 0, "%lld", whatever);
+						LENGTHEN_BUF2(26);
+						ast_str_append(&sql2, 0, "%s%lld", first ? "" : ",", whatever);
 					} else {
-						LENGTHEN_BUF2(1);
-						ast_str_append(&sql2, 0, "0");
+						LENGTHEN_BUF2(2);
+						ast_str_append(&sql2, 0, "%s0", first ? "" : ",");
 					}
 				} else if (strncmp(cur->type, "float", 5) == 0) {
 					long double whatever;
 					if (value && sscanf(value, "%Lf", &whatever) == 1) {
-						LENGTHEN_BUF2(50);
-						ast_str_append(&sql2, 0, "%30Lf", whatever);
+						LENGTHEN_BUF2(51);
+						ast_str_append(&sql2, 0, "%s%30Lf", first ? "" : ",", whatever);
 					} else {
-						LENGTHEN_BUF2(1);
-						ast_str_append(&sql2, 0, "0");
+						LENGTHEN_BUF2(2);
+						ast_str_append(&sql2, 0, "%s0", first ? "" : ",");
 					}
 				/* XXX Might want to handle dates, times, and other misc fields here XXX */
 				} else {
@@ -257,19 +259,16 @@
 						PQescapeStringConn(conn, escapebuf, value, strlen(value), NULL);
 					else
 						escapebuf[0] = '\0';
-					LENGTHEN_BUF2(strlen(escapebuf) + 2);
-					ast_str_append(&sql2, 0, "'%s'", escapebuf);
-				}
-			}
-			LENGTHEN_BUF2(1);
-			ast_str_append(&sql2, 0, ",");
+					LENGTHEN_BUF2(strlen(escapebuf) + 3);
+					ast_str_append(&sql2, 0, "%s'%s'", first ? "" : ",", escapebuf);
+				}
+			}
+			first = 0;
   		}
 		AST_RWLIST_UNLOCK(&psql_columns);
-		LENGTHEN_BUF1(sql2->len);
-		sql->str[sql->used - 1] = ')';
-		sql2->str[sql2->used - 1] = ')';
-		ast_str_append(&sql, 0, "%s", sql2->str);
-		ast_verb(11, "[%s]\n", sql->str);
+		LENGTHEN_BUF1(ast_str_strlen(sql2) + 2);
+		ast_str_append(&sql, 0, ")%s)", ast_str_buffer(sql2));
+		ast_verb(11, "[%s]\n", ast_str_buffer(sql));
 
 		ast_debug(2, "inserting a CDR record.\n");
 
@@ -297,7 +296,7 @@
 				return -1;
 			}
 		}
-		result = PQexec(conn, sql->str);
+		result = PQexec(conn, ast_str_buffer(sql));
 		if (PQresultStatus(result) != PGRES_COMMAND_OK) {
 			pgerror = PQresultErrorMessage(result);
 			ast_log(LOG_ERROR, "Failed to insert call detail record into database!\n");
@@ -308,7 +307,7 @@
 				ast_log(LOG_ERROR, "Connection reestablished.\n");
 				connected = 1;
 				PQclear(result);
-				result = PQexec(conn, sql->str);
+				result = PQexec(conn, ast_str_buffer(sql));
 				if (PQresultStatus(result) != PGRES_COMMAND_OK) {
 					pgerror = PQresultErrorMessage(result);

[... 4075 lines stripped ...]



More information about the asterisk-commits mailing list