reading cookies works now

This commit is contained in:
overflowerror 2021-06-13 13:14:14 +02:00
parent 55cf10890c
commit 22f983e9fe

View file

@ -19,21 +19,34 @@ char* getCookie(ctx_t* ctx, const char* key) {
return NULL; return NULL;
} }
char** saveptr = NULL; char* saveptr = NULL;
char* str = cookieHeader; char* str = cookieHeader;
char* value = NULL; char* value = NULL;
while((str = strtok_r(str, "; ", saveptr)) != NULL) { while((str = strtok_r(str, ";", &saveptr)) != NULL) {
while(*str == ' ') str++;
char* keyCandidate = str; char* keyCandidate = str;
str = strtok_r(NULL, "=", saveptr);
for (; *str != '='; str++) {
if (*str == '\0') {
str = NULL;
break;
}
}
if (str == NULL) { if (str == NULL) {
// illegal cookie definition; ignore // illegal cookie definition; ignore
// str is already NULL
continue; continue;
} }
*str = '\0';
if (strcmp(keyCandidate, key) == 0) { if (strcmp(keyCandidate, key) == 0) {
value = str; value = str + 1;
break;
} }
str = NULL; str = NULL;