[Asterisk-cvs] asterisk/funcs func_strings.c,1.8,1.9

russell russell
Tue Oct 11 21:14:16 CDT 2005


Update of /usr/cvsroot/asterisk/funcs
In directory mongoose.digium.com:/tmp/cvs-serv2413/funcs

Modified Files:
	func_strings.c 
Log Message:
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.


Index: func_strings.c
===================================================================
RCS file: /usr/cvsroot/asterisk/funcs/func_strings.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- func_strings.c	25 Sep 2005 20:47:00 -0000	1.8
+++ func_strings.c	12 Oct 2005 01:09:04 -0000	1.9
@@ -69,39 +69,43 @@
 
 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;
 	}
 
-	return ret;
+	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 buf;
 }
 
 #ifndef BUILTIN_FUNC




More information about the svn-commits mailing list