Commit 12b3a911 authored by Joshua Bussdieker's avatar Joshua Bussdieker

Multiheader support

parent 8ce3713d
......@@ -279,6 +279,32 @@ http_GetHdr(const struct http *hp, const char *hdr, char **ptr)
return (1);
}
unsigned
http_EnumHdr(const struct http *hp, int offset, const char *hdr, char **ptr)
{
unsigned u, l;
char *p;
l = hdr[0];
diagnostic(l == strlen(hdr + 1));
assert(hdr[l] == ':');
for (u = offset == 0 ? HTTP_HDR_FIRST : offset; u < hp->nhd; u++) {
if (u < hp->nhd && http_IsHdr(&hp->hd[u], hdr)) {
Tcheck(hp->hd[u]);
p = hp->hd[u].b + l;
while (vct_issp(*p))
p++;
*ptr = p;
return u+1;
}
}
*ptr = NULL;
return 0;
}
/*--------------------------------------------------------------------
* Find a given data element in a header according to RFC2616's #rule
......
......@@ -459,32 +459,39 @@ KEY_Match(struct http *http, const uint8_t *key)
unsigned l = vbe16dec(key);
int not_flag = 0;
int case_flag = 0;
i = http_GetHdr(http, (const char*)(key+3), &h);
// TODO: Perhaps not matcher should allow this
if (i == 0)
return 0;
const char *matcher = key + 4 + key[3] + 1;
while (*matcher != 0 && *matcher != -1) {
char *m = matcher + 1;
unsigned u = 0;
int subresult = 0;
switch (matcher[0]) {
case M_WORD:
if (!word_matcher(m, h, strlen(m), case_flag) ^ not_flag)
while (u = http_EnumHdr(http, u, (const char*)(key+3), &h)) {
subresult |= word_matcher(m, h, strlen(m), case_flag);
}
if (!(subresult ^ not_flag))
result = 0;
break;
case M_SUBSTRING:
if (!substring_matcher(m, h, strlen(m), case_flag) ^ not_flag)
while (u = http_EnumHdr(http, u, (const char*)(key+3), &h)) {
subresult |= substring_matcher(m, h, strlen(m), case_flag);
}
if (!(subresult ^ not_flag))
result = 0;
break;
case M_BEGINNING:
if (!beginning_substring_matcher(m, h, strlen(m), case_flag) ^ not_flag)
while (u = http_EnumHdr(http, u, (const char*)(key+3), &h)) {
subresult |= beginning_substring_matcher(m, h, strlen(m), case_flag);
}
if (!(subresult ^ not_flag))
result = 0;
break;
case M_PARAMETER:
if (!parameter_prefix_matcher(m, h, strlen(m), case_flag) ^ not_flag)
while (u = http_EnumHdr(http, u, (const char*)(key+3), &h)) {
subresult |= parameter_prefix_matcher(m, h, strlen(m), case_flag);
}
if (!(subresult ^ not_flag))
result = 0;
break;
case M_CASE:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment