aboutsummaryrefslogtreecommitdiffstats
path: root/main/app.c
diff options
context:
space:
mode:
authorjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-17 19:51:53 +0000
committerjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2010-02-17 19:51:53 +0000
commitb47f51986102eea9795a0c3914c2705556635e09 (patch)
tree850473272a4f4cf99ce0a3c90eecca8facc60bcc /main/app.c
parentb003798c0ad0b5654e018363f38f3885ac1a004e (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/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;
}