From patchwork Sun Nov 14 17:27:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1554909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=CYBgMneH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::53a; helo=mail-ed1-x53a.google.com; envelope-from=swupdate+bncbcxploxj6ikrbm4oywgamgqen26rsqi@googlegroups.com; receiver=) Received: from mail-ed1-x53a.google.com (mail-ed1-x53a.google.com [IPv6:2a00:1450:4864:20::53a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HsfRq2Btzz9sWJ for ; Mon, 15 Nov 2021 04:28:23 +1100 (AEDT) Received: by mail-ed1-x53a.google.com with SMTP id r16-20020a056402019000b003e6cbb77ed2sf2176860edv.10 for ; Sun, 14 Nov 2021 09:28:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1636910900; cv=pass; d=google.com; s=arc-20160816; b=EaLWZ8Am+FhV3eBlS5vH9vEY2tsAVEQ8upuLH468usf+JuBjVysnizuYVFZmUwRUdY 6p31TbTCQpikNpAHBDU6EnFVwcrn/ftk61agapxmlBBNhzAxw72vgZK4lBy/oPC5ZEwA AwRWVm1xeYt/Vf0HyOHJiHHu7JqxN9BXbMdc/Lr1GLW9kox8fMaRJTqjeptnIjpKKgO7 ViM2khXW6z+bPT/6xO9L425r6JnX90Ob1fVq7uIvF+2nJ0/rqYDBFArBFK50zyZsqAe/ ERj7Qh0o8/BWnibnHuDSp8mGnXzu1ulaokbtFmmf7fbEw9tJhjx+rdSkTARMkFFm06pz o0XA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=Ilromw2X7yJ6fkMz9zp3yjudE4IS6t6k4q/qexDZevg=; b=gVMRwciMdbzYA2JUdQ15p5RQ88l+ymjytCyVM8XAmvE/CEJR8ybup+jbsjOKLAJ9P7 RtFt92XAMehjz/T7WJU3BpscFUDw9PSPHbi9t8zlGZk2Jy+s1wms7miz4apISkXpm08z 5grghb6IEo+4Xh5zxaW6KyWmldfiLviZV8KTiTqCpFwvtyq5vuDmPhAgwx0dgusJdWW7 yE2+lddZDD2rdElcTrfz7l0r+iX1Zy0iI8N/BwODQ5DcQJyqNYOZXoClsAdeQpFWidVZ HFlVL5EYpZo4TMB+3A7wK4D2EcjEcUlLPT4kJFO2FXXQAGjnhDe3NwekGZGI9uawKJCK 3qQQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Ilromw2X7yJ6fkMz9zp3yjudE4IS6t6k4q/qexDZevg=; b=CYBgMneHVQBlNhdFSjdpeFtDfGKmbZlf+aCP5Pde45baq4hzVCeGLmp2h3qVQ55R+x H3dfn2O4t/71+Eg/fRSpvvrKlt5qlVLE3+kwsZV7p/MyzcHBw+Mq1mmGTv70M6ZLtm7r aMfZRWsAkIsDjUtoNG/pFneWL6BvbQCqTqDi7wtgMOxf57eEHzSyhuCgutmvwM1jozOF pCDqz10CFUaDiOy60pBfyTUBqlbj19zUblWeaEqTY3YRbHKOy2YuWE0justRKmggmsCp tScaUsqf5ZJd9GVs/z8ccvNtweCDOEfHS2ouoYjH4Cwg4fD05bWHvv+sF8CV9KHk4zvt DzMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Ilromw2X7yJ6fkMz9zp3yjudE4IS6t6k4q/qexDZevg=; b=z5AQn9HJPmMBhnbf6iR7g/YpjpmOL3sV0/5Gws7byJ3CkhUVqluzA9x9awO2Aj+Oya 8eiOsocJYAcgZMLCmtrwRZS5YHDYHiv8vmpRk0eL8Qv/6AmleDfAwj+Qid6HSDsO/0rv wohRCseeP5ePyi0dZpgl+QPFNHAcxBdYCh6Yl0c6Qvq769RcoQNXUDiPUeXoG+8EpFcw 7xox6/nZXa6endOUL41uZWpJI1M13AfHZJlBv5x9VrwJLC0Hv44SchV8/8ZzMNDjGSj7 TWtWOl0eGvnajsZhs+GHrxIbrKuo386b8jIHD2z6Abf6YjF/diWgDA3w+EN/SUzRoWSZ 1v1w== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533xUlu4wreyA2xVrWuPAkGda8if0IHIoHWPMX9bvTSDkSrzI+3d GqQku/xzrtRxSpWysdrmRk4= X-Google-Smtp-Source: ABdhPJxUSJI1JU8ZbO6dvo2xlBHLPaz7cfXUg8LHzxMK02zLl5HvAnlt3/G/DmE3aq20zb7+mZVbBw== X-Received: by 2002:a17:906:1c56:: with SMTP id l22mr16697548ejg.208.1636910900036; Sun, 14 Nov 2021 09:28:20 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:aa7:c944:: with SMTP id h4ls3824632edt.1.gmail; Sun, 14 Nov 2021 09:28:19 -0800 (PST) X-Received: by 2002:aa7:cb86:: with SMTP id r6mr45203158edt.236.1636910899264; Sun, 14 Nov 2021 09:28:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636910899; cv=none; d=google.com; s=arc-20160816; b=WfvThibe3khM4BFw3GaHRfAF5jcgZJ9l19Q5S49A04MupSpURdMo1B/qvS7Gq9/J0B 4YD95yJyWqnSHfYydEDdLfp6thFIjjgOmZzNRT0ZOoOlapWkZcDrMonG7M2Nj5xAfFXG pQSjztC2XkGI0s9wZD+5GRNYEP3sXccZW26gyQcs4mXmnG94R6Klj5guG1doOQ+dXN8y cDztL6trskyu36LL1xQhcj76WA8kiBV/063ncaCCtwW7TS8qpo5ylu6BKI7nhJfBDcUu XwA4m1RhI9R+Btm1yVgyrmlh9nqHUSMD/H+MrbKo88TC20c7ccFyoi4oBd80IcfRrNhu 0oIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=uZ4XYBoErPW1Top5U6amX+UzF7uzJFLpN5mRtZOZ8fc=; b=jM+vl0FFD1ChKnfC4oB/A6VZepM42a8zfmIUxIj09702UkZHAVew3nPsIn/ee77U3J ixzGyATsZ739Lkrj/z1aFMtIUZmSnJ2CyK1P/c0mXS0tKCvbp6rY2WFjfv7NiAnojoRO ZgPMQDMq4biOIZJfft3eyKtSth8YhNwUqecdTHHucSd8G46C9tEBr0MhqUf4sAIeTi/V eTZiPX/FHJ1Ap6BfnGWEciNr+IxTO0GDo1shihVtRofpOb/OXkDp1nOl7+DMXpf6a8Qw f++bJhuc5NHLyf1EnMuM3l4as/Um00FqR3NQzlsAjYbuYEzIOvumZsmmGWkXNxWfXaJh LRfg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id bi21si922480edb.0.2021.11.14.09.28.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 14 Nov 2021 09:28:19 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4HsfRl0GS5z1qwdP; Sun, 14 Nov 2021 18:28:19 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4HsfRl07zqz1qqkB; Sun, 14 Nov 2021 18:28:19 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id uy9A8cdLLgRN; Sun, 14 Nov 2021 18:28:18 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Sun, 14 Nov 2021 18:28:18 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id EDBD74540853; Sun, 14 Nov 2021 18:28:17 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 4GJK4RnO5Qon; Sun, 14 Nov 2021 18:28:14 +0100 (CET) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id 2172D454275B; Sun, 14 Nov 2021 18:27:46 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH V2 18/36] channel_curl: allow an external callback for headers Date: Sun, 14 Nov 2021 18:27:15 +0100 Message-Id: <20211114172733.71602-19-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211114172733.71602-1-sbabic@denx.de> References: <20211114172733.71602-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Headers are handled automatically by the channel. Add an optional callback that the channel can call to handle the headers. Signed-off-by: Stefano Babic --- corelib/channel_curl.c | 63 +++++++++++++++++++++++------------------- include/channel_curl.h | 2 ++ 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 4ae2bed..4894c06 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -454,36 +454,43 @@ static size_t channel_callback_headers(char *buffer, size_t size, size_t nitems, { channel_data_t *channel_data = (channel_data_t *)userdata; struct dict *dict = channel_data->received_headers; - char *info = malloc(size * nitems + 1); + char *info; char *p, *key, *val; - if (!info) { - ERROR("No memory allocated for headers, headers not collected !!"); - return nitems * size; - } - /* - * Work on a local copy because the buffer is not - * '\0' terminated - */ - memcpy(info, buffer, size * nitems); - info[size * nitems] = '\0'; - p = memchr(info, ':', size * nitems); - if (p) { - *p = '\0'; - key = info; - val = p + 1; /* Next char after ':' */ - while(isspace((unsigned char)*val)) val++; - /* Remove '\n', '\r', and '\r\n' from header's value. */ - *strchrnul(val, '\r') = '\0'; - *strchrnul(val, '\n') = '\0'; - /* For multiple same-key headers, only the last is saved. */ - dict_set_value(dict, key, val); - TRACE("Header processed: %s : %s", key, val); - } else { - TRACE("Header not processed: '%s'", info); + if (dict) { + info = malloc(size * nitems + 1); + if (!info) { + ERROR("No memory allocated for headers, headers not collected !!"); + return nitems * size; + } + /* + * Work on a local copy because the buffer is not + * '\0' terminated + */ + memcpy(info, buffer, size * nitems); + info[size * nitems] = '\0'; + p = memchr(info, ':', size * nitems); + if (p) { + *p = '\0'; + key = info; + val = p + 1; /* Next char after ':' */ + while(isspace((unsigned char)*val)) val++; + /* Remove '\n', '\r', and '\r\n' from header's value. */ + *strchrnul(val, '\r') = '\0'; + *strchrnul(val, '\n') = '\0'; + /* For multiple same-key headers, only the last is saved. */ + dict_set_value(dict, key, val); + TRACE("Header processed: %s : %s", key, val); + } else { + TRACE("Header not processed: '%s'", info); + } + + free(info); } - free(info); + if (channel_data->headers) + return channel_data->headers(buffer, size, nitems, userdata); + return nitems * size; } @@ -610,12 +617,12 @@ channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_da goto cleanup; } - if (channel_data->received_headers) { + if (channel_data->received_headers || channel_data->headers) { if ((curl_easy_setopt(channel_curl->handle, CURLOPT_HEADERFUNCTION, channel_callback_headers) != CURLE_OK) || (curl_easy_setopt(channel_curl->handle, CURLOPT_HEADERDATA, - channel_data->received_headers) != CURLE_OK)) { + channel_data) != CURLE_OK)) { result = CHANNEL_EINIT; goto cleanup; } diff --git a/include/channel_curl.h b/include/channel_curl.h index fe68a99..456367d 100644 --- a/include/channel_curl.h +++ b/include/channel_curl.h @@ -71,6 +71,8 @@ typedef struct { bool nofollow; size_t (*dwlwrdata)(char *streamdata, size_t size, size_t nmemb, void *data); + size_t (*headers)(char *streamdata, size_t size, size_t nmemb, + void *data); struct swupdate_digest *dgst; char sha1hash[SWUPDATE_SHA_DIGEST_LENGTH * 2 + 1]; sourcetype source;