/* * Refreshes the header mask. Useful after httpHeaderDelAt constructs */ void httpHeaderRefreshMask(HttpHeader * hdr) { HttpHeaderPos pos = HttpHeaderInitPos; HttpHeaderEntry *e; httpHeaderMaskInit(&hdr->mask, 0); debug(55, 7) ("refreshing the mask in hdr %p\n", hdr); while ((e = httpHeaderGetEntry(hdr, &pos))) { CBIT_SET(hdr->mask, e->id); } }
/* calculates a bit mask of a given array; does not reset mask! */ void httpHeaderCalcMask(HttpHeaderMask * mask, const int *enums, int count) { int i; assert(mask && enums); assert(count < sizeof(*mask) * 8); /* check for overflow */ for (i = 0; i < count; ++i) { assert(!CBIT_TEST(*mask, enums[i])); /* check for duplicates */ CBIT_SET(*mask, enums[i]); } }
/* appends an entry; * does not call httpHeaderEntryClone() so one should not reuse "*e" */ void httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e) { assert(hdr && e); assert_eid(e->id); debug(55, 7) ("%p adding entry: %d at %d\n", hdr, e->id, hdr->entries.count); if (CBIT_TEST(hdr->mask, e->id)) Headers[e->id].stat.repCount++; else CBIT_SET(hdr->mask, e->id); arrayAppend(&hdr->entries, e); /* increment header length, allow for ": " and crlf */ hdr->len += strLen(e->name) + 2 + strLen(e->value) + 2; }
/* * deletes all fields with a given name if any, returns #fields deleted; */ int httpHeaderDelByName(HttpHeader * hdr, const char *name) { int count = 0; HttpHeaderPos pos = HttpHeaderInitPos; HttpHeaderEntry *e; httpHeaderMaskInit(&hdr->mask, 0); /* temporal inconsistency */ debug(55, 7) ("deleting '%s' fields in hdr %p\n", name, hdr); while ((e = httpHeaderGetEntry(hdr, &pos))) { if (!strCaseCmp(e->name, name)) { httpHeaderDelAt(hdr, pos); count++; } else CBIT_SET(hdr->mask, e->id); } return count; }
void cacheDigestAdd(CacheDigest * cd, const cache_key * key) { assert(cd && key); /* hash */ cacheDigestHashKey(cd, key); /* turn on corresponding bits */ #if CD_FAST_ADD CBIT_SET(cd->mask, hashed_keys[0]); CBIT_SET(cd->mask, hashed_keys[1]); CBIT_SET(cd->mask, hashed_keys[2]); CBIT_SET(cd->mask, hashed_keys[3]); #else { int on_xition_cnt = 0; if (!CBIT_TEST(cd->mask, hashed_keys[0])) { CBIT_SET(cd->mask, hashed_keys[0]); on_xition_cnt++; } if (!CBIT_TEST(cd->mask, hashed_keys[1])) { CBIT_SET(cd->mask, hashed_keys[1]); on_xition_cnt++; } if (!CBIT_TEST(cd->mask, hashed_keys[2])) { CBIT_SET(cd->mask, hashed_keys[2]); on_xition_cnt++; } if (!CBIT_TEST(cd->mask, hashed_keys[3])) { CBIT_SET(cd->mask, hashed_keys[3]); on_xition_cnt++; } statHistCount(&statCounter.cd.on_xition_count, on_xition_cnt); } #endif cd->count++; }