From a7c92fad28bb88bec2bf5b9f093971ca3b574545 Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Sat, 17 Jul 2010 17:39:28 +0000 Subject: Merged revisions 277568 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r277568 | tilghman | 2010-07-16 16:54:29 -0500 (Fri, 16 Jul 2010) | 8 lines Since we split values at the semicolon, we should store values with a semicolon as an encoded value. (closes issue #17369) Reported by: gkservice Patches: 20100625__issue17369.diff.txt uploaded by tilghman (license 14) Tested by: tilghman ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@277773 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_config_pgsql.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'res/res_config_pgsql.c') diff --git a/res/res_config_pgsql.c b/res/res_config_pgsql.c index b4ff74d54..3bed287e6 100644 --- a/res/res_config_pgsql.c +++ b/res/res_config_pgsql.c @@ -1,8 +1,8 @@ /* * Asterisk -- A telephony toolkit for Linux. * - * Copyright (C) 1999-2005, Digium, Inc. - * + * Copyright (C) 1999-2010, Digium, Inc. + * * Manuel Guesdon - PostgreSQL RealTime Driver Author/Adaptor * Mark Spencer - Asterisk Author * Matthew Boehm - MySQL RealTime Driver Author @@ -46,6 +46,7 @@ AST_THREADSTORAGE(sql_buf); AST_THREADSTORAGE(findtable_buf); AST_THREADSTORAGE(where_buf); AST_THREADSTORAGE(escapebuf_buf); +AST_THREADSTORAGE(semibuf_buf); #define RES_CONFIG_PGSQL_CONF "res_pgsql.conf" @@ -95,11 +96,21 @@ static struct ast_cli_entry cli_realtime[] = { #define ESCAPE_STRING(buffer, stringname) \ do { \ - int len; \ - if ((len = strlen(stringname)) > (ast_str_size(buffer) - 1) / 2) { \ - ast_str_make_space(&buffer, len * 2 + 1); \ + int len = strlen(stringname); \ + struct ast_str *semi = ast_str_thread_get(&semibuf_buf, len * 3 + 1); \ + const char *chunk = stringname; \ + ast_str_reset(semi); \ + for (; *chunk; chunk++) { \ + if (strchr(";^", *chunk)) { \ + ast_str_append(&semi, 0, "^%02hhX", *chunk); \ + } else { \ + ast_str_append(&semi, 0, "%c", *chunk); \ + } \ + } \ + if (ast_str_strlen(semi) > (ast_str_size(buffer) - 1) / 2) { \ + ast_str_make_space(&buffer, ast_str_strlen(semi) * 2 + 1); \ } \ - PQescapeStringConn(pgsqlConn, ast_str_buffer(buffer), stringname, len, &pgresult); \ + PQescapeStringConn(pgsqlConn, ast_str_buffer(buffer), ast_str_buffer(semi), ast_str_size(buffer), &pgresult); \ } while (0) static void destroy_table(struct tables *table) @@ -391,7 +402,7 @@ static struct ast_variable *realtime_pgsql(const char *database, const char *tab stringp = PQgetvalue(result, rowIndex, i); while (stringp) { chunk = strsep(&stringp, ";"); - if (!ast_strlen_zero(ast_strip(chunk))) { + if (chunk && !ast_strlen_zero(ast_realtime_decode_chunk(ast_strip(chunk)))) { if (prev) { prev->next = ast_variable_new(fieldnames[i], chunk, ""); if (prev->next) { @@ -550,7 +561,7 @@ static struct ast_config *realtime_multi_pgsql(const char *database, const char stringp = PQgetvalue(result, rowIndex, i); while (stringp) { chunk = strsep(&stringp, ";"); - if (!ast_strlen_zero(ast_strip(chunk))) { + if (chunk && !ast_strlen_zero(ast_realtime_decode_chunk(ast_strip(chunk)))) { if (initfield && !strcmp(initfield, fieldnames[i])) { ast_category_rename(cat, chunk); } @@ -744,7 +755,7 @@ static int update2_pgsql(const char *database, const char *tablename, va_list ap release_table(table); return -1; } - + newval = va_arg(ap, const char *); ESCAPE_STRING(escapebuf, newval); if (pgresult) { -- cgit v1.2.3