[FFmpeg-devel] [PATCH] HTTP cookie support

Michael Niedermayer michaelni at gmx.at
Sun Jan 20 20:27:23 CET 2013


On Sun, Jan 13, 2013 at 09:38:53PM -0500, Micah Galizia wrote:
> OK,
> 
> All nits addressed and I changed to the while instead of do ... it kind of
> feels strange setting things to NULL and keeping an extra pointer around,
> but it does cut down a few lines ... it also feels strange using a goto.
> Documentation patch is the same, but I regenerated because I used `git
> reset` to roll them both back and I wasn't sure if it'd affect `git am` on
> your end.
> 
> Anyway, thanks for the review.
> 
> PS: is there a difference between "nit" and "Nit"?

>  http.c |  115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 115 insertions(+)
> e6791bc41d8cf11bee89a49148c72bfe0c7107bf  0001-add-HTTP-protocol-cookie-support.patch
> From e256881955527ef72c1016a41f8f2129a0308cd4 Mon Sep 17 00:00:00 2001
> From: Micah Galizia <micahgalizia at gmail.com>
> Date: Sun, 13 Jan 2013 21:32:57 -0500
> Subject: [PATCH 1/2] add HTTP protocol cookie support
> 
> ---
>  libavformat/http.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 115 insertions(+)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index a9d952b..0719afe 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -64,6 +64,7 @@ typedef struct {
>      int is_akamai;
>      int rw_timeout;
>      char *mime_type;
> +    char *cookies;          ///< holds newline (\n) delimited Set-Cookie header field values (without the "Set-Cookie: " field name)
>  } HTTPContext;
>  
>  #define OFFSET(x) offsetof(HTTPContext, x)
> @@ -80,6 +81,7 @@ static const AVOption options[] = {
>  {"post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D|E },
>  {"timeout", "set timeout of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, D|E },
>  {"mime_type", "set MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
> +{"cookies", "set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax", OFFSET(cookies), AV_OPT_TYPE_STRING, {0}, 0, 0, 0 },
>  {NULL}
>  };
>  #define HTTP_CLASS(flavor)\
> @@ -359,11 +361,116 @@ static int process_line(URLContext *h, char *line, int line_count,
>              s->is_akamai = 1;
>          } else if (!av_strcasecmp (tag, "Content-Type")) {
>              av_free(s->mime_type); s->mime_type = av_strdup(p);
> +        } else if (!av_strcasecmp (tag, "Set-Cookie")) {
> +            if (!s->cookies) {
> +                if (!(s->cookies = av_strdup(p)))
> +                    return AVERROR(ENOMEM);
> +            } else {
> +                char *tmp = s->cookies;
> +                size_t str_size = strlen(tmp) + strlen(p) + 2;
> +                if (!(s->cookies = av_malloc(str_size))) {
> +                    s->cookies = tmp;
> +                    return AVERROR(ENOMEM);
> +                }
> +                snprintf(s->cookies, str_size, "%s\n%s", tmp, p);
> +                av_free(tmp);
> +            }
>          }
>      }
>      return 1;
>  }
>  
> +/**
> + * Create a string containing cookie values for use as a HTTP cookie header
> + * field value for a particular path and domain from the cookie values stored in
> + * the HTTP protocol context. The cookie string is stored in *cookies.
> + *
> + * @return a negative value if an error condition occurred, 0 otherwise
> + */
> +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]);

this leaks if executed twice (CID968584)


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

> +                cdomain = av_strdup(&param[7]);

this similarly can leak (CID968585)

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I have never wished to cater to the crowd; for what I know they do not
approve, and what they approve I do not know. -- Epicurus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130120/801d5d59/attachment.asc>


More information about the ffmpeg-devel mailing list