FreeCalypso > hg > themwi-system-sw
comparison libsip/primary_parse.c @ 45:f1cf80c7e243
libsip/primary_parse.c: fully trim leading and trailing spaces
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 06 Sep 2022 15:15:42 -0800 |
parents | 30572642e853 |
children |
comparison
equal
deleted
inserted
replaced
44:30572642e853 | 45:f1cf80c7e243 |
---|---|
82 return(0); | 82 return(0); |
83 else | 83 else |
84 return(1); | 84 return(1); |
85 } | 85 } |
86 | 86 |
87 static void | |
88 trim_trailing_spaces(sp) | |
89 char *sp; | |
90 { | |
91 char *ep; | |
92 | |
93 ep = index(sp, '\0'); | |
94 while (ep > sp && isspace(ep[-1])) | |
95 ep--; | |
96 *ep = '\0'; | |
97 } | |
98 | |
87 parse_incoming_sip_msg(msg) | 99 parse_incoming_sip_msg(msg) |
88 struct sip_pkt_rx *msg; | 100 struct sip_pkt_rx *msg; |
89 { | 101 { |
90 char *msg_end = msg->pkt_buffer + msg->pkt_length; | 102 char *msg_end = msg->pkt_buffer + msg->pkt_length; |
91 char *cp, *endp, *nextp; | 103 char *cp, *endp, *nextp, *sp; |
92 unsigned hdr_cnt; | 104 unsigned hdr_cnt; |
93 int rc; | 105 int rc; |
94 | 106 |
95 /* begin by isolating the Request-Line or Status-Line */ | 107 /* begin by isolating the Request-Line or Status-Line */ |
96 rc = find_crlf(msg->pkt_buffer, msg_end, &endp, &nextp); | 108 rc = find_crlf(msg->pkt_buffer, msg_end, &endp, &nextp); |
130 return(-1); | 142 return(-1); |
131 if (*cp++ != ':') | 143 if (*cp++ != ':') |
132 return(-1); | 144 return(-1); |
133 } else | 145 } else |
134 return(-1); | 146 return(-1); |
135 while (cp < endp && isspace(*cp)) | 147 sp = cp; |
136 cp++; | |
137 msg->hdr_fields[hdr_cnt++].field_value = cp; | |
138 cp = nextp; | 148 cp = nextp; |
139 while (cp < msg_end && (*cp == ' ' || *cp == '\t')) { | 149 while (cp < msg_end && (*cp == ' ' || *cp == '\t')) { |
140 rc = find_crlf(cp, msg_end, &endp, &nextp); | 150 rc = find_crlf(cp, msg_end, &endp, &nextp); |
141 if (!rc) | 151 if (!rc) |
142 return(-1); | 152 return(-1); |
143 cp = nextp; | 153 cp = nextp; |
144 } | 154 } |
145 *endp = '\0'; | 155 *endp = '\0'; |
156 while (isspace(*sp)) | |
157 sp++; | |
158 trim_trailing_spaces(sp); | |
159 msg->hdr_fields[hdr_cnt++].field_value = sp; | |
146 } | 160 } |
147 msg->num_hdr_fields = hdr_cnt; | 161 msg->num_hdr_fields = hdr_cnt; |
148 msg->msg_body = nextp; | 162 msg->msg_body = nextp; |
149 msg->msg_body_len = msg_end - nextp; | 163 msg->msg_body_len = msg_end - nextp; |
150 return(0); | 164 return(0); |