MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / parse_single_part

Function parse_single_part

parser/parse_body.c:153–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151
152
153static int parse_single_part(struct body_part *part, char * start, char * end)
154{
155 char * tmp, *body_end, * mime_end;
156 unsigned int mime;
157
158 part->mime = -1;
159
160 if (*start=='\r') {
161 start++;
162 if (*start=='\n') start++;
163 } else if (*start=='\n') {
164 start++;
165 } else {
166 LM_ERR("invalid separator between boundry and body [%x/%x]\n",
167 *start,*(start+1));
168 return -1;
169 }
170
171 if (*(end-1)=='\n') {
172 end--;
173 if (*(end-1)=='\r') end--;
174 } else if (*(end-1)=='\r') {
175 end--;
176 } else {
177 LM_ERR("invalid separator between body and boundry [%x/%x]\n",
178 *(end-2),*(end-1));
179 return -1;
180 }
181
182 LM_DBG("parsing part [%.*s...]\n",
183 (int)((end-start)<25?end-start:25), start);
184
185 tmp = start;
186 while (1)
187 {
188 struct hdr_field hd;
189 memset(&hd, 0, sizeof (struct hdr_field));
190
191 tmp = get_hdr_field_unparsed(tmp, end, &hd);
192 if (tmp == NULL || hd.type == HDR_ERROR_T)
193 {
194 LM_ERR("Error parsing body part header\n");
195 return -1;
196 }
197
198 if (hd.type == HDR_CONTENTTYPE_T)
199 {
200 body_end = hd.body.s + hd.body.len;
201 mime_end = decode_mime_type(hd.body.s, body_end, &mime, NULL);
202
203 if (mime_end == NULL)
204 {
205 LM_ERR("Error parsing MIME\n");
206 return -1;
207 }
208 part->mime = mime;
209 part->mime_s = hd.body;
210 }

Callers 1

parse_sip_bodyFunction · 0.85

Calls 2

get_hdr_field_unparsedFunction · 0.85
decode_mime_typeFunction · 0.85

Tested by

no test coverage detected