static int http_proxy_open(URLContext *h, const char *uri, int flags)

{

    HTTPContext *s = h->priv_data;

    char hostname[1024], hoststr[1024];

    char auth[1024], pathbuf[1024], *path;

    char line[1024], lower_url[100];

    int port, ret = 0;

    HTTPAuthType cur_auth_type;

    char *authstr;



    h->is_streamed = 1;



    av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,

                 pathbuf, sizeof(pathbuf), uri);

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

    path = pathbuf;

    if (*path == '/')

        path++;



    ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,

                NULL);

redo:

    ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,

                     &h->interrupt_callback, NULL);

    if (ret < 0)

        return ret;



    authstr = ff_http_auth_create_response(&s->proxy_auth_state, auth,

                                           path, "CONNECT");

    snprintf(s->buffer, sizeof(s->buffer),

             "CONNECT %s HTTP/1.1\r\n"

             "Host: %s\r\n"

             "Connection: close\r\n"

             "%s%s"

             "\r\n",

             path,

             hoststr,

             authstr ? "Proxy-" : "", authstr ? authstr : "");

    av_freep(&authstr);



    if ((ret = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)

        goto fail;



    s->buf_ptr = s->buffer;

    s->buf_end = s->buffer;

    s->line_count = 0;

    s->filesize = -1;

    cur_auth_type = s->proxy_auth_state.auth_type;



    for (;;) {

        int new_loc;

        // Note: This uses buffering, potentially reading more than the

        // HTTP header. If tunneling a protocol where the server starts

        // the conversation, we might buffer part of that here, too.

        // Reading that requires using the proper ffurl_read() function

        // on this URLContext, not using the fd directly (as the tls

        // protocol does). This shouldn't be an issue for tls though,

        // since the client starts the conversation there, so there

        // is no extra data that we might buffer up here.

        if (http_get_line(s, line, sizeof(line)) < 0) {

            ret = AVERROR(EIO);

            goto fail;

        }



        av_dlog(h, "header='%s'\n", line);



        ret = process_line(h, line, s->line_count, &new_loc);

        if (ret < 0)

            goto fail;

        if (ret == 0)

            break;

        s->line_count++;

    }

    if (s->http_code == 407 && cur_auth_type == HTTP_AUTH_NONE &&

        s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {

        ffurl_close(s->hd);

        s->hd = NULL;

        goto redo;

    }



    if (s->http_code < 400)

        return 0;

    ret = AVERROR(EIO);



fail:

    http_proxy_close(h);

    return ret;

}

static int http_proxy_open(URLContext *h, const char *uri, int flags)

{

    HTTPContext *s = h->priv_data;

    char hostname[1024], hoststr[1024];

    char auth[1024], pathbuf[1024], *path;

    char line[1024], lower_url[100];

    int port, ret = 0;

    HTTPAuthType cur_auth_type;

    char *authstr;



    h->is_streamed = 1;



    av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,

                 pathbuf, sizeof(pathbuf), uri);

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

    path = pathbuf;

    if (*path == '/')

        path++;



    ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port,

                NULL);

redo:

    ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE,

                     &h->interrupt_callback, NULL);

    if (ret < 0)

        return ret;



    authstr = ff_http_auth_create_response(&s->proxy_auth_state, auth,

                                           path, "CONNECT");

    snprintf(s->buffer, sizeof(s->buffer),

             "CONNECT %s HTTP/1.1\r\n"

             "Host: %s\r\n"

             "Connection: close\r\n"

             "%s%s"

             "\r\n",

             path,

             hoststr,

             authstr ? "Proxy-" : "", authstr ? authstr : "");

    av_freep(&authstr);



    if ((ret = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)

        goto fail;



    s->buf_ptr = s->buffer;

    s->buf_end = s->buffer;

    s->line_count = 0;

    s->filesize = -1;

    cur_auth_type = s->proxy_auth_state.auth_type;



    for (;;) {

        int new_loc;

        

        

        

        

        

        

        

        

        if (http_get_line(s, line, sizeof(line)) < 0) {

            ret = AVERROR(EIO);

            goto fail;

        }



        av_dlog(h, "header='%s'\n", line);



        ret = process_line(h, line, s->line_count, &new_loc);

        if (ret < 0)

            goto fail;

        if (ret == 0)

            break;

        s->line_count++;

    }

    if (s->http_code == 407 && cur_auth_type == HTTP_AUTH_NONE &&

        s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {

        ffurl_close(s->hd);

        s->hd = NULL;

        goto redo;

    }



    if (s->http_code < 400)

        return 0;

    ret = AVERROR(EIO);



fail:

    http_proxy_close(h);

    return ret;

}

    int port, ret = 0;     if (s->http_code == 407 && cur_auth_type == HTTP_AUTH_NONE &&         s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {
static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)

{

    HTTPContext *s = VAR_0->priv_data;

    char VAR_3[1024], VAR_4[1024];

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

    char VAR_8[1024], VAR_9[100];

    int VAR_10, VAR_11 = 0;

    HTTPAuthType cur_auth_type;

    char *VAR_12;



    VAR_0->is_streamed = 1;



    av_url_split(NULL, 0, VAR_5, sizeof(VAR_5), VAR_3, sizeof(VAR_3), &VAR_10,

                 VAR_6, sizeof(VAR_6), VAR_1);

    ff_url_join(VAR_4, sizeof(VAR_4), NULL, NULL, VAR_3, VAR_10, NULL);

    VAR_7 = VAR_6;

    if (*VAR_7 == '/')

        VAR_7++;



    ff_url_join(VAR_9, sizeof(VAR_9), "tcp", NULL, VAR_3, VAR_10,

                NULL);

redo:

    VAR_11 = ffurl_open(&s->hd, VAR_9, AVIO_FLAG_READ_WRITE,

                     &VAR_0->interrupt_callback, NULL);

    if (VAR_11 < 0)

        return VAR_11;



    VAR_12 = ff_http_auth_create_response(&s->proxy_auth_state, VAR_5,

                                           VAR_7, "CONNECT");

    snprintf(s->buffer, sizeof(s->buffer),

             "CONNECT %s HTTP/1.1\r\n"

             "Host: %s\r\n"

             "Connection: close\r\n"

             "%s%s"

             "\r\n",

             VAR_7,

             VAR_4,

             VAR_12 ? "Proxy-" : "", VAR_12 ? VAR_12 : "");

    av_freep(&VAR_12);



    if ((VAR_11 = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)

        goto fail;



    s->buf_ptr = s->buffer;

    s->buf_end = s->buffer;

    s->line_count = 0;

    s->filesize = -1;

    cur_auth_type = s->proxy_auth_state.auth_type;



    for (;;) {

        int VAR_13;

        

        

        

        

        

        

        

        

        if (http_get_line(s, VAR_8, sizeof(VAR_8)) < 0) {

            VAR_11 = AVERROR(EIO);

            goto fail;

        }



        av_dlog(VAR_0, "header='%s'\n", VAR_8);



        VAR_11 = process_line(VAR_0, VAR_8, s->line_count, &VAR_13);

        if (VAR_11 < 0)

            goto fail;

        if (VAR_11 == 0)

            break;

        s->line_count++;

    }

    if (s->http_code == 407 && cur_auth_type == HTTP_AUTH_NONE &&

        s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) {

        ffurl_close(s->hd);

        s->hd = NULL;

        goto redo;

    }



    if (s->http_code < 400)

        return 0;

    VAR_11 = AVERROR(EIO);



fail:

    http_proxy_close(VAR_0);

    return VAR_11;

}

static int FUNC_0(URLContext *VAR_0, const char *VAR_1, int VAR_2)
{ HTTPContext *s = VAR_0->priv_data; char VAR_3[1024], VAR_4[1024]; char VAR_5[1024], VAR_6[1024], *VAR_7; char VAR_8[1024], VAR_9[100]; int VAR_10, VAR_11 = 0; HTTPAuthType cur_auth_type; char *VAR_12; VAR_0->is_streamed = 1; av_url_split(NULL, 0, VAR_5, sizeof(VAR_5), VAR_3, sizeof(VAR_3), &VAR_10,
VAR_6, sizeof(VAR_6), VAR_1); ff_url_join(VAR_4, sizeof(VAR_4), NULL, NULL, VAR_3, VAR_10, NULL); VAR_7 = VAR_6; if (*VAR_7 == '/')
VAR_7++; ff_url_join(VAR_9, sizeof(VAR_9), "tcp", NULL, VAR_3, VAR_10,
NULL); redo:
VAR_11 = ffurl_open(&s->hd, VAR_9, AVIO_FLAG_READ_WRITE,
&VAR_0->interrupt_callback, NULL); if (VAR_11 < 0)
return VAR_11; VAR_12 = ff_http_auth_create_response(&s->proxy_auth_state, VAR_5,
VAR_7, "CONNECT"); snprintf(s->buffer, sizeof(s->buffer),
"CONNECT %s HTTP/1.1\r\n"
"Host: %s\r\n"
"Connection: close\r\n"
"%s%s"
"\r\n",
VAR_7,
VAR_4,
VAR_12 ? "Proxy-" : "", VAR_12 ? VAR_12 : ""); av_freep(&VAR_12); if ((VAR_11 = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0)
goto fail; s->buf_ptr = s->buffer; s->buf_end = s->buffer; s->line_count = 0; s->filesize = -1; cur_auth_type = s->proxy_auth_state.auth_type; for (;;) { int VAR_13; if (http_get_line(s, VAR_8, sizeof(VAR_8)) < 0) { VAR_11 = AVERROR(EIO); goto fail; } av_dlog(VAR_0, "header='%s'\n", VAR_8); VAR_11 = process_line(VAR_0, VAR_8, s->line_count, &VAR_13); if (VAR_11 < 0)
goto fail; if (VAR_11 == 0)
break; s->line_count++; } if (s->http_code == 407 && cur_auth_type == HTTP_AUTH_NONE &&
s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) { ffurl_close(s->hd); s->hd = NULL; goto redo; } if (s->http_code < 400)
return 0; VAR_11 = AVERROR(EIO); fail:
http_proxy_close(VAR_0); return VAR_11; }