From patchwork Thu Apr 25 14:23:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 48258 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:2d06:b0:1a9:af23:56c1 with SMTP id tw6csp1418352pzb; Thu, 25 Apr 2024 07:24:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXBnnZRjUr9HAhFfF4Wuw9xXWWoqRliemtlCqFJPUmLul0RBJXBopTDqujYbwyLI4AAoc/gnJa89XWpWtrrkgel6ykYb+TRLgivUg== X-Google-Smtp-Source: AGHT+IGkJcMwBDQd4C2lJ+LTFGJv1FkufJao2AUrxYHDFg5pNCp/SjXth3jV4o7vuAOttq5diSYP X-Received: by 2002:a05:6402:22cd:b0:572:4b64:918c with SMTP id dm13-20020a05640222cd00b005724b64918cmr508916edb.1.1714055041942; Thu, 25 Apr 2024 07:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1714055041; cv=none; d=google.com; s=arc-20160816; b=DpCrJxEFkJPzGJ02zZQ4TiyNfW3uI6z8oc3vVI2h+XG6JP8MBk4cex8nfIscLxaUhH AkjsiovBh0ReojgxXM0dvsm/ApwLJ1QDSYQHGLqm4kjUi4ePEUIyTxFxOi4WBK4J3hM5 D0GyGMkg5Tcj1FrdgXTUG/mdiKi/YsISh9PMbZbq/cldsuArqTXcx+Rr3KA+q7h9rDeO R8EBx30cNjH+LrMlVIXDEMsscwG1FhN4LDcefHTls4Psuj7M5+CjE5Z8kKagWpFYxCFe h0k0liJYCG2oSUBxBre4P2W2C3jlnnF2kD3orbqBpOzBjefOu81XwtugTwxrXKpMLS4w NhKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=44D68o2dqDf4QP4DQedv9a/bRC+o5vjW3c/pu1O7EgU=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=RzJYPF0Cnd2yMToJ625VsIGbfkfu2g5FBvlBeNWkgej/UUfNQCHNVRfEYhPkNR5xpT etaE5nZevyJF7VxekiF9JYZao/p50ewmIKJw/kQw+toLDXpd4kn0geZsozoRdTspG3iJ 3Ekk29GOLPuePs9/FI6Lfd9249FlnjtSt2lZJ4yd0GouKmKcICvk/XIJ+D0Fx/RYNZS8 dMJHHXpQn51WEf1HjMgYXe8BsN5fxNJ5IyyZfXcobLe8DrHfrE6BulzJ3JvkVsYB33rd VBue3ijORQ3bbvo6ad0wRJqdor9jRRSDHVKXSmETAm48D8LkBGTCurTRK38OH9b32fUg 2zHQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=nGcamYnq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v1-20020a509541000000b00571e26e1552si8069764eda.33.2024.04.25.07.24.01; Thu, 25 Apr 2024 07:24:01 -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 header.s=20230601 header.b=nGcamYnq; 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=QUARANTINE 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 CD97168D366; Thu, 25 Apr 2024 17:23:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0134568CD6B for ; Thu, 25 Apr 2024 17:23:43 +0300 (EEST) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-41b51ee24f9so3511445e9.1 for ; Thu, 25 Apr 2024 07:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714055022; x=1714659822; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=eaOag0BmhQ1HXj5JcI3JvsdcEBCJp2i5uSJb0z9CKkw=; b=nGcamYnq9T43+P2986i19MQVZdnKQGXpYJ5qGAl9UiYYMhNbKOi2W3H+9E2oG23D2t 1ZuhXU4YKRB3wzR6dkpR+eNBiXWhoUpo0Z4LN4BH8AB594fNJDjff5OVhjrD36LcGMEg j9ME1utT50dlx+5fIn1CserfUUEgjkM47VU2psljlhu6fDcshmiTCxMMjWcs7sMaDqNU ozkvQmTKFNI6qszJOgfmjnwPh3RjeClQzf/UwIHUoapixyLeA92oDB2GQn0Yejd0oSXl SRO16l9lBhYmOd1gjYu8ZcuGyUWsJfYwbJOVCiAoJVA6ybNsuo3EwTHZOndFitJQh8NG 4aGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714055022; x=1714659822; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eaOag0BmhQ1HXj5JcI3JvsdcEBCJp2i5uSJb0z9CKkw=; b=kOAsaihnOh/u+J1J5NPZSR+AG/TJXv5+974uuBTjv1z5UZmUJmU4rTNLSFX5BmOEyO wAfodExA/k6OX8ILvSsczYB2JpqEhI7C0MdYo5W0W+lTaXPIc6PKlmvEZe/g/h+Eux/O biwLadFROpF32cTXm6Hwn/bk+N1QfCVq0tq6woZPqlhnvoLz8pVpgT7zVgqIp9y2dUsP DmqkZnVHHkijhzOaxxvJcf3xJHuPiohZz5mMYumvOWSGZm2U2iikX3zM4SCRFcP9L24F D4xMwVls/Ey+A8q89/6Eb+3nV6ceq1GQwSE+9l9y7cyeLn8JrIObAUiuXWxLHBSclLso mt1A== X-Gm-Message-State: AOJu0Yy0JydhNM5pCaWtFLijVpFN7lpXlXuCC9rsedDxzfkuZYvc1Ace 90pC9nBj3dkHmjRKx+fiPTNIJ2JyVeZddcPo+60INXBvpEcBQ3lHgIuLsA== X-Received: by 2002:a05:600c:1906:b0:418:9bd6:be2c with SMTP id j6-20020a05600c190600b004189bd6be2cmr2406831wmq.2.1714055022202; Thu, 25 Apr 2024 07:23:42 -0700 (PDT) Received: from localhost.localdomain (33bf0029.skybroadband.com. [51.191.0.41]) by smtp.gmail.com with ESMTPSA id o12-20020a5d684c000000b0034aa1e534c2sm14582018wrw.96.2024.04.25.07.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 07:23:41 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Apr 2024 15:23:29 +0100 Message-ID: <20240425142330.288815-2-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240425142330.288815-1-derek.buitenhuis@gmail.com> References: <20240425142330.288815-1-derek.buitenhuis@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/2] avformat/http: Rename parse_set_cookie_expiry_time to parse_http_date X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: S8rWDS20DHTa That is what it actually does, and it will be needed for more than the Expiry header soon. Signed-off-by: Derek Buitenhuis --- libavformat/http.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index eecc4fd357..d324674e97 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -56,7 +56,7 @@ #define MAX_CACHED_REDIRECTS 32 #define HTTP_SINGLE 1 #define HTTP_MUTLI 2 -#define MAX_EXPIRY 19 +#define MAX_DATE_LEN 19 #define WHITESPACES " \n\t\r" typedef enum { LOWER_PROTO, @@ -913,29 +913,29 @@ static int parse_icy(HTTPContext *s, const char *tag, const char *p) return 0; } -static int parse_set_cookie_expiry_time(const char *exp_str, struct tm *buf) +static int parse_http_date(const char *date_str, struct tm *buf) { - char exp_buf[MAX_EXPIRY]; - int i, j, exp_buf_len = MAX_EXPIRY-1; - char *expiry; + char date_buf[MAX_DATE_LEN]; + int i, j, date_buf_len = MAX_DATE_LEN-1; + char *date; // strip off any punctuation or whitespace - for (i = 0, j = 0; exp_str[i] != '\0' && j < exp_buf_len; i++) { - if ((exp_str[i] >= '0' && exp_str[i] <= '9') || - (exp_str[i] >= 'A' && exp_str[i] <= 'Z') || - (exp_str[i] >= 'a' && exp_str[i] <= 'z')) { - exp_buf[j] = exp_str[i]; + for (i = 0, j = 0; date_str[i] != '\0' && j < date_buf_len; i++) { + if ((date_str[i] >= '0' && date_str[i] <= '9') || + (date_str[i] >= 'A' && date_str[i] <= 'Z') || + (date_str[i] >= 'a' && date_str[i] <= 'z')) { + date_buf[j] = date_str[i]; j++; } } - exp_buf[j] = '\0'; - expiry = exp_buf; + date_buf[j] = '\0'; + date = date_buf; // move the string beyond the day of week - while ((*expiry < '0' || *expiry > '9') && *expiry != '\0') - expiry++; + while ((*date < '0' || *date > '9') && *date != '\0') + date++; - return av_small_strptime(expiry, "%d%b%Y%H%M%S", buf) ? 0 : AVERROR(EINVAL); + return av_small_strptime(date, "%d%b%Y%H%M%S", buf) ? 0 : AVERROR(EINVAL); } static int parse_set_cookie(const char *set_cookie, AVDictionary **dict) @@ -995,7 +995,7 @@ static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies) // ensure the cookie is not expired or older than an existing value if ((e = av_dict_get(new_params, "expires", NULL, 0)) && e->value) { struct tm new_tm = {0}; - if (!parse_set_cookie_expiry_time(e->value, &new_tm)) { + if (!parse_http_date(e->value, &new_tm)) { AVDictionaryEntry *e2; // if the cookie has already expired ignore it @@ -1012,7 +1012,7 @@ static int parse_cookie(HTTPContext *s, const char *p, AVDictionary **cookies) e2 = av_dict_get(old_params, "expires", NULL, 0); if (e2 && e2->value) { struct tm old_tm = {0}; - if (!parse_set_cookie_expiry_time(e->value, &old_tm)) { + if (!parse_http_date(e->value, &old_tm)) { if (av_timegm(&new_tm) < av_timegm(&old_tm)) { av_dict_free(&new_params); av_dict_free(&old_params); @@ -1064,7 +1064,7 @@ static void parse_expires(HTTPContext *s, const char *p) { struct tm tm; - if (!parse_set_cookie_expiry_time(p, &tm)) { + if (!parse_http_date(p, &tm)) { s->expires = av_timegm(&tm); } } @@ -1295,7 +1295,7 @@ static int get_cookies(HTTPContext *s, char **cookies, const char *path, // if the cookie has expired, don't add it if ((e = av_dict_get(cookie_params, "expires", NULL, 0)) && e->value) { struct tm tm_buf = {0}; - if (!parse_set_cookie_expiry_time(e->value, &tm_buf)) { + if (!parse_http_date(e->value, &tm_buf)) { if (av_timegm(&tm_buf) < av_gettime() / 1000000) goto skip_cookie; }