summaryrefslogtreecommitdiff
path: root/main/app.c
diff options
context:
space:
mode:
authorJeff Peeler <jpeeler@digium.com>2010-02-17 19:51:53 +0000
committerJeff Peeler <jpeeler@digium.com>2010-02-17 19:51:53 +0000
commit27a4cda821b3093bb41c29e23d1fb9d62890597a (patch)
tree850473272a4f4cf99ce0a3c90eecca8facc60bcc /main/app.c
parente8d201e870bbadea78d448e21cc2c19c3da8c13d (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: https://origsvn.digium.com/svn/asterisk/trunk@247295 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/app.c')
-rw-r--r--main/app.c19
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(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) {
+ if (regcomp(&regexbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) {
+ ast_log(LOG_ERROR, "Regex compile failed on: %s\n", groupmatch);
+ return 0;
+ }
+
+ if (regcomp(&regexbuf_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(&regexbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
+ if (!regexec(&regexbuf_group, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !regexec(&regexbuf_category, gi->category, 0, NULL, 0)))) {
count++;
}
}
AST_RWLIST_UNLOCK(&groups);
- regfree(&regexbuf);
+ regfree(&regexbuf_group);
+ regfree(&regexbuf_category);
return count;
}