From patchwork Thu Sep 6 11:40:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 966929 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=209.85.221.55; helo=mail-wr1-f55.google.com; envelope-from=swupdate+bncbcxploxj6ikrbrveytoakgqeyfmw72y@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="NGIyCu4G"; dkim-atps=neutral Received: from mail-wr1-f55.google.com (mail-wr1-f55.google.com [209.85.221.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425dtd0ntqz9s55 for ; Thu, 6 Sep 2018 21:40:56 +1000 (AEST) Received: by mail-wr1-f55.google.com with SMTP id d17-v6sf2049812wrr.14 for ; Thu, 06 Sep 2018 04:40:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1536234054; cv=pass; d=google.com; s=arc-20160816; b=kTTwLkAlEx0r4v+zXzTavX4A71cbLHOYRXxwwUI+EIRWex8chE2YmX4UMeUGLqMqhW jKxZjUrshrTOHSe8pfKLjR7ek40fU0PS8Wxd2CFdiH7e4esuSiOlKDtpderozC+T53yh kxfBo7wjbSlHj3NHjcHZFLcglco7/iXFuuFLaXzzBVBU3a9JsGcac+X98XKnh3td8RAk mFCORfjBZaWdpuTwG8gNdIIrIgyc4WYBqFU0lYTOq6HMm2pZi2Uhk5vWCdSvzNHGLepS fsDT89+AYP83obHI00bNBeg6x9SjFEZnwNtIRjKVgS2P+yzYDBhjRXKS7XjCj/2pHbo7 5e2A== 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:mime-version:sender:dkim-signature; bh=q3TkFqoIuuZicTstqCVhtwPJvKlEBpEpbiUVv0iCtGk=; b=jlYSS3eYDIA3T6FVTen7qXq9biKSlLryXh7cnhFWEXIbg+KqOItL5LJvJBqG4wAmJh u0eVsL+bM4BDvLXQPPuV+y++Q9DeR8aNYn8Gr4ZGEkESnrE44oDPlFSklc3Ncvs0fGM0 xOY9x3Lql/dHkRQ+iTHJarQf+iICcD79CwWtLGLtho64dexHXNAn/o6aBVmbou1DhuNm eQOrrT6SEmjJ5jerWiSmzvgZstnM//UOcwxO7nYf8o3j5jGJdCOceYzi7wGjSX8/RxPt zw6Fjt02czpD84YsPyLdVqY9Ang/BCV4Rr10UDQhS8ORAYDHgkEPheFIBUgyuwc+L/EM MSLg== 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=q3TkFqoIuuZicTstqCVhtwPJvKlEBpEpbiUVv0iCtGk=; b=NGIyCu4GK+nsg7Wd0JXS4BTuiVcqjcCmOQwJIO0JBKeWMVbAXAa3RVkiUTih7/jjsQ RbDV/ofmkhNoYBZ02Vld/BeSpQbtf5shxc+ZPBspK5rH+CHCpdVTLgsmDxqWhfaK3RfK 9LP6a2D1RdP1DXwefyyD14BtUxVAGghRDMVKtHXmoJkJtc3SnnW7Z6SOTaM050ogK9Jx EBkcKj49z+ej+GhS2jwLWjjPGCZMRnNKmDK+bvr9Z/vejxu8m2mTvVR3fPDjnYEVvlcE oddc7sV7hlnYheREaTFWJFpR/ftYKSiVFooWECSXtIv4dIwo/nDk2iiVMOUgiYZGR6lK KH9w== 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=q3TkFqoIuuZicTstqCVhtwPJvKlEBpEpbiUVv0iCtGk=; b=gt+7ZeDZq/0OO3rBepyzOBzR9+FXVymZA0TKdsdJIyr0UL8WfLRBLGPazil3rovG+J rq0jSFh0ntcrpXuzFXlX3Gjvqi30WIjdCtiA8jhe/DGv5gahW/SN1flISj49UVIMTz6c dc7DAbhMpyZud6AQswcpGwz72s6Z1E0BdgWP7pFj1kgr7vD/8fsaqhBH/vMNzstM33v7 xLRP+FKqFKu8jRUEsKM920HpGVxsELaAMKsyUJRlgYLuFwpvM5PH6pVKahm3sniMouTa GJd7ZoKtcwxzmsGlJO3bn3+tLDiMf5U5ox+1p3StqGcvzJ5FkWUlGEoF4dYAQss9DGUQ Dq5g== Sender: swupdate@googlegroups.com X-Gm-Message-State: APzg51B/UIdjm2rmh96Mk+UmuwbhFSRo2lsq3u7geABm7fe0j0h6oSyU cfnYVmXR7qZNfKNOELJdii8= X-Google-Smtp-Source: ANB0VdaZb3H3+clPDhCYTW1NV0Rf81uYjYpxN3gyy9R7B9j8f8sq/H09h9zBGxm1UR6/ZYZHc1/bTQ== X-Received: by 2002:adf:eb0e:: with SMTP id s14-v6mr33276wrn.3.1536234054487; Thu, 06 Sep 2018 04:40:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:adf:8265:: with SMTP id 92-v6ls1685627wrb.2.gmail; Thu, 06 Sep 2018 04:40:54 -0700 (PDT) X-Received: by 2002:adf:ad4b:: with SMTP id p69-v6mr221788wrc.31.1536234053971; Thu, 06 Sep 2018 04:40:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536234053; cv=none; d=google.com; s=arc-20160816; b=dUf4aPqSVLEmH0AOUXmfBBFQSjzZg29bODkCAJlqSYDr9j2BLCweeJL7nnKmcVjjR8 C2sKJ9ud6eyoqxSn7q079zWh8sKoOACvqZ2NNmIuKTmaoOwWs2bLZhAyTqBRDN4MW6zN bWPnBtamNY/uRT6rmZ/IhnV2ic/dtrYigpgOcYcJuPyC4Vk3yHpMMpc4QgegCKHJEQfL 7Vd0qjPaYibRhiWelIo1zufDHWzof88d//KmoX7n4Oqp/UPET9zsv4FeVpntLiHhNvI/ b93Rdz28CV6kpuGK9oJKu7dqjaighy3Sj1JK3ZVmhK84mpkaSwTh7kjRGYkt/MI279wp Q89Q== 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; bh=1Z15SHJS0mKjGhzO8gY4GkfVWOmt/m8JrMQ8CBhGF1A=; b=EZ2yUAhaqsf++sd9dFK/rK9tvdzy6iRxweIfnK7Yk+gNz2MR+JvyKkdVOKCq8L3Mtq RZiKOJzTH6rvf8Jl+9kT+TTxIEO9RT7bhYgVL9OAVGPh+HxY01TPreUoNJCwuj9cDheE ZRzcyihNo6CEgxLyhw6EoYhPfr0/yKyDK2+cZyhqxhx/ecYA0KyjjrKx/t1Fc/oDzHuP m0swDn/vPPIHGFoBnZJZBtc3dH13UAc1AbZewTE6ZcIgmBxTmss60T5YlJ/tRvlnWMO6 5iDToJHhJcS+g0k5VUrdtaEOwv9Q5OZnPLsL7wD4xO5uUlmVYRTBdSccjgjCq8G4dae8 AfDw== 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 t23-v6si433516wmh.4.2018.09.06.04.40.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 04:40:53 -0700 (PDT) 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 425dtY5Rmwz1qvnY; Thu, 6 Sep 2018 13:40:53 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 425dtY5KGKz1qrVm; Thu, 6 Sep 2018 13:40:53 +0200 (CEST) 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 Iioey5BQljFP; Thu, 6 Sep 2018 13:40:52 +0200 (CEST) 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; Thu, 6 Sep 2018 13:40:52 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 27714454035B; Thu, 6 Sep 2018 13:40:52 +0200 (CEST) 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 naDQplEOtdRj; Thu, 6 Sep 2018 13:40:49 +0200 (CEST) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 1F31B4540559; Thu, 6 Sep 2018 13:40:44 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 6/9] Factorize reading of identities from config file Date: Thu, 6 Sep 2018 13:40:38 +0200 Message-Id: <20180906114041.21828-6-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906114041.21828-1-sbabic@denx.de> References: <20180906114041.21828-1-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: , identities are read up now by the Hawkbit connector. Factorize it and put in common code to make it available to other servers. Signed-off-by: Stefano Babic --- corelib/swupdate_settings.c | 36 ++++++++++++++++++++++++++++++++++++ include/swupdate_settings.h | 4 ++++ suricatta/server_hawkbit.c | 33 ++------------------------------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/corelib/swupdate_settings.c b/corelib/swupdate_settings.c index ec726f2..f18a0e8 100644 --- a/corelib/swupdate_settings.c +++ b/corelib/swupdate_settings.c @@ -25,6 +25,7 @@ #include "swupdate.h" #include "parselib.h" #include "swupdate_settings.h" +#include "swupdate_dict.h" #include "compat.h" struct run_as { @@ -125,3 +126,38 @@ int read_settings_user_id(const char *filename, const char *module, uid_t *useri return 0; } + + +/* + * Callback to be used to put a section of configuration + * into a dictionary + */ +int settings_into_dict(void *settings, void *data) +{ + void *elem; + int count, i; + char name[80], value[80]; + struct dict *dictionary = (struct dict *) data; + + count = get_array_length(LIBCFG_PARSER, settings); + + for(i = 0; i < count; ++i) { + elem = get_elem_from_idx(LIBCFG_PARSER, settings, i); + + if (!elem) + continue; + + if(!(exist_field_string(LIBCFG_PARSER, elem, "name"))) + continue; + if(!(exist_field_string(LIBCFG_PARSER, elem, "value"))) + continue; + + GET_FIELD_STRING(LIBCFG_PARSER, elem, "name", name); + GET_FIELD_STRING(LIBCFG_PARSER, elem, "value", value); + dict_set_value(dictionary, name, value); + TRACE("Identify for configData: %s --> %s\n", + name, value); + } + + return 0; +} diff --git a/include/swupdate_settings.h b/include/swupdate_settings.h index 1c06095..7101cc5 100644 --- a/include/swupdate_settings.h +++ b/include/swupdate_settings.h @@ -11,6 +11,7 @@ #ifdef CONFIG_LIBCONFIG int read_module_settings(const char *filename, const char *module, settings_callback fcn, void *data); int read_settings_user_id(const char *filename, const char *module, uid_t *userid, gid_t *groupid); +int settings_into_dict(void *settings, void *data); #else #include static inline int read_module_settings(const char __attribute__ ((__unused__))*filename, @@ -33,6 +34,9 @@ static inline int read_settings_user_id(const char __attribute__ ((__unused__))* return 0; } + +static inline int settings_into_dict(void __attribute__ ((__unused__)) *settings, + void __attribute__ ((__unused__))*data); #endif #endif diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index ebcf7f1..31266c0 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -1556,35 +1556,6 @@ static int suricatta_settings(void *elem, void __attribute__ ((__unused__)) *da } -static int suricatta_configdata_settings(void *settings, void __attribute__ ((__unused__)) *data) -{ - void *elem; - int count, i; - char name[80], value[80]; - - count = get_array_length(LIBCFG_PARSER, settings); - - for(i = 0; i < count; ++i) { - elem = get_elem_from_idx(LIBCFG_PARSER, settings, i); - - if (!elem) - continue; - - if(!(exist_field_string(LIBCFG_PARSER, elem, "name"))) - continue; - if(!(exist_field_string(LIBCFG_PARSER, elem, "value"))) - continue; - - GET_FIELD_STRING(LIBCFG_PARSER, elem, "name", name); - GET_FIELD_STRING(LIBCFG_PARSER, elem, "value", value); - dict_set_value(&server_hawkbit.configdata, name, value); - TRACE("Identify for configData: %s --> %s\n", - name, value); - } - - return 0; -} - server_op_res_t server_start(char *fname, int argc, char *argv[]) { update_state_t update_state = STATE_NOT_AVAILABLE; @@ -1597,8 +1568,8 @@ server_op_res_t server_start(char *fname, int argc, char *argv[]) if (fname) { read_module_settings(fname, "suricatta", suricatta_settings, NULL); - read_module_settings(fname, "identify", suricatta_configdata_settings, - NULL); + read_module_settings(fname, "identify", settings_into_dict, + &server_hawkbit.configdata); } if (loglevel >= DEBUGLEVEL) {