diff options
author | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-02-17 19:51:53 +0000 |
---|---|---|
committer | jpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-02-17 19:51:53 +0000 |
commit | b47f51986102eea9795a0c3914c2705556635e09 (patch) | |
tree | 850473272a4f4cf99ce0a3c90eecca8facc60bcc /main | |
parent | b003798c0ad0b5654e018363f38f3885ac1a004e (diff) |
Add support for GROUP_MATCH_COUNT regex matching on category
Current support for regex matching was previously only available on the group.
Also, error reporting for regex failures has been added. In addition to this
feature enhancement a unit test has been written to check the regular expression
logic to ensure the count operation is working as expected.
(closes issue #16642)
Reported by: kobaz
Patches:
groupmatch2.patch uploaded by kobaz (license 834)
Review: https://reviewboard.asterisk.org/r/503/
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@247295 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r-- | main/app.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/main/app.c b/main/app.c index 24676713f..7cb7e30b0 100644 --- a/main/app.c +++ b/main/app.c @@ -1091,27 +1091,34 @@ int ast_app_group_get_count(const char *group, const char *category) int ast_app_group_match_get_count(const char *groupmatch, const char *category) { struct ast_group_info *gi = NULL; - regex_t regexbuf; + regex_t regexbuf_group; + regex_t regexbuf_category; int count = 0; - if (ast_strlen_zero(groupmatch)) { + if (ast_strlen_zero(groupmatch)) return 0; - } /* if regex compilation fails, return zero matches */ - if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) { + if (regcomp(®exbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) { + ast_log(LOG_ERROR, "Regex compile failed on: %s\n", groupmatch); + return 0; + } + + if (regcomp(®exbuf_category, category, REG_EXTENDED | REG_NOSUB)) { + ast_log(LOG_ERROR, "Regex compile failed on: %s\n", category); return 0; } AST_RWLIST_RDLOCK(&groups); AST_RWLIST_TRAVERSE(&groups, gi, group_list) { - if (!regexec(®exbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { + if (!regexec(®exbuf_group, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !regexec(®exbuf_category, gi->category, 0, NULL, 0)))) { count++; } } AST_RWLIST_UNLOCK(&groups); - regfree(®exbuf); + regfree(®exbuf_group); + regfree(®exbuf_category); return count; } |