added cookie parsing in http headers. it is to parse the cookie header from the browser. e.g., once the user is authenticated (/magic/login) it is handed a token - a site-wide cookie. the browser then hands it back on every request. Reference: /n/sources/patch/applied/libhttpd-cookie-parsing Date: Wed Sep 26 21:16:52 CES 2007 Signed-off-by: fst@9netics.com --- /sys/src/libhttpd/parse.c Tue Sep 25 18:39:58 2007 +++ /sys/src/libhttpd/parse.c Tue Sep 25 18:39:52 2007 @@ -46,6 +46,7 @@ static void mimeauthorization(Hlex*, char*); static void mimeconnection(Hlex*, char*); static void mimecontlen(Hlex*, char*); +static void mimecookie(Hlex*, char*); static void mimeexpect(Hlex*, char*); static void mimefresh(Hlex*, char*); static void mimefrom(Hlex*, char*); @@ -77,6 +78,7 @@ {"authorization", mimeauthorization}, {"connection", mimeconnection}, {"content-length", mimecontlen}, + {"cookie", mimecookie}, {"expect", mimeexpect}, {"fresh", mimefresh}, {"from", mimefrom}, @@ -670,6 +672,32 @@ mimetransenc(Hlex *h, char *) { h->c->head.transenc = mimehfields(h); +} + +static void +mimecookie(Hlex *h, char *) +{ + HSPairs *p; + char *s; + + p = nil; + for(;;){ + while(lex(h) != Word) + if(h->tok != ';' && h->tok != ',') { + goto breakout; + } + + s = hstrdup(h->c, h->wordval); + while (lex(h) != Word && h->tok != QString) + if (h->tok != '=') { + goto breakout; + } + + p = hmkspairs(h->c, s, hstrdup(h->c, h->wordval), p); + } + +breakout: + h->c->head.cookie = hrevspairs(p); } static void --- /sys/include/httpd.h Tue Sep 25 18:40:10 2007 +++ /sys/include/httpd.h Tue Sep 25 18:40:07 2007 @@ -179,6 +179,7 @@ HRange *range; char *authuser; /* authorization info */ char *authpass; + HSPairs *cookie; /* if present, list of cookies */ /* * experimental headers