static int http_open_cnx(URLContext *h)

{

    const char *path, *proxy_path, *lower_proto = "tcp", *local_path;

    char hostname[1024], hoststr[1024], proto[10];

    char auth[1024], proxyauth[1024];

    char path1[1024];

    char buf[1024], urlbuf[1024];

    int port, use_proxy, err, location_changed = 0, redirects = 0;

    HTTPAuthType cur_auth_type, cur_proxy_auth_type;

    HTTPContext *s = h->priv_data;

    URLContext *hd = NULL;



    proxy_path = getenv("http_proxy");

    use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&

        av_strstart(proxy_path, "http://", NULL);



    /* fill the dest addr */

 redo:

    /* needed in any case to build the host string */

    av_url_split(proto, sizeof(proto), auth, sizeof(auth),

                 hostname, sizeof(hostname), &port,

                 path1, sizeof(path1), s->location);

    ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);



    if (!strcmp(proto, "https")) {

        lower_proto = "tls";

        use_proxy = 0;

        if (port < 0)

            port = 443;

    }

    if (port < 0)

        port = 80;



    if (path1[0] == '\0')

        path = "/";

    else

        path = path1;

    local_path = path;

    if (use_proxy) {

        /* Reassemble the request URL without auth string - we don't

         * want to leak the auth to the proxy. */

        ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s",

                    path1);

        path = urlbuf;

        av_url_split(NULL, 0, proxyauth, sizeof(proxyauth),

                     hostname, sizeof(hostname), &port, NULL, 0, proxy_path);

    }



    ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);

    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE,

                     &h->interrupt_callback, NULL);

    if (err < 0)

        goto fail;



    s->hd = hd;

    cur_auth_type = s->auth_state.auth_type;

    cur_proxy_auth_type = s->auth_state.auth_type;

    if (http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0)

        goto fail;

    if (s->http_code == 401) {

        if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {

            ffurl_close(hd);

            goto redo;

        } else

            goto fail;

    }

    if (s->http_code == 407) {

        if (cur_proxy_auth_type == HTTP_AUTH_NONE &&

            s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {

            ffurl_close(hd);

            goto redo;

        } else

            goto fail;

    }

    if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)

        && location_changed == 1) {

        /* url moved, get next */

        ffurl_close(hd);

        if (redirects++ >= MAX_REDIRECTS)

            return AVERROR(EIO);

        location_changed = 0;

        goto redo;

    }

    return 0;

 fail:

    if (hd)

        ffurl_close(hd);

    s->hd = NULL;

    return AVERROR(EIO);

}

static int http_open_cnx(URLContext *h)

{

    const char *path, *proxy_path, *lower_proto = "tcp", *local_path;

    char hostname[1024], hoststr[1024], proto[10];

    char auth[1024], proxyauth[1024];

    char path1[1024];

    char buf[1024], urlbuf[1024];

    int port, use_proxy, err, location_changed = 0, redirects = 0;

    HTTPAuthType cur_auth_type, cur_proxy_auth_type;

    HTTPContext *s = h->priv_data;

    URLContext *hd = NULL;



    proxy_path = getenv("http_proxy");

    use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&

        av_strstart(proxy_path, "http:



    

 redo:

    

    av_url_split(proto, sizeof(proto), auth, sizeof(auth),

                 hostname, sizeof(hostname), &port,

                 path1, sizeof(path1), s->location);

    ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);



    if (!strcmp(proto, "https")) {

        lower_proto = "tls";

        use_proxy = 0;

        if (port < 0)

            port = 443;

    }

    if (port < 0)

        port = 80;



    if (path1[0] == '\0')

        path = "/";

    else

        path = path1;

    local_path = path;

    if (use_proxy) {

        



        ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s",

                    path1);

        path = urlbuf;

        av_url_split(NULL, 0, proxyauth, sizeof(proxyauth),

                     hostname, sizeof(hostname), &port, NULL, 0, proxy_path);

    }



    ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL);

    err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE,

                     &h->interrupt_callback, NULL);

    if (err < 0)

        goto fail;



    s->hd = hd;

    cur_auth_type = s->auth_state.auth_type;

    cur_proxy_auth_type = s->auth_state.auth_type;

    if (http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0)

        goto fail;

    if (s->http_code == 401) {

        if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {

            ffurl_close(hd);

            goto redo;

        } else

            goto fail;

    }

    if (s->http_code == 407) {

        if (cur_proxy_auth_type == HTTP_AUTH_NONE &&

            s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {

            ffurl_close(hd);

            goto redo;

        } else

            goto fail;

    }

    if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)

        && location_changed == 1) {

        

        ffurl_close(hd);

        if (redirects++ >= MAX_REDIRECTS)

            return AVERROR(EIO);

        location_changed = 0;

        goto redo;

    }

    return 0;

 fail:

    if (hd)

        ffurl_close(hd);

    s->hd = NULL;

    return AVERROR(EIO);

}

    char auth[1024], proxyauth[1024];
static int FUNC_0(URLContext *VAR_0)

{

    const char *VAR_1, *VAR_2, *VAR_3 = "tcp", *VAR_4;

    char VAR_5[1024], VAR_6[1024], VAR_7[10];

    char VAR_8[1024], VAR_9[1024];

    char VAR_10[1024];

    char VAR_11[1024], VAR_12[1024];

    int VAR_13, VAR_14, VAR_15, VAR_16 = 0, VAR_17 = 0;

    HTTPAuthType cur_auth_type, cur_proxy_auth_type;

    HTTPContext *s = VAR_0->priv_data;

    URLContext *hd = NULL;



    VAR_2 = getenv("http_proxy");

    VAR_14 = (VAR_2 != NULL) && !getenv("no_proxy") &&

        av_strstart(VAR_2, "http:



    

 redo:

    

    av_url_split(VAR_7, sizeof(VAR_7), VAR_8, sizeof(VAR_8),

                 VAR_5, sizeof(VAR_5), &VAR_13,

                 VAR_10, sizeof(VAR_10), s->location);

    ff_url_join(VAR_6, sizeof(VAR_6), NULL, NULL, VAR_5, VAR_13, NULL);



    if (!strcmp(VAR_7, "https")) {

        VAR_3 = "tls";

        VAR_14 = 0;

        if (VAR_13 < 0)

            VAR_13 = 443;

    }

    if (VAR_13 < 0)

        VAR_13 = 80;



    if (VAR_10[0] == '\0')

        VAR_1 = "/";

    else

        VAR_1 = VAR_10;

    VAR_4 = VAR_1;

    if (VAR_14) {

        



        ff_url_join(VAR_12, sizeof(VAR_12), VAR_7, NULL, VAR_5, VAR_13, "%s",

                    VAR_10);

        VAR_1 = VAR_12;

        av_url_split(NULL, 0, VAR_9, sizeof(VAR_9),

                     VAR_5, sizeof(VAR_5), &VAR_13, NULL, 0, VAR_2);

    }



    ff_url_join(VAR_11, sizeof(VAR_11), VAR_3, NULL, VAR_5, VAR_13, NULL);

    VAR_15 = ffurl_open(&hd, VAR_11, AVIO_FLAG_READ_WRITE,

                     &VAR_0->interrupt_callback, NULL);

    if (VAR_15 < 0)

        goto fail;



    s->hd = hd;

    cur_auth_type = s->auth_state.auth_type;

    cur_proxy_auth_type = s->auth_state.auth_type;

    if (http_connect(VAR_0, VAR_1, VAR_4, VAR_6, VAR_8, VAR_9, &VAR_16) < 0)

        goto fail;

    if (s->http_code == 401) {

        if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {

            ffurl_close(hd);

            goto redo;

        } else

            goto fail;

    }

    if (s->http_code == 407) {

        if (cur_proxy_auth_type == HTTP_AUTH_NONE &&

            s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {

            ffurl_close(hd);

            goto redo;

        } else

            goto fail;

    }

    if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)

        && VAR_16 == 1) {

        

        ffurl_close(hd);

        if (VAR_17++ >= MAX_REDIRECTS)

            return AVERROR(EIO);

        VAR_16 = 0;

        goto redo;

    }

    return 0;

 fail:

    if (hd)

        ffurl_close(hd);

    s->hd = NULL;

    return AVERROR(EIO);

}

static int FUNC_0(URLContext *VAR_0)
{ const char *VAR_1, *VAR_2, *VAR_3 = "tcp", *VAR_4; char VAR_5[1024], VAR_6[1024], VAR_7[10]; char VAR_8[1024], VAR_9[1024]; char VAR_10[1024]; char VAR_11[1024], VAR_12[1024]; int VAR_13, VAR_14, VAR_15, VAR_16 = 0, VAR_17 = 0; HTTPAuthType cur_auth_type, cur_proxy_auth_type; HTTPContext *s = VAR_0->priv_data; URLContext *hd = NULL; VAR_2 = getenv("http_proxy"); VAR_14 = (VAR_2 != NULL) && !getenv("no_proxy") &&
av_strstart(VAR_2, "http:
redo:
av_url_split(VAR_7, sizeof(VAR_7), VAR_8, sizeof(VAR_8),
VAR_5, sizeof(VAR_5), &VAR_13,
VAR_10, sizeof(VAR_10), s->location); ff_url_join(VAR_6, sizeof(VAR_6), NULL, NULL, VAR_5, VAR_13, NULL); if (!strcmp(VAR_7, "https")) { VAR_3 = "tls"; VAR_14 = 0; if (VAR_13 < 0)
VAR_13 = 443; } if (VAR_13 < 0)
VAR_13 = 80; if (VAR_10[0] == '\0')
VAR_1 = "/"; else
VAR_1 = VAR_10; VAR_4 = VAR_1; if (VAR_14) { ff_url_join(VAR_12, sizeof(VAR_12), VAR_7, NULL, VAR_5, VAR_13, "%s",
VAR_10); VAR_1 = VAR_12; av_url_split(NULL, 0, VAR_9, sizeof(VAR_9),
VAR_5, sizeof(VAR_5), &VAR_13, NULL, 0, VAR_2); } ff_url_join(VAR_11, sizeof(VAR_11), VAR_3, NULL, VAR_5, VAR_13, NULL); VAR_15 = ffurl_open(&hd, VAR_11, AVIO_FLAG_READ_WRITE,
&VAR_0->interrupt_callback, NULL); if (VAR_15 < 0)
goto fail; s->hd = hd; cur_auth_type = s->auth_state.auth_type; cur_proxy_auth_type = s->auth_state.auth_type; if (http_connect(VAR_0, VAR_1, VAR_4, VAR_6, VAR_8, VAR_9, &VAR_16) < 0)
goto fail; if (s->http_code == 401) { if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) { ffurl_close(hd); goto redo; } else goto fail; } if (s->http_code == 407) { if (cur_proxy_auth_type == HTTP_AUTH_NONE &&
s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) { ffurl_close(hd); goto redo; } else goto fail; } if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307)
&& VAR_16 == 1) { ffurl_close(hd); if (VAR_17++ >= MAX_REDIRECTS)
return AVERROR(EIO); VAR_16 = 0; goto redo; } return 0; fail:
if (hd)
ffurl_close(hd); s->hd = NULL; return AVERROR(EIO); }