New parser for cookies (bug #58459)
This commit is contained in:
parent
7c998760b4
commit
75e9a82289
@ -1,11 +1,15 @@
|
|||||||
ChangeLog for davfs2
|
ChangeLog for davfs2
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
2020-05-20 Werner Baumann (werner.baumann@onlinehome.de)
|
2020-06-07 Werner Baumann (werner.baumann@onlinehome.de)
|
||||||
|
* webdav.c, get_cookies:
|
||||||
|
New parser for cookies (bug #58459).
|
||||||
|
|
||||||
|
2020-06-06 Werner Baumann (werner.baumann@onlinehome.de)
|
||||||
* webdav.c, add_header:
|
* webdav.c, add_header:
|
||||||
Use ";" instead of "," as seperator (bug #58459).
|
Use ";" instead of "," as seperator (bug #58459).
|
||||||
|
|
||||||
2020-05-20 Werner Baumann (werner.baumann@onlinehome.de)
|
2020-06-06 Werner Baumann (werner.baumann@onlinehome.de)
|
||||||
* mount_davfs.c, log_dbg_config:
|
* mount_davfs.c, log_dbg_config:
|
||||||
Add log message.
|
Add log message.
|
||||||
|
|
||||||
|
65
src/webdav.c
65
src/webdav.c
@ -1563,50 +1563,53 @@ file_reader(void *userdata, const char *block, size_t length)
|
|||||||
static void
|
static void
|
||||||
get_cookies(ne_request *req, void *userdata, const ne_status *status)
|
get_cookies(ne_request *req, void *userdata, const ne_status *status)
|
||||||
{
|
{
|
||||||
const char *cookie_hdr = ne_get_response_header(req, "Set-Cookie");
|
void *cursor = NULL;
|
||||||
if (!cookie_hdr)
|
const char *name;
|
||||||
return;
|
const char *value;
|
||||||
|
|
||||||
const char *next = cookie_hdr;
|
cursor = ne_response_header_iterate(req, cursor, &name, &value);
|
||||||
while (next) {
|
while (cursor) {
|
||||||
const char *start = next;
|
if (strcasecmp(name, "Set-Cookie") != 0) {
|
||||||
next = strchr(start, ',');
|
cursor = ne_response_header_iterate(req, cursor, &name, &value);
|
||||||
const char *end = strchr(start, ';');
|
continue;
|
||||||
if (next) {
|
|
||||||
if (!end || end > next)
|
|
||||||
end = next;
|
|
||||||
next++;
|
|
||||||
} else if (!end) {
|
|
||||||
end = start + strlen(start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (start < end && *start == ' ')
|
char *s;
|
||||||
start++;
|
const char *end = strchr(value, ';');
|
||||||
while (end > start && *(end - 1) == ' ')
|
if (end) {
|
||||||
end--;
|
s = xstrndup(value, end - value);
|
||||||
|
} else {
|
||||||
|
s = xstrdup(value);
|
||||||
|
}
|
||||||
|
char *es = strchr(s, '=');
|
||||||
|
if (!es) {
|
||||||
|
free(s);
|
||||||
|
cursor = ne_response_header_iterate(req, cursor, &name, &value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
char *es = strchr(start, '=');
|
char *cookie = s;
|
||||||
if (!es)
|
while (*cookie == ' ')
|
||||||
continue;
|
cookie++;
|
||||||
size_t nl = es - start;
|
while (*(cookie + strlen(cookie) - 1) == ' ')
|
||||||
size_t vl = end - es - 1;
|
*(cookie + strlen(cookie) - 1) = 0;
|
||||||
if (nl == 0 || vl == 0)
|
int nl = es - cookie;
|
||||||
continue;
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < n_cookies; i++) {
|
for (i = 0; i < n_cookies; i++) {
|
||||||
if (!cookie_list[i]) {
|
if (!cookie_list[i]) {
|
||||||
cookie_list[i] = xstrndup(start, end - start);
|
cookie_list[i] = xstrdup(cookie);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (strncmp(cookie_list[i], start, nl) == 0) {
|
if (strncmp(cookie_list[i], cookie, nl) == 0) {
|
||||||
if (strncmp(cookie_list[i] + nl + 1, es + 1, vl) != 0) {
|
free(cookie_list[i]);
|
||||||
free(cookie_list[i]);
|
cookie_list[i] = xstrdup(cookie);
|
||||||
cookie_list[i] = xstrndup(start, end - start);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(s);
|
||||||
|
cursor = ne_response_header_iterate(req, cursor, &name, &value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user