MCPcopy Create free account
hub / github.com/NetSys/bess / parse_headers

Function parse_headers

core/utils/http_parser.cc:240–309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238}
239
240static const char *parse_headers(const char *buf, const char *buf_end,
241 struct phr_header *headers,
242 size_t *num_headers, size_t max_headers,
243 int *ret) {
244 for (;; ++*num_headers) {
245 CHECK_EOF();
246 if (*buf == '\015') {
247 ++buf;
248 EXPECT_CHAR('\012');
249 break;
250 } else if (*buf == '\012') {
251 ++buf;
252 break;
253 }
254 if (*num_headers == max_headers) {
255 *ret = -1;
256 return NULL;
257 }
258 if (!(*num_headers != 0 && (*buf == ' ' || *buf == '\t'))) {
259 /* parsing name, but do not discard SP before colon, see
260 * http://www.mozilla.org/security/announce/2006/mfsa2006-33.html */
261 headers[*num_headers].name = buf;
262 static const char ranges1[] ALIGNED(16) =
263 "\x00 " /* control chars and up to SP */
264 "\"\"" /* 0x22 */
265 "()" /* 0x28,0x29 */
266 ",," /* 0x2c */
267 "//" /* 0x2f */
268 ":@" /* 0x3a-0x40 */
269 "[]" /* 0x5b-0x5d */
270 "{\377"; /* 0x7b-0xff */
271 int found;
272 buf = findchar_fast(buf, buf_end, ranges1, sizeof ranges1 - 1, &found);
273 if (!found) {
274 CHECK_EOF();
275 }
276 while (1) {
277 if (*buf == ':') {
278 break;
279 } else if (!token_char_map[(unsigned char)*buf]) {
280 *ret = -1;
281 return NULL;
282 }
283 ++buf;
284 CHECK_EOF();
285 }
286 if ((headers[*num_headers].name_len = buf - headers[*num_headers].name) ==
287 0) {
288 *ret = -1;
289 return NULL;
290 }
291 ++buf;
292 for (;; ++buf) {
293 CHECK_EOF();
294 if (!(*buf == ' ' || *buf == '\t')) {
295 break;
296 }
297 }

Callers 3

parse_requestFunction · 0.85
parse_responseFunction · 0.85
phr_parse_headersFunction · 0.85

Calls 2

findchar_fastFunction · 0.85
get_token_to_eolFunction · 0.85

Tested by

no test coverage detected