From patchwork Wed Nov 14 16:02:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 997807 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:4864:20::438; helo=mail-wr1-x438.google.com; envelope-from=swupdate+bncbcxploxj6ikrbfeowhpqkgqesst3h4i@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="QXAMTAaj"; dkim-atps=neutral Received: from mail-wr1-x438.google.com (mail-wr1-x438.google.com [IPv6:2a00:1450:4864:20::438]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w8Qc4CGJz9s3C for ; Thu, 15 Nov 2018 03:02:31 +1100 (AEDT) Received: by mail-wr1-x438.google.com with SMTP id w16sf2985211wrk.10 for ; Wed, 14 Nov 2018 08:02:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542211349; cv=pass; d=google.com; s=arc-20160816; b=HFVaydWAktypcbUvNk5CJB2pQnWgZ5hoXndAVwHV/MM18bKVi9gQdZi3YbUfASMa1a yC4+94bSuPr5kF7FP43IKxpnGAkQg+kWyoa1fWnJPDv/zfd2tWoC8L84qupTJBD6afFj wRn80/QZHPRXmlrS/pHG5xYRjmYTGo/kYb0GZFB5arUj0C7XBOKMcj8ii5qm7G1QsmUw kkJR/V9QUV1DVzN9q1AB2l++oDhvQzd848LT4dlrLopkPy01Wy/qF1m1ot75tfNR9gf9 Tyf1NxJsXR3+xJ5XY2tlqDNyM8ilw5jn5U0Y93A6FUVdz+xa3HHqKqY4nzamrBZtzqmi 5m7g== 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=vHKls4XSrQQfAgwmRoV7iCP69dpVMvulgJnXwhPhlHU=; b=SumrkCtPAwheZdRKPfeQA6RZO9ihu6XMaVEWh0MCBVVVzqwV1YaJpB6j4g9lIcvs68 24gBbar/QwtyJ0eONwR/TY4o8ukzdJzluFICbM3OaSwR1SATG3R3uHq5jcOrM6DL/ZxR s1eNkZOHG37QJUCcmpT+3O6WMInyYGJ+6+POriCGAHH7l6UFumjwtBDjhUe7lQnrauyx dUdmt8NS205eBQkjtmjZwZhImfafTfQ4C8+juUpitxrojZWsAssboUxuZByLO/OXKVOj Jykewbcn/aEmI+jXcN2KMJuJ9C3Jn1jjD2srVl3ZF/peHi3Sv/yl+1qarVMEmR07wMqZ Kzgw== 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=vHKls4XSrQQfAgwmRoV7iCP69dpVMvulgJnXwhPhlHU=; b=QXAMTAajO5yYv8/G32BX0DnrArXA1nPZMDKYrqOX/3fOdtOWucOE8uQ4Z3UnBtH+9o qXR8v+q2woMEnjc5HrPQyt5x/8FdUb6mT+FO+9si3axgfGhE9hcnTuOh5zvVbVJXSP3E EaPwHRj0sCy1Kiu6FPFS+Tn0Q3sqbj4J5ZluPG3IpFUW/6gJju+0Udmq1/GKksfJyMZ2 bg9MW9U2rFId7+YbcK6j3K9yryz6HIf7Ias5hoRFndLwQIpXHxhm30l4yw7kNo+lXwLb aSjvgdkRGD2ur/pumybUBHcviG0qgJaO5mXR80UuhoIH3sXZKdkesdOqUXMWZ8nPvzR1 Cpug== 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=vHKls4XSrQQfAgwmRoV7iCP69dpVMvulgJnXwhPhlHU=; b=CIJzbowGX/NRbbSmDbSGG2/GFz0NKxcbSfmrayRXnNvwZLaaWCZIKV5Ijzy+h0NEgo 7XRDCKA/EPsF3tOFQkhOVzYRNoQ3B5zMtkBH7QSTm7yd6DQH1vPIjeLyQyrardXFtl3a 86KBaBWtZYIrJebcpDtNXhs2cDEnvMEA5Fsz2D0d/y33twjTSTBfDZUh1Rc69GfWEk/D O/9lgxeIQs8tetqHgslmfttZlk7Y1shwqtoOZHXpgSdvGZ1tND+pQMCx7K5/mrhHfwhY vxXaN6A+znDmIeR8IYW+Vue00FgW6atVSnxTgnQ6WfGeriEPcDCtWKwAbJVYJ1T80/qM OGXA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gJarvybu9G2TWHRvbiIa4K4j0YOhbXf7vOaTp98Pfwixt52Q/BP wwITNEO/G5wb8PC/9FN3B9k= X-Google-Smtp-Source: AJdET5ct45qYk+U2hIe/Jxr+yHDveJjFsNVZT8pEbaTAwjEyCuuKlT0bkhjqE4iZtK3ZmK3IF3l6iw== X-Received: by 2002:a1c:5d8c:: with SMTP id r134-v6mr14001wmb.3.1542211348979; Wed, 14 Nov 2018 08:02:28 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:5d43:: with SMTP id r64-v6ls76434wmb.26.gmail; Wed, 14 Nov 2018 08:02:28 -0800 (PST) X-Received: by 2002:a1c:85c7:: with SMTP id h190mr357044wmd.13.1542211348458; Wed, 14 Nov 2018 08:02:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542211348; cv=none; d=google.com; s=arc-20160816; b=blbniRQIUChHWN5sZS3Z45U6Aw8VTu2OkmwkSyZ4FqAEabK6cFePJj9JbQpOmt8dIv mGfZHMJ0r82nj5B6zQAAcAIDLqi0qT1eQIvzUiZoRVXbUeiJ/WPTCh59NVBEutZoh31R Xy9SOByUdfTG5oUmIkxHq6qER1SgoYb/4ct1XzHaQyXSyypBJUcYHndhm2F53BjTpib8 ukmpuVbFPfW1iQlPMxHNpooUMvEpYHVPlEuLagRjvUChqgoPABMOOaM+M/QVu8RvocgY TnhCsmskuJNeDJHGZgk9oNBhRf0GEhdCdlrzKOuLMcR5rb5sfyBgwN49+Ejkpu5FXIkc MSow== 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=AsIn1uIrykUWWQxyjhp3dLOiKdz+wYPn5OGcALSBHeI=; b=lnq9kRgA6DXzi65l9mfmtcqMrG88yWjrlXhNKzgv0D/D/40juoFlPD0LY+/F24mZAW liQCrMlOHXKdZJ3/aJi6Mr+lWBP8SaMvX+fpOaS55/JcBvoScdHLM9SHUszWdT3J3rq9 ccCG3aYcf2wQvuCBOuOu2KqD1WRCw31+dgdWz9HqKI+YfYM2qtMcfrY+F4g+9LgQnF5p PrNUrDe2Ccwx0idDSNDOvdNXxQ61ZXvbTDJk6sAy6yEbVa1X2Vorb9/bc547A8OKr4nA pfNOb5FTdMqv6gJG15lOaEF/WZx9yC0xOIVHTxEqV3rGAGHEJEj3YtyAtM+X6OcmyUMD fd0A== 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 p15si249640wrm.5.2018.11.14.08.02.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 08:02:28 -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 42w8QX1rp1z1r01b; Wed, 14 Nov 2018 17:02:28 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42w8QX1fphz1qsJM; Wed, 14 Nov 2018 17:02:28 +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 ZFdB5B_TQ_30; Wed, 14 Nov 2018 17:02: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; Wed, 14 Nov 2018 17:02:27 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 2B0F74540038; Wed, 14 Nov 2018 17:02: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 FbhZRTozwNlU; Wed, 14 Nov 2018 17:02:23 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id A42214540471; Wed, 14 Nov 2018 17:02:23 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH v2 1/5] Factorize function to count elements in array of strings Date: Wed, 14 Nov 2018 17:02:17 +0100 Message-Id: <20181114160221.18242-2-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114160221.18242-1-sbabic@denx.de> References: <20181114160221.18242-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.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 --- Changes in v2: - Use "ref" attribute to set a link - Use separators to identify part of link - Explicitely set links instead of implicitely set via strings. - Allow to link any attribute in sw-description not just the root node. - Several cleanup - Note: this is quite a complete new version, most code from V1 was rewritten core/util.c | 16 ++++++++++++++++ include/util.h | 1 + 2 files changed, 17 insertions(+) diff --git a/core/util.c b/core/util.c index 15d38b7..a357ea3 100644 --- a/core/util.c +++ b/core/util.c @@ -481,6 +481,22 @@ char** string_split(const char* in, const char d) return result; } +/* + * Count number of elements in an array of strings + * Last item must have a NULL terminator + */ +unsigned int count_string_array(const char **nodes) +{ + const char **iter = nodes; + int count = 0; + + while (*iter != NULL) { + iter++; + count++; + } + return count; +} + unsigned long long ustrtoull(const char *cp, unsigned int base) { errno = 0; diff --git a/include/util.h b/include/util.h index 06f4a83..0a95967 100644 --- a/include/util.h +++ b/include/util.h @@ -179,6 +179,7 @@ void get_sw_versions(char *cfgfname, struct swupdate_cfg *sw); __u64 version_to_number(const char *version_string); int check_hw_compatibility(struct swupdate_cfg *cfg); int count_elem_list(struct imglist *list); +unsigned int count_string_array(const char **nodes); /* Decryption key functions */ int load_decryption_key(char *fname); From patchwork Wed Nov 14 16:02:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 997810 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:4864:20::43f; helo=mail-wr1-x43f.google.com; envelope-from=swupdate+bncbcxploxj6ikrbheowhpqkgqe7ua4u5q@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="jnvb9sU5"; dkim-atps=neutral Received: from mail-wr1-x43f.google.com (mail-wr1-x43f.google.com [IPv6:2a00:1450:4864:20::43f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w8Ql3NZKz9sB7 for ; Thu, 15 Nov 2018 03:02:39 +1100 (AEDT) Received: by mail-wr1-x43f.google.com with SMTP id v2-v6sf17520587wrn.0 for ; Wed, 14 Nov 2018 08:02:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542211357; cv=pass; d=google.com; s=arc-20160816; b=oKXSG3SX1iwdJOvWeMFZowODs4aM15iacLh5eLo9XGpr7yzwIsPtQ49Qz2pn9zrwZw gHfwy4/fjKyDLbrkizERTNZU2UTNmpFkRAkXKjjZJH4ElCxmFbWHpo5x5cY5N8o73u+c JBaJIZAtzZnPTS37On2XR2Eo102TUomBTd5cHb4YmVgnrJQdkx24MuZZ0mDg1TPh7tn5 GcftxhpiAVfTbehmqbr+IcgFrz17NKsUmVkqtSQzn7DGlH/Zx+TOj8HnoXEQo+0ph0hE qXeBHRQetSCscp4DzfKhIFNP2Va1ZaG3m3mUs9hszm08gtCZxCmDYDpgxZk1yKrJ3CbG TDoQ== 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=E6Qy71KVzIE+sqkrWorA99t/UIr0WbjVuBtYhcmfxyU=; b=c/a3BdSwSuv4kwB0r1j9GLSKWYXsf5Mi0iaJb7vA8cgThmiHQpuFES5sHP3n/aqFCr nPYnv5MNPCC+i/j9M/byxf+4Acf9tv6inzA/UZTpXZpegZx/5qhJm6HuV9u3lwN5yMxI Dy6M3Htihtv9t8zxqgKc/xCRItWheAOHoLK+2eVxo/Z6SFsctpH+7uVmNvzOxGbS8T+v S1uRbDrsXXSC872HMj65gRsxhuyAxSwAf1ab8RijkTGVznlE46TCr/bPU8wHioOmRPuR S2g//5qE0oNsF1pUB1ka0Kq8Uxcw9GVETTsBq7j57K3vV1xQGrWnDVAYg/BGHlCKch+e xrWw== 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=E6Qy71KVzIE+sqkrWorA99t/UIr0WbjVuBtYhcmfxyU=; b=jnvb9sU5mZR4Dyc6QIW4RpIxq+eVk7nt7NHyWh8yOH9JAESnFizuCWJLngMF0q6bw0 z9O/RTj9cTbRiuVqE40vkkd8Dj4M2nnbQpvIhKEm5V7Ty2Y4DBpUsoLW1gXSa2MuUK26 AtDDpbOiXoojkqao/L4RvP8FxHBBU3N5m808g7MFwdI9mQAp+rUAapW66U4yIR1dnrZ3 9OBYd+6T8X9yXMBT2IcBvEIcUZBrxda0di3os2v0NmHTtEucM0SumNxfr3s2ciTXcJCE K8CTBbapvtVP1/PSWktXjhxMQPzScF7OUOmE7xmQdFTFYbYxbDDPAeVH3PJlxgCbPTZo m6gQ== 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=E6Qy71KVzIE+sqkrWorA99t/UIr0WbjVuBtYhcmfxyU=; b=trlMaiM4T/88Vvkq1uiXdRWVwkmYTo0ixGK9XpT3aSpgKXsO1pn+vp7YOFhWhr0osE jAgUmeb+JoqDQCHXkg3mL4YgZg7HPFQiPAbEr+NgoMNWRqrBnCcyJ710rSpdsm0Cn+f+ j/2nLknwOKJvbwu9Hj9h1pRGKWqYeHFb8TKln3gs23vzv0338f3t5iV4SzGgJygwCvV3 faKrOF5PCdwiVoLIleYusQKuQjft5VYT+/QEJJUdu77/7trZCkIqwQsbnhkTBxB9YFui LLRxbGE6ts4BiMisxgBT+zejLQnLkJxF3rzxURMDz8C+FvvL8sH9QsS0w5b+Ew29DLB3 qL6Q== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gIJbXDng+u9j0VRWcdLL8Uew3kUMPPGJenMtVbtvfM5urpTBzkl PVFm8V84Egxv9r7j7vTpgZs= X-Google-Smtp-Source: AJdET5cUf1x3sA2d9yngyZTggkgwJHKiFCG6NCK/3K8xo7WHlXHBmnbq+pDkc2u94dU3rPC66+oFpw== X-Received: by 2002:adf:e60d:: with SMTP id p13mr34967wrm.6.1542211357005; Wed, 14 Nov 2018 08:02:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:44d6:: with SMTP id r205ls252340wma.24.canary-gmail; Wed, 14 Nov 2018 08:02:36 -0800 (PST) X-Received: by 2002:a1c:b482:: with SMTP id d124-v6mr479640wmf.16.1542211356463; Wed, 14 Nov 2018 08:02:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542211356; cv=none; d=google.com; s=arc-20160816; b=K0OfrEI0fmSq4C7XGQD/XxzZ+zX/if7121SUidLGloYa/OjLBR2V+vHVkTG//1WKj1 CQPWymQi4LqbtBEn2OUy1KrL2WU18AgVOcIQA3f1k4WrW28/7l55iI1Q/f5v3rKmxged ywhudmbdDArUWJwMcEtqO/XFDETsRH2iuEtN4LLiOyVzTG2/oLkQJHt/5+2zZrrYZ+c7 JQsNyCbZXkxLBVnkoi4ndkWauOjBQhi+YuGa7b1B7UaE1+AWHvNXLNl9BLUwUUv5QacE 0gcUpZtbheNP3oo8Eb1YUAKSoeLn+C4HsxyH6qIJHoK6/F1GcYx4fXKXIFJXA30PpvDu 7zaw== 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=NKOq6u6JqqIcxwsVBR4uufPHHIv/xsOxrdAT6AdPomI=; b=ryE2b1bp6/Ce2uWPOTuMizA1Q57FL68UxVI4wi6syLfAIw+oQSoOEj7FiFQOFGfyiP ixMnCRTEZth7OL+Ma1GiIfA/E7xnSJGFVE1ORkc1EWXCbiaZHyrhCh/nMTizEjczK1mO 7aSNWmVhMKvPS5O1DP6SVPCTbfpUEk7M2GNlnA0V4L4V+6uJ8997uZ2brRLWKF+xcoED +5F+mer+WMFw4OKHqjsJFLe3xog9oiEqwubD2K4h4BJ3iqrUpEjGYf2ZLz9SRdprGcMe e88rcitNSbIthBbcONEC8BprMBqlKyMw+3j2JNK3li1Kdm+tFxy5ZVXLulkMT7+mVTDA i7zA== 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 l4-v6si676230wrb.4.2018.11.14.08.02.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 08:02:36 -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 42w8Qh1y3Jz1r2tM; Wed, 14 Nov 2018 17:02:36 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42w8Qh1hB5z1qqkW; Wed, 14 Nov 2018 17:02:36 +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 HMxzYT8NNIbA; Wed, 14 Nov 2018 17:02: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; Wed, 14 Nov 2018 17:02:32 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 3BCDB4540038; Wed, 14 Nov 2018 17:02: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 nGaNZ0mYbCSX; Wed, 14 Nov 2018 17:02:26 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id BBA654540474; Wed, 14 Nov 2018 17:02:23 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH v2 2/5] util: function to free an array of strings Date: Wed, 14 Nov 2018 17:02:18 +0100 Message-Id: <20181114160221.18242-3-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114160221.18242-1-sbabic@denx.de> References: <20181114160221.18242-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: , Signed-off-by: Stefano Babic --- Changes in v2: None core/util.c | 10 ++++++++++ include/util.h | 1 + 2 files changed, 11 insertions(+) diff --git a/core/util.c b/core/util.c index a357ea3..3ad0fd0 100644 --- a/core/util.c +++ b/core/util.c @@ -497,6 +497,16 @@ unsigned int count_string_array(const char **nodes) return count; } +void free_string_array(char **nodes) +{ + char **iter; + if (!nodes) + return; + for (iter = nodes; *iter != NULL; iter++) + free(*iter); + free(nodes); +} + unsigned long long ustrtoull(const char *cp, unsigned int base) { errno = 0; diff --git a/include/util.h b/include/util.h index 0a95967..faf8aec 100644 --- a/include/util.h +++ b/include/util.h @@ -180,6 +180,7 @@ __u64 version_to_number(const char *version_string); int check_hw_compatibility(struct swupdate_cfg *cfg); int count_elem_list(struct imglist *list); unsigned int count_string_array(const char **nodes); +void free_string_array(char **nodes); /* Decryption key functions */ int load_decryption_key(char *fname); From patchwork Wed Nov 14 16:02:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 997809 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:4864:20::339; helo=mail-wm1-x339.google.com; envelope-from=swupdate+bncbcxploxj6ikrbgeowhpqkgqe7xruavq@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="EOhVXasl"; dkim-atps=neutral Received: from mail-wm1-x339.google.com (mail-wm1-x339.google.com [IPv6:2a00:1450:4864:20::339]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w8Qg36kQz9sB7 for ; Thu, 15 Nov 2018 03:02:35 +1100 (AEDT) Received: by mail-wm1-x339.google.com with SMTP id y185-v6sf14827767wmg.6 for ; Wed, 14 Nov 2018 08:02:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542211353; cv=pass; d=google.com; s=arc-20160816; b=VxQdjJxtMf45SowT/JsU1RtNiWpExxxAcJvwmJs5CCQ/B3vxVrEp+dzDLunRBld2Vy DM+BU05x0e6YimYZQtPNu0brl/Reek5d3NNxAUkdC6NKbnFliBv9fG/P0ZwLXF63lwqH 0UY3Vrq86rAiNm9o0Tc5JLLLgUVuPaDK33xCTW2mYz//Szq44ikT5BGbLSSd09bCpxH1 890YxcobZkJI0gDcwLvjIRAMiILwhaOMDED6FJPlcyJaOKl78ys2sg41CmluBSh6Mm4H Ija43p8UHCa2RHlLgJBlJ7n18KAAOyv7rgVg6rdVR4QaBuvP/PRhwsxLHgiRA5Egl2na T8yA== 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=fJ812BK3ti0fp5haDy8VS83K5nCXbc6N0oudGJbKPTo=; b=uzqDkibDs3+IOyXZOLyFzXtTMHS2/9SYiXmdwjeMyLOZZr3z185Lax+DbIZyOMmkVu Nfl5Y9QKR8OHW7IUIokb1ureN9Kfp0HsMP27ZhVoW2HVlHKVi0AxD4NlqTjjDKu9qtNa IIm4pKqQ8iovB/YSqFUHSxcSX0d9mQQFuJhJ09wyq72FEKprYkdeVhxhljQkHy1VbpgV 7O+k4cuWce7J2wepCXFXr5HC/SrQ7EjbxP6nHJ/7sSbJZQBldA1SvVZwgzt8iNqRHduI Jazy+K4KaHrMr1KFqAHeNP5JcdAHos4s2vIp4QSBWKJWd1iMwQgF1jKeDpDtoJ2gsytv iCDQ== 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=fJ812BK3ti0fp5haDy8VS83K5nCXbc6N0oudGJbKPTo=; b=EOhVXaslSWLVhMjDXUBjoX4JQZhiKHNWBGUu4ZdqrVEXbcqiHIYeJDMUWLJPXnz5Zc KXNwT6Sj6tOG+EWb2Woqbxb61G6POFQFw2CJSJIXIDwmrf31c4tQfcSEj9+wXJe83OdA Gi1tQ+/WiVVGM+xB8i8Ktif3i35qsJXo357Ks5w72VFn++ABK8eXOcb0aqgaPq8jpYNk g1BgsoK7CwP9DTBgkbE7/PXi7OUMxqjDaJ7DMD6mY2Ex9NZfTARvqcsFgiWEgi8auID5 3FVp2V36owAQ/ohU3jQj7idSW5zU9p1RndrQyCgE6zbz5WhUml0EawpF6sp9JTwAkzzb 4YCw== 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=fJ812BK3ti0fp5haDy8VS83K5nCXbc6N0oudGJbKPTo=; b=FHSbljYjDnn+BLKWdnbXwQBrfvFuafjzHjXGX+I5fEez28L3oR88842Mox6JPJJw4w lM/YAhvWAZmXd1zjqWM80cASR559KWXe5Cb4HeB6EII+/y4uFHgxxRRFxgBiJIxLESe9 m1Ue9/ciPCjCfrRR2dIFOicEU45Sd1JgrASFu1N8mlFP0xHL8fHj0nNDLvBGpQxG5NVk FWss8xhfNBVJqStDtWznY8khXowdhLb4frybEM8sSeQ4n6Oaflanqd23k85ff405BTVD ZwdoTyOoyW+mCFlfGeYtNd5hDis8jvfEK7dlGj4hNTw7dKJJvM6ceNZO+HYodHKsWpTD Gotg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gILXUlWoNyaVeq54pOu3b5jA9a4s3N5/vta/odsvafkKor2WBDd l0IofNQaXmcrNaf1bND5Ga4= X-Google-Smtp-Source: AJdET5c3B4hQy9WQ4mONvYrkIcigZLluIediE8RAVenKl2fBPBM07SayW4kTm7xSSlG2U809vw1cUg== X-Received: by 2002:a1c:178b:: with SMTP id 133mr17060wmx.3.1542211352958; Wed, 14 Nov 2018 08:02:32 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:a05:: with SMTP id 5-v6ls2898925wmk.17.canary-gmail; Wed, 14 Nov 2018 08:02:32 -0800 (PST) X-Received: by 2002:a1c:1887:: with SMTP id 129-v6mr475188wmy.3.1542211352361; Wed, 14 Nov 2018 08:02:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542211352; cv=none; d=google.com; s=arc-20160816; b=GmQy2ypxU7d+YGSFIFg+tdcBtn4qK6cIe3Reu6zQJmbODZgUwtUQOqwmV397GJab+a wl38ZxXLjiFjkm9DOoWcXJP9IEzo4BYKxhqFfwNaoTLe9hAP0QstU/SrVPYZ6EpbQs/6 mRRd2FVuUV5ENvfJZUVJ145iOAnSLGPYJt3ezp+BjbweWmbywpboJQH/McwDiNQtaPeg vZXume/6/lGrzQ+qCQ0KPPA/QM2Ywch8b2RJWC4Jo3UjobfOMxHdd9CldDBIuTiAVmYd vW9DqKxeTMGrjhK9vVBKOFy2jbMKJHv4wxgMLcnlLPbAHP1Qr0AortqOknTFkAEzgzdh v/mA== 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=C3S7dA9mUYlBD8Rbvf0MHgY2rnHUT6b2eyDkI5exjrg=; b=tsRsILM5EdNNNeRhP293NhhX93H4cWZNpalTchgMnDhkYgWOvjN6JZ6T6uDn5DHHa4 oiOCzAOgct3T5Wgoo+d2+ggHJi7IRodVwmFHrvyUZPdBvFW+SbGTqsXfRSU3LgAMNZ/h CT3oCEd/zVfUbWEfpEXsqZJNTz7bo+lD9A75mcc0T0B7FGfEXdipfScdNExq6ZhJrjzW +AwpwuWoAmicz/nSU+u5Ym21fhaFhASwgawTGhWDR8EO6KjQYe1pphu8dRt7YT1sA5B8 MXb5s11D+C5gaNwt2u8s9DoQy4RNuPi3zsd98/ycirmKnxRS1KrsqQGSY6Z4rUqOaBrF K8cg== 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 c76-v6si304281wmc.0.2018.11.14.08.02.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 08:02:32 -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 42w8Qc12HZz1r2tM; Wed, 14 Nov 2018 17:02:32 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42w8Qc0nGfz1qqkW; Wed, 14 Nov 2018 17:02:32 +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 rFPTsuJze3hW; Wed, 14 Nov 2018 17:02:31 +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; Wed, 14 Nov 2018 17:02:31 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id DF2A84540038; Wed, 14 Nov 2018 17:02:30 +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 6AGE5yZba_UJ; Wed, 14 Nov 2018 17:02:27 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id D5B4B45404E3; Wed, 14 Nov 2018 17:02:23 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH v2 3/5] parser: function to get a new path of a node Date: Wed, 14 Nov 2018 17:02:19 +0100 Message-Id: <20181114160221.18242-4-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114160221.18242-1-sbabic@denx.de> References: <20181114160221.18242-1-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: , Using links, the path to a node must be computed again. The function set_find_path() get the string pointed to the link and modify the array of strings containing the whole path to a node. A convention is used to traverse the tree upwards. If the string begins with "..", this means to go up in the tree. Multiple leading ".." are allowed to go up into the tree. Signed-off-by: Stefano Babic --- Changes in v2: None corelib/parsing_library.c | 56 +++++++++++++++++++++++++++++++++++++++ include/parselib.h | 10 +++++++ 2 files changed, 66 insertions(+) diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index e9739fe..00463a7 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "generated/autoconf.h" #include "bsdqueue.h" @@ -19,6 +20,8 @@ #include "swupdate.h" #include "parselib.h" +#define MAX_LINKS_DEPTH 10 + void check_field_string(const char *src, char *dst, const size_t max_len) { assert(max_len>0); @@ -159,3 +162,56 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) ascii_to_hash(hash, hash_ascii); } + +bool set_find_path(const char **nodes, const char *newpath, char **tmp) +{ + unsigned int nleading; + char **iter, **paths; + unsigned int count = count_string_array(nodes); + unsigned int countpaths; + + if (!newpath) + return false; + + /* + * Check if we have to traverse back + */ + for (nleading = 0; newpath[nleading] == '.'; nleading++); + + /* + * delimiter at the beginning indicates a relative path + * exactly as in Unix, that mean .. for the upper directory + * .. = parent + * .... = parent of parent + * The number of leading "." must be even, else + * it is a malformed path + */ + if (nleading % 2) + return false; + + nleading /= 2; + if ((count - nleading) <= 0) + return false; + + count -= nleading; + if (count > 0) count--; + + paths = string_split(newpath, '.'); + + /* + * check if there is enough space in nodes + */ + countpaths = count_string_array((const char **)paths); + if (count + countpaths >= MAX_PARSED_NODES) + return false; + if (!countpaths) + nodes[count++] = newpath; + else + for (iter = paths; *iter != NULL; iter++, count++) + nodes[count] = *iter; + nodes[count] = NULL; + + tmp = paths; + + return true; +} diff --git a/include/parselib.h b/include/parselib.h index f53dd00..2fca3b5 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -9,6 +9,7 @@ #define _PARSE_LIBRARY_H #include +#include typedef enum { LIBCFG_PARSER, @@ -18,6 +19,12 @@ typedef enum { typedef void (*iterate_callback)(const char *name, const char *value, void *data); +/* + * This is to limit the structure (array) used to save the whole + * path to the entry to be read. + */ +#define MAX_PARSED_NODES 20 + #ifdef CONFIG_LIBCONFIG #include #define LIBCONFIG_VERSION ((LIBCONFIG_VER_MAJOR << 16) | \ @@ -83,6 +90,9 @@ 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); void check_field_string(const char *src, char *dst, const size_t max_len); +bool find_root(parsertype p, void *root, const char **nodes); +void *get_node(parsertype p, void *root, const char **nodes); +bool set_find_path(const char **nodes, const char *newpath, char **tmp); #define GET_FIELD_STRING(p, e, name, d) \ get_field_string_with_size(p, e, name, d, sizeof(d)) From patchwork Wed Nov 14 16:02:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 997813 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:4864:20::23e; helo=mail-lj1-x23e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbiuowhpqkgqehn3vykq@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="nRkbHMbm"; dkim-atps=neutral Received: from mail-lj1-x23e.google.com (mail-lj1-x23e.google.com [IPv6:2a00:1450:4864:20::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w8Qt1rD2z9sB7 for ; Thu, 15 Nov 2018 03:02:46 +1100 (AEDT) Received: by mail-lj1-x23e.google.com with SMTP id e8-v6sf5965865ljg.22 for ; Wed, 14 Nov 2018 08:02:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542211363; cv=pass; d=google.com; s=arc-20160816; b=TGgiMI6sg8XXakWLr57rAQwnEcym7WArU7Uv3DxA2meE3mX6WGvJE0G0TwcvApz5qV PirMXTRkm8mA+EDEKO9f2qAlluq4A7ijJBh1tlD325OPRWGQvEEGCCqkAyaLrzq395bD 5Ed7g2kvaCGWsbOmclKEJkoeNyHDiXaLXbdJMPaTQuH6/ShNscEznlPljLl28sTRcyIX ATyOCEr2q8va/Qy3L6og64KZoyyuECDO90Tj/i4tV4VZ1xm4eQtSQ7Ch4m30ntpGZyhu JDUiA6o/uHcoQdPsc1+lk+PMTgcizkZBgj7IyvosFHQO6JSnDzKPACd6kcBE/szZ5bPL OWhg== 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=H9dKpJnsbUYHym93tjNc0rG+mlk2+d5CnZNZYuc2Sx0=; b=WIzhnYpOZg+ttOTBPV2dP1m4eLuCV8J79pnHqstiNbDoKYfAEoY+vuqV36WNlOKtfG 4JemiFlCdiBqMPd2WEg7WfyEts/GZz/0eOqxeBtBN3+pHHkbjt4GuDZPfHZCi+KBLYA7 eUdSEv++kcMv1/+34KcY3329LY7xKrEYlU/wGEfBpVVG3nWl2XPsdX2/EMpNLPrSPVtk jU+yrKNqc9T1oDZOkDouieOJbmVcJ738cwGnf7DSUmq+s4tI267YqDTFy875dAzH9Z4P 364F/TdHPu0ZccclwWIlgzkQunb2joMYJlp7K8msveza5UXc++qgG9xmUhLUt1xKN0N4 9yjg== 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=H9dKpJnsbUYHym93tjNc0rG+mlk2+d5CnZNZYuc2Sx0=; b=nRkbHMbm9ZGRQdRvbGMjWQtCIg90Ke2wH4wbvjczGUBux3CsGLF2lQ3n6ft80tfy2t DNdqeP10GjGJBED9f2EdltFt4+lRMQG4uoEF0F6EuMMXu85d8ePGXIbyj61LCTPCNUAI zmtI6/T6uVLNp6xOh7q8IFyyMNbV0CDisfb2aYoVJb/TPd/WGL0RfewCK7WlJ1e3Twzw 6OR0QdAKgY/clSvv2xgj2M2OH6Ee443ZNVfQ6tw9ADSuX3+Q/uJd237wsKzBv2Mx/EA+ tbwS2/m9c4u6IeiScrs5MayFRm+bs2OX31W9j2jEQdc//E2rGLI04iR6gn4gKtaUuIoU E4SQ== 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=H9dKpJnsbUYHym93tjNc0rG+mlk2+d5CnZNZYuc2Sx0=; b=QmcaZhoIIjk/N9rAodeqJTATsTVWpvTu6nyQ4OM9nPydVb8xXICOPOeD1SDsfpZqIW JGr5hK6cQ5S/8LkdLk8c3NChRf9WXvP5FzCeJKFz3aUaD7a2dsDfiO+5xeF+sxSSbJqE 9V6M9JVK5+JrDSos/1XRzvcFfm43biSItxQ8CCpUS45Ir5c9qSaYtoEOBUbcvAL3fAae IjtoOslqlCtfpZdtDy1UTdunS23BIHwUyiEAvlwj0Ik0LZyDvPwH4yK6ukZrZ0ZMyo3j sKoeO1E5IAvtfSgYSOfjlWKxyb+hYx3HYynHh7Jfvsy7HFIO6YIhZ++kRBXfA37Bk9w5 oAFQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gK2JskaMyrvwurcXRGMwtJoW/AwfzQsK6zLgdDSu1YPUz2e0kyF jDXBtsj/OcZccBZUqab97M0= X-Google-Smtp-Source: AJdET5eb1CmqrDZpXQeD2ZSHCtukIN2o5FlTt0fM1uJSTyr0XJG6QxYANS+2xlPDTAMewxQZxXwnvQ== X-Received: by 2002:a19:d819:: with SMTP id p25mr13980lfg.6.1542211362902; Wed, 14 Nov 2018 08:02:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:9d05:: with SMTP id t5-v6ls1341955lji.23.gmail; Wed, 14 Nov 2018 08:02:42 -0800 (PST) X-Received: by 2002:a2e:42ce:: with SMTP id h75-v6mr268178ljf.27.1542211362229; Wed, 14 Nov 2018 08:02:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542211362; cv=none; d=google.com; s=arc-20160816; b=sG1CIOB5Iq3cn04A3ctcSaKy7W/tbgCXpYmunDimvfCf3ejCqZxFxZTlKM+p/OtfhM WJFT/LnLpAKOhfY1BsAIzyaOOmLmBsiGBF2WDyoNq+CC8PaY/alLpbEcUQ4LYrc4bNEz NIt/gpP2/e55v3jFdAwuZZ6f6ntwbwHjCAykrl6Pc0BLxc2r6K8WRsXILCVTG9dG7b2I LJa5bvBoi1i2XUAOzdwCA1eHcEhADwQFcSJUSSdKPESjCSrYhCsZ0roWWmRLD7B9hiTv ZVfo3xqz8135xcvsmsXo3oywn54Sd+039RQyIYHCncLm5PBJoIvxY2hzWFPid4VKjSOT Xm5Q== 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=IvAMmCW2EnzjteE8wKbLahYU9rJAZlttqPPr16FkjgA=; b=uWXQWrpnMdw9nG+87WHM7la6YWJkcvvXAsN5zVuIpEpjwPmD1clRh96N5iZnSBM3mq 7ySvDIyAHkVM4adFT7Q1iB8ZqC61yoXFBn5P6q6Tr57ppWsrxhxMNz+I822cRg5rVyhB sV8SqjqKeT5NOi30bMdWUQU4tf9+OtbcC6G2M8FSRFKvPjIEEuxjrwDTewHTKu9nd3vQ zA/eAqblDs6HJ7ivvoclrdduIKXKJqmxV7RPpJkUR0sjIJ/HN2y6JKbGROZO4GjYUWwt 2ky4xG6WtZFRUi67uO3rRQZSslbnXaaRqWqDDb7ZFm92XTxjBG3DihbBidd5E/1obcyu vpxw== 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 t5-v6si913999lje.3.2018.11.14.08.02.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 08:02:42 -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 42w8Qn4P8Hz1r01W; Wed, 14 Nov 2018 17:02:41 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42w8Qn4Cpzz1qsJK; Wed, 14 Nov 2018 17:02: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 k1-GzhlCE37a; Wed, 14 Nov 2018 17:02:35 +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; Wed, 14 Nov 2018 17:02:35 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id A79B94540471; Wed, 14 Nov 2018 17:02:34 +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 uR6N5abS1S8M; Wed, 14 Nov 2018 17:02:30 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 23399454065E; Wed, 14 Nov 2018 17:02:24 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH v2 4/5] parser: introduce links in sw-description Date: Wed, 14 Nov 2018 17:02:20 +0100 Message-Id: <20181114160221.18242-5-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114160221.18242-1-sbabic@denx.de> References: <20181114160221.18242-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.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: , There are a lot of use cases when special configurations are needed. Current sw-description requires that each entry is full described and does not allow to factorize some parts. This means that in most cases entries are duplicated multiple times even if changes are minimal between sections. This patch introduce links for the root node. If the node is a string instead of an object, it is interpreted as new link to be follow. The parser tries to follow the links recursively (a maximum number of 10 links is introduce to avoid deadlocks). The patch factorizes how to call find_node() for the specific parser. Instead of using two mechanism (a formatted sting and an array of strings) for libconfig and json, use an array of strings for both. Signed-off-by: Stefano Babic --- Changes in v2: None corelib/parsing_library.c | 137 ++++++++++++----- corelib/parsing_library_libconfig.c | 71 +++++++++ corelib/parsing_library_libjson.c | 37 +++++ include/parselib.h | 10 +- parser/parser.c | 219 +++++++++++++--------------- 5 files changed, 320 insertions(+), 154 deletions(-) diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index 00463a7..fd451ac 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -153,6 +153,39 @@ int exist_field_string(parsertype p, void *e, const char *path) return 0; } +void *find_root(parsertype p, void *root, const char **nodes) +{ + + switch (p) { + case LIBCFG_PARSER: + return find_root_libconfig((config_t *)root, nodes, MAX_LINKS_DEPTH); + + case JSON_PARSER: + return find_root_json((json_object *)root, nodes, MAX_LINKS_DEPTH); + default: + (void)root; + (void)nodes; + } + + return NULL; +} + +void *get_node(parsertype p, void *root, const char **nodes) +{ + + switch (p) { + case LIBCFG_PARSER: + return get_node_libconfig((config_t *)root, nodes); + case JSON_PARSER: + return get_node_json((json_object *)root, nodes); + default: + (void)root; + (void)nodes; + } + + return NULL; +} + void get_hash_value(parsertype p, void *elem, unsigned char *hash) { char hash_ascii[80]; @@ -165,52 +198,86 @@ void get_hash_value(parsertype p, void *elem, unsigned char *hash) bool set_find_path(const char **nodes, const char *newpath, char **tmp) { - unsigned int nleading; - char **iter, **paths; - unsigned int count = count_string_array(nodes); - unsigned int countpaths; - - if (!newpath) - return false; + char **paths; + unsigned int count; + char *saveptr; + char *token, *ref; + bool first = true; + int allocstr = 0; /* - * Check if we have to traverse back + * Include of files is not supported, + * each reference should start with '#' */ - for (nleading = 0; newpath[nleading] == '.'; nleading++); - - /* - * delimiter at the beginning indicates a relative path - * exactly as in Unix, that mean .. for the upper directory - * .. = parent - * .... = parent of parent - * The number of leading "." must be even, else - * it is a malformed path - */ - if (nleading % 2) + if (!newpath || (newpath[0] != '#') || (strlen(newpath) < 3)) return false; - nleading /= 2; - if ((count - nleading) <= 0) + ref = strdup(newpath); + if (!ref) { + ERROR("No memory: failed for %lu bytes", + strlen(newpath) + 1); return false; - - count -= nleading; - if (count > 0) count--; - - paths = string_split(newpath, '.'); + } /* - * check if there is enough space in nodes + * First find how many strings should be stored + * Each token is stored temporarily on the heap */ - countpaths = count_string_array((const char **)paths); - if (count + countpaths >= MAX_PARSED_NODES) + count = 0; + token = strtok_r(&ref[1], "/", &saveptr); + while (token) { + count++; + token = strtok_r(NULL, "/", &saveptr); + } + free(ref); /* string was changed, clean and copy again */ + + if (!count) + return false; + + paths = calloc(count + 1, sizeof(char*) * count); + if (!paths) { + ERROR("No memory: calloc failed for %lu bytes", + sizeof(char*) * count); + return false; + } + count = count_string_array(nodes); + ref = strdup(newpath); + if (!ref) { + ERROR("No memory: failed for %lu bytes", + strlen(newpath) + 1); + free(paths); return false; - if (!countpaths) - nodes[count++] = newpath; - else - for (iter = paths; *iter != NULL; iter++, count++) - nodes[count] = *iter; - nodes[count] = NULL; + } + + token = strtok_r(&ref[1], "/", &saveptr); + while (token) { + if (!strcmp(token, "..")) { + if (!count) { + free(ref); + free_string_array(paths); + return false; + } + count--; + } else if (strcmp(token, ".")) { + if (first) { + count = 0; + } + paths[allocstr] = strdup(token); + nodes[count++] = paths[allocstr++]; + paths[allocstr] = NULL; + nodes[count] = NULL; + if (count >= MAX_PARSED_NODES) { + ERROR("Big depth in link, giving up..."); + free_string_array(paths); + free(ref); + return false; + } + } + token = strtok_r(NULL, "/", &saveptr); + first = false; + } + free(ref); tmp = paths; return true; diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c index 415116b..d3fc3c2 100644 --- a/corelib/parsing_library_libconfig.c +++ b/corelib/parsing_library_libconfig.c @@ -13,12 +13,34 @@ #include #include #include +#include #include "generated/autoconf.h" #include "bsdqueue.h" #include "util.h" #include "swupdate.h" #include "parselib.h" +static void path_libconfig(const char **nodes, char *root, unsigned int rootsize) +{ + const char **node; + int nbytes, left; + char *buf; + const char *concat; + bool first=true; + + root[0] = '\0'; + + for (node = nodes, buf = root, left = rootsize; *node != NULL; node++) { + concat = first ? "" : "."; + nbytes = snprintf(buf, left, "%s%s", concat, *node); + buf += nbytes; + left -= nbytes; + first = false; + if (left ==0) + break; + } +} + void get_value_libconfig(const config_setting_t *e, void *dest) { int type = config_setting_type(e); @@ -108,3 +130,52 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path) return NULL; } + +void *get_node_libconfig(config_t *cfg, const char **nodes) +{ + config_setting_t *setting; + char root[1024]; + + path_libconfig(nodes, root, sizeof(root)); + setting = config_lookup(cfg, root); + if (setting) + return setting; + + return NULL; +} + +void *find_root_libconfig(config_t *cfg, const char **nodes, unsigned int depth) +{ + config_setting_t *elem; + char root[1024]; + const char *ref; + char **tmp = NULL; + + /* + * check for deadlock links, block recursion + */ + if (!(--depth)) + return NULL; + + path_libconfig(nodes, root, sizeof(root)); + + /* + * If this is root node for the device, + * it is a group and lenght is not 0. + * If it is a link, follow it + */ + elem = config_lookup(cfg, root); + + if (elem && config_setting_is_group(elem) == CONFIG_TRUE) { + ref = get_field_string_libconfig(elem, "ref"); + if (ref) { + if (!set_find_path(nodes, ref, tmp)) + return NULL; + elem = find_root_libconfig(cfg, nodes, depth); + free_string_array(tmp); + } + } + + return elem; + +} diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c index b1f5775..0322a4f 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -179,4 +180,40 @@ char *json_get_data_url(json_object *json_root, const char *key) : strndup(json_object_get_string(json_data), MAX_URL_LENGTH); } +void *find_root_json(json_object *root, const char **nodes, unsigned int depth) +{ + json_object *node; + enum json_type type; + char **tmp = NULL; + const char *str; + + /* + * check for deadlock links, block recursion + */ + if (!(--depth)) + return false; + + node = find_json_recursive_node(root, nodes); + + if (node) { + type = json_object_get_type(node); + + if (type == json_type_object || type == json_type_array) { + str = get_field_string_json(node, "ref"); + if (str) { + if (!set_find_path(nodes, str, tmp)) + return NULL; + node = find_root_json(root, nodes, depth); + free_string_array(tmp); + } + } + } + return node; +} + +void *get_node_json(json_object *root, const char **nodes) +{ + return find_json_recursive_node(root, nodes); +} + diff --git a/include/parselib.h b/include/parselib.h index 2fca3b5..5cbc255 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -39,6 +39,8 @@ void *get_child_libconfig(void *e, const char *name); void iterate_field_libconfig(config_setting_t *e, iterate_callback cb, void *data); const char *get_field_string_libconfig(config_setting_t *e, const char *path); +void *find_root_libconfig(config_t *cfg, const char **nodes, unsigned int depth); +void *get_node_libconfig(config_t *cfg, const char **nodes); #else #define config_setting_get_elem(a,b) (NULL) @@ -49,6 +51,8 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path); #define get_child_libconfig(e, name) (NULL) #define iterate_field_libconfig(e, cb, data) { } #define get_field_cfg(e, path, dest) +#define find_root_libconfig(cfg, nodes, depth) (NULL) +#define get_node_libconfig(cfg, nodes) (NULL) #endif #ifdef CONFIG_JSON @@ -65,6 +69,8 @@ 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); +void *find_root_json(json_object *root, const char **nodes, unsigned int depth); +void *get_node_json(json_object *root, const char **nodes); #else #define find_node_json(a, b, c) (NULL) @@ -75,6 +81,8 @@ char *json_get_data_url(json_object *json_root, const char *key); #define json_object_object_get_ex(a,b,c) (0) #define json_object_array_get_idx(a, b) (0) #define json_object_array_length(a) (0) +#define find_root_json(root, nodes, depth) (NULL) +#define get_node_json(root, nodes) (NULL) #endif typedef int (*settings_callback)(void *elem, void *data); @@ -90,7 +98,7 @@ 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); void check_field_string(const char *src, char *dst, const size_t max_len); -bool find_root(parsertype p, void *root, const char **nodes); +void *find_root(parsertype p, void *root, const char **nodes); void *get_node(parsertype p, void *root, const char **nodes); bool set_find_path(const char **nodes, const char *newpath, char **tmp); diff --git a/parser/parser.c b/parser/parser.c index 19181d1..bc89b9d 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -29,115 +30,125 @@ #define NODEROOT (!strlen(CONFIG_PARSERROOT) ? \ "software" : CONFIG_PARSERROOT) -#ifdef CONFIG_LIBCONFIG -static config_setting_t *find_node_libconfig(config_t *cfg, - const char *field, struct swupdate_cfg *swcfg) +#if defined(CONFIG_LIBCONFIG) || defined(CONFIG_JSON) + +static bool path_append(const char **nodes, const char *field) { - config_setting_t *setting; - struct hw_type *hardware; + unsigned int count = 0; - char node[1024]; + count = count_string_array(nodes); - if (!field) - return NULL; + if (count >= MAX_PARSED_NODES) + return false; - hardware = &swcfg->hw; + nodes[count++] = field; + nodes[count] = NULL; - if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) { - /* Try with both software set and board name */ - if (strlen(hardware->boardname)) { - snprintf(node, sizeof(node), "%s.%s.%s.%s.%s", - NODEROOT, - hardware->boardname, - swcfg->software_set, - swcfg->running_mode, - field); - setting = config_lookup(cfg, node); - if (setting) - return setting; - } - /* still here, try with software set and mode */ - snprintf(node, sizeof(node), "%s.%s.%s.%s", - NODEROOT, - swcfg->software_set, - swcfg->running_mode, - field); - setting = config_lookup(cfg, node); - if (setting) - return setting; - - } - - /* Try with board name */ - if (strlen(hardware->boardname)) { - snprintf(node, sizeof(node), "%s.%s.%s", - NODEROOT, - hardware->boardname, - field); - setting = config_lookup(cfg, node); - if (setting) - return setting; - } - /* Fall back without board entry */ - snprintf(node, sizeof(node), "%s.%s", - NODEROOT, - field); - return config_lookup(cfg, node); + return true; } -#endif - -#ifdef CONFIG_JSON -static json_object *find_node_json(json_object *root, const char *node, +static void *find_node(parsertype p, void *root, const char *field, struct swupdate_cfg *swcfg) { - json_object *jnode = NULL; - const char *simple_nodes[] = {NODEROOT, node, NULL}; + struct hw_type *hardware; + const char **nodes; + int i; + + if (!field) + return NULL; hardware = &swcfg->hw; - if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) { - if (strlen(hardware->boardname)) { - const char *nodes[] = {NODEROOT, hardware->boardname, - swcfg->software_set, swcfg->running_mode, - node, NULL}; - jnode = find_json_recursive_node(root, nodes); - if (jnode) - return jnode; - } else { - const char *nodes[] = {NODEROOT, swcfg->software_set, - swcfg->running_mode, node, NULL}; - jnode = find_json_recursive_node(root, nodes); - if (jnode) - return jnode; + nodes = (const char **)calloc(MAX_PARSED_NODES, sizeof(*nodes)); + + for (i = 0; i < 4; i++) { + nodes[0] = NULL; + switch(i) { + case 0: + if (strlen(swcfg->running_mode) && strlen(swcfg->software_set) && + strlen(hardware->boardname)) { + nodes[0] = NODEROOT; + nodes[1] = hardware->boardname; + nodes[2] = swcfg->software_set; + nodes[3] = swcfg->running_mode; + nodes[4] = NULL; + } + break; + case 1: + /* try with software set and mode */ + if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) { + nodes[0] = NODEROOT; + nodes[1] = swcfg->software_set; + nodes[2] = swcfg->running_mode; + nodes[3] = NULL; + } + break; + case 2: + /* Try with board name */ + if (strlen(hardware->boardname)) { + nodes[0] = NODEROOT; + nodes[1] = hardware->boardname; + nodes[2] = NULL; + } + break; + case 3: + /* Fall back without board entry */ + nodes[0] = NODEROOT; + nodes[1] = NULL; + break; } - } - if (strlen(hardware->boardname)) { - const char *nodes[] = {NODEROOT, hardware->boardname, node, - NULL}; - jnode = find_json_recursive_node(root, nodes); - if (jnode) - return jnode; + /* + * If conditions are not set, + * skip to the next option + */ + if (!nodes[0]) + continue; + + /* + * The first find_root() search for + * the root element from board, selection + * The second one starts from root and follow the tree + * to search for element + */ + if (find_root(p, root, nodes)) { + void *node = NULL; + if (!path_append(nodes, field)) + return NULL; + node = find_root(p, root, nodes); + + if (node) { + free(nodes); + return node; + } + } } - return find_json_recursive_node(root, simple_nodes); + free(nodes); + + return NULL; } -#endif -#if defined(CONFIG_LIBCONFIG) || defined(CONFIG_JSON) -static void *find_node(parsertype p, void *root, const char *node, - struct swupdate_cfg *swcfg) +static bool get_common_fields(parsertype p, void *cfg, struct swupdate_cfg *swcfg) { - switch (p) { - case LIBCFG_PARSER: - return find_node_libconfig((config_t *)root, node, swcfg); - case JSON_PARSER: - return find_node_json((json_object *)root, node, swcfg); + + void *setting; + + if((setting = find_node(p, cfg, "version", swcfg)) == NULL) { + ERROR("Missing version in configuration file"); + return false; } + + GET_FIELD_STRING(p, setting, NULL, swcfg->version); + TRACE("Version %s", swcfg->version); - return NULL; + if((setting = find_node(p, cfg, "description", swcfg)) != NULL) { + GET_FIELD_STRING(p, setting, NULL, swcfg->description); + TRACE("Description %s", swcfg->description); + } + + return true; } static void add_properties_cb(const char *name, const char *value, void *data) @@ -672,11 +683,8 @@ static int parser(parsertype p, void *cfg, struct swupdate_cfg *swcfg) int parse_cfg (struct swupdate_cfg *swcfg, const char *filename) { config_t cfg; - const char *str; - char node[128]; parsertype p = LIBCFG_PARSER; int ret; - config_setting_t *setting; memset(&cfg, 0, sizeof(cfg)); config_init(&cfg); @@ -694,24 +702,8 @@ int parse_cfg (struct swupdate_cfg *swcfg, const char *filename) return -1; } - if((setting = find_node(p, &cfg, "version", swcfg)) == NULL) { - ERROR("Missing version in configuration file"); + if (!get_common_fields(p, &cfg, swcfg)) return -1; - } else { - GET_FIELD_STRING(p, setting, NULL, swcfg->version); - TRACE("Version %s", swcfg->version); - } - - if((setting = find_node(p, &cfg, "description", swcfg)) != NULL) { - GET_FIELD_STRING(p, setting, NULL, swcfg->description); - TRACE("Description %s", swcfg->description); - } - - snprintf(node, sizeof(node), "%s.embedded-script", - NODEROOT); - if (config_lookup_string(&cfg, node, &str)) { - TRACE("Found Lua Software:\n%s", str); - } ret = parser(p, &cfg, swcfg); @@ -734,7 +726,7 @@ int parse_json(struct swupdate_cfg *swcfg, const char *filename) struct stat stbuf; unsigned int size; char *string; - json_object *cfg, *setting; + json_object *cfg; parsertype p = JSON_PARSER; /* Read the file. If there is an error, report it and exit. */ @@ -764,18 +756,9 @@ int parse_json(struct swupdate_cfg *swcfg, const char *filename) return -1; } - if((setting = find_node(p, cfg, "version", swcfg)) == NULL) { - ERROR("Missing version in configuration file"); + if (!get_common_fields(p, cfg, swcfg)) { free(string); return -1; - } else { - GET_FIELD_STRING(p, setting, NULL, swcfg->version); - TRACE("Version %s", swcfg->version); - } - - if((setting = find_node(p, cfg, "description", swcfg)) != NULL) { - GET_FIELD_STRING(p, setting, NULL, swcfg->description); - TRACE("Description %s", swcfg->description); } ret = parser(p, cfg, swcfg); From patchwork Wed Nov 14 16:02:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 997811 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:4864:20::53f; helo=mail-ed1-x53f.google.com; envelope-from=swupdate+bncbcxploxj6ikrbhmowhpqkgqezk5igyi@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="Rq4kP7co"; dkim-atps=neutral Received: from mail-ed1-x53f.google.com (mail-ed1-x53f.google.com [IPv6:2a00:1450:4864:20::53f]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42w8Qm1yGnz9sBN for ; Thu, 15 Nov 2018 03:02:40 +1100 (AEDT) Received: by mail-ed1-x53f.google.com with SMTP id h24-v6sf8615510ede.9 for ; Wed, 14 Nov 2018 08:02:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542211357; cv=pass; d=google.com; s=arc-20160816; b=AADFT7LZUQkyq6MXY2ZBa0PQWblsw6eA3+LELuSJIEeP0rEEZEmIRipTODSC+hXpMW AkWVNmeciCNh64bcjjN3qfkTLDNnxzftRIifX2lDbs0Zh11NFPH56aEfrAppJdBR93oB ov/GgRfWb1coMLB3D9xP78W/kIiRyXrXm+92wrln6uzMuUg3sqav8DcW4d52SewSkukP 0ftdxmiiekIBz7KMoMmsnqayImvZfkW/OG+zvMbEVnIno/8SD1P434zW3+tqAQoeIJMn pGn4Y443LNIv1dOO9ixyn0n7PhON27IScqEIjmyjlo/yknD/EGdwMXVlhR1to5BY0xIU HdKQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:sender:dkim-signature; bh=P2VTWFspMuGrMhUU89prrdXvLPbntRmCoIhpqsuzgiM=; b=RZ/7U4hbc5Krii+wTAIo1b4MiU16yZ19bIxs4ZAKo2EWUPJ1OzokaDm7ciCwH17XTh n5JUntVUgW+YM5xlvua+FBYFUcA/rmHF4DEq3w3QaZEqVYvoTdBe2L8H8LCjQ89pfLA9 YlsaFjQC7klynfICfuF9NP22OryOOxqXLiXyUl4atunfQzWcdY9oMfFem6QtUKLK3Cop rqfc++lVVv4JprG9FnqI9fXtqJgUjr1YS8hPwG6tCHSqsjjhNTa7sLOj9EWjjKnq4c6y ioRY1NTQ3jIg4lgxRFyGt0Ed541oizUaQDmWIqG4ZULBxmv8aS8m7vyVAoqtRIdFr2EZ IYNA== 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:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=P2VTWFspMuGrMhUU89prrdXvLPbntRmCoIhpqsuzgiM=; b=Rq4kP7co8PwiVea7HrCV06dSLMi78v1WHxNeiRqwoiZQouL5D3+ZIlGRZZ1UtKZnh1 fSMw6LLCFYsBTGYtzWUlKqo3HMoI4oCRTP1eWqzJdnSrCO0ei5xqrfSFNNEu9F2ukHOk Uh+8UtfeL7LE7aoGwLVnfd8Io76QA1zq0kJaooU+dY4DUbOAf4wHW2tvRWRsL1hL/H+O LmwzGc9Nx6puIa9o5mEqr7TokeYa2rZ07xILCOusUIe3o64kCRaQjnKKCBYJgA+P/Vmj AtXUzEUEcsV8u5gnJh3sf7KLTGbixXfmyqG73385kjrUFFFSIuDMVA4q0L7G/is/xSKE K+2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding :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=P2VTWFspMuGrMhUU89prrdXvLPbntRmCoIhpqsuzgiM=; b=a2mGilaagH0vB+qzFJgDBjwcbFrHOWp09AK/LvkgbWdUvqcg9l9Xpp0iLRGEeqw8xS pA4RSLr+tUOga9ZfNL1GC6iU4uEk9B0ofz8riE+nTS9QVW58Yjtr9Hn4XI+eoasXFCvs U/R9I5S+j2VQqT9/tMt5DDBJFrvE/oMv5a1q6LA55nlaYZ8//ApqDQK4D937gRPmhzr9 tACNZEgHQbnBobclusvaQt+DflzV9wSCUVS0HCvInVBLkAq59pOTYhUC99CbiIapnrUl +QkMNdML86FypECkdRKOtZAwSOInIBynbzlUM++4KckicuSSwAy+/8ZVuN8ktwGS4QMj yD5g== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gJbtAZmwZNyzG1c0QKCNtX8YUEnBf7tx8rhtS+fLvpA5cP6eL3N sWWWl4Pu/s029paOrVzkuNs= X-Google-Smtp-Source: AJdET5fbnrUS69rcWXKeh+HFnHcCLd3qU85n9Eq2zj1/uDc8ftgBwstRKpgKaerfbhNlzXNjthdP0A== X-Received: by 2002:a17:906:70d1:: with SMTP id g17-v6mr7890ejk.2.1542211357786; Wed, 14 Nov 2018 08:02:37 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a50:b362:: with SMTP id r31-v6ls3468871edd.0.gmail; Wed, 14 Nov 2018 08:02:37 -0800 (PST) X-Received: by 2002:a50:cb48:: with SMTP id h8-v6mr578338edi.3.1542211357304; Wed, 14 Nov 2018 08:02:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542211357; cv=none; d=google.com; s=arc-20160816; b=nfAODA4GqONvwG+f5q2KsbN4zfg4ugAt6CMl0BGcweTG9Cz35C39b7s+xth5vwV1/X QH4FUNEvU6YEeJ6fX5eNhZO/cLnR2Reyf7MNBeAeDStwJvYAFUx0nMaxsiDbkXoMPcWm NITeqFVytJ7jvfySUQVAp1I/VHsDDB6z6XpQ4c9tsaZD73uIhNGKJwRJNsvNKJzYpqdi EOheFagOaAsZxKYpestAdd/Up0DZaRfqcqiQhRLY/oDFZJCAJcuQlB022v2A2U/7y6zl i720pYULhRBsnx9QhTYcI9ba28WsELK1NEthCkhNBDlAw5YfpDZnv3I6gTcSuo+pjbju XCUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=pvOTfapSjntrmbzJitZvuEpKz21385AIm4mdCfReJpY=; b=oxDAlj3kWzj4qhMf5j0T5cOngsOe/ID0hI8UfPT48rbTvHjyXY2hL/RhEIN7CCCY9s R8KlQqrN5nXNxfbXAvc5RNUpVSNabpBg9zaDN0mXBwqaE1nSWzvuP/DFuV7/rD751yyP D6aST/SxdaMZh0kL5jqmRGFLkND5dw3maAyjLdEmKWGqZaqc3aEK+kaK2okgwzuhO8BB WqMn4/l2xBF99BPpWCwoHI2hmts+dODqOO8EUmgfHMdC8zzPvZKBsncvvESZQrAW5QIG 2ideQ5ueir5g/rOAxBk3XIRpfNJjqZP2mrr5MKaPqO/mfHoHXk/qLhS+E8T4dtr9qFS0 ub2g== 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 a35-v6si1237064edd.1.2018.11.14.08.02.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 08:02: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 42w8Qj0FS7z1r01X; Wed, 14 Nov 2018 17:02:37 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42w8Qj04zBz1qsJK; Wed, 14 Nov 2018 17:02: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 0bO-UNPSeNjC; Wed, 14 Nov 2018 17:02: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; Wed, 14 Nov 2018 17:02:36 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id AFD494540474; Wed, 14 Nov 2018 17:02: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 n_jw6oX6pyyP; Wed, 14 Nov 2018 17:02:32 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 5E1D04540664; Wed, 14 Nov 2018 17:02:24 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH v2 5/5] doc: explain usage of links in sw-description Date: Wed, 14 Nov 2018 17:02:21 +0100 Message-Id: <20181114160221.18242-6-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181114160221.18242-1-sbabic@denx.de> References: <20181114160221.18242-1-sbabic@denx.de> MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by 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 --- Changes in v2: None doc/source/sw-description.rst | 225 ++++++++++++++++++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index 36c02b2..51fe670 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -318,6 +318,231 @@ while another device can have raw flash and install an UBI filesystem. Neverthel both just a different format of the same release and they could be described together in sw-description. It is important to understand the priorities how SWUpdate scans for entries during the parsing. +Using links +----------- + +sw-description can become very complex. Let's think to have just one board, but in multiple +hw revision and they differ in Hardware. Some of them can be grouped together, some of them +require a dedicated section. A way (but not the only one !) could be to add *mode* and selects +the section with `-e stable,`. + +:: + + software = + { + version = "0.1.0"; + + myboard = { + stable = { + + hardware-compatibility: ["1.0", "1.2", "2.0", "1.ยง, "3.0", "3.1"]; + rev-1.0: { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-1.2: { + hardware-compatibility: ["1.2"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-2.0: { + hardware-compatibility: ["2.0"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-1.3: { + hardware-compatibility: ["1.3"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + + rev-3.0: + { + hardware-compatibility: ["3.0"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + rev-3.1: + { + hardware-compatibility: ["3.1"]; + images: ( + ... + ); + scripts: ( + ... + ); + } + } + } + } + +If each of them requires an own section, it is the way to do. Anyway, it is more probable +than revisions can be grouped together, for example board with the same major revision +number could have the same installation instructions. This leads in the example to 3 groups +for rev1.X, rev2.X and rev3.X. Links allow to group section together. When a string is found +when SWUpdate searches for a group (images, files, script, bootenv), it replaces the current path +in the tree with the value of the string. In this way, the example above can be written in this way: + +:: + + software = + { + version = "0.1.0"; + + myboard = { + stable = { + + hardware-compatibility: ["1.0", "1.2", "2.0", "1.3, "3.0", "3.1"]; + rev-1x: { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev1.0 = { + ref = "#../rev-1x"; + } + rev1.2 = { + ref = "#../rev-1x"; + } + rev1.3 = { + ref = "#../rev-1x"; + } + rev-2x: { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev2.0 = { + ref = "#../rev-2x"; + } + + rev-3x: + { + images: ( + ... + ); + scripts: ( + ... + ); + } + rev3.0 = { + ref = "#../rev-3x"; + } + rev3.1 = { + ref = "#../rev-3x"; + } + } + } + } + +The link can be absolute or relative. The keyword *"ref"* is used to indicate a link. If this is found, SWUpdate +will traverse the tree and replaces the current path with the values find in the string pointed by "ref". There are +simple rules for a link: + + - it must start with the character '#' + - "." points to the current level in the tree + - ".." points to the parent level in the tree + - "/" is used as filed separator in the link + + +A relative path has a number of +leading "../" to move the current cursor to the parent leaf of the tree. +In the following example, rev40 sets a link to a "common" section, where `images` +is found. This is sets via a link, too, to a section in the parent node. +The path `software.myboard.stable.common.images` is then replaced by +`software.myboard.stable.trythis` + +:: + + software = + { + version = { + ref = "#../commonversion"; + } + + hardware-compatibility = ["rev10", "rev11", "rev20"]; + + commonversion = "0.7-linked"; + + pc:{ + stable:{ + + common:{ + images = + { + ref = "#../../trythis"; + } + }; + + trythis:( + { + filename = "rootfs1.ext4"; + device = "/dev/mmcblk0p8"; + type = "raw"; + } , + { + filename = "rootfs5.ext4"; + device = "/dev/mmcblk0p7"; + type = "raw"; + } + ); + pdm3rev10: + { + images:( + { + filename = "rootfs.ext3"; device = "/dev/mmcblk0p2";} + ); + uboot:( + { name = "bootpart"; + value = "0:2";} + ); + }; + pdm3rev11 = + { + ref = "#../pdm3rev10"; + } + pdm3rev20 = + { + ref = "#../pdm3rev10"; + } + pdm3rev40 = + { + ref = "#../common"; + } + }; + }; + } + + +Each entry in sw-description can be redirect by a link as in the above example for the +"version" attribute. + hardware-compatibility ----------------------