static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,

                    AVDictionary *opts, AVDictionary *opts2, int *is_http)

{

    HLSContext *c = s->priv_data;

    AVDictionary *tmp = NULL;

    const char *proto_name = NULL;

    int ret;



    av_dict_copy(&tmp, opts, 0);

    av_dict_copy(&tmp, opts2, 0);



    if (av_strstart(url, "crypto", NULL)) {

        if (url[6] == '+' || url[6] == ':')

            proto_name = avio_find_protocol_name(url + 7);

    }



    if (!proto_name)

        proto_name = avio_find_protocol_name(url);



    if (!proto_name)

        return AVERROR_INVALIDDATA;



    // only http(s) & file are allowed

    if (av_strstart(proto_name, "file", NULL)) {

        if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {

            av_log(s, AV_LOG_ERROR,

                "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"

                "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",

                url);

            return AVERROR_INVALIDDATA;

        }

    } else if (av_strstart(proto_name, "http", NULL)) {

        ;

    } else

        return AVERROR_INVALIDDATA;



    if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')

        ;

    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')

        ;

    else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))

        return AVERROR_INVALIDDATA;



    if (c->http_persistent && *pb && av_strstart(proto_name, "http", NULL)) {

        ret = open_url_keepalive(c->ctx, pb, url);

        if (ret == AVERROR_EXIT) {

            return ret;

        } else if (ret < 0) {

            if (ret != AVERROR_EOF)

                av_log(s, AV_LOG_WARNING,

                    "keepalive request failed for '%s', retrying with new connection: %s\n",

                    url, av_err2str(ret));

            ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);

        }

    } else {

        ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);

    }

    if (ret >= 0) {

        // update cookies on http response with setcookies.

        char *new_cookies = NULL;



        if (!(s->flags & AVFMT_FLAG_CUSTOM_IO))

            av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies);



        if (new_cookies) {

            av_free(c->cookies);

            c->cookies = new_cookies;

        }



        av_dict_set(&opts, "cookies", c->cookies, 0);

    }



    av_dict_free(&tmp);



    if (is_http)

        *is_http = av_strstart(proto_name, "http", NULL);



    return ret;

}

static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url,

                    AVDictionary *opts, AVDictionary *opts2, int *is_http)

{

    HLSContext *c = s->priv_data;

    AVDictionary *tmp = NULL;

    const char *proto_name = NULL;

    int ret;



    av_dict_copy(&tmp, opts, 0);

    av_dict_copy(&tmp, opts2, 0);



    if (av_strstart(url, "crypto", NULL)) {

        if (url[6] == '+' || url[6] == ':')

            proto_name = avio_find_protocol_name(url + 7);

    }



    if (!proto_name)

        proto_name = avio_find_protocol_name(url);



    if (!proto_name)

        return AVERROR_INVALIDDATA;



    

    if (av_strstart(proto_name, "file", NULL)) {

        if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(url, c->allowed_extensions)) {

            av_log(s, AV_LOG_ERROR,

                "Filename extension of \'%s\' is not a common multimedia extension, blocked for security reasons.\n"

                "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",

                url);

            return AVERROR_INVALIDDATA;

        }

    } else if (av_strstart(proto_name, "http", NULL)) {

        ;

    } else

        return AVERROR_INVALIDDATA;



    if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')

        ;

    else if (av_strstart(url, "crypto", NULL) && !strncmp(proto_name, url + 7, strlen(proto_name)) && url[7 + strlen(proto_name)] == ':')

        ;

    else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5))

        return AVERROR_INVALIDDATA;



    if (c->http_persistent && *pb && av_strstart(proto_name, "http", NULL)) {

        ret = open_url_keepalive(c->ctx, pb, url);

        if (ret == AVERROR_EXIT) {

            return ret;

        } else if (ret < 0) {

            if (ret != AVERROR_EOF)

                av_log(s, AV_LOG_WARNING,

                    "keepalive request failed for '%s', retrying with new connection: %s\n",

                    url, av_err2str(ret));

            ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);

        }

    } else {

        ret = s->io_open(s, pb, url, AVIO_FLAG_READ, &tmp);

    }

    if (ret >= 0) {

        

        char *new_cookies = NULL;



        if (!(s->flags & AVFMT_FLAG_CUSTOM_IO))

            av_opt_get(*pb, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&new_cookies);



        if (new_cookies) {

            av_free(c->cookies);

            c->cookies = new_cookies;

        }



        av_dict_set(&opts, "cookies", c->cookies, 0);

    }



    av_dict_free(&tmp);



    if (is_http)

        *is_http = av_strstart(proto_name, "http", NULL);



    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, AVIOContext **VAR_1, const char *VAR_2,

                    AVDictionary *VAR_3, AVDictionary *VAR_4, int *VAR_5)

{

    HLSContext *c = VAR_0->priv_data;

    AVDictionary *tmp = NULL;

    const char *VAR_6 = NULL;

    int VAR_7;



    av_dict_copy(&tmp, VAR_3, 0);

    av_dict_copy(&tmp, VAR_4, 0);



    if (av_strstart(VAR_2, "crypto", NULL)) {

        if (VAR_2[6] == '+' || VAR_2[6] == ':')

            VAR_6 = avio_find_protocol_name(VAR_2 + 7);

    }



    if (!VAR_6)

        VAR_6 = avio_find_protocol_name(VAR_2);



    if (!VAR_6)

        return AVERROR_INVALIDDATA;



    

    if (av_strstart(VAR_6, "file", NULL)) {

        if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(VAR_2, c->allowed_extensions)) {

            av_log(VAR_0, AV_LOG_ERROR,

                "Filename extension of \'%VAR_0\' is not a common multimedia extension, blocked for security reasons.\n"

                "If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",

                VAR_2);

            return AVERROR_INVALIDDATA;

        }

    } else if (av_strstart(VAR_6, "http", NULL)) {

        ;

    } else

        return AVERROR_INVALIDDATA;



    if (!strncmp(VAR_6, VAR_2, strlen(VAR_6)) && VAR_2[strlen(VAR_6)] == ':')

        ;

    else if (av_strstart(VAR_2, "crypto", NULL) && !strncmp(VAR_6, VAR_2 + 7, strlen(VAR_6)) && VAR_2[7 + strlen(VAR_6)] == ':')

        ;

    else if (strcmp(VAR_6, "file") || !strncmp(VAR_2, "file,", 5))

        return AVERROR_INVALIDDATA;



    if (c->http_persistent && *VAR_1 && av_strstart(VAR_6, "http", NULL)) {

        VAR_7 = open_url_keepalive(c->ctx, VAR_1, VAR_2);

        if (VAR_7 == AVERROR_EXIT) {

            return VAR_7;

        } else if (VAR_7 < 0) {

            if (VAR_7 != AVERROR_EOF)

                av_log(VAR_0, AV_LOG_WARNING,

                    "keepalive request failed for '%VAR_0', retrying with new connection: %VAR_0\n",

                    VAR_2, av_err2str(VAR_7));

            VAR_7 = VAR_0->io_open(VAR_0, VAR_1, VAR_2, AVIO_FLAG_READ, &tmp);

        }

    } else {

        VAR_7 = VAR_0->io_open(VAR_0, VAR_1, VAR_2, AVIO_FLAG_READ, &tmp);

    }

    if (VAR_7 >= 0) {

        

        char *VAR_8 = NULL;



        if (!(VAR_0->flags & AVFMT_FLAG_CUSTOM_IO))

            av_opt_get(*VAR_1, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&VAR_8);



        if (VAR_8) {

            av_free(c->cookies);

            c->cookies = VAR_8;

        }



        av_dict_set(&VAR_3, "cookies", c->cookies, 0);

    }



    av_dict_free(&tmp);



    if (VAR_5)

        *VAR_5 = av_strstart(VAR_6, "http", NULL);



    return VAR_7;

}

static int FUNC_0(AVFormatContext *VAR_0, AVIOContext **VAR_1, const char *VAR_2,
AVDictionary *VAR_3, AVDictionary *VAR_4, int *VAR_5)
{ HLSContext *c = VAR_0->priv_data; AVDictionary *tmp = NULL; const char *VAR_6 = NULL; int VAR_7; av_dict_copy(&tmp, VAR_3, 0); av_dict_copy(&tmp, VAR_4, 0); if (av_strstart(VAR_2, "crypto", NULL)) { if (VAR_2[6] == '+' || VAR_2[6] == ':')
VAR_6 = avio_find_protocol_name(VAR_2 + 7); } if (!VAR_6)
VAR_6 = avio_find_protocol_name(VAR_2); if (!VAR_6)
return AVERROR_INVALIDDATA; if (av_strstart(VAR_6, "file", NULL)) { if (strcmp(c->allowed_extensions, "ALL") && !av_match_ext(VAR_2, c->allowed_extensions)) { av_log(VAR_0, AV_LOG_ERROR,
"Filename extension of \'%VAR_0\' is not a common multimedia extension, blocked for security reasons.\n"
"If you wish to override this adjust allowed_extensions, you can set it to \'ALL\' to allow all\n",
VAR_2); return AVERROR_INVALIDDATA; } } else if (av_strstart(VAR_6, "http", NULL)) { ; } else return AVERROR_INVALIDDATA; if (!strncmp(VAR_6, VAR_2, strlen(VAR_6)) && VAR_2[strlen(VAR_6)] == ':')
; else if (av_strstart(VAR_2, "crypto", NULL) && !strncmp(VAR_6, VAR_2 + 7, strlen(VAR_6)) && VAR_2[7 + strlen(VAR_6)] == ':')
; else if (strcmp(VAR_6, "file") || !strncmp(VAR_2, "file,", 5))
return AVERROR_INVALIDDATA; if (c->http_persistent && *VAR_1 && av_strstart(VAR_6, "http", NULL)) { VAR_7 = open_url_keepalive(c->ctx, VAR_1, VAR_2); if (VAR_7 == AVERROR_EXIT) { return VAR_7; } else if (VAR_7 < 0) { if (VAR_7 != AVERROR_EOF)
av_log(VAR_0, AV_LOG_WARNING,
"keepalive request failed for '%VAR_0', retrying with new connection: %VAR_0\n",
VAR_2, av_err2str(VAR_7)); VAR_7 = VAR_0->io_open(VAR_0, VAR_1, VAR_2, AVIO_FLAG_READ, &tmp); } } else { VAR_7 = VAR_0->io_open(VAR_0, VAR_1, VAR_2, AVIO_FLAG_READ, &tmp); } if (VAR_7 >= 0) { char *VAR_8 = NULL; if (!(VAR_0->flags & AVFMT_FLAG_CUSTOM_IO))
av_opt_get(*VAR_1, "cookies", AV_OPT_SEARCH_CHILDREN, (uint8_t**)&VAR_8); if (VAR_8) { av_free(c->cookies); c->cookies = VAR_8; } av_dict_set(&VAR_3, "cookies", c->cookies, 0); } av_dict_free(&tmp); if (VAR_5)
*VAR_5 = av_strstart(VAR_6, "http", NULL); return VAR_7; }