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, ...@@ -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); 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_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *mgr)
struct vlc_http_msg *req)
{ {
return mgr->jar != NULL ? vlc_http_msg_add_cookies(req, mgr->jar) : 0; return mgr->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)
{
if (mgr->jar != NULL)
vlc_http_msg_get_cookies(resp, mgr->jar, https, host, path);
} }
struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj, 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, ...@@ -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 char *host, unsigned port,
const struct vlc_http_msg *req); const struct vlc_http_msg *req);
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *, struct vlc_http_msg *); struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *);
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);
/** /**
* Creates an HTTP connection manager * Creates an HTTP connection manager
......
...@@ -326,20 +326,8 @@ struct vlc_http_msg *vlc_http_mgr_request(struct vlc_http_mgr *mgr, bool https, ...@@ -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); return vlc_http_msg_get_initial(&stream);
} }
int vlc_http_mgr_send_cookies(struct vlc_http_mgr *mgr, struct vlc_http_cookie_jar_t *vlc_http_mgr_get_jar(struct vlc_http_mgr *mgr)
struct vlc_http_msg *req)
{ {
assert(mgr == NULL); assert(mgr == NULL);
return vlc_http_msg_add_cookies(req, jar); return 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);
} }
...@@ -853,6 +853,9 @@ void vlc_http_msg_get_cookies(const struct vlc_http_msg *m, ...@@ -853,6 +853,9 @@ void vlc_http_msg_get_cookies(const struct vlc_http_msg *m,
vlc_http_cookie_jar_t *jar, bool secure, vlc_http_cookie_jar_t *jar, bool secure,
const char *host, const char *path) const char *host, const char *path)
{ {
if (jar == NULL)
return;
for (unsigned i = 0; i < m->count; i++) for (unsigned i = 0; i < m->count; i++)
if (!strcasecmp(m->headers[i][0], "Set-Cookie")) if (!strcasecmp(m->headers[i][0], "Set-Cookie"))
vlc_http_cookies_store(jar, m->headers[i][1], secure, host, path); 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, ...@@ -878,6 +881,9 @@ int vlc_http_msg_add_cookies(struct vlc_http_msg *m,
else else
return 0; return 0;
if (jar == NULL)
return 0;
if (m->authority[0] == '[') if (m->authority[0] == '[')
host = strndup(m->authority + 1, strcspn(m->authority + 1, "]")); host = strndup(m->authority + 1, strcspn(m->authority + 1, "]"));
else else
......
...@@ -64,7 +64,7 @@ vlc_http_res_req(const struct vlc_http_resource *res) ...@@ -64,7 +64,7 @@ vlc_http_res_req(const struct vlc_http_resource *res)
if (res->referrer != NULL) /* TODO: validate URL */ if (res->referrer != NULL) /* TODO: validate URL */
vlc_http_msg_add_header(req, "Referer", "%s", res->referrer); 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"); */ /* 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, ...@@ -93,8 +93,8 @@ struct vlc_http_msg *vlc_http_res_open(struct vlc_http_resource *res,
if (resp == NULL) if (resp == NULL)
return NULL; return NULL;
vlc_http_mgr_recv_cookies(res->manager, res->secure, res->host, res->path, vlc_http_msg_get_cookies(resp, vlc_http_mgr_get_jar(res->manager),
resp); res->secure, res->host, res->path);
int status = vlc_http_msg_get_status(resp); int status = vlc_http_msg_get_status(resp);
if (status < 200 || status >= 599) 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