MCPcopy Create free account
hub / github.com/dillo-browser/dillo / Cache_parse_multiple_fields

Function Cache_parse_multiple_fields

src/cache.c:617–654  ·  view source on GitHub ↗

* Extract multiple fields from the header. */

Source from the content-addressed store, hash-verified

615 * Extract multiple fields from the header.
616 */
617static Dlist *Cache_parse_multiple_fields(const char *header,
618 const char *fieldname)
619{
620 uint_t i, j;
621 Dlist *fields = dList_new(8);
622 char *field;
623
624 for (i = 0; header[i]; i++) {
625 /* Search fieldname */
626 for (j = 0; fieldname[j]; j++)
627 if (D_ASCII_TOLOWER(fieldname[j]) != D_ASCII_TOLOWER(header[i + j]))
628 break;
629 if (fieldname[j]) {
630 /* skip to next line */
631 for (i += j; header[i] != '\n'; i++);
632 continue;
633 }
634
635 i += j;
636 if (header[i] == ':') {
637 /* Field found! */
638 while (header[++i] == ' ' || header[i] == '\t');
639 for (j = 0; header[i + j] != '\n'; j++);
640 while (j && (header[i + j - 1] == ' ' || header[i + j - 1] == '\t'))
641 j--;
642 field = dStrndup(header + i, j);
643 dList_append(fields, field);
644 } else {
645 while (header[i] != '\n') i++;
646 }
647 }
648
649 if (dList_length(fields) == 0) {
650 dList_free(fields);
651 fields = NULL;
652 }
653 return fields;
654}
655
656/**
657 * Scan, allocate, and set things according to header info.

Callers 1

Cache_parse_headerFunction · 0.85

Calls 5

dList_newFunction · 0.85
dStrndupFunction · 0.85
dList_appendFunction · 0.85
dList_lengthFunction · 0.85
dList_freeFunction · 0.85

Tested by

no test coverage detected