[vlc-commits] https: revector cookie handling

Rémi Denis-Courmont git at videolan.org
Thu Jan 7 19:22:34 CET 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jan  7 20:22:01 2016 +0200| [4522316a813429fafee861f0ed1c3fe258785b86] | committer: Rémi Denis-Courmont

https: revector cookie handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4522316a813429fafee861f0ed1c3fe258785b86
---

 modules/access/http/connmgr.c   |   13 ++-----------
 modules/access/http/connmgr.h   |    5 +----
 modules/access/http/file_test.c |   16 ++--------------
 modules/access/http/message.c   |    6 ++++++
 modules/access/http/resource.c  |    6 +++---
 5 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/modules/access/http/connmgr.c b/modules/access/http/connmgr.c
index 704c5d4..b7a3808 100644
--- a/modules/access/http/connmgr.c
+++ b/modules/access/http/connmgr.c
@@ -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,
diff --git a/modules/access/http/connmgr.h b/modules/access/http/connmgr.h
index 32b67ff..a0d7e3c 100644
--- a/modules/access/http/connmgr.h
+++ b/modules/access/http/connmgr.h
@@ -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
diff --git a/modules/access/http/file_test.c b/modules/access/http/file_test.c
index 489ddb2..977eddd 100644
--- a/modules/access/http/file_test.c
+++ b/modules/access/http/file_test.c
@@ -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;
 }
diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index fb7a866..7bea981 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -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
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index 858e989..e3a4e06 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -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)



More information about the vlc-commits mailing list