Index: chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.784 diff -u -r1.784 chan_sip.c --- chan_sip.c 20 Jul 2005 17:05:18 -0000 1.784 +++ chan_sip.c 25 Jul 2005 09:43:03 -0000 @@ -838,24 +838,6 @@ return res; } -/* - * If there is a string in , strip everything around and return - * the content. Otherwise return the original argument. - */ -static char *get_in_brackets(char *c) -{ - char *n = strchr(c, '<'); - - if (n) { - c = n + 1; - n = strchr(c, '>'); - /* Lose the part after the > */ - if (n) - *n = '\0'; - } - return c; -} - /*--- parse_sip_options: Parse supported header in incoming packet */ unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported) { @@ -1339,13 +1321,17 @@ *o = '\0'; } -/*--- ditch_braces: Pick out text in braces from character string ---*/ -static char *ditch_braces(char *tmp) +/*--- ditch_braces: Pick out text in braces from character string ---*/ +/* returns pointer to terminated stripped string. modifies input string. + * mode == 0: find the text within braces after quoted section + * mode == 1: find the text within braces ignoring quotes + * TODO: i don't know, if mode == 1 makes sense at all, but this was the + * functionality of former function call get_in_brackets(char*) */ +static char *ditch_braces(char *tmp, int mode) { - char *c = tmp; - char *n; - char *q; - if ((q = strchr(tmp, '"')) ) { + char *c = tmp, *n, *q; + + if (!mode && (q = strchr(tmp, '"')) ) { c = q + 1; if ((q = strchr(c, '"')) ) c = q + 1; @@ -1356,12 +1342,11 @@ } if ((n = strchr(c, '<')) ) { c = n + 1; - while(*c && *c != '>') c++; + while (*c && *c != '>') c++; if (*c != '>') { ast_log(LOG_WARNING, "No closing brace in '%s'\n", tmp); - } else { + } else *c = '\0'; - } return n+1; } return c; @@ -3751,7 +3736,7 @@ /* We have no URI, use To: or From: header as URI (depending on direction) */ c = get_header(orig, (ast_test_flag(p, SIP_OUTGOING)) ? "To" : "From"); ast_copy_string(stripped, c, sizeof(stripped)); - c = get_in_brackets(stripped); + c = ditch_braces(stripped, 1); n = strchr(c, ';'); if (n) *n = '\0'; @@ -4223,7 +4208,7 @@ char stripped[256]=""; char *c, *n; ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped)); - c = get_in_brackets(stripped); + c = ditch_braces(stripped, 1); n = strchr(c, ';'); if (n) *n = '\0'; @@ -4465,7 +4450,7 @@ memset(to, 0, sizeof(to)); ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from)); - c = ditch_braces(from); + c = ditch_braces(from, 0); if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); return -1; @@ -4480,7 +4465,7 @@ if (p->subscribed == 1) { ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to)); - c = ditch_braces(to); + c = ditch_braces(to, 0); if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); return -1; @@ -4943,7 +4928,7 @@ else of = get_header(&p->initreq, "From"); ast_copy_string(from, of, sizeof(from)); - of = ditch_braces(from); + of = ditch_braces(from, 0); ast_copy_string(p->from,of,sizeof(p->from)); if (strncmp(of, "sip:", 4)) { ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); @@ -5124,7 +5109,7 @@ /* Look for brackets */ ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); - c = get_in_brackets(contact); + c = ditch_braces(contact, 1); /* Save full contact to call pvt for later bye or re-invite */ ast_copy_string(pvt->fullcontact, c, sizeof(pvt->fullcontact)); @@ -5209,7 +5194,7 @@ } /* Look for brackets */ ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); - c = get_in_brackets(contact); + c = ditch_braces(contact, 1); if (!strcasecmp(c, "*") || !expiry) { /* Unregister this peer */ /* This means remove all registrations and return OK */ @@ -5673,7 +5658,7 @@ *t = '\0'; ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp)); - c = ditch_braces(tmp); + c = ditch_braces(tmpl, 0); /* Ditch ;user=phone */ name = strchr(c, ';'); if (name) @@ -5769,7 +5754,7 @@ ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp)); if (ast_strlen_zero(tmp)) return 0; - c = ditch_braces(tmp); + c = ditch_braces(tmp, 0); if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not an RDNIS SIP header (%s)?\n", c); return -1; @@ -5797,10 +5782,10 @@ req = &p->initreq; if (req->rlPart2) ast_copy_string(tmp, req->rlPart2, sizeof(tmp)); - c = ditch_braces(tmp); + c = ditch_braces(tmp, 0); ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf)); - fr = ditch_braces(tmpf); + fr = ditch_braces(tmpf, 0); if (strncmp(c, "sip:", 4)) { ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); @@ -5901,13 +5886,13 @@ return -1; } - refer_to = ditch_braces(h_refer_to); + refer_to = ditch_braces(h_refer_to, 0); if (!( (p_referred_by = get_header(req, "Referred-By")) && (h_referred_by = ast_strdupa(p_referred_by)) )) { ast_log(LOG_WARNING, "No Referrred-By Header That's not illegal\n"); return -1; } else { - referred_by = ditch_braces(h_referred_by); + referred_by = ditch_braces(h_referred_by, 0); } h_contact = get_header(req, "Contact"); @@ -6025,7 +6010,7 @@ req = &p->initreq; ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp)); - c = ditch_braces(tmp); + c = ditch_braces(tmp, 0); if (strncmp(c, "sip:", 4)) { @@ -6203,7 +6188,7 @@ if (!ast_strlen_zero(rpid)) p->callingpres = get_rpid_num(rpid,rpid_num, sizeof(rpid_num)); - of = ditch_braces(from); + of = ditch_braces(from, 0); if (ast_strlen_zero(p->exten)) { t = uri; if (!strncmp(t, "sip:", 4)) @@ -8263,7 +8248,7 @@ char tmp[256] = ""; char *s, *e; ast_copy_string(tmp, get_header(req, "Contact"), sizeof(tmp)); - s = ditch_braces(tmp); + s = ditch_braces(tmp, 0); e = strchr(s, ';'); if (e) *e = '\0';