- dynstr_init(&d);
- n = 0;
- while((c = (unsigned char)*s++)) {
- if((t = strchr(table, c))) {
- b[n++] = t - table;
- if(n == 4) {
- dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
- dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
- dynstr_append(&d, (b[2] << 6) + b[3]);
- n = 0;
- }
- } else if(c == '=') {
- if(n >= 2) {
- dynstr_append(&d, (b[0] << 2) + (b[1] >> 4));
- if(n == 3)
- dynstr_append(&d, (b[1] << 4) + (b[2] >> 2));
+ memset(cd, 0, sizeof *cd);
+ s = skipwhite(s, 0);
+ while(*s) {
+ /* Skip separators */
+ if(*s == ';' || *s == ',') {
+ ++s;
+ s = skipwhite(s, 0);
+ continue;
+ }
+ if(!(s = parsetoken(s, &n, http_separator))) return -1;
+ s = skipwhite(s, 0);
+ if(*s++ != '=') return -1;
+ s = skipwhite(s, 0);
+ if(!(s = parseword(s, &v, http_separator))) return -1;
+ if(n[0] == '$') {
+ /* Some bit of meta-information */
+ if(!strcmp(n, "$Version"))
+ cd->version = v;
+ else if(!strcmp(n, "$Path")) {
+ if(cd->ncookies > 0 && cd->cookies[cd->ncookies-1].path == 0)
+ cd->cookies[cd->ncookies-1].path = v;
+ else {
+ error(0, "redundant $Path in Cookie: header");
+ return -1;
+ }
+ } else if(!strcmp(n, "$Domain")) {
+ if(cd->ncookies > 0 && cd->cookies[cd->ncookies-1].domain == 0)
+ cd->cookies[cd->ncookies-1].domain = v;
+ else {
+ error(0, "redundant $Domain in Cookie: header");
+ return -1;
+ }