Commit 9911e583 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: add non-TLS support to connection manager

parent c8f672ff
...@@ -130,7 +130,7 @@ static int Open(vlc_object_t *obj) ...@@ -130,7 +130,7 @@ static int Open(vlc_object_t *obj)
sys->manager = NULL; sys->manager = NULL;
sys->file = 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) if (sys->manager == NULL)
goto error; goto error;
...@@ -203,7 +203,6 @@ vlc_module_begin() ...@@ -203,7 +203,6 @@ vlc_module_begin()
add_shortcut("https") add_shortcut("https")
set_callbacks(Open, Close) set_callbacks(Open, Close)
// TODO: force HTTP/2 over TCP add_bool("http2", false, N_("Force HTTP/2"),
//add_bool("http2", false, N_("HTTP 2.0"), N_("Force HTTP version 2.0 over TCP."), true)
// N_("Negotiate HTTP version 2.0"), true)
vlc_module_end() vlc_module_end()
...@@ -135,6 +135,7 @@ struct vlc_http_mgr ...@@ -135,6 +135,7 @@ struct vlc_http_mgr
vlc_object_t *obj; vlc_object_t *obj;
vlc_tls_creds_t *creds; vlc_tls_creds_t *creds;
struct vlc_http_conn *conn; struct vlc_http_conn *conn;
bool use_h2c;
}; };
static struct vlc_http_conn *vlc_http_mgr_find(struct vlc_http_mgr *mgr, 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, ...@@ -180,10 +181,13 @@ struct vlc_http_msg *vlc_http_mgr_reuse(struct vlc_http_mgr *mgr,
return NULL; return NULL;
} }
struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr, static struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
const char *host, unsigned port, const char *host, unsigned port,
const struct vlc_http_msg *req) 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) if (mgr->creds == NULL)
{ /* First TLS connection: load x509 credentials */ { /* First TLS connection: load x509 credentials */
mgr->creds = vlc_tls_ClientCreate(mgr->obj); mgr->creds = vlc_tls_ClientCreate(mgr->obj);
...@@ -226,7 +230,47 @@ struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr, ...@@ -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); 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)); struct vlc_http_mgr *mgr = malloc(sizeof (*mgr));
if (unlikely(mgr == NULL)) if (unlikely(mgr == NULL))
...@@ -235,6 +279,7 @@ struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj) ...@@ -235,6 +279,7 @@ struct vlc_http_mgr *vlc_http_mgr_create(vlc_object_t *obj)
mgr->obj = obj; mgr->obj = obj;
mgr->creds = NULL; mgr->creds = NULL;
mgr->conn = NULL; mgr->conn = NULL;
mgr->use_h2c = h2c;
return mgr; return mgr;
} }
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
struct vlc_http_mgr; struct vlc_http_mgr;
struct vlc_http_msg; struct vlc_http_msg;
struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr, 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);
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); void vlc_http_mgr_destroy(struct vlc_http_mgr *mgr);
...@@ -121,8 +121,8 @@ static struct vlc_http_msg *vlc_http_file_open(struct vlc_http_file *file, ...@@ -121,8 +121,8 @@ static struct vlc_http_msg *vlc_http_file_open(struct vlc_http_file *file,
if (unlikely(req == NULL)) if (unlikely(req == NULL))
return NULL; return NULL;
struct vlc_http_msg *resp = vlc_https_request(file->manager, file->host, struct vlc_http_msg *resp = vlc_http_mgr_request(file->manager, true,
file->port, req); file->host, file->port, req);
vlc_http_msg_destroy(req); vlc_http_msg_destroy(req);
resp = vlc_http_msg_get_final(resp); resp = vlc_http_msg_get_final(resp);
......
...@@ -232,13 +232,14 @@ static const struct vlc_http_stream_cbs stream_callbacks = ...@@ -232,13 +232,14 @@ static const struct vlc_http_stream_cbs stream_callbacks =
static struct vlc_http_stream stream = { &stream_callbacks }; static struct vlc_http_stream stream = { &stream_callbacks };
struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr, 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)
{ {
const char *str; const char *str;
char *end; char *end;
assert(https);
assert(mgr == NULL); assert(mgr == NULL);
assert(!strcmp(host, "www.example.com")); assert(!strcmp(host, "www.example.com"));
assert(port == 8443); assert(port == 8443);
......
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