From patchwork Sat Mar 25 14:31:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Micah Galizia X-Patchwork-Id: 3096 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp527385vsy; Sat, 25 Mar 2017 07:31:34 -0700 (PDT) X-Received: by 10.28.227.213 with SMTP id a204mr2118826wmh.120.1490452293935; Sat, 25 Mar 2017 07:31:33 -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 v7si7594886wrv.93.2017.03.25.07.31.33; Sat, 25 Mar 2017 07:31:33 -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 C63CD6898D7; Sat, 25 Mar 2017 16:31:00 +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 2AED4689821 for ; Sat, 25 Mar 2017 16:30:54 +0200 (EET) Received: by mail-it0-f66.google.com with SMTP id 190so3265850itm.3 for ; Sat, 25 Mar 2017 07:31:15 -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=bC9TkrN6VXcfq1oG8OHHz1LNsYbEkEOcqld/xBHK5vI=; b=p+NwEhnChO1JVHRIeqJFPNLgejJoiA+2wUlIrHqVimMtCON/J1YLHY89UTFpoIhgIc IodOgv164ZHaQp8VGdxDIfm0BCPsISmNbjtydtmoKvFDYBLC1hfywUmv73VY/z/Vz7T5 aC3bN2Uv52uQdNh7VkIJyNVQWDQHtDmNHaje34EgGsYA/Y9Mf6S2C0LZHIxblDDuaK3V rkuC3WhDIxGnC6Bz1I+OLShDXEWcAVE+7bVKgbw3uY7pvNiJZL1Ij+LoRmeyaUBWBxtw jMSaBOI5Qzm2dScKcz4eGp1tCPOT/jpqGM6kXoO2ZMiVJlyslNuFPOkVS7W9HwGbmXbs Gx9w== 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=bC9TkrN6VXcfq1oG8OHHz1LNsYbEkEOcqld/xBHK5vI=; b=Qem7lFa4Ss7BJZdqhJIFrsBh9odWGFghYZ0znnesniiR3MtP7qD3/0kxItGlU+C1uP wTXcSUzep0Tp3H0gBjAByiSTBP3ke0S+QaavyxBMXNuf/+QDBiX6CUYAPzDaEYFBLRw2 xo3hvWKFnOXo0VwXTWgj3Z/qEaDlDTiRUFVQMtld9lkYPglcmVEB074vG1A1RklhHrCy XMEva6cyaGZGY3bwtojQXG29ZIUMS9yHac47dk5/a8FnbTFVyq58qMbZOKQk0NKwuXm/ B+KJ92ySsrvpa0wP9AZyf+AlExPF2sHMewSYoxyDmunLsyTDEBARpIzorKMJWUltdbV+ nlSQ== X-Gm-Message-State: AFeK/H0M69ay6KuqVuJxPfSBUm9Bks8wgKxzbfXqy8j9TN4hLlZGQhZCA7FQmfNkpz4VoQ== X-Received: by 10.36.32.69 with SMTP id t66mr2208405itt.110.1490452273984; Sat, 25 Mar 2017 07:31:13 -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 y203sm2772573iod.11.2017.03.25.07.31.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Mar 2017 07:31:13 -0700 (PDT) From: Micah Galizia To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Mar 2017 10:31:00 -0400 Message-Id: <20170325143100.13597-2-micahgalizia@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170325143100.13597-1-micahgalizia@gmail.com> References: <20170325121155.3a1182dd@debian> <20170325143100.13597-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 | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 293a8a7..f7d1925 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,8 @@ #define MAX_REDIRECTS 8 #define HTTP_SINGLE 1 #define HTTP_MUTLI 2 +#define MAX_EXPIRY 30 +#define WHITESPACES " \n\t\r" typedef enum { LOWER_PROTO, READ_HEADERS, @@ -877,15 +880,20 @@ 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; + char exp_buf[MAX_EXPIRY]; set_cookies = NULL; // store the cookie in a dict in case it is updated in the response 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 +907,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, j, exp_len; + struct tm tm_buf = {0}; + char *expiry = ¶m[8]; + + // strip off any punctuation or whitespace + exp_len = strlen(expiry); + for (i = 0, j = 0; i < exp_len; i++) { + if ((expiry[i] >= '0' && expiry[i] <= '9') || + (expiry[i] >= 'A' && expiry[i] <= 'Z') || + (expiry[i] >= 'a' && expiry[i] <= 'z')) { + exp_buf[j] = expiry[i]; + j++; + } + } + exp_buf[j] = '\0'; + + // move the string beyond the day of week + i = 0; + while ((exp_buf[i] < '0' || exp_buf[i] > '9') && (i < j)) + i++; + + if (av_small_strptime(&exp_buf[i], "%d%b%Y%H%M%SGMT", &tm_buf)) { + time_t now = av_gettime() / 1000000; + if (av_timegm(&tm_buf) < now) + expired = 1; + } } else { // ignore unknown attributes } @@ -907,9 +942,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; }