aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_strings.c
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-12 01:09:04 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2005-10-12 01:09:04 +0000
commit498f9c4b948beaeb547c5795ce970db0b05bf07e (patch)
tree25920fbc6ef125eb85018e6cb00161044c59b05d /funcs/func_strings.c
parent585bed62995f7fd660f3299104f0359a9636005f (diff)
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: http://svn.digium.com/svn/asterisk/trunk@6744 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_strings.c')
-rwxr-xr-xfuncs/func_strings.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c
index 303ca77d7..dced1e1a6 100755
--- a/funcs/func_strings.c
+++ b/funcs/func_strings.c
@@ -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)
{
- 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) {
- /* Regex in quotes */
- arg = strchr(tmp, '"');
- if (arg) {
- arg++;
- earg = strrchr(arg, '"');
- if (earg) {
- *earg = '\0';
- }
- } else {
- arg = tmp;
- }
+ if (!tmp) {
+ ast_log(LOG_ERROR, "Out of memory in %s(%s)\n", cmd, data);
+ return buf;
+ }
- 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);
- ret = NULL;
- } else {
- ret = regexec(&regexbuf, data, 0, NULL, 0) ? ret_false : ret_true;
+ /* Regex in quotes */
+ arg = strchr(tmp, '"');
+ if (arg) {
+ arg++;
+ earg = strrchr(arg, '"');
+ if (earg) {
+ *earg++ = '\0';
+ /* Skip over any spaces before the data we are checking */
+ while (*earg == ' ')
+ earg++;
}
- regfree(&regexbuf);
} 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