From 1440ad06cd7fdbbb9509a81f603f48490e4a87a9 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Fri, 30 Aug 2013 01:00:00 +0000 Subject: [PATCH] pbx.c: Make ast_str_substitute_variables_full() not mask variables. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@397975 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- funcs/func_cdr.c | 6 ++++-- main/pbx.c | 18 +++++++++------- tests/test_substitution.c | 44 ++++++++++++++++++++------------------- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/funcs/func_cdr.c b/funcs/func_cdr.c index 6d9fb19a14..4739edf48b 100644 --- a/funcs/func_cdr.c +++ b/funcs/func_cdr.c @@ -269,8 +269,10 @@ static int cdr_read(struct ast_channel *chan, const char *cmd, char *parse, return 0; } fmt_time.tv_usec = tv_usec; - ast_localtime(&fmt_time, &tm, NULL); - ast_strftime(tempbuf, sizeof(*tempbuf), "%Y-%m-%d %T", &tm); + if (fmt_time.tv_sec || fmt_time.tv_usec) { + ast_localtime(&fmt_time, &tm, NULL); + ast_strftime(tempbuf, sizeof(*tempbuf), "%Y-%m-%d %T", &tm); + } } else if (!strcasecmp("disposition", args.variable)) { int disposition; diff --git a/main/pbx.c b/main/pbx.c index fa2f645947..09f3d95ec7 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -4479,11 +4479,12 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead /* Substitute if necessary */ if (needsub) { - size_t used; - if (!ltmp) - ltmp = ast_alloca(VAR_BUF_SIZE); + size_t my_used; - pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used); + if (!ltmp) { + ltmp = ast_alloca(VAR_BUF_SIZE); + } + pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &my_used); vars = ltmp; } else { vars = var; @@ -4568,11 +4569,12 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead /* Substitute if necessary */ if (needsub) { - size_t used; - if (!ltmp) - ltmp = ast_alloca(VAR_BUF_SIZE); + size_t my_used; - pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used); + if (!ltmp) { + ltmp = ast_alloca(VAR_BUF_SIZE); + } + pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &my_used); vars = ltmp; } else { vars = var; diff --git a/tests/test_substitution.c b/tests/test_substitution.c index 02796b619c..04b9837bc7 100644 --- a/tests/test_substitution.c +++ b/tests/test_substitution.c @@ -53,16 +53,17 @@ static enum ast_test_result_state test_chan_integer(struct ast_test *test, char workspace[4096]; struct ast_str *str = ast_str_create(16); - ast_test_status_update(test, "Testing '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED"); for (i = 0; i < 256; i++) { *ifield = i; ast_str_substitute_variables(&str, 0, c, expression); pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace)); + if (sscanf(workspace, "%d", &value1) != 1 || value1 != i || sscanf(ast_str_buffer(str), "%d", &value2) != 1 || value2 != i) { ast_test_status_update(test, "%s != %s and/or %d != %d != %d\n", ast_str_buffer(str), workspace, value1, value2, i); okay = 0; } } + ast_test_status_update(test, "Tested '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED"); ast_free(str); @@ -76,16 +77,17 @@ static enum ast_test_result_state test_chan_integer_accessor(struct ast_test *te char workspace[4096]; struct ast_str *str = ast_str_create(16); - ast_test_status_update(test, "Testing '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED"); for (i = 0; i < 256; i++) { setter(c, i); ast_str_substitute_variables(&str, 0, c, expression); pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace)); + if (sscanf(workspace, "%d", &value1) != 1 || value1 != i || sscanf(ast_str_buffer(str), "%d", &value2) != 1 || value2 != i) { ast_test_status_update(test, "%s != %s and/or %d != %d != %d\n", ast_str_buffer(str), workspace, value1, value2, i); okay = 0; } } + ast_test_status_update(test, "Tested '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED"); ast_free(str); @@ -105,13 +107,14 @@ static enum ast_test_result_state test_chan_string(struct ast_test *test, setter(c, values[i]); ast_str_substitute_variables(&str, 0, c, expression); pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace)); - ast_test_status_update(test, "Testing '%s' . . . . . %s\n", - expression, okay ? "passed" : "FAILED"); + if (strcmp(getter(c), ast_str_buffer(str)) != 0 || strcmp(getter(c), workspace) != 0) { ast_test_status_update(test, "%s != %s != %s\n", getter(c), ast_str_buffer(str), workspace); okay = 0; } } + ast_test_status_update(test, "Tested '%s' . . . . . %s\n", + expression, okay ? "passed" : "FAILED"); ast_free(str); @@ -132,14 +135,15 @@ static enum ast_test_result_state test_chan_variable(struct ast_test *test, pbx_builtin_setvar_helper(c, varname, values[i]); ast_str_substitute_variables(&str, 0, c, ast_str_buffer(var)); pbx_substitute_variables_helper(c, ast_str_buffer(var), workspace, sizeof(workspace)); - ast_test_status_update(test, "Testing '%s' . . . . . %s\n", - ast_str_buffer(var), okay ? "passed" : "FAILED"); + if (strcmp(values[i], ast_str_buffer(str)) != 0 || strcmp(values[i], workspace) != 0) { ast_test_status_update(test, "%s != %s != %s\n", values[i], ast_str_buffer(str), workspace); okay = 0; } } + ast_test_status_update(test, "Tested '%s' . . . . . %s\n", + ast_str_buffer(var), okay ? "passed" : "FAILED"); ast_free(str); ast_free(var); @@ -156,13 +160,14 @@ static enum ast_test_result_state test_chan_function(struct ast_test *test, ast_str_substitute_variables(&str, 0, c, expression); pbx_substitute_variables_helper(c, expression, workspace, sizeof(workspace)); - ast_test_status_update(test, "Testing '%s' . . . . . %s\n", - expression, okay ? "passed" : "FAILED"); + if (strcmp(workspace, ast_str_buffer(str)) != 0) { - ast_test_status_update(test, "test_chan_function, expr: '%s' ... %s != %s\n", + ast_test_status_update(test, "expr: '%s' ... %s != %s\n", expression, ast_str_buffer(str), workspace); okay = 0; } + ast_test_status_update(test, "Tested '%s' . . . . . %s\n", + expression, okay ? "passed" : "FAILED"); ast_free(str); @@ -182,15 +187,13 @@ static enum ast_test_result_state test_2way_function(struct ast_test *test, ast_str_substitute_variables(&str, 0, c, ast_str_buffer(expression)); okay = !strcmp(ast_str_buffer(str), "foobarbaz"); - - ast_test_status_update(test, "Testing '%s%s' and '%s%s' . . . . . %s\n", - encode1, encode2, decode1, decode2, - okay ? "passed" : "FAILED"); - if (!okay) { - ast_test_status_update(test, " '%s' != 'foobarbaz'\n", + ast_test_status_update(test, "'%s' != 'foobarbaz'\n", ast_str_buffer(str)); } + ast_test_status_update(test, "Tested '%s%s' and '%s%s' . . . . . %s\n", + encode1, encode2, decode1, decode2, + okay ? "passed" : "FAILED"); ast_free(str); @@ -204,16 +207,15 @@ static enum ast_test_result_state test_expected_result(struct ast_test *test, int okay; ast_str_substitute_variables(&str, 0, c, expression); - okay = !strcmp(ast_str_buffer(str), result); - - ast_test_status_update(test, "Testing '%s' ('%s') == '%s' . . . . . %s\n", - ast_str_buffer(str), expression, result, - okay ? "passed" : "FAILED"); + okay = !strcmp(ast_str_buffer(str), result); if (!okay) { - ast_test_status_update(test, "test_expected_result: '%s' != '%s'\n", + ast_test_status_update(test, "'%s' != '%s'\n", ast_str_buffer(str), result); } + ast_test_status_update(test, "Tested '%s' ('%s') == '%s' . . . . . %s\n", + ast_str_buffer(str), expression, result, + okay ? "passed" : "FAILED"); ast_free(str);