FreeCalypso > hg > themwi-system-sw
diff libsip/grok_from.c @ 51:36a30349b490
sip-in: parse INVITE From header
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 07 Sep 2022 17:53:10 -0800 |
parents | |
children | 8d311fd1138b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libsip/grok_from.c Wed Sep 07 17:53:10 2022 -0800 @@ -0,0 +1,100 @@ +/* + * Here we implement further parsing of the From header, + * beyond the preliminary step of uas_get_basic_headers(). + */ + +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include "grok_from.h" + +grok_from_header(from_hdr, gfr) + char *from_hdr; + struct grok_from *gfr; +{ + char *cp = from_hdr, *bp; + int bracketed; + + if (*cp == '<' || !strncasecmp(cp, "sip:", 4)) { + gfr->cnam = 0; + gfr->cnam_len = 0; + gfr->cnam_quoted = 0; + } else { + if (*cp == '"') { + cp++; + gfr->cnam = cp; + for (;;) { + if (!*cp) + return(-1); + if (*cp == '"') + break; + if (*cp++ == '\\') { + if (!*cp) + return(-1); + cp++; + } + } + gfr->cnam_len = cp - gfr->cnam; + gfr->cnam_quoted = 1; + cp++; + while (isspace(*cp)) + cp++; + if (*cp != '<') + return(-1); + } else { + gfr->cnam = cp; + for (;;) { + if (!*cp) + return(-1); + if (*cp == '<') + break; + cp++; + } + for (bp = cp; bp > gfr->cnam && isspace(bp[-1]); bp--) + ; + gfr->cnam_len = bp - gfr->cnam; + gfr->cnam_quoted = 0; + } + } + if (*cp == '<') { + cp++; + bracketed = 1; + } else + bracketed = 0; + gfr->uri = cp; + if (strncasecmp(cp, "sip:", 4)) + return(-1); + cp += 4; + gfr->user = cp; + for (;;) { + if (!*cp || *cp == '<' || *cp == '>') + return(-1); + if (*cp == '@') + break; + cp++; + } + if (cp == gfr->user) + return(-1); + gfr->user_len = cp - gfr->user; + cp++; + for (;;) { + switch (*cp) { + case '\0': + case ';': + if (bracketed) + return(-1); + else + break; + case '>': + if (bracketed) + break; + else + return(-1); + case '<': + return(-1); + } + cp++; + } + gfr->uri_len = cp - gfr->uri; + return(0); +}