From 486b6042f39664bd8f325e8a0b035f80b2a9765d Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Tue, 20 Sep 2011 21:05:42 +0000 Subject: [PATCH] Merged revisions 337062 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/10 ................ r337062 | kmoore | 2011-09-20 16:05:01 -0500 (Tue, 20 Sep 2011) | 18 lines Merged revisions 337061 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r337061 | kmoore | 2011-09-20 16:04:11 -0500 (Tue, 20 Sep 2011) | 11 lines Make CANMATCH with the new pattern match engine behave more like the old one When checking an extension for E_CANMATCH using the new extension matching algorithm, an exact match was not returned as a possible match resulting in the queue failing to allow a caller to exit on DTMF. This removes the requirement that an extension be longer than acquired digits for an E_CANMATCH operation to succeed. (closes issue ASTERISK-18044) Review: https://reviewboard.asterisk.org/r/1367/ ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@337063 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/pbx.c | 2 +- tests/test_pbx.c | 39 ++++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/main/pbx.c b/main/pbx.c index e67458b65e..d790f0656c 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -1873,7 +1873,7 @@ static void new_find_extension(const char *str, struct scoreboard *score, struct return; /* the first match is all we need */ \ } \ } \ - } else if (p->next_char && !*(str + 1)) { \ + } else if ((p->next_char || action == E_CANMATCH) && !*(str + 1)) { \ score->canmatch = 1; \ score->canmatch_exten = get_canmatch_exten(p); \ if (action == E_CANMATCH || action == E_MATCHMORE) { \ diff --git a/tests/test_pbx.c b/tests/test_pbx.c index 1bcce17701..5e2e232edf 100644 --- a/tests/test_pbx.c +++ b/tests/test_pbx.c @@ -153,29 +153,35 @@ struct pbx_test_pattern { const struct exten_info *exten; }; -static int test_exten(const struct pbx_test_pattern *test_pattern, struct ast_test *test) +static int test_exten(const struct pbx_test_pattern *test_pattern, struct ast_test *test, int new_engine) { struct pbx_find_info pfi = { { 0 }, }; struct ast_exten *exten; if (!(exten = pbx_find_extension(NULL, NULL, &pfi, test_pattern->context, test_pattern->test_exten, test_pattern->priority, NULL, test_pattern->test_cid, E_MATCH))) { - ast_test_status_update(test, "Cannot find extension %s in context %s." - "Test failed.\n", test_pattern->test_exten, test_pattern->context); + ast_test_status_update(test, "Cannot find extension %s in context %s with the %s pattern match engine. " + "Test failed.\n", test_pattern->test_exten, test_pattern->context, (new_engine ? "new" : "old")); return -1; } if (strcmp(ast_get_extension_name(exten), test_pattern->exten->exten)) { - ast_test_status_update(test, "Expected extension %s but got extension %s instead." - "Test failed.\n", test_pattern->exten->exten, ast_get_extension_name(exten)); + ast_test_status_update(test, "Expected extension %s but got extension %s instead with the %s pattern match engine. " + "Test failed.\n", test_pattern->exten->exten, ast_get_extension_name(exten), (new_engine ? "new" : "old")); return -1; } if (test_pattern->test_cid && strcmp(ast_get_extension_cidmatch(exten), test_pattern->test_cid)) { - ast_test_status_update(test, "Expected CID match %s but got CID match %s instead." - "Test failed.\n", test_pattern->exten->cid, ast_get_extension_cidmatch(exten)); + ast_test_status_update(test, "Expected CID match %s but got CID match %s instead with the %s pattern match engine. " + "Test failed.\n", test_pattern->exten->cid, ast_get_extension_cidmatch(exten), (new_engine ? "new" : "old")); return -1; } - ast_test_status_update(test, "Successfully matched %s to exten %s in context %s\n", - test_pattern->test_exten, test_pattern->exten->exten, test_pattern->context); + if (!ast_canmatch_extension(NULL, test_pattern->context, test_pattern->test_exten, + test_pattern->priority, test_pattern->test_cid)) { + ast_test_status_update(test, "Partial match failed for extension %s in context %s with the %s pattern match engine. " + "Test failed.\n", test_pattern->test_exten, test_pattern->context, (new_engine ? "new" : "old")); + return -1; + } + ast_test_status_update(test, "Successfully matched %s to exten %s in context %s with the %s pattern match engine\n", + test_pattern->test_exten, test_pattern->exten->exten, test_pattern->context, (new_engine ? "new" : "old")); return 0; } @@ -185,7 +191,7 @@ AST_TEST_DEFINE(pattern_match_test) enum ast_test_result_state res = AST_TEST_PASS; static const char TEST_PATTERN[] = "test_pattern"; static const char TEST_PATTERN_INCLUDE[] = "test_pattern_include"; - int i; + int i, j; /* The array of contexts to register for our test. * To add more contexts, just add more rows to this array. @@ -300,12 +306,15 @@ AST_TEST_DEFINE(pattern_match_test) /* At this stage, the dialplan is built. Now we iterate over * the tests array to attempt to find each of the specified - * extensions. + * extensions with the old and new pattern matching engines. */ - for (i = 0; i < ARRAY_LEN(tests); ++i) { - if (test_exten(&tests[i], test)) { - res = AST_TEST_FAIL; - break; + for (j = 0; j < 2; j++) { + pbx_set_extenpatternmatchnew(j); + for (i = 0; i < ARRAY_LEN(tests); ++i) { + if (test_exten(&tests[i], test, j)) { + res = AST_TEST_FAIL; + break; + } } }