[FFmpeg-devel] [PATCH 3/3] http: return cookie errors

wm4 nfxjfg at googlemail.com
Fri Mar 21 18:51:32 CET 2014


This forwards errors returned by get_cookies() to the caller. Before
this, errors were completely ignored.

This also requires changing the return value to success if no cookies
are set. Obviously, not specifying any cookie should not be an error.
---
Not too sure about this? Do we want this? Certainly it should return
some errors (especially stuff like out of memory), but on the other
hand, refusing all http connections just because the cookie string
is broken isn't so great either.

Also, I didn't really test the error path.
---
 libavformat/http.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 64ca4ae..296d873 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -539,9 +539,10 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path,
     int ret = 0;
     char *next, *cookie, *set_cookies = av_strdup(s->cookies), *cset_cookies = set_cookies;
 
-    if (!set_cookies) return AVERROR(EINVAL);
-
     *cookies = NULL;
+    if (!set_cookies)
+        return ret;
+
     while ((cookie = av_strtok(set_cookies, "\n", &next))) {
         int domain_offset = 0;
         char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL;
@@ -746,7 +747,9 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
                            "Content-Type: %s\r\n", s->content_type);
     if (!has_header(s->headers, "\r\nCookie: ") && s->cookies) {
         char *cookies = NULL;
-        if (!get_cookies(s, &cookies, path, hoststr) && cookies) {
+        if ((err = get_cookies(s, &cookies, path, hoststr)) < 0)
+            goto done;
+        if (cookies) {
             len += av_strlcatf(headers + len, sizeof(headers) - len,
                                "Cookie: %s\r\n", cookies);
             av_free(cookies);
-- 
1.9.0



More information about the ffmpeg-devel mailing list