Commit e7553ea2187eaab0ae20b2188df060f49b46f394
1 parent
1fb86288
add cookie request parsing and fix post (form vars) parsing. User new parsed coo…
…kies within worker/process
Showing
3 changed files
with
50 additions
and
16 deletions
| ... | ... | @@ -29,7 +29,9 @@ |
| 29 | 29 | #include "http/header.h" |
| 30 | 30 | #include "http/parser.h" |
| 31 | 31 | #include "http/message.h" |
| 32 | +#include "http/request.h" | |
| 32 | 33 | #include "hash.h" |
| 34 | +#include "hash_value.h" | |
| 33 | 35 | |
| 34 | 36 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) |
| 35 | 37 | |
| ... | ... | @@ -67,6 +69,42 @@ httpParserHeader( |
| 67 | 69 | current->dbody = 0; |
| 68 | 70 | } |
| 69 | 71 | |
| 72 | + if (0 == strncasecmp("cookie", name, nname-1)) { | |
| 73 | + HttpRequest request = (HttpRequest)this->current; | |
| 74 | + char * pair = value; | |
| 75 | + size_t togo = lend - value; | |
| 76 | + | |
| 77 | + while(NULL != pair && 0 < togo) { | |
| 78 | + char * key = pair; | |
| 79 | + char * eqsign; | |
| 80 | + char * val; | |
| 81 | + size_t nval; | |
| 82 | + | |
| 83 | + for (; *key == ' ' && key < lend; key++, togo--); | |
| 84 | + eqsign = memchr(key, '=', togo); | |
| 85 | + | |
| 86 | + if (NULL == eqsign) { | |
| 87 | + break; | |
| 88 | + } | |
| 89 | + | |
| 90 | + togo -= (eqsign - key); | |
| 91 | + pair = memchr(eqsign, ';', togo); | |
| 92 | + | |
| 93 | + if (NULL == pair) { | |
| 94 | + pair = (char *)lend; | |
| 95 | + } | |
| 96 | + | |
| 97 | + nval = pair-eqsign-1; | |
| 98 | + val = (0 != nval)? eqsign+1 : NULL; | |
| 99 | + | |
| 100 | + hashAdd(request->cookies, | |
| 101 | + new(HashValue, key, eqsign-key, val, nval)); | |
| 102 | + | |
| 103 | + togo -= (pair - eqsign); | |
| 104 | + pair++; | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 70 | 108 | hashAdd(current->header, |
| 71 | 109 | new(HttpHeader, name, nname, value, lend - value)); |
| 72 | 110 | } | ... | ... |
| ... | ... | @@ -64,25 +64,20 @@ httpWorkerProcess(HttpWorker this, Stream st) |
| 64 | 64 | HttpMessage rmessage = reqq->msgs[i]; |
| 65 | 65 | HttpRequest request = (HttpRequest)(reqq->msgs[i]); |
| 66 | 66 | HttpMessage response = NULL; |
| 67 | - HttpHeader cookie = hashGet( | |
| 68 | - rmessage->header, | |
| 69 | - CSTRA("cookie")); | |
| 70 | 67 | |
| 71 | - if (NULL == this->session && NULL != cookie) { | |
| 72 | - int i; | |
| 68 | + /** | |
| 69 | + * \todo store the cookie count in the request to make a simple | |
| 70 | + * check possible to prevent this lookup if no cookies exists | |
| 71 | + * at all | |
| 72 | + */ | |
| 73 | + if (NULL == this->session) { | |
| 74 | + HashValue sidstr = hashGet(request->cookies, CSTRA("sid")); | |
| 73 | 75 | |
| 74 | - for (i=0; i<cookie->cvalue; i++) { | |
| 75 | - char * sidstr = strstr(cookie->value[i], "sid"); | |
| 76 | + if (NULL != sidstr) { | |
| 77 | + unsigned long sid; | |
| 76 | 78 | |
| 77 | - if (NULL != sidstr) { | |
| 78 | - unsigned long sid; | |
| 79 | - | |
| 80 | - sidstr = strchr(sidstr, '=')+1; | |
| 81 | - sid = strtoul(sidstr, NULL, 10); | |
| 82 | - | |
| 83 | - this->session = sessionGet(this->sroot, sid); | |
| 84 | - break; | |
| 85 | - } | |
| 79 | + sid = strtoul((char*)(sidstr->value), NULL, 10); | |
| 80 | + this->session = sessionGet(this->sroot, sid); | |
| 86 | 81 | } |
| 87 | 82 | } |
| 88 | 83 | ... | ... |
Please
register
or
login
to post a comment