From patchwork Mon Nov 20 11:09:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23d; helo=mail-wm0-x23d.google.com; envelope-from=swupdate+bncbcxploxj6ikrbixqzliakgqeduz4bmi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="BzF6edpc"; dkim-atps=neutral Received: from mail-wm0-x23d.google.com (mail-wm0-x23d.google.com [IPv6:2a00:1450:400c:c09::23d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxK4wG3z9s5L for ; Mon, 20 Nov 2017 22:10:29 +1100 (AEDT) Received: by mail-wm0-x23d.google.com with SMTP id c82sf1473156wme.8 for ; Mon, 20 Nov 2017 03:10:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176227; cv=pass; d=google.com; s=arc-20160816; b=iGkngOVLv0F2WQ3K0nKt7TF3qE6d8rWkY56iVqpYgTOc8iMQjxyjs7Nk7z6oBn3skn 2kVTXD6s32At+wAtAtD+cKRttnbXv2R3+mGW3Az40/cVrlcbre7CB5PQBOPEhLekd52L zZohNGYKASRAabD64TbyaOSji2QI5Eas9xpXSBcRKpXDsBWYDIAs8wq8kyxVBTAYuKVs kvhgg5DIFZOAjQVHU2GWEK1/UF5cXV+92sIRD/cY/2oD4pxJJr8bVyOOwbGsnHoXy2WA xh9fBSLMU8N03NiE0XA934SvkRC3vY5S9ZpDdjqMnXein6Dt+krupN/B0bxFbeXnJR6u Snig== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=BqUN/4yJVGJrGZJ3IQ+BymyHDiKQCtrKxzdg9Gd0+EU=; b=qH4TGAso8uEqXuejDEg9Vpewj8KBBD5qB/efDctmhsu1SZNpjP3kPVUm3d/LQ54FNU 0lzxkcverHmeMtq+nh5tGnGaLmAiVLfO6d8l3zZ5NJkN1CTTzIx2EZCimHfDzb70ovuN x2tKmwEMRqt3dv4xT8qpLrjeexsysPKKMCh+88Mc4D3TrCXfhLazMhXCLpXnHiGefHeP 805/ZsXlslesvxrpEHvpkfI2lJvvuJNsiG3NlyAAm0lidCpuzBpOMMummsz3JvR4xAVH US1NmMREG2pXgJXnOLaqBvPIVpccmnRM/PLF1CKLy0zDRtYoekGsTWnhUIXbpZvV83t6 SYZg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=BqUN/4yJVGJrGZJ3IQ+BymyHDiKQCtrKxzdg9Gd0+EU=; b=BzF6edpcHVYR3fCPGjLXJ+Vc+t12AE0XydNYUlarJjPZayxg81XsJ2Bdn84lOy03eY FdokV9/G0uMbkf+qNgr56NgDo4iOD1/LAInPkwKnnudSQZRvc/On7kbu0Afc7cwison4 Bh0wdPwWQ8Iic37YmCNHAGffzlIEzc897DSRabJK/di7x6yByHRl8WSGxMosVeSlqWKz oe/y6CjEccG9IytVW4THrVFDND+QQeRmMgcYUfXeVENxIYf/RZtvjfzWSBcNtrcJT4IR ecgES3T79tiJgCZG4s3ja91tXdj+GF9cCB0ECGcxtQAdcd1U+xP3nxZeREBqukQxQZQa Qw4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id: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=BqUN/4yJVGJrGZJ3IQ+BymyHDiKQCtrKxzdg9Gd0+EU=; b=Yxq71KVo/O1LeZPo9ZlEsLQKjD6Tvufe+by27IX1vR4/SS8OscSMsWhd2ufTcbCbFK kpjVoahZ3+voI0ctgewVfSQrj8vHBQ8SwE3ygL4Rjo8lC33H+FIet3+w58MnbkxrtTo1 3abTiYfq0hZEV3/9c9ZuI36bTJ/EEa17pLouIb+opNVbmoTtrOR8AVlyV7HrHWkYDIsb P977EQsj8MoZkX3yCjZfIZ4XiMrVnR9DgX3sR4AVz2osa0GYbiZQ531/8oT7qQJ4VO4d BZYI/Kx/mTnSxKvKpNv/ykAaYKqqLQJ4Xx2OpdnAl66OheLwqPACNQXW5864EmowTHe4 zlPQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX7o5Je0omQq/g1EVgmAFgbcuN5t3Y3+zhjxeBWfjuDY59/m0qzL vwHrIGg4qeAREJLRscFnMRA= X-Google-Smtp-Source: AGs4zMZHZDHIWdi0EekORDXG7PReIvCleZDv7d2xoVdNgHpaChAv4rCw0mTSFlukuWt3WxPoxxISXA== X-Received: by 10.28.199.8 with SMTP id x8mr143617wmf.1.1511176226976; Mon, 20 Nov 2017 03:10:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.170.48 with SMTP id o45ls4966752edc.3.gmail; Mon, 20 Nov 2017 03:10:26 -0800 (PST) X-Received: by 10.80.206.3 with SMTP id y3mr4232287edi.11.1511176226823; Mon, 20 Nov 2017 03:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176226; cv=none; d=google.com; s=arc-20160816; b=0o68LYEYwHvieuoB7ZakjW9JfqwWXLaGv/hDKjnedy1RHOFOYYWvsLWthuxN/YTErg QypEyWywqkyLs7hYACI8/PfY07AOmnxxXSt6RvsFn6xBqq7Zr9jgWFSTQBeW1gQzjEeH bfO0P6xjaA7mjydmkXp9Nv0byRiYzdJWGTRVMCnKyHUVZ8IXlFC5gBNAI1GBvH83/fq/ 61ktF/DJ9ubYKLSWTZijYdy6qGzzBXoa3xDS3W9FUqZaKQqG62LafAqFtHQc3IR3CdFK GWkkR8MoJg9e5yDPXUyFyqD38qyvE5hwlo5Uygu6pz5j44GnfyrJ/vLOK5JkKtS6+xCu zwHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=2f9SDDJ27QPybdUKpmR9PAEGivRQNkFmjRovjFsisko=; b=wiFi0GPRzRvlcBtwgbQ4V0jjZK5FbBWte/1jmX9SWimrqQb7mcp/3ewLRjZp/qIwO4 AiZW66PfJETu71nU0CElkJanooNlITHuZwfT6eym0yOSpqiSKRlveaBpZn2vA5guZRjj AeljS2v/6PcZhpIGhUDhC1XJ55a60O29M5MO+aKDskWlq+tRNTQqaFJDHkmOTShI9Ysd 9m+xwH0PuzGFtdDuL6VGd5fGj2cKEIu1sOgxaJdX4G86V3p/eZUoXgVJ5+J5QISDISPP IChsdlkcWVhakf9qt5Clhz1EnM/yhQwUD24gk+8NBJQvBhdwmRUxidjkwwQIgauNpqMI ub+Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 a67si768927edf.3.2017.11.20.03.10.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:26 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxG41fkz1qsDt; Mon, 20 Nov 2017 12:10:26 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxG3mmJz1qqkZ; Mon, 20 Nov 2017 12:10:26 +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 DSwz2i03c4Vj; Mon, 20 Nov 2017 12:10:25 +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; Mon, 20 Nov 2017 12:10:25 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 2DAC245405A9; Mon, 20 Nov 2017 12:10:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id y9OV1Kauyv-Y; Mon, 20 Nov 2017 12:10:19 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 02CF44540378; Mon, 20 Nov 2017 12:10:18 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 01/17] parser: added function to get net child in tree Date: Mon, 20 Nov 2017 12:09:54 +0100 Message-Id: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 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 best guess record for 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: , Add function to get next element in the sw-description Signed-off-by: Stefano Babic --- corelib/parsing_library.c | 15 +++++++++++++++ corelib/parsing_library_libconfig.c | 5 +++++ corelib/parsing_library_libjson.c | 12 ++++++++++++ include/parselib.h | 5 +++++ 4 files changed, 37 insertions(+) diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index eb3001f..79f3886 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -59,6 +59,21 @@ int get_array_length(parsertype p, void *root) return 0; } +void *get_child(parsertype p, void *e, const char *name) +{ + switch (p) { + case LIBCFG_PARSER: + return get_child_libconfig(e, name); + case JSON_PARSER: + return get_child_json((json_object *)e, name); + default: + (void)e; + (void)name; + } + + return NULL; +} + void *get_elem_from_idx(parsertype p, void *node, int idx) { switch (p) { diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c index 5624c99..f0cfb38 100644 --- a/corelib/parsing_library_libconfig.c +++ b/corelib/parsing_library_libconfig.c @@ -54,6 +54,11 @@ void get_value_libconfig(const config_setting_t *e, void *dest) } } +void *get_child_libconfig(void *e, const char *name) +{ + return config_setting_get_member(e, name); +} + void get_field_cfg(config_setting_t *e, const char *path, void *dest) { config_setting_t *elem; diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c index 12c95cc..2f64d41 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -49,6 +49,18 @@ json_object *find_json_recursive_node(json_object *root, const char **names) return node; } +void *get_child_json(json_object *e, const char *path) +{ + json_object *node = NULL; + + if (path) { + if (!json_object_object_get_ex(e, path, &node)) + return NULL; + } + + return node; +} + const char *get_field_string_json(json_object *e, const char *path) { const char *str; diff --git a/include/parselib.h b/include/parselib.h index c055721..c32920a 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -37,6 +37,7 @@ typedef enum { void get_value_libconfig(const config_setting_t *e, void *dest); void get_field_cfg(config_setting_t *e, const char *path, void *dest); +void *get_child_libconfig(void *e, const char *name); const char *get_field_string_libconfig(config_setting_t *e, const char *path); #else @@ -45,6 +46,7 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path); #define config_setting_lookup_string(a, b, str) (0) #define find_node_libconfig(cfg, field, swcfg) (NULL) #define get_field_string_libconfig(e, path) (NULL) +#define get_child_libconfig(e, name) (NULL) #define get_field_cfg(e, path, dest) #endif @@ -54,11 +56,13 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path); const char *get_field_string_json(json_object *e, const char *path); void get_value_json(json_object *e, void *dest); void get_field_json(json_object *e, const char *path, void *dest); +void *get_child_json(json_object *e, const char *name); json_object *find_json_recursive_node(json_object *root, const char **names); #else #define find_node_json(a, b, c) (NULL) #define get_field_string_json(e, path) (NULL) +#define get_child_json(e, name) (NULL) #define get_field_json(e, path, dest) #define json_object_object_get_ex(a,b,c) (0) #define json_object_array_get_idx(a, b) (0) @@ -72,6 +76,7 @@ void get_field_string_with_size(parsertype p, void *e, const char *path, char *d, size_t n); int get_array_length(parsertype p, void *root); void *get_elem_from_idx(parsertype p, void *node, int idx); +void *get_child(parsertype p, void *node, const char *name); void get_field(parsertype p, void *e, const char *path, void *dest); int exist_field_string(parsertype p, void *e, const char *path); void get_hash_value(parsertype p, void *elem, unsigned char *hash); From patchwork Mon Nov 20 11:09:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839507 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23e; helo=mail-wm0-x23e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbh7qzliakgqemkd7sxy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Mfp/hypy"; dkim-atps=neutral Received: from mail-wm0-x23e.google.com (mail-wm0-x23e.google.com [IPv6:2a00:1450:400c:c09::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxH5VlCz9s4s for ; Mon, 20 Nov 2017 22:10:26 +1100 (AEDT) Received: by mail-wm0-x23e.google.com with SMTP id b189sf6205676wmd.5 for ; Mon, 20 Nov 2017 03:10:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176223; cv=pass; d=google.com; s=arc-20160816; b=fW4T2ylWnRUfmr4DWYpolUvpDD2gZEkfoE/E7vCt3Z21U/tdeh0KJVEXPYC7uiOxYF TA54CJYbZceaW/AK+HSlMADmnyK/sp3bhfQ7rx27NBGTXoDEBVojsaXv6iTwM7634dz8 1K2Oeyuj2PSyU1ln4mUkGly8SSRBbO7utXwug821XRp/fJb5zzeZOfnoCcnAsifK8Zeo CWRxjL91SJzfM3tSRJldixDeBL8P1qXLtQm9h2Y9FaYaAGkv0mJGaJn/NpT/Scfo7n3e KkxrsLcMkMjkPKzTDogNqV4TJiJsZk+V4Hs4wSSWePOmPDLDcStOrikOFJ5Ay2yu3/+6 adLQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=6TS1gRYv4/iLVS6aW2jESLBSh9FlLC4nq4v6aZAQjlA=; b=ONE/BUnCZ2MP19ctqx3sr5Ty7ruJE+rvZ5Sedk+r6E6DGlIsjZV/WuWMBGq2dN6ORG WtnD18TMeO4zmesBaY38NCKUGUpfZn3SpUr7SDt0+wkh6BZ4nIfx5AQJpP8gLcQQ2hF2 XqJ/IKJA2gYgmNkiG9wmxg5rJ7w2OuTjc3UDehdwl8VbEmzK0Cx7J7yJrWYM9d4gBXXA LIynCNsLFYtAdSPwsHK6nDo9OoVHjmnnjNUybdBXZkpLPKBjAuxhjyC036pSm4945LEp Zxb53at26JYL6JxEo0IR/HOHTGJtpD+ihWEQ6NH6kwZdnDldT40FgSDyQVlX23pYtNtW nvLA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=6TS1gRYv4/iLVS6aW2jESLBSh9FlLC4nq4v6aZAQjlA=; b=Mfp/hypyoV75xC13aQI1J/oorvAV2Zxy26xEpYPgZcqK6weFstbQJDUQUeEIHnxjei xjM9QzmeJPyNFAq7prycUG37DPK7iLxIQBl2H9aZZfjbKf00KS0zjvWqlY2TuSHc1lEa ZZn8/6D2awXt/WyYPbOi4jDv/cWjJEnO+0vtHjKk7BL2tXtTDdI+5bVMCqi/zXKpTIPY QHOeUoPjEDvOeBf4LY0cpBprWmBY8ZxN5aBmrHikALSaGOF8yCN6yytZyLvXact+Zi2C 6LrIn4QrPXjDtJrTxq19s1INXLSVuuY9SXfjdZ5/mImXEqKJ/C0uqC4ZPzk73h9rHYx7 bvGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=6TS1gRYv4/iLVS6aW2jESLBSh9FlLC4nq4v6aZAQjlA=; b=BH/Qp2Q84Pk5tQTYMn+xQ20FB3yhhqsd+0otkUN0/LvVedcIm5D3gJd3bSpoAWAyqA O4U3qzpFaEVaqV4NkTHbWPd+waCzhHBA6bFtfHLqy8qsRAPOv1obo4wV9+EhVb7d4FGN XKrFXt3MPoAlKBWt9xkDt3Ooz6EPRu0fpFi8goWARyiL+HgJYJe8CfPQddjithcWp8bl kkajDdv10SQxv7zv4HvF3euOLD4M72IYZITHL+6Co3yapEBObppt6AjXYlB2MZ8C1yho b7oqqJbRzn7qrjL3+rMY28gMce+/8DqVOIwyJRSMUA4eXcr/39hdcp4gqLQdmwlfrknv WlJQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX5uCEoJMretshuXnSep95nf7TtaeWfic+7mfZrsAwdiiArJKvnc rzB6eufrO3IhVzZ3oKZbEEo= X-Google-Smtp-Source: AGs4zMb94wU0pyi4maPdLb3vUhsTYhY1eD/dx6RBRJNcY35cF//snMMlr4K2ZXwB6Hnd2NgtC/zYdw== X-Received: by 10.28.92.212 with SMTP id q203mr140522wmb.1.1511176223377; Mon, 20 Nov 2017 03:10:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.170.48 with SMTP id o45ls4966673edc.3.gmail; Mon, 20 Nov 2017 03:10:23 -0800 (PST) X-Received: by 10.80.195.1 with SMTP id a1mr443997edb.8.1511176222957; Mon, 20 Nov 2017 03:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176222; cv=none; d=google.com; s=arc-20160816; b=jSy6OC8TcKPcpxEQqR4RSLyFXlyrMXZw7ecEa0cqTPY6c9Asvs1buxG/Dd3sczIhPM k7XecID9cpKX8VqMEcDoJ1x7qo8KxxjGTWTefhFpaabRB6pr+exeyzKGedBSK8LF/B0i jynefkTvDptzF8EehYJh222tzK0divoVmm8cCVZDYRIf3RHiwn6zx+UG6gazpDV/Ey6Q tUXxijtCkqQXWJOYzJ/nDqIQs+CMvrEOj9aH4jdpr/aTxOxZbpTVvO1QrXM9H6QVkAV/ 1PI4Wn7U3ajQZpQ3nWWoPAxI9raAHdG1u9tQ/RJLQaAVOLHf/HtEo23aNtqd5QAH24bC Atxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=KAXzYtzNv4oMq/Oq+ucB+zCf2iwpXMQb+eGgs1o9aGE=; b=ikuXqGNXzmCTjqH8E8yftUle55qc8Y4L+8EstOd2hcqCMKbePntjVZWSd0Ll6RUzaK I7fvgQxBk2tF4s2sIg5H96sk8ISFjUktje4Su/IT2gaqxgMvbmhADkh2iEIPPwyWpSQC IOFOS62o6/HBTyVDY4sAPxPMwPWW99arro2CMIabMrXB6hJkr5w/FoXg4jaqA5iqHKAR MnfqSb976OVcfH3/dr3mxw67hMU/v9KahH9uvSAWlSjJ5zeroMwWdP8ddDcsvqI93lbU i1pEr2J98pL3etFULn6L/BK7vVYmOqxVVAScEjIUGM4Rz4PTyWx6z9X90dzczTqUTgla a9qQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 q7si823278edd.0.2017.11.20.03.10.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:22 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxB51vJz1qsDt; Mon, 20 Nov 2017 12:10:22 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxB4pZCz1qqkX; Mon, 20 Nov 2017 12:10:22 +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 o-_EBUWu-eL2; Mon, 20 Nov 2017 12:10:21 +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; Mon, 20 Nov 2017 12:10:21 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 61A7E45406EE; Mon, 20 Nov 2017 12:10:21 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q1FQKzrc-qKy; Mon, 20 Nov 2017 12:10:19 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 2558F454057C; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 02/17] dictionary: allow duplication of keys Date: Mon, 20 Nov 2017 12:09:55 +0100 Message-Id: <1511176210-28928-2-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , Add function to just insert and not replace an entry in a dictionary. This helps in case key is duplicated with more values. Signed-off-by: Stefano Babic --- corelib/swupdate_dict.c | 29 +++++++++++++++++------------ include/swupdate_dict.h | 1 + 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/corelib/swupdate_dict.c b/corelib/swupdate_dict.c index 1fc8007..46e8203 100644 --- a/corelib/swupdate_dict.c +++ b/corelib/swupdate_dict.c @@ -43,6 +43,22 @@ static struct dict_entry *get_entry(struct dictlist *dictionary, char *key) return NULL; } +int dict_insert_entry(struct dictlist *dictionary, char *key, char *value) +{ + struct dict_entry *entry = (struct dict_entry *)malloc(sizeof(*entry)); + + if (!entry) + return -ENOMEM; + + memset(entry, 0, sizeof(*entry)); + entry->varname = strdup(key); + entry->value = strdup(value); + + LIST_INSERT_HEAD(dictionary, entry, next); + + return 0; +} + char *dict_get_value(struct dictlist *dictionary, char *key) { struct dict_entry *entry = get_entry(dictionary, key); @@ -66,18 +82,7 @@ int dict_set_value(struct dictlist *dictionary, char *key, char *value) free(entry); } - entry = (struct dict_entry *)malloc(sizeof(*entry)); - - if (!entry) - return -ENOMEM; - - memset(entry, 0, sizeof(*entry)); - entry->varname = strdup(key); - entry->value = strdup(value); - - LIST_INSERT_HEAD(dictionary, entry, next); - - return 0; + return dict_insert_entry(dictionary, key, value); } void dict_remove_entry(struct dict_entry *entry) diff --git a/include/swupdate_dict.h b/include/swupdate_dict.h index 86f739e..1bd2f5e 100644 --- a/include/swupdate_dict.h +++ b/include/swupdate_dict.h @@ -33,6 +33,7 @@ LIST_HEAD(dictlist, dict_entry); char *dict_get_value(struct dictlist *dictionary, char *key); int dict_set_value(struct dictlist *dictionary, char *key, char *value); +int dict_insert_entry(struct dictlist *dictionary, char *key, char *value); void dict_remove(struct dictlist *dictionary, char *key); void dict_remove_entry(struct dict_entry *entry); From patchwork Mon Nov 20 11:09:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::237; helo=mail-wr0-x237.google.com; envelope-from=swupdate+bncbcxploxj6ikrbixqzliakgqeduz4bmi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="bmNmMi0p"; dkim-atps=neutral Received: from mail-wr0-x237.google.com (mail-wr0-x237.google.com [IPv6:2a00:1450:400c:c0c::237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxK5GYrz9s71 for ; Mon, 20 Nov 2017 22:10:29 +1100 (AEDT) Received: by mail-wr0-x237.google.com with SMTP id z75sf5840990wrc.5 for ; Mon, 20 Nov 2017 03:10:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176226; cv=pass; d=google.com; s=arc-20160816; b=e7TBkKX1/mx/ZbfsUJR2JAJs5UJR5CZlRNjb71oxmOQtw96RToesk1EuR3+CmQV7sG ib918XTnViyAdFp/LXDY2umEjM6jkGPnjsUTQebnd3jOphHHHGf0Ky/DJT35B2pePN0t OySW2YOEp6JITgqjLYhJboi7UwFr9i9ZxJ/bWILiQsKWex+GQJjvH6PycQqEe3XB7LFA bYA+ynIA2GEYd8oH9TyTHXGlimjX5OES1mgkn1fj6u7yFevXV6SmyOIAj6sn+Hibo8qQ 2DPot2uQ0AxI51mAkusUP32t8uLd10xqO3GsQDhQEgHKeCUov2RGkQoFSwaOfJo8OcXg Sxjg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=9jrYwMgwA2BXTm47gBbeIYebG09pDO8N/+NRVdHJYao=; b=xXWqG1Oq3iUGClUbUMtogFeiEhI0lQZaAD6csx0/TKk/o5sKsS73uLQvpwkaRwrxo0 tQHo41tyyWdoLOb/Rt8zSE+Jz91Y3cZRMtCcwhcEUmhFllza4JeXVlsVwC0Lf38/fl6X 2dbWh0ZEIcI+kmgBPkmOQshLljNsYUI3Pf+1rTgkqnG1TwxuE+aOtNV2+I5ZNkdZIshE GkrRuRcxPmF0+J1rcwbYZ0hVmR2kI0X1IR1PBz73L0FfZI8RGxSCSAE5QeNJc0xh0OVe zGwVaxWRRokDS1X3Yu0ubYUCn1rkGWUMcGH3IKxruEVLrJ2w6YvXRqAE6im032sbhRZI 6JEQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=9jrYwMgwA2BXTm47gBbeIYebG09pDO8N/+NRVdHJYao=; b=bmNmMi0pxdbkWKhRyKdr4x8P0tuCPX3st9HI5PvZom0gmPfA6y5cJG8EsrTc4R+mXG zysM6HvfFCtHUBD6a6CiP2YiFqK0K8XzPql95Zfb/dOrPyo+q30/ODSoevwXfNWNIq6v mhGImNAsvJstOHPrdRTHIbwPAJb3l3tEigVzS5WlVS8Pe4MU4zxITJCp8kD0rsvNg+dt KsLq2eShqxQ2doH55PZ6LNJdqvcfA+9he52hHgUP2JHfDZJIfaYyMMvY0lhGvvdD1Mv/ MaNSmuLyPJ+yjaJrpaXzJVEKOpaoN830+9cs6Yb6v9aQyM+2iAvBObFTOOYGnWvuS66e 7DNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=9jrYwMgwA2BXTm47gBbeIYebG09pDO8N/+NRVdHJYao=; b=W842rJ+Au/jc3GwzsPtaDYReMZruob9kfK3Oqhg1t8Db6A4loVXAqhSXXG/IUZCH7G IefkXZKMJzONwgYc9DkinxKCMk3WTTselFEdsCLLENHBRbWI1HvruyDe0JkZVdWY7je5 RTwAHhVQGeF+eeql5vPLfmB2W6Vnmthb8kI6Q0GJbMGe1Z3PRWbaKVarsJa2LwsQvQhg C8qXz9kicmkN+rJY+quYrCAoF0QJhcI50Jj0XRPlB7hfiQ46opeDPptFn+NVqjb2dKKL +Sn/zPwIHM9X4N5ODyxJp7ACgXgBDhFJDm8koqxJVk96RL4D+28ndsz6iuxcFK7KwtzS XqsQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4Fb5mlJcdIagDMCZ3/s0KZQJkfWD58NqwByA7ZZMB9vMyA8RVp t4IqcaP9qs6XMQG3s0XBprE= X-Google-Smtp-Source: AGs4zMbt5KP0pFCFENF9/IHGagTH2T3MSxxbnpbhtkqXsYL2zH3cdgTEq0VZmo+k6qV1t9Hexd1qjA== X-Received: by 10.28.133.11 with SMTP id h11mr141607wmd.0.1511176226515; Mon, 20 Nov 2017 03:10:26 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.139.130 with SMTP id n124ls888341wmd.10.canary-gmail; Mon, 20 Nov 2017 03:10:26 -0800 (PST) X-Received: by 10.28.132.74 with SMTP id g71mr1241564wmd.15.1511176225984; Mon, 20 Nov 2017 03:10:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176225; cv=none; d=google.com; s=arc-20160816; b=IGEv7+tQWKiY5MVfZoFvqcJaKWdb/dxfzV5CI2qboeH0W86Wrx+ekJ9PcKMSy3HrHp md6vdbOWAeoFoJL5Eiykkz+ZSiYjZVKcSHlR9iXE9XfVtBC/9CUAS8xFAtcRZ+eBm7PZ 0K/ARxpxZWnnCMU9pPl4m1P8pPUiodpYyCInWSREeGRL1yVRkzVGVTfR6YTvDjPLTWnw axfN8a7kxHcdfJPAcWRQbrasi1lpSi+CUn+wTK60j2x8T0zOUHz2nvDGwFuWtkOXM+UR 7F6FlUj322nprIdhJ9f8gE//adWpQEVdTcAgZcoWzG8cU+QffI4by4QubTMWylhwkl+Q zoaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=or3lPmc4IDWpYsmeqLdB07bDBKXV0+Ihfd3Hq3RcttU=; b=gAKWcYld08CEBAc+ubWOkXC/pg12Y0BSd29+FVvnANbmW00lEeuR5tUm8pNQUbYUwS tQj+tTFI063htP5G4JWv3KodUQcqG6gHAb58c4/QmmLcrL36NV3MShX2O7mOJSwJLyyi FV8XHGmv3CjxxTBnWCBXTZvBLMMRgl/ERuCUMpZv/MK7nK8UXf3JB3la88nkdb5CVHMi XsMzODMVSChCvRZGLQK3vyql6Fcu2yPALouYDFRcmP3qlHPOzH5sRDt4/HC6CKFg2cM+ kPnrRed+JYS73juW1UAA5HPvgkMXxnOkOK6UxYC76Ri1U88/yiYVYZuCZey8OQuZ3Xdn xAAw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id o2si681768wmf.1.2017.11.20.03.10.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:25 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxF5VTMz1qtFg; Mon, 20 Nov 2017 12:10:25 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxF5HBbz1qqkZ; Mon, 20 Nov 2017 12:10:25 +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 5YHmF2n0oJg1; Mon, 20 Nov 2017 12:10:25 +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; Mon, 20 Nov 2017 12:10:25 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id B7F82454057C; Mon, 20 Nov 2017 12:10:24 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GWZ_D0A745nD; Mon, 20 Nov 2017 12:10:21 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 3D01145405A9; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 03/17] dictionary: add utility to drop the database Date: Mon, 20 Nov 2017 12:09:56 +0100 Message-Id: <1511176210-28928-3-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for 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: , Add fucntion dict_drop_db() and call it from installer. Signed-off-by: Stefano Babic --- corelib/installer.c | 7 +++---- corelib/swupdate_dict.c | 9 +++++++++ include/swupdate_dict.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/corelib/installer.c b/corelib/installer.c index d2dee28..ae86d09 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -407,7 +407,6 @@ static void remove_sw_file(char __attribute__ ((__unused__)) *fname) void cleanup_files(struct swupdate_cfg *software) { char fn[64]; struct img_type *img; - struct dict_entry *bootvar; struct hw_type *hw; const char* TMPDIR = get_tmpdir(); @@ -433,9 +432,9 @@ void cleanup_files(struct swupdate_cfg *software) { LIST_REMOVE(img, next); free(img); } - LIST_FOREACH(bootvar, &software->bootloader, next) { - dict_remove_entry(bootvar); - } + + dict_drop_db(&software->bootloader); + snprintf(fn, sizeof(fn), "%s%s", TMPDIR, BOOT_SCRIPT_SUFFIX); remove_sw_file(fn); diff --git a/corelib/swupdate_dict.c b/corelib/swupdate_dict.c index 46e8203..4c8fb44 100644 --- a/corelib/swupdate_dict.c +++ b/corelib/swupdate_dict.c @@ -103,3 +103,12 @@ void dict_remove(struct dictlist *dictionary, char *key) dict_remove_entry(entry); } + +void dict_drop_db(struct dictlist *dictionary) +{ + struct dict_entry *var; + + LIST_FOREACH(var, dictionary, next) { + dict_remove_entry(var); + } +} diff --git a/include/swupdate_dict.h b/include/swupdate_dict.h index 1bd2f5e..d8edb63 100644 --- a/include/swupdate_dict.h +++ b/include/swupdate_dict.h @@ -36,5 +36,6 @@ int dict_set_value(struct dictlist *dictionary, char *key, char *value); int dict_insert_entry(struct dictlist *dictionary, char *key, char *value); void dict_remove(struct dictlist *dictionary, char *key); void dict_remove_entry(struct dict_entry *entry); +void dict_drop_db(struct dictlist *dictionary); #endif From patchwork Mon Nov 20 11:09:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23f; helo=mail-wm0-x23f.google.com; envelope-from=swupdate+bncbcxploxj6ikrbj7qzliakgqer2x2zci@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="q9EWOYPn"; dkim-atps=neutral Received: from mail-wm0-x23f.google.com (mail-wm0-x23f.google.com [IPv6:2a00:1450:400c:c09::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxQ37Z4z9s4s for ; Mon, 20 Nov 2017 22:10:34 +1100 (AEDT) Received: by mail-wm0-x23f.google.com with SMTP id b189sf6205862wmd.5 for ; Mon, 20 Nov 2017 03:10:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176231; cv=pass; d=google.com; s=arc-20160816; b=T6Gi5bdHQWLmr7ZUt/FRmTFUuMtGVcwxn49VekiESRQQUMKLPVvYni6UYoLz1SuDwL DkMyRFYPUwOBilxn4iYMZo68bstvI0RzxAu6UKRtaXNTDlmKY0WeBmFObCVxsZTxXld1 fQZVGGHcp80E0By31zV90EIsN4+nHqGlC1f56d88GvOnF0vhkU7nwd9MilbKFCD8MTi/ +5Ri+y79FvzDXgUajdT7oE2Ghv01/gIhXyHZkBkxNxCdWkPY87bRCrXQYahnSSD1DvwG PiJP4MDR1PenKT8XDdVbm3s0I+UFZtjjErR++Ts7xgQ7BMgeMBJxuWgQp+PHkPSCKijY iiGw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=iwGfbvXhcnB8P2687z0Zgxms4hLZPqL/gt57wy24yLw=; b=mVlS3J7xKYCSxijHrVBWzV5IGz169xbMHW63wA6wOXqgvl2w43RqNEJoD54nr6hoND DlAz8HlbW8XVRjZGFJpLj2tstUjg2SKZv+MUEixqZd9fIArqBWwwFfRFYDAk7a9Wf5By nzJSQt6Ock1ALGq3AmfRlZT218yrl95hUNmbR0dOPdzm1MwJTD/95qaFQaGJWf1D6Y95 akJTsXXjDRhv6pNMLzWsQiT45giLaeZ556dg4dV/jI1i0YeIFp+uhQnxxbuR+pFQA8/B JGH9QTy5KRWsPVxTyVTdlnw8VItxwazZy3SJiI922LnDw2mNZDT8iUQyPAx+im8KqF6g 6rWg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=iwGfbvXhcnB8P2687z0Zgxms4hLZPqL/gt57wy24yLw=; b=q9EWOYPnpop0SAf1c+cc5bJ36sqiVgZc1LKoJQIth096q2Ak/Ay6mQJxvW/mYYjTJS WLNKy956lrzf+2qxNsiO4Zg7QXC868tgkbha0zdWIZDOq0Ajvgjk+V1yN1ztFcC32oPR hqx5SpybtKHMopTeSnCh9owQWAsGozQ3aYbiJLkrv7aT54jqZBt08tpnDmziP4U+ODFL 9FkvqRgS5zktWlqn16xFMp+VB6ZxLOM+WgAFSjdN1EaKkSclXu6XkmmT5M5OKPAHd5TR w1/HbFHNlXBUtrT0nPMbgrEWokmQ1ugPT18U+oCnT7D9cX5SydwAJ1gScHo7K7TiN8Df xfiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=iwGfbvXhcnB8P2687z0Zgxms4hLZPqL/gt57wy24yLw=; b=I3Ai0FlRdOBha7g7DwgJdksSsPlku5hzlOTnfy2a44zPaNLIobKtSRAdwkjuUz9/Jw PZ8Kr9WXqqqPWTvV7xJl7VsrDfgQuWO8rwdX2cdUceoEQTWzd8IEQTLwmmTRVPY63ixo 9O3Io+Hij0TepcD86x09BL4DxYdVOlxaBfWrlT9+AkKdao2LkGRTuMQ+NUsdf82aH92G jYrotpSZI3zhwEwFUPvWIXDhDs+ODhcaSoW1l7Ogl85lE9mhwTOrCAQYQAln+pZ9yE0m B4mDDLUYl1tL/HbTADqPsH1PLNeb8WI58jmqtDIKzBI5RvbbuxdXDoCYfAbI6SvWVWYv 0Z/Q== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4jPbNSctFwjKQTHeGuSd+gQTWd1JRiBOGNTNplw+imeu03I7FW T4ucxyRZfhjO7NMZbAVn4ZU= X-Google-Smtp-Source: AGs4zMYn2Te4EYAvlLhHitVHnHs+VjbSPMKpGwH8nFMits9oW5dg2FxCpAnjhsCf4GjBiCATvtR2cQ== X-Received: by 10.28.198.67 with SMTP id w64mr117481wmf.6.1511176231582; Mon, 20 Nov 2017 03:10:31 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.197.15 with SMTP id v15ls893250wmf.2.canary-gmail; Mon, 20 Nov 2017 03:10:31 -0800 (PST) X-Received: by 10.223.151.204 with SMTP id t12mr1117864wrb.20.1511176231187; Mon, 20 Nov 2017 03:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176231; cv=none; d=google.com; s=arc-20160816; b=HkwFYFWoTBrH+pKHwWgP4um/l4dBPLNZeVlQ302i2oWPAyILT5Q75bfl+bFOa8Iyqn CtaD6JZjBSRG7iTzCVXcS6Uul024OhIzTsQArUoU3Py05zH5aQuh1hq/8pDnrxZodNVx OBGY8a+1LHxuXmbbVKuPouJeZfO8pdSs9/5+tCJ8tpg2dirnb6b815v7GW//yphKmS// 8fHQ/iEvvTavR+XHkD+UaYGWMY56F401nmdj6mi3ERGPC+n2mnLU8xOGTF1shujhp0S9 ojOh5MlSnfr6+7bBvdzPUi/oWYDmtu45DSMXBaktMpA6CvHmU92rh4rqbeFpPa4QiJsi 4XSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=KV74lM1gW13tCzC4fBeR6gZjlPOLD9KjvoC2PsB5etM=; b=iGTFYTgTLfWpxGgf63PMkcmWxAD6h7ATymgzIh86MxZACYV4O4jPLe8PkwigvCEtbn SNG7SuACL6x9/+Q0lhKCgFp6IZ7FulbULHHic/p4Mt5tWDPACvN08sxvpoAEN8L+juj2 R8oWYfs9jusKa6AB08aQ3jYVi7n7XwjTn0gGVnpT966gPj/0+FUGo7wytcY7FiwqeZJb 9k+osRP9MuGuNvIKLpKtlaK+gwpXPZ9XhBvZF9hyKlSEm1Xwvb6emUx72L++RYXvVpoF iGnqo4Mp62pknaGqj5/1ABc0rtRHMHmyioKV1GsVbKXbKDTD4qpAM3pVSUhCVIXi/KLB 4jMg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 j26si769426wmh.0.2017.11.20.03.10.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:31 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxL6xTQz1qsDt; Mon, 20 Nov 2017 12:10:30 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxL62Gpz1qqkj; Mon, 20 Nov 2017 12:10:30 +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 ShntdQRTyDUw; Mon, 20 Nov 2017 12:10:27 +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; Mon, 20 Nov 2017 12:10:27 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 1F54D4540378; Mon, 20 Nov 2017 12:10:27 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MY-hZJIgGT_q; Mon, 20 Nov 2017 12:10:24 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 57F024540623; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 04/17] Add set of properties for each image Date: Mon, 20 Nov 2017 12:09:57 +0100 Message-Id: <1511176210-28928-4-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , Support free to be set attributes for each image. They are set as forbootloader with a couple of , and put into a dictionary for each image. They are not used by the installer, but can be retrieved by the handler to trim the installation. Signed-off-by: Stefano Babic --- include/swupdate.h | 1 + parser/parser.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/swupdate.h b/include/swupdate.h index 09e81d5..f0a6c28 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -77,6 +77,7 @@ struct img_type { int install_directly; int is_script; int is_partitioner; + struct dictlist properties; long long partsize; int fdin; /* Used for streaming file */ off_t offset; /* offset in cpio file */ diff --git a/parser/parser.c b/parser/parser.c index fe70b3b..8dfb326 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -152,6 +152,35 @@ static void *find_node(parsertype p, void *root, const char *node, return NULL; } +static void add_properties(parsertype p, void *node, struct img_type *image) +{ + + void *properties, *prop; + int count, i; + + properties = get_child(p, node, "properties"); + if (properties) { + count = get_array_length(p, properties); + + TRACE("Found %d properties for %s:", count, image->fname); + + for (i = 0; i < count; i++) { + char key[255]; + char value[255]; + prop = get_elem_from_idx(p, properties, i); + GET_FIELD_STRING(p, prop, "name", key); + GET_FIELD_STRING(p, prop, "value", value); + TRACE("\t\tProperty %d: name=%s val=%s ", i, + key, + value + ); + if (dict_insert_entry(&image->properties, key, value)) + ERROR("Property not stored, skipping..."); + + } + } +} + #ifdef CONFIG_HW_COMPATIBILITY /* * Check if the software can run on the hardware @@ -466,7 +495,10 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua "Version must be checked" : "" ); + add_properties(p, elem, image); + if (run_embscript(p, elem, image, L, swcfg->embscript)) { + dict_drop_db(&image->properties); free(image); return -1; } @@ -537,7 +569,10 @@ static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_ (strlen(file->id.name) && file->id.install_if_different) ? "Version must be checked" : ""); + add_properties(p, elem, file); + if (run_embscript(p, elem, file, L, swcfg->embscript)) { + dict_drop_db(&file->properties); free(file); return -1; } From patchwork Mon Nov 20 11:09:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23a; helo=mail-wm0-x23a.google.com; envelope-from=swupdate+bncbcxploxj6ikrbkhqzliakgqeezkzafa@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="flbkfUtK"; dkim-atps=neutral Received: from mail-wm0-x23a.google.com (mail-wm0-x23a.google.com [IPv6:2a00:1450:400c:c09::23a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxR0GcVz9s5L for ; Mon, 20 Nov 2017 22:10:34 +1100 (AEDT) Received: by mail-wm0-x23a.google.com with SMTP id p65sf1962004wma.1 for ; Mon, 20 Nov 2017 03:10:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176232; cv=pass; d=google.com; s=arc-20160816; b=eMZjjr/7/znue6TijwuyM41A5tthftMC8OJgI4xZKJRAdYjFoXgIBAIQgN110U7OjC IbYL3yV1NBEaSUV9wOI7+WeF/L7Y1v07DrFFPEAul0aue48cx6uwzuOkuOe9O5JiUy9N aTVQWyqai3eCSkWi5wqW21XY/f+rEnq7DFzSeDvq4DJmgzgVPdunUBY8EvRirP9/0VOX aKAPpn2l+j3KvPjuPfWqUTu1LdKhy0ViUXDri1eihZ/+mdX3wwv7Esosvs2GNf+F2GsQ 3FA9tjUVxtTMa14mkEWMuV/qmE0Ds1LJLTbfD6RUcFMNbZSfABCWjkAF6tpgKvZ5jmdM gWkw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=zozAwAyzyWXaPwdsqT+zmB6p2Xwv439+10g0KxBr++A=; b=rFm1eE620y7+/X5flIqqknyAdi7sIuMfE06RXrKRrbaIePoi/7RY1HnngwGtyPcBRn C2qM+LRkcZv3ecPfsZp3KALSJnnPC0D23bPXVFIuPy80JakqPGmMxqzLBSiuZbL9iBhP pBM6dWgd5Y+BFbhFv1JrJzSrpOv5Xlk2wUXdz5aYxiXjckpEa32kHLxGzUpzMeR7EhYI 4mmY60UqcIMV5VGp1j1+W0PgwXKN1dd1gF6MAtmDPypJorx1J0amoqsqqY3r0mmsctM2 N/SqAL57M+BWCKbykoNtKPCeHjEO5cudV3XgGavH+52P1vjO4wMjI083mKHropBavEXq T/nA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=zozAwAyzyWXaPwdsqT+zmB6p2Xwv439+10g0KxBr++A=; b=flbkfUtKXI0FL7DHaWhi71AowTDFfEuXbMfvTDDE3dnJMBrZJCz2jd5pO8fIxoqTJa JBV9chWk1wcbtAxXn+zZRNfO7PplUmyznRxdwo7K/H3iWZrwufIgOoQbBkHoiBDIxbMO l1ZNtjoGijmgzOuYr9H3YO2LnP1BxFf55II1XfGTxxA579kmPDHD0/fHXNlelgZo9Heg NLpRqTHioGW6uS/tDU58l8YF+HqFdmm+BhvHJlHkXdjzPhyIPP+yWgbw2hrJdRKT9AhG H5ivdKc1EpTsG6Icsiyo1mTkztgIoa7XKiEVT2r69ESvLZ3Kdesg/OLkRnYeOk0YVhCH id8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=zozAwAyzyWXaPwdsqT+zmB6p2Xwv439+10g0KxBr++A=; b=uKoMPqlgeT6/VGDxlVuKjwQmQeWtHBHFLgkzNplBqmWBo5nlwJPhZAF9yTJ5DDtJQo 5/ucOoyJAh16cljB77lnllHu8cNuYRS3hntx6KrlGz3noqCmjmUpFZVy1oAwRXAI/eg/ R+tffiybppuT5lCnvnW7KjjRnoA/kWyJFxOiCoaIkHSwcAOAYoj83U7ywgv6pboiMP/+ jUnrNIn5x4Tl0gr7lunMY0rpdsqdulCix4HfF81G29692xEnhzvRL4N2IVmkOgDrNHyX mOzx80s3LSJ09COBrhQslhs4hNMajcX6ATfnDxx9pXXR6F3jJCsZsI9S2Yr4BIlA/W4+ gwHA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX5axU9nodVowlJ4JygUosWpXb6QNIzh63/+1wUVFnUmI4/kyxij eWQCL9sMoaUpOgJiufwCqys= X-Google-Smtp-Source: AGs4zMYbykyzFVCs0WQvlzDkIJQcL225Epw1hqALVZGF0lyZNvl9q0ZsRSaNrBlAe+EgvChwrEI4ZQ== X-Received: by 10.28.199.8 with SMTP id x8mr143620wmf.1.1511176232442; Mon, 20 Nov 2017 03:10:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.130.71 with SMTP id e68ls898327wmd.9.gmail; Mon, 20 Nov 2017 03:10:32 -0800 (PST) X-Received: by 10.223.157.206 with SMTP id q14mr155704wre.11.1511176232175; Mon, 20 Nov 2017 03:10:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176232; cv=none; d=google.com; s=arc-20160816; b=FAqp/Gkj4wi6VI3ePbdYmgBkbeFJ+UmLQCoubDG1HQwEbwVHOsMGhr20w2GMBKS1xE 4tuGWzY6caKHWVRKORJ/wRFGBwx2vHduUYuqUXUDmHheHg85oY220NGn1L5eiUTC9q81 p5G/xDj1dK6v/mLDiNVY4sr4qPzd+SQvvE6Ywr21iZGnziilZiOLKwuPRY9aD2beMZik bYNOcnyHAgSBOsWNDZn0sVfc0CFjBbzhvE6In0QLGYM4SHjR+a/AFQHM/qq71qFt2UQS NSeD3+MC+sCZDrTSAyUpGPIuz3g+PsN3FJECKInKBDbchvajbmHjCOJ9/DbQ1Bn+3JBN PBdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ebXDL02GH2Gz13gROglPBsQ0wq9mghqrt74X12up1Iw=; b=VO5CcZ/yzU203XHRIX0ARtEI3e9A4B+EkpecZypy7gEUV/W/v13KA69wd33FuoD0f3 BaQYh02PCX/D4Qc2crQyNIKwX2s6SXLXhH/i8HKzepWMmkeax79+EFD4T9gTiwIIDWTs rCYnkACn8y+9pCu0pJPMoxRENXSYkrr0hHCo/HB82eKa2ZnQRaRepDXFvpBI1NfjHhuk r3+ewOU+ERcxJhhfvNxDjCf6/nNRtC7b9Ip12mOkIBYTo4G06v6RnepCEWYSA1Bf80nI P2NLv5+fuXUvVFlXn6tYLp3+uQmbk1L2N3RHaRz7llj85Pzn/pFrybTKp2Xx0/nqegFj n2bQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 r70si388593wmg.2.2017.11.20.03.10.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:32 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxM6vlRz1qsDt; Mon, 20 Nov 2017 12:10:31 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxM6SL8z1qqkW; Mon, 20 Nov 2017 12:10:31 +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 SesQB9SbcaTw; Mon, 20 Nov 2017 12:10:30 +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; Mon, 20 Nov 2017 12:10:30 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 5E6C2454057C; Mon, 20 Nov 2017 12:10:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hXsyxJXzeixH; Mon, 20 Nov 2017 12:10:25 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 755A94540625; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 05/17] drop db properties in cleanup Date: Mon, 20 Nov 2017 12:09:58 +0100 Message-Id: <1511176210-28928-5-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , Signed-off-by: Stefano Babic --- corelib/installer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/corelib/installer.c b/corelib/installer.c index ae86d09..b874e7e 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -429,6 +429,7 @@ void cleanup_files(struct swupdate_cfg *software) { } remove_sw_file(fn); } + dict_drop_db(&img->properties); LIST_REMOVE(img, next); free(img); } From patchwork Mon Nov 20 11:09:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::23f; helo=mail-lf0-x23f.google.com; envelope-from=swupdate+bncbcxploxj6ikrblhqzliakgqei73teuq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="QqbMvbNk"; dkim-atps=neutral Received: from mail-lf0-x23f.google.com (mail-lf0-x23f.google.com [IPv6:2a00:1450:4010:c07::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxV6pTwz9s4s for ; Mon, 20 Nov 2017 22:10:38 +1100 (AEDT) Received: by mail-lf0-x23f.google.com with SMTP id i125sf1989529lfe.23 for ; Mon, 20 Nov 2017 03:10:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176236; cv=pass; d=google.com; s=arc-20160816; b=TMVkSO8ye5MVIlpOBcK3UgGVXlx2l1hBOPzv1hn8CKQTXfzDI+sFvjbG8vlE0JZuMi IlhpoUk++1GX2aONj1HtjDry40Svus8ntcO9QRJ+3eZ2L2RRmBHTPbnUqq3VNGazybk0 WBR4S4gvi/X42teIEFbsUdE3Anl9aZKGXzDDb8rXUN4jz7Rw/0nOU+oOx76q2wjLVdhW 6x32Ssc+E1vcZUm8XvC+vFd7gI5wTPu4zqiLvg0NpKu/5V7ju2fyCjivdqodnu9Uwk1f WRnRqCcWogGSvMdnwT09SdOPb6A2qSkHEKAq5baRAIBnag8iYdtgi6RdS2ch9+EbC1kn TGMA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=Xm1MAXtVjZBje4Yf0VtoDfE2xAHtgRoEtecGzbRw/Ts=; b=TPBadslSGBPkVD3d+cnE5qxdmzlPOt7tVSYEeQ/KMGJdtKOfkEwK6WYHSJoAhBBfvf sRURLqvnSTDwSkPAPMnHaEhkx7rOh13Q0odKkMZvuvw2FiV2URp83ZTFDC66SK4pCrC5 wRXDcvO++zUbbHidLbNfB34RaXfCXCB0MPSJ0De2ifgCMrBOzvpuOhAq8Aswysougd5a /YImi2ehYrw0YVa1NIde/pVhipJ1H9INaFWc/KFLpNTIrAvXz0moYNdd+7jRUCt9qUmE dF0/dsMf0I+vpwX6VlcozJ4fv0HeGAtU8n2PDqMN+NTHuVnEosAFVxd7Ne6uRBSep/NP 2krA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=Xm1MAXtVjZBje4Yf0VtoDfE2xAHtgRoEtecGzbRw/Ts=; b=QqbMvbNkGIaRQvVAvodCtvO37N7OvEeXI9EvYK7iszGzCZLxhc92rBo7GOIM+NsFRB cAtcbgRTpbaMLIEmMEYb31YhUlcr7bEuFhL4hZrRYMCVXJy4n985RZxs6jH729Qud0Ic d0r6fEg74K6M9KZ5Yvom+kft6/mZ+U50AEoNv090zwQ9bxH4OwyULL0PcgwOMQ6wTEPr ARWPTd8bNYHoTbl5K94iO4/r6leTCkoJZRRmkZux4Pp48EJBfGUqB4f8i45w6GLTW5jE i+0o8w4fuYE+ssyq54pWFSlCo3wOZjj19NiSA+zRgGm7uMM0rFWmLVnc5TF/ZTwyojWh lLuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=Xm1MAXtVjZBje4Yf0VtoDfE2xAHtgRoEtecGzbRw/Ts=; b=hNubbE3AuEnRXxQlJmzzAFmcib13ElslpIH7ef3KES4v9ZBKk6Tknwo3IoiHHCeQhg deO3ZcjOL2OAEU3UtHMEZjKmFe84mth5eC6tmUMsIv1dvuiB+t/Gqap2fKMBes6mkSOG 75OI0Tm5TOwdYYm8Veq1Rk4mKAURtU4aQrWQcIwe9jx35NhOrzAeODvYdoBnbD9qhv0h SmIojldby8h43fpwe/xf66fsPbh7QMHd5NwZOMKi4X6r9tI8o2U9lEtbNSK8AKhB3CO2 7izveoL4Meyr2gnBgwRRXyiw0QR+OOqNqsai1XaFBfmILZ5JIa1vluSEOMfRU2X0KxKm LuCw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX7JdoKNCS2BWejunFjOWScf4gxQmgK2cfz6PMpTP491DoWb69L3 cV111QabBsgVwy7sT38sfJ0= X-Google-Smtp-Source: AGs4zMaVqYvmojM1xFtb04J2vBrDdYotX8PrqxxVs8/lThFVNOIJUu2jbsii39ZJi0jtqLT9FqoC8A== X-Received: by 10.46.84.9 with SMTP id i9mr32867ljb.8.1511176236265; Mon, 20 Nov 2017 03:10:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.109.9 with SMTP id i9ls1374164ljc.14.gmail; Mon, 20 Nov 2017 03:10:35 -0800 (PST) X-Received: by 10.46.16.202 with SMTP id 71mr458065ljq.31.1511176235787; Mon, 20 Nov 2017 03:10:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176235; cv=none; d=google.com; s=arc-20160816; b=eJTdgoSuiY+oyiL7U2d+sZAp6PfCQOiLTIJPRVWmqvAYGAmq/5u/yUJ8X6XqX6EFfH G6cEau8jVEU11Ra9uC3Epy88RcWLpFuO0BNcP0LBb4UnFzIW6x21v0XJtq7WMQEF993y sFUdmRFg8+MLNr7NXxC2WCqOlTuSIt0D1IpvHSuYnocYroby345WDkiDf1jP7VHG95ij d3xHr5DlWAi5oP2/xHG+G1ow3UPPa+L3azNkUtG0805dYqZFInaKrqEb8VLeFGWU1vz1 Lik6YG7jeCaMe83j5CPYSgv047p+Ozp40N5D2aoaMXPx1xRTf707yVuRT2QYuYynGT0u PROQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=z9Xk3hcXjDpbZgk9iBevck/4DsszlyR0w/AdTQnPJEM=; b=KnH2SPIbFqXdFY4iTMvy/TVUwm52ze4yjSx1WdHU94VEz7ayxmzUgN7AvhyN9rMkkp bLQD8gpk/qaVrAkRPQGGZ1+mu1hwadZA2n4fgFZmA7KJLczXhx0Si71lxP5YSotBcJYR 2853+XW+P3MrHpZ9ofNjqYk4PydjCzFdFEL05pbFQmOdLQ02LDnsKSEGjLpOSFJ0TAgx dYrZfUajnjTk9qUxoh6YJd1wyz+dA2FmzlV+pHhseSnzyvN65d1l6Lk4q8UVZvQvcPGh TR/RgrDKA2nMQ2P/DxagM3ZngpyjVGr0hpYtHkIaA4QJ9PC1WpIbumjdA0GzlixrICqm WKLw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id b78si803764ljf.3.2017.11.20.03.10.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:35 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxR29Nzz1qtFg; Mon, 20 Nov 2017 12:10:35 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxR1xDKz1qqkW; Mon, 20 Nov 2017 12:10:35 +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 dSsSeGHJLBo4; Mon, 20 Nov 2017 12:10:30 +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; Mon, 20 Nov 2017 12:10:30 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id D7B5C45405A9; Mon, 20 Nov 2017 12:10:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ov8JXRNqsiE2; Mon, 20 Nov 2017 12:10:27 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 8CE9C4540626; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 06/17] Kconfig: adding a CURL switch Date: Mon, 20 Nov 2017 12:09:59 +0100 Message-Id: <1511176210-28928-6-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for 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: , A CONFIG_CURL is introduced to move curl code into a separate library. Signed-off-by: Stefano Babic --- Kconfig | 5 +++++ Makefile.flags | 2 +- suricatta/Config.in | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Kconfig b/Kconfig index 4d244bc..e46ff05 100644 --- a/Kconfig +++ b/Kconfig @@ -61,6 +61,10 @@ menu "Swupdate Settings" menu "General Configuration" +config CURL + bool + default n + config SYSTEMD bool "enable systemd support" default n @@ -278,6 +282,7 @@ config DOWNLOAD bool "Enable image downloading" default n depends on HAVE_LIBCURL + select CURL help Enable update from image URL using libcurl. The stream is sent via IPC to the installer as it is done for other interfaces. diff --git a/Makefile.flags b/Makefile.flags index c9f32f5..041a08e 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -113,7 +113,7 @@ endif endif # Image downloading support -ifneq ($(CONFIG_DOWNLOAD),) +ifneq ($(CONFIG_CURL),) LDLIBS += curl endif diff --git a/suricatta/Config.in b/suricatta/Config.in index 554ee61..62e448a 100644 --- a/suricatta/Config.in +++ b/suricatta/Config.in @@ -72,6 +72,7 @@ config SURICATTA_HAWKBIT depends on HAVE_LIBCURL depends on HAVE_JSON_C select JSON + select CURL help Support for hawkBit server. https://projects.eclipse.org/projects/iot.hawkbit From patchwork Mon Nov 20 11:10:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::239; helo=mail-lf0-x239.google.com; envelope-from=swupdate+bncbcxploxj6ikrbm7qzliakgqeshuxvdy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="n3dHDh75"; dkim-atps=neutral Received: from mail-lf0-x239.google.com (mail-lf0-x239.google.com [IPv6:2a00:1450:4010:c07::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxf3F9Fz9s4s for ; Mon, 20 Nov 2017 22:10:46 +1100 (AEDT) Received: by mail-lf0-x239.google.com with SMTP id w23sf2034368lfd.4 for ; Mon, 20 Nov 2017 03:10:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176243; cv=pass; d=google.com; s=arc-20160816; b=GWjZbK7hdciYEO6aMShXAM7c3Rp9mbMWOmPZatbPAK66JBBC7mzb/dY7z1PJm8iGyI tDJ6bczMGHY9uUxr4N1h/XI4DOHsy3lAe6MzATg0PJiOAe6TIHhjxTjVVN4zWwSbFBan mdzDZ4XprjIUKMux0cFIF/vjS79kJlxtsgUzCEJfXu7/yjrdf10dl1lcCeTesCQkeg4u MXRis8GGUxefAl/eYXr0IAQZ5P7gWSj+sWmbekEoFlfDMzO9x1rcR9PNZ5a+51KXt+zh iFUgzgf5MAWUAZt/OVCBk4xHsXiRtfJ8ZaBohVSHQWV3T6NHSwbKn107ETGueUAz/Lga a/+A== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=hhOAAkuRMFXwOlzRojv7Q5vW3pMQpwNNIV6qan7O4Ss=; b=TBqSzSiJkZAdo06lurk6barZxfsXqP2A/C/zO2oUINgqvAPoCGCUgPmf9gy/w533jI 49wovHScUrgqfdQ23MQHjwOnpCg9UBjD1WPb4JoWI1nQw7ildpQ5ATZ5TZXMXy1B+5Ck yBAvQD8Ntg4zAbZ83fYkhR5lXeCWYeEtRPLbVOFifkcsd0Jk4SrgrUF1ChJEHN6Ac3ef 2L7/3KMu2VwBxa+Vdcc/ugJKdb5ZhnHm+kjOQbum8rUL3pZ2v1RirSYcImEoFnQqZ5/6 bDD0xuqZn3M2puMnYgke3ZlPThfGxHS11V4WPArtmyWouHZUCXBQHTm0VAu8prj1KvE6 Lf5Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=hhOAAkuRMFXwOlzRojv7Q5vW3pMQpwNNIV6qan7O4Ss=; b=n3dHDh75LF14+u7GZRidrQmD70qcI6zuCpZ8zW5INchLy+m3JJpNRJM5PceRTdCFJF JZP0Jnv7UsnBlczBFGkN7Qav2Vb1xcGMrTeROoOyuv5RqLoemkDZKG+dqkOvVOCQMhSP QdwySCJwKPOlxm2lZqLNsH4a6uwYnn+ITMrxNvYqFMqokrVq6OiQQHTxUdORIJ4xuk2Y 0rrvwwcUapGk0JlM7wx4AX7FL5ffV5JbNHn/ASkcZtXR0K3RXC5CjKbH374gHVv2LDea EWuE92UzRASJnT1DgJ4ATHJ74E/08v7msDwZD2HI7sxDUwvbUry4OS5rtNvRp2Dog9Gb LMiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=hhOAAkuRMFXwOlzRojv7Q5vW3pMQpwNNIV6qan7O4Ss=; b=qbYy8Ppzv8IGJsiLY5DxZDoqkNrqGZulhE+/t1xUhB0ePgIeWo0D9L61/pT6bj2PBZ NAgOPhq9tVm/hfXbAlCGix5FRaxu9JcWekwGMvpUDs1fEWHEQSnd0rvjOO1byQqxE2zW Bl0kRuC3+TFWedScqz9RjtFy4ukiO8GzaEKk5FT+k2etYzMCXsx/Qiwf+QM6mXhFLZyp 9KgruPhY2Bdwx9Cz5B7APfKbogiNNUp7svPuQF2exjjOXYRnswJkXYY1us2dC1LO/gHU 9Yh03QgU4TbNMhJ1kym73sLPUmYlDzITgcQj9XcX1TwycT0aOOGp4W5gATei6QU0fC7N JyVw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4oTkf+EBzPg/ZW9mRM7xmr5EQJR8NWvqVOCjI00dzicvRpYpk3 U6arbP/RrgpYgcqa2Vx51zo= X-Google-Smtp-Source: AGs4zMZ4MtM/CpAWEgT/BFIH1k1A5r+fLCV2kYL0yOFoMfMtD0VdlSz1k0fnoq5fDGqy8eo811ynzg== X-Received: by 10.25.15.203 with SMTP id 72mr21695lfp.13.1511176243536; Mon, 20 Nov 2017 03:10:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.20.8 with SMTP id u8ls1374361ljd.9.gmail; Mon, 20 Nov 2017 03:10:43 -0800 (PST) X-Received: by 10.25.168.76 with SMTP id r73mr374551lfe.41.1511176243276; Mon, 20 Nov 2017 03:10:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176243; cv=none; d=google.com; s=arc-20160816; b=rAZjG3hjLxjn25lYV+pgAKIVo09ExEANwg1bKQVvbJPvlVyZe7aGkJTxS4Vj9/0aoH rEDX+WFRuWzSnJ8NdBqPmx1HjRlzTJfFfcxf0AX6j9xV5keV2UbK+mrRAxd+9VTxDqJm tuG4x2CGRX/ZM92/1ihScHdbJ8DYcYMkxmfnC3k/SKEkjIZp0kpmqa4EGZJs/oibETna KfS/og7BfdLwkOPlFsd2mMknVPgF3YoCZdDVe6JrmMu9uhMObdUqFOnYKfcE6VUi6V0C 51xp75T2VHMVqRslaawBdJkkTNoGqCdKkdPn4v7cEVLiW3zpv5sk90XCf6G+Owj6NY0t Ledw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ChO0IJV21Zs7CCYmDl2pPA7D0KwgjQyxJcfiGTH61TI=; b=VhyEa56rPva5ZZFQGv5jx5pf0h0hK/i3imxvFhMqvoObr566Hv6kaIOcHpyQ4B9AZA 5tqMS4UmJTyHwgNgNNf+CqXmK7dEZL7QA3XODsL4ooyhqRqmaskWu3eG2qg8SSTMS3tA 4qJHtFIu1C2FTInimS/+bV7zSBjdnGNA8J1BpUKgA+oCT3zxsI9SoljOxL318cow7Md0 kxRGvLipK4c1oQFuHbr07ObjF/4WHkaM5iEerGWHyRJIPPPtYgQJZZV1DhDOSzOXXa/P cSUjVg9DdCuvX6d2mPjJsETsawiJwbrjMb+0D4Zda76SPZnYI3lOvDa9TX25+Ho4M7Rd fDNw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id g190si691967lfg.4.2017.11.20.03.10.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:43 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxZ4lyQz1qqkr; Mon, 20 Nov 2017 12:10:42 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxZ4YD2z1qqkW; Mon, 20 Nov 2017 12:10:42 +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 T5apG_X6y9gy; Mon, 20 Nov 2017 12:10:36 +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; Mon, 20 Nov 2017 12:10:36 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 5C5124540623; Mon, 20 Nov 2017 12:10:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9Rlu8L82lgaJ; Mon, 20 Nov 2017 12:10:29 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id A49994540631; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 07/17] channel_hawkbit: move to corelib for reusing Date: Mon, 20 Nov 2017 12:10:00 +0100 Message-Id: <1511176210-28928-7-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for 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: , Open a channel via curl can be reused outside the Hawkbit server. Rename the file dropping the hawkbit suffix and move the code outside of suricatta. The code can be generalised to be used by any code that uses libcurl and JSON to communicate with a server. Signed-off-by: Stefano Babic --- corelib/Makefile | 1 + corelib/channel_curl.c | 941 ++++++++++++++++++++++++++++++++++++++++++++ include/channel_curl.h | 63 +++ suricatta/Makefile | 2 +- suricatta/channel_hawkbit.c | 941 -------------------------------------------- suricatta/channel_hawkbit.h | 63 --- suricatta/server_hawkbit.c | 2 +- 7 files changed, 1007 insertions(+), 1006 deletions(-) create mode 100644 corelib/channel_curl.c create mode 100644 include/channel_curl.h delete mode 100644 suricatta/channel_hawkbit.c delete mode 100644 suricatta/channel_hawkbit.h diff --git a/corelib/Makefile b/corelib/Makefile index 16767b2..693ad47 100644 --- a/corelib/Makefile +++ b/corelib/Makefile @@ -13,3 +13,4 @@ lib-$(CONFIG_ENCRYPTED_IMAGES) += swupdate_decrypt.o lib-$(CONFIG_LIBCONFIG) += swupdate_settings.o \ parsing_library_libconfig.o lib-$(CONFIG_JSON) += parsing_library_libjson.o +lib-$(CONFIG_CURL) += channel_curl.o diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c new file mode 100644 index 0000000..6c16592 --- /dev/null +++ b/corelib/channel_curl.c @@ -0,0 +1,941 @@ +/* + * Author: Christian Storm + * Copyright (C) 2016, Siemens AG + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_SURICATTA_SSL +#include +#endif +#include "suricatta/channel.h" +#include "channel_curl.h" +#include "suricatta/suricatta.h" + +#define SPEED_LOW_BYTES_SEC 8 +#define SPEED_LOW_TIME_SEC 300 +#define KEEPALIVE_DELAY 204L +#define KEEPALIVE_INTERVAL 120L + +typedef struct { + char *memory; + size_t size; +} output_data_t; + +typedef struct { + char *proxy; + char *effective_url; + CURL *handle; + struct curl_slist *header; +} channel_curl_t; + +typedef struct { + channel_data_t *channel_data; + int output; + output_data_t *outdata; +} write_callback_t; + +#ifdef CONFIG_SURICATTA_SSL +static SHA_CTX checksum_ctx; +#endif + +/* Prototypes for "internal" functions */ +/* Note that they're not `static` so that they're callable from unit tests. */ +size_t channel_callback_write_file(void *streamdata, size_t size, size_t nmemb, + write_callback_t *data); +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); +static void channel_log_effective_url(channel_t *this); + +/* Prototypes for "public" functions */ +channel_op_res_t channel_hawkbit_init(void); +channel_op_res_t channel_close(channel_t *this); +channel_op_res_t channel_open(channel_t *this, void *cfg); +channel_op_res_t channel_get(channel_t *this, void *data); +channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle); +channel_op_res_t channel_put(channel_t *this, void *data); +channel_t *channel_new(void); + + +channel_op_res_t channel_hawkbit_init(void) +{ +#ifdef CONFIG_SURICATTA_SSL +#define CURL_FLAGS CURL_GLOBAL_SSL +#else +#define CURL_FLAGS CURL_GLOBAL_NOTHING +#endif + CURLcode curlrc = curl_global_init(CURL_FLAGS); + if (curlrc != CURLE_OK) { + ERROR("Initialization of channel failed (%d): '%s'\n", curlrc, + curl_easy_strerror(curlrc)); + return CHANNEL_EINIT; + } +#undef CURL_FLAGS + return CHANNEL_OK; +} + +channel_t *channel_new(void) +{ + channel_t *newchan = (channel_t *)calloc(1, sizeof(*newchan) + + sizeof(channel_curl_t)); + + if (newchan) { + newchan->priv = (void *)newchan + sizeof(*newchan); + newchan->open = &channel_open; + newchan->close = &channel_close; + newchan->get = &channel_get; + newchan->get_file = &channel_get_file; + newchan->put = &channel_put; + } + + return newchan; +} + +channel_op_res_t channel_close(channel_t *this) +{ + channel_curl_t *channel_curl = this->priv; + + if ((channel_curl->proxy != NULL) && + (channel_curl->proxy != USE_PROXY_ENV)) { + free(channel_curl->proxy); + } + if (channel_curl->handle == NULL) { + return CHANNEL_OK; + } + curl_easy_cleanup(channel_curl->handle); + channel_curl->handle = NULL; + + return CHANNEL_OK; +} + +channel_op_res_t channel_open(channel_t *this, void *cfg) +{ + assert(this != NULL); + channel_curl_t *channel_curl = this->priv; + assert(channel_curl->handle == NULL); + + channel_data_t *channel_cfg = (channel_data_t *)cfg; + + if ((channel_cfg != NULL) && (channel_cfg->proxy != NULL)) { + channel_curl->proxy = channel_cfg->proxy == USE_PROXY_ENV + ? USE_PROXY_ENV + : strdup(channel_cfg->proxy); + if (channel_curl->proxy == NULL) { + return CHANNEL_EINIT; + } + } + + if ((channel_curl->handle = curl_easy_init()) == NULL) { + ERROR("Initialization of channel failed.\n"); + return CHANNEL_EINIT; + } + + return CHANNEL_OK; +} + +static channel_op_res_t result_channel_callback_write_file; +size_t channel_callback_write_file(void *streamdata, size_t size, size_t nmemb, + write_callback_t *data) +{ + if (!nmemb) { + return 0; + } + if (!data) + return 0; + result_channel_callback_write_file = CHANNEL_OK; +#ifdef CONFIG_SURICATTA_SSL + if (SHA1_Update(&checksum_ctx, streamdata, size * nmemb) != 1) { + ERROR("Updating checksum of chunk failed.\n"); + result_channel_callback_write_file = CHANNEL_EIO; + return 0; + } +#endif + if (ipc_send_data(data->output, streamdata, (int)(size * nmemb)) < + 0) { + ERROR("Writing into SWUpdate IPC stream failed.\n"); + result_channel_callback_write_file = CHANNEL_EIO; + return 0; + } + + if (data->channel_data->checkdwl && data->channel_data->checkdwl()) + return 0; + /* + * Now check if there is a callback from the server + * during the download + */ + + return size * nmemb; +} + +size_t channel_callback_membuffer(void *streamdata, size_t size, size_t nmemb, + write_callback_t *data) +{ + if (!nmemb) { + return 0; + } + if (!data) { + return 0; + } + + size_t realsize = size * nmemb; + output_data_t *mem = data->outdata; + + mem->memory = realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory == NULL) { + ERROR("Channel get operation failed with OOM\n"); + return 0; + } + memcpy(&(mem->memory[mem->size]), streamdata, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + return realsize; +} + +static void channel_log_effective_url(channel_t *this) +{ + channel_curl_t *channel_curl = this->priv; + + CURLcode curlrc = + curl_easy_getinfo(channel_curl->handle, CURLINFO_EFFECTIVE_URL, + &channel_curl->effective_url); + if (curlrc != CURLE_OK && curlrc == CURLE_UNKNOWN_OPTION) { + ERROR("Get channel's effective URL response unsupported by " + "libcURL %s.\n", + LIBCURL_VERSION); + return; + } + TRACE("Channel's effective URL resolved to %s\n", + channel_curl->effective_url); +} + +channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code) +{ + channel_curl_t *channel_curl = this->priv; + CURLcode curlrc = + curl_easy_getinfo(channel_curl->handle, CURLINFO_RESPONSE_CODE, + http_response_code); + if (curlrc != CURLE_OK && curlrc == CURLE_UNKNOWN_OPTION) { + ERROR("Get channel HTTP response code unsupported by libcURL " + "%s.\n", + LIBCURL_VERSION); + return CHANNEL_EINIT; + } + switch (*http_response_code) { + case 0: /* libcURL: no server response code has been received yet */ + DEBUG("No HTTP response code has been received yet!\n"); + return CHANNEL_EBADMSG; + case 401: /* Unauthorized. The request requires user authentication. */ + case 403: /* Forbidden. */ + case 405: /* Method not Allowed. */ + case 407: /* Proxy Authentication Required */ + case 503: /* Service Unavailable */ + return CHANNEL_EACCES; + case 400: /* Bad Request, e.g., invalid parameters */ + case 404: /* Wrong URL */ + case 406: /* Not acceptable. Accept header is not response compliant */ + case 443: /* Connection refused */ + return CHANNEL_EBADMSG; + case 429: /* Bad Request, i.e., too many requests. Try again later. */ + return CHANNEL_EAGAIN; + case 200: + case 206: + return CHANNEL_OK; + case 500: + return CHANNEL_EBADMSG; + default: + ERROR("Channel operation returned unhandled HTTP error code " + "%ld\n", + *http_response_code); + return CHANNEL_EBADMSG; + } +} + +channel_op_res_t channel_map_curl_error(CURLcode res) +{ + switch (res) { + case CURLE_NOT_BUILT_IN: + case CURLE_BAD_FUNCTION_ARGUMENT: + case CURLE_UNKNOWN_OPTION: + case CURLE_SSL_ENGINE_NOTFOUND: + case CURLE_SSL_ENGINE_SETFAILED: + case CURLE_SSL_CERTPROBLEM: + case CURLE_SSL_CIPHER: + case CURLE_SSL_ENGINE_INITFAILED: + case CURLE_SSL_CACERT_BADFILE: + case CURLE_SSL_CRL_BADFILE: + case CURLE_SSL_ISSUER_ERROR: +#if LIBCURL_VERSION_NUM >= 0x072900 + case CURLE_SSL_INVALIDCERTSTATUS: +#endif +#if LIBCURL_VERSION_NUM >= 0x072700 + case CURLE_SSL_PINNEDPUBKEYNOTMATCH: +#endif + return CHANNEL_EINIT; + case CURLE_COULDNT_RESOLVE_PROXY: + case CURLE_COULDNT_RESOLVE_HOST: + case CURLE_COULDNT_CONNECT: + case CURLE_INTERFACE_FAILED: + case CURLE_SSL_CONNECT_ERROR: + case CURLE_PEER_FAILED_VERIFICATION: + case CURLE_SSL_CACERT: + case CURLE_USE_SSL_FAILED: + return CHANNEL_ENONET; + case CURLE_OPERATION_TIMEDOUT: + case CURLE_SEND_ERROR: + case CURLE_RECV_ERROR: + case CURLE_GOT_NOTHING: + case CURLE_HTTP_POST_ERROR: + case CURLE_PARTIAL_FILE: + return CHANNEL_EAGAIN; + case CURLE_OUT_OF_MEMORY: + return CHANNEL_ENOMEM; + case CURLE_REMOTE_FILE_NOT_FOUND: + return CHANNEL_ENOENT; + case CURLE_FILESIZE_EXCEEDED: + case CURLE_ABORTED_BY_CALLBACK: + case CURLE_WRITE_ERROR: + case CURLE_CHUNK_FAILED: + case CURLE_SSL_SHUTDOWN_FAILED: + return CHANNEL_EIO; + case CURLE_TOO_MANY_REDIRECTS: + return CHANNEL_ELOOP; + case CURLE_BAD_CONTENT_ENCODING: + case CURLE_CONV_FAILED: + case CURLE_CONV_REQD: + return CHANNEL_EILSEQ; + case CURLE_REMOTE_ACCESS_DENIED: + case CURLE_LOGIN_DENIED: + return CHANNEL_EACCES; + case CURLE_OK: + return CHANNEL_OK; + default: + return CHANNEL_EINIT; + } +} + +channel_op_res_t channel_set_options(channel_t *this, + channel_data_t *channel_data, + channel_method_t method) +{ + channel_curl_t *channel_curl = this->priv; + channel_op_res_t result = CHANNEL_OK; + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_URL, + channel_data->url) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_USERAGENT, + "libcurl-agent/1.0") != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_LOW_SPEED_LIMIT, + SPEED_LOW_BYTES_SEC) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_LOW_SPEED_TIME, + SPEED_LOW_TIME_SEC) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_HTTPHEADER, + channel_curl->header) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_MAXREDIRS, -1) != + CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_FOLLOWLOCATION, 1) != + CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_REDIR_PROTOCOLS, + CURLPROTO_HTTP | CURLPROTO_HTTPS) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, + CURLOPT_CAINFO, + channel_data->cafile) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, + CURLOPT_SSLKEY, + channel_data->sslkey) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, + CURLOPT_SSLCERT, + channel_data->sslcert) != CURLE_OK)) { + result = CHANNEL_EINIT; + goto cleanup; + } + + if (channel_data->strictssl == true) { + if ((curl_easy_setopt(channel_curl->handle, + CURLOPT_SSL_VERIFYHOST, + 2L) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, + CURLOPT_SSL_VERIFYPEER, + 1L) != CURLE_OK)) { + result = CHANNEL_EINIT; + goto cleanup; + } + } + else { + if ((curl_easy_setopt(channel_curl->handle, + CURLOPT_SSL_VERIFYHOST, + 0L) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, + CURLOPT_SSL_VERIFYPEER, + 0L) != CURLE_OK)) { + result = CHANNEL_EINIT; + goto cleanup; + } + } + + 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: + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_POST, 1L) != + CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_POSTFIELDS, + channel_data->json_string) != CURLE_OK)) { + result = CHANNEL_EINIT; + goto cleanup; + } + if (channel_data->debug) { + TRACE("Post JSON: %s\n", channel_data->json_string); + } + break; + } + + if (channel_curl->proxy != NULL) { + if (channel_curl->proxy != USE_PROXY_ENV) { + if (curl_easy_setopt( + channel_curl->handle, CURLOPT_PROXY, + channel_curl->proxy) != CURLE_OK) { + result = CHANNEL_EINIT; + goto cleanup; + } + } + if (curl_easy_setopt(channel_curl->handle, CURLOPT_NETRC, + CURL_NETRC_OPTIONAL) != CURLE_OK) { + result = CHANNEL_EINIT; + goto cleanup; + } + } + + CURLcode curlrc = + curl_easy_setopt(channel_curl->handle, CURLOPT_TCP_KEEPALIVE, 1L); + if (curlrc == CURLE_OK) { + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_TCP_KEEPIDLE, + KEEPALIVE_DELAY) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, + CURLOPT_TCP_KEEPINTVL, + KEEPALIVE_INTERVAL) != CURLE_OK)) { + ERROR("TCP Keep-alive interval and delay could not be " + "configured.\n"); + result = CHANNEL_EINIT; + goto cleanup; + } + } else { + if (curlrc != CURLE_UNKNOWN_OPTION) { + ERROR("Channel could not be configured to sent " + "keep-alive probes.\n"); + result = CHANNEL_EINIT; + goto cleanup; + } + } + +cleanup: + return result; +} + +static size_t put_read_callback(void *ptr, size_t size, size_t nmemb, void *data) +{ + channel_data_t *channel_data = (channel_data_t *)data; + unsigned int bytes; + size_t n; + + /* Check data to be sent */ + bytes = strlen(channel_data->json_string) - channel_data->offs; + + if (!bytes) + return 0; + + n = min(bytes, size * nmemb); + + memcpy(ptr, &channel_data->json_string[channel_data->offs], n); + channel_data->offs += n; + + return n; +} + +static channel_op_res_t channel_post_method(channel_t *this, void *data) +{ + channel_curl_t *channel_curl = this->priv; + assert(data != NULL); + assert(channel_curl->handle != NULL); + + channel_op_res_t result = CHANNEL_OK; + channel_data_t *channel_data = (channel_data_t *)data; + + if (channel_data->debug) { + curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); + } + + if (((channel_curl->header = curl_slist_append( + channel_curl->header, "Content-Type: application/json")) == + NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "Accept: application/json")) == NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "charsets: utf-8")) == NULL)) { + ERROR("Set channel header failed.\n"); + result = CHANNEL_EINIT; + goto cleanup_header; + } + + if ((result = channel_set_options(this, channel_data, CHANNEL_POST)) != + CHANNEL_OK) { + ERROR("Set channel option failed.\n"); + goto cleanup_header; + } + + CURLcode curlrc = curl_easy_perform(channel_curl->handle); + if (curlrc != CURLE_OK) { + ERROR("Channel put operation failed (%d): '%s'\n", curlrc, + curl_easy_strerror(curlrc)); + result = channel_map_curl_error(curlrc); + goto cleanup_header; + } + + channel_log_effective_url(this); + + long http_response_code; + if ((result = channel_map_http_code(this, &http_response_code)) != + CHANNEL_OK) { + ERROR("Channel operation returned HTTP error code %ld.\n", + http_response_code); + goto cleanup_header; + } + TRACE("Channel put operation returned HTTP status code %ld.\n", + http_response_code); + +cleanup_header: + curl_easy_reset(channel_curl->handle); + curl_slist_free_all(channel_curl->header); + channel_curl->header = NULL; + + return result; +} + +static channel_op_res_t channel_put_method(channel_t *this, void *data) +{ + channel_curl_t *channel_curl = this->priv; + assert(data != NULL); + assert(channel_curl->handle != NULL); + + channel_op_res_t result = CHANNEL_OK; + channel_data_t *channel_data = (channel_data_t *)data; + channel_data->offs = 0; + + if (channel_data->debug) { + curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); + } + + if (((channel_curl->header = curl_slist_append( + channel_curl->header, "Content-Type: application/json")) == + NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "Accept: application/json")) == NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "charsets: utf-8")) == NULL)) { + ERROR("Set channel header failed.\n"); + result = CHANNEL_EINIT; + goto cleanup_header; + } + + if ((result = channel_set_options(this, channel_data, CHANNEL_PUT)) != + CHANNEL_OK) { + ERROR("Set channel option failed.\n"); + 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, + (curl_off_t)strlen(channel_data->json_string)) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_READDATA, channel_data) != + CURLE_OK)) { + ERROR("Set channel option failed.\n"); + goto cleanup_header; + } + + CURLcode curlrc = curl_easy_perform(channel_curl->handle); + if (curlrc != CURLE_OK) { + ERROR("Channel put operation failed (%d): '%s'\n", curlrc, + curl_easy_strerror(curlrc)); + result = channel_map_curl_error(curlrc); + goto cleanup_header; + } + + channel_log_effective_url(this); + + long http_response_code; + if ((result = channel_map_http_code(this, &http_response_code)) != CHANNEL_OK) { + ERROR("Channel operation returned HTTP error code %ld.\n", + http_response_code); + goto cleanup_header; + } + TRACE("Channel put operation returned HTTP error code %ld.\n", + http_response_code); + +cleanup_header: + curl_easy_reset(channel_curl->handle); + curl_slist_free_all(channel_curl->header); + channel_curl->header = NULL; + + return result; +} + +channel_op_res_t channel_put(channel_t *this, void *data) +{ + assert(data != NULL); + + channel_data_t *channel_data = (channel_data_t *)data; + + switch (channel_data->method) { + case CHANNEL_PUT: + return channel_put_method(this, data); + case CHANNEL_POST: + return channel_post_method(this, data); + default: + TRACE("Channel method (POST, PUT) is not set !\n"); + return CHANNEL_EINIT; + } +} + +channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle) +{ + channel_curl_t *channel_curl = this->priv; + assert(data != NULL); + assert(channel_curl->handle != NULL); + + channel_op_res_t result = CHANNEL_OK; + channel_data_t *channel_data = (channel_data_t *)data; + +#ifdef CONFIG_SURICATTA_SSL + memset(channel_data->sha1hash, 0x0, SHA_DIGEST_LENGTH * 2 + 1); + if (SHA1_Init(&checksum_ctx) != 1) { + result = CHANNEL_EINIT; + ERROR("Cannot initialize sha1 checksum context.\n"); + goto cleanup; + } +#endif + + if (channel_data->debug) { + curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); + } + + if (((channel_curl->header = curl_slist_append( + channel_curl->header, + "Content-Type: application/octet-stream")) == NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "Accept: application/octet-stream")) == + NULL)) { + result = CHANNEL_EINIT; + ERROR("Set channel header failed.\n"); + goto cleanup_header; + } + + if ((result = channel_set_options(this, channel_data, CHANNEL_GET)) != + CHANNEL_OK) { + ERROR("Set channel option failed.\n"); + goto cleanup_header; + } + + if (file_handle == FD_USE_IPC) { + for (int retries = 3; retries >= 0; retries--) { + file_handle = ipc_inst_start_ext(SOURCE_SURICATTA, + channel_data->info == NULL ? 0 : strlen(channel_data->info), + channel_data->info); + if (file_handle > 0) + break; + sleep(1); + } + if (file_handle < 0) { + ERROR("Cannot open SWUpdate IPC stream: %s\n", strerror(errno)); + result = CHANNEL_EIO; + goto cleanup_header; + } + } else { + assert(file_handle > 0); + } + + write_callback_t wrdata; + wrdata.channel_data = channel_data; + wrdata.output = file_handle; + result_channel_callback_write_file = CHANNEL_OK; + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEFUNCTION, + channel_callback_write_file) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEDATA, + &wrdata) != CURLE_OK)) { + ERROR("Cannot setup file writer callback function.\n"); + result = CHANNEL_EINIT; + goto cleanup_file; + } + + /* Depending on the architecture and libcurl, this is at + * least 2^32 - 1 bytes, i.e., enough to account for a 4GiB + * download. Although 32-Bit curl defines `curl_off_t` as + * (signed) long long, use unsigned here, but it wastes some + * bits on 64-Bit. + */ + unsigned long long int total_bytes_downloaded = 0; + unsigned char try_count = 0; + CURLcode curlrc = CURLE_OK; + do { + if (try_count > 0) { + if (channel_data->retries == 0) { + ERROR( + "Channel get operation failed (%d): '%s'\n", + curlrc, curl_easy_strerror(curlrc)); + result = channel_map_curl_error(curlrc); + goto cleanup_file; + } + + if (try_count > channel_data->retries) { + ERROR("Channel get operation aborted because " + "of too many failed download attempts " + "(%d).\n", + channel_data->retries); + result = CHANNEL_ELOOP; + goto cleanup_file; + } + + DEBUG("Channel connection interrupted, trying resume " + "after %llu bytes.", + total_bytes_downloaded); + if (curl_easy_setopt( + channel_curl->handle, CURLOPT_RESUME_FROM_LARGE, + total_bytes_downloaded) != CURLE_OK) { + ERROR("Could not set Channel resume seek (%d): " + "'%s'\n", + curlrc, curl_easy_strerror(curlrc)); + result = channel_map_curl_error(curlrc); + goto cleanup_file; + } + TRACE("Channel sleeps for %d seconds now.", + channel_data->retry_sleep); + if (sleep(channel_data->retry_sleep) > 0) { + TRACE("Channel's sleep got interrupted, " + "retrying nonetheless now."); + } + TRACE("Channel awakened from sleep."); + } + + curlrc = curl_easy_perform(channel_curl->handle); + result = channel_map_curl_error(curlrc); + if ((result != CHANNEL_OK) && (result != CHANNEL_EAGAIN)) { + ERROR("Channel operation returned error (%d): '%s'\n", + curlrc, curl_easy_strerror(curlrc)); + goto cleanup_file; + } + + double bytes_downloaded; + CURLcode resdlprogress = curl_easy_getinfo( + channel_curl->handle, CURLINFO_SIZE_DOWNLOAD, + &bytes_downloaded); + if (resdlprogress != CURLE_OK) { + ERROR("Channel does not report bytes downloaded (%d): " + "'%s'\n", + resdlprogress, curl_easy_strerror(resdlprogress)); + result = channel_map_curl_error(resdlprogress); + goto cleanup_file; + } + total_bytes_downloaded += bytes_downloaded; + + } while (++try_count && (result != CHANNEL_OK)); + + channel_log_effective_url(this); + + DEBUG("Channel downloaded %llu bytes ~ %llu MiB.\n", + total_bytes_downloaded, total_bytes_downloaded / 1024 / 1024); + + long http_response_code; + if ((result = channel_map_http_code(this, &http_response_code)) != + CHANNEL_OK) { + ERROR("Channel operation returned HTTP error code %ld.\n", + http_response_code); + goto cleanup_file; + } + TRACE("Channel operation returned HTTP status code %ld.\n", + http_response_code); + + if (result_channel_callback_write_file != CHANNEL_OK) { + result = CHANNEL_EIO; + goto cleanup_file; + } + +#ifdef CONFIG_SURICATTA_SSL + unsigned char sha1hash[SHA_DIGEST_LENGTH]; + if (SHA1_Final(sha1hash, &checksum_ctx) != 1) { + ERROR("Cannot compute checksum.\n"); + goto cleanup_file; + } + char sha1hexchar[3]; + for (int i = 0; i < SHA_DIGEST_LENGTH; i++) { + sprintf(sha1hexchar, "%02x", sha1hash[i]); + strcat(channel_data->sha1hash, sha1hexchar); + } +#endif + +cleanup_file: + /* NOTE ipc_end() calls close() but does not return its error code, + * so use close() here directly to issue an error in case. + * Also, for a given file handle, calling ipc_end() would make + * no semantic sense. */ + if (close(file_handle) != 0) { + ERROR("Channel error while closing download target handle: '%s'\n", + strerror(errno)); + } +cleanup_header: + curl_easy_reset(channel_curl->handle); + curl_slist_free_all(channel_curl->header); + channel_curl->header = NULL; + +#ifdef CONFIG_SURICATTA_SSL +cleanup: +#endif + return result; +} + +channel_op_res_t channel_get(channel_t *this, void *data) +{ + channel_curl_t *channel_curl = this->priv; + assert(data != NULL); + assert(channel_curl.handle != NULL); + + channel_op_res_t result = CHANNEL_OK; + channel_data_t *channel_data = (channel_data_t *)data; + + if (channel_data->debug) { + curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); + } + + if (((channel_curl->header = curl_slist_append( + channel_curl->header, "Content-Type: application/json")) == + NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "Accept: application/json")) == NULL) || + ((channel_curl->header = curl_slist_append( + channel_curl->header, "charsets: utf-8")) == NULL)) { + result = CHANNEL_EINIT; + ERROR("Set channel header failed.\n"); + goto cleanup_header; + } + + if ((result = channel_set_options(this, channel_data, CHANNEL_GET)) != + CHANNEL_OK) { + ERROR("Set channel option failed.\n"); + goto cleanup_header; + } + + output_data_t chunk = {.memory = NULL, .size = 0}; + if ((chunk.memory = malloc(1)) == NULL) { + ERROR("Channel buffer reservation failed with OOM.\n"); + result = CHANNEL_ENOMEM; + goto cleanup_header; + } + + write_callback_t wrdata; + wrdata.channel_data = channel_data; + wrdata.outdata = &chunk; + + if ((curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEFUNCTION, + channel_callback_membuffer) != CURLE_OK) || + (curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEDATA, + (void *)&wrdata) != CURLE_OK)) { + ERROR("Cannot setup memory buffer writer callback function.\n"); + result = CHANNEL_EINIT; + goto cleanup_chunk; + } + + DEBUG("Trying to GET %s", channel_data->url); + CURLcode curlrc = curl_easy_perform(channel_curl->handle); + if (curlrc != CURLE_OK) { + ERROR("Channel get operation failed (%d): '%s'\n", curlrc, + curl_easy_strerror(curlrc)); + result = channel_map_curl_error(curlrc); + goto cleanup_chunk; + } + + channel_log_effective_url(this); + + long http_response_code; + if ((result = channel_map_http_code(this, &http_response_code)) != + CHANNEL_OK) { + ERROR("Channel operation returned HTTP error code %ld.\n", + http_response_code); + if (http_response_code == 500) { + DEBUG("The error's message is: '%s'\n", chunk.memory); + } + if (http_response_code == 404) { + DEBUG("The error's message is: '%s'\n", chunk.memory); + } + goto cleanup_chunk; + } + TRACE("Channel operation returned HTTP status code %ld.\n", + http_response_code); + + assert(channel_data->json_reply == NULL); + enum json_tokener_error json_res; + struct json_tokener *json_tokenizer = json_tokener_new(); + do { + channel_data->json_reply = json_tokener_parse_ex( + json_tokenizer, chunk.memory, (int)chunk.size); + } while ((json_res = json_tokener_get_error(json_tokenizer)) == + json_tokener_continue); + if (json_res != json_tokener_success) { + ERROR("Error while parsing channel's returned JSON data: %s\n", + json_tokener_error_desc(json_res)); + result = CHANNEL_EBADMSG; + goto cleanup_json_tokenizer; + } + if (channel_data->debug) { + TRACE("Get JSON: %s\n", chunk.memory); + } + +cleanup_json_tokenizer: + json_tokener_free(json_tokenizer); +cleanup_chunk: + chunk.memory != NULL ? free(chunk.memory) : (void)0; +cleanup_header: + curl_easy_reset(channel_curl->handle); + curl_slist_free_all(channel_curl->header); + channel_curl->header = NULL; + + return result; +} diff --git a/include/channel_curl.h b/include/channel_curl.h new file mode 100644 index 0000000..ed262fc --- /dev/null +++ b/include/channel_curl.h @@ -0,0 +1,63 @@ +/* + * Author: Christian Storm + * Copyright (C) 2016, Siemens AG + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +#pragma once +#include +#include +#ifdef CONFIG_SURICATTA_SSL +#include +#endif + +/* hawkBit Channel Implementation Private Header File. + * + * This is a "private" header for testability, i.e., the declarations and + * definitions herein should be used by `server_hawkbit.c`, `channel_hawkbit.c`, + * and unit tests only. + */ + +typedef enum { + CHANNEL_GET, + CHANNEL_POST, + CHANNEL_PUT, +} channel_method_t; + +#define FD_USE_IPC -2 + +#define USE_PROXY_ENV (char *)0x11 + +typedef struct { + char *url; + char *json_string; + json_object *json_reply; + char *cafile; + char *sslkey; + char *sslcert; + char *proxy; + char *info; + unsigned int retry_sleep; + unsigned int offs; + unsigned int method; + unsigned int retries; + bool debug; + bool strictssl; + int (*checkdwl)(void); +#ifdef CONFIG_SURICATTA_SSL + char sha1hash[SHA_DIGEST_LENGTH * 2 + 1]; +#endif +} channel_data_t; diff --git a/suricatta/Makefile b/suricatta/Makefile index 72b3e76..fabe926 100644 --- a/suricatta/Makefile +++ b/suricatta/Makefile @@ -1,4 +1,4 @@ lib-$(CONFIG_SURICATTA) += state.o suricatta.o ifneq ($(CONFIG_SURICATTA_HAWKBIT),) -lib-$(CONFIG_SURICATTA) += channel_hawkbit.o server_hawkbit.o +lib-$(CONFIG_SURICATTA) += server_hawkbit.o endif diff --git a/suricatta/channel_hawkbit.c b/suricatta/channel_hawkbit.c deleted file mode 100644 index f3d00a0..0000000 --- a/suricatta/channel_hawkbit.c +++ /dev/null @@ -1,941 +0,0 @@ -/* - * Author: Christian Storm - * Copyright (C) 2016, Siemens AG - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef CONFIG_SURICATTA_SSL -#include -#endif -#include "suricatta/channel.h" -#include "channel_hawkbit.h" -#include "suricatta/suricatta.h" - -#define SPEED_LOW_BYTES_SEC 8 -#define SPEED_LOW_TIME_SEC 300 -#define KEEPALIVE_DELAY 204L -#define KEEPALIVE_INTERVAL 120L - -typedef struct { - char *memory; - size_t size; -} output_data_t; - -typedef struct { - char *proxy; - char *effective_url; - CURL *handle; - struct curl_slist *header; -} channel_curl_t; - -typedef struct { - channel_data_t *channel_data; - int output; - output_data_t *outdata; -} write_callback_t; - -#ifdef CONFIG_SURICATTA_SSL -static SHA_CTX checksum_ctx; -#endif - -/* Prototypes for "internal" functions */ -/* Note that they're not `static` so that they're callable from unit tests. */ -size_t channel_callback_write_file(void *streamdata, size_t size, size_t nmemb, - write_callback_t *data); -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); -static void channel_log_effective_url(channel_t *this); - -/* Prototypes for "public" functions */ -channel_op_res_t channel_hawkbit_init(void); -channel_op_res_t channel_close(channel_t *this); -channel_op_res_t channel_open(channel_t *this, void *cfg); -channel_op_res_t channel_get(channel_t *this, void *data); -channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle); -channel_op_res_t channel_put(channel_t *this, void *data); -channel_t *channel_new(void); - - -channel_op_res_t channel_hawkbit_init(void) -{ -#ifdef CONFIG_SURICATTA_SSL -#define CURL_FLAGS CURL_GLOBAL_SSL -#else -#define CURL_FLAGS CURL_GLOBAL_NOTHING -#endif - CURLcode curlrc = curl_global_init(CURL_FLAGS); - if (curlrc != CURLE_OK) { - ERROR("Initialization of channel failed (%d): '%s'\n", curlrc, - curl_easy_strerror(curlrc)); - return CHANNEL_EINIT; - } -#undef CURL_FLAGS - return CHANNEL_OK; -} - -channel_t *channel_new(void) -{ - channel_t *newchan = (channel_t *)calloc(1, sizeof(*newchan) + - sizeof(channel_curl_t)); - - if (newchan) { - newchan->priv = (void *)newchan + sizeof(*newchan); - newchan->open = &channel_open; - newchan->close = &channel_close; - newchan->get = &channel_get; - newchan->get_file = &channel_get_file; - newchan->put = &channel_put; - } - - return newchan; -} - -channel_op_res_t channel_close(channel_t *this) -{ - channel_curl_t *channel_curl = this->priv; - - if ((channel_curl->proxy != NULL) && - (channel_curl->proxy != USE_PROXY_ENV)) { - free(channel_curl->proxy); - } - if (channel_curl->handle == NULL) { - return CHANNEL_OK; - } - curl_easy_cleanup(channel_curl->handle); - channel_curl->handle = NULL; - - return CHANNEL_OK; -} - -channel_op_res_t channel_open(channel_t *this, void *cfg) -{ - assert(this != NULL); - channel_curl_t *channel_curl = this->priv; - assert(channel_curl->handle == NULL); - - channel_data_t *channel_cfg = (channel_data_t *)cfg; - - if ((channel_cfg != NULL) && (channel_cfg->proxy != NULL)) { - channel_curl->proxy = channel_cfg->proxy == USE_PROXY_ENV - ? USE_PROXY_ENV - : strdup(channel_cfg->proxy); - if (channel_curl->proxy == NULL) { - return CHANNEL_EINIT; - } - } - - if ((channel_curl->handle = curl_easy_init()) == NULL) { - ERROR("Initialization of channel failed.\n"); - return CHANNEL_EINIT; - } - - return CHANNEL_OK; -} - -static channel_op_res_t result_channel_callback_write_file; -size_t channel_callback_write_file(void *streamdata, size_t size, size_t nmemb, - write_callback_t *data) -{ - if (!nmemb) { - return 0; - } - if (!data) - return 0; - result_channel_callback_write_file = CHANNEL_OK; -#ifdef CONFIG_SURICATTA_SSL - if (SHA1_Update(&checksum_ctx, streamdata, size * nmemb) != 1) { - ERROR("Updating checksum of chunk failed.\n"); - result_channel_callback_write_file = CHANNEL_EIO; - return 0; - } -#endif - if (ipc_send_data(data->output, streamdata, (int)(size * nmemb)) < - 0) { - ERROR("Writing into SWUpdate IPC stream failed.\n"); - result_channel_callback_write_file = CHANNEL_EIO; - return 0; - } - - if (data->channel_data->checkdwl && data->channel_data->checkdwl()) - return 0; - /* - * Now check if there is a callback from the server - * during the download - */ - - return size * nmemb; -} - -size_t channel_callback_membuffer(void *streamdata, size_t size, size_t nmemb, - write_callback_t *data) -{ - if (!nmemb) { - return 0; - } - if (!data) { - return 0; - } - - size_t realsize = size * nmemb; - output_data_t *mem = data->outdata; - - mem->memory = realloc(mem->memory, mem->size + realsize + 1); - if (mem->memory == NULL) { - ERROR("Channel get operation failed with OOM\n"); - return 0; - } - memcpy(&(mem->memory[mem->size]), streamdata, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; - return realsize; -} - -static void channel_log_effective_url(channel_t *this) -{ - channel_curl_t *channel_curl = this->priv; - - CURLcode curlrc = - curl_easy_getinfo(channel_curl->handle, CURLINFO_EFFECTIVE_URL, - &channel_curl->effective_url); - if (curlrc != CURLE_OK && curlrc == CURLE_UNKNOWN_OPTION) { - ERROR("Get channel's effective URL response unsupported by " - "libcURL %s.\n", - LIBCURL_VERSION); - return; - } - TRACE("Channel's effective URL resolved to %s\n", - channel_curl->effective_url); -} - -channel_op_res_t channel_map_http_code(channel_t *this, long *http_response_code) -{ - channel_curl_t *channel_curl = this->priv; - CURLcode curlrc = - curl_easy_getinfo(channel_curl->handle, CURLINFO_RESPONSE_CODE, - http_response_code); - if (curlrc != CURLE_OK && curlrc == CURLE_UNKNOWN_OPTION) { - ERROR("Get channel HTTP response code unsupported by libcURL " - "%s.\n", - LIBCURL_VERSION); - return CHANNEL_EINIT; - } - switch (*http_response_code) { - case 0: /* libcURL: no server response code has been received yet */ - DEBUG("No HTTP response code has been received yet!\n"); - return CHANNEL_EBADMSG; - case 401: /* Unauthorized. The request requires user authentication. */ - case 403: /* Forbidden. */ - case 405: /* Method not Allowed. */ - case 407: /* Proxy Authentication Required */ - case 503: /* Service Unavailable */ - return CHANNEL_EACCES; - case 400: /* Bad Request, e.g., invalid parameters */ - case 404: /* Wrong URL */ - case 406: /* Not acceptable. Accept header is not response compliant */ - case 443: /* Connection refused */ - return CHANNEL_EBADMSG; - case 429: /* Bad Request, i.e., too many requests. Try again later. */ - return CHANNEL_EAGAIN; - case 200: - case 206: - return CHANNEL_OK; - case 500: - return CHANNEL_EBADMSG; - default: - ERROR("Channel operation returned unhandled HTTP error code " - "%ld\n", - *http_response_code); - return CHANNEL_EBADMSG; - } -} - -channel_op_res_t channel_map_curl_error(CURLcode res) -{ - switch (res) { - case CURLE_NOT_BUILT_IN: - case CURLE_BAD_FUNCTION_ARGUMENT: - case CURLE_UNKNOWN_OPTION: - case CURLE_SSL_ENGINE_NOTFOUND: - case CURLE_SSL_ENGINE_SETFAILED: - case CURLE_SSL_CERTPROBLEM: - case CURLE_SSL_CIPHER: - case CURLE_SSL_ENGINE_INITFAILED: - case CURLE_SSL_CACERT_BADFILE: - case CURLE_SSL_CRL_BADFILE: - case CURLE_SSL_ISSUER_ERROR: -#if LIBCURL_VERSION_NUM >= 0x072900 - case CURLE_SSL_INVALIDCERTSTATUS: -#endif -#if LIBCURL_VERSION_NUM >= 0x072700 - case CURLE_SSL_PINNEDPUBKEYNOTMATCH: -#endif - return CHANNEL_EINIT; - case CURLE_COULDNT_RESOLVE_PROXY: - case CURLE_COULDNT_RESOLVE_HOST: - case CURLE_COULDNT_CONNECT: - case CURLE_INTERFACE_FAILED: - case CURLE_SSL_CONNECT_ERROR: - case CURLE_PEER_FAILED_VERIFICATION: - case CURLE_SSL_CACERT: - case CURLE_USE_SSL_FAILED: - return CHANNEL_ENONET; - case CURLE_OPERATION_TIMEDOUT: - case CURLE_SEND_ERROR: - case CURLE_RECV_ERROR: - case CURLE_GOT_NOTHING: - case CURLE_HTTP_POST_ERROR: - case CURLE_PARTIAL_FILE: - return CHANNEL_EAGAIN; - case CURLE_OUT_OF_MEMORY: - return CHANNEL_ENOMEM; - case CURLE_REMOTE_FILE_NOT_FOUND: - return CHANNEL_ENOENT; - case CURLE_FILESIZE_EXCEEDED: - case CURLE_ABORTED_BY_CALLBACK: - case CURLE_WRITE_ERROR: - case CURLE_CHUNK_FAILED: - case CURLE_SSL_SHUTDOWN_FAILED: - return CHANNEL_EIO; - case CURLE_TOO_MANY_REDIRECTS: - return CHANNEL_ELOOP; - case CURLE_BAD_CONTENT_ENCODING: - case CURLE_CONV_FAILED: - case CURLE_CONV_REQD: - return CHANNEL_EILSEQ; - case CURLE_REMOTE_ACCESS_DENIED: - case CURLE_LOGIN_DENIED: - return CHANNEL_EACCES; - case CURLE_OK: - return CHANNEL_OK; - default: - return CHANNEL_EINIT; - } -} - -channel_op_res_t channel_set_options(channel_t *this, - channel_data_t *channel_data, - channel_method_t method) -{ - channel_curl_t *channel_curl = this->priv; - channel_op_res_t result = CHANNEL_OK; - if ((curl_easy_setopt(channel_curl->handle, CURLOPT_URL, - channel_data->url) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_USERAGENT, - "libcurl-agent/1.0") != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_LOW_SPEED_LIMIT, - SPEED_LOW_BYTES_SEC) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_LOW_SPEED_TIME, - SPEED_LOW_TIME_SEC) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_HTTPHEADER, - channel_curl->header) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_MAXREDIRS, -1) != - CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_FOLLOWLOCATION, 1) != - CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_REDIR_PROTOCOLS, - CURLPROTO_HTTP | CURLPROTO_HTTPS) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, - CURLOPT_CAINFO, - channel_data->cafile) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, - CURLOPT_SSLKEY, - channel_data->sslkey) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, - CURLOPT_SSLCERT, - channel_data->sslcert) != CURLE_OK)) { - result = CHANNEL_EINIT; - goto cleanup; - } - - if (channel_data->strictssl == true) { - if ((curl_easy_setopt(channel_curl->handle, - CURLOPT_SSL_VERIFYHOST, - 2L) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, - CURLOPT_SSL_VERIFYPEER, - 1L) != CURLE_OK)) { - result = CHANNEL_EINIT; - goto cleanup; - } - } - else { - if ((curl_easy_setopt(channel_curl->handle, - CURLOPT_SSL_VERIFYHOST, - 0L) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, - CURLOPT_SSL_VERIFYPEER, - 0L) != CURLE_OK)) { - result = CHANNEL_EINIT; - goto cleanup; - } - } - - 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: - if ((curl_easy_setopt(channel_curl->handle, CURLOPT_POST, 1L) != - CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_POSTFIELDS, - channel_data->json_string) != CURLE_OK)) { - result = CHANNEL_EINIT; - goto cleanup; - } - if (channel_data->debug) { - TRACE("Post JSON: %s\n", channel_data->json_string); - } - break; - } - - if (channel_curl->proxy != NULL) { - if (channel_curl->proxy != USE_PROXY_ENV) { - if (curl_easy_setopt( - channel_curl->handle, CURLOPT_PROXY, - channel_curl->proxy) != CURLE_OK) { - result = CHANNEL_EINIT; - goto cleanup; - } - } - if (curl_easy_setopt(channel_curl->handle, CURLOPT_NETRC, - CURL_NETRC_OPTIONAL) != CURLE_OK) { - result = CHANNEL_EINIT; - goto cleanup; - } - } - - CURLcode curlrc = - curl_easy_setopt(channel_curl->handle, CURLOPT_TCP_KEEPALIVE, 1L); - if (curlrc == CURLE_OK) { - if ((curl_easy_setopt(channel_curl->handle, CURLOPT_TCP_KEEPIDLE, - KEEPALIVE_DELAY) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, - CURLOPT_TCP_KEEPINTVL, - KEEPALIVE_INTERVAL) != CURLE_OK)) { - ERROR("TCP Keep-alive interval and delay could not be " - "configured.\n"); - result = CHANNEL_EINIT; - goto cleanup; - } - } else { - if (curlrc != CURLE_UNKNOWN_OPTION) { - ERROR("Channel could not be configured to sent " - "keep-alive probes.\n"); - result = CHANNEL_EINIT; - goto cleanup; - } - } - -cleanup: - return result; -} - -static size_t put_read_callback(void *ptr, size_t size, size_t nmemb, void *data) -{ - channel_data_t *channel_data = (channel_data_t *)data; - unsigned int bytes; - size_t n; - - /* Check data to be sent */ - bytes = strlen(channel_data->json_string) - channel_data->offs; - - if (!bytes) - return 0; - - n = min(bytes, size * nmemb); - - memcpy(ptr, &channel_data->json_string[channel_data->offs], n); - channel_data->offs += n; - - return n; -} - -static channel_op_res_t channel_post_method(channel_t *this, void *data) -{ - channel_curl_t *channel_curl = this->priv; - assert(data != NULL); - assert(channel_curl->handle != NULL); - - channel_op_res_t result = CHANNEL_OK; - channel_data_t *channel_data = (channel_data_t *)data; - - if (channel_data->debug) { - curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); - } - - if (((channel_curl->header = curl_slist_append( - channel_curl->header, "Content-Type: application/json")) == - NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "Accept: application/json")) == NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "charsets: utf-8")) == NULL)) { - ERROR("Set channel header failed.\n"); - result = CHANNEL_EINIT; - goto cleanup_header; - } - - if ((result = channel_set_options(this, channel_data, CHANNEL_POST)) != - CHANNEL_OK) { - ERROR("Set channel option failed.\n"); - goto cleanup_header; - } - - CURLcode curlrc = curl_easy_perform(channel_curl->handle); - if (curlrc != CURLE_OK) { - ERROR("Channel put operation failed (%d): '%s'\n", curlrc, - curl_easy_strerror(curlrc)); - result = channel_map_curl_error(curlrc); - goto cleanup_header; - } - - channel_log_effective_url(this); - - long http_response_code; - if ((result = channel_map_http_code(this, &http_response_code)) != - CHANNEL_OK) { - ERROR("Channel operation returned HTTP error code %ld.\n", - http_response_code); - goto cleanup_header; - } - TRACE("Channel put operation returned HTTP status code %ld.\n", - http_response_code); - -cleanup_header: - curl_easy_reset(channel_curl->handle); - curl_slist_free_all(channel_curl->header); - channel_curl->header = NULL; - - return result; -} - -static channel_op_res_t channel_put_method(channel_t *this, void *data) -{ - channel_curl_t *channel_curl = this->priv; - assert(data != NULL); - assert(channel_curl->handle != NULL); - - channel_op_res_t result = CHANNEL_OK; - channel_data_t *channel_data = (channel_data_t *)data; - channel_data->offs = 0; - - if (channel_data->debug) { - curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); - } - - if (((channel_curl->header = curl_slist_append( - channel_curl->header, "Content-Type: application/json")) == - NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "Accept: application/json")) == NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "charsets: utf-8")) == NULL)) { - ERROR("Set channel header failed.\n"); - result = CHANNEL_EINIT; - goto cleanup_header; - } - - if ((result = channel_set_options(this, channel_data, CHANNEL_PUT)) != - CHANNEL_OK) { - ERROR("Set channel option failed.\n"); - 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, - (curl_off_t)strlen(channel_data->json_string)) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_READDATA, channel_data) != - CURLE_OK)) { - ERROR("Set channel option failed.\n"); - goto cleanup_header; - } - - CURLcode curlrc = curl_easy_perform(channel_curl->handle); - if (curlrc != CURLE_OK) { - ERROR("Channel put operation failed (%d): '%s'\n", curlrc, - curl_easy_strerror(curlrc)); - result = channel_map_curl_error(curlrc); - goto cleanup_header; - } - - channel_log_effective_url(this); - - long http_response_code; - if ((result = channel_map_http_code(this, &http_response_code)) != CHANNEL_OK) { - ERROR("Channel operation returned HTTP error code %ld.\n", - http_response_code); - goto cleanup_header; - } - TRACE("Channel put operation returned HTTP error code %ld.\n", - http_response_code); - -cleanup_header: - curl_easy_reset(channel_curl->handle); - curl_slist_free_all(channel_curl->header); - channel_curl->header = NULL; - - return result; -} - -channel_op_res_t channel_put(channel_t *this, void *data) -{ - assert(data != NULL); - - channel_data_t *channel_data = (channel_data_t *)data; - - switch (channel_data->method) { - case CHANNEL_PUT: - return channel_put_method(this, data); - case CHANNEL_POST: - return channel_post_method(this, data); - default: - TRACE("Channel method (POST, PUT) is not set !\n"); - return CHANNEL_EINIT; - } -} - -channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle) -{ - channel_curl_t *channel_curl = this->priv; - assert(data != NULL); - assert(channel_curl->handle != NULL); - - channel_op_res_t result = CHANNEL_OK; - channel_data_t *channel_data = (channel_data_t *)data; - -#ifdef CONFIG_SURICATTA_SSL - memset(channel_data->sha1hash, 0x0, SHA_DIGEST_LENGTH * 2 + 1); - if (SHA1_Init(&checksum_ctx) != 1) { - result = CHANNEL_EINIT; - ERROR("Cannot initialize sha1 checksum context.\n"); - goto cleanup; - } -#endif - - if (channel_data->debug) { - curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); - } - - if (((channel_curl->header = curl_slist_append( - channel_curl->header, - "Content-Type: application/octet-stream")) == NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "Accept: application/octet-stream")) == - NULL)) { - result = CHANNEL_EINIT; - ERROR("Set channel header failed.\n"); - goto cleanup_header; - } - - if ((result = channel_set_options(this, channel_data, CHANNEL_GET)) != - CHANNEL_OK) { - ERROR("Set channel option failed.\n"); - goto cleanup_header; - } - - if (file_handle == FD_USE_IPC) { - for (int retries = 3; retries >= 0; retries--) { - file_handle = ipc_inst_start_ext(SOURCE_SURICATTA, - channel_data->info == NULL ? 0 : strlen(channel_data->info), - channel_data->info); - if (file_handle > 0) - break; - sleep(1); - } - if (file_handle < 0) { - ERROR("Cannot open SWUpdate IPC stream: %s\n", strerror(errno)); - result = CHANNEL_EIO; - goto cleanup_header; - } - } else { - assert(file_handle > 0); - } - - write_callback_t wrdata; - wrdata.channel_data = channel_data; - wrdata.output = file_handle; - result_channel_callback_write_file = CHANNEL_OK; - if ((curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEFUNCTION, - channel_callback_write_file) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEDATA, - &wrdata) != CURLE_OK)) { - ERROR("Cannot setup file writer callback function.\n"); - result = CHANNEL_EINIT; - goto cleanup_file; - } - - /* Depending on the architecture and libcurl, this is at - * least 2^32 - 1 bytes, i.e., enough to account for a 4GiB - * download. Although 32-Bit curl defines `curl_off_t` as - * (signed) long long, use unsigned here, but it wastes some - * bits on 64-Bit. - */ - unsigned long long int total_bytes_downloaded = 0; - unsigned char try_count = 0; - CURLcode curlrc = CURLE_OK; - do { - if (try_count > 0) { - if (channel_data->retries == 0) { - ERROR( - "Channel get operation failed (%d): '%s'\n", - curlrc, curl_easy_strerror(curlrc)); - result = channel_map_curl_error(curlrc); - goto cleanup_file; - } - - if (try_count > channel_data->retries) { - ERROR("Channel get operation aborted because " - "of too many failed download attempts " - "(%d).\n", - channel_data->retries); - result = CHANNEL_ELOOP; - goto cleanup_file; - } - - DEBUG("Channel connection interrupted, trying resume " - "after %llu bytes.", - total_bytes_downloaded); - if (curl_easy_setopt( - channel_curl->handle, CURLOPT_RESUME_FROM_LARGE, - total_bytes_downloaded) != CURLE_OK) { - ERROR("Could not set Channel resume seek (%d): " - "'%s'\n", - curlrc, curl_easy_strerror(curlrc)); - result = channel_map_curl_error(curlrc); - goto cleanup_file; - } - TRACE("Channel sleeps for %d seconds now.", - channel_data->retry_sleep); - if (sleep(channel_data->retry_sleep) > 0) { - TRACE("Channel's sleep got interrupted, " - "retrying nonetheless now."); - } - TRACE("Channel awakened from sleep."); - } - - curlrc = curl_easy_perform(channel_curl->handle); - result = channel_map_curl_error(curlrc); - if ((result != CHANNEL_OK) && (result != CHANNEL_EAGAIN)) { - ERROR("Channel operation returned error (%d): '%s'\n", - curlrc, curl_easy_strerror(curlrc)); - goto cleanup_file; - } - - double bytes_downloaded; - CURLcode resdlprogress = curl_easy_getinfo( - channel_curl->handle, CURLINFO_SIZE_DOWNLOAD, - &bytes_downloaded); - if (resdlprogress != CURLE_OK) { - ERROR("Channel does not report bytes downloaded (%d): " - "'%s'\n", - resdlprogress, curl_easy_strerror(resdlprogress)); - result = channel_map_curl_error(resdlprogress); - goto cleanup_file; - } - total_bytes_downloaded += bytes_downloaded; - - } while (++try_count && (result != CHANNEL_OK)); - - channel_log_effective_url(this); - - DEBUG("Channel downloaded %llu bytes ~ %llu MiB.\n", - total_bytes_downloaded, total_bytes_downloaded / 1024 / 1024); - - long http_response_code; - if ((result = channel_map_http_code(this, &http_response_code)) != - CHANNEL_OK) { - ERROR("Channel operation returned HTTP error code %ld.\n", - http_response_code); - goto cleanup_file; - } - TRACE("Channel operation returned HTTP status code %ld.\n", - http_response_code); - - if (result_channel_callback_write_file != CHANNEL_OK) { - result = CHANNEL_EIO; - goto cleanup_file; - } - -#ifdef CONFIG_SURICATTA_SSL - unsigned char sha1hash[SHA_DIGEST_LENGTH]; - if (SHA1_Final(sha1hash, &checksum_ctx) != 1) { - ERROR("Cannot compute checksum.\n"); - goto cleanup_file; - } - char sha1hexchar[3]; - for (int i = 0; i < SHA_DIGEST_LENGTH; i++) { - sprintf(sha1hexchar, "%02x", sha1hash[i]); - strcat(channel_data->sha1hash, sha1hexchar); - } -#endif - -cleanup_file: - /* NOTE ipc_end() calls close() but does not return its error code, - * so use close() here directly to issue an error in case. - * Also, for a given file handle, calling ipc_end() would make - * no semantic sense. */ - if (close(file_handle) != 0) { - ERROR("Channel error while closing download target handle: '%s'\n", - strerror(errno)); - } -cleanup_header: - curl_easy_reset(channel_curl->handle); - curl_slist_free_all(channel_curl->header); - channel_curl->header = NULL; - -#ifdef CONFIG_SURICATTA_SSL -cleanup: -#endif - return result; -} - -channel_op_res_t channel_get(channel_t *this, void *data) -{ - channel_curl_t *channel_curl = this->priv; - assert(data != NULL); - assert(channel_curl.handle != NULL); - - channel_op_res_t result = CHANNEL_OK; - channel_data_t *channel_data = (channel_data_t *)data; - - if (channel_data->debug) { - curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); - } - - if (((channel_curl->header = curl_slist_append( - channel_curl->header, "Content-Type: application/json")) == - NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "Accept: application/json")) == NULL) || - ((channel_curl->header = curl_slist_append( - channel_curl->header, "charsets: utf-8")) == NULL)) { - result = CHANNEL_EINIT; - ERROR("Set channel header failed.\n"); - goto cleanup_header; - } - - if ((result = channel_set_options(this, channel_data, CHANNEL_GET)) != - CHANNEL_OK) { - ERROR("Set channel option failed.\n"); - goto cleanup_header; - } - - output_data_t chunk = {.memory = NULL, .size = 0}; - if ((chunk.memory = malloc(1)) == NULL) { - ERROR("Channel buffer reservation failed with OOM.\n"); - result = CHANNEL_ENOMEM; - goto cleanup_header; - } - - write_callback_t wrdata; - wrdata.channel_data = channel_data; - wrdata.outdata = &chunk; - - if ((curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEFUNCTION, - channel_callback_membuffer) != CURLE_OK) || - (curl_easy_setopt(channel_curl->handle, CURLOPT_WRITEDATA, - (void *)&wrdata) != CURLE_OK)) { - ERROR("Cannot setup memory buffer writer callback function.\n"); - result = CHANNEL_EINIT; - goto cleanup_chunk; - } - - DEBUG("Trying to GET %s", channel_data->url); - CURLcode curlrc = curl_easy_perform(channel_curl->handle); - if (curlrc != CURLE_OK) { - ERROR("Channel get operation failed (%d): '%s'\n", curlrc, - curl_easy_strerror(curlrc)); - result = channel_map_curl_error(curlrc); - goto cleanup_chunk; - } - - channel_log_effective_url(this); - - long http_response_code; - if ((result = channel_map_http_code(this, &http_response_code)) != - CHANNEL_OK) { - ERROR("Channel operation returned HTTP error code %ld.\n", - http_response_code); - if (http_response_code == 500) { - DEBUG("The error's message is: '%s'\n", chunk.memory); - } - if (http_response_code == 404) { - DEBUG("The error's message is: '%s'\n", chunk.memory); - } - goto cleanup_chunk; - } - TRACE("Channel operation returned HTTP status code %ld.\n", - http_response_code); - - assert(channel_data->json_reply == NULL); - enum json_tokener_error json_res; - struct json_tokener *json_tokenizer = json_tokener_new(); - do { - channel_data->json_reply = json_tokener_parse_ex( - json_tokenizer, chunk.memory, (int)chunk.size); - } while ((json_res = json_tokener_get_error(json_tokenizer)) == - json_tokener_continue); - if (json_res != json_tokener_success) { - ERROR("Error while parsing channel's returned JSON data: %s\n", - json_tokener_error_desc(json_res)); - result = CHANNEL_EBADMSG; - goto cleanup_json_tokenizer; - } - if (channel_data->debug) { - TRACE("Get JSON: %s\n", chunk.memory); - } - -cleanup_json_tokenizer: - json_tokener_free(json_tokenizer); -cleanup_chunk: - chunk.memory != NULL ? free(chunk.memory) : (void)0; -cleanup_header: - curl_easy_reset(channel_curl->handle); - curl_slist_free_all(channel_curl->header); - channel_curl->header = NULL; - - return result; -} diff --git a/suricatta/channel_hawkbit.h b/suricatta/channel_hawkbit.h deleted file mode 100644 index ed262fc..0000000 --- a/suricatta/channel_hawkbit.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Author: Christian Storm - * Copyright (C) 2016, Siemens AG - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc. - */ - -#pragma once -#include -#include -#ifdef CONFIG_SURICATTA_SSL -#include -#endif - -/* hawkBit Channel Implementation Private Header File. - * - * This is a "private" header for testability, i.e., the declarations and - * definitions herein should be used by `server_hawkbit.c`, `channel_hawkbit.c`, - * and unit tests only. - */ - -typedef enum { - CHANNEL_GET, - CHANNEL_POST, - CHANNEL_PUT, -} channel_method_t; - -#define FD_USE_IPC -2 - -#define USE_PROXY_ENV (char *)0x11 - -typedef struct { - char *url; - char *json_string; - json_object *json_reply; - char *cafile; - char *sslkey; - char *sslcert; - char *proxy; - char *info; - unsigned int retry_sleep; - unsigned int offs; - unsigned int method; - unsigned int retries; - bool debug; - bool strictssl; - int (*checkdwl)(void); -#ifdef CONFIG_SURICATTA_SSL - char sha1hash[SHA_DIGEST_LENGTH * 2 + 1]; -#endif -} channel_data_t; diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index 1b0e600..186e9f0 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -33,7 +33,7 @@ #include #include "suricatta/suricatta.h" #include "suricatta/channel.h" -#include "channel_hawkbit.h" +#include "channel_curl.h" #include "suricatta/state.h" #include "server_hawkbit.h" #include "parselib.h" From patchwork Mon Nov 20 11:10:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23b; helo=mail-wr0-x23b.google.com; envelope-from=swupdate+bncbcxploxj6ikrblxqzliakgqendnzcii@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="O26xuxHk"; dkim-atps=neutral Received: from mail-wr0-x23b.google.com (mail-wr0-x23b.google.com [IPv6:2a00:1450:400c:c0c::23b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxY6HF4z9s5L for ; Mon, 20 Nov 2017 22:10:41 +1100 (AEDT) Received: by mail-wr0-x23b.google.com with SMTP id o14sf5806844wrf.6 for ; Mon, 20 Nov 2017 03:10:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176238; cv=pass; d=google.com; s=arc-20160816; b=GweeVZ3nlmPvMyPmVDYJc0YlIyy0UuN/FcxDnLfrFQQkdqKguRhsOlJ+OcADZrdkU6 vzng2saxzkZh6AWFD7sb191TghQeNpPHUHIDSsu6Us73aIHCqogIL44ovJJE0e3xex8c PxWUB4ZtgQT/u07OY9hcLJns3qFYfv9NH1gLk3pszUFYT234dR0s5cnRoaHo2tQoq/uJ ZeOVA1sp5tb7sWG6pC/vFq7VSg21fXxk543Wr0S+PsvjkejSw6bOg/9+igCjpckXZzMC g7dCDtIH8G2GGmfa9676cXISbFJ2ukn3T4M45UizNxOnwuhb+z6AJWBwWecODhX7mhUv yDlQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=V30t5B9oo3HDwsHDGhZIftE3qNLS5cGXn4IjEYYmiXM=; b=JIC1nvrUJUuS9xKJ15Zv5V76dEXgTgi9YAf7V9KUIhtFQXDAlxvwaoIOLMWfiqmjwl G9OgUAFVWMRWmz969kb1PaGFg+wDdiYhBgyCTnP4pQw3hop+4C0GUv1xGQ6FMU8GEOxP FIbbnNejGPtXdp5Hcrl8ZITWRIHOKHdsXYCohk3EQrhPtCuSwfeL3LMSWWUI6MifgpXW qtYHI2A3dHwujRRJGKsHYZUMkrY2OCDpsCdaFUmUIG5QrgYZDhXshJ8ke9Ilb4R8Y6Ml 9TjPGjqD1skOoXU4wTCMXT6rAfYBgCirXSn/ayys40pBvYTWjFF3EN/cjqkvoLsmPWDE RQbg== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=V30t5B9oo3HDwsHDGhZIftE3qNLS5cGXn4IjEYYmiXM=; b=O26xuxHkq5vGyGwRZKu+h1mr3bwXmyYGhgyGj8NUZAOfSR4Ro4wlaISOHK3qPpSZ5q Fv6Afmd4/N2ipuPj+nqarWR4SMystVCD7GOeFJZqzkCFCXJZoVnvh9qyvd3gL/Zjq+dY 5QeCIIbCRfdxX187l6uBDSJ/LTj5yrwvLZbOFiTmnC4TOu7B6v+jNoTqgwhHSIbf8GRo iEbaybya53OzwydEDCtNJE3jwqOnj722IgJbLCyV7z8Oaz1dVENhtwRhFzTmS9fNawc8 g94NkBo8Dq8cWROm9CMtf/jBGIFauG3bbqGXN5MzH12fzqMScYeWq1QTvNasMo23yGia TQVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=V30t5B9oo3HDwsHDGhZIftE3qNLS5cGXn4IjEYYmiXM=; b=QPzLKfmP5+2tH4QJnROemR01+26rt2HSy/ZN+pjhQv4e8n7keYJG0l4Zgc2b6UpdPr pWNXT5V/aQYn+EK8o7zh573675oAj2Z+WVplBWcbz2sErYD8qjNaKcprlpO8YwNmgsCw urs0nm7Y8KFktNIkMVVTA12IBHG9B8oy5Di21dYg6wmVBWSfO/z9wrIgGx+dUmhUu72d Gbj6637qcekesm4+/WZ7UPN4HcoQlfUYzP5gcYAvmVZ5OC+aZctI5hWhr76EK1UIfZeA moviItIlQE9j2LB+KmuUVC4st8MGamlOluBvWRqM+N8067v8G8LwmDCzCPxcVNYXX8Gu laUw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX7DcOVTjx0CkWgGxDok/MT65ZfiGqc2E8m7E5scZT0ZZ9YQSa9X p9Qi6L4SjCvEpPIHuoyfZRQ= X-Google-Smtp-Source: AGs4zMbWypQZwc4BeFsucN06ltnrve0lnIZsczeiKMy+8X0LJcj+o9tQZx8kkP9vqNyGavW3cMzEGQ== X-Received: by 10.28.225.68 with SMTP id y65mr141677wmg.7.1511176238488; Mon, 20 Nov 2017 03:10:38 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.167.100 with SMTP id h91ls4960423edc.8.gmail; Mon, 20 Nov 2017 03:10:38 -0800 (PST) X-Received: by 10.80.137.157 with SMTP id g29mr4212201edg.2.1511176238221; Mon, 20 Nov 2017 03:10:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176238; cv=none; d=google.com; s=arc-20160816; b=L3gCNpKTv/0MyVVou6jt1Mzc2LQ2HvjSBTt1zxQIF7BsdmVpcPqvhXxjNh/77fgX5e VAGEGTulHP1Amd4ZMHjT6bL9QYTKq9QnXb0qqidVbTWbvPsNIpY8gjqOm2mTcCeejb3V V5tr2TsxR2KLcxerXiv63sd1jiCam+1ORVDJzBkV9t+iLDTUwG3qhiYx6ylp4WG22zUz pOO69cQIR/1lneKcIsIRu7IpYs0dXJyqOPalx2vVvqYaTlGvwsOpqmIoHawg2eTSp/yy Nwn6NpL6m/J25eczkijNNgnCP/j/LNtUq2gLbRadmmq47EFu7lCy4vvyAB4wOi0yiYG7 cn7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ANNXKt4sMn6kEL3p27IRJP3aCIQDpoPf3VZYOCPGRHU=; b=MtpN26oOxS0DSwkSrq7jl3OZPYB/QSW2DOraz+j2jSc3jYorCLahmXGtTthSXuh6jj zr4NRfvTUmE+g7r2PJK4ZZEQLyaCZAQ23MOi7XkLW2Gn9FjSvTNr51PZuY7EKV48a/5h b7OGYK6As7GGr/gVlO0/V5BhAPs3f9+Dw15O+1GaliG1AXHbPpyYFMfWPDEHBh4jz9GW NiYT6YG2PdCHJ26k4ClkBlrdyQCqbql7Pg9OCXA7oDC/bsPYl2asIDfnlQA+elkikNeK r39pfve8WxNY6/xSD+gYljqrn1b0nw6PyOGC7dDpBNeTtJXWSMqDO8h2DOqTPLjBLj6F n7Yw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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.10]) by gmr-mx.google.com with ESMTPS id q7si823328edd.0.2017.11.20.03.10.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:38 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxT6y3Zz1qqkr; Mon, 20 Nov 2017 12:10:37 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxT6n3Mz1qqkZ; Mon, 20 Nov 2017 12:10:37 +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 LRuzxyiM6Q7D; Mon, 20 Nov 2017 12:10:32 +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; Mon, 20 Nov 2017 12:10:32 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 1A5FC4540378; Mon, 20 Nov 2017 12:10:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YxOcNfN9vLUX; Mon, 20 Nov 2017 12:10:29 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id C4EAC4540633; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 08/17] channel_curl: drop reference to hawkbit Date: Mon, 20 Nov 2017 12:10:01 +0100 Message-Id: <1511176210-28928-8-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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: , Function can be used outside hawkbit - rename channel_hawkbit_init() to channel_curl_init(). Signed-off-by: Stefano Babic --- corelib/channel_curl.c | 4 ++-- suricatta/server_hawkbit.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 6c16592..073bf16 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -76,7 +76,7 @@ channel_op_res_t channel_set_options(channel_t *this, channel_data_t *channel_da static void channel_log_effective_url(channel_t *this); /* Prototypes for "public" functions */ -channel_op_res_t channel_hawkbit_init(void); +channel_op_res_t channel_curl_init(void); channel_op_res_t channel_close(channel_t *this); channel_op_res_t channel_open(channel_t *this, void *cfg); channel_op_res_t channel_get(channel_t *this, void *data); @@ -85,7 +85,7 @@ channel_op_res_t channel_put(channel_t *this, void *data); channel_t *channel_new(void); -channel_op_res_t channel_hawkbit_init(void) +channel_op_res_t channel_curl_init(void) { #ifdef CONFIG_SURICATTA_SSL #define CURL_FLAGS CURL_GLOBAL_SSL diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index 186e9f0..100f0a0 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -106,7 +106,7 @@ static hawkbit_enums_t hawkbit_enums[] = { #define ALL_MANDATORY_SET (TENANT_BIT | ID_BIT | URL_BIT) -extern channel_op_res_t channel_hawkbit_init(void); +extern channel_op_res_t channel_curl_init(void); /* Prototypes for "internal" functions */ /* Note that they're not `static` so that they're callable from unit tests. */ json_object *json_get_key(json_object *json_root, const char *key); @@ -1718,7 +1718,7 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) return SERVER_EINIT; } - if (channel_hawkbit_init() != CHANNEL_OK) + if (channel_curl_init() != CHANNEL_OK) return SERVER_EINIT; /* From patchwork Mon Nov 20 11:10:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::238; helo=mail-wr0-x238.google.com; envelope-from=swupdate+bncbcxploxj6ikrblpqzliakgqepn22h3q@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="tcSLx14+"; dkim-atps=neutral Received: from mail-wr0-x238.google.com (mail-wr0-x238.google.com [IPv6:2a00:1450:400c:c0c::238]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxY2R3dz9s4s for ; Mon, 20 Nov 2017 22:10:41 +1100 (AEDT) Received: by mail-wr0-x238.google.com with SMTP id v69sf2144311wrb.3 for ; Mon, 20 Nov 2017 03:10:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176237; cv=pass; d=google.com; s=arc-20160816; b=olrXTjus/3v5cL5ihZsyoYJNVoDs+pCZiyob0u2nL13HYyUE0iJZk2wavR/AUxrmrq JZHWEZ7FL2ppDZAEpYh6B6otyFUjWB7JIP/X43aHSk3GJSxcKabTUwMajkpLaJMBD3m0 U4Q9Al+p140zDVQ4YX3QV+NqiOSQhq2MWoVFoJNF5Wra4mZHq4ClDoC+CqphACSRlwNE peg0Euc16eG/EmtseRUl6BUKh76S8wIOT0jKW5dKzI0BIh/NUjCtpC1DrZFPl3/Ifeb2 vYJUGqBujfhOljKmFL+QeQWHWUjQa78QRqHRKKeUVLjT/Pj/O7QMyloQwVxAgLdUWMrW +SQw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=LRoSdRebQE1qWbBUYb00WQ6bF2A3JwGvkPV1nz+Pgrc=; b=JZhH4zme6kN7BEnAgJNgPPh/W62klbS2xyBB7GOjk0PfLWirVX5MfRXWljdWz7j5it ED7K063Uu2VKpGPjvIFCv41sWDzLartCnX/3D81RGt8y4mKsp0cKARZqXFngPrEgDbtH W2FXAxKsX+JWukww/eY9sIRmV/TR4LjmpTnHrNtcFRIf9iY0uAx826lQbEugU62LSmyA CR98W6nqkir0VFEcsk7G5JNxN+e7laCiMRk4yBY0mcNq5pLYYVGj9E5Zzl+g9U9EwPL6 FYgpFvSnSAImvcCyKP6EtrGwEN4hXvQq0qCdQvs0bnvDfuF58i2A5ZBPZVWSYP5XawRu 67ow== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=LRoSdRebQE1qWbBUYb00WQ6bF2A3JwGvkPV1nz+Pgrc=; b=tcSLx14+R91ieA6dq+xXnq50r7k7951EVrhxyrawLaBs3GFGQkfUS/xScY2LeRif56 QsvplepMDdZ+hVPpFepK1wr78hMvRKPfXu+RSMFaaQxM4CFnuXXSj8uoPgRA83X+eu1Y bKvsz/MZKHWeEVpx72eZzedvYDYhe+GptKdXkQiZa7pSzovv+ZkmOTbnLqeeSTJ1toj4 NqvO9HJhRC2GBl2j5gAfX+/rf0+y0Svd0FOELtmzZAZuA8Z6i3QexIZFDlFTgRy6jKhC aDcyxmRNKQIM98XN88xvBGt163L0PNjky8ZbxgQvpkoclwn+OIy/0eGjYQ5ZQwwFybEf UVTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=LRoSdRebQE1qWbBUYb00WQ6bF2A3JwGvkPV1nz+Pgrc=; b=byJ1T3yxEAwfchlXpk5xYy2diPhvYpEE/+rXCQVQ83ePG1PiarrCAU3o2KN3jd2pYY 4m+Qcy7Ec+aPsQnFHgeKBZhJXj4wu3pYOcXZm71XoA9iWeAqM+rs7l5Kkh2KJTvngG01 YomYkUX4zAMTWakPAGS+SA+UAVEJt/vaFfGCWcEAYoklV5LQe6ouEHpoqwkxnkoEkyNz cMVp6edZpkzi15ivTaiQCv5hb+Qtq5L0iE9O2xUuCG4hKdecl0yGl5u4UkXXZnCRXsA6 sVMX+z2Y8f7vURn1GIntCFEEwpLLWpyP2eYMQvOSqcpVrhBry93AqU2F+w62eKwTqhRy tMYQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4DYql+aX3Sw+6frfcwSdn05GXjX+eyg8Q+rpdrSoT/ClUcG1m5 A3X86XT9m/QRzYK/LRJ/vX0= X-Google-Smtp-Source: AGs4zMYuMVmpGtsV8S6/S7uIE7NnSnMmVoRx6/zZ/6fix/jVNgqeXl8Bfi5pGsw2SWVFZ9Y9njyYWg== X-Received: by 10.28.147.75 with SMTP id v72mr143607wmd.2.1511176237881; Mon, 20 Nov 2017 03:10:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.144.2 with SMTP id s2ls877046wmd.12.canary-gmail; Mon, 20 Nov 2017 03:10:37 -0800 (PST) X-Received: by 10.28.190.7 with SMTP id o7mr1373902wmf.2.1511176237452; Mon, 20 Nov 2017 03:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176237; cv=none; d=google.com; s=arc-20160816; b=OBaO8wGscwrjnv8Au8z/Jbp2X7IuTd2VNeHc9aflc9AClPaJi5qI4qwfp9c2BUK+g6 HmUfcgqKUMCiCtyCyEiOEtAlXcPie01iLh62+3F84VIV5pNNPlQyZVrdjTm+2MR2TxyK GCsa6LpZLFL8RyZXydUq0kVA9UwKQgvYX9IE9bsSmPydZMAUUMF6NyyKO1QIoAE+5C4Q 6LtoG19tSa6co9utFjG/wqTHAgNpUyaQYylpi606AFBlj/GcUAP/dPDzgT0p7V+XgK0D J7UfPq3GQ1/ZGlHxgtDiNgKAKJ5qQRhnBnquw8G6gb1oA/9+8w452vbZp++eX13kwhZL 3CgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nJDZVUXlX2J09yH+Bciao3Dj/zCnUMS6rVLbdV9SG9U=; b=oqwgLtAKH+plmGXF/6tpsW+un3f6GQNu5AAutYmsVqpPsxTJc98sZiwuPwSJUkyphv VTgnsz28TjgHqLgUpjC9dFlTChj5qyzdfUJ4Ys2/9rf0MTy7pOCoq/oklnngivwl8LYh DZqDiC8IQHF9Quamyer5I3IbUFjBHVIceGdxPbSKtF4z5EmSVUKOyvNHXAD2MqzG1KTm vktx4MiN+w6zx3DvoCw1T/oMDbWj1EoN5RqasQstrOz5qZb9SpRWFTPwwjJtakVhJn4p 8T/+uN+pDOtYyxbRg7sYk7kQFAO2P/hgT0Z/6XWQVEzI+I/ragBJhEZKmltOk0hUKiK8 3hsg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 t37si824106wrc.3.2017.11.20.03.10.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:37 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxT1YjWz1qsDt; Mon, 20 Nov 2017 12:10:37 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxT1Gl8z1qqkZ; Mon, 20 Nov 2017 12:10:37 +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 bJmltKClTyA8; Mon, 20 Nov 2017 12:10:36 +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; Mon, 20 Nov 2017 12:10:35 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 8105A454057C; Mon, 20 Nov 2017 12:10:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V-oDY_l8cD95; Mon, 20 Nov 2017 12:10:32 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id DC6724540641; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 09/17] verify: let choose the SHA length Date: Mon, 20 Nov 2017 12:10:02 +0100 Message-Id: <1511176210-28928-9-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , SWUpdate uses only sha256 to compute hashes. Add a parameter to swupdate_HASH_init to let decide the caller the alg to be used. Signed-off-by: Stefano Babic --- core/cpio_utils.c | 2 +- corelib/verify_signature.c | 19 +++++++++++++------ include/sslapi.h | 21 ++++++++++++++++----- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/core/cpio_utils.c b/core/cpio_utils.c index de674ec..0112f12 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -137,7 +137,7 @@ int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs, unsi } if (IsValidHash(hash)) { - dgst = swupdate_HASH_init(); + dgst = swupdate_HASH_init(SHA_DEFAULT); if (!dgst) return -EFAULT; } diff --git a/corelib/verify_signature.c b/corelib/verify_signature.c index 0596578..3ffa328 100644 --- a/corelib/verify_signature.c +++ b/corelib/verify_signature.c @@ -29,12 +29,12 @@ #define BUFSIZE (1024 * 8) -static int dgst_init(struct swupdate_digest *dgst) +static int dgst_init(struct swupdate_digest *dgst, const EVP_MD *md) { int rc; ERR_clear_error(); - rc = EVP_DigestInit_ex(dgst->ctx, EVP_sha256(), NULL); + rc = EVP_DigestInit_ex(dgst->ctx, md, NULL); if (rc != 1) { ERROR("EVP_DigestInit_ex failed: %s\n", ERR_error_string(ERR_get_error(), NULL)); return -EINVAL; /* failed */ @@ -158,7 +158,7 @@ int swupdate_verify_file(struct swupdate_digest *dgst, const char *sigfile, goto out; } - if ((dgst_init(dgst) < 0) || (dgst_verify_init(dgst) < 0)) { + if ((dgst_init(dgst, EVP_sha256()) < 0) || (dgst_verify_init(dgst) < 0)) { status = -ENOKEY; goto out; } @@ -331,9 +331,10 @@ out: return status; } #endif -struct swupdate_digest *swupdate_HASH_init(void) +struct swupdate_digest *swupdate_HASH_init(const char *SHAlength) { struct swupdate_digest *dgst; + const EVP_MD *md; int ret; dgst = calloc(1, sizeof(*dgst)); @@ -341,6 +342,11 @@ struct swupdate_digest *swupdate_HASH_init(void) return NULL; } + if ((!SHAlength) || strcmp(SHAlength, "sha1")) + md = EVP_sha256(); + else + md = EVP_sha1(); + dgst->ctx = EVP_MD_CTX_create(); if(dgst->ctx == NULL) { ERROR("EVP_MD_CTX_create failed, error 0x%lx\n", ERR_get_error()); @@ -348,7 +354,7 @@ struct swupdate_digest *swupdate_HASH_init(void) return NULL; } - ret = dgst_init(dgst); + ret = dgst_init(dgst, md); if (ret) { free(dgst); return NULL; @@ -363,7 +369,8 @@ int swupdate_HASH_update(struct swupdate_digest *dgst, unsigned char *buf, if (!dgst) return -EFAULT; - EVP_DigestUpdate (dgst->ctx, buf, len); + if (EVP_DigestUpdate (dgst->ctx, buf, len) != 1) + return -EIO; return 0; } diff --git a/include/sslapi.h b/include/sslapi.h index 1df656d..9d02502 100644 --- a/include/sslapi.h +++ b/include/sslapi.h @@ -20,12 +20,14 @@ #ifndef _SWUPDATE_SSL_H #define _SWUPDATE_SSL_H +#define SHA_DEFAULT "sha256" + /* * openSSL is not mandatory * Let compile when openSSL is not activated */ -#if defined(CONFIG_HASH_VERIFY) || defined(CONFIG_ENCRYPTED_IMAGES) - +#if defined(CONFIG_HASH_VERIFY) || defined(CONFIG_ENCRYPTED_IMAGES) || \ + defined(CONFIG_SURICATTA_SSL) #include #include #include @@ -35,6 +37,7 @@ #include #include #include + #ifdef CONFIG_SIGALG_CMS #if defined(LIBRESSL_VERSION_NUMBER) #error "LibreSSL does not support CMS, please select RSA PKCS" @@ -42,6 +45,7 @@ #include #endif #endif + #include struct swupdate_digest { @@ -84,7 +88,7 @@ struct swupdate_digest { #if defined(CONFIG_HASH_VERIFY) int swupdate_dgst_init(struct swupdate_cfg *sw, const char *keyfile); -struct swupdate_digest *swupdate_HASH_init(void); +struct swupdate_digest *swupdate_HASH_init(const char *SHALength); int swupdate_HASH_update(struct swupdate_digest *dgst, unsigned char *buf, size_t len); int swupdate_HASH_final(struct swupdate_digest *dgst, unsigned char *md_value, @@ -99,8 +103,8 @@ int swupdate_HASH_compare(unsigned char *hash1, unsigned char *hash2); #define swupdate_dgst_init(sw, keyfile) ( 0 ) #define swupdate_HASH_init(p) ( NULL ) #define swupdate_verify_file(dgst, sigfile, file) ( 0 ) -#define swupdate_HASH_update(p, buf, len) -#define swupdate_HASH_final(p, result, len) +#define swupdate_HASH_update(p, buf, len) (-1) +#define swupdate_HASH_final(p, result, len) (-1) #define swupdate_HASH_cleanup(sw) #define swupdate_HASH_compare(hash1,hash2) (0) #endif @@ -123,5 +127,12 @@ void swupdate_DECRYPT_cleanup(struct swupdate_digest *dgst); #define swupdate_DECRYPT_cleanup(p) #endif +/* + * if openSSL is not selected + */ +#ifndef SHA_DIGEST_LENGTH +#define SHA_DIGEST_LENGTH 20 +#endif + #endif From patchwork Mon Nov 20 11:10:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23e; helo=mail-wr0-x23e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbmhqzliakgqe5v56giy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="VVUDvhrO"; dkim-atps=neutral Received: from mail-wr0-x23e.google.com (mail-wr0-x23e.google.com [IPv6:2a00:1450:400c:c0c::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxb5Mt7z9s5L for ; Mon, 20 Nov 2017 22:10:43 +1100 (AEDT) Received: by mail-wr0-x23e.google.com with SMTP id o14sf5806912wrf.6 for ; Mon, 20 Nov 2017 03:10:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176240; cv=pass; d=google.com; s=arc-20160816; b=ge1/PdlkNgSAQyHYWrKTsnC9vMWV9UC+ADb8U4HH764z97945LpQRkUFy7SfOxqUDQ gegOdib1nX8rqSmOudKTvFkdgSqVpf0R3lPH4rWD8ySMVhGSVdOdJEXFz4nPf4NwzKNi jAlu6imyQb0wjGtWfNDpu/Q6Euc/5EzB3bvhLAINaENabqilUkrUocs4ozcULQCPO83s 6bbqiscXnTPPM4lpa5yrZfRiXRfHnoK+l6+dup6wX6lps8gxfji3XfX1YEWi9heJvmV2 LV9Q20NVsegOARlNN1D2WUK1pMwoBZMpOI03R8KvufFkQcKZzK7F8f5JG7JKXbBB6Pa3 Rnvg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=FJFLskeBIMuV8yhRQUSHJR+QUy0RZ4u799MV/zmbvtg=; b=GgHjg9rKle9WjboUDJ1lVNavFpDE0JZRVkJp6ADsAQNKOloK4IxZV+fi2uvrElwaPT 092nWG+9wlx3DixlaO4fqZlNZGdoUnZHsDeNGr3aqSGgxcjuQq+/FqUTTjKEw2v8uzzE X+HWNqUtxnf4lHAreHH+zKwUyRW7cEBzZVNb4i35HEXH36m+hZn7omvARcy/QPvPkpeC TAJOIDrPHz+6TSatMDzLRPxIPZ/+3Gub1pIaZuCKoMF002hKtTFq6EaYRjIhvhcun7TT 05NDkce1Oz6B/DN3KjewVLQqavrrsqUVHwKhWM4dpuhOFp6oqUi7/6PSgqML4t2thUFc eicQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=FJFLskeBIMuV8yhRQUSHJR+QUy0RZ4u799MV/zmbvtg=; b=VVUDvhrOSxn9HqCmrly5P7v4L917QC53i5ZjaMAw/ePHNYL8c121jPzUtUNwGlMKsX ynoC6qWi281p8mt27DcqSnp3MaBdWguUIVKdNa46vp5qCoGxnp+j9bLMWDDLwE51t9Je gOPPuRCyj5jzG/DxZ0G5FGikcJoyepD8cLaf0VlaXoDDdJIDTUWOn1HMrI8Z1tfbGZlW uM6dCT1BkXkxoZeCynxTflizCeKe3DSRRbR6jwKkWETQFGwLEKYIOohsiKLsGF6kImeZ IFs36l4bb0sKJWi4Rhn4e6BUsceO6TUAqzRx6dZtUw4pX48RvV0RVObrzmXgHuZR1Ji+ bvJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=FJFLskeBIMuV8yhRQUSHJR+QUy0RZ4u799MV/zmbvtg=; b=cCQhhUMclNEMvMnRdIA7SFZVmkY7PXfbrBJ55h2v/jgX6v+Ts4C2146cw+7qHj00JJ 7/AoUdpZTjD9qYA6XPC0Usqxx5V/BUK2YYWYlUgbjUuhd4QIFdhlr4efBtR6DW5prxxt M5eV8L09zwhWb4PrMlaR/ssY4fpF0k2zdiiSnGLL+Mc7v2frX54HBP1UJoYVMqCrLLCR bcTtyVJ3iHyuuiw4Tu68/tiNBb/bEnoawI5Zg9vGeWLSeWCAQOuEpaWHbC9j6bJgnCW1 C1+mHA/TLSurorWfhghqrgO/TLtWUheWHpiJBybb1cY1j3aG6LIhrUS8g9sAmAE08kWU cXkQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX71/F84roDxFu39nhsot+DE4gKCDjuLhLrnQWRldgbGIWfZCmbU 77HcPOmVH0Li5Vd0Sjjglss= X-Google-Smtp-Source: AGs4zMbwqnkE9veQh3FPjMpliAjoy95KRrRbQX5wJ2kulqDOaIQjDkcM3Y9UeL/5ez3Rya/18cXCzw== X-Received: by 10.28.198.67 with SMTP id w64mr117482wmf.6.1511176240833; Mon, 20 Nov 2017 03:10:40 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.147.19 with SMTP id m19ls4975323eda.1.gmail; Mon, 20 Nov 2017 03:10:40 -0800 (PST) X-Received: by 10.80.164.203 with SMTP id x11mr4221303edb.7.1511176240522; Mon, 20 Nov 2017 03:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176240; cv=none; d=google.com; s=arc-20160816; b=U0o6FMh7slftDhOf41ADOiKCDyGwX4Dh8n3K2WgAirAe8BAndjC6EwqytP+1o1CmKx OeZn03JkXzVliqmAgHqYH70rzQct8R2687XRpPifmMTqCO/G6oe4XRxUgxUopp17a8Cx c9F3iRHg79KaPCvmIcRQmYM33hs0K1s+K1zXHoEe0RNSxHg9N2hnom8uyYqiU4q+OlBf 660yTuYYEM2Lac29c8xS4FbKErRAGFerjsLJeiGPQ/pMRyCIOkrEaqOSuXolqBDE9dQU awPvV2DmyrLWlYcDN7PaDqTnFcnZuBBMUi0HRhitl/8tcQsCqMcebEKk0/3Q5ZkmOGkN J4Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=hYB6txity2YON7JSLECsV6NKOY9is1RdUW4NKCUI/6c=; b=epWrrtKaEMw3s5CW/0tv9SETD37Jk/x9CDMZIQoFkZhiatsltTwRjhRX2jjQwFFoiu l/X7II3YScHZNEP1fSzYcj/4CpiK9YVuVvEoiNHOGpU1Th7KG6xgEpWXtTLrHaNEFDYc mVuw6stg+nho5lzoklICNnlV8d26MpFZbfWTeIwzwraGm9o0XpIJV4Y7UfAzEKQWS3dm MKCOLt7wHKfSUAZ4zGEwz0zMckzihatXzETuyniLbkU/psIHlAWHFfJ00cTUl/zioyhJ Age3sK5ifVtti/Sco8KIPusD8S7xdm6jm3UT+x90G3QZL74aosN6fc9rtB9fEp/L4oQk b2Bg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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.10]) by gmr-mx.google.com with ESMTPS id a23si621562edd.1.2017.11.20.03.10.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:40 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxX1jf4z1qtFg; Mon, 20 Nov 2017 12:10:40 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxX1bSmz1qqkW; Mon, 20 Nov 2017 12:10:40 +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 93VFOoO_S8oH; Mon, 20 Nov 2017 12:10:38 +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; Mon, 20 Nov 2017 12:10:38 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 119AD4540378; Mon, 20 Nov 2017 12:10:38 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DjyvUMhIGqEH; Mon, 20 Nov 2017 12:10:35 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id F3F7F4540645; Mon, 20 Nov 2017 12:10:19 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 10/17] channel_curl: use runtime detection for SSL Date: Mon, 20 Nov 2017 12:10:03 +0100 Message-Id: <1511176210-28928-10-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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: , Replace CONFIG_SURICATTA_SSL with a runtime variable to reuse the code with or without SSL enabled. Replace deprecated functions to compute SHA with EVP as described in openSSL documentation. SWUpdate has already a set of wrapper function that should be used instead of accessing to the underlying library. Signed-off-by: Stefano Babic --- corelib/channel_curl.c | 66 ++++++++++++++++++++++------------------------ include/channel_curl.h | 8 +++--- suricatta/server_hawkbit.c | 3 +++ 3 files changed, 38 insertions(+), 39 deletions(-) diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 073bf16..257efbe 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -29,12 +29,9 @@ #include #include #include -#ifdef CONFIG_SURICATTA_SSL -#include -#endif +#include "sslapi.h" #include "suricatta/channel.h" #include "channel_curl.h" -#include "suricatta/suricatta.h" #define SPEED_LOW_BYTES_SEC 8 #define SPEED_LOW_TIME_SEC 300 @@ -59,9 +56,6 @@ typedef struct { output_data_t *outdata; } write_callback_t; -#ifdef CONFIG_SURICATTA_SSL -static SHA_CTX checksum_ctx; -#endif /* Prototypes for "internal" functions */ /* Note that they're not `static` so that they're callable from unit tests. */ @@ -171,13 +165,17 @@ size_t channel_callback_write_file(void *streamdata, size_t size, size_t nmemb, if (!data) return 0; result_channel_callback_write_file = CHANNEL_OK; -#ifdef CONFIG_SURICATTA_SSL - if (SHA1_Update(&checksum_ctx, streamdata, size * nmemb) != 1) { - ERROR("Updating checksum of chunk failed.\n"); - result_channel_callback_write_file = CHANNEL_EIO; - return 0; + + if (data->channel_data->usessl) { + if (swupdate_HASH_update(data->channel_data->dgst, + streamdata, + size * nmemb) < 0) { + ERROR("Updating checksum of chunk failed.\n"); + result_channel_callback_write_file = CHANNEL_EIO; + return 0; + } } -#endif + if (ipc_send_data(data->output, streamdata, (int)(size * nmemb)) < 0) { ERROR("Writing into SWUpdate IPC stream failed.\n"); @@ -646,14 +644,15 @@ channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle) channel_op_res_t result = CHANNEL_OK; channel_data_t *channel_data = (channel_data_t *)data; -#ifdef CONFIG_SURICATTA_SSL - memset(channel_data->sha1hash, 0x0, SHA_DIGEST_LENGTH * 2 + 1); - if (SHA1_Init(&checksum_ctx) != 1) { - result = CHANNEL_EINIT; - ERROR("Cannot initialize sha1 checksum context.\n"); - goto cleanup; + if (channel_data->usessl) { + memset(channel_data->sha1hash, 0x0, SHA_DIGEST_LENGTH * 2 + 1); + channel_data->dgst = swupdate_HASH_init("sha1"); + if (!channel_data->dgst) { + result = CHANNEL_EINIT; + ERROR("Cannot initialize sha1 checksum context.\n"); + return result; + } } -#endif if (channel_data->debug) { curl_easy_setopt(channel_curl->handle, CURLOPT_VERBOSE, 1L); @@ -799,18 +798,20 @@ channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle) goto cleanup_file; } -#ifdef CONFIG_SURICATTA_SSL - unsigned char sha1hash[SHA_DIGEST_LENGTH]; - if (SHA1_Final(sha1hash, &checksum_ctx) != 1) { - ERROR("Cannot compute checksum.\n"); - goto cleanup_file; - } - char sha1hexchar[3]; - for (int i = 0; i < SHA_DIGEST_LENGTH; i++) { - sprintf(sha1hexchar, "%02x", sha1hash[i]); - strcat(channel_data->sha1hash, sha1hexchar); + if (channel_data->usessl) { + unsigned char sha1hash[SHA_DIGEST_LENGTH]; + unsigned int md_len; + if (swupdate_HASH_final(channel_data->dgst, sha1hash, &md_len) != 1) { + ERROR("Cannot compute checksum.\n"); + goto cleanup_file; + } + + char sha1hexchar[3]; + for (int i = 0; i < SHA_DIGEST_LENGTH; i++) { + sprintf(sha1hexchar, "%02x", sha1hash[i]); + strcat(channel_data->sha1hash, sha1hexchar); + } } -#endif cleanup_file: /* NOTE ipc_end() calls close() but does not return its error code, @@ -826,9 +827,6 @@ cleanup_header: curl_slist_free_all(channel_curl->header); channel_curl->header = NULL; -#ifdef CONFIG_SURICATTA_SSL -cleanup: -#endif return result; } diff --git a/include/channel_curl.h b/include/channel_curl.h index ed262fc..98240a9 100644 --- a/include/channel_curl.h +++ b/include/channel_curl.h @@ -20,9 +20,7 @@ #pragma once #include #include -#ifdef CONFIG_SURICATTA_SSL -#include -#endif +#include "sslapi.h" /* hawkBit Channel Implementation Private Header File. * @@ -55,9 +53,9 @@ typedef struct { unsigned int method; unsigned int retries; bool debug; + bool usessl; bool strictssl; int (*checkdwl)(void); -#ifdef CONFIG_SURICATTA_SSL + struct swupdate_digest *dgst; char sha1hash[SHA_DIGEST_LENGTH * 2 + 1]; -#endif } channel_data_t; diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index 100f0a0..59f4cb3 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -149,6 +149,9 @@ static channel_data_t channel_data_defaults = {.debug = false, .retries = DEFAULT_RESUME_TRIES, .retry_sleep = DEFAULT_RESUME_DELAY, +#ifdef CONFIG_SURICATTA_SSL + .usessl = true, +#endif .strictssl = true}; static struct timeval server_time; From patchwork Mon Nov 20 11:10:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23e; helo=mail-wm0-x23e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbmpqzliakgqe4i7bppq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="aPG7CkYC"; dkim-atps=neutral Received: from mail-wm0-x23e.google.com (mail-wm0-x23e.google.com [IPv6:2a00:1450:400c:c09::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxb26FZz9s4s for ; Mon, 20 Nov 2017 22:10:43 +1100 (AEDT) Received: by mail-wm0-x23e.google.com with SMTP id i17sf6192115wmb.7 for ; Mon, 20 Nov 2017 03:10:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176241; cv=pass; d=google.com; s=arc-20160816; b=kcTrbDrhQy79Om3GnRESSCfGLMviIw7KfPg+T/G0sRxiKFeou8v06gC8FYFn7lopp9 wFmBMYrvSw+iD297urMqAE07p8uqRL/mJkhc/21kL61mi7jLT/5D0T/IVWVyaqUYEbOG sVLXV4ALhn+emNMCdWBJpedoW708lGDit3WDB51F+EaCXn2Y2ykG4Xx0+7wFDG51kzzq kOv6TedblTR8gYaGBPoN3Zq+dA7DAunBr7QTR9vHO5odmHQO1syfi4HHctP2Mxcq4Ix2 bEIdMRvwkWIadgxV4DcxMQX4TN1+oT+UigpBT9iL0vhpWxSLsfG11fOZomCnqDCE1UPm IQrA== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=4G1VEkSRa5z6rO0nvtQZQkNzTzo4igyScZ/Kqz5bCOo=; b=A8XD91eYNXBydeYAQCzCcSyY7yTwJZk2Z6ZgLfeMNCi5NnkJ2QQqAkA8pBw6ds7WkJ 1MxB/Q16bBghM0JUz9CdwNwwNoNzlOorz/3HTW4SnMkq/kU2G0USd1I4VkBqZHTsH78R eZ5/ox6Fp2/yQDYiEzciEUyJBN/aJX2fz8hAtNJWzDBVk121JsgUK8mNpEuUw/eSmiCY CqZZjzMoL1YIdZiNZGjxlGnK9UOWk8xaLws9+ZTsqb9NtvXiYAhCGEiFM/9hN4rTUXrb eiflQzbauI3UJDhXt7LNhOg/8EjmkBRIhLJV5N3e1rMvgkJmCDynzsjzvlGVowmb5/Oc Fjlw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=4G1VEkSRa5z6rO0nvtQZQkNzTzo4igyScZ/Kqz5bCOo=; b=aPG7CkYCYaWA5GbNXqS+UVbvlRmnZOt8RoJBvlTfr3eEJD9g1DGSkvLQAlW7hh7qmu xYdIaRIMBQ4TkFo0aJZlFs/qrhyCWWACX5Y8XIy1mEu7jkiwom7ZVe9S1eLh3ujr1dZ6 Av1oBqka7Ju75ThPjL9k+MOjymTYRXDecrd7j1nOL5yYYieqqqLeK9BvPQg8OP/b292n 3TQRIOL2faCZS9Pv2QkNfQ/xYIVA2zL6ZoWlYj5QFtyXITADW+/jsW9mSu4NXMJzYrGu jNv9e+DSRqOkXN3g8NTuU1lYFSBYy5/lXp3wpq6/A+u4j9LVq0yoakGuFvFlDsp2XA2S r2vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=4G1VEkSRa5z6rO0nvtQZQkNzTzo4igyScZ/Kqz5bCOo=; b=Zs3BxnMvYClUb9bxLs6K/yynDESXExEysPZwoXg22d0tAhHYQBdn9HDw8clRdrngRQ TYW/rMyLTvJ0hONWmzubO6s+XvLIdruelve+AWTINM5a0blJO0TjZSLbjj39XlJH/DIr NvOr0bZqagZpJmVVkFxplBK3/nwSCWF3NMIXuKtEnXBZuMa15dQoVEFZmMglhG0MIHDO HAVj0/oNf5GxV1h/thMnJlQppvwMkXGaX1a7gat31DC2TlALQq0hxH4hPoQOXm+zo+bB iAYShr6lXquQnvenJc5D0FRRVKNBHTExLpN4lKSOQ47ihl3dd3AeawIqcExo67/e2o6z XANA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4rpQtE1nTx0cSzFnHCpTg95zkQfMfffEnsjZhdHBbAW01Gmc9Q mxFnH9mo7LC6uLuYAdl5VTY= X-Google-Smtp-Source: AGs4zMbfu8+eMQOkQB7MIFTC5PWL1xfFLsqIEgCCgJ8IkeOdWXfVD0LQu0/gEuDHj9bSlG/lxPT58Q== X-Received: by 10.28.113.149 with SMTP id d21mr143342wmi.5.1511176241110; Mon, 20 Nov 2017 03:10:41 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.130.71 with SMTP id e68ls898400wmd.9.gmail; Mon, 20 Nov 2017 03:10:40 -0800 (PST) X-Received: by 10.28.31.82 with SMTP id f79mr1299776wmf.26.1511176240954; Mon, 20 Nov 2017 03:10:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176240; cv=none; d=google.com; s=arc-20160816; b=ojWzzh9eraDFIaqvSAlEdCrisat4N41Cbw+wJEHM1v8jf+S5TN+pXFWfoSRMGZvK9c WTmPQQTjO6mmypKeFh266A4/kFpfspqZBFganvjmD9jszD/L+OF3515r9KVM80JChTzI UzSv1NqM847TK8hJbHM0fbkPCU87EgXWT7VX0/KVjP4+nywvG+NOPd4WNVMkWaIgYv1Q lfQv7TaP6hinUSB9z7ddD1yZDIORgg8nnZbEKZHrQdEQjQLShq8czFXDY5HRSPzG8aos LIAXjbJMB2Gv0bRLxLK75nFkAkrPiDYXXsO48Sl3rHXxERDVe02R2bXoDJ/A5avA9FTo 61pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ukZSMXoCf1flPzvYDnHjyWUNLLS1LcYXxCrEqSJVTmU=; b=kaIFkY5+uHNWK2ZCDlZ3qQEL1u1+GHciJVuLhh1NH7Q2vq2LP3ONVQNPTJP9JPXEix H7+MGg/Tqu3mO6J4xV+wHaAJJ9dIkiZztiDnNhwIsJ302jB7ljYeRL/XSO5jaw+mx2T/ jX6hFjwDwc45zzTJcn4TzLYWLiFICtwU93DKsUYHczac+qulxScIXs71Ptb0wovDZH// +GHWpdYSRdpqV2AYtcCfP0R4oR4xkZoDrRVjZXZnnMhrv0H6PfHHgS+xvlIT1lYTxsrR 1O+WNxgr8xVdyErxt5QIp0duZpMdNqOVMyQNGz4Sd0hKq1rNUPbQ02AFCW0oPNgLMrAU eYLw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 j13si442577wmh.1.2017.11.20.03.10.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:40 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxX5STXz1qsDt; Mon, 20 Nov 2017 12:10:40 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxX5M3dz1qqkc; Mon, 20 Nov 2017 12:10:40 +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 8Y5v9nG8ihh4; Mon, 20 Nov 2017 12:10:39 +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; Mon, 20 Nov 2017 12:10:39 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id E8139454057C; Mon, 20 Nov 2017 12:10:38 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Wk6_D5X8d4Cc; Mon, 20 Nov 2017 12:10:36 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 175B0454064D; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 11/17] Debug output in curl just if debug is set Date: Mon, 20 Nov 2017 12:10:04 +0100 Message-Id: <1511176210-28928-11-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , A debug flag is allowed for each connection made via libcurl. Check if the debug flag is set before calling DEBUG(/). Signed-off-by: Stefano Babic --- corelib/channel_curl.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 257efbe..705b887 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -538,8 +538,10 @@ static channel_op_res_t channel_post_method(channel_t *this, void *data) http_response_code); goto cleanup_header; } - TRACE("Channel put operation returned HTTP status code %ld.\n", - http_response_code); + if (channel_data->debug) { + TRACE("Channel put operation returned HTTP status code %ld.\n", + http_response_code); + } cleanup_header: curl_easy_reset(channel_curl->handle); @@ -790,8 +792,10 @@ channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle) http_response_code); goto cleanup_file; } - TRACE("Channel operation returned HTTP status code %ld.\n", - http_response_code); + if (channel_data->debug) { + TRACE("Channel operation returned HTTP status code %ld.\n", + http_response_code); + } if (result_channel_callback_write_file != CHANNEL_OK) { result = CHANNEL_EIO; @@ -822,6 +826,10 @@ cleanup_file: ERROR("Channel error while closing download target handle: '%s'\n", strerror(errno)); } + if (channel_data->dgst) { + swupdate_HASH_cleanup(channel_data->dgst); + } + cleanup_header: curl_easy_reset(channel_curl->handle); curl_slist_free_all(channel_curl->header); @@ -881,7 +889,9 @@ channel_op_res_t channel_get(channel_t *this, void *data) goto cleanup_chunk; } - DEBUG("Trying to GET %s", channel_data->url); + if (channel_data->debug) { + DEBUG("Trying to GET %s", channel_data->url); + } CURLcode curlrc = curl_easy_perform(channel_curl->handle); if (curlrc != CURLE_OK) { ERROR("Channel get operation failed (%d): '%s'\n", curlrc, @@ -890,7 +900,9 @@ channel_op_res_t channel_get(channel_t *this, void *data) goto cleanup_chunk; } - channel_log_effective_url(this); + if (channel_data->debug) { + channel_log_effective_url(this); + } long http_response_code; if ((result = channel_map_http_code(this, &http_response_code)) != @@ -905,8 +917,10 @@ channel_op_res_t channel_get(channel_t *this, void *data) } goto cleanup_chunk; } - TRACE("Channel operation returned HTTP status code %ld.\n", - http_response_code); + if (channel_data->debug) { + TRACE("Channel operation returned HTTP status code %ld.\n", + http_response_code); + } assert(channel_data->json_reply == NULL); enum json_tokener_error json_res; From patchwork Mon Nov 20 11:10:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::23f; helo=mail-lf0-x23f.google.com; envelope-from=swupdate+bncbcxploxj6ikrbmxqzliakgqeinpua3y@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="pPVKvvNW"; dkim-atps=neutral Received: from mail-lf0-x23f.google.com (mail-lf0-x23f.google.com [IPv6:2a00:1450:4010:c07::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxd1cYhz9s4s for ; Mon, 20 Nov 2017 22:10:45 +1100 (AEDT) Received: by mail-lf0-x23f.google.com with SMTP id a132sf1989707lfa.17 for ; Mon, 20 Nov 2017 03:10:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176242; cv=pass; d=google.com; s=arc-20160816; b=ilpviUdIfxuoHtHSnmEVedVctZKEX1ENjcidkSsRre25ABPo/YJfpE9Qhkyawj+ufz mz9SEZX1qa+kw8Xc5MKujq1jaQb4LQWn/h4AKmh3j/8nOS2WsPjh3BjBvTme91byjMRX qUeAF+JA9Zsa2JjFjpmZQMaOg1ZifhmGKpUbSm55+vmqvoIzPKSbRkdZHfF5aaBTzJQV xeX8va8pwOZFzHJTtXsae3d99y/AyFk7W1XfYBZVxeRbH9kbXfvVDwUlwKnUPNSQpWKt uvAPGDNO8VwGcW98ZbTB6KNIAgaad+4e/SoPfe99sQU3ED21EowEeND+RpomfUYTZosY Aw+Q== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=FwuNr3ORttF+nNc4tH6fdRtvraKeMMSbCdThGmzmod4=; b=dlTFYvKzbV/YnoKmZs1taOzePSbW/5Xq3ou2vnYbxybMIQSL8hOBMXlfG2K7YXO0sQ Cw7UC7VFcNUvIxdf+92ggVaFPCyhE9oOcKlrBNiAT37i5ssOe69JOLzhqWynQoyO1RBo xm/CqlqO5iX2WrC12CLhQJz2H+PrSUxOCbD5xowMBuy2x48h7o6KgeZz/Tzu86qllReY pW7Z/9BF5tv0qMDttZ5+qgZYia0xfuY5YeJc3+sEhBMvnrK54Z9QySR3Y2jvFb5Wf4mL 6XcvW0zFpUTrZjuEMG4rpZK9mA/4mio4pLwoos5mOA3CVstXp9FaI0exyoHxYQqyzTXM /PZA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=FwuNr3ORttF+nNc4tH6fdRtvraKeMMSbCdThGmzmod4=; b=pPVKvvNWfj62T8jCCO2SX5bQaFkrvsyY08D4i93miY4WtEHKWSKVtCplYRk7dmW2uM /XKYQiDlrcmOK5z7CpbT3kRI6OTNtlz0/zHBaP5IXwlU6kwp2p+/UEQlMSzRgRbD1+Gw UWvYb/dmkK75S+ttvjgh0djxeerxoNN5PRW239SIP2EbZTjr+FYg0aQA3c5etJPkXwwI +jFGtRQuvqg7aSzIRtTdrGQNmh4Y9oU5EPUWYi5cpiMUu/U50csLaBu3VwWhV/A1Z1cB s/429Dofa+DWHOyAqvrUXEkkbUmQ0pFcErvLskuWMx88Tl7eGj0pGAFRXAKIlg7tOyQ2 YySQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=FwuNr3ORttF+nNc4tH6fdRtvraKeMMSbCdThGmzmod4=; b=IoWAhzcEt7zveCOEwU5FxAcA82rEx2QUPPaBePOqr9bJQr8HJ96fjHRM6ZDqOssUAR xTyywjTYs9rpqjo7m9rep/eHf6G07JAVmlyX+nsIH2xGEKWO2Yp6yXGggl8rLMcHqjb3 ynAr5h4XluL8SmKBQT74nsXcyIj6McekFiVaGj5iUvdX/Sas1yDbyP97b7eReNq15qG6 pdQiqLMm+s9SAe3nuHPsNYoSX3bIjnpLYyT6s6vfx3TJ5PT7BeRXS2rdzH24qTYkKAbL sOUtAVNRH8mkJ1vxk9MMNyS9MRNoj1Yk5bv6WU5S7QM3kV45ll+18DSfI5n6jofTlV0r BKvQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX709k9Vd7UVwO1CtXYexX4IorK4mqO1GMmohTK5PktzzSpDradJ 6vvjxBhPWC3FymwbqFZXysI= X-Google-Smtp-Source: AGs4zMZE3EAvqMakQ7sS745AdMd/6BLSilc3EQ/aRIoLhN9+PwEFsCKEsWcwwdOeCsXwmjLyo82Eng== X-Received: by 10.25.115.140 with SMTP id h12mr21581lfk.3.1511176242695; Mon, 20 Nov 2017 03:10:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.20.8 with SMTP id u8ls1374352ljd.9.gmail; Mon, 20 Nov 2017 03:10:42 -0800 (PST) X-Received: by 10.46.56.19 with SMTP id f19mr460367lja.33.1511176242291; Mon, 20 Nov 2017 03:10:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176242; cv=none; d=google.com; s=arc-20160816; b=tt0DMenaFSjh7y6w/8a7waPbejTbPD4J0P4C3JWO9K20oGXF2A59HFREtfV3jkLTN1 rtPO293r0t5CPiCmtPjYahkLZIgrjirnRm6wxcMM++bpUA8P5K8kB1a+Bhid4i/9pddD Xwqa4fpTIXC/Sym/nKdqCG8AkoRY8vpM4Sw0IVm2i/SIxDNjFgnrkXocQea+bD+2xDL9 2sVv4BmNUcOTYshwSsD2s/a3e8kK4Ip/XYVvfLgBurq5RfTwy5Fa2OBtJTNnHrFERUio NxSqJ9y3VZwUZOqJuE9uqRCNp+0/pBdFEhtRQmI00yO53YqlTeSfAF/ENZJY9A3pchuV IXkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=sr/I0rX+tl97bRc89UdCgittAQU6sJ/FxB4PcKxZoVQ=; b=M7ytHAkkUCgk/jTto6JEcfD/y3UDWqQouhHbmn3Wm+WOJB+aFMVCq0njtN4apgIRwm AJRhJd6Fjy6GawHxTrp6a8pq/n6F+DzJ5LRWs6+f/DKUUsU3m+PGpgTkyPtQRm4L6ao6 jgmcIOkfulI6hASPeRBniK8jVzWAjrTVK/4r4qpTm9EVnlwXIWtf6OsAKKpgYYaMY8TV tTFhX3cTsOqrIaym/omjjxCZrsTMmioDv9Pd72Rskf6vUxXCQ+5KYnpTauit79mC6Enr VoZdMeH4YDYopKDDEjHR3SIIwYGiKBj1EP4fssEePvDT3KRyHCQnCTCzdfOsHSWD4hX6 jUOw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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.10]) by gmr-mx.google.com with ESMTPS id q27si770241lfd.0.2017.11.20.03.10.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:42 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxY5L9bz1qqkr; Mon, 20 Nov 2017 12:10:41 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxY565jz1qqkZ; Mon, 20 Nov 2017 12:10:41 +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 S6Kq6Igojvj5; Mon, 20 Nov 2017 12:10:40 +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; Mon, 20 Nov 2017 12:10:40 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 331164540625; Mon, 20 Nov 2017 12:10:40 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id n11681d5d1FA; Mon, 20 Nov 2017 12:10:38 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 31E3F4540650; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 12/17] Drop prototypes from suricatta API Date: Mon, 20 Nov 2017 12:10:05 +0100 Message-Id: <1511176210-28928-12-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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: , After moving to allocated channel, there is no need to export the channels function. Signed-off-by: Stefano Babic --- include/suricatta/channel.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/suricatta/channel.h b/include/suricatta/channel.h index 3b20c14..98fc851 100644 --- a/include/suricatta/channel.h +++ b/include/suricatta/channel.h @@ -36,9 +36,4 @@ struct channel { void *priv; }; -extern channel_op_res_t channel_open(channel_t *this, void *cfg); -extern channel_op_res_t channel_close(channel_t *this); -extern channel_op_res_t channel_put(channel_t *this, void *data); -extern channel_op_res_t channel_get(channel_t *this, void *data); -extern channel_op_res_t channel_get_file(channel_t *this, void *data, int file_handle); channel_t *channel_new(void); From patchwork Mon Nov 20 11:10:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::240; helo=mail-lf0-x240.google.com; envelope-from=swupdate+bncbcxploxj6ikrbnpqzliakgqe7hcta2y@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="IOy5TorV"; dkim-atps=neutral Received: from mail-lf0-x240.google.com (mail-lf0-x240.google.com [IPv6:2a00:1450:4010:c07::240]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxg6mJ3z9s5L for ; Mon, 20 Nov 2017 22:10:47 +1100 (AEDT) Received: by mail-lf0-x240.google.com with SMTP id g127sf2027066lfe.19 for ; Mon, 20 Nov 2017 03:10:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176245; cv=pass; d=google.com; s=arc-20160816; b=MCaSEFS60IOG0uWbDIlOsVHX1YfQ9GLpEAvkoNNidA0w/D8rpiuVQUKQaqtIbtgStc JNJgbF0qRyKCPu0CO5otVjVHDCJgdMIIATYWpF2aTiGuDQG8AoMrN06Y1vC3JwdF5cIz JmNFoCwOUoytjYAp0BFPuced0KJ+tZbnGZOdNJV6tjN2PY94siSvzbeELXmgEa1IM+hn 1QPa+yIJff3VOMREZLsCNgBHTnRYOeoJY94m59sfwAe74VXAQWU+PodfohEqIMAzRnIk uBVMjzW+KvfDfnr20hKqSZ08JpEdeoXWj25P8qCaIVj7Avz47HfUa17TEpa1WP8oJ0Gm IeGQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=UuSVSJCZrWVXLwOhrD6JQ2IrdbAHURHtjjLpuEFqhBU=; b=y803Msy3cilbH0d2Z9rs/B3sDmLFNGvaQ0DxBC0Fsybn/iWNJFYT6YhPdPE0e1PYWo qyB2ZRVWttqlbPcGeSC5MwfZcMYOs6RSTnTiyPIPRCZXBZ2qvEpgtg3w+4tpMLEK36Od jdod6cEYnwCFf4Az9bb40ha+OBF77P5e3/5D8M0CeYf2ni5OjvdNQE6zp9X50QXR8dzr DKl7sI2VexUq+wIjswdtUizK26dqHCPZFU0U3DkhBAj9IUYwwPkl7hiMyXx1HxJo+m63 rBwfHBTdDcOYiKqn1ifgI0U8+3gAT0vlkffsoOqkfvAT8ksaDBjLvlFctuPO60SYbSVq 6P1Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=UuSVSJCZrWVXLwOhrD6JQ2IrdbAHURHtjjLpuEFqhBU=; b=IOy5TorVwifk3YvDyWa8LH9e2o0+Q/vYjxnZkbiKv9V0t72ZWKryfW7tbAAUkzNd/7 AKfzRDB3QnouXL25kOERVKEr6baEZmX72FQYUmHcc8dhDSTuBxg0u2lyFrv9ERbGHWzO Rf1O7kMO5F7koC56Go+snqNVxoCN17EyYAwSdGaKiGnq+QjN84XQy7wMDVYKlDckvSgV 7dNUSfDEE5dwsQSggYEc4uI6V/9lcyXMpBQwyHyyxFADJkPgovHSGcJvg4YOKYjz6Xjr ECyq8waARn6ofZhWBZ2o3y9km6WLqs6/v5DuFPYGJKJ4kUkSFG355BCiOfiua4msJtFS 1m6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=UuSVSJCZrWVXLwOhrD6JQ2IrdbAHURHtjjLpuEFqhBU=; b=uA4QhV9OW1mCCtZpBC2UkK+BV3LdT9LhDHW3UKJLtXod8ag8ZqRfkwe4zLQroaa+H8 X5JQ4hgFBC2mP2yAXHX9oinkYOwp8Fxioee/QTOVjJezYWaevr9xazus4kMxjABikp/8 /JQ28MhLRuLuAxgCrXLssNFJzYRNKLOJp0FXoVzaqbXbO1Ld4jhXTsgKooWTqzZxRmB4 dC/hSgEDYofYWLmHb+7zi65aKliEmq7OjLck7V8Wrx1UIzcXGBqHsXwi7Rv1eYHBoRep lWUuP3huNdWhs7WtWxX1HOZNDWBSHm/lnCvh6GWxIfELRacPPoGRn5s6Xh9OhSVaeuFg Itlw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX63Nyq3hx/zUK/2bNBXKQRxxsnpH9uHpd1BoiPfxET+UZVZ9qev 9bEAIXbxrPWTGJ9pBeGyLO4= X-Google-Smtp-Source: AGs4zMbX8K6l9sNIQOnkJkwTcCeO6dPG+Z58wsQ9puYaSca4JsLGXtNFXBBYM/WcEa0VpUlzvEc7FQ== X-Received: by 10.46.95.76 with SMTP id t73mr31915ljb.12.1511176245082; Mon, 20 Nov 2017 03:10:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.101.66 with SMTP id z63ls1381946ljb.7.gmail; Mon, 20 Nov 2017 03:10:44 -0800 (PST) X-Received: by 10.46.57.19 with SMTP id g19mr453474lja.3.1511176244785; Mon, 20 Nov 2017 03:10:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176244; cv=none; d=google.com; s=arc-20160816; b=nA/BY+yAbBlN3iL0FCLP4VmqDnMo3VUNwyit45omFZ4DgCoIZ80CGIQyOBrqVPHyYa ds2FC8h8Y67ssaJCmmtjxvBP6DCbooNqndw6tCNANTcZB257nRVyQry25QRIm/gX43Js CJA5BqIh4xF47C6J90iTfPzvhI61plZ4ulZ2/qrAGHGRI8gBZBUbF/xsew+lmqcUSylO xrhe08KaC3DBiV7aZOaYomf8bxf1nyVFPF/XNFkmt4E/5DKsmNTVs8Cu4Ivk5mTkZylh /LtCONNIZ00yo3UIWQ/HX7Ms02eUsGghh1jM7V53EBsUqE89AJedjVUN2DKtjUnjWlZV whGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=D6W37fS5nGxNAV3tQpoFdtycAGlLdpRVyJPQeicLPpU=; b=HsUR2ObXmyd5HZgv5DNrg0Uvbic5OgTjFfnPv7JXKFxFsCHfGC9OiiOSF2kzVjfMUW IWAN583V+iq6aCQZHiaFXps/OiM7z3GLLj0WJFjVNCz1xojgW5+NI2SPF4c4nE5sJeQ6 Ubp+IewUs10h34aLENNo8cGIheY0FdGuJS712sUcNkBsVcLukQhEhpfc3t0jC7/ytExy sVlcl1Vi/qSM0Cn1oEuBIK4Wa9TPchg8zHkbSphjgcjz9mgvnbneG6KYdsLLcPypXzzf +y0zJKHlFdlfPZ9nUTyYFHEBF1KRNSpS+aF25dUsmYlWxf6IJYxcI8szTm+Hhn7Dk5pX nQXw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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.10]) by gmr-mx.google.com with ESMTPS id o75si625396lfc.2.2017.11.20.03.10.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:44 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxc1wFnz1qtFg; Mon, 20 Nov 2017 12:10:44 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxc1lZLz1qqkg; Mon, 20 Nov 2017 12:10:44 +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 MVajxupZBvXq; Mon, 20 Nov 2017 12:10:41 +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; Mon, 20 Nov 2017 12:10:41 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 3D9364540378; Mon, 20 Nov 2017 12:10:41 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LwdXL9aIxA6u; Mon, 20 Nov 2017 12:10:39 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 496674540664; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 13/17] Remove dependencies from suricatta for channel API Date: Mon, 20 Nov 2017 12:10:06 +0100 Message-Id: <1511176210-28928-13-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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: , Channel API is independent from suricatta daemon. Split the headers to separate channel API from suricatta. Signed-off-by: Stefano Babic --- include/channel_op_res.h | 37 +++++++++++++++++++++++++++++++++++++ include/suricatta/channel.h | 2 +- include/suricatta/suricatta.h | 16 ++-------------- 3 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 include/channel_op_res.h diff --git a/include/channel_op_res.h b/include/channel_op_res.h new file mode 100644 index 0000000..2e40ef1 --- /dev/null +++ b/include/channel_op_res.h @@ -0,0 +1,37 @@ +/* + * (C) Copyright 2017 + * Stefano Babic, DENX Software Engineering, sbabic@denx.de. + * + * Author: Christian Storm + * Copyright (C) 2016, Siemens AG + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +#pragma once + +typedef enum { + CHANNEL_OK, + CHANNEL_EINIT, + CHANNEL_ENONET, + CHANNEL_ENOMEM, + CHANNEL_EACCES, + CHANNEL_ENOENT, + CHANNEL_EIO, + CHANNEL_EILSEQ, + CHANNEL_EAGAIN, + CHANNEL_ELOOP, + CHANNEL_EBADMSG +} channel_op_res_t; diff --git a/include/suricatta/channel.h b/include/suricatta/channel.h index 98fc851..f0c13a7 100644 --- a/include/suricatta/channel.h +++ b/include/suricatta/channel.h @@ -18,7 +18,7 @@ */ #pragma once -#include "suricatta.h" +#include "channel_op_res.h" /* Suricatta Channel Interface. * diff --git a/include/suricatta/suricatta.h b/include/suricatta/suricatta.h index c04aff4..e38af4d 100644 --- a/include/suricatta/suricatta.h +++ b/include/suricatta/suricatta.h @@ -19,6 +19,8 @@ #pragma once +#include "channel_op_res.h" + /* Suricatta Main Interface. * * `start_suricatta()` is the main interface to suricatta's functionality. @@ -29,20 +31,6 @@ */ typedef enum { - CHANNEL_OK, - CHANNEL_EINIT, - CHANNEL_ENONET, - CHANNEL_ENOMEM, - CHANNEL_EACCES, - CHANNEL_ENOENT, - CHANNEL_EIO, - CHANNEL_EILSEQ, - CHANNEL_EAGAIN, - CHANNEL_ELOOP, - CHANNEL_EBADMSG -} channel_op_res_t; - -typedef enum { SERVER_OK, SERVER_EERR, SERVER_EBADMSG, From patchwork Mon Nov 20 11:10:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23f; helo=mail-wr0-x23f.google.com; envelope-from=swupdate+bncbcxploxj6ikrbnpqzliakgqe7hcta2y@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="Mq+JhkCG"; dkim-atps=neutral Received: from mail-wr0-x23f.google.com (mail-wr0-x23f.google.com [IPv6:2a00:1450:400c:c0c::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxg6mJQz9s71 for ; Mon, 20 Nov 2017 22:10:47 +1100 (AEDT) Received: by mail-wr0-x23f.google.com with SMTP id v8sf5793548wrd.21 for ; Mon, 20 Nov 2017 03:10:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176245; cv=pass; d=google.com; s=arc-20160816; b=w1XoLOh5zuZ+0T8n8+kNpy8qBKkZercQTOj0pfiiXxjs6dxGbT2FpvjidZ2ov8t2sh dirRfORIBkfcRKAozzTiOQID02zHrGoqABFkbG/UZYxXSvN1W2worByZdkFK1KstVAmE ZOnq+tfqID8xK9ke9oDh5qHQ0TMml9HIRhFUXCr5MrU6B+i2nCs2NVk5hIf1HdUQIX3h 98j6iYWNC1Z642LlRzjhvcdxdGuC9BQ5biDUmDUNUCsQqpqVyavOBK2JU/O5LyTEDw9w HRko8gXSnT4yPyegB1p50tEYZO30ofVNOcPuWprr8YQ6ppmg/7ap+cCFhXBx5r1GUYTV VDmw== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=quILr/4E9NgPfAt+GIXfTTD7KRh8sKMEivHCE1PU3xQ=; b=mS7bWHVoG3oDc+tIoUDnuqfPDwtv91IpGsXCWZLjCleMaVWP0J1RFq9uCI8YVaJRM3 MEHKyYMFKSnRTqKVKWj4RHtnJFwAfRhdYEdDskuvScQEhwCJnK1fwcpOP15gM111FhMD HVtQT2kipuOmTUge2UbAx6OVNvijyp15MSWm9Jc63XoEU7hRXjDneevVG2KaaG6SwfzO ZE+FJfw2UnRw/eHRZ3WRavMM/zYD0s2LSFl/eZcMAjJryuypFuRbFwKTK2u9O/iPxJef wm6PZW1NuCH95ui/drHYqAJqQPVJEqXrgCPrHF7Xn0TP9uqSOztpuQKpqC7Nbqteo0nd 8wcA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=quILr/4E9NgPfAt+GIXfTTD7KRh8sKMEivHCE1PU3xQ=; b=Mq+JhkCGZjxQ7khJB5kG97FAc8KOb9wpUO9e09yVh+6VFbwy9cakaEThaA7dxPqN8J 2j+V4S2zj0YlPVgS9D0eO7XGTk/dOxtU47UzDnSjf9rBWIWdZrbe4JQ3FvBALo9s+P2m 80tjSNYBhHEIcTPMNFzExJK5uEF6jNsBWZgljNFexWFQQQOJffu1DNTLRvXR07et+VdG yAJMBCCN0c1R0sE51l59wMgLrLbbBLSN3rNvD13QsZ7L2apck08uWbiiXeIltv3uYKWl UCLca/oLlyRaXdLDAKGx1O2gQMkzdiC/lbnPTL/Z/gChOgG0t3hzJurQhI7s2I1aLz6T Badg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=quILr/4E9NgPfAt+GIXfTTD7KRh8sKMEivHCE1PU3xQ=; b=gHU89T3RrAEwxVOBwjjRie+flNZZFdXnfksSaKJ3YImd22zcjutUlewzkuRssi05S4 FVnbUVJkZf+R3J6Y/ZB39cU4niEY6/1tMlOA5uibxyiOCRVKC7RY/sayooR0FdXzK9AM Py9G+Ps+x2rovYOBkV2ouEOArQMvxmSnYlprMTDKn7HLoeer29UwrnZ/bvJd1P7zfx1U Y/A6EctxCYAyc9wE9IIqEx5Y2tCchGcWdoz9agEcb0Uv0FwetKVmVvo3Q+d0kTIC0uLj Ujy2tG722fQQOWyPCKhzxMoTyHsDPfbNi7wPxlTyTPJ7mIuzivr/u4KDNakj8Wa1lb7P n7hQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX5MpaC/18Rr2uRmmlXoqsvMKchny880uYhbS16G3dqA4kHZZo9q R8k1ZTPNdLqLAYYUsgnHezc= X-Google-Smtp-Source: AGs4zMYgU+qZwPkF4xIhBNEUrFm1z5jPeEm2jHtuFb4rs+GmhI693vl5SDMrC2FCmXVVDIi8+IFVsQ== X-Received: by 10.28.209.143 with SMTP id i137mr26485wmg.4.1511176245322; Mon, 20 Nov 2017 03:10:45 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.26.20 with SMTP id a20ls900713wma.5.gmail; Mon, 20 Nov 2017 03:10:45 -0800 (PST) X-Received: by 10.28.20.212 with SMTP id 203mr1348449wmu.22.1511176245026; Mon, 20 Nov 2017 03:10:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176244; cv=none; d=google.com; s=arc-20160816; b=y9kC9OHgCAmIMLA2gwLSFU64U+pPfcTU5uDSQ0FJHSCT7OIIxebUKu6LeZp/gysUxY Uei/+GnvbRUe/qoZ1VUCMgaZsMgWN/hepD0LCavbQJl8SZGQOj9P3S0GgEf26evmfGIV SVAN9UReDlIEL0td1+hEi3ESxtZ6h+/UdpC1GHvMshosm2gahjPLUIDUQW0swAE5jdj2 ykFP/QRryQAZSxU9JOO0ZNnX+AtB9NIQ1cYFcWhBBxJXSk4kNcCbMWVR+mz7e14rQaiS rnWYWe/sG04ratJCL3XDjmMpp46X3IKSTqxVtccAUFnbU2ziCDeIDfN8mW9WX0YgPM6q Gj4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=4q/6+oGeKBkb80uGWLmvuWnOKFqc5aJC/X64VmLLSzM=; b=N+kxkH44zLaw+NW4HcEIXIuD35mkDNssdtk1TdzySQhPvVLtENHa9J6mrB7S2/2drK QiWLKKemRtoroqoos73lG13i5zJ7IUBO5ulFTnXAFs44jK3BQ7BBUv75mzJpCdG3lOCr 0PlPQbloHfp31rX7yBsvmp7Y18k9kyD/Vfek1FWif76IB02dJY8mPJ4vNqgtn6zASCTn BuL5k3SsiIQDDjYYDE9UkqiAVv28v9lGj/yhTuwNUW8svpwtd2a2BNvfmj+6Ub1rMHCC NYoAYXhcQvzzCho7O5qIcAJfw9s4WooXrCvwqPZI0aJsad5/+JaBq8LpJ5Onz+AyRZlx bBpg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 i136si718149wmd.2.2017.11.20.03.10.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:44 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxc5tSqz1qsSh; Mon, 20 Nov 2017 12:10:44 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxc5ndDz1qqkW; Mon, 20 Nov 2017 12:10:44 +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 su1qKcdP3P_h; Mon, 20 Nov 2017 12:10:43 +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; Mon, 20 Nov 2017 12:10:43 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id B1D23454057C; Mon, 20 Nov 2017 12:10:42 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tB8rlo-MT0Ey; Mon, 20 Nov 2017 12:10:40 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 63EBD454066F; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 14/17] Move channel.h away from suricatta Date: Mon, 20 Nov 2017 12:10:07 +0100 Message-Id: <1511176210-28928-14-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , Signed-off-by: Stefano Babic --- corelib/channel_curl.c | 2 +- include/channel.h | 39 +++++++++++++++++++++++++++++++++++++++ include/suricatta/channel.h | 39 --------------------------------------- suricatta/server_hawkbit.c | 2 +- suricatta/server_hawkbit.h | 1 - 5 files changed, 41 insertions(+), 42 deletions(-) create mode 100644 include/channel.h delete mode 100644 include/suricatta/channel.h diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c index 705b887..608f5d3 100644 --- a/corelib/channel_curl.c +++ b/corelib/channel_curl.c @@ -30,7 +30,7 @@ #include #include #include "sslapi.h" -#include "suricatta/channel.h" +#include "channel.h" #include "channel_curl.h" #define SPEED_LOW_BYTES_SEC 8 diff --git a/include/channel.h b/include/channel.h new file mode 100644 index 0000000..f0c13a7 --- /dev/null +++ b/include/channel.h @@ -0,0 +1,39 @@ +/* + * Author: Christian Storm + * Copyright (C) 2016, Siemens AG + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +#pragma once +#include "channel_op_res.h" + +/* Suricatta Channel Interface. + * + * Each suricatta channel has to implement this interface. + * Cf. `channel_hawkbit.c` for an example implementation targeted towards the + * [hawkBit](https://projects.eclipse.org/projects/iot.hawkbit) server. + */ +typedef struct channel channel_t; +struct channel { + channel_op_res_t (*open)(channel_t *this, void *cfg); + channel_op_res_t (*close)(channel_t *this); + channel_op_res_t (*get)(channel_t *this, void *data); + channel_op_res_t (*get_file)(channel_t *this, void *data, int file_handle); + channel_op_res_t (*put)(channel_t *this, void *data); + void *priv; +}; + +channel_t *channel_new(void); diff --git a/include/suricatta/channel.h b/include/suricatta/channel.h deleted file mode 100644 index f0c13a7..0000000 --- a/include/suricatta/channel.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Author: Christian Storm - * Copyright (C) 2016, Siemens AG - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc. - */ - -#pragma once -#include "channel_op_res.h" - -/* Suricatta Channel Interface. - * - * Each suricatta channel has to implement this interface. - * Cf. `channel_hawkbit.c` for an example implementation targeted towards the - * [hawkBit](https://projects.eclipse.org/projects/iot.hawkbit) server. - */ -typedef struct channel channel_t; -struct channel { - channel_op_res_t (*open)(channel_t *this, void *cfg); - channel_op_res_t (*close)(channel_t *this); - channel_op_res_t (*get)(channel_t *this, void *data); - channel_op_res_t (*get_file)(channel_t *this, void *data, int file_handle); - channel_op_res_t (*put)(channel_t *this, void *data); - void *priv; -}; - -channel_t *channel_new(void); diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index 59f4cb3..9649d27 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -32,7 +32,7 @@ #include #include #include "suricatta/suricatta.h" -#include "suricatta/channel.h" +#include "channel.h" #include "channel_curl.h" #include "suricatta/state.h" #include "server_hawkbit.h" diff --git a/suricatta/server_hawkbit.h b/suricatta/server_hawkbit.h index 51938c9..fba399c 100644 --- a/suricatta/server_hawkbit.h +++ b/suricatta/server_hawkbit.h @@ -19,7 +19,6 @@ #pragma once #include -#include #include #include From patchwork Mon Nov 20 11:10:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4010:c07::23c; helo=mail-lf0-x23c.google.com; envelope-from=swupdate+bncbcxploxj6ikrbnxqzliakgqe5xttjqy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="NMec/Xj+"; dkim-atps=neutral Received: from mail-lf0-x23c.google.com (mail-lf0-x23c.google.com [IPv6:2a00:1450:4010:c07::23c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxh58wsz9s72 for ; Mon, 20 Nov 2017 22:10:48 +1100 (AEDT) Received: by mail-lf0-x23c.google.com with SMTP id x76sf1061041lfb.7 for ; Mon, 20 Nov 2017 03:10:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176246; cv=pass; d=google.com; s=arc-20160816; b=H9AITT8fhQAqXtQpbqMWy8DxZFBEruu//6CINNZSMahQfjwoH0QF+sbjybUi4txTJL E+OFdXQKMmpD9GeCQSk+9IlIkwmCKb7QQLC9NxgoMxAOMJUv00gmVozVGNrIgqvcGGxA oEus16Osj1T8bhLro1umdENn4Fwzj3b1THMAkjYUcfnamLlXgzhrqG3YmRKkVC3lK5d6 0Dnrsr2ZP6iXcPgdUlYRScP4lcaN4mWMawGeL63ySV66HH70iVtAJ8r+nvM6cr5Q5/S2 vXo5ItGsgY4SdBO/qCg/n4a8LCehAU3omOWOe0MgZ+axn9LO7rhZvNdVjJ5G02IT/ZzU WHFg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=t5e3Hv+lgVkFeL4aiRIld4J2syswnlD4pZcs9iRWT4g=; b=yWDFfNzHYJqihabNCj7aXHd5BTh9Xe/HgTnd2I5q4xIbxU+sl7H5xsosp4reD8/9H+ zes1FR1zqWG+vwVluXFY2HRH3pKT/Dmn276adIVLy1tVF/8jHBR9+RX4AhOFSr6ma6rl VOKQ9MLWRDTbwGdRJvh+803J0+lJpVJTElNxyClvcaDEwwIwNtnyyBhN3HzawKCDPCdl Cfp9WWJ56a+IIlNZto1VFNVXYAy1E3u8q/ztBgHD92pIK5jXLKmvurxtWbw/u6NBYjEh KdRY622az7pkWE2OrhvxpudLqG7l97HECYbGGvyaIQuLlY6tn0Cob3/lmhBo6X+LRDjC 8KlQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=t5e3Hv+lgVkFeL4aiRIld4J2syswnlD4pZcs9iRWT4g=; b=NMec/Xj+Lyj1zyHegx9xQxcdPKq/6barxtLR01Ycg4eqHRjgnjaK1/bEboylDyrkr5 QxLJzSPxb9C7zpA67Wyd9myma2TIhwaZcs+zdkn/JDwhxazV+Ob4zIyVXu7yM4kRIU5+ t7cWuoAWphV9R7mbvkVGuD5VSBQsqSsP9NjedUbU7Exh3lghapBL6ZmWf3lwtxreyYAc /LZ+J/7hNo/L6eTukfVgHa5lJxVWaxx1UtCyEOnip+fUdF5gNBjfDAaY42PLJxqVTBvS pBwm3VLGkcrqfLaI3bDTQmmsQ3G/DmnmQf/ODogsx76nK9+7fYpqa1Pt2Gl+xL2OACMf Srsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=t5e3Hv+lgVkFeL4aiRIld4J2syswnlD4pZcs9iRWT4g=; b=U0Utqjew8OK2AsL1FQMbSaK6l3qSL9aXxw1QfORFRaTKnGn8I8sUo+pMQlO21MARvU zqih64CjANEG+CVpzVKj59LLi/RCd8UjN3B0/K8mg7dnWwttjK9DXL0OBP1x6s+8+/d9 6GuSV8Nv81e/fax0tCbw/sCDM65H3D9q5p/z2Jpf3/9AiKjsgFLjYWIsBJGhxbIIBK70 Z5u9lwnWAgp9beIvrDIqRd/NY1rgabXgArQXJg4GEpREh1PAzdacKXMzUM2ZtQ6/akia ncEjqMfQqbGlqlw4PZyW0uouspke57mxbSL/PdvZB3I5l45i1a62rUT/2bvezg7o2BLr +Tmw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX7uVTiz9fELtBLd+zDzXEOEC6Jt/h7Wa1u8aCH/pVZqExFZll25 NxJA9uj/i0mVzXhDtYqxd/8= X-Google-Smtp-Source: AGs4zMYyUFLdQo6vgYkyM3X+VUU1L942HuAbFbWug/Ey0jFqCf1NJDkXCObk8OG0ksOPGvkDo5gRQA== X-Received: by 10.46.42.129 with SMTP id q123mr23114ljq.4.1511176246079; Mon, 20 Nov 2017 03:10:46 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.101.66 with SMTP id z63ls1381957ljb.7.gmail; Mon, 20 Nov 2017 03:10:45 -0800 (PST) X-Received: by 10.46.33.198 with SMTP id h67mr404328lji.41.1511176245930; Mon, 20 Nov 2017 03:10:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176245; cv=none; d=google.com; s=arc-20160816; b=yJz+KLrKjY0xbi9rrLoCT2VyeSKj9kUrtST5qRlhVut4SIUHfS6yIyWMXf3uychkbb kb9WW9Gyzn23lt4ptX6SfIzS3qenVmoNWssqrBLbZwHyxeEGuIOY+XRlsuud6CmBweNe dYwlLutaE1kJodRNZ77RVnaZdHKS1fDiDN6g0TJMwMKYR7cfrjYgoKi1KnzZAArUHhSS rzY30HJtDJo6udR2yGDoqaPtNWoij/xGhxzGYiTg2r9on/n6Zf4AdnTW6ulCXq8nnEXJ cMArw29OgFxTh184zA1iDgIK9T8y5EtYdpDNPT1spG24tuk2Zx5C9HHdzmEOg6F4LekO hQHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=zSTBsUjThsTQZZFO5o3kfP5do+KxtKIrswD2Ya/6wPY=; b=gDoWtY/esX5V0y0uOXtkzTXn8u0nI/JrD7t22hinmsKeTkVmv5JON7Y/2HtxiqvACn 3+9C5P449vHrhsPn7/a8p9B34cpPcJD3XGYncIlydpyKqibQKoni+xMc/xY7Y+oFAa+h 6O0amrrHyWP0FwEQKAHxc6aoq3DCwPtZvdnKgLUp7+loMjIbd/bThHiUTMGarIl4BFut e4y2egtAqlhiNC0WOrc75BkUMmr7OtUQM7WOmPnEZ3/QSxGjuXfu0stemiiMroPQcw4V 77d4RzyRU0vVWodZPBbxsoblmWwjDh3FXAur5p0GJET0VM2O45p9guiJss8vT/hE2LkV zwJg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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.10]) by gmr-mx.google.com with ESMTPS id q27si770255lfd.0.2017.11.20.03.10.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:45 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.10; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 3ygQxd2x5Hz1qqkr; Mon, 20 Nov 2017 12:10:45 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxd2h73z1qqkW; Mon, 20 Nov 2017 12:10:45 +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 iGSXAPpQb5vS; Mon, 20 Nov 2017 12:10:44 +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; Mon, 20 Nov 2017 12:10:44 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 8A10E4540623; Mon, 20 Nov 2017 12:10:43 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ujGY_msjcdN9; Mon, 20 Nov 2017 12:10:41 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 7DA944540679; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 15/17] Factorize some json function for reuse Date: Mon, 20 Nov 2017 12:10:08 +0100 Message-Id: <1511176210-28928-15-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.10 is neither permitted nor denied by best guess record for 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: , Signed-off-by: Stefano Babic --- corelib/parsing_library_libjson.c | 47 ++++++++++++++++++++++++++++++++++++ include/parselib.h | 5 ++++ suricatta/server_hawkbit.c | 50 +-------------------------------------- 3 files changed, 53 insertions(+), 49 deletions(-) diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c index 2f64d41..67cbc2c 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -31,6 +31,8 @@ #include "swupdate.h" #include "parselib.h" +#define MAX_URL_LENGTH 2048 + json_object *find_json_recursive_node(json_object *root, const char **names) { json_object *node = root; @@ -114,3 +116,48 @@ void get_field_json(json_object *e, const char *path, void *dest) get_value_json(e, dest); } } + +json_object *json_get_key(json_object *json_root, const char *key) +{ + json_object *json_child; + if (json_object_object_get_ex(json_root, key, &json_child)) { + return json_child; + } + return NULL; +} + +const char *json_get_value(struct json_object *json_root, + const char *key) +{ + json_object *json_data = json_get_key(json_root, key); + + if (json_data == NULL) + return ""; + + return json_object_get_string(json_data); +} + +json_object *json_get_path_key(json_object *json_root, const char **json_path) +{ + json_object *json_data = json_root; + while (*json_path) { + const char *key = *json_path; + json_data = json_get_key(json_data, key); + if (json_data == NULL) { + return NULL; + } + json_path++; + } + return json_data; +} + +char *json_get_data_url(json_object *json_root, const char *key) +{ + json_object *json_data = json_get_path_key( + json_root, (const char *[]){"_links", key, "href", NULL}); + return json_data == NULL + ? NULL + : strndup(json_object_get_string(json_data), MAX_URL_LENGTH); +} + + diff --git a/include/parselib.h b/include/parselib.h index c32920a..7c44a5e 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -58,6 +58,11 @@ void get_value_json(json_object *e, void *dest); void get_field_json(json_object *e, const char *path, void *dest); void *get_child_json(json_object *e, const char *name); json_object *find_json_recursive_node(json_object *root, const char **names); +json_object *json_get_key(json_object *json_root, const char *key); +const char *json_get_value(struct json_object *json_root, + const char *key); +json_object *json_get_path_key(json_object *json_root, const char **json_path); +char *json_get_data_url(json_object *json_root, const char *key); #else #define find_node_json(a, b, c) (NULL) diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index 9649d27..175396c 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -32,6 +32,7 @@ #include #include #include "suricatta/suricatta.h" +#include "parselib.h" #include "channel.h" #include "channel_curl.h" #include "suricatta/state.h" @@ -45,7 +46,6 @@ #define DEFAULT_RESUME_DELAY 5 #define INITIAL_STATUS_REPORT_WAIT_DELAY 10 -#define MAX_URL_LENGTH 2048 #define STRINGIFY(...) #__VA_ARGS__ #define JSON_OBJECT_FREED 1 #define ENOMEM_ASPRINTF -1 @@ -109,11 +109,6 @@ static hawkbit_enums_t hawkbit_enums[] = { extern channel_op_res_t channel_curl_init(void); /* Prototypes for "internal" functions */ /* Note that they're not `static` so that they're callable from unit tests. */ -json_object *json_get_key(json_object *json_root, const char *key); -const char *json_get_value(struct json_object *json_root, - const char *key); -json_object *json_get_path_key(json_object *json_root, const char **json_path); -char *json_get_data_url(json_object *json_root, const char *key); server_op_res_t map_channel_retcode(channel_op_res_t response); server_op_res_t server_handle_initial_state(update_state_t stateovrrd); static int server_update_status_callback(ipc_message *msg); @@ -208,49 +203,6 @@ static bool hawkbit_enum_check(const char *key, const char *value) return false; } -json_object *json_get_key(json_object *json_root, const char *key) -{ - json_object *json_child; - if (json_object_object_get_ex(json_root, key, &json_child)) { - return json_child; - } - return NULL; -} - -const char *json_get_value(struct json_object *json_root, - const char *key) -{ - json_object *json_data = json_get_key(json_root, key); - - if (json_data == NULL) - return ""; - - return json_object_get_string(json_data); -} - -json_object *json_get_path_key(json_object *json_root, const char **json_path) -{ - json_object *json_data = json_root; - while (*json_path) { - const char *key = *json_path; - json_data = json_get_key(json_data, key); - if (json_data == NULL) { - return NULL; - } - json_path++; - } - return json_data; -} - -char *json_get_data_url(json_object *json_root, const char *key) -{ - json_object *json_data = json_get_path_key( - json_root, (const char *[]){"_links", key, "href", NULL}); - return json_data == NULL - ? NULL - : strndup(json_object_get_string(json_data), MAX_URL_LENGTH); -} - static const char *json_get_deployment_update_action(json_object *json_reply) { if (!json_reply) From patchwork Mon Nov 20 11:10:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839522 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::237; helo=mail-wr0-x237.google.com; envelope-from=swupdate+bncbcxploxj6ikrbohqzliakgqeyeb3w4q@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="DL2xosa/"; dkim-atps=neutral Received: from mail-wr0-x237.google.com (mail-wr0-x237.google.com [IPv6:2a00:1450:400c:c0c::237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxk3dZjz9s4s for ; Mon, 20 Nov 2017 22:10:50 +1100 (AEDT) Received: by mail-wr0-x237.google.com with SMTP id v8sf5793627wrd.21 for ; Mon, 20 Nov 2017 03:10:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176248; cv=pass; d=google.com; s=arc-20160816; b=jYnk0oBLGGiR+NeD8mUOl10Wr2B8MkV7GGZghd94r2iV9OiXyPc9X1I79EwMw9FtVt IZK4MfSeyjqjZaHHfYrGq65vPJ5fjtPdEUim79zWQ/zM9/wpfKI1/6eBiOBcxNHcnKBv L77y4msyJCDbflchHxuE/rUGnH71Gm/ob9fBqF2Fn7vumB2EaMUV4f+A/+8CSOqwXtI9 E+gyPP4Br3nRIYf73b0c2LRVmZxP1GNZQ3XEDuNSyPj8J66J4RqgoIf/u+ZG725h6C20 XV74MetgQi6Nxfpl+rX4RMO6Qx1vjVbdO0FaqNhIy76RcbtArQwA+Dx92mpjbqtR14P3 +BaQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=RzApW62yklpDriIRgmguVmtj0/zF0o/cRtJg5tokoq0=; b=PDwpaqJ1wTUfFoGY8YYIRG2J2i1vCfqDE1JbDtlp1SYSN8ri4i/bryO1npm1bxYErd JsF+PZnipdHdmy7mYYlormB9+J7hv4J2etDg26UZk0nttUjNVECz6xUw0V4mh745s5oI /RhVqFwJ+DP0WC4iVdX/tuU6F4E9IpDciYgMBJfTx0MvCdG1mbFIXWlrDWWqELgknimj ct80uvh2/jv0RUTN/vdKtVjT2rvn4j/x49aRt0Ol1qEcTBlTiblggrJn9pFQki8cJIXA xo+X9B2xWcb6CM0XtwxszUHIbmlC30+fFznSpwL6Ei7s09s5g+U4PO6M1WFWW2X6CBpx iIsw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=RzApW62yklpDriIRgmguVmtj0/zF0o/cRtJg5tokoq0=; b=DL2xosa/FfqLFDlt8CtsN4Eh6zqglozJPXU1LZaZc6OC+4B8g8lrV3dGVrsYkLQzZA GOVoBo+R91kkjCkjh48uG+q2XwVKRTWhp1B2qrmC51cvQ53S1Q+2mFIGaTl7NIikGCbs FK3xu+XBwRFeESnonFPE0DaLzWHSL2+ET+dOpD8Qa3ezcrtdEHvv5T6Oqsojv0p9Z45Z 9nBVmS7vGlJ7OcTHrqFPAyg6TXF56bWEurOywOSCCA3CKJWR7bDvA21ZwEWgijfN/NxC 4QBJT3zSOa2bLd7MuqEvswoNAJSQwXgZ26GP+lBJi3I7p5zZTEotpWihFa0d23s2CcBd sekA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=RzApW62yklpDriIRgmguVmtj0/zF0o/cRtJg5tokoq0=; b=Z0Xor2njX1lm88wiMReSNyXBEGdH5y0F7t+gMipu4ssV9U0lQktyIgXzLekmXUeUeF pSq1v7/BYCcRXQjPAfa772y3OMGmlHHoPRH//k7wk9CzbUuIBYz02VKjjThZBf3Vs88d jXpMcsXsuq5o6g6yhtF7qD6xKnQtfmRbTpWJsPMMWS1YYoNoNyJv8/mE71QUKtnch/rk 8RH+YXHWXljNmIUkfbFJX3mpnIT9sxmXDHi4wSkmN2k3xqQkdkiXOCZVfexmBoPeFHHf UVHDmkIHd2IXPj6rtOn7A+AF2LLkatjCRGxqVI/3hNxSOXx5yeiiNXDZfxtnF80S3RgQ WbCA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX6zvq0ST5qy6+BYe9PniQ4uBithAfGuZCVg2lWYbd8UWAui1aFA tX/Sldhv5eFFL94kaomHwvE= X-Google-Smtp-Source: AGs4zMaOkdfGIVwc/derhHYqdt3P8RI5sYq6ORHYfWJ7AX8wYSxSeQE6bNBGrRcuVVXPyaBjYCKX4w== X-Received: by 10.28.0.2 with SMTP id 2mr89569wma.3.1511176248302; Mon, 20 Nov 2017 03:10:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.120.3 with SMTP id t3ls892472wmc.5.canary-gmail; Mon, 20 Nov 2017 03:10:47 -0800 (PST) X-Received: by 10.28.132.74 with SMTP id g71mr1241701wmd.15.1511176247725; Mon, 20 Nov 2017 03:10:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176247; cv=none; d=google.com; s=arc-20160816; b=ZysOhNo1ZOkw5p2rDUAp2rMsx53wxK1e3uzwdvf5Wih6b2Z4Im1AFziLuAybQwQGtQ gAD9pdw3ieNi1vReiGcgZcAkVDm45J9XvDudcEoEmvCR0sJVp8g35i7SgjiGzCEKDDBy JzEWOglnt2oquEFk/fTmOFbB5RD1vaPGMyQo7ElysPe2TKYa0Z79yUqAEsjhYLkoXd0/ 4Qmw5tQ97uoYKOtd18O2uj5gx47iL6EqMDNPex/MgellhZjUmDOrokoMnv9Js1XCwCpe W7jcWyG/7aHFDPfNGTQOBkPK3toPLCPF6b9qtiebNsmc/OIx9oLFZQxfK0KqvCn9wtdk nQUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=SdyJPotmIXKladHJaT6aGL5mh3nmqg6d4KubEYVfURI=; b=mTxkczMnSjcolVMLrm1XVFNbbV/h5OI/3JQGO0JH4ZiCiVIhsvn23SaM/EGIaNMrCn FDe0hg0xcHKLN8RsmcVB0jWiGzgLmV0Yd/f1JwgRFR99hd3AcH6NzrszSFcRGYJ+PeB9 wvMU86iqY5sWCSvS34DZgj186KrwgslUGdz/g7ZWpQ33ibzq2V4/CU7dzx9qQsZ7SXIq 3n8P3jIQRePddnSwduXqoWbKwcfwIVcjGYFjrtMPOk0/QBB0VkMCx8l6Udxsr5w6DHVK baUUYANWU1ewLfp/+u9yak9324zgewFvYDwpzunhvXgWQi0RMCxJkzbK8TdpAYas4KQN RJnw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 t37si824130wrc.3.2017.11.20.03.10.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:47 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxg3nSjz1qsSX; Mon, 20 Nov 2017 12:10:47 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxg3cD4z1qqkZ; Mon, 20 Nov 2017 12:10:47 +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 lXdcHfup7Zcy; Mon, 20 Nov 2017 12:10:46 +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; Mon, 20 Nov 2017 12:10:46 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 6E8914540378; Mon, 20 Nov 2017 12:10:45 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WpC8LhnA979c; Mon, 20 Nov 2017 12:10:42 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 95CEF454067B; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 16/17] handler: swupdate forwarder Date: Mon, 20 Nov 2017 12:10:09 +0100 Message-Id: <1511176210-28928-16-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , Add a handler to forward SWU images. A global SWU can contain other SWU that are forwarded to other devices (or subsystems) running SWUpdate as well. The handler transfers an embedded SWU to all destinations assigned into sw-description at the same time (streaming works with the handler). The destinations are defined in properties for the entry: { filename = "image.swu"; type = "swuforward"; properties: ({ name = "url"; value = "http://:8080"; } ); } The handler assumes that the destinations are running SWUpdate with activated Webserver and uses the REST-API to send the image. Signed-off-by: Stefano Babic --- handlers/Config.in | 15 ++ handlers/Makefile | 1 + handlers/swuforward_handler.c | 465 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 481 insertions(+) create mode 100644 handlers/swuforward_handler.c diff --git a/handlers/Config.in b/handlers/Config.in index 5264f0d..596f069 100644 --- a/handlers/Config.in +++ b/handlers/Config.in @@ -161,6 +161,21 @@ config REMOTE_HANDLER comment "remote handler needs zeromq" depends on !HAVE_LIBZEROMQ +config SWUFORWARDER_HANDLER + bool "SWU forwarder" + depends on HAVE_LIBCURL + select CURL + select JSON + default n + help + This allows to build a chain of updater. A + SWU can contains other SWUs for other systems. + The handler takes a list of URLs and forward the + embedded SWU to the other devices using the + Webserver REST API. + +comment "SWU forwarder requires libcurl" + depends on !HAVE_LIBCURL config BOOTLOADERHANDLER bool "bootloader" diff --git a/handlers/Makefile b/handlers/Makefile index b51e3ec..f89bbad 100644 --- a/handlers/Makefile +++ b/handlers/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_SHELLSCRIPTHANDLER) += shell_scripthandler.o obj-$(CONFIG_RAW) += raw_handler.o obj-$(CONFIG_REMOTE_HANDLER) += remote_handler.o obj-$(CONFIG_BOOTLOADERHANDLER) += boot_handler.o +obj-$(CONFIG_SWUFORWARDER_HANDLER) += swuforward_handler.o diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c new file mode 100644 index 0000000..b59de98 --- /dev/null +++ b/handlers/swuforward_handler.c @@ -0,0 +1,465 @@ +/* + * (C) Copyright 2017 + * Stefano Babic, DENX Software Engineering, sbabic@denx.de. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ + +/* + * This handler allows to create a mesh of devices using SWUpdate + * as agent. The handler is called if an artifact is a SWU image + * and sends it to the devices provided in sw-description. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "bsdqueue.h" +#include "channel_curl.h" +#include "channel.h" +#include "parselib.h" + +/* + * The Webserver in SWUpdate expets a custom header + * with the filename + */ +#define CUSTOM_HEADER "X_FILENAME: " +#define MAX_WAIT_MS 30000 +#define POST_URL "/handle_post_request" +#define STATUS_URL "/getstatus.json" + +/* + * The hzandler checks if a remote update was successful + * asking for the status. It is supposed that the boards go on + * until they report a success or failure. + * Following timeout is introduced in case boards answer, but they do not + * go out for some reasons from the running state. + */ +#define TIMEOUT_GET_ANSWER_SEC 900 /* 15 minutes */ +#define POLLING_TIME_REQ_STATUS 50 /* in mSec */ + +void swuforward_handler(void); + +/* + * Track each connection + * The handler maintains a list of connections and sends the SWU + * to all of them at once. + */ +struct curlconn { + CURL *curl_handle; /* CURL handle for posting image */ + const void *buffer; /* temprary buffer to transfer image */ + unsigned int nbytes; /* bytes to be transferred per iteration */ + size_t total_bytes; /* size of SWU image */ + char *url; /* URL for forwarding */ + bool gotMsg; /* set if the remote board has sent a new msg */ + RECOVERY_STATUS SWUpdateStatus; /* final status of update */ + LIST_ENTRY(curlconn) next; +}; +LIST_HEAD(listconns, curlconn); + +/* + * global handler data + * + */ +struct hnd_priv { + CURLM *cm; /* libcurl multi handle */ + unsigned int maxwaitms; /* maximum time in CURL wait */ + size_t size; /* size of SWU */ + struct listconns conns; /* list of connections */ +}; + +/* + * CURL callback when posting data + * Read from connection buffer and copy to CURL buffer + */ +static size_t curl_read_data(void *buffer, size_t size, size_t nmemb, void *userp) +{ + struct curlconn *conn = (struct curlconn *)userp; + size_t nbytes; + + if (!nmemb) + return 0; + if (!userp) { + ERROR("Failure IPC stream file descriptor \n"); + return -EFAULT; + } + + if (conn->nbytes > (nmemb * size)) + nbytes = nmemb * size; + else + nbytes = conn->nbytes; + + memcpy(buffer, conn->buffer, nbytes); + + conn->nbytes -= nbytes; + + return nmemb; +} + +/* + * This is the copyimage's callback. When called, + * there is a buffer to be passed to curl connections + */ +static int swu_forward_data(void *data, const void *buf, unsigned int len) +{ + struct hnd_priv *priv = (struct hnd_priv *)data; + int ret, still_running = 0; + + struct curlconn *conn; + LIST_FOREACH(conn, &priv->conns, next) { + conn->nbytes += len; + conn->buffer = buf; + } + + do { + int ready = 1; + + LIST_FOREACH(conn, &priv->conns, next) { + if (conn->nbytes > 0) { + ready = 0; + break; + } + } + + /* + * Buffer transferred to all connections, + * just returns and wait for next + */ + if (ready) + break; + + int numfds=0; + ret = curl_multi_wait(priv->cm, NULL, 0, priv->maxwaitms, &numfds); + if (ret != CURLM_OK) { + ERROR("curl_multi_wait() returns %d", ret); + return FAILURE; + } + + curl_multi_perform(priv->cm, &still_running); + } while (still_running); + + if (!still_running) { + LIST_FOREACH(conn, &priv->conns, next) { + /* check if the buffer was transfered */ + if (conn->nbytes) { + ERROR("Connection lost, data not transferred"); + } + conn->total_bytes += len - conn->nbytes; + if (conn->total_bytes != priv->size) { + ERROR("Connection lost, SWU not transferred"); + return -EIO; + } + } + ERROR("Connection lost, skipping data"); + } + + return 0; +} + +/* + * Send a GET to retrieve all traces from the connected board + */ +static int get_answer(struct curlconn *conn, RECOVERY_STATUS *result, bool ignore) +{ + channel_data_t channel_cfg = { + .debug = false, + .retries = 0, + .retry_sleep = 0, + .usessl = false}; + channel_op_res_t response; + channel_t *channel = channel_new(); + + /* + * Open a curl channel, do not connect yet + */ + if (channel->open(channel, &channel_cfg) != CHANNEL_OK) { + return -EIO; + } + + if (asprintf(&channel_cfg.url, "%s/%s", + conn->url, STATUS_URL) < 0) { + ERROR("Out of memory.\n"); + return -ENOMEM; + } + + /* Retrieve last message */ + response = channel->get(channel, (void *)&channel_cfg); + + if (response != CHANNEL_OK) { + channel->close(channel); + free(channel); + free(channel_cfg.url); + return -1; + } + + json_object *json_data = json_get_path_key( + channel_cfg.json_reply, + (const char *[]){"Status", NULL}); + if (json_data == NULL) { + ERROR("Got malformed JSON: Could not find Status"); + DEBUG("Got JSON: %s\n", json_object_to_json_string(json_data)); + return -1; + } + int status = json_object_get_int(json_data); + + json_data = json_get_path_key( + channel_cfg.json_reply, + (const char *[]){"Msg", NULL}); + const char *msg = json_object_get_string(json_data); + + json_data = json_get_path_key( + channel_cfg.json_reply, + (const char *[]){"LastResult", NULL}); + if (json_data == NULL) { + ERROR("Got malformed JSON: Could not find Last Result"); + DEBUG("Got JSON: %s\n", json_object_to_json_string(json_data)); + return -1; + } + int lastResult = json_object_get_int(json_data); + + if (strlen(msg) > 0) + conn->gotMsg = (strlen(msg) > 0) ? true : false; + + if (!ignore) { + if (strlen(msg)) { + TRACE("Update to %s : %s", conn->url, msg); + } + if (status == IDLE) { + TRACE("Update to %s : %s", conn->url, + (lastResult == SUCCESS) ? "SUCCESS !" : "FAILURE"); + } + } + + free(channel_cfg.url); + channel->close(channel); + free(channel); + + *result = lastResult; + + return status; +} + +static int retrieve_msgs(struct hnd_priv *priv, bool ignore) +{ + struct curlconn *conn; + int ret; + int result = 0; + + LIST_FOREACH(conn, &priv->conns, next) { + int count = 0; + do { + ret = get_answer(conn, &conn->SWUpdateStatus, ignore); + if (!conn->gotMsg) { + usleep(POLLING_TIME_REQ_STATUS * 1000); + count++; + } else + count = 0; + if (count > ((TIMEOUT_GET_ANSWER_SEC * 1000) / + POLLING_TIME_REQ_STATUS)) { + ret = -ETIMEDOUT; + } + } while (ret > 0); + if (ret != 0 || (conn->SWUpdateStatus != SUCCESS)) { + ERROR("Update to %s was NOT successful !", conn->url); + result = -1; + } + } + + return result; +} + +static int install_remote_swu(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + struct hnd_priv priv; + struct curlconn *conn; + int ret, still_running = 0; + struct dict_entry *url; + struct curl_slist *headerlist; + CURLMsg *msg = NULL; + + /* + * A single SWU can contains encrypted artifacts, + * but the SWU itself canot be encrypted. + * Raise an error if the encrypted attribute is set + */ + + if (img->is_encrypted) { + ERROR("SWU to be forwarded cannot be encrypted"); + return -EINVAL; + } + + /* Reset list of connections */ + LIST_INIT(&priv.conns); + + /* initialize CURL */ + ret = curl_global_init(CURL_GLOBAL_DEFAULT); + if (ret != CURLE_OK) { + ret = FAILURE; + goto handler_exit; + } + priv.cm = curl_multi_init(); + priv.maxwaitms = MAX_WAIT_MS; + priv.size = img->size; + + /* + * Parse handler properties to get URLs for destination + * + */ + LIST_FOREACH(url, &img->properties, next) { + char curlheader[SWUPDATE_GENERAL_STRING_SIZE + strlen(CUSTOM_HEADER)]; + + if (!url->varname || !url->value || strcmp(url->varname, "url")) + continue; + + conn = (struct curlconn *)calloc(1, sizeof(struct curlconn)); + if (!conn) { + ERROR("FAULT: no memory"); + ret = -ENOMEM; + goto handler_exit; + } + + headerlist = NULL; + + conn->curl_handle = curl_easy_init(); + conn->url = url->value; + + if (!conn->curl_handle) { + /* something very bad, it should never happen */ + ERROR("FAULT: no handle from libcurl"); + return FAILURE; + } + + snprintf(curlheader, sizeof(curlheader), "%s%s", CUSTOM_HEADER, img->fname); + headerlist = curl_slist_append(headerlist, curlheader); + + if ((curl_easy_setopt(conn->curl_handle, CURLOPT_POST, 1L) != CURLE_OK) || + (curl_easy_setopt(conn->curl_handle, CURLOPT_READFUNCTION, + curl_read_data) != CURLE_OK) || + (curl_easy_setopt(conn->curl_handle, CURLOPT_READDATA, + conn) !=CURLE_OK) || + (curl_easy_setopt(conn->curl_handle, CURLOPT_USERAGENT, + "libcurl-agent/1.0") != CURLE_OK) || + (curl_easy_setopt(conn->curl_handle, CURLOPT_POSTFIELDSIZE, + img->size)!=CURLE_OK) || + (curl_easy_setopt(conn->curl_handle, CURLOPT_HTTPHEADER, + headerlist) != CURLE_OK)) { + ERROR("curl set_option was not successful"); + ret = FAILURE; + goto handler_exit; + } + + /* get verbose debug output please */ + curl_easy_setopt(conn->curl_handle, CURLOPT_VERBOSE, 1L); + + char *posturl = NULL; + posturl = (char *)malloc(strlen(conn->url) + strlen(POST_URL) + 1); + sprintf(posturl, "%s%s", conn->url, POST_URL); + + /* Set URL */ + if (curl_easy_setopt(conn->curl_handle, CURLOPT_URL, posturl) != CURLE_OK) { + ERROR("Cannot set URL in libcurl"); + free(posturl); + ret = FAILURE; + goto handler_exit; + } + free(posturl); + curl_multi_add_handle(priv.cm, conn->curl_handle); + LIST_INSERT_HEAD(&priv.conns, conn, next); + } + + retrieve_msgs(&priv, true); + + curl_multi_perform(priv.cm, &still_running); + + ret = copyimage(&priv, img, swu_forward_data); + + if (ret) { + ERROR("Transferring SWU image was not successful"); + goto handler_exit; + } + + /* + * Now checks if transfer was successful + */ + int msgs_left = 0; + while ((msg = curl_multi_info_read(priv.cm, &msgs_left))) { + CURL *eh = NULL; + int http_status_code=0; + if (msg->msg != CURLMSG_DONE) { + ERROR("curl_multi_info_read(), CURLMsg=%d\n", msg->msg); + ret = FAILURE; + break; + } + LIST_FOREACH(conn, &priv.conns, next) { + if (conn->curl_handle == msg->easy_handle) { + eh = conn->curl_handle; + break; + } + } + + if (!eh) { + ERROR("curl handle not found in connections"); + ret = FAILURE; + break; + } + + curl_easy_getinfo(eh, CURLINFO_RESPONSE_CODE, &http_status_code); + + if (http_status_code != 200) { + ERROR("Sending %s to %s failed with %d", + img->fname, conn->url, http_status_code); + ret = FAILURE; + break; + } + } + + /* + * Now check if remote updates were successful + */ + if (!ret) { + ret = retrieve_msgs(&priv, false); + } + +handler_exit: + LIST_FOREACH(conn, &priv.conns, next) { + LIST_REMOVE(conn, next); + curl_multi_remove_handle(priv.cm, conn->curl_handle); + curl_easy_cleanup(conn->curl_handle); + free(conn); + } + + curl_multi_cleanup(priv.cm); + + return ret; +} + +__attribute__((constructor)) +void swuforward_handler(void) +{ + register_handler("swuforward", install_remote_swu, + IMAGE_HANDLER, NULL); +} From patchwork Mon Nov 20 11:10:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 839523 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::237; helo=mail-wm0-x237.google.com; envelope-from=swupdate+bncbcxploxj6ikrbohqzliakgqeyeb3w4q@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="hbN0YN8o"; dkim-atps=neutral Received: from mail-wm0-x237.google.com (mail-wm0-x237.google.com [IPv6:2a00:1450:400c:c09::237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ygQxl0CL7z9s5L for ; Mon, 20 Nov 2017 22:10:50 +1100 (AEDT) Received: by mail-wm0-x237.google.com with SMTP id b189sf6206254wmd.5 for ; Mon, 20 Nov 2017 03:10:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1511176248; cv=pass; d=google.com; s=arc-20160816; b=nJethB4eGhlepcTw60W0qjys1tZF+4t/Be65x1kYV8SAcAEmA3gq7siO8/Oo0qZ3sQ a1KuoiCKJ+QkTt1OHdZYjiuuEkkmcJBkP7tkrPx0mmFqiJdkshqf/Eaxzxvax+LoqYl0 dEUZdf5id0vqb7REN8HpM0KoRiS0xzdlTt7W3GLDVo6fA2vGK+t9vX9LY0602lH3PItq b0clm6DU9Ncx4jFadZU/rAEGg4v3UwBbFbT2Z5NfB2NYd/APSoRDeu+nJzHPhVoD8RJJ dtlJyzZeVyDnSkU3Y8QJ2xl3BH2T9cnR1LXeVRSKb1GRk7mhqsEH4OVGIFZm/NTGAqf8 ogcg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=0boR/xr/wwMFXSGCTwBGWPg0sivoPGMZ3OZQ+AFpuH4=; b=NIzbuY8z9IKnE91rETU832VXz/INbfe6c/Pl7rkPZRFC3eXqPWSGb0y6hAUEhBUzTt TJFXXryx21JCNRO5CPF8ji7rPiyzzk7Ad5XogLvIj7X9PZvQm311L+QczZmk7m+zb7Bt Kt/pRge7qhvy3kaAO5JpAeVNjnYdcWxJCuEBmkDStvYRy9i/UNwLpbdQaXGp80p59m5b ESdJO6+flpP5xKu9skgfxIzPshvpOaMPtSra9tbrfMWOSicSps3xNEMKhWYp7d+Ly9WC R/phFIjkcmvEbO6tNFypvYUOCm5LPcO000PZpC+Ej6yCA+AhCq2Yfv+WwAKww7so7iSL GGdQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0boR/xr/wwMFXSGCTwBGWPg0sivoPGMZ3OZQ+AFpuH4=; b=hbN0YN8o8r0IkHpOavK6qNmsi4OkKagz8i+gRvuIgvpbX5Re+YlEn7oioPdwNMLAkW zR62r/cCRnOQxmn3seZIDBu4GOsIii7ouN+GMYxWxXtOajG0i5BgGFXOsizo5cyyGMom tCuVGOC06GCN63DNQjaw0TONBIy+zRZCncaezJQvKhKx7vw3UtT7iRtvMhzYwb7Vz7ds VMIlgUsLkkRI0IDYcx+Fw2vc/m/ROFUr7FtJnLBtxzrhQEjSIBwHympCQvpQZniM1j9W VMQ+VId5sgN/koEq7XjqYGFuR47Z9cpGG5TSpjqEKbNcGnTlNVblFLYFB95+tjejuqsC m1lQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references: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=0boR/xr/wwMFXSGCTwBGWPg0sivoPGMZ3OZQ+AFpuH4=; b=YNsq2YVsu78uCm0Da086IhBWsY8ijltOCj7OMwTHBGVLaZgC0qwBbM0jyArec3qwmF IS+D58VGR3UzwefGWlKHoAN3kIc17sbT0ABcfHXhLbmbfKIP9FZ9md2bsN9Cvhk1R4tb pyeQhEqBXT1+g5/dwVzLpSaMm0NnN9tmFClZtzVqdvZBph7ztmB6jVuE2W9Up5wYYnJy EgsWpVyyaO3dRXSY6nFdwGnO5HJ9n/eNAr1+PYviLHjYvofPXvKdmvJ/f/trumLLfX8X DSHQh1AmEjzd61ZOVH915Grj6NEgIOTiGJujznJnsEcz1z9mG2HBFN4y3L0YBsYV9CTb iGRg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AJaThX4grvFJdMnf6Zyp/d7qOZnWe5G/A9f9E/aBdhwgqeofwsQVooow HlMBhxxBIr+7233jbi3EOvU= X-Google-Smtp-Source: AGs4zMYyh1exT6DzGJAna/8k0PnUKv0ncIxaR0lKI7JU6XcZBnUkPs6el4D3EcYGEabSf1wWridJsQ== X-Received: by 10.28.202.18 with SMTP id a18mr145524wmg.6.1511176248219; Mon, 20 Nov 2017 03:10:48 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.139.130 with SMTP id n124ls888532wmd.10.canary-gmail; Mon, 20 Nov 2017 03:10:47 -0800 (PST) X-Received: by 10.28.31.82 with SMTP id f79mr1299844wmf.26.1511176247882; Mon, 20 Nov 2017 03:10:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511176247; cv=none; d=google.com; s=arc-20160816; b=l6RGGuQOYanwJnLYr28p0d6+x5f/+A/cvCev8wzfZbqLMj3dBOAoqyqO5Zjau0v1Ni ov/2sEid9ztcu1GlsO8D7Je+LzkQa/Ooum12K0cVgoMnN6DlSN5/rZWab4944Y6IZkLZ 81lvOTZu3j3xmjVJqUYT8jWBaWFtjbJCnrVLVyFbb4M3ATIYgDDTlvYl79dt1eh5gv3b TynQwG6thoBgJtCjAjyz6CVlqqIAQ51qUM5BjTgJE/BP4WC6gBoZgtSvzCGOq4j6/wUr v3u+SH7l5kciXXd9ULsT/PLr4ntaFBBvXcAJW1tIAE+Kv2ga7Qx3LqTu+iW1Wbh4GXOR 110w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IeBPOooHl0wH+W9f1GAb7dgBYZyelRGk1fsE/hNMAKg=; b=Togvcuc9C4NvLZFus2z2p/Dx1RHcaAkCwrwR2T05ljAqeylXLVORymyUrxds1Il2Kc kYL1yzW4zd98veR/+GlknqOzC20peQBSDBs8MbHeZ8KIcgvkcXyxibkL+CjMRoi62DyU W/rdUXCx2zuv7/hhPQL0m9ijjBMXDK9LQKhta1dHypdgFP0txySNfxz2uGvCsl+Eqd03 lFzAO1qhh/lua13acrLM/WKI39M5vcgr5jnhDA1aM1TUG0o/1bTuqtCtZ1RK3qm1cmHO xomCzmsBNg25lpEsTodZEldav0XvK+RqfwkEiAwhrqTCgAELz523elEGLCLiA24mqMzU sTKw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 o2si681831wmf.1.2017.11.20.03.10.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 03:10:47 -0800 (PST) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for 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 3ygQxg4tzvz1qsSZ; Mon, 20 Nov 2017 12:10:47 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3ygQxg4ktjz1qqkW; Mon, 20 Nov 2017 12:10:47 +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 fbnBGSNEsBGo; Mon, 20 Nov 2017 12:10:46 +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; Mon, 20 Nov 2017 12:10:46 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 22661454057C; Mon, 20 Nov 2017 12:10:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iW-7cVcipdAx; Mon, 20 Nov 2017 12:10:43 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id B285145406DC; Mon, 20 Nov 2017 12:10:20 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 17/17] doc: add doc for SWU forwarder handler Date: Mon, 20 Nov 2017 12:10:10 +0100 Message-Id: <1511176210-28928-17-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511176210-28928-1-git-send-email-sbabic@denx.de> References: <1511176210-28928-1-git-send-email-sbabic@denx.de> 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 best guess record for 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: , Signed-off-by: Stefano Babic --- doc/source/handlers.rst | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 5536e0f..0167245 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -258,8 +258,8 @@ image, this is not implemented as it carries some security implications since the behavior of SWUpdate is changed dynamically. -Remote handlers ---------------- +Remote handler +-------------- Remote handlers are thought for binding legacy installers without having the necessity to rewrite them in Lua. The remote @@ -311,3 +311,38 @@ It is duty of the external process to take care of the amount of data transferred and to release resources when the last chunk is received. For each DATA message, the external process answers with a *ACK* or *NACK* message. + +SWU forwarder +--------------- + +The SWU forwarder handler can be used to update other systems where SWUpdate +is running. It can be used in case of master / slaves systems, where the master +is connected to the network and the "slaves" are hidden to the external world. +The master is then the only interface to the world. A geenral SWU can contain +embedded SWU images as single artifacts, and the SWU handler will forward it +to the devices listed in the descritpion of the artifact. +The handler can have a list of "url" properties. Each url is the address of a +secondary board where SWUpdate is running with webserver activated. +The SWU handler expects to talk with SWUpdate's embedded webserver. This helps +to update systems where an old version of SWUpdate is running, because the +embedded webserver is a common feature present in all versions. +The handler will send the embedded SWU to all URLs at the same time, and setting +``installed-directly`` is supported by this handler. + +The following example shows how to set a SWU as artifact and enables +the SWU forwarder: + + +:: + + images: ( + { + filename = "image.swu"; + type = "swuforward"; + + properties: ( + { + name = "url"; + value = "http://192.168.178.41:8080"; + }); + });