aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-13 08:36:35 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-13 08:36:35 +0000
commita41b34a63c52608e7e5c8e6aced613815461f4c2 (patch)
tree0559c99680217b78c0bda37a131b5f09794f43c6 /res
parentb298a3aa9b396c4055bf75104b4fb89212c44d4a (diff)
Merge ast_str_opaque branch (discontinue usage of ast_str internals)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@163991 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_agi.c6
-rw-r--r--res/res_clialiases.c4
-rw-r--r--res/res_config_curl.c16
-rw-r--r--res/res_config_ldap.c14
-rw-r--r--res/res_config_odbc.c6
-rw-r--r--res/res_config_pgsql.c108
-rw-r--r--res/res_config_sqlite.c23
-rw-r--r--res/res_http_post.c2
8 files changed, 89 insertions, 90 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index cfdd48e39..bda3e79a4 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -377,13 +377,13 @@ int ast_agi_send(int fd, struct ast_channel *chan, char *fmt, ...)
if (agidebug) {
if (chan) {
- ast_verbose("<%s>AGI Tx >> %s", chan->name, buf->str);
+ ast_verbose("<%s>AGI Tx >> %s", chan->name, ast_str_buffer(buf));
} else {
- ast_verbose("AGI Tx >> %s", buf->str);
+ ast_verbose("AGI Tx >> %s", ast_str_buffer(buf));
}
}
- return ast_carefulwrite(fd, buf->str, buf->used, 100);
+ return ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100);
}
/* linked list of AGI commands ready to be executed by Async AGI */
diff --git a/res/res_clialiases.c b/res/res_clialiases.c
index 1ea302401..156212f6b 100644
--- a/res/res_clialiases.c
+++ b/res/res_clialiases.c
@@ -101,7 +101,7 @@ static char *cli_alias_passthrough(struct ast_cli_entry *e, int cmd, struct ast_
if (!ast_strlen_zero(a->word)) {
struct ast_str *real_cmd = ast_str_alloca(strlen(alias->real_cmd) + strlen(line) + 1);
ast_str_append(&real_cmd, 0, "%s%s", alias->real_cmd, line);
- generator = ast_cli_generator(real_cmd->str, a->word, a->n);
+ generator = ast_cli_generator(ast_str_buffer(real_cmd), a->word, a->n);
} else {
generator = ast_cli_generator(alias->real_cmd, a->word, a->n);
}
@@ -121,7 +121,7 @@ static char *cli_alias_passthrough(struct ast_cli_entry *e, int cmd, struct ast_
ast_str_append(&real_cmd, 0, " %s", a->argv[i - 1]);
}
- ast_cli_command(a->fd, real_cmd->str);
+ ast_cli_command(a->fd, ast_str_buffer(real_cmd));
} else {
ast_cli_command(a->fd, alias->real_cmd);
}
diff --git a/res/res_config_curl.c b/res/res_config_curl.c
index b159c768d..1d259c845 100644
--- a/res/res_config_curl.c
+++ b/res/res_config_curl.c
@@ -88,7 +88,7 @@ static struct ast_variable *realtime_curl(const char *url, const char *unused, v
va_end(ap);
ast_str_append(&query, 0, ")}");
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
/* Remove any trailing newline characters */
if ((stringp = strchr(buffer, '\r')) || (stringp = strchr(buffer, '\n')))
@@ -170,7 +170,7 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
ast_str_append(&query, 0, ")}");
/* Do the CURL query */
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
if (!(cfg = ast_config_new()))
goto exit_multi;
@@ -258,7 +258,7 @@ static int update_curl(const char *url, const char *unused, const char *keyfield
va_end(ap);
ast_str_append(&query, 0, ")}");
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
/* Line oriented output */
stringp = buffer;
@@ -321,7 +321,7 @@ static int update2_curl(const char *url, const char *unused, va_list ap)
ast_str_append(&query, 0, ")}");
/* TODO: Make proxies work */
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
/* Line oriented output */
stringp = buffer;
@@ -385,7 +385,7 @@ static int store_curl(const char *url, const char *unused, va_list ap)
va_end(ap);
ast_str_append(&query, 0, ")}");
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
stringp = buffer;
while (*stringp <= ' ')
@@ -452,7 +452,7 @@ static int destroy_curl(const char *url, const char *unused, const char *keyfiel
va_end(ap);
ast_str_append(&query, 0, ")}");
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
/* Line oriented output */
stringp = buffer;
@@ -511,7 +511,7 @@ static int require_curl(const char *url, const char *unused, va_list ap)
va_end(ap);
ast_str_append(&query, 0, ")}");
- pbx_substitute_variables_helper(NULL, query->str, buffer, sizeof(buffer));
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, sizeof(buffer));
return atoi(buffer);
}
@@ -544,7 +544,7 @@ static struct ast_config *config_curl(const char *url, const char *unused, const
ast_str_set(&query, 0, "${CURL(%s/static?file=%s)}", url, buf1);
/* Do the CURL query */
- pbx_substitute_variables_helper(NULL, query->str, buffer, bufsize);
+ pbx_substitute_variables_helper(NULL, ast_str_buffer(query), buffer, bufsize);
/* Line oriented output */
stringp = buffer;
diff --git a/res/res_config_ldap.c b/res/res_config_ldap.c
index 8fbfef897..7ff9015f2 100644
--- a/res/res_config_ldap.c
+++ b/res/res_config_ldap.c
@@ -789,7 +789,7 @@ static struct ast_variable **realtime_ldap_base_ap(unsigned int *entries_count_p
do {
/* freeing ldap_result further down */
result = ldap_search_ext_s(ldapConn, clean_basedn,
- LDAP_SCOPE_SUBTREE, filter->str, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
+ LDAP_SCOPE_SUBTREE, ast_str_buffer(filter), NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
&ldap_result_msg);
if (result != LDAP_SUCCESS && is_ldap_connect_error(result)) {
ast_log(LOG_DEBUG, "Failed to query database. Try %d/10\n",
@@ -808,7 +808,7 @@ static struct ast_variable **realtime_ldap_base_ap(unsigned int *entries_count_p
if (result != LDAP_SUCCESS) {
ast_log(LOG_WARNING, "Failed to query database. Check debug for more info.\n");
- ast_log(LOG_WARNING, "Query: %s\n", filter->str);
+ ast_log(LOG_WARNING, "Query: %s\n", ast_str_buffer(filter));
ast_log(LOG_WARNING, "Query Failed because: %s\n", ldap_err2string(result));
} else {
/* this is where we create the variables from the search result
@@ -818,7 +818,7 @@ static struct ast_variable **realtime_ldap_base_ap(unsigned int *entries_count_p
vars = realtime_ldap_result_to_vars(table_config, ldap_result_msg, entries_count_ptr);
} else {
ast_debug(1, "Could not find any entry matching %s in base dn %s.\n",
- filter->str, clean_basedn);
+ ast_str_buffer(filter), clean_basedn);
}
ldap_msgfree(ldap_result_msg);
@@ -1246,7 +1246,7 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
do {
/* freeing ldap_result further down */
result = ldap_search_ext_s(ldapConn, clean_basedn,
- LDAP_SCOPE_SUBTREE, filter->str, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
+ LDAP_SCOPE_SUBTREE, ast_str_buffer(filter), NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
&ldap_result_msg);
if (result != LDAP_SUCCESS && is_ldap_connect_error(result)) {
ast_log(LOG_WARNING, "Failed to query database. Try %d/3\n",
@@ -1266,7 +1266,7 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
if (result != LDAP_SUCCESS) {
ast_log(LOG_WARNING, "Failed to query directory. Check debug for more info.\n");
- ast_log(LOG_WARNING, "Query: %s\n", filter->str);
+ ast_log(LOG_WARNING, "Query: %s\n", ast_str_buffer(filter));
ast_log(LOG_WARNING, "Query Failed because: %s\n",
ldap_err2string(result));
@@ -1433,7 +1433,7 @@ static int update2_ldap(const char *basedn, const char *table_name, va_list ap)
do {
/* freeing ldap_result further down */
result = ldap_search_ext_s(ldapConn, clean_basedn,
- LDAP_SCOPE_SUBTREE, filter->str, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
+ LDAP_SCOPE_SUBTREE, ast_str_buffer(filter), NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT,
&ldap_result_msg);
if (result != LDAP_SUCCESS && is_ldap_connect_error(result)) {
ast_log(LOG_WARNING, "Failed to query database. Try %d/3\n",
@@ -1453,7 +1453,7 @@ static int update2_ldap(const char *basedn, const char *table_name, va_list ap)
if (result != LDAP_SUCCESS) {
ast_log(LOG_WARNING, "Failed to query directory. Check debug for more info.\n");
- ast_log(LOG_WARNING, "Query: %s\n", filter->str);
+ ast_log(LOG_WARNING, "Query: %s\n", ast_str_buffer(filter));
ast_log(LOG_WARNING, "Query Failed because: %s\n",
ldap_err2string(result));
diff --git a/res/res_config_odbc.c b/res/res_config_odbc.c
index a815a9de9..8de431475 100644
--- a/res/res_config_odbc.c
+++ b/res/res_config_odbc.c
@@ -555,9 +555,9 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
/* Done with the table metadata */
ast_odbc_release_table(tableptr);
- res = SQLPrepare(stmt, (unsigned char *)sql->str, SQL_NTS);
+ res = SQLPrepare(stmt, (unsigned char *)ast_str_buffer(sql), SQL_NTS);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
- ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql->str);
+ ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", ast_str_buffer(sql));
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
return NULL;
}
@@ -606,7 +606,7 @@ static int update2_odbc(const char *database, const char *table, va_list ap)
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
/* Since only a single thread can access this memory, we can retrieve what would otherwise be lost. */
sql = ast_str_thread_get(&sql_buf, 16);
- ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n", sql->str);
+ ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n", ast_str_buffer(sql));
return -1;
}
diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c
index a22f03a6d..877901243 100644
--- a/res/res_config_pgsql.c
+++ b/res/res_config_pgsql.c
@@ -94,10 +94,10 @@ static struct ast_cli_entry cli_realtime[] = {
#define ESCAPE_STRING(buffer, stringname) \
do { \
int len; \
- if ((len = strlen(stringname)) > (buffer->len - 1) / 2) { \
+ if ((len = strlen(stringname)) > (ast_str_size(buffer) - 1) / 2) { \
ast_str_make_space(&buffer, len * 2 + 1); \
} \
- PQescapeStringConn(pgsqlConn, buffer->str, stringname, len, &pgresult); \
+ PQescapeStringConn(pgsqlConn, ast_str_buffer(buffer), stringname, len, &pgresult); \
} while (0)
static void destroy_table(struct tables *table)
@@ -137,7 +137,7 @@ static struct tables *find_table(const char *tablename)
/* Not found, scan the table */
ast_str_set(&sql, 0, "SELECT a.attname, t.typname, a.attlen, a.attnotnull, d.adsrc, a.atttypmod FROM pg_class c, pg_type t, pg_attribute a LEFT OUTER JOIN pg_attrdef d ON a.atthasdef AND d.adrelid = a.attrelid AND d.adnum = a.attnum WHERE c.oid = a.attrelid AND a.atttypid = t.oid AND (a.attnum > 0) AND c.relname = '%s' ORDER BY c.relname, attnum", tablename);
- result = PQexec(pgsqlConn, sql->str);
+ result = PQexec(pgsqlConn, ast_str_buffer(sql));
ast_debug(1, "Query of table structure complete. Now retrieving results.\n");
if (PQresultStatus(result) != PGRES_TUPLES_OK) {
pgerror = PQresultErrorMessage(result);
@@ -260,7 +260,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
return NULL;
}
- ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'", tablename, newparam, op, escapebuf->str);
+ ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'", tablename, newparam, op, ast_str_buffer(escapebuf));
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
if (!strchr(newparam, ' '))
@@ -275,7 +275,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
return NULL;
}
- ast_str_append(&sql, 0, " AND %s%s '%s'", newparam, op, escapebuf->str);
+ ast_str_append(&sql, 0, " AND %s%s '%s'", newparam, op, ast_str_buffer(escapebuf));
}
va_end(ap);
@@ -286,10 +286,10 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
return NULL;
}
- if (!(result = PQexec(pgsqlConn, sql->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query '%s@%s'. Check debug for more info.\n", tablename, database);
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
return NULL;
@@ -300,7 +300,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query '%s@%s'. Check debug for more info.\n", tablename, database);
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -308,7 +308,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab
}
}
- ast_debug(1, "PostgreSQL RealTime: Result=%p Query: %s\n", result, sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Result=%p Query: %s\n", result, ast_str_buffer(sql));
if ((num_rows = PQntuples(result)) > 0) {
int i = 0;
@@ -410,7 +410,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
return NULL;
}
- ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op, escapebuf->str);
+ ast_str_set(&sql, 0, "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op, ast_str_buffer(escapebuf));
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
if (!strchr(newparam, ' '))
@@ -425,7 +425,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
return NULL;
}
- ast_str_append(&sql, 0, " AND %s%s '%s'", newparam, op, escapebuf->str);
+ ast_str_append(&sql, 0, " AND %s%s '%s'", newparam, op, ast_str_buffer(escapebuf));
}
if (initfield) {
@@ -441,10 +441,10 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
return NULL;
}
- if (!(result = PQexec(pgsqlConn, sql->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query %s@%s. Check debug for more info.\n", table, database);
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
return NULL;
@@ -455,7 +455,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query %s@%s. Check debug for more info.\n", table, database);
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -463,7 +463,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char
}
}
- ast_debug(1, "PostgreSQL RealTime: Result=%p Query: %s\n", result, sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Result=%p Query: %s\n", result, ast_str_buffer(sql));
if ((num_rows = PQntuples(result)) > 0) {
int numFields = PQnfields(result);
@@ -570,7 +570,7 @@ static int update_pgsql(const char *database, const char *tablename, const char
release_table(table);
return -1;
}
- ast_str_set(&sql, 0, "UPDATE %s SET %s = '%s'", tablename, newparam, escapebuf->str);
+ ast_str_set(&sql, 0, "UPDATE %s SET %s = '%s'", tablename, newparam, ast_str_buffer(escapebuf));
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
@@ -588,7 +588,7 @@ static int update_pgsql(const char *database, const char *tablename, const char
return -1;
}
- ast_str_append(&sql, 0, ", %s = '%s'", newparam, escapebuf->str);
+ ast_str_append(&sql, 0, ", %s = '%s'", newparam, ast_str_buffer(escapebuf));
}
va_end(ap);
release_table(table);
@@ -600,9 +600,9 @@ static int update_pgsql(const char *database, const char *tablename, const char
return -1;
}
- ast_str_append(&sql, 0, " WHERE %s = '%s'", keyfield, escapebuf->str);
+ ast_str_append(&sql, 0, " WHERE %s = '%s'", keyfield, ast_str_buffer(escapebuf));
- ast_debug(1, "PostgreSQL RealTime: Update SQL: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Update SQL: %s\n", ast_str_buffer(sql));
/* We now have our complete statement; Lets connect to the server and execute it. */
ast_mutex_lock(&pgsql_lock);
@@ -611,10 +611,10 @@ static int update_pgsql(const char *database, const char *tablename, const char
return -1;
}
- if (!(result = PQexec(pgsqlConn, sql->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
ast_free(sql);
@@ -626,7 +626,7 @@ static int update_pgsql(const char *database, const char *tablename, const char
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -696,7 +696,7 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
ast_free(sql);
return -1;
}
- ast_str_append(&where, 0, "%s %s='%s'", first ? "" : " AND", newparam, escapebuf->str);
+ ast_str_append(&where, 0, "%s %s='%s'", first ? "" : " AND", newparam, ast_str_buffer(escapebuf));
first = 0;
}
@@ -730,13 +730,13 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
return -1;
}
- ast_str_append(&sql, 0, "%s %s='%s'", first ? "" : ",", newparam, escapebuf->str);
+ ast_str_append(&sql, 0, "%s %s='%s'", first ? "" : ",", newparam, ast_str_buffer(escapebuf));
}
release_table(table);
- ast_str_append(&sql, 0, " %s", where->str);
+ ast_str_append(&sql, 0, " %s", ast_str_buffer(where));
- ast_debug(1, "PostgreSQL RealTime: Update SQL: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Update SQL: %s\n", ast_str_buffer(sql));
/* We now have our complete statement; connect to the server and execute it. */
ast_mutex_lock(&pgsql_lock);
@@ -745,10 +745,10 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
return -1;
}
- if (!(result = PQexec(pgsqlConn, sql->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
return -1;
@@ -759,7 +759,7 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -823,25 +823,25 @@ static int store_pgsql(const char *database, const char *table, va_list ap)
/* Create the first part of the query using the first parameter/value pairs we just extracted
If there is only 1 set, then we have our query. Otherwise, loop thru the list and concat */
ESCAPE_STRING(buf, newparam);
- ast_str_set(&sql1, 0, "INSERT INTO %s (%s", table, buf->str);
+ ast_str_set(&sql1, 0, "INSERT INTO %s (%s", table, ast_str_buffer(buf));
ESCAPE_STRING(buf, newval);
- ast_str_set(&sql2, 0, ") VALUES ('%s'", buf->str);
+ ast_str_set(&sql2, 0, ") VALUES ('%s'", ast_str_buffer(buf));
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
ESCAPE_STRING(buf, newparam);
- ast_str_append(&sql1, 0, ", %s", buf->str);
+ ast_str_append(&sql1, 0, ", %s", ast_str_buffer(buf));
ESCAPE_STRING(buf, newval);
- ast_str_append(&sql2, 0, ", '%s'", buf->str);
+ ast_str_append(&sql2, 0, ", '%s'", ast_str_buffer(buf));
}
va_end(ap);
- ast_str_append(&sql1, 0, "%s)", sql2->str);
+ ast_str_append(&sql1, 0, "%s)", ast_str_buffer(sql2));
- ast_debug(1, "PostgreSQL RealTime: Insert SQL: %s\n", sql1->str);
+ ast_debug(1, "PostgreSQL RealTime: Insert SQL: %s\n", ast_str_buffer(sql1));
- if (!(result = PQexec(pgsqlConn, sql1->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql1)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql1->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql1));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
return -1;
@@ -852,7 +852,7 @@ static int store_pgsql(const char *database, const char *table, va_list ap)
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql1->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql1));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -918,21 +918,21 @@ static int destroy_pgsql(const char *database, const char *table, const char *ke
ESCAPE_STRING(buf1, keyfield);
ESCAPE_STRING(buf2, lookup);
- ast_str_set(&sql, 0, "DELETE FROM %s WHERE %s = '%s'", table, buf1->str, buf2->str);
+ ast_str_set(&sql, 0, "DELETE FROM %s WHERE %s = '%s'", table, ast_str_buffer(buf1), ast_str_buffer(buf2));
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
ESCAPE_STRING(buf1, newparam);
ESCAPE_STRING(buf2, newval);
- ast_str_append(&sql, 0, " AND %s = '%s'", buf1->str, buf2->str);
+ ast_str_append(&sql, 0, " AND %s = '%s'", ast_str_buffer(buf1), ast_str_buffer(buf2));
}
va_end(ap);
- ast_debug(1, "PostgreSQL RealTime: Delete SQL: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Delete SQL: %s\n", ast_str_buffer(sql));
- if (!(result = PQexec(pgsqlConn, sql->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
return -1;
@@ -943,7 +943,7 @@ static int destroy_pgsql(const char *database, const char *table, const char *ke
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -992,7 +992,7 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
"WHERE filename='%s' and commented=0"
"ORDER BY cat_metric DESC, var_metric ASC, category, var_name ", table, file);
- ast_debug(1, "PostgreSQL RealTime: Static SQL: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Static SQL: %s\n", ast_str_buffer(sql));
/* We now have our complete statement; Lets connect to the server and execute it. */
ast_mutex_lock(&pgsql_lock);
@@ -1001,10 +1001,10 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
return NULL;
}
- if (!(result = PQexec(pgsqlConn, sql->str))) {
+ if (!(result = PQexec(pgsqlConn, ast_str_buffer(sql)))) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query '%s@%s'. Check debug for more info.\n", table, database);
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
ast_mutex_unlock(&pgsql_lock);
return NULL;
@@ -1015,7 +1015,7 @@ static struct ast_config *config_pgsql(const char *database, const char *table,
&& result_status != PGRES_NONFATAL_ERROR) {
ast_log(LOG_WARNING,
"PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
- ast_debug(1, "PostgreSQL RealTime: Query: %s\n", sql->str);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
PQresultErrorMessage(result), PQresStatus(result_status));
ast_mutex_unlock(&pgsql_lock);
@@ -1163,16 +1163,16 @@ static int require_pgsql(const char *database, const char *tablename, va_list ap
ast_mutex_lock(&pgsql_lock);
if (!pgsql_reconnect(database)) {
ast_mutex_unlock(&pgsql_lock);
- ast_log(LOG_ERROR, "Unable to add column: %s\n", sql->str);
+ ast_log(LOG_ERROR, "Unable to add column: %s\n", ast_str_buffer(sql));
ast_free(sql);
continue;
}
ast_debug(1, "About to run ALTER query on table '%s' to add column '%s'\n", tablename, elm);
- result = PQexec(pgsqlConn, sql->str);
+ result = PQexec(pgsqlConn, ast_str_buffer(sql));
ast_debug(1, "Finished running ALTER query on table '%s'\n", tablename);
if (PQresultStatus(result) != PGRES_COMMAND_OK) {
- ast_log(LOG_ERROR, "Unable to add column: %s\n", sql->str);
+ ast_log(LOG_ERROR, "Unable to add column: %s\n", ast_str_buffer(sql));
}
PQclear(result);
ast_mutex_unlock(&pgsql_lock);
@@ -1399,9 +1399,9 @@ static int pgsql_reconnect(const char *database)
if (!ast_strlen_zero(dbpass))
ast_str_append(&connInfo, 0, " password=%s", dbpass);
- ast_debug(1, "%u connInfo=%s\n", (unsigned int)connInfo->len, connInfo->str);
- pgsqlConn = PQconnectdb(connInfo->str);
- ast_debug(1, "%u connInfo=%s\n", (unsigned int)connInfo->len, connInfo->str);
+ ast_debug(1, "%u connInfo=%s\n", (unsigned int)ast_str_size(connInfo), ast_str_buffer(connInfo));
+ pgsqlConn = PQconnectdb(ast_str_buffer(connInfo));
+ ast_debug(1, "%u connInfo=%s\n", (unsigned int)ast_str_size(connInfo), ast_str_buffer(connInfo));
ast_free(connInfo);
connInfo = NULL;
diff --git a/res/res_config_sqlite.c b/res/res_config_sqlite.c
index 756de0cd5..114aa803b 100644
--- a/res/res_config_sqlite.c
+++ b/res/res_config_sqlite.c
@@ -789,6 +789,7 @@ static int cdr_handler(struct ast_cdr *cdr)
struct sqlite_cache_tables *tbl = find_table(cdr_table);
struct sqlite_cache_columns *col;
struct ast_str *sql1 = ast_str_create(160), *sql2 = ast_str_create(16);
+ int first = 1;
if (!tbl) {
ast_log(LOG_WARNING, "No such table: %s\n", cdr_table);
@@ -805,33 +806,31 @@ static int cdr_handler(struct ast_cdr *cdr)
continue;
}
if (sscanf(tmp, "%d", &scannum) == 1) {
- ast_str_append(&sql1, 0, "%s,", col->name);
- ast_str_append(&sql2, 0, "%d,", scannum);
+ ast_str_append(&sql1, 0, "%s%s", first ? "" : ",", col->name);
+ ast_str_append(&sql2, 0, "%s%d", first ? "" : ",", scannum);
}
} else {
ast_cdr_getvar(cdr, col->name, &tmp, workspace, sizeof(workspace), 0, 0);
if (!tmp) {
continue;
}
- ast_str_append(&sql1, 0, "%s,", col->name);
+ ast_str_append(&sql1, 0, "%s%s", first ? "" : ",", col->name);
tmp = sqlite_mprintf("%Q", tmp);
- ast_str_append(&sql2, 0, "%s,", tmp);
+ ast_str_append(&sql2, 0, "%s%s", first ? "" : ",", tmp);
sqlite_freemem(tmp);
}
}
release_table(tbl);
- sql1->str[--sql1->used] = '\0';
- sql2->str[--sql2->used] = '\0';
- ast_str_append(&sql1, 0, "%s)", sql2->str);
+ ast_str_append(&sql1, 0, "%s)", ast_str_buffer(sql2));
ast_free(sql2);
- ast_debug(1, "SQL query: %s\n", sql1->str);
+ ast_debug(1, "SQL query: %s\n", ast_str_buffer(sql1));
ast_mutex_lock(&mutex);
RES_CONFIG_SQLITE_BEGIN
- error = sqlite_exec(db, sql1->str, NULL, NULL, &errormsg);
+ error = sqlite_exec(db, ast_str_buffer(sql1), NULL, NULL, &errormsg);
RES_CONFIG_SQLITE_END(error)
ast_mutex_unlock(&mutex);
@@ -1413,13 +1412,13 @@ static int realtime_update2_handler(const char *database, const char *table,
first = 0;
}
- ast_str_append(&sql, 0, " %s", where->str);
- ast_debug(1, "SQL query: %s\n", sql->str);
+ ast_str_append(&sql, 0, " %s", ast_str_buffer(where));
+ ast_debug(1, "SQL query: %s\n", ast_str_buffer(sql));
ast_mutex_lock(&mutex);
RES_CONFIG_SQLITE_BEGIN
- error = sqlite_exec(db, sql->str, NULL, NULL, &errormsg);
+ error = sqlite_exec(db, ast_str_buffer(sql), NULL, NULL, &errormsg);
RES_CONFIG_SQLITE_END(error)
if (!error) {
diff --git a/res/res_http_post.c b/res/res_http_post.c
index 4a3156720..26daf7ad8 100644
--- a/res/res_http_post.c
+++ b/res/res_http_post.c
@@ -390,7 +390,7 @@ static struct ast_str *http_post_callback(struct ast_tcptls_session_instance *se
NULL, "The was an error parsing the request.");
}
- if (!(message_count = process_message(message, post_dir->str))) {
+ if (!(message_count = process_message(message, ast_str_buffer(post_dir)))) {
ast_log(LOG_ERROR, "Invalid MIME data, found no parts!\n");
g_object_unref(message);
return ast_http_error((*status = 400),