annotate libsip/grok_from.c @ 224:62184b971c8e

smpp-send/input.c: copy-n-paste error
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Aug 2023 12:27:36 -0800
parents 8d311fd1138b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Here we implement further parsing of the From header,
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * beyond the preliminary step of uas_get_basic_headers().
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <string.h>
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <strings.h>
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "grok_from.h"
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 grok_from_header(from_hdr, gfr)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char *from_hdr;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 struct grok_from *gfr;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *cp = from_hdr, *bp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 int bracketed;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (*cp == '<' || !strncasecmp(cp, "sip:", 4)) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 gfr->cnam = 0;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 gfr->cnam_len = 0;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 gfr->cnam_quoted = 0;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 } else {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (*cp == '"') {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 gfr->cnam = cp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 for (;;) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (!*cp)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (*cp == '"')
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 break;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (*cp++ == '\\') {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!*cp)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 gfr->cnam_len = cp - gfr->cnam;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 gfr->cnam_quoted = 1;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 while (isspace(*cp))
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (*cp != '<')
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 } else {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 gfr->cnam = cp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 for (;;) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!*cp)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (*cp == '<')
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 break;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 for (bp = cp; bp > gfr->cnam && isspace(bp[-1]); bp--)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 ;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 gfr->cnam_len = bp - gfr->cnam;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 gfr->cnam_quoted = 0;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (*cp == '<') {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 bracketed = 1;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 } else
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 bracketed = 0;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 gfr->uri = cp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (strncasecmp(cp, "sip:", 4))
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 cp += 4;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 gfr->user = cp;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 for (;;) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!*cp || *cp == '<' || *cp == '>')
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (*cp == '@')
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 break;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (cp == gfr->user)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 gfr->user_len = cp - gfr->user;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 cp++;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 for (;;) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 switch (*cp) {
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 case '\0':
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 case ';':
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (bracketed)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 else
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 break;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 case '>':
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 if (bracketed)
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 break;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 else
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 return(-1);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 case '<':
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 return(-1);
58
8d311fd1138b libsip/grok_from.c: fix bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
95 default:
8d311fd1138b libsip/grok_from.c: fix bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
96 cp++;
8d311fd1138b libsip/grok_from.c: fix bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
97 continue;
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
58
8d311fd1138b libsip/grok_from.c: fix bug
Mychaela Falconia <falcon@freecalypso.org>
parents: 51
diff changeset
99 break;
51
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 gfr->uri_len = cp - gfr->uri;
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 return(0);
36a30349b490 sip-in: parse INVITE From header
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 }