_really_ rewrite get_in_brackets to do the right thing (including skipping escaped...
authorKevin P. Fleming <kpfleming@digium.com>
Mon, 25 Jul 2005 21:40:17 +0000 (21:40 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Mon, 25 Jul 2005 21:40:17 +0000 (21:40 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6205 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c

index a8c641f..8a86a62 100755 (executable)
@@ -1321,31 +1321,46 @@ static void url_decode(char *s)
        *o = '\0';
 }
 
        *o = '\0';
 }
 
-/*--- get_in_brackets: Pick out text in braces from character string ---*/
+/*--- get_in_brackets: Pick out text in brackets from character string ---*/
 /* returns pointer to terminated stripped string. modifies input string. */
 static char *get_in_brackets(char *tmp)
 {
 /* returns pointer to terminated stripped string. modifies input string. */
 static char *get_in_brackets(char *tmp)
 {
-       char *c = tmp, *n, *q;
-
-       if ((q = strchr(tmp, '"'))) {
-               c = q + 1;
-               if ((q = strchr(c, '"')) )
-                       c = q + 1;
-               else {
-                       ast_log(LOG_WARNING, "No closing quote in '%s'\n", tmp);
-                       c = tmp;
+       char *parse;
+       char *first_quote;
+       char *first_bracket;
+       char *second_bracket;
+       char last_char;
+
+       parse = tmp;
+       while (1) {
+               first_quote = strchr(parse, '"');
+               first_bracket = strchr(parse, '<');
+               if (first_quote && first_bracket && (first_quote < first_bracket)) {
+                       last_char = '\0';
+                       for (parse = first_quote + 1; *parse; parse++) {
+                               if ((*parse == '"') && (last_char != '\\'))
+                                       break;
+                               last_char = *parse;
+                       }
+                       if (!*parse) {
+                               ast_log(LOG_WARNING, "No closing quote found in '%s'\n", tmp);
+                               return tmp;
+                       }
+                       parse++;
+                       continue;
                }
                }
+               if (first_bracket) {
+                       second_bracket = strchr(first_bracket + 1, '>');
+                       if (second_bracket) {
+                               *second_bracket = '\0';
+                               return first_bracket + 1;
+                       } else {
+                               ast_log(LOG_WARNING, "No closing bracket found in '%s'\n", tmp);
+                               return tmp;
+                       }
+               }
+               return tmp;
        }
        }
-       if ((n = strchr(c, '<')) ) {
-               c = n + 1;
-               while (*c && *c != '>') c++;
-               if (*c != '>') {
-                       ast_log(LOG_WARNING, "No closing brace in '%s'\n", tmp);
-               } else
-                       *c = '\0';
-               return n+1;
-       }
-       return c;
 }
 
 /*--- sip_sendtext: Send SIP MESSAGE text within a call ---*/
 }
 
 /*--- sip_sendtext: Send SIP MESSAGE text within a call ---*/