Skip to content
Snippets Groups Projects
Commit 33377538 authored by Russell Bryant's avatar Russell Bryant
Browse files

provide the correct string to evaluate with the given regex, instead of the

entire string provided as input to the REGEX function..  Also, use the
provided buffer to store the result.


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6744 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent c5a8178b
No related branches found
No related tags found
No related merge requests found
...@@ -69,39 +69,43 @@ struct ast_custom_function fieldqty_function = { ...@@ -69,39 +69,43 @@ struct ast_custom_function fieldqty_function = {
static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
{ {
char *ret_true = "1", *ret_false = "0", *ret;
char *arg, *earg, *tmp, errstr[256] = ""; char *arg, *earg, *tmp, errstr[256] = "";
int errcode; int errcode;
regex_t regexbuf; regex_t regexbuf;
ret = ret_false; /* convince me otherwise */ ast_copy_string(buf, "0", len);
tmp = ast_strdupa(data); tmp = ast_strdupa(data);
if (tmp) { if (!tmp) {
/* Regex in quotes */ ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
arg = strchr(tmp, '"'); return buf;
if (arg) { }
arg++;
earg = strrchr(arg, '"');
if (earg) {
*earg = '\0';
}
} else {
arg = tmp;
}
if ((errcode = regcomp(&regexbuf, arg, REG_EXTENDED | REG_NOSUB))) { /* Regex in quotes */
regerror(errcode, &regexbuf, errstr, sizeof(errstr)); arg = strchr(tmp, '"');
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr); if (arg) {
ret = NULL; arg++;
} else { earg = strrchr(arg, '"');
ret = regexec(&regexbuf, data, 0, NULL, 0) ? ret_false : ret_true; if (earg) {
*earg++ = '\0';
/* Skip over any spaces before the data we are checking */
while (*earg == ' ')
earg++;
} }
regfree(&regexbuf);
} else { } else {
ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data); arg = tmp;
}
if ((errcode = regcomp(&regexbuf, arg, REG_EXTENDED | REG_NOSUB))) {
regerror(errcode, &regexbuf, errstr, sizeof(errstr));
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr);
} else {
if (!regexec(&regexbuf, earg ? earg : "", 0, NULL, 0))
ast_copy_string(buf, "1", len);
} }
regfree(&regexbuf);
return ret; return buf;
} }
#ifndef BUILTIN_FUNC #ifndef BUILTIN_FUNC
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment