aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-20 16:30:13 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-20 16:30:13 +0000
commitcfd99de79e83b24f1f9aa407e194affbb1573dfc (patch)
tree64dd4eded77bcd188fbbfead9571d7128314ec5e
parentc862bed097b69d753183d2948212755dda02c98f (diff)
make IF dialplan function handle quoted strings properly (bug #4322, with API mods)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5750 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xfuncs/func_logic.c6
-rwxr-xr-xinclude/asterisk/utils.h38
-rwxr-xr-xutils.c36
3 files changed, 69 insertions, 11 deletions
diff --git a/funcs/func_logic.c b/funcs/func_logic.c
index 41a50e359..d4e6cdfb7 100755
--- a/funcs/func_logic.c
+++ b/funcs/func_logic.c
@@ -55,6 +55,12 @@ static char *builtin_function_if(struct ast_channel *chan, char *cmd, char *data
}
if (expr && iftrue) {
+ expr = ast_strip_quoted(expr, "\"", "\"");
+ iftrue = ast_strip_quoted(iftrue, "\"", "\"");
+
+ if (iffalse) {
+ iffalse = ast_strip_quoted(iffalse, "\"", "\"");
+ }
ret = ast_true(expr) ? iftrue : iffalse;
if (ret) {
ast_copy_string(buf, ret, len);
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h
index 5a772b12f..443908578 100755
--- a/include/asterisk/utils.h
+++ b/include/asterisk/utils.h
@@ -130,7 +130,43 @@ struct ast_hostent {
char buf[1024];
};
-extern char *ast_strip(char *buf);
+/*!
+ \brief Strip leading/trailing whitespace from a string.
+ \param s The string to be stripped (will be modified).
+ \return The stripped string.
+
+ This functions strips all leading and trailing whitespace
+ characters from the input string, and returns a pointer to
+ the resulting string. The string is modified in place.
+*/
+char *ast_strip(char *s);
+
+/*!
+ \brief Strip leading/trailing whitespace and quotes from a string.
+ \param s The string to be stripped (will be modified).
+ \param beg_quotes The list of possible beginning quote characters.
+ \param end_quotes The list of matching ending quote characters.
+ \return The stripped string.
+
+ This functions strips all leading and trailing whitespace
+ characters from the input string, and returns a pointer to
+ the resulting string. The string is modified in place.
+
+ It can also remove beginning and ending quote (or quote-like)
+ characters, in matching pairs. If the first character of the
+ string matches any character in beg_quotes, and the last
+ character of the string is the matching character in
+ end_quotes, then they are removed from the string.
+
+ Examples:
+ \code
+ ast_strip_quoted(buf, "\"", "\"");
+ ast_strip_quoted(buf, "'", "'");
+ ast_strip_quoted(buf, "[{(", "]})");
+ \endcode
+ */
+char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes);
+
extern struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp);
/* ast_md5_hash: Produces MD5 hash based on input string */
extern void ast_md5_hash(char *output, char *input);
diff --git a/utils.c b/utils.c
index 594ef6e7b..ee6074348 100755
--- a/utils.c
+++ b/utils.c
@@ -33,17 +33,33 @@
static char base64[64];
static char b2a[256];
-char *ast_strip(char *buf)
+char *ast_strip(char *s)
{
- char *start;
- /* Strip off trailing whitespace, returns, etc */
- while (!ast_strlen_zero(buf) && (buf[strlen(buf)-1]<33))
- buf[strlen(buf)-1] = '\0';
- start = buf;
- /* Strip off leading whitespace, returns, etc */
- while (*start && (*start < 33))
- *start++ = '\0';
- return start;
+ char *e;
+
+ while (*s && (*s < 33)) s++;
+ e = s + strlen(s) - 1;
+ while ((e > s) && (*e < 33)) e--;
+ *++e = '\0';
+
+ return s;
+}
+
+char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
+{
+ char *e;
+ char *q;
+
+ s = ast_strip(s);
+ if ((q = strchr(beg_quotes, *s))) {
+ e = s + strlen(s) - 1;
+ if (*e == *(end_quotes + (q - beg_quotes))) {
+ s++;
+ *e = '\0';
+ }
+ }
+
+ return s;
}
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined( __NetBSD__ ) || defined(__APPLE__)