static int get_cookies(HTTPContext *s, char **cookies, const char *path,

                       const char *domain)

{

    // cookie strings will look like Set-Cookie header field values.  Multiple

    // Set-Cookie fields will result in multiple values delimited by a newline

    int ret = 0;

    char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;



    if (!set_cookies) return AVERROR(EINVAL);



    *cookies = NULL;

    while ((cookie = av_strtok(set_cookies, "\n", &next))) {

        int domain_offset = 0;

        char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;

        set_cookies = NULL;



        while ((param = av_strtok(cookie, "; ", &next_param))) {

            cookie = NULL;

            if        (!av_strncasecmp("path=",   param, 5)) {


                cpath = av_strdup(&param[5]);

            } else if (!av_strncasecmp("domain=", param, 7)) {


                cdomain = av_strdup(&param[7]);

            } else if (!av_strncasecmp("secure",  param, 6) ||

                       !av_strncasecmp("comment", param, 7) ||

                       !av_strncasecmp("max-age", param, 7) ||

                       !av_strncasecmp("version", param, 7)) {

                // ignore Comment, Max-Age, Secure and Version

            } else {

                av_free(cvalue);

                cvalue = av_strdup(param);

            }

        }



        // ensure all of the necessary values are valid

        if (!cdomain || !cpath || !cvalue) {

            av_log(s, AV_LOG_WARNING,

                   "Invalid cookie found, no value, path or domain specified\n");

            goto done_cookie;

        }



        // check if the request path matches the cookie path

        if (av_strncasecmp(path, cpath, strlen(cpath)))

            goto done_cookie;



        // the domain should be at least the size of our cookie domain

        domain_offset = strlen(domain) - strlen(cdomain);

        if (domain_offset < 0)

            goto done_cookie;



        // match the cookie domain

        if (av_strcasecmp(&domain[domain_offset], cdomain))

            goto done_cookie;



        // cookie parameters match, so copy the value

        if (!*cookies) {

            if (!(*cookies = av_strdup(cvalue))) {

                ret = AVERROR(ENOMEM);

                goto done_cookie;

            }

        } else {

            char *tmp = *cookies;

            size_t str_size = strlen(cvalue) + strlen(*cookies) + 3;

            if (!(*cookies = av_malloc(str_size))) {

                ret = AVERROR(ENOMEM);

                goto done_cookie;

            }

            snprintf(*cookies, str_size, "%s; %s", tmp, cvalue);

            av_free(tmp);

        }



        done_cookie:



        av_free(cvalue);

        if (ret < 0) {

            if (*cookies) av_freep(cookies);

            av_free(cset_cookies);

            return ret;

        }

    }



    av_free(cset_cookies);



    return 0;

}
static int get_cookies(HTTPContext *s, char **cookies, const char *path,

                       const char *domain)

{

    

    

    int ret = 0;

    char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;



    if (!set_cookies) return AVERROR(EINVAL);



    *cookies = NULL;

    while ((cookie = av_strtok(set_cookies, "\n", &next))) {

        int domain_offset = 0;

        char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;

        set_cookies = NULL;



        while ((param = av_strtok(cookie, "; ", &next_param))) {

            cookie = NULL;

            if        (!av_strncasecmp("path=",   param, 5)) {


                cpath = av_strdup(&param[5]);

            } else if (!av_strncasecmp("domain=", param, 7)) {


                cdomain = av_strdup(&param[7]);

            } else if (!av_strncasecmp("secure",  param, 6) ||

                       !av_strncasecmp("comment", param, 7) ||

                       !av_strncasecmp("max-age", param, 7) ||

                       !av_strncasecmp("version", param, 7)) {

                

            } else {

                av_free(cvalue);

                cvalue = av_strdup(param);

            }

        }



        

        if (!cdomain || !cpath || !cvalue) {

            av_log(s, AV_LOG_WARNING,

                   "Invalid cookie found, no value, path or domain specified\n");

            goto done_cookie;

        }



        

        if (av_strncasecmp(path, cpath, strlen(cpath)))

            goto done_cookie;



        

        domain_offset = strlen(domain) - strlen(cdomain);

        if (domain_offset < 0)

            goto done_cookie;



        

        if (av_strcasecmp(&domain[domain_offset], cdomain))

            goto done_cookie;



        

        if (!*cookies) {

            if (!(*cookies = av_strdup(cvalue))) {

                ret = AVERROR(ENOMEM);

                goto done_cookie;

            }

        } else {

            char *tmp = *cookies;

            size_t str_size = strlen(cvalue) + strlen(*cookies) + 3;

            if (!(*cookies = av_malloc(str_size))) {

                ret = AVERROR(ENOMEM);

                goto done_cookie;

            }

            snprintf(*cookies, str_size, "%s; %s", tmp, cvalue);

            av_free(tmp);

        }



        done_cookie:



        av_free(cvalue);

        if (ret < 0) {

            if (*cookies) av_freep(cookies);

            av_free(cset_cookies);

            return ret;

        }

    }



    av_free(cset_cookies);



    return 0;

}
static int FUNC_0(HTTPContext *VAR_0, char **VAR_1, const char *VAR_2,

                       const char *VAR_3)

{

    

    

    int VAR_4 = 0;

    char *VAR_5, *VAR_6, *VAR_7 = av_strdup(VAR_0->VAR_1), *VAR_8 = VAR_7;



    if (!VAR_7) return AVERROR(EINVAL);



    *VAR_1 = NULL;

    while ((VAR_6 = av_strtok(VAR_7, "\n", &VAR_5))) {

        int VAR_9 = 0;

        char *VAR_10, *VAR_11, *VAR_12 = NULL, *VAR_13 = NULL, *VAR_14 = NULL;

        VAR_7 = NULL;



        while ((VAR_10 = av_strtok(VAR_6, "; ", &VAR_11))) {

            VAR_6 = NULL;

            if        (!av_strncasecmp("VAR_2=",   VAR_10, 5)) {


                VAR_13 = av_strdup(&VAR_10[5]);

            } else if (!av_strncasecmp("VAR_3=", VAR_10, 7)) {


                VAR_12 = av_strdup(&VAR_10[7]);

            } else if (!av_strncasecmp("secure",  VAR_10, 6) ||

                       !av_strncasecmp("comment", VAR_10, 7) ||

                       !av_strncasecmp("max-age", VAR_10, 7) ||

                       !av_strncasecmp("version", VAR_10, 7)) {

                

            } else {

                av_free(VAR_14);

                VAR_14 = av_strdup(VAR_10);

            }

        }



        

        if (!VAR_12 || !VAR_13 || !VAR_14) {

            av_log(VAR_0, AV_LOG_WARNING,

                   "Invalid VAR_6 found, no value, VAR_2 or VAR_3 specified\n");

            goto done_cookie;

        }



        

        if (av_strncasecmp(VAR_2, VAR_13, strlen(VAR_13)))

            goto done_cookie;



        

        VAR_9 = strlen(VAR_3) - strlen(VAR_12);

        if (VAR_9 < 0)

            goto done_cookie;



        

        if (av_strcasecmp(&VAR_3[VAR_9], VAR_12))

            goto done_cookie;



        

        if (!*VAR_1) {

            if (!(*VAR_1 = av_strdup(VAR_14))) {

                VAR_4 = AVERROR(ENOMEM);

                goto done_cookie;

            }

        } else {

            char *VAR_15 = *VAR_1;

            size_t str_size = strlen(VAR_14) + strlen(*VAR_1) + 3;

            if (!(*VAR_1 = av_malloc(str_size))) {

                VAR_4 = AVERROR(ENOMEM);

                goto done_cookie;

            }

            snprintf(*VAR_1, str_size, "%VAR_0; %VAR_0", VAR_15, VAR_14);

            av_free(VAR_15);

        }



        done_cookie:



        av_free(VAR_14);

        if (VAR_4 < 0) {

            if (*VAR_1) av_freep(VAR_1);

            av_free(VAR_8);

            return VAR_4;

        }

    }



    av_free(VAR_8);



    return 0;

}
static int FUNC_0(HTTPContext *VAR_0, char **VAR_1, const char *VAR_2,
const char *VAR_3)
{ int VAR_4 = 0; char *VAR_5, *VAR_6, *VAR_7 = av_strdup(VAR_0->VAR_1), *VAR_8 = VAR_7; if (!VAR_7) return AVERROR(EINVAL); *VAR_1 = NULL; while ((VAR_6 = av_strtok(VAR_7, "\n", &VAR_5))) { int VAR_9 = 0; char *VAR_10, *VAR_11, *VAR_12 = NULL, *VAR_13 = NULL, *VAR_14 = NULL; VAR_7 = NULL; while ((VAR_10 = av_strtok(VAR_6, "; ", &VAR_11))) { VAR_6 = NULL; if        (!av_strncasecmp("VAR_2=",   VAR_10, 5)) { VAR_13 = av_strdup(&VAR_10[5]); } else if (!av_strncasecmp("VAR_3=", VAR_10, 7)) { VAR_12 = av_strdup(&VAR_10[7]); } else if (!av_strncasecmp("secure",  VAR_10, 6) || !av_strncasecmp("comment", VAR_10, 7) ||
!av_strncasecmp("max-age", VAR_10, 7) ||
!av_strncasecmp("version", VAR_10, 7)) { } else { av_free(VAR_14); VAR_14 = av_strdup(VAR_10); } } if (!VAR_12 || !VAR_13 || !VAR_14) { av_log(VAR_0, AV_LOG_WARNING,
"Invalid VAR_6 found, no value, VAR_2 or VAR_3 specified\n"); goto done_cookie; } if (av_strncasecmp(VAR_2, VAR_13, strlen(VAR_13)))
goto done_cookie; VAR_9 = strlen(VAR_3) - strlen(VAR_12); if (VAR_9 < 0)
goto done_cookie; if (av_strcasecmp(&VAR_3[VAR_9], VAR_12))
goto done_cookie; if (!*VAR_1) { if (!(*VAR_1 = av_strdup(VAR_14))) { VAR_4 = AVERROR(ENOMEM); goto done_cookie; } } else { char *VAR_15 = *VAR_1; size_t str_size = strlen(VAR_14) + strlen(*VAR_1) + 3; if (!(*VAR_1 = av_malloc(str_size))) { VAR_4 = AVERROR(ENOMEM); goto done_cookie; } snprintf(*VAR_1, str_size, "%VAR_0; %VAR_0", VAR_15, VAR_14); av_free(VAR_15); } done_cookie:
av_free(VAR_14); if (VAR_4 < 0) { if (*VAR_1) av_freep(VAR_1); av_free(VAR_8); return VAR_4; } } av_free(VAR_8); return 0; }