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

https: add vlc_http_connect()

parent 5138d869
......@@ -84,6 +84,52 @@ static vlc_tls_t *vlc_https_connect_i11e(vlc_tls_creds_t *creds,
return res;
}
struct vlc_http_connecting
{
vlc_object_t *obj;
const char *host;
unsigned port;
vlc_sem_t done;
};
static void *vlc_http_connect_thread(void *data)
{
struct vlc_http_connecting *c = data;
vlc_tls_t *tls;
tls = vlc_http_connect(c->obj, c->host, c->port);
vlc_sem_post(&c->done);
return tls;
}
/** Interruptible vlc_http_connect() */
static vlc_tls_t *vlc_http_connect_i11e(vlc_object_t *obj,
const char *host, unsigned port)
{
struct vlc_http_connecting c;
vlc_thread_t th;
c.obj = obj;
c.host = host;
c.port = port;
vlc_sem_init(&c.done, 0);
if (vlc_clone(&th, vlc_http_connect_thread, &c, VLC_THREAD_PRIORITY_INPUT))
return NULL;
void *res;
if (vlc_sem_wait_i11e(&c.done))
vlc_cancel(th);
vlc_join(th, &res);
vlc_sem_destroy(&c.done);
if (res == VLC_THREAD_CANCELED)
res = NULL;
return res;
}
struct vlc_http_mgr
{
vlc_object_t *obj;
......
......@@ -96,25 +96,40 @@ static int vlc_tcp_connect(vlc_object_t *obj, const char *name, unsigned port)
vlc_cleanup_pop();
freeaddrinfo(res);
#ifndef _WIN32
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
#else
ioctlsocket(fd, FIONBIO, &(unsigned long){ 1 });
#endif
return fd;
}
vlc_tls_t *vlc_http_connect(vlc_object_t *obj, const char *name, unsigned port)
{
if (port == 0)
port = 80;
int fd = vlc_tcp_connect(obj, name, port);
if (fd == -1)
return NULL;
vlc_tls_t *tls = vlc_tls_DummyCreate(obj, fd);
if (tls == NULL)
net_Close(fd);
return tls;
}
vlc_tls_t *vlc_https_connect(vlc_tls_creds_t *creds, const char *name,
unsigned port, bool *restrict two)
{
if (port == 0)
port = 443;
int fd = vlc_tcp_connect(VLC_OBJECT(creds), name, port);
int fd = vlc_tcp_connect(creds->p_parent, name, port);
if (fd == -1)
return NULL;
#ifndef _WIN32
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
#else
ioctlsocket(fd, FIONBIO, &(unsigned long){ 1 });
#endif
/* TLS with ALPN */
const char *alpn[] = { "h2", "http/1.1", NULL };
char *alp;
......
......@@ -24,11 +24,14 @@
#include <stddef.h>
#include <stdbool.h>
struct vlc_object_t;
struct vlc_tls;
struct vlc_tls_creds;
struct vlc_tls *vlc_https_connect(struct vlc_tls_creds *creds,
const char *name, unsigned port,
bool *restrict two);
struct vlc_tls *vlc_http_connect(struct vlc_object_t *obj,
const char *name, unsigned port);
#endif
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