[vlc-commits] https: add non-TLS support to connection manager
Rémi Denis-Courmont
git at videolan.org
Sat Dec 19 13:06:49 CET 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Dec 19 13:49:26 2015 +0200| [9911e583e14b5fb7f000d5e74e616bb390bdab13] | committer: Rémi Denis-Courmont
https: add non-TLS support to connection manager
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9911e583e14b5fb7f000d5e74e616bb390bdab13
---
modules/access/http/access.c | 7 +++---
modules/access/http/connmgr.c | 53 ++++++++++++++++++++++++++++++++++++---
modules/access/http/connmgr.h | 8 +++---
modules/access/http/file.c | 4 +--
modules/access/http/file_test.c | 7 +++---
5 files changed, 62 insertions(+), 17 deletions(-)
diff --git a/modules/access/http/access.c b/modules/access/http/access.c
index c7d19a3..6ef5b09 100644
--- a/modules/access/http/access.c
+++ b/modules/access/http/access.c
@@ -130,7 +130,7 @@ static int Open(vlc_object_t *obj)
sys->manager = NULL;
sys->file = NULL;
- sys->manager = vlc_http_mgr_create(obj);
+ sys->manager = vlc_http_mgr_create(obj, var_InheritBool(obj, "http2"));
if (sys->manager == NULL)
goto error;
@@ -203,7 +203,6 @@ vlc_module_begin()
add_shortcut("https")
set_callbacks(Open, Close)
- // TODO: force HTTP/2 over TCP
- //add_bool("http2", false, N_("HTTP 2.0"),
- // N_("Negotiate HTTP version 2.0"), true)
+ add_bool("http2", false, N_("Force HTTP/2"),
+ N_("Force HTTP version 2.0 over TCP."), true)
vlc_module_end()
diff --git a/modules/access/http/connmgr.c b/modules/access/http/connmgr.c
index 318483e..f110057 100644
--- a/modules/access/http/connmgr.c
+++ b/modules/access/http/connmgr.c
@@ -135,6 +135,7 @@ struct vlc_http_mgr
vlc_object_t *obj;
vlc_tls_creds_t *creds;
struct vlc_http_conn *conn;
+ bool use_h2c;
};
static struct vlc_http_conn *vlc_http_mgr_find(struct vlc_http_mgr *mgr,
@@ -180,10 +181,13 @@ struct vlc_http_msg *vlc_http_mgr_reuse(struct vlc_http_mgr *mgr,
return NULL;
}
-struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
- const char *host, unsigned port,
- const struct vlc_http_msg *req)
+static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
+ const char *host, unsigned port,
+ const struct vlc_http_msg *req)
{
+ if (mgr->creds == NULL && mgr->conn != NULL)
+ return NULL; /* switch from HTTP to HTTPS not implemented */
+
if (mgr->creds == NULL)
{ /* First TLS connection: load x509 credentials */
mgr->creds = vlc_tls_ClientCreate(mgr->obj);
@@ -226,7 +230,47 @@ struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
return vlc_http_mgr_reuse(mgr, host, port, req);
}
-struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj)
+static struct vlc_http_msg *vlc_http_request(struct vlc_http_mgr *mgr,
+ const char *host, unsigned port,
+ const struct vlc_http_msg *req)
+{
+ if (mgr->creds != NULL && mgr->conn != NULL)
+ return NULL; /* switch from HTTPS to HTTP not implemented */
+
+ struct vlc_http_msg *resp = vlc_http_mgr_reuse(mgr, host, port, req);
+ if (resp != NULL)
+ return resp;
+
+ vlc_tls_t *tls = vlc_http_connect_i11e(mgr->obj, host, port);
+ if (tls == NULL)
+ return NULL;
+
+ struct vlc_http_conn *conn;
+
+ if (mgr->use_h2c)
+ conn = vlc_h2_conn_create(tls);
+ else
+ conn = vlc_h1_conn_create(tls);
+
+ if (unlikely(conn == NULL))
+ {
+ vlc_tls_Close(tls);
+ return NULL;
+ }
+
+ mgr->conn = conn;
+
+ return vlc_http_mgr_reuse(mgr, host, port, req);
+}
+
+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 *m)
+{
+ return (https ? vlc_https_request : vlc_http_request)(mgr, host, port, m);
+}
+
+struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj, bool h2c)
{
struct vlc_http_mgr *mgr = malloc(sizeof (*mgr));
if (unlikely(mgr == NULL))
@@ -235,6 +279,7 @@ struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj)
mgr->obj = obj;
mgr->creds = NULL;
mgr->conn = NULL;
+ mgr->use_h2c = h2c;
return mgr;
}
diff --git a/modules/access/http/connmgr.h b/modules/access/http/connmgr.h
index de9db2f..d84778e 100644
--- a/modules/access/http/connmgr.h
+++ b/modules/access/http/connmgr.h
@@ -21,9 +21,9 @@
struct vlc_http_mgr;
struct vlc_http_msg;
-struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
- const char *host, unsigned port,
- const struct vlc_http_msg *req);
+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);
-struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj);
+struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj, bool try_h2c);
void vlc_http_mgr_destroy(struct vlc_http_mgr *mgr);
diff --git a/modules/access/http/file.c b/modules/access/http/file.c
index ee25c4a..6a8a47b 100644
--- a/modules/access/http/file.c
+++ b/modules/access/http/file.c
@@ -121,8 +121,8 @@ static struct vlc_http_msg *vlc_http_file_open(struct vlc_http_file *file,
if (unlikely(req == NULL))
return NULL;
- struct vlc_http_msg *resp = vlc_https_request(file->manager, file->host,
- file->port, req);
+ struct vlc_http_msg *resp = vlc_http_mgr_request(file->manager, true,
+ file->host, file->port, req);
vlc_http_msg_destroy(req);
resp = vlc_http_msg_get_final(resp);
diff --git a/modules/access/http/file_test.c b/modules/access/http/file_test.c
index 713964c..40b83b0 100644
--- a/modules/access/http/file_test.c
+++ b/modules/access/http/file_test.c
@@ -232,13 +232,14 @@ static const struct vlc_http_stream_cbs stream_callbacks =
static struct vlc_http_stream stream = { &stream_callbacks };
-struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
- const char *host, unsigned port,
- const struct vlc_http_msg *req)
+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)
{
const char *str;
char *end;
+ assert(https);
assert(mgr == NULL);
assert(!strcmp(host, "www.example.com"));
assert(port == 8443);
More information about the vlc-commits
mailing list