mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 04:30:28 +00:00
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
This commit is contained in:
@@ -69,21 +69,28 @@ struct ast_custom_function fieldqty_function = {
|
||||
|
||||
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] = "";
|
||||
int errcode;
|
||||
regex_t regexbuf;
|
||||
|
||||
ret = ret_false; /* convince me otherwise */
|
||||
ast_copy_string(buf, "0", len);
|
||||
|
||||
tmp = ast_strdupa(data);
|
||||
if (tmp) {
|
||||
if (!tmp) {
|
||||
ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Regex in quotes */
|
||||
arg = strchr(tmp, '"');
|
||||
if (arg) {
|
||||
arg++;
|
||||
earg = strrchr(arg, '"');
|
||||
if (earg) {
|
||||
*earg = '\0';
|
||||
*earg++ = '\0';
|
||||
/* Skip over any spaces before the data we are checking */
|
||||
while (*earg == ' ')
|
||||
earg++;
|
||||
}
|
||||
} else {
|
||||
arg = tmp;
|
||||
@@ -92,16 +99,13 @@ static char *builtin_function_regex(struct ast_channel *chan, char *cmd, char *d
|
||||
if ((errcode = regcomp(®exbuf, arg, REG_EXTENDED | REG_NOSUB))) {
|
||||
regerror(errcode, ®exbuf, errstr, sizeof(errstr));
|
||||
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, data, errstr);
|
||||
ret = NULL;
|
||||
} else {
|
||||
ret = regexec(®exbuf, data, 0, NULL, 0) ? ret_false : ret_true;
|
||||
if (!regexec(®exbuf, earg ? earg : "", 0, NULL, 0))
|
||||
ast_copy_string(buf, "1", len);
|
||||
}
|
||||
regfree(®exbuf);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifndef BUILTIN_FUNC
|
||||
|
Reference in New Issue
Block a user