FreeCalypso > hg > themwi-system-sw
annotate libsip/primary_parse.c @ 235:bd493b21f215
libnumdb2: port check_nanp.c
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Mon, 14 Aug 2023 13:57:10 -0800 |
| parents | f1cf80c7e243 |
| children |
| rev | line source |
|---|---|
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we are going to implement the first stage of |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * parsing for incoming SIP UDP packets, using struct sip_pkt_rx |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * defined in parse.h. |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "parse.h" |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 find_crlf(ptr, msg_end, endp, nextp) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char *ptr, *msg_end, **endp, **nextp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 for (;;) { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 if (ptr >= msg_end) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 switch (*ptr) { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 case '\0': |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 case '\n': |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 *endp = ptr; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 *nextp = ptr + 1; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 case '\r': |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 *endp = ptr; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 ptr++; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (ptr >= msg_end) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (*ptr != '\n') |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 *nextp = ptr + 1; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 ptr++; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 static |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 try_status_line(msg) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 struct sip_pkt_rx *msg; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 { |
|
44
30572642e853
libsip/primary_parse.c: SIP-Version is case-insensitive per RFC 3261
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
45 if (strncasecmp(msg->pkt_buffer, "SIP/2.0 ", 8)) |
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (!isdigit(msg->pkt_buffer[8])) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (!isdigit(msg->pkt_buffer[9])) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (!isdigit(msg->pkt_buffer[10])) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (msg->pkt_buffer[11] != ' ') |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 msg->status_code = atoi(msg->pkt_buffer + 8); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 msg->status_str = msg->pkt_buffer + 8; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return(1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 static |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 try_request_line(msg) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 struct sip_pkt_rx *msg; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 char *cp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 cp = msg->pkt_buffer; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (!isupper(*cp)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 while (isalnum(*cp)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 cp++; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (*cp != ' ') |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 msg->req_method = msg->pkt_buffer; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *cp++ = '\0'; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 msg->req_uri = cp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 while (*cp && !isspace(*cp)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 cp++; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (*cp != ' ') |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 *cp++ = '\0'; |
|
44
30572642e853
libsip/primary_parse.c: SIP-Version is case-insensitive per RFC 3261
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
81 if (strcasecmp(cp, "SIP/2.0")) |
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 else |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 return(1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
|
45
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
87 static void |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
88 trim_trailing_spaces(sp) |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
89 char *sp; |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
90 { |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
91 char *ep; |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
92 |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
93 ep = index(sp, '\0'); |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
94 while (ep > sp && isspace(ep[-1])) |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
95 ep--; |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
96 *ep = '\0'; |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
97 } |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
98 |
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 parse_incoming_sip_msg(msg) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 struct sip_pkt_rx *msg; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 char *msg_end = msg->pkt_buffer + msg->pkt_length; |
|
45
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
103 char *cp, *endp, *nextp, *sp; |
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 unsigned hdr_cnt; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 int rc; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 /* begin by isolating the Request-Line or Status-Line */ |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 rc = find_crlf(msg->pkt_buffer, msg_end, &endp, &nextp); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 if (!rc) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 *endp = '\0'; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (try_status_line(msg)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 msg->parse_msgtype = SIP_MSG_TYPE_RESP; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 else if (try_request_line(msg)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 msg->parse_msgtype = SIP_MSG_TYPE_REQ; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 else |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 /* now preparse header fields */ |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 cp = nextp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 for (hdr_cnt = 0; ; ) { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 rc = find_crlf(cp, msg_end, &endp, &nextp); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 if (!rc) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 if (endp == cp) /* final CRLF? */ |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 break; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 if (!isalpha(*cp)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (hdr_cnt >= MAX_HEADER_FIELDS) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 return(-2); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 msg->hdr_fields[hdr_cnt].field_name = cp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 while (cp < endp && (isalnum(*cp) || *cp == '-')) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 cp++; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 if (cp >= endp) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 if (*cp == ':') |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 *cp++ = '\0'; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 else if (isspace(*cp)) { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 *cp++ = '\0'; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 while (cp < endp && isspace(*cp)) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 cp++; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 if (cp >= endp) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 if (*cp++ != ':') |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 } else |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 return(-1); |
|
45
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
147 sp = cp; |
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 cp = nextp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 while (cp < msg_end && (*cp == ' ' || *cp == '\t')) { |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 rc = find_crlf(cp, msg_end, &endp, &nextp); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (!rc) |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 return(-1); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 cp = nextp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 *endp = '\0'; |
|
45
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
156 while (isspace(*sp)) |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
157 sp++; |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
158 trim_trailing_spaces(sp); |
|
f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
Mychaela Falconia <falcon@freecalypso.org>
parents:
44
diff
changeset
|
159 msg->hdr_fields[hdr_cnt++].field_value = sp; |
|
40
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 } |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 msg->num_hdr_fields = hdr_cnt; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 msg->msg_body = nextp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 msg->msg_body_len = msg_end - nextp; |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 return(0); |
|
77d980126efd
libsip started with primary parsing function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
