/* return a list of entries with the same id separated by ',' and ws */ String httpHeaderGetList(const HttpHeader * hdr, http_hdr_type id) { String s = StringNull; HttpHeaderEntry *e; HttpHeaderPos pos = HttpHeaderInitPos; debug(55, 6) ("%p: joining for id %d\n", hdr, id); /* only fields from ListHeaders array can be "listed" */ assert(CBIT_TEST(ListHeadersMask, id)); if (!CBIT_TEST(hdr->mask, id)) return s; while ((e = httpHeaderGetEntry(hdr, &pos))) { if (e->id == id) strListAdd(&s, strBuf(e->value), ','); } /* * note: we might get an empty (len==0) string if there was an "empty" * header; we must not get a NULL string though. */ assert(strBuf(s)); /* temporary warning: remove it! @?@ @?@ @?@ */ if (!strLen(s)) debug(55, 3) ("empty list header: %s (%d)\n", strBuf(Headers[id].name), id); debug(55, 6) ("%p: joined for id %d: %s\n", hdr, id, strBuf(s)); return s; }
/* * Returns the value of the specified header. */ String httpHeaderGetByName(const HttpHeader * hdr, const char *name) { http_hdr_type id; HttpHeaderPos pos = HttpHeaderInitPos; HttpHeaderEntry *e; String result = StringNull; assert(hdr); assert(name); /* First try the quick path */ id = httpHeaderIdByNameDef(name, strlen(name)); if (id != -1) return httpHeaderGetStrOrList(hdr, id); /* Sorry, an unknown header name. Do linear search */ while ((e = httpHeaderGetEntry(hdr, &pos))) { if (e->id == HDR_OTHER && strCaseCmp(e->name, name) == 0) { strListAdd(&result, strBuf(e->value), ','); } } return result; }
/* appends an item to the list if not already there */ void strListAddUnique(String * str, const char *item, char del) { if (!strListIsMember(str, item, del)) strListAdd(str, item, del); }