Commit 4522316a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: revector cookie handling

parent a79cc76f
......@@ -299,18 +299,9 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
return (https ? vlc_https_request : vlc_http_request)(mgr, host, port, m);
}
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *mgr,
struct vlc_http_msg *req)
struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *mgr)
{
return mgr->jar != NULL ? vlc_http_msg_add_cookies(req, mgr->jar) : 0;
}
void vlc_http_mgr_recv_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
const struct vlc_http_msg *resp)
{
if (mgr->jar != NULL)
vlc_http_msg_get_cookies(resp, mgr->jar, https, host, path);
return mgr->jar;
}
struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj,
......
......@@ -51,10 +51,7 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
const char *host, unsigned port,
const struct vlc_http_msg *req);
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *, struct vlc_http_msg *);
void vlc_http_mgr_recv_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
const struct vlc_http_msg *resp);
struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *);
/**
* Creates an HTTP connection manager
......
......@@ -326,20 +326,8 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https,
return vlc_http_msg_get_initial(&stream);
}
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *mgr,
struct vlc_http_msg *req)
struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *mgr)
{
assert(mgr == NULL);
return vlc_http_msg_add_cookies(req, jar);
}
void vlc_http_mgr_recv_cookies(struct vlc_http_mgr *mgr, bool https,
const char *host, const char *path,
const struct vlc_http_msg *resp)
{
assert(mgr == NULL);
assert(https);
assert(!strcmp(host, "www.example.com"));
assert(!strcmp(path, "/dir/file.ext?a=b"));
vlc_http_msg_get_cookies(resp, jar, https, host, path);
return jar;
}
......@@ -853,6 +853,9 @@ void vlc_http_msg_get_cookies(const struct vlc_http_msg *m,
vlc_http_cookie_jar_t *jar, bool secure,
const char *host, const char *path)
{
if (jar == NULL)
return;
for (unsigned i = 0; i < m->count; i++)
if (!strcasecmp(m->headers[i][0], "Set-Cookie"))
vlc_http_cookies_store(jar, m->headers[i][1], secure, host, path);
......@@ -878,6 +881,9 @@ int vlc_http_msg_add_cookies(struct vlc_http_msg *m,
else
return 0;
if (jar == NULL)
return 0;
if (m->authority[0] == '[')
host = strndup(m->authority + 1, strcspn(m->authority + 1, "]"));
else
......
......@@ -64,7 +64,7 @@ vlc_http_res_req(const struct vlc_http_resource *res)
if (res->referrer != NULL) /* TODO: validate URL */
vlc_http_msg_add_header(req, "Referer", "%s", res->referrer);
vlc_http_mgr_send_cookies(res->manager, req);
vlc_http_msg_add_cookies(req, vlc_http_mgr_get_jar(res->manager));
/* TODO: vlc_http_msg_add_header(req, "TE", "gzip, deflate"); */
......@@ -93,8 +93,8 @@ struct vlc_http_msg *vlc_http_res_open(struct vlc_http_resource *res,
if (resp == NULL)
return NULL;
vlc_http_mgr_recv_cookies(res->manager, res->secure, res->host, res->path,
resp);
vlc_http_msg_get_cookies(resp, vlc_http_mgr_get_jar(res->manager),
res->secure, res->host, res->path);
int status = vlc_http_msg_get_status(resp);
if (status < 200 || status >= 599)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment