diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-13 08:36:35 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-12-13 08:36:35 +0000 |
commit | a41b34a63c52608e7e5c8e6aced613815461f4c2 (patch) | |
tree | 0559c99680217b78c0bda37a131b5f09794f43c6 /funcs | |
parent | b298a3aa9b396c4055bf75104b4fb89212c44d4a (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 'funcs')
-rw-r--r-- | funcs/func_curl.c | 30 | ||||
-rw-r--r-- | funcs/func_odbc.c | 121 | ||||
-rw-r--r-- | funcs/func_realtime.c | 30 | ||||
-rw-r--r-- | funcs/func_strings.c | 13 |
4 files changed, 77 insertions, 117 deletions
diff --git a/funcs/func_curl.c b/funcs/func_curl.c index 3a936e704..d4f34b850 100644 --- a/funcs/func_curl.c +++ b/funcs/func_curl.c @@ -354,14 +354,11 @@ static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *da register int realsize = size * nmemb; struct ast_str **pstr = (struct ast_str **)data; - ast_debug(3, "Called with data=%p, str=%p, realsize=%d, len=%zu, used=%zu\n", data, *pstr, realsize, (*pstr)->len, (*pstr)->used); + ast_debug(3, "Called with data=%p, str=%p, realsize=%d, len=%zu, used=%zu\n", data, *pstr, realsize, ast_str_size(*pstr), ast_str_strlen(*pstr)); - if (ast_str_make_space(pstr, (((*pstr)->used + realsize + 1) / 512 + 1) * 512 + 230) == 0) { - memcpy(&((*pstr)->str[(*pstr)->used]), ptr, realsize); - (*pstr)->used += realsize; - } + ast_str_append_substr(pstr, 0, ptr, realsize); - ast_debug(3, "Now, len=%zu, used=%zu\n", (*pstr)->len, (*pstr)->used); + ast_debug(3, "Now, len=%zu, used=%zu\n", ast_str_size(*pstr), ast_str_strlen(*pstr)); return realsize; } @@ -467,18 +464,15 @@ static int acf_curl_exec(struct ast_channel *chan, const char *cmd, char *info, curl_easy_setopt(*curl, CURLOPT_POST, 0); } - if (str->used) { - str->str[str->used] = '\0'; - if (str->str[str->used - 1] == '\n') { - str->str[str->used - 1] = '\0'; - } + if (ast_str_strlen(str)) { + ast_str_trim_blanks(str); - ast_log(LOG_NOTICE, "str='%s'\n", str->str); + ast_debug(3, "str='%s'\n", ast_str_buffer(str)); if (hashcompat) { - char *remainder = str->str; + char *remainder = ast_str_buffer(str); char *piece; - struct ast_str *fields = ast_str_create(str->used / 2); - struct ast_str *values = ast_str_create(str->used / 2); + struct ast_str *fields = ast_str_create(ast_str_strlen(str) / 2); + struct ast_str *values = ast_str_create(ast_str_strlen(str) / 2); int rowcount = 0; while ((piece = strsep(&remainder, "&"))) { char *name = strsep(&piece, "="); @@ -488,12 +482,12 @@ static int acf_curl_exec(struct ast_channel *chan, const char *cmd, char *info, ast_str_append(&values, 0, "%s%s", rowcount ? "," : "", piece); rowcount++; } - pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", fields->str); - ast_copy_string(buf, values->str, len); + pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields)); + ast_copy_string(buf, ast_str_buffer(values), len); ast_free(fields); ast_free(values); } else { - ast_copy_string(buf, str->str, len); + ast_copy_string(buf, ast_str_buffer(str), len); } ret = 0; } diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c index 36f530c6a..06ffecc50 100644 --- a/funcs/func_odbc.c +++ b/funcs/func_odbc.c @@ -34,6 +34,7 @@ <use>iodbc</use> ***/ +#define USE_ODBC #include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision$") @@ -46,6 +47,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/res_odbc.h" #include "asterisk/app.h" #include "asterisk/cli.h" +#include "asterisk/strings.h" /*** DOCUMENTATION <function name="ODBC_FETCH" language="en_US"> @@ -281,8 +283,8 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co /* Additionally set the value as a whole (but push an empty string if value is NULL) */ pbx_builtin_pushvar_helper(chan, "VALUE", value ? value : ""); - pbx_substitute_variables_helper(chan, query->sql_write, buf->str, buf->len - 1); - pbx_substitute_variables_helper(chan, query->sql_insert, insertbuf->str, insertbuf->len - 1); + ast_str_substitute_variables(&buf, 0, chan, query->sql_write); + ast_str_substitute_variables(&insertbuf, 0, chan, query->sql_insert); /* Restore prior values */ for (i = 0; i < args.argc; i++) { @@ -300,7 +302,7 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co if (!ast_strlen_zero(query->writehandle[dsn])) { obj = ast_odbc_request_obj(query->writehandle[dsn], 0); if (obj) - stmt = ast_odbc_direct_execute(obj, generic_execute, buf->str); + stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(buf)); } if (stmt) { status = "SUCCESS"; @@ -309,14 +311,14 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co } } - if (stmt && rows == 0 && !ast_strlen_zero(insertbuf->str)) { + if (stmt && rows == 0 && ast_str_strlen(insertbuf) != 0) { SQLCloseCursor(stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt); for (dsn = 0; dsn < 5; dsn++) { if (!ast_strlen_zero(query->writehandle[dsn])) { obj = ast_odbc_request_obj(query->writehandle[dsn], 0); if (obj) { - stmt = ast_odbc_direct_execute(obj, generic_execute, insertbuf->str); + stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(insertbuf)); } } if (stmt) { @@ -409,8 +411,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha pbx_builtin_pushvar_helper(chan, varname, args.field[x]); } - ast_str_make_space(&sql, strlen(query->sql_read) * 2 + 300); - pbx_substitute_variables_helper(chan, query->sql_read, sql->str, sql->len - 1); + ast_str_substitute_variables(&sql, 0, chan, query->sql_read); /* Restore prior values */ for (x = 0; x < args.argc; x++) { @@ -435,7 +436,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha if (!ast_strlen_zero(query->readhandle[dsn])) { obj = ast_odbc_request_obj(query->readhandle[dsn], 0); if (obj) { - stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str); + stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)); } } if (stmt) { @@ -444,7 +445,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha } if (!stmt) { - ast_log(LOG_ERROR, "Unable to execute query [%s]\n", sql->str); + ast_log(LOG_ERROR, "Unable to execute query [%s]\n", ast_str_buffer(sql)); if (obj) { ast_odbc_release_obj(obj); } @@ -460,7 +461,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha res = SQLNumResultCols(stmt, &colcount); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql->str); + ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", ast_str_buffer(sql)); SQLCloseCursor(stmt); SQLFreeHandle (SQL_HANDLE_STMT, stmt); ast_odbc_release_obj(obj); @@ -478,13 +479,13 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { int res1 = -1; if (res == SQL_NO_DATA) { - ast_verb(4, "Found no rows [%s]\n", sql->str); + ast_verb(4, "Found no rows [%s]\n", ast_str_buffer(sql)); res1 = 0; buf[0] = '\0'; ast_copy_string(rowcount, "0", sizeof(rowcount)); status = "NODATA"; } else { - ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, sql->str); + ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, ast_str_buffer(sql)); status = "FETCHERROR"; } SQLCloseCursor(stmt); @@ -505,6 +506,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha for (x = 0; x < colcount; x++) { int i; struct ast_str *coldata = ast_str_thread_get(&coldata_buf, 16); + char *ptrcoldata; if (y == 0) { char colname[256]; @@ -516,30 +518,15 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha snprintf(colname, sizeof(colname), "field%d", x); } - if (coldata->len < maxcol + 1) { - ast_str_make_space(&coldata, maxcol + 1); - } + ast_str_make_space(&coldata, maxcol + 1); - if (colnames->used) { + if (ast_str_strlen(colnames)) { ast_str_append(&colnames, 0, ","); } - ast_str_make_space(&colnames, strlen(colname) * 2 + 1 + colnames->used); - - /* Copy data, encoding '\' and ',' for the argument parser */ - for (i = 0; i < sizeof(colname); i++) { - if (escapecommas && (colname[i] == '\\' || colname[i] == ',')) { - colnames->str[colnames->used++] = '\\'; - } - colnames->str[colnames->used++] = colname[i]; - - if (colname[i] == '\0') { - colnames->used--; - break; - } - } + ast_str_append_escapecommas(&colnames, 0, colname, sizeof(colname)); if (resultset) { - void *tmp = ast_realloc(resultset, sizeof(*resultset) + colnames->used + 1); + void *tmp = ast_realloc(resultset, sizeof(*resultset) + ast_str_strlen(colnames) + 1); if (!tmp) { ast_log(LOG_ERROR, "No space for a new resultset?\n"); ast_free(resultset); @@ -555,12 +542,12 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha return -1; } resultset = tmp; - strcpy((char *)resultset + sizeof(*resultset), colnames->str); + strcpy((char *)resultset + sizeof(*resultset), ast_str_buffer(colnames)); } } buflen = strlen(buf); - res = SQLGetData(stmt, x + 1, SQL_CHAR, coldata->str, coldata->len, &indicator); + res = ast_str_SQLGetData(&coldata, -1, stmt, x + 1, SQL_CHAR, &indicator); if (indicator == SQL_NULL_DATA) { ast_debug(3, "Got NULL data\n"); ast_str_reset(coldata); @@ -568,39 +555,42 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha } if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql->str); + ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", ast_str_buffer(sql)); y = -1; buf[0] = '\0'; goto end_acf_read; } - ast_debug(2, "Got coldata of '%s'\n", coldata->str); - coldata->used = strlen(coldata->str); + ast_debug(2, "Got coldata of '%s'\n", ast_str_buffer(coldata)); + + if (buflen) { + buf[buflen++] = ','; + } /* Copy data, encoding '\' and ',' for the argument parser */ - for (i = 0; i < coldata->used; i++) { - if (escapecommas && (coldata->str[i] == '\\' || coldata->str[i] == ',')) { + ptrcoldata = ast_str_buffer(coldata); + for (i = 0; i < ast_str_strlen(coldata); i++) { + if (escapecommas && (ptrcoldata[i] == '\\' || ptrcoldata[i] == ',')) { buf[buflen++] = '\\'; } - buf[buflen++] = coldata->str[i]; + buf[buflen++] = ptrcoldata[i]; - if (buflen >= len - 2) + if (buflen >= len - 2) { break; + } - if (coldata->str[i] == '\0') + if (ptrcoldata[i] == '\0') { break; + } } - buf[buflen++] = ','; buf[buflen] = '\0'; ast_debug(2, "buf is now set to '%s'\n", buf); } - /* Trim trailing comma */ - buf[buflen - 1] = '\0'; ast_debug(2, "buf is now set to '%s'\n", buf); if (resultset) { - row = ast_calloc(1, sizeof(*row) + buflen); + row = ast_calloc(1, sizeof(*row) + buflen + 1); if (!row) { ast_log(LOG_ERROR, "Unable to allocate space for more rows in this resultset.\n"); status = "MEMERROR"; @@ -612,8 +602,10 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha /* Get next row */ res = SQLFetch(stmt); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - if (res != SQL_NO_DATA) - ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, sql->str); + if (res != SQL_NO_DATA) { + ast_log(LOG_WARNING, "Error %d in FETCH [%s]\n", res, ast_str_buffer(sql)); + } + /* Number of rows in the resultset */ y++; break; } @@ -624,7 +616,7 @@ end_acf_read: snprintf(rowcount, sizeof(rowcount), "%d", y); pbx_builtin_setvar_helper(chan, "ODBCROWS", rowcount); pbx_builtin_setvar_helper(chan, "ODBCSTATUS", status); - pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames->str); + pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(colnames)); if (resultset) { int uid; struct ast_datastore *odbc_store; @@ -1042,8 +1034,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args pbx_builtin_pushvar_helper(chan, varname, args.field[i]); } - /*!\note This does not set sql->used, so don't try to use that value. */ - pbx_substitute_variables_helper(chan, query->sql_read, sql->str, sql->len - 1); + ast_str_substitute_variables(&sql, 0, chan, query->sql_read); ast_channel_free(chan); if (a->argc == 5 && !strcmp(a->argv[4], "exec")) { @@ -1068,7 +1059,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args } ast_debug(1, "Got obj\n"); - if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str))) { + if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)))) { ast_odbc_release_obj(obj); continue; } @@ -1077,7 +1068,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args res = SQLNumResultCols(stmt, &colcount); if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_cli(a->fd, "SQL Column Count error!\n[%s]\n\n", sql->str); + ast_cli(a->fd, "SQL Column Count error!\n[%s]\n\n", ast_str_buffer(sql)); SQLCloseCursor(stmt); SQLFreeHandle (SQL_HANDLE_STMT, stmt); ast_odbc_release_obj(obj); @@ -1091,10 +1082,10 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args SQLFreeHandle(SQL_HANDLE_STMT, stmt); ast_odbc_release_obj(obj); if (res == SQL_NO_DATA) { - ast_cli(a->fd, "Returned %d rows. Query executed on handle %d:%s [%s]\n", rows, dsn, query->readhandle[dsn], sql->str); + ast_cli(a->fd, "Returned %d rows. Query executed on handle %d:%s [%s]\n", rows, dsn, query->readhandle[dsn], ast_str_buffer(sql)); break; } else { - ast_cli(a->fd, "Error %d in FETCH [%s]\n", res, sql->str); + ast_cli(a->fd, "Error %d in FETCH [%s]\n", res, ast_str_buffer(sql)); } AST_RWLIST_UNLOCK(&queries); return CLI_SUCCESS; @@ -1106,18 +1097,14 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args snprintf(colname, sizeof(colname), "field%d", x); } - if (coldata->len < maxcol + 1) { - ast_str_make_space(&coldata, maxcol + 1); - } - - res = SQLGetData(stmt, x + 1, SQL_CHAR, coldata->str, coldata->len, &indicator); + res = ast_str_SQLGetData(&coldata, maxcol, stmt, x + 1, SQL_CHAR, &indicator); if (indicator == SQL_NULL_DATA) { ast_str_set(&coldata, 0, "(nil)"); res = SQL_SUCCESS; } if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) { - ast_cli(a->fd, "SQL Get Data error %d!\n[%s]\n\n", res, sql->str); + ast_cli(a->fd, "SQL Get Data error %d!\n[%s]\n\n", res, ast_str_buffer(sql)); SQLCloseCursor(stmt); SQLFreeHandle(SQL_HANDLE_STMT, stmt); ast_odbc_release_obj(obj); @@ -1125,7 +1112,7 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args return CLI_SUCCESS; } - ast_cli(a->fd, "%-20.20s %s\n", colname, coldata->str); + ast_cli(a->fd, "%-20.20s %s\n", colname, ast_str_buffer(coldata)); } /* Get next row */ res = SQLFetch(stmt); @@ -1144,10 +1131,10 @@ static char *cli_odbc_read(struct ast_cli_entry *e, int cmd, struct ast_cli_args ast_odbc_release_obj(obj); if (!executed) { - ast_cli(a->fd, "Failed to execute query. [%s]\n", sql->str); + ast_cli(a->fd, "Failed to execute query. [%s]\n", ast_str_buffer(sql)); } } else { /* No execution, just print out the resulting SQL */ - ast_cli(a->fd, "%s\n", sql->str); + ast_cli(a->fd, "%s\n", ast_str_buffer(sql)); } AST_RWLIST_UNLOCK(&queries); return CLI_SUCCESS; @@ -1250,8 +1237,8 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg /* Additionally set the value as a whole (but push an empty string if value is NULL) */ pbx_builtin_pushvar_helper(chan, "VALUE", S_OR(a->argv[4], "")); - pbx_substitute_variables_helper(chan, query->sql_write, sql->str, sql->len - 1); - ast_debug(1, "SQL is %s\n", sql->str); + ast_str_substitute_variables(&sql, 0, chan, query->sql_write); + ast_debug(1, "SQL is %s\n", ast_str_buffer(sql)); ast_channel_free(chan); if (a->argc == 6 && !strcmp(a->argv[5], "exec")) { @@ -1268,7 +1255,7 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg if (!(obj = ast_odbc_request_obj(query->writehandle[dsn], 0))) { continue; } - if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, sql->str))) { + if (!(stmt = ast_odbc_direct_execute(obj, generic_execute, ast_str_buffer(sql)))) { ast_odbc_release_obj(obj); continue; } @@ -1286,7 +1273,7 @@ static char *cli_odbc_write(struct ast_cli_entry *e, int cmd, struct ast_cli_arg ast_cli(a->fd, "Failed to execute query.\n"); } } else { /* No execution, just print out the resulting SQL */ - ast_cli(a->fd, "%s\n", sql->str); + ast_cli(a->fd, "%s\n", ast_str_buffer(sql)); } AST_RWLIST_UNLOCK(&queries); return CLI_SUCCESS; diff --git a/funcs/func_realtime.c b/funcs/func_realtime.c index 17e3a2d2b..065864511 100644 --- a/funcs/func_realtime.c +++ b/funcs/func_realtime.c @@ -141,24 +141,6 @@ AST_THREADSTORAGE(buf1); AST_THREADSTORAGE(buf2); AST_THREADSTORAGE(buf3); -static char *hash_escape(struct ast_str **str, const char *value) -{ - int len; - ast_str_reset(*str); - - if ((*str)->len < (len = strlen(value) * 2 + 1)) { - ast_str_make_space(str, len); - } - for (; *value; value++) { - if (*value == ',' || *value == '\\') { - (*str)->str[(*str)->used++] = '\\'; - } - (*str)->str[(*str)->used++] = *value; - } - (*str)->str[(*str)->used] = '\0'; - return (*str)->str; -} - static int function_realtime_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { struct ast_variable *var, *head; @@ -206,7 +188,7 @@ static int function_realtime_read(struct ast_channel *chan, const char *cmd, cha out = ast_str_alloca(resultslen); for (var = head; var; var = var->next) ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1); - ast_copy_string(buf, out->str, len); + ast_copy_string(buf, ast_str_buffer(out), len); if (chan) ast_autoservice_stop(chan); @@ -303,16 +285,16 @@ static int realtimefield_read(struct ast_channel *chan, const char *cmd, char *d } } else if (which == rthash) { ast_debug(1, "Setting hash key %s to value %s\n", var->name, var->value); - ast_str_append(&fields, 0, "%s%s", first ? "" : ",", hash_escape(&escapebuf, var->name)); - ast_str_append(&values, 0, "%s%s", first ? "" : ",", hash_escape(&escapebuf, var->value)); + ast_str_append(&fields, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->name, INT_MAX)); + ast_str_append(&values, 0, "%s%s", first ? "" : ",", ast_str_set_escapecommas(&escapebuf, 0, var->value, INT_MAX)); first = 0; } } ast_variables_destroy(head); if (which == rthash) { - pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", fields->str); - ast_copy_string(buf, values->str, len); + pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields)); + ast_copy_string(buf, ast_str_buffer(values), len); } if (chan) { @@ -418,7 +400,7 @@ static int function_realtime_readdestroy(struct ast_channel *chan, const char *c for (var = head; var; var = var->next) { ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1); } - ast_copy_string(buf, out->str, len); + ast_copy_string(buf, ast_str_buffer(out), len); ast_destroy_realtime(args.family, args.fieldmatch, args.value, SENTINEL); diff --git a/funcs/func_strings.c b/funcs/func_strings.c index da7525170..fa43752a4 100644 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -321,7 +321,7 @@ static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, ch ); const char *orig_list, *ptr; const char *begin, *cur, *next; - int dlen, flen; + int dlen, flen, first = 1; struct ast_str *result = ast_str_thread_get(&result_buf, 16); char *delim; @@ -385,15 +385,12 @@ static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, ch begin += flen + dlen; } else { /* Copy field to output */ - if (result->used) { + if (!first) { ast_str_append(&result, 0, "%s", delim); } - /* Have to do it this way, since we're not null-terminated. */ - strncpy(result->str + result->used, begin, cur - begin); - result->used += cur - begin; - result->str[result->used] = '\0'; - + ast_str_append_substr(&result, 0, begin, cur - begin + 1); + first = 0; begin = cur + dlen; } } while (*cur != '\0'); @@ -401,7 +398,7 @@ static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, ch ast_channel_unlock(chan); } - ast_copy_string(buf, result->str, len); + ast_copy_string(buf, ast_str_buffer(result), len); return 0; } |