comparison 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
comparison
equal deleted inserted replaced
50:daf1c26d7ae2 51:36a30349b490
1 /*
2 * Here we implement further parsing of the From header,
3 * beyond the preliminary step of uas_get_basic_headers().
4 */
5
6 #include <ctype.h>
7 #include <string.h>
8 #include <strings.h>
9 #include "grok_from.h"
10
11 grok_from_header(from_hdr, gfr)
12 char *from_hdr;
13 struct grok_from *gfr;
14 {
15 char *cp = from_hdr, *bp;
16 int bracketed;
17
18 if (*cp == '<' || !strncasecmp(cp, "sip:", 4)) {
19 gfr->cnam = 0;
20 gfr->cnam_len = 0;
21 gfr->cnam_quoted = 0;
22 } else {
23 if (*cp == '"') {
24 cp++;
25 gfr->cnam = cp;
26 for (;;) {
27 if (!*cp)
28 return(-1);
29 if (*cp == '"')
30 break;
31 if (*cp++ == '\\') {
32 if (!*cp)
33 return(-1);
34 cp++;
35 }
36 }
37 gfr->cnam_len = cp - gfr->cnam;
38 gfr->cnam_quoted = 1;
39 cp++;
40 while (isspace(*cp))
41 cp++;
42 if (*cp != '<')
43 return(-1);
44 } else {
45 gfr->cnam = cp;
46 for (;;) {
47 if (!*cp)
48 return(-1);
49 if (*cp == '<')
50 break;
51 cp++;
52 }
53 for (bp = cp; bp > gfr->cnam && isspace(bp[-1]); bp--)
54 ;
55 gfr->cnam_len = bp - gfr->cnam;
56 gfr->cnam_quoted = 0;
57 }
58 }
59 if (*cp == '<') {
60 cp++;
61 bracketed = 1;
62 } else
63 bracketed = 0;
64 gfr->uri = cp;
65 if (strncasecmp(cp, "sip:", 4))
66 return(-1);
67 cp += 4;
68 gfr->user = cp;
69 for (;;) {
70 if (!*cp || *cp == '<' || *cp == '>')
71 return(-1);
72 if (*cp == '@')
73 break;
74 cp++;
75 }
76 if (cp == gfr->user)
77 return(-1);
78 gfr->user_len = cp - gfr->user;
79 cp++;
80 for (;;) {
81 switch (*cp) {
82 case '\0':
83 case ';':
84 if (bracketed)
85 return(-1);
86 else
87 break;
88 case '>':
89 if (bracketed)
90 break;
91 else
92 return(-1);
93 case '<':
94 return(-1);
95 }
96 cp++;
97 }
98 gfr->uri_len = cp - gfr->uri;
99 return(0);
100 }