From patchwork Mon Sep 14 14:57:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Storm, Christian" X-Patchwork-Id: 1363679 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::33d; helo=mail-wm1-x33d.google.com; envelope-from=swupdate+bncbdd6bwv65qpbbuej735akgqehghniiq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=siemens.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20161025 header.b=lJTLvEHH; dkim-atps=neutral Received: from mail-wm1-x33d.google.com (mail-wm1-x33d.google.com [IPv6:2a00:1450:4864:20::33d]) (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 ozlabs.org (Postfix) with ESMTPS id 4BqqGG23Ccz9sWJ for ; Tue, 15 Sep 2020 00:57:26 +1000 (AEST) Received: by mail-wm1-x33d.google.com with SMTP id 23sf91029wmk.8 for ; Mon, 14 Sep 2020 07:57:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1600095440; cv=pass; d=google.com; s=arc-20160816; b=RwN8qGQJrB7kl7dKwShV2MuwS/SnEbOLPba3lucwhlNA4E0Fwjj27ls/2afi53pl5u kNv49CSAPBHgAXCdBnFi9QNs34uu+9JZWHj1VAhNoBncsk5EBPx3hAFCiW7Jf6+rh3KR nDhSsOXzPjhqBtosB9xmF7GJgMIbGJVF7aupi3fktd7p1zXgNmacQXMZVId+6VouiEQp Nkrfcw4wXFrqdfGmJ7Ar/tTTRc3oO0khZ2ZHKWfcLFGq7VwwSQhK0aG4J9xhVA4Pk6kx dBaTw65Twb+zU1Oo6ENB8XfmJWZQ8884Ectil/Yi6WaFuJNQrnAQ5JDI00CbrTUlaLJv 7M9A== 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=wiTxza5hZqBJ/PgrLD/B/3Yuew0LIDD48pkGDSC//H4=; b=zqTlMHAW2vITEV3t2RkTinRWDk49s8YMyHOLGgxoNmMbAH//PYjD2wwRqB/cIBHO8Z hDCA0BgxiYJqAGX09B1SeX+v4cWnTm+fjOrWwzIgj4991EKFStaO6WL4JfQT8156wPiM 0L4rMNV34dTXU1WzThT7YTY6Yw7iZfnKf4dM3ZS2raX1eXBmX2Mhqv+opSWWT7IdfwTU yEwdpbnxJqvHoP2fJbdJUw3Lw3z1EIvFy2El2hT0/PZrZFg4QDLRQnHjTMVaiGwvxZrQ rvTdOKn3jW8un1aIGRogwGNQHPUPRbQGEOUXOO615fa97zUZufP5+HQWRmJvbQhN0+Qf zKwA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; 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=wiTxza5hZqBJ/PgrLD/B/3Yuew0LIDD48pkGDSC//H4=; b=lJTLvEHH2RDbbpS0090XXc7choEC0cV5ZjtI4FV49Bl175d1slgQHqyXQ0ci8hJn6+ 295wSLmHgPmdBuPprKEqvo7WYOJliKQ5FAAX4cF09JcVv2qbuPPeKoPUHQO3hIt9CjED dYso+OnlW/L35LV3jYU7wfab+JW5ok/2puQTSklI/goKYl4ZxWt20QC5YStLcRjZBFth w3gvgm7gk6UX4oXvR2uNmA6QdrolM4elzSBaP16HJMB4Zyv8cahYW8vQ4XQpPB1/o8ug cQ5jJCknsYpTVF1sWSkvvxwIk5jdf8Mm7bRRSsm2A57TYrQAk9wlzqUPeTuJ1fuf371I dzIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; 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=wiTxza5hZqBJ/PgrLD/B/3Yuew0LIDD48pkGDSC//H4=; b=Xbv2f2mMbNbBol9sUjDe2jghOmaf6oAYjRP+FrsDk0yt4kT8GY2xQRzBzX2oJJ1VNo uysOkmuDWNgQLYe/zCrUeb5/ei4NE/HQAirM4DyrpScqJxdFOMQnlS8dAXU+AOUMYuo1 DZSlyOk4tLHry8hArK3FEc5PwfUZkaBH6wFxmig5CNYVXaJtQXM308cAHU1h8PEx+RBk eEeWz1kNy5xrewqtDJ73x4/Tp/xU5HkwCIMBWfV8k3XDN2A7Qu+T6Ky99sJGfWkmH9hf r9j80tpxy3hM+qCbh7VmVKmMIphV/GApA2BJiNXiyNmREdkHDHCw/uJzqtCL4KbMXGTh AhzQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM533D2Ym6GQg8Jj/tEPpOzpyGMJkFGBrUsgBXSOKIDBwgO7z+2ser 10uW7YSP0LGQt5m2Nm7Hfp4= X-Google-Smtp-Source: ABdhPJyMnpnUyaiFziyBlYSp327m2QifZABIYxPwFJCY3pcpZVJ5L/oaldE7wh9DUV2KgxS1jRFpkg== X-Received: by 2002:a1c:f719:: with SMTP id v25mr11967229wmh.159.1600095440521; Mon, 14 Sep 2020 07:57:20 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:80d7:: with SMTP id b206ls4849012wmd.1.canary-gmail; Mon, 14 Sep 2020 07:57:19 -0700 (PDT) X-Received: by 2002:a1c:7918:: with SMTP id l24mr15869967wme.46.1600095439500; Mon, 14 Sep 2020 07:57:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600095439; cv=none; d=google.com; s=arc-20160816; b=0obz05gA/PeVCmONVsVueNdXYLx/04U8tKpmIraHOVxMsEbeYTZdYVF8j8Tl+lnCPq /SnakMkALK4k3uGC8NYNyTFHGHogJV990l4AkwFM6hm0Dpl8IXUoiNla2KFzVjf694QI 7rP5oUdzUfI0GpT8x6aNToPB9IHKT2NF7YhHCuhpOobqkeN1330cBSL+CKhZ/iy//+qV aQUcxy2O5w9sG59LYVrUdPOIbm2W7FSWnK/qCKVpzYLbCTP447pJCQMdtxFJDK8nMqF8 P5hj29yK2emWlUJHcYrOUlkcHCN0ycUFG+nfj1u8WBLZYMMifr9aq8xQpOLkY7XihohH XzWg== 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=G16roBHTNGzaplsk96SYMY7xKnH6tlHrGXxq017/xgs=; b=Ernoi1vMgzzy7arNx6BCF1bML/0LBb4TgeOSp46C9Dnjh5CCX/7ylubsANBZoe8m2T zYNt1EUKx5bVg1+MH67FwxTlKuk6LWSThaX/obZU1PFkThROzd49ZpJBca2usoUPd8+C RICadlibF8OxT8JFHfa/L1EgLaMEOc9IXkcJWwUjoPaIVJxxnx7NAzyoDEclggpF/xLr Um9wcS0ntwlBDx9zhz7ZyEhQC84IRkqL15OQYVhZvY5Bsnrl20UT1f6ziB0RIl/kyIfp tppmm55cY5c4l6RK+dQ/6FT0XzN47HYfyJjHdT2bzeFgxrOEMfrPdkTxQ9u/Y7nognd3 42gg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id 21si345520wmj.2.2020.09.14.07.57.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2020 07:57:19 -0700 (PDT) Received-SPF: pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id 08EEvJkC004721 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 14 Sep 2020 16:57:19 +0200 Received: from MD1ZFJVC.ad001.siemens.net ([139.22.42.140]) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id 08EEv7pU008872; Mon, 14 Sep 2020 16:57:18 +0200 From: Christian Storm To: swupdate@googlegroups.com Cc: Christian Storm Subject: [swupdate] [PATCH 13/14] channel_curl: Make setting channel operation method symmetric Date: Mon, 14 Sep 2020 16:57:11 +0200 Message-Id: <20200914145712.4989-13-christian.storm@siemens.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200914145712.4989-1-christian.storm@siemens.com> References: <20200914145712.4989-1-christian.storm@siemens.com> MIME-Version: 1.0 X-Original-Sender: christian.storm@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of christian.storm@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=christian.storm@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com 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: , Move setting the channel operation method to the method implementations so that channel_set_options() only sets options common to all methods. Signed-off-by: Christian Storm --- corelib/channel_curl.c | 63 +++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index b69eb3b..5142c71 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -60,8 +60,7 @@ size_t channel_callback_membuffer(void *streamdata, size_t size, size_t nmemb, write_callback_t *data); channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code); channel_op_res_t channel_map_curl_error(CURLcode res); -channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_data, - channel_method_t method); +channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_data); char *channel_get_redirect_url(channel_t *this); static void channel_log_effective_url(channel_t *this); @@ -475,9 +474,7 @@ static channel_op_res_t channel_set_content_type(channel_t *this, return result; } -channel_op_res_t channel_set_options(channel_t *this, - channel_data_t *channel_data, - channel_method_t method) +channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_data) { if (channel_data->low_speed_timeout == 0) { channel_data->low_speed_timeout = SPEED_LOW_TIME_SEC; @@ -620,27 +617,6 @@ channel_op_res_t channel_set_options(channel_t *this, } } - switch (method) { - case CHANNEL_GET: - if (curl_easy_setopt(channel_curl->handle, CURLOPT_CUSTOMREQUEST, - "GET") != CURLE_OK) { - result = CHANNEL_EINIT; - goto cleanup; - } - break; - case CHANNEL_PUT: - if ((curl_easy_setopt(channel_curl->handle, CURLOPT_PUT, 1L) != - CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_UPLOAD, 1L) != - CURLE_OK)) { - result = CHANNEL_EINIT; - goto cleanup; - } - break; - case CHANNEL_POST: - break; - } - if (channel_curl->proxy != NULL) { if (channel_curl->proxy != USE_PROXY_ENV) { if (curl_easy_setopt( @@ -808,8 +784,7 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) goto cleanup_header; } - if ((result = channel_set_options(this, channel_data, CHANNEL_POST)) != - CHANNEL_OK) { + if ((result = channel_set_options(this, channel_data)) != CHANNEL_OK) { ERROR("Set channel option failed."); goto cleanup_header; } @@ -822,7 +797,7 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) (curl_easy_setopt(channel_curl->handle, CURLOPT_POSTFIELDS, channel_data->request_body) != CURLE_OK)) { result = CHANNEL_EINIT; - ERROR("Set channel option failed."); + ERROR("Set POST channel method option failed."); goto cleanup_header; } if (channel_data->debug) { @@ -875,12 +850,18 @@ static channel_op_res_t channel_put_method(channel_t *this, void *data) goto cleanup_header; } - if ((result = channel_set_options(this, channel_data, CHANNEL_PUT)) != - CHANNEL_OK) { + if ((result = channel_set_options(this, channel_data)) != CHANNEL_OK) { ERROR("Set channel option failed."); goto cleanup_header; } + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_PUT, 1L) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_UPLOAD, 1L) != CURLE_OK)) { + ERROR("Set PUT channel method option failed."); + result = CHANNEL_EINIT; + goto cleanup_header; + } + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_READFUNCTION, put_read_callback) != CURLE_OK) || (curl_easy_setopt(channel_curl->handle, CURLOPT_INFILESIZE_LARGE, @@ -966,12 +947,18 @@ channel_op_res_t channel_get_file(channel_t *this, void *data) goto cleanup_header; } - if ((result = channel_set_options(this, channel_data, CHANNEL_GET)) != - CHANNEL_OK) { + if ((result = channel_set_options(this, channel_data)) != CHANNEL_OK) { ERROR("Set channel option failed."); goto cleanup_header; } + if (curl_easy_setopt(channel_curl->handle, CURLOPT_CUSTOMREQUEST, "GET") != + CURLE_OK) { + ERROR("Set GET channel method option failed."); + result = CHANNEL_EINIT; + goto cleanup_header; + } + for (int retries = 3; retries >= 0; retries--) { file_handle = ipc_inst_start_ext(channel_data->source, channel_data->info == NULL ? 0 : strlen(channel_data->info), @@ -1141,12 +1128,18 @@ channel_op_res_t channel_get(channel_t *this, void *data) goto cleanup_header; } - if ((result = channel_set_options(this, channel_data, CHANNEL_GET)) != - CHANNEL_OK) { + if ((result = channel_set_options(this, channel_data)) != CHANNEL_OK) { ERROR("Set channel option failed."); goto cleanup_header; } + if (curl_easy_setopt(channel_curl->handle, CURLOPT_CUSTOMREQUEST, "GET") != + CURLE_OK) { + ERROR("Set GET channel method option failed."); + result = CHANNEL_EINIT; + goto cleanup_header; + } + if ((result = setup_reply_buffer(channel_curl->handle, &wrdata)) != CHANNEL_OK) { goto cleanup_header; }