Example #1
0
static void *vlc_https_connect_thread(void *data)
{
    struct vlc_https_connecting *c = data;
    vlc_tls_t *tls;

    char *proxy = vlc_https_proxy_find(c->host, c->port);
    if (proxy != NULL)
    {
        tls = vlc_https_connect_proxy(c->creds, c->host, c->port, &c->http2,
                                      proxy);
        free(proxy);
    }
    else
        tls = vlc_https_connect(c->creds, c->host, c->port, &c->http2);
    vlc_sem_post(&c->done);
    return tls;
}
Example #2
0
static int server_socket(unsigned *port)
{
    int fd = socket(PF_INET6, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP);
    if (fd == -1)
        return -1;

    struct sockaddr_in6 addr = {
        .sin6_family = AF_INET6,
#ifdef HAVE_SA_LEN
        .sin6_len = sizeof (addr),
#endif
        .sin6_addr = in6addr_loopback,
    };
    socklen_t addrlen = sizeof (addr);

    if (bind(fd, (struct sockaddr *)&addr, addrlen)
     || getsockname(fd, (struct sockaddr *)&addr, &addrlen))
    {
        close(fd);
        return -1;
    }

    *port = ntohs(addr.sin6_port);
    return fd;
}

int main(void)
{
    char *url;
    unsigned port;
    bool two = false;

    /* Test bad URLs */
    vlc_https_connect_proxy(NULL, "www.example.com", 0, &two,
                            "/test");
    vlc_https_connect_proxy(NULL, "www.example.com", 0, &two,
                            "ftp://proxy.example.com/");

    int lfd = server_socket(&port);
    if (lfd == -1)
        return 77;

    if (asprintf(&url, "http://[::1]:%u", port) < 0)
        url = NULL;

    assert(url != NULL);

    /* Test connection failure */
    vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);

    if (listen(lfd, 255))
    {
        close(lfd);
        return 77;
    }

    vlc_thread_t th;
    if (vlc_clone(&th, proxy_thread, (void*)(intptr_t)lfd,
                  VLC_THREAD_PRIORITY_LOW))
        assert(!"Thread error");

    /* Test proxy error */
    vlc_https_connect_proxy(NULL, "www.example.com", 0, &two, url);

    vlc_cancel(th);
    vlc_join(th, NULL);
    assert(connection_count > 0);
    free(url);
    close(lfd);
}