Commit 072e04e9 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

https: insecure HTTP support for file download layer

parent 9911e583
...@@ -195,12 +195,12 @@ static void Close(vlc_object_t *obj) ...@@ -195,12 +195,12 @@ static void Close(vlc_object_t *obj)
} }
vlc_module_begin() vlc_module_begin()
set_description(N_("HTTP/TLS input")) set_description(N_("HTTPS input"))
set_shortname(N_("HTTPS")) set_shortname(N_("HTTPS"))
set_category(CAT_INPUT) set_category(CAT_INPUT)
set_subcategory(SUBCAT_INPUT_ACCESS) set_subcategory(SUBCAT_INPUT_ACCESS)
set_capability("access", 2) set_capability("access", 2)
add_shortcut("https") add_shortcut("https", "http")
set_callbacks(Open, Close) set_callbacks(Open, Close)
add_bool("http2", false, N_("Force HTTP/2"), add_bool("http2", false, N_("Force HTTP/2"),
......
...@@ -46,6 +46,7 @@ struct vlc_http_file ...@@ -46,6 +46,7 @@ struct vlc_http_file
struct vlc_http_msg *resp; struct vlc_http_msg *resp;
char *host; char *host;
unsigned port; unsigned port;
bool secure;
char *authority; char *authority;
char *path; char *path;
char *agent; char *agent;
...@@ -60,7 +61,8 @@ static struct vlc_http_msg *vlc_http_file_req(const struct vlc_http_file *file, ...@@ -60,7 +61,8 @@ static struct vlc_http_msg *vlc_http_file_req(const struct vlc_http_file *file,
struct vlc_http_msg *req; struct vlc_http_msg *req;
const char *str; const char *str;
req = vlc_http_req_create("GET", "https", file->authority, file->path); req = vlc_http_req_create("GET", file->secure ? "https" : "http",
file->authority, file->path);
if (unlikely(req == NULL)) if (unlikely(req == NULL))
return NULL; return NULL;
...@@ -121,8 +123,8 @@ static struct vlc_http_msg *vlc_http_file_open(struct vlc_http_file *file, ...@@ -121,8 +123,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_http_mgr_request(file->manager, true, struct vlc_http_msg *resp = vlc_http_mgr_request(file->manager,
file->host, file->port, req); file->secure, 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);
...@@ -189,23 +191,24 @@ struct vlc_http_file *vlc_http_file_create(struct vlc_http_mgr *mgr, ...@@ -189,23 +191,24 @@ struct vlc_http_file *vlc_http_file_create(struct vlc_http_mgr *mgr,
const char *ref) const char *ref)
{ {
vlc_url_t url; vlc_url_t url;
bool secure;
vlc_UrlParse(&url, uri); vlc_UrlParse(&url, uri);
if (url.psz_protocol == NULL if (url.psz_protocol == NULL || url.psz_host == NULL)
|| vlc_ascii_strcasecmp(url.psz_protocol, "https") goto error;
|| url.psz_host == NULL)
{ if (!vlc_ascii_strcasecmp(url.psz_protocol, "https"))
vlc_UrlClean(&url); secure = true;
return NULL; else if (!vlc_ascii_strcasecmp(url.psz_protocol, "http"))
} secure = false;
else
goto error;
struct vlc_http_file *file = malloc(sizeof (*file)); struct vlc_http_file *file = malloc(sizeof (*file));
if (unlikely(file == NULL)) if (unlikely(file == NULL))
{ goto error;
vlc_UrlClean(&url);
return NULL;
}
file->secure = secure;
file->host = strdup(url.psz_host); file->host = strdup(url.psz_host);
file->port = url.i_port; file->port = url.i_port;
file->authority = vlc_http_authority(url.psz_host, url.i_port); file->authority = vlc_http_authority(url.psz_host, url.i_port);
...@@ -236,6 +239,9 @@ struct vlc_http_file *vlc_http_file_create(struct vlc_http_mgr *mgr, ...@@ -236,6 +239,9 @@ struct vlc_http_file *vlc_http_file_create(struct vlc_http_mgr *mgr,
file = NULL; file = NULL;
} }
return file; return file;
error:
vlc_UrlClean(&url);
return NULL;
} }
int vlc_http_file_get_status(struct vlc_http_file *file) int vlc_http_file_get_status(struct vlc_http_file *file)
...@@ -278,7 +284,8 @@ char *vlc_http_file_get_redirect(struct vlc_http_file *file) ...@@ -278,7 +284,8 @@ char *vlc_http_file_get_redirect(struct vlc_http_file *file)
{ {
char *url; char *url;
if (unlikely(asprintf(&url, "https://%s%.*s", file->authority, if (unlikely(asprintf(&url, "%s://%s%.*s",
file->secure ? "https" : "http", file->authority,
(int)len, location)) < 0) (int)len, location)) < 0)
return NULL; return NULL;
return url; return url;
......
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