mirror of
https://github.com/sigmasternchen/CShore
synced 2025-03-15 16:18:56 +00:00
reading cookies works now
This commit is contained in:
parent
55cf10890c
commit
22f983e9fe
1 changed files with 17 additions and 4 deletions
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue