From patchwork Sat Mar 25 01:42:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 3091 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp344914vsy; Fri, 24 Mar 2017 18:49:22 -0700 (PDT) X-Received: by 10.28.5.8 with SMTP id 8mr142071wmf.70.1490406562851; Fri, 24 Mar 2017 18:49:22 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q6si939204wrd.50.2017.03.24.18.49.22; Fri, 24 Mar 2017 18:49:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3DBF3689720; Sat, 25 Mar 2017 03:48:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7D50468831A for ; Sat, 25 Mar 2017 03:48:52 +0200 (EET) Received: by mail-it0-f66.google.com with SMTP id 76so1298068itj.0 for ; Fri, 24 Mar 2017 18:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZRw74BQjXgN9c60oc22kPp/lGDtNvhMLau3Zi5/XRdE=; b=N6trkkZEsXJqbtj23Vo8mBBJVQe6K8zRXR5hht3PxrPg91fV2XZI+Qz+zrm9P1cPQ8 C/fKDJsA0fqG6qzYRWUMcMG8lA7jD80lGq06fv1l5TXzl9Cb03CluThN34v6/hRI8fsc GrwlQrYWM1IwVrCAs6XjJNkRYn8178DCdpzN+XFrLak4roXZYVqJuW58WMr4OZucpm0v +35GeiZGHVtqoI5AgcXWUrJ2S9EjuJDr6/BFxkWOAYWTLrt6jEscUmMZfE/S7Q0fThHF c+zenBSNT9N9QdiFTc6WX9fCeJe/ux0BNG1Gyet8hP7pR9UWJ9457+ZqH0JgE94pnrgo Femg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZRw74BQjXgN9c60oc22kPp/lGDtNvhMLau3Zi5/XRdE=; b=FmE0bcfK7r+RQgX/tgQxqOdgkWNucHRXFVfWY9rvNyKZdiuQSYNV4N9GcXWAaRljm5 IJ4eqjZwW/Hj+Br0g7n+P7rV8gdhmBjfNRvwEoQO58j9ZLrWkDVRcjhrEALUmo41B5S5 2Vj8zGbxoc0dAZj24hVdsBqF1d2eWF34oLOgTOxBkDMbVd2qBRsGzUKL65kNG7qRdkMH vN0VGyAgf0zv+bPfSMdJ+6UkupWfV6xhU7OWa6dj/SCrIp8pRL0QR0dzMVL2GhnyQNkZ kVuwbdjWjGsq/GIrBrAO9OYAG7c15zm2ZZ0t07E96DoG1uhJNx1YOSLY9twj5UzDYphx MjiA== X-Gm-Message-State: AFeK/H2cbChh5/MdygW16nk/TmJc3qJyBlJ0Kmy3V4ITKA5kTiZJ69bj0Vmh3WwkTXsSew== X-Received: by 10.107.7.210 with SMTP id g79mr10856181ioi.34.1490406147797; Fri, 24 Mar 2017 18:42:27 -0700 (PDT) Received: from localhost.localdomain (ip-24-54-73-138.user.start.ca. [24.54.73.138]) by smtp.gmail.com with ESMTPSA id a196sm1835109itc.14.2017.03.24.18.42.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Mar 2017 18:42:27 -0700 (PDT) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Mar 2017 21:42:18 -0400 Message-Id: <20170325014218.1329-2-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170325014218.1329-1-micahgalizia@gmail.com> References: <20170325014218.1329-1-micahgalizia@gmail.com> Subject: [FFmpeg-devel] [PATCH] Ignore expired cookies X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Micah Galizia MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Micah Galizia --- libavformat/http.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 293a8a7..37bdacf 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -29,6 +29,7 @@ #include "libavutil/avstring.h" #include "libavutil/opt.h" #include "libavutil/time.h" +#include "libavutil/parseutils.h" #include "avformat.h" #include "http.h" @@ -48,6 +49,7 @@ #define MAX_REDIRECTS 8 #define HTTP_SINGLE 1 #define HTTP_MUTLI 2 +#define WHITESPACES " \n\t\r" typedef enum { LOWER_PROTO, READ_HEADERS, @@ -877,7 +879,7 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path, *cookies = NULL; while ((cookie = av_strtok(set_cookies, "\n", &next))) { - int domain_offset = 0; + int domain_offset = 0, expired = 0; char *param, *next_param, *cdomain = NULL, *cpath = NULL, *cvalue = NULL; set_cookies = NULL; @@ -885,7 +887,11 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path, if (parse_cookie(s, cookie, &s->cookie_dict)) av_log(s, AV_LOG_WARNING, "Unable to parse '%s'\n", cookie); - while ((param = av_strtok(cookie, "; ", &next_param))) { + while ((param = av_strtok(cookie, ";", &next_param))) { + + // move past any leading whitespace + param += strspn(param, WHITESPACES); + if (cookie) { // first key-value pair is the actual cookie value cvalue = av_strdup(param); @@ -899,6 +905,33 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path, int leading_dot = (param[7] == '.'); av_free(cdomain); cdomain = av_strdup(¶m[7+leading_dot]); + } else if (!av_strncasecmp("expires=", param, 8)) { + int i = 0, j = 0; + struct tm tm_buf = {0}; + char *expiry = av_strdup(¶m[8]); + + // strip off any punctuation or whitespace + for (; i < strlen(expiry); i++) { + if ((expiry[i] >= '0' && expiry[i] <= '9') || + (expiry[i] >= 'A' && expiry[i] <= 'Z') || + (expiry[i] >= 'a' && expiry[i] <= 'z')) { + expiry[j] = expiry[i]; + j++; + } + } + expiry[j] = '\0'; + + // move the string beyond the day of week + i = 0; + while ((expiry[i] < '0' || expiry[i] > '9') && (i < j)) + i++; + + if (av_small_strptime(&expiry[i], "%d%b%Y%H%M%SGMT", &tm_buf)) { + if (av_timegm(&tm_buf) < time(NULL)) + expired = 1; + } + + av_free(expiry); } else { // ignore unknown attributes } @@ -907,9 +940,9 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path, cdomain = av_strdup(domain); // ensure all of the necessary values are valid - if (!cdomain || !cpath || !cvalue) { + if (expired || !cdomain || !cpath || !cvalue ) { av_log(s, AV_LOG_WARNING, - "Invalid cookie found, no value, path or domain specified\n"); + "Invalid cookie found, expired or no value, path or domain specified\n"); goto done_cookie; }