[asterisk-commits] tilghman: branch tilghman/str_substitution r182112 - in /team/tilghman/str_su...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 13 14:13:18 CDT 2009


Author: tilghman
Date: Fri Mar 13 14:13:15 2009
New Revision: 182112

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=182112
Log:
More testing reveals more bugs

Modified:
    team/tilghman/str_substitution/funcs/func_aes.c
    team/tilghman/str_substitution/main/pbx.c
    team/tilghman/str_substitution/main/strings.c
    team/tilghman/str_substitution/tests/test_substitution.c

Modified: team/tilghman/str_substitution/funcs/func_aes.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_aes.c?view=diff&rev=182112&r1=182111&r2=182112
==============================================================================
--- team/tilghman/str_substitution/funcs/func_aes.c (original)
+++ team/tilghman/str_substitution/funcs/func_aes.c Fri Mar 13 14:13:15 2009
@@ -111,9 +111,9 @@
 	if (buf) {
 		len = maxlen;
 	} else if (maxlen == -1) {
-		len = ast_str_size(*str) - ast_str_strlen(*str);
+		len = ast_str_size(*str);
 	} else if (maxlen > 0) {
-		len = maxlen - ast_str_strlen(*str);
+		len = maxlen;
 	} else {
 		len = INT_MAX;
 	}
@@ -146,7 +146,7 @@
 		 * the data is encrypted or decrypted and put back into the original
 		 * buffer. */
 		memset(curblock, 0, AES_BLOCK_SIZE);
-		memcpy(curblock, tmpP, (data_len < AES_BLOCK_SIZE) ? data_len : AES_BLOCK_SIZE);
+		memcpy(curblock, tmpP, AES_BLOCK_SIZE);
 		if (encrypt) {
 			ast_aes_encrypt(curblock, (unsigned char *) tmpP, &ecx);
 		} else {
@@ -162,16 +162,16 @@
 			ast_base64encode(buf, (unsigned char *) tmp, elen, len);
 		} else {
 			if (maxlen >= 0) {
-				ast_str_make_space(str, maxlen ? maxlen : ast_str_strlen(*str) + elen * 4 / 3 + 2);
+				ast_str_make_space(str, maxlen ? maxlen : elen * 4 / 3 + 2);
 			}
-			ast_base64encode(ast_str_buffer(*str) + ast_str_strlen(*str), (unsigned char *) tmp, elen, ast_str_size(*str) - ast_str_strlen(*str));
+			ast_base64encode(ast_str_buffer(*str), (unsigned char *) tmp, elen, ast_str_size(*str));
 			ast_str_update(*str);
 		}
 	} else {
 		if (buf) {
 			memcpy(buf, tmp, len);
 		} else {
-			ast_str_append(str, maxlen, "%s", tmp);
+			ast_str_set(str, maxlen, "%s", tmp);
 		}
 	}
 	ast_free(tmp);

Modified: team/tilghman/str_substitution/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/main/pbx.c?view=diff&rev=182112&r1=182111&r2=182112
==============================================================================
--- team/tilghman/str_substitution/main/pbx.c (original)
+++ team/tilghman/str_substitution/main/pbx.c Fri Mar 13 14:13:15 2009
@@ -2860,7 +2860,7 @@
 
 	if (offset > 0) {
 		/* Go ahead and chop off the beginning */
-		memcpy(ast_str_buffer(value), ast_str_buffer(value) + offset, ast_str_strlen(value) - offset);
+		memcpy(ast_str_buffer(value), ast_str_buffer(value) + offset, ast_str_strlen(value) - offset + 1);
 		lr -= offset;
 	}
 

Modified: team/tilghman/str_substitution/main/strings.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/main/strings.c?view=diff&rev=182112&r1=182111&r2=182112
==============================================================================
--- team/tilghman/str_substitution/main/strings.c (original)
+++ team/tilghman/str_substitution/main/strings.c Fri Mar 13 14:13:15 2009
@@ -149,7 +149,6 @@
 		ptr--;
 	}
 	*ptr = '\0';
-	(*buf)->__AST_STR_USED--;
 	return (*buf)->__AST_STR_STR;
 }
 

Modified: team/tilghman/str_substitution/tests/test_substitution.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/tests/test_substitution.c?view=diff&rev=182112&r1=182111&r2=182112
==============================================================================
--- team/tilghman/str_substitution/tests/test_substitution.c (original)
+++ team/tilghman/str_substitution/tests/test_substitution.c Fri Mar 13 14:13:15 2009
@@ -132,6 +132,16 @@
 	ast_str_set(&expression, 0, "%s%s%s", decode1, ast_str_buffer(str), decode2);
 	ast_str_substitute_variables(&str, 0, c, ast_str_buffer(expression));
 	ast_cli(fd, "Testing '%s%s' and '%s%s' . . . . . %s\n", encode1, encode2, decode1, decode2, !strcmp(ast_str_buffer(str), "foobarbaz") ? "passed" : "FAILED");
+	if (strcmp(ast_str_buffer(str), "foobarbaz")) {
+		ast_cli(fd, "  '%s' != 'foobarbaz'\n", ast_str_buffer(str));
+	}
+}
+
+static void test_expected_result(int fd, struct ast_channel *c, const char *expression, const char *result)
+{
+	struct ast_str *str = ast_str_thread_get(&buf_buf, 16);
+	ast_str_substitute_variables(&str, 0, c, expression);
+	ast_cli(fd, "Testing '%s' ('%s') == '%s' . . . . . %s\n", ast_str_buffer(str), expression, result, !strcmp(ast_str_buffer(str), result) ? "passed" : "FAILED");
 }
 
 static char *handle_cli_test_substitution(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -176,6 +186,19 @@
 	test_chan_variable(a->fd, c, "GROUP()");
 	test_2way_function(a->fd, c, "${AES_ENCRYPT(abcdefghijklmnop,", ")}", "${AES_DECRYPT(abcdefghijklmnop,", ")}");
 	test_2way_function(a->fd, c, "${BASE64_ENCODE(", ")}", "${BASE64_DECODE(", ")}");
+	pbx_builtin_setvar_helper(c, "foo", "123");
+	pbx_builtin_setvar_helper(c, "bar", "foo");
+	pbx_builtin_setvar_helper(c, "baz", "fo");
+	test_expected_result(a->fd, c, "${foo}${foo}", "123123");
+	test_expected_result(a->fd, c, "A${foo}A${foo}A", "A123A123A");
+	test_expected_result(a->fd, c, "A${${bar}}A", "A123A");
+	test_expected_result(a->fd, c, "A${${baz}o}A", "A123A");
+	test_expected_result(a->fd, c, "A${${baz}o:1}A", "A23A");
+	test_expected_result(a->fd, c, "A${${baz}o:1:1}A", "A2A");
+	test_expected_result(a->fd, c, "A${${baz}o:1:-1}A", "A2A");
+	test_expected_result(a->fd, c, "A${${baz}o:-1:1}A", "A3A");
+	test_expected_result(a->fd, c, "A${${baz}o:-2:1}A", "A2A");
+	test_expected_result(a->fd, c, "A${${baz}o:-2:-1}A", "A2A");
 
 	/* For testing dialplan functions */
 	for (i = 0; ; i++) {




More information about the asterisk-commits mailing list