From patchwork Wed Jan 17 14:34:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 862290 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+bncbdn7dbh5yqibbnn67xjakgqewqrwana@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="AF709xAT"; 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 3zM8lF2mPbz9s7M for ; Thu, 18 Jan 2018 01:35:36 +1100 (AEDT) Received: by mail-wm0-x23a.google.com with SMTP id b193sf4066740wmd.7 for ; Wed, 17 Jan 2018 06:35:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516199734; cv=pass; d=google.com; s=arc-20160816; b=SXTiKFrAKm0UeNnK2vyA14UfwebDJVG5Q1jNrt+Tn/+CVPcJpfbhr1P2NnRKzr2epZ Pr4eFKjNY0btsxj+ndquh5Fq69fMSBIgMHjr3deLv4ltXSrF4VJIQX6BNWpaQxqTGopI UP35SV7um6FCDW5SR55UixxsT2iNNYJO2tXkGR8uujD3S/96+YScapId7MTOdoanZz7h 4sQoZiQLZ6BzJLDRWPIhcFfKheP9qsF/Bpr4ODOWPAXBIlJYJ1frMatCGr8Tx0dTSTFT +ETn56D1TGeq3sfGBko//XUl7ZlSTqW/IS4csvr+QEqOKs/0qaVC+0kcjEiiI6OBmkGt WM7g== 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=PKIMfklIqwwGZgGWFkNkhpqotRZdV2zCR0oXp5UuTwo=; b=ufLJ51ANNOct8BKHv829PjDO9nHndVjk/8NSGDJD4H4Q8yTP4DDVrWFzH36GzsuFTR PrphljMtsMjCxSs+Ew2CdTx0loxQRmjXHRrblntSnF7KBeCw895Me5LBRqMhisknHuGF 2MD8MGiMdUQIxfubVTQkc/3p/HOcP1baxvnHtW1fD9z/9Gb/QuQq0BRm1+hdgPm3FD9H x93ur/PcRgOBr/CKtPYo93rL3TJhZ98kKBAIjVKcOUzq1y4Z8NbB0YcAa4lDGjIvXh2c FJcG2oBw/DckUYX+wwIu8EiQpnuRjQ0U/jQalOeNPIsPX8Gx+GxpLgEjKq82nE6UovR2 rRjQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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=PKIMfklIqwwGZgGWFkNkhpqotRZdV2zCR0oXp5UuTwo=; b=AF709xATw1sGFmDc9qh3kZ2XYK5+6yMq7eX/WwAt30mCLMjsrCx05hbPSEzTxLBPBJ a6LILkTNGvT45xrn6G8TV/u0yiQ901Qz7oUBw0sigpl0WkE/gQ/GYPIN02EQS+9UHvUq ev8tZrKVj4mj+4VWERupAbRsb+I/omwrhTVQl7utub6sHdPEk6TRR5vxW9a4q9Fq64Fa cm7ZZ2ZKG8Fe4jlKnQhxHshFDO6v1VFAdCfrsJkfBku1LATgwQapg1q6s2CvG4INld/0 ZEw4dEdgFy1r2WpN6JmI1hN/6KbJrMGag0DM4SoPlLjomW0i6T33LujJs/7hVrygfIdI CI2Q== 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=PKIMfklIqwwGZgGWFkNkhpqotRZdV2zCR0oXp5UuTwo=; b=fwXvDhU5f+JQFXqpxmkPuAd10BPQIfOerNb5XclR0CcE18oObpVTcfEhdk6Ulu/8i/ Ztuqp7sj1dm5ztin77YJIZkiJ4/EqBNFR6L0kEzGdi04E4GQI5m7ksL+1dMUhrppP8yQ St6Mniz6uj202giVn4gzdoExwuMIwpLvOsdgohS4fP27J6oeb3kMPxrSVWGKBi3ZV1s4 c3++wYz47HQxF2rXAQlYGqD1uTAzjX/i2kYQ+ssKltpsWZVjRNXj1nOEA7kNTILqoEsO Q6hgFxlI5pcP/sxXMindT0Epxc1Z4x+J+GTjA63PvJac3XYuPZ8TqcerhOD7YEVQiPGQ pTdQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytfvcd6lpGRd4Oo/ZcQQ1oz7bbsrnFBtpj/XsPA/KQjRuBAy8ToL HCJMhfPZlKg7saOCOzVzCdc= X-Google-Smtp-Source: ACJfBosFS8zu3dOYDnZXoXpl5BvcCVmXe9o6YPxsG/zoFfazAMaxIl1ej5WOSzhfl5/VtWFn75BPEA== X-Received: by 10.28.156.133 with SMTP id f127mr35152wme.1.1516199733925; Wed, 17 Jan 2018 06:35:33 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.198.74 with SMTP id u10ls1708825wrg.7.gmail; Wed, 17 Jan 2018 06:35:33 -0800 (PST) X-Received: by 10.28.241.15 with SMTP id p15mr292544wmh.5.1516199733337; Wed, 17 Jan 2018 06:35:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516199733; cv=none; d=google.com; s=arc-20160816; b=FYen5WmD+stbwaocBpK8pA17yJXq9F0nPsvd5jYUYSWgJfbh2gTT/k+lQEwsd7gnVw OrMPrdESmarx9FC45YBp+icPiADDMShvrriTMbzkfl3D9vRLJjRH5r5OZ6LV6Kr50hkO LcO1LqyVjFOzvmjTmksIrNaWoxQmW9w1FiHxizAvfrPT5A4+dJ6kvjBB6YQm3LiQl2Gf Th37xECdEX68309X7aMP2Hc+fEnIs+1jU+92NUSGw55uhUuruXa6hkeH99MZSyp8Q4b8 YbR7dhgHd3LvpHfR8tc8uDLRweaK0dClp7oOfEYGSgAaO2htuwF10+N7UxO88kymdSX8 wEZg== 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=8krUzkKpVwJl1D2oUERkxRsfa48xnsxGp/ZiFA+q4Vk=; b=qsZQ+QNYhsnPRbRmPdVLmhNy3xq0gwQAh6y+Awktp3BbEmek8OWZSEJqV8YDoxHb4Q 18bIovUfSUXvhVuY7elQyGSPNK4a1TTk54aZDQmHsUWIVSlDd2RARJPonWmnkRLfTf36 CenQMQBDjfXfT5yEG1Ds9L3VFrEwN6Hjor+VDARGBJvwC+7o5HxDKD+3NeKKw551obje OlcLpS+7Q/piAMloKr7zkQX91QzqR9Andkid/OXeSTM8aumhUhtmSj+twxRnoshCaMs+ FtV6gklPSaBhsadFN1w+VmtuDe0kUNMQb486sAboZv33Jid1q5rXOJfvS5M1xd7eJsq0 yoxg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Received: from dd41138.kasserver.com (dd41138.kasserver.com. [85.13.157.12]) by gmr-mx.google.com with ESMTPS id d125si1164104wmc.0.2018.01.17.06.35.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:35:33 -0800 (PST) Received-SPF: neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) client-ip=85.13.157.12; Received: from WS08941.weidmueller.com (unknown [217.244.7.16]) by dd41138.kasserver.com (Postfix) with ESMTPSA id AF27611A0698; Wed, 17 Jan 2018 15:35:32 +0100 (CET) From: stefan@herbrechtsmeier.net To: swupdate@googlegroups.com Cc: Stefan Herbrechtsmeier Subject: [swupdate] [PATCH v2 1/5] dict: Rename dictionary struct and its key to distinguish it from simple lists Date: Wed, 17 Jan 2018 15:34:02 +0100 Message-Id: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 X-Original-Sender: stefan@herbrechtsmeier.net X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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: , From: Stefan Herbrechtsmeier Signed-off-by: Stefan Herbrechtsmeier Reviewed-by: Stefano Babic --- Changes in v3: None Changes in v2: None bootloader/grub.c | 12 ++++++------ bootloader/grub.h | 2 +- corelib/installer.c | 4 ++-- corelib/swupdate_dict.c | 18 +++++++++--------- handlers/swuforward_handler.c | 2 +- include/swupdate.h | 4 ++-- include/swupdate_dict.h | 14 +++++++------- suricatta/server_hawkbit.c | 6 +++--- suricatta/server_hawkbit.h | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/bootloader/grub.c b/bootloader/grub.c index 7a59e4a..2f6172e 100644 --- a/bootloader/grub.c +++ b/bootloader/grub.c @@ -113,7 +113,7 @@ static int grubenv_parse_script(struct grubenv_t *grubenv, const char *script) goto cleanup; } - /* load varname-value pairs from script into grubenv dictlist */ + /* load key-value pairs from script into grubenv dictionary */ /* Note that variables with no value assigned are skipped now. * We should consider whether we want to replicate U-Boot behavior * (unset if no value given). GRUB env tool distinguishes unsetting @@ -153,7 +153,7 @@ static inline void grubenv_update_size(struct grubenv_t *grubenv) /* lengths of strings + '=' and '\n' characters */ LIST_FOREACH(grubvar, &grubenv->vars, next) { - size = size + strlen(grubvar->varname) + + size = size + strlen(grubvar->key) + strlen(grubvar->value) + 2; } size += strlen(GRUBENV_HEADER); @@ -194,9 +194,9 @@ static int grubenv_write(struct grubenv_t *grubenv) strncpy(buf, GRUBENV_HEADER, strlen(GRUBENV_HEADER) + 1); LIST_FOREACH(grubvar, &grubenv->vars, next) { - llen = strlen(grubvar->varname) + strlen(grubvar->value) + 2; + llen = strlen(grubvar->key) + strlen(grubvar->value) + 2; /* +1 for null termination */ - snprintf(line, llen + 1, "%s=%s\n", grubvar->varname, + snprintf(line, llen + 1, "%s=%s\n", grubvar->key, grubvar->value); strncat(buf, line, llen); } @@ -240,7 +240,7 @@ static inline void grubenv_close(struct grubenv_t *grubenv) struct dict_entry *grubvar; LIST_FOREACH(grubvar, &grubenv->vars, next) { - dict_remove(&grubenv->vars, grubvar->varname); + dict_remove(&grubenv->vars, grubvar->key); } } @@ -320,7 +320,7 @@ int bootloader_apply_list(const char *script) if ((ret = grubenv_open(&grubenv))) goto cleanup; - /* add variables from sw-description into dict list */ + /* add variables from sw-description into dictionary list */ if ((ret = grubenv_parse_script(&grubenv, script))) goto cleanup; diff --git a/bootloader/grub.h b/bootloader/grub.h index 70de232..df49ba6 100644 --- a/bootloader/grub.h +++ b/bootloader/grub.h @@ -29,7 +29,7 @@ #define GRUBENV_PATH_NEW GRUBENV_PATH ".new" struct grubenv_t { - struct dictlist vars; + struct dict vars; size_t size; }; diff --git a/corelib/installer.c b/corelib/installer.c index 4f58794..e5bf895 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -206,10 +206,10 @@ static int prepare_boot_script(struct swupdate_cfg *cfg, const char *script) return -1; LIST_FOREACH(bootvar, &cfg->bootloader, next) { - if (!bootvar->varname || !bootvar->value) + if (!bootvar->key || !bootvar->value) continue; snprintf(buf, sizeof(buf), "%s %s\n", - bootvar->varname, + bootvar->key, bootvar->value); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { TRACE("Error saving temporary file"); diff --git a/corelib/swupdate_dict.c b/corelib/swupdate_dict.c index a6bb1a0..2cdad47 100644 --- a/corelib/swupdate_dict.c +++ b/corelib/swupdate_dict.c @@ -19,19 +19,19 @@ #include "util.h" #include "swupdate_dict.h" -static struct dict_entry *get_entry(struct dictlist *dictionary, char *key) +static struct dict_entry *get_entry(struct dict *dictionary, char *key) { struct dict_entry *entry; LIST_FOREACH(entry, dictionary, next) { - if (strcmp(key, entry->varname) == 0) + if (strcmp(key, entry->key) == 0) return entry; } return NULL; } -int dict_insert_entry(struct dictlist *dictionary, char *key, char *value) +int dict_insert_entry(struct dict *dictionary, char *key, char *value) { struct dict_entry *entry = (struct dict_entry *)malloc(sizeof(*entry)); @@ -39,7 +39,7 @@ int dict_insert_entry(struct dictlist *dictionary, char *key, char *value) return -ENOMEM; memset(entry, 0, sizeof(*entry)); - entry->varname = strdup(key); + entry->key = strdup(key); entry->value = strdup(value); LIST_INSERT_HEAD(dictionary, entry, next); @@ -47,7 +47,7 @@ int dict_insert_entry(struct dictlist *dictionary, char *key, char *value) return 0; } -char *dict_get_value(struct dictlist *dictionary, char *key) +char *dict_get_value(struct dict *dictionary, char *key) { struct dict_entry *entry = get_entry(dictionary, key); @@ -57,7 +57,7 @@ char *dict_get_value(struct dictlist *dictionary, char *key) return entry->value; } -int dict_set_value(struct dictlist *dictionary, char *key, char *value) +int dict_set_value(struct dict *dictionary, char *key, char *value) { struct dict_entry *entry = get_entry(dictionary, key); @@ -76,12 +76,12 @@ int dict_set_value(struct dictlist *dictionary, char *key, char *value) void dict_remove_entry(struct dict_entry *entry) { LIST_REMOVE(entry, next); - free(entry->varname); + free(entry->key); free(entry->value); free(entry); } -void dict_remove(struct dictlist *dictionary, char *key) +void dict_remove(struct dict *dictionary, char *key) { struct dict_entry *entry = get_entry(dictionary, key); @@ -92,7 +92,7 @@ void dict_remove(struct dictlist *dictionary, char *key) dict_remove_entry(entry); } -void dict_drop_db(struct dictlist *dictionary) +void dict_drop_db(struct dict *dictionary) { struct dict_entry *var; diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c index 973bce3..c804628 100644 --- a/handlers/swuforward_handler.c +++ b/handlers/swuforward_handler.c @@ -327,7 +327,7 @@ static int install_remote_swu(struct img_type *img, LIST_FOREACH(url, &img->properties, next) { char curlheader[SWUPDATE_GENERAL_STRING_SIZE + strlen(CUSTOM_HEADER)]; - if (!url->varname || !url->value || strcmp(url->varname, "url")) + if (!url->key || !url->value || strcmp(url->key, "url")) continue; conn = (struct curlconn *)calloc(1, sizeof(struct curlconn)); diff --git a/include/swupdate.h b/include/swupdate.h index 74e7637..c88d638 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -66,7 +66,7 @@ struct img_type { int install_directly; int is_script; int is_partitioner; - struct dictlist properties; + struct dict properties; long long partsize; int fdin; /* Used for streaming file */ off_t offset; /* offset in cpio file */ @@ -123,7 +123,7 @@ struct swupdate_cfg { struct imglist partitions; struct imglist scripts; struct imglist bootscripts; - struct dictlist bootloader; + struct dict bootloader; struct proclist extprocs; void *dgst; /* Structure for signed images */ struct swupdate_global_cfg globals; diff --git a/include/swupdate_dict.h b/include/swupdate_dict.h index 0f74c98..2cae5ca 100644 --- a/include/swupdate_dict.h +++ b/include/swupdate_dict.h @@ -11,18 +11,18 @@ #include struct dict_entry { - char *varname; + char *key; char *value; LIST_ENTRY(dict_entry) next; }; -LIST_HEAD(dictlist, dict_entry); +LIST_HEAD(dict, 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); +char *dict_get_value(struct dict *dictionary, char *key); +int dict_set_value(struct dict *dictionary, char *key, char *value); +int dict_insert_entry(struct dict *dictionary, char *key, char *value); +void dict_remove(struct dict *dictionary, char *key); void dict_remove_entry(struct dict_entry *entry); -void dict_drop_db(struct dictlist *dictionary); +void dict_drop_db(struct dict *dictionary); #endif diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index a409871..c84de65 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -1336,7 +1336,7 @@ int get_target_data_length(void) struct dict_entry *entry; LIST_FOREACH(entry, &server_hawkbit.configdata, next) { - len += strlen(entry->varname) + strlen(entry->value) + strlen (" : ") + 6; + len += strlen(entry->key) + strlen(entry->value) + strlen (" : ") + 6; } return len; @@ -1370,14 +1370,14 @@ server_op_res_t server_send_target_data(void) if (ENOMEM_ASPRINTF == asprintf(&keyvalue, config_data, ((first) ? ' ' : ','), - entry->varname, + entry->key, entry->value)) { ERROR("hawkBit server reply cannot be sent because of OOM.\n"); result = SERVER_EINIT; goto cleanup; } first = false; - TRACE("KEYVALUE=%s %s %s", keyvalue, entry->varname, entry->value); + TRACE("KEYVALUE=%s %s %s", keyvalue, entry->key, entry->value); strcat(configData, keyvalue); free(keyvalue); diff --git a/suricatta/server_hawkbit.h b/suricatta/server_hawkbit.h index 50ab1e3..f851812 100644 --- a/suricatta/server_hawkbit.h +++ b/suricatta/server_hawkbit.h @@ -28,7 +28,7 @@ typedef struct { unsigned int polling_interval; bool polling_interval_from_server; bool debug; - struct dictlist configdata; + struct dict configdata; bool has_to_send_configData; char *configData_url; char *cancel_url; From patchwork Wed Jan 17 14:34:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 862291 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::23d; helo=mail-lf0-x23d.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbqn67xjakgqedxqdvvq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="juSVrOfm"; dkim-atps=neutral Received: from mail-lf0-x23d.google.com (mail-lf0-x23d.google.com [IPv6:2a00:1450:4010:c07::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 3zM8lT0wBsz9s71 for ; Thu, 18 Jan 2018 01:35:48 +1100 (AEDT) Received: by mail-lf0-x23d.google.com with SMTP id q21sf5986350lfa.14 for ; Wed, 17 Jan 2018 06:35:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516199745; cv=pass; d=google.com; s=arc-20160816; b=XoYLqOVNVclBKMaLK5ElcryJWU1wcTZSnjT7qz1nasetgfyhL/NjY4OjxdJ7rw0TGK v1YRjtu7buIOoad3dVC72Czr1N4BV9F5jPV1r1qZiPtCiLCN33v24gQvERoQtfCehDMu eMqJjiGYOyMlIoJKd8/TkehDIgtT0BZYShpkMyQ6xkawQ0lKk1b9mUQ+CVRPZhmR52sj c/jojXrjT+r3spOpUlZmjmZezUcVz6UnGOymmKGefxaPxqXWDQ5IxMtP3ImCuqZoF0UH wywFCbd6yYGB09mSD038x7HyIvkId/8YZrYHHNdQp27DcSs6bREh29yob7gmMgI2G8lV 2v7g== 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:arc-authentication-results:arc-message-signature:sender :dkim-signature:arc-authentication-results; bh=ZmWXSgLcoKegOqA7uXbkgSLbfA21ju2l3rqRv6T19Zc=; b=m8BP0oVqQLPmkYx83hsGl68CDcFCnK5hYVUKqVc+61Bg3RZPcCj1ixoWHcSWcLO/lM Q1xax3y7JkpEswzp9aEnUQoQQmXuC4Y8jI3jTc7OVFQSAvG01uqfLnr6RbgbnJCxU5kL VQmI1YL+Z3M2wr0bJlu9qO8hLy/of7nSf1fMMEIc9+9590oRDui/rDvYtIlf7iCL5v96 ey5q7pcdO+3xhYjlqIaHR4N93OWRZQ4zhimlWhK1FBki4jb20Q522NrVCaqguSJvTeoJ olsvczlNm2KQeiO2BAt4qm29yBaq9l4/Lkb6QmpnrE8G1+6VdGTbysUmfbkIXmDgWsJR xQ0w== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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=ZmWXSgLcoKegOqA7uXbkgSLbfA21ju2l3rqRv6T19Zc=; b=juSVrOfmVRBx8bvwlac1uRbrDt1ppCs9pxAfPUCNi2mzr3X6CA5zDpp6r4VwN1iuAy xtd3DrAuxhOqyK6O70MXeqmRLIYaf9FOrTAnObinz1jq9yajqyZ1c8SqLnvatXgfK6pj duAZNveaOxNrlJhW5M9gnrHADIRfZJQW9j19GKy+Mh19FsO8n68RTguPGEMnIdJt4Yaz +Ay5mt6iznWGv2314T1l5FaxVhRd7WXLyjlgyZI2dHzeMqM/V2xa6yw5/UOmDz8aDvrm ok/0LKfEQeawn1li3wmSutFrDY3xArjQt9R76viEcBLeIrofam2C9PjQ2nCZd+odFEF/ SYYw== 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=ZmWXSgLcoKegOqA7uXbkgSLbfA21ju2l3rqRv6T19Zc=; b=TgS6qcwXqsfUUJXDgcJE/bykz4ElxLMB2rdZneGD/BGDjRRmbACSvuLTHUdsuIA6/L XFnSwbwswUnYra6oWsll5I6rQ8Cn5O31aRBpQaGeWQYoEx5mOZe9yGU3pnBFKpNt+NGC evNS4AoIRqkdme0V2PxImKjVwJ3oZ8HcqnUnBI4hdZzEemEA4v+vATcNL1EDoT1vKeMN 3AU67wEfV1aeNZAABL2amUWjrtpiV3MSj8wsC1J4PvOlhPQD9f+TzQIAU9w3vLYS/cjR lbE8rT0FVBeZCoCfAqsGOARWuHX1yyvrLC2jo4AaFrJRE0bqgUwlTdrzSPemmNdfs4W0 IocQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKGB3mIoI/S7OI+xcdtVTKLeFQliCShSNCgLVqIQotodrdQcderROVJZ TJC6k78lGuPvATl0Xjv14mY= X-Google-Smtp-Source: ACJfBotB9heSJboEZ8nGs7TTY2QbPN+wGmaOE1Hcjz3hf0mKpPIMMoqC4olBUy6i55/QASOTuMN0sw== X-Received: by 10.46.55.17 with SMTP id e17mr117555lja.13.1516199745581; Wed, 17 Jan 2018 06:35:45 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 10.25.151.15 with SMTP id z15ls140455lfd.14.gmail; Wed, 17 Jan 2018 06:35:44 -0800 (PST) X-Received: by 10.46.87.24 with SMTP id l24mr1111935ljb.30.1516199744170; Wed, 17 Jan 2018 06:35:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516199744; cv=none; d=google.com; s=arc-20160816; b=Z3GfjNH0asfP6HHXUhlTsRzs69URSziJ3MYIPD7OK5JTJscrZXIuLX5hDeCPePoCeO OvGZbP6/rz94RThMbQ+gV7LpiQrHbjQZrxFr+PsDwW4hHLvibIsOmCe6BAcCj2jfUk9g ybHIDKWuNPlaxSeki5DE+Kn7vGZiJItL2y0Mnkq3hNvsL/HjO5TQTFt5hsDUOZk2KCL6 zhxakZaeRI/1ynjlLOfpyfPFQbNMS9UlnswV5xUQxOC5im1dP1Zm0kBZ3IFlbTjQUUiC vc2Fk63XLxJvk+YaLoAhSfCQ+hmXl/wh5RX1SUj9Q/SoGkmiSn5K5jUvDkHZxgW9/8cx J2eA== 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:arc-authentication-results; bh=FhCmygC9Ytf5j0f2YPtR4ukvaCB2z4ePGSdy7+6x7kA=; b=nRZQZ7JG9tRg0gW98NlN1r4oMcup/BY9DxWvqtzrB1ug7nmF8aW3laL2jS3Qx15euG f5bjC8hb1ZqWDmHyfjUeXIU8eeW5UcG8QGVgWHB5XJcIKT/GKNByaiJkPAGwkKtoW7j8 vBtA7jIcedD7zzVOy+GMUzE1J7t16Ad1nsd9gCv07dgeI40oR99KRNWaVp/bRqJcpyvT jOnfKTo3h0dEq2zhf3zAB4r76LyOXGFZK/BqTEMfHaK5C6FeXWhftBCbD8Ezbr7My08K wvlHL4WFC7Gv7Ga6J9cdupw0eac+LUj2X/BX5TTl2rh4iuMSLH9jbSYG9L5tGpsUVJtz jv/w== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Received: from dd41138.kasserver.com (dd41138.kasserver.com. [85.13.157.12]) by gmr-mx.google.com with ESMTPS id l26si208266lja.0.2018.01.17.06.35.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:35:43 -0800 (PST) Received-SPF: neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) client-ip=85.13.157.12; Received: from WS08941.weidmueller.com (unknown [217.244.7.16]) by dd41138.kasserver.com (Postfix) with ESMTPSA id 3AA3211A0698; Wed, 17 Jan 2018 15:35:43 +0100 (CET) From: stefan@herbrechtsmeier.net To: swupdate@googlegroups.com Cc: Stefan Herbrechtsmeier Subject: [swupdate] [PATCH v2 2/5] corelib: Rework dictionary to support multiple values per key Date: Wed, 17 Jan 2018 15:34:03 +0100 Message-Id: <1516199646-5607-2-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> References: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> MIME-Version: 1.0 X-Original-Sender: stefan@herbrechtsmeier.net X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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: , From: Stefan Herbrechtsmeier Signed-off-by: Stefan Herbrechtsmeier Reviewed-by: Stefano Babic Tested-by: Stefano Babic --- Changes in v3: - Add const to all dict key and value parameters - Update swuforward to iterate over the value list Changes in v2: None bootloader/grub.c | 20 +++---- corelib/installer.c | 9 +-- corelib/swupdate_dict.c | 130 ++++++++++++++++++++++++++++++++---------- handlers/swuforward_handler.c | 11 +--- include/swupdate_dict.h | 22 +++++-- parser/parser.c | 2 +- suricatta/server_hawkbit.c | 14 +++-- 7 files changed, 143 insertions(+), 65 deletions(-) diff --git a/bootloader/grub.c b/bootloader/grub.c index 2f6172e..dc35718 100644 --- a/bootloader/grub.c +++ b/bootloader/grub.c @@ -153,8 +153,10 @@ static inline void grubenv_update_size(struct grubenv_t *grubenv) /* lengths of strings + '=' and '\n' characters */ LIST_FOREACH(grubvar, &grubenv->vars, next) { - size = size + strlen(grubvar->key) + - strlen(grubvar->value) + 2; + char *key = dict_entry_get_key(grubvar); + char *value = dict_entry_get_value(grubvar); + + size = size + strlen(key) + strlen(value) + 2; } size += strlen(GRUBENV_HEADER); grubenv->size = size; @@ -194,10 +196,12 @@ static int grubenv_write(struct grubenv_t *grubenv) strncpy(buf, GRUBENV_HEADER, strlen(GRUBENV_HEADER) + 1); LIST_FOREACH(grubvar, &grubenv->vars, next) { - llen = strlen(grubvar->key) + strlen(grubvar->value) + 2; + char *key = dict_entry_get_key(grubvar); + char *value = dict_entry_get_value(grubvar); + + llen = strlen(key) + strlen(value) + 2; /* +1 for null termination */ - snprintf(line, llen + 1, "%s=%s\n", grubvar->key, - grubvar->value); + snprintf(line, llen + 1, "%s=%s\n", key, value); strncat(buf, line, llen); } @@ -237,11 +241,7 @@ cleanup: * allocation */ static inline void grubenv_close(struct grubenv_t *grubenv) { - struct dict_entry *grubvar; - - LIST_FOREACH(grubvar, &grubenv->vars, next) { - dict_remove(&grubenv->vars, grubvar->key); - } + dict_drop_db(&grubenv->vars); } /* I feel that '#' and '=' characters should be forbidden. Although it's not diff --git a/corelib/installer.c b/corelib/installer.c index e5bf895..f778d8b 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -206,11 +206,12 @@ static int prepare_boot_script(struct swupdate_cfg *cfg, const char *script) return -1; LIST_FOREACH(bootvar, &cfg->bootloader, next) { - if (!bootvar->key || !bootvar->value) + char *key = dict_entry_get_key(bootvar); + char *value = dict_entry_get_value(bootvar); + + if (!key || !value) continue; - snprintf(buf, sizeof(buf), "%s %s\n", - bootvar->key, - bootvar->value); + snprintf(buf, sizeof(buf), "%s %s\n", key, value); if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { TRACE("Error saving temporary file"); ret = -1; diff --git a/corelib/swupdate_dict.c b/corelib/swupdate_dict.c index 2cdad47..be21ff2 100644 --- a/corelib/swupdate_dict.c +++ b/corelib/swupdate_dict.c @@ -2,6 +2,9 @@ * (C) Copyright 2016 * Stefano Babic, DENX Software Engineering, sbabic@denx.de. * + * Copyright (C) 2018 Weidmüller Interface GmbH & Co. KG + * Stefan Herbrechtsmeier + * * SPDX-License-Identifier: GPL-2.0-or-later */ @@ -19,7 +22,52 @@ #include "util.h" #include "swupdate_dict.h" -static struct dict_entry *get_entry(struct dict *dictionary, char *key) +static int insert_list_elem(struct dict_list *list, const char *value) +{ + struct dict_list_elem *elem = (struct dict_list_elem *)malloc(sizeof(*elem)); + + if (!elem) + return -ENOMEM; + + memset(elem, 0, sizeof(*elem)); + elem->value = strdup(value); + + LIST_INSERT_HEAD(list, elem, next); + + return 0; +} + +static void remove_list_elem(struct dict_list_elem *elem) +{ + LIST_REMOVE(elem, next); + free(elem->value); + free(elem); +} + +static void remove_list(struct dict_list *list) +{ + struct dict_list_elem *elem; + + LIST_FOREACH(elem, list, next) { + remove_list_elem(elem); + } +} + +static struct dict_entry *insert_entry(struct dict *dictionary, const char *key) +{ + struct dict_entry *entry = (struct dict_entry *)malloc(sizeof(*entry)); + if (!entry) + return NULL; + + memset(entry, 0, sizeof(*entry)); + entry->key = strdup(key); + + LIST_INSERT_HEAD(dictionary, entry, next); + + return entry; +} + +static struct dict_entry *get_entry(struct dict *dictionary, const char *key) { struct dict_entry *entry; @@ -31,72 +79,92 @@ static struct dict_entry *get_entry(struct dict *dictionary, char *key) return NULL; } -int dict_insert_entry(struct dict *dictionary, char *key, char *value) +static void remove_entry(struct dict_entry *entry) { - struct dict_entry *entry = (struct dict_entry *)malloc(sizeof(*entry)); + LIST_REMOVE(entry, next); + free(entry->key); + remove_list(&entry->list); + free(entry); +} +char *dict_entry_get_key(struct dict_entry *entry) +{ if (!entry) - return -ENOMEM; + return NULL; - memset(entry, 0, sizeof(*entry)); - entry->key = strdup(key); - entry->value = strdup(value); + return entry->key; +} - LIST_INSERT_HEAD(dictionary, entry, next); +char *dict_entry_get_value(struct dict_entry *entry) +{ + if (!entry || !LIST_FIRST(&entry->list)) + return NULL; - return 0; + return LIST_FIRST(&entry->list)->value; } -char *dict_get_value(struct dict *dictionary, char *key) +struct dict_list *dict_get_list(struct dict *dictionary, const char *key) { struct dict_entry *entry = get_entry(dictionary, key); if (!entry) return NULL; - return entry->value; + return &entry->list; } -int dict_set_value(struct dict *dictionary, char *key, char *value) +char *dict_get_value(struct dict *dictionary, const char *key) { struct dict_entry *entry = get_entry(dictionary, key); - /* - * Set to new value if key is already in - * dictionary - */ - if (entry) { - LIST_REMOVE(entry, next); - free(entry); - } + if (!entry) + return NULL; - return dict_insert_entry(dictionary, key, value); + return dict_entry_get_value(entry); } -void dict_remove_entry(struct dict_entry *entry) +int dict_insert_value(struct dict *dictionary, const char *key, const char *value) { - LIST_REMOVE(entry, next); - free(entry->key); - free(entry->value); - free(entry); + struct dict_entry *entry = get_entry(dictionary, key); + + if (!entry) { + entry = insert_entry(dictionary, key); + if (!entry) + return -ENOMEM; + } + + return insert_list_elem(&entry->list, value); } -void dict_remove(struct dict *dictionary, char *key) +int dict_set_value(struct dict *dictionary, const char *key, const char *value) { + struct dict_entry *entry = get_entry(dictionary, key); + + if (entry) + remove_entry(entry); + entry = insert_entry(dictionary, key); + if (!entry) + return -ENOMEM; + + return insert_list_elem(&entry->list, value); +} + +void dict_remove(struct dict *dictionary, const char *key) +{ struct dict_entry *entry = get_entry(dictionary, key); if (!entry) return; - dict_remove_entry(entry); + remove_entry(entry); } void dict_drop_db(struct dict *dictionary) { - struct dict_entry *var; + struct dict_entry *entry; - LIST_FOREACH(var, dictionary, next) { - dict_remove_entry(var); + LIST_FOREACH(entry, dictionary, next) { + remove_entry(entry); } } diff --git a/handlers/swuforward_handler.c b/handlers/swuforward_handler.c index c804628..8b0c17f 100644 --- a/handlers/swuforward_handler.c +++ b/handlers/swuforward_handler.c @@ -292,7 +292,7 @@ static int install_remote_swu(struct img_type *img, struct hnd_priv priv; struct curlconn *conn; int ret, still_running = 0; - struct dict_entry *url; + struct dict_list_elem *url; struct curl_slist *headerlist; CURLMsg *msg = NULL; @@ -320,16 +320,9 @@ static int install_remote_swu(struct img_type *img, priv.maxwaitms = MAX_WAIT_MS; priv.size = img->size; - /* - * Parse handler properties to get URLs for destination - * - */ - LIST_FOREACH(url, &img->properties, next) { + LIST_FOREACH(url, dict_get_list(&img->properties, "url"), next) { char curlheader[SWUPDATE_GENERAL_STRING_SIZE + strlen(CUSTOM_HEADER)]; - if (!url->key || !url->value || strcmp(url->key, "url")) - continue; - conn = (struct curlconn *)calloc(1, sizeof(struct curlconn)); if (!conn) { ERROR("FAULT: no memory"); diff --git a/include/swupdate_dict.h b/include/swupdate_dict.h index 2cae5ca..82988ac 100644 --- a/include/swupdate_dict.h +++ b/include/swupdate_dict.h @@ -10,19 +10,29 @@ #include +struct dict_list_elem { + char *value; + LIST_ENTRY(dict_list_elem) next; +}; + +LIST_HEAD(dict_list, dict_list_elem); + struct dict_entry { char *key; - char *value; + struct dict_list list; LIST_ENTRY(dict_entry) next; }; LIST_HEAD(dict, dict_entry); -char *dict_get_value(struct dict *dictionary, char *key); -int dict_set_value(struct dict *dictionary, char *key, char *value); -int dict_insert_entry(struct dict *dictionary, char *key, char *value); -void dict_remove(struct dict *dictionary, char *key); -void dict_remove_entry(struct dict_entry *entry); +char *dict_entry_get_key(struct dict_entry *entry); +char *dict_entry_get_value(struct dict_entry *entry); + +struct dict_list *dict_get_list(struct dict *dictionary, const char *key); +char *dict_get_value(struct dict *dictionary, const char *key); +int dict_set_value(struct dict *dictionary, const char *key, const char *value); +int dict_insert_value(struct dict *dictionary, const char *key, const char *value); +void dict_remove(struct dict *dictionary, const char *key); void dict_drop_db(struct dict *dictionary); #endif diff --git a/parser/parser.c b/parser/parser.c index 04cd549..2e9208d 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -162,7 +162,7 @@ static void add_properties(parsertype p, void *node, struct img_type *image) key, value ); - if (dict_insert_entry(&image->properties, key, value)) + if (dict_insert_value(&image->properties, key, value)) ERROR("Property not stored, skipping..."); } diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index c84de65..02ffb3a 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -1336,7 +1336,10 @@ int get_target_data_length(void) struct dict_entry *entry; LIST_FOREACH(entry, &server_hawkbit.configdata, next) { - len += strlen(entry->key) + strlen(entry->value) + strlen (" : ") + 6; + char *key = dict_entry_get_key(entry); + char *value = dict_entry_get_value(entry); + + len += strlen(key) + strlen(value) + strlen (" : ") + 6; } return len; @@ -1367,17 +1370,20 @@ server_op_res_t server_send_target_data(void) char *keyvalue = NULL; LIST_FOREACH(entry, &server_hawkbit.configdata, next) { + char *key = dict_entry_get_key(entry); + char *value = dict_entry_get_value(entry); + if (ENOMEM_ASPRINTF == asprintf(&keyvalue, config_data, ((first) ? ' ' : ','), - entry->key, - entry->value)) { + key, + value)) { ERROR("hawkBit server reply cannot be sent because of OOM.\n"); result = SERVER_EINIT; goto cleanup; } first = false; - TRACE("KEYVALUE=%s %s %s", keyvalue, entry->key, entry->value); + TRACE("KEYVALUE=%s %s %s", keyvalue, key, value); strcat(configData, keyvalue); free(keyvalue); From patchwork Wed Jan 17 14:34:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 862292 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::23e; helo=mail-lf0-x23e.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbt567xjakgqef7ledgi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="J8N22zP5"; dkim-atps=neutral Received: from mail-lf0-x23e.google.com (mail-lf0-x23e.google.com [IPv6:2a00:1450:4010:c07::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 3zM8lj69Rtz9s71 for ; Thu, 18 Jan 2018 01:36:01 +1100 (AEDT) Received: by mail-lf0-x23e.google.com with SMTP id q6sf6154869lfi.23 for ; Wed, 17 Jan 2018 06:36:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516199759; cv=pass; d=google.com; s=arc-20160816; b=b6NiSOXE4hJSwXG/22dStZ5TYmdv62zkd4Ubw0Kjr/6noUtv/ES7OutBA+NqI4ipoo pJGN/pVzb4qQV+OfA+0geOUAPwCQnve40XzDZ+9huRtq7HzjSI8MZS8qSgck1J8GLNkM JnvPsvYaj6iamNxlS94hAK/OlLspiJedDanSkgPUCjd0zVwS+f4RjiXcWfkNoM8Tqmu9 ONdZGebEWA89m+CtmKo56qyPmHfihMQAw+Dlp4eMwz8r7nKacjlHoO4ItSMAH7eoh39S NRrbynXW0AokGQbvX9rZEMNYqkzK45+8jn5+4hCkxDKvIFeA7s917tm99IU2mwN9j7gx HzLQ== 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=wNU5b920Ltrci4G4YqkX/4DbCIBVKzfjxtbC85tJG4w=; b=GtLt6zcbaYPuB1HI933R4r6pj+mLmBYAObUTi5GDJfNqFWwQeDTvZ2H1EMKBJdINP5 sMHJo/S/2NYFsSo/vKi6neBMhPXvUfL/X5OQRAVALKaX5TXZl5UUGTzNoePt1Fz8Nllu 2pVOXTeY4PALlj+OFe0AQFzhVxcXVLKOPUbgFOeG/4SKgIqp56lslvXNQ7uApvxuX59L OvHtPcaSTFyZ1p0so7Qm3PIroEei7cQ4pQbiidSIPCtJD3TPgAMiXybuAV62wS5cBSVk IG7LfvoBSZ1rKCFbapa/gOM+ncRV++9zQ3KQLURnQG9Z6NQHx4XCGqcOikT0PgSnIrhO mD9g== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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=wNU5b920Ltrci4G4YqkX/4DbCIBVKzfjxtbC85tJG4w=; b=J8N22zP5lTPAfcjVhz/qB1amTaWy3ThslBi7udoyRokss+x2rtb3pvHcOzNEXzlB87 YNsnHwNYOZ35luQdqLBJ2enXba2rF3OKPBFLvR4iOyC6vESZVTeboA7HMz3EzheqtGvy jTdO4lswcpk1PXet8EfpK744daoOBHm791VfQL3SiMl1OM9PO7bbCRTmmuJ6D0wmEKck LBvxsOfpvA+04BjZ0cuiTy3pLys2tqeNscugx8JQNAa4BcAXl/Vgn23N7u+37e414UWX dkJIw2cfNvQmCm4DjNbiCkZ9MCPn92U/VJwj3dqm9xDHJZIwog8fBMZduaheq0igCDSy 1uYQ== 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=wNU5b920Ltrci4G4YqkX/4DbCIBVKzfjxtbC85tJG4w=; b=mUbzia5/yDLklR7A1GPZlWxUJ96kq41hIFpqllUbEtUp0fwUtlQrYOqfAyluu98v4y URDP1Z2xNcOvn3yVkuhrsJ6UqmowIFNaOCLklPVaIwwkA4ZGLBGJyEnDKh9fNW8Rrb2U rp1iKXb4+SDRp3EoWYmu1awujOWAfAqZoLVGprYX/CWrGsLX4lid/bFxfMG/9VqkNCtm P3k85N51zdgWFsoGM+8BNOk9WMIRIwEnkdSbV4QZAvb2viRGsJebQiXTMUxgDbu5vloj ajXvMYSL24fFVaF21e4rbgimH5gZYfjdrdRddfeiU6YLvY1NKdFmnBRmAzrylgDR+5Hd Enyg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytcaXWY9C6xY1yS2e28IcPU9Bm9Ibze8xn9UMRHG45HdNUaehttG nkPlXl5Jc/du2JoOEH7JqJE= X-Google-Smtp-Source: ACJfBov6Xv9jA3OJjiLI6YmKt2LRRyJRJbyrnaNVEUxzqnA09jMsY3CbPrjAr2Fl9Ab9cmtnl5roEQ== X-Received: by 10.25.24.166 with SMTP id 38mr52436lfy.7.1516199759143; Wed, 17 Jan 2018 06:35:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.34.1 with SMTP id i1ls718908lji.14.gmail; Wed, 17 Jan 2018 06:35:58 -0800 (PST) X-Received: by 10.46.69.136 with SMTP id s130mr806052lja.10.1516199758578; Wed, 17 Jan 2018 06:35:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516199758; cv=none; d=google.com; s=arc-20160816; b=zOQKVTtk/S6WlBDkC9HOl6UdckK1kSDNUbGXij0pfoI+dVmFLjZBfrDVot59mvK1sK 5JSNtES29nNjsa93j770BcpI83L8nZKoFEcC9tXK9AA+W55xJ9FgRMrdiI+3DomgbB67 jZmFRlHfPyndGlIYm0K49M2TrwLg+qpfNQ/z7c+r9RNVxHtL1T4QNFstB22As8TycTz6 GOeVKPLu3lwej7uMRdLVHx4P7R9bYtUmXxRpkA7AvL8M1FMdWxLiHMIcmLt2tiRSwWgd iJuRy6SOvIx4tGDwoGVD27vHsXBBkX2xr3krTGSbJX0I/liXf1nV8zh7IB7uIQKOiT+E 01+Q== 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=ENgOEF5SUss0l9joEwkGxuVhtq2DXMyonz7/KlZh7L0=; b=rW7GPLPG1XnRvF0ExfAa2hDr4DM9QGQDZC4EcAyzI+W4fboz0aek0YbUWiDwhMjwwX y8v2obpmtJ81H97PixHmxs1uo/fA8kNMTciiQvlbiDGkL7Kt0jjdgn5qs5KM2Ky3QN3G bmYWjOFc/zg8LXD85GBw1oyVFSfKWa8HBouIUOyvbhKMsP62q12Gf4O/JdtlKuiByqtg m28HyFqCKSED+I5ilHi3pw34BkqaN2YZbNCKT9rXcASx/ao1OY89JQkwcZ+28j3BOJ58 5lkOa39QDicGvuS2uIuveQAqCpgEsE/SjxMBWlEgCTgwzrWaUxnzSblR7RlrBwVtqP66 XTfw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Received: from dd41138.kasserver.com (dd41138.kasserver.com. [85.13.157.12]) by gmr-mx.google.com with ESMTPS id b10si451244lfe.4.2018.01.17.06.35.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:35:58 -0800 (PST) Received-SPF: neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) client-ip=85.13.157.12; Received: from WS08941.weidmueller.com (unknown [217.244.7.16]) by dd41138.kasserver.com (Postfix) with ESMTPSA id 84BB311A0698; Wed, 17 Jan 2018 15:35:57 +0100 (CET) From: stefan@herbrechtsmeier.net To: swupdate@googlegroups.com Cc: Stefan Herbrechtsmeier Subject: [swupdate] [PATCH v2 3/5] parser: Replace properties array with a group of properties Date: Wed, 17 Jan 2018 15:34:04 +0100 Message-Id: <1516199646-5607-3-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> References: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> X-Original-Sender: stefan@herbrechtsmeier.net X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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: , From: Stefan Herbrechtsmeier Signed-off-by: Stefan Herbrechtsmeier Reviewed-by: Stefano Babic Tested-by: Stefano Babic --- Changes in v3: - Suppress build warning if libconfig or libjson are disabled - Suppress build warning if both libconfig and libjson are disabled - Update the documentation of the SWU forwarder - Add an array to the documentation example of SWU forwarder Changes in v2: - Check name and value inside add_properties_cb function to skip NULL values - Add support for properties with value arrays corelib/parsing_library.c | 16 ++++++++++++++++ corelib/parsing_library_libconfig.c | 24 ++++++++++++++++++++++++ corelib/parsing_library_libjson.c | 31 +++++++++++++++++++++++++++++++ doc/source/handlers.rst | 12 +++++------- include/parselib.h | 9 +++++++++ parser/parser.c | 35 +++++++++++++++-------------------- 6 files changed, 100 insertions(+), 27 deletions(-) diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index 5d30f2d..767d30d 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -62,6 +62,22 @@ void *get_child(parsertype p, void *e, const char *name) return NULL; } +void iterate_field(parsertype p, void *e, iterate_callback cb, void *data) +{ + switch (p) { + case LIBCFG_PARSER: + iterate_field_libconfig(e, cb, data); + break; + case JSON_PARSER: + iterate_field_json(e, cb, data); + break; + default: + (void)e; + (void)cb; + (void)data; + } +} + 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 0664712..415116b 100644 --- a/corelib/parsing_library_libconfig.c +++ b/corelib/parsing_library_libconfig.c @@ -47,6 +47,30 @@ void *get_child_libconfig(void *e, const char *name) return config_setting_get_member(e, name); } +void iterate_field_libconfig(config_setting_t *e, iterate_callback cb, void *data) +{ + config_setting_t *entry, *elem; + const char *str; + int i, j; + + if (!cb) + return; + + for (i = 0; i < config_setting_length(e); i++) { + entry = config_setting_get_elem(e, i); + if (!config_setting_length(entry)) { + str = config_setting_get_string(entry); + cb(entry->name, str, data); + } else { + for (j = 0; j < config_setting_length(entry); j++) { + elem = config_setting_get_elem(entry, j); + str = config_setting_get_string(elem); + cb(entry->name, str, data); + } + } + } +} + 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 844aca9..e24d1e9 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -51,6 +51,37 @@ void *get_child_json(json_object *e, const char *path) return node; } +void iterate_field_json(json_object *e, iterate_callback cb, void *data) +{ + json_object *subnode; + const char *str; + int i; + + if (!cb || json_object_get_type(e) != json_type_object) + return; + + json_object_object_foreach(e, key, node) { + switch (json_object_get_type(node)) { + case json_type_string: + str = json_object_get_string(node); + cb(key, str, data); + break; + case json_type_array: + for (i = 0; i < json_object_array_length(node); i++) { + subnode = json_object_array_get_idx(node, i); + if (json_object_get_type(subnode) != json_type_string) + continue; + + str = json_object_get_string(subnode); + cb(key, str, data); + } + break; + default: + break; + } + } +} + const char *get_field_string_json(json_object *e, const char *path) { const char *str; diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 74bf94a..a27647f 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -321,8 +321,8 @@ 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 general SWU can contain embedded SWU images as single artifacts, and the SWU handler will forward it to the devices listed in the description 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 handler can have a single "url" properties entry with an array of urls. 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. @@ -340,9 +340,7 @@ the SWU forwarder: filename = "image.swu"; type = "swuforward"; - properties: ( - { - name = "url"; - value = "http://192.168.178.41:8080"; - }); + properties: { + url = ["http://192.168.178.41:8080", "http://192.168.178.42:8080"]; + }; }); diff --git a/include/parselib.h b/include/parselib.h index e189751..f53dd00 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -15,6 +15,9 @@ typedef enum { JSON_PARSER } parsertype; +typedef void (*iterate_callback)(const char *name, const char *value, + void *data); + #ifdef CONFIG_LIBCONFIG #include #define LIBCONFIG_VERSION ((LIBCONFIG_VER_MAJOR << 16) | \ @@ -26,6 +29,8 @@ 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); +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); #else @@ -35,6 +40,7 @@ const char *get_field_string_libconfig(config_setting_t *e, const char *path); #define find_node_libconfig(cfg, field, swcfg) (NULL) #define get_field_string_libconfig(e, path) (NULL) #define get_child_libconfig(e, name) (NULL) +#define iterate_field_libconfig(e, cb, data) { } #define get_field_cfg(e, path, dest) #endif @@ -45,6 +51,7 @@ 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); +void iterate_field_json(json_object *e, iterate_callback cb, void *data); 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, @@ -56,6 +63,7 @@ char *json_get_data_url(json_object *json_root, const char *key); #define find_node_json(a, b, c) (NULL) #define get_field_string_json(e, path) (NULL) #define get_child_json(e, name) (NULL) +#define iterate_field_json(e, cb, data) { } #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) @@ -70,6 +78,7 @@ void get_field_string_with_size(parsertype p, void *e, const char *path, 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 iterate_field(parsertype p, void *e, iterate_callback cb, void *data); 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); diff --git a/parser/parser.c b/parser/parser.c index 2e9208d..f07559d 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -140,32 +140,27 @@ 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) +static void add_properties_cb(const char *name, const char *value, void *data) { + struct img_type *image = (struct img_type *)data; - void *properties, *prop; - int count, i; + if (!name || !value) + return; + + TRACE("\t\tProperty %s: %s", name, value); + if (dict_insert_value(&image->properties, (char *)name, (char *)value)) + ERROR("Property not stored, skipping..."); +} + +static void add_properties(parsertype p, void *node, struct img_type *image) +{ + void *properties; 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_value(&image->properties, key, value)) - ERROR("Property not stored, skipping..."); + TRACE("Found properties for %s:", image->fname); - } + iterate_field(p, properties, add_properties_cb, image); } } From patchwork Wed Jan 17 14:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 862293 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+bncbdn7dbh5yqibbwv67xjakgqe57maesy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="LeNf9pfE"; 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 3zM8lx1V9Jz9s71 for ; Thu, 18 Jan 2018 01:36:12 +1100 (AEDT) Received: by mail-wr0-x238.google.com with SMTP id h38sf6721051wrh.11 for ; Wed, 17 Jan 2018 06:36:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516199770; cv=pass; d=google.com; s=arc-20160816; b=d036MKbmNm2lvpl24fnxuuU5DTv42FRDvCrDtNwYNdxgWW8R4L7AZ4aDauNAQzdS45 RMqd31boUZSWNPoupXhyF4JBWL2FqCsbvvcJMwYOezjI5QYlm21VDg/1iFhAal07sU7R MCAvuSvcTiFHggzWa9N4oGT63+aV4jhsJWXxWKnjn1G9x5Fe3Q0MB6mQKgO5AG6Ie8lV DX1QftE2xTPre6GbyOsQwWbEppw/VTXVJi70oqXke1Effe8sgQk0Xc2SoxCabuRVAX8H 1Q5wNhZaTOd2tEApxkNF7R13Rc3UcQpOZbyC9JgpdZpLdH1PenAFmWe/GyhpjFShBPIR 8ZTw== 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=FLYSDCWXwnv7MBvU9SOBytJXsj9egOascOCu9xKIv6s=; b=wwaY7R840NTBLMsmsxEW0qTBmmQhMHk2DQhLj98L4mV9PNxTjfkNAcCx7H+7cK6vqA QLzLVhe9rJfHqmBsr5UAcqTVbeTv29zKd9yOM48OllkwzbVWogI8kViWPk4ZUHqEu8km BTdHYs8ieLuT78IbVOOAwoDA4ORJLrGsLmK4AH7Qe/GGuWFs2lx1fIdu/oyKCdEchJiN I255Urqz5Lwm4V1cribM/5kmGq65rj3paGMQfwE9tSHVxcndq+yFmMr1Xp7ut+Kl5eaK OkZBS0Scf6Ob387kfU4U5dos4J66tt9uDQJIJXm0KS2lvGoxs+PgFGXvaRgBfMI2+FEl uKpQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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=FLYSDCWXwnv7MBvU9SOBytJXsj9egOascOCu9xKIv6s=; b=LeNf9pfEcgZjSgv4/f9khSvkkPSv5GFwZk2XwEjr/6a6Be1iyY3Xp+GsXH7+3ycAdW dfswO3NNE4vlXIlMc0Kc4nEMQRAZk3kB3fCElL3cjjyhHXM4dHhWJ4ha4LPe5rDh61F2 jsifL1FvC/QIUudkwiVohFchewsj4593oId/oiUCC10ynsFP51QBJm+FeM9NXjbykMIZ mi/XNpjJtSBUz4Frfyuqn0Jr+BPst+lu6nCGMYJYLLpvs1fd+lf+q6KWfrovn6qKMIcP m9+5V1rPwnmJHAC+Wah3SMd8LmFn007Arqio7GeTbfYiYIxexufe+eeppCKzMjiQzJgE DZ0w== 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=FLYSDCWXwnv7MBvU9SOBytJXsj9egOascOCu9xKIv6s=; b=G+0jyjCszZXVCfNSjO64Y1CXXgyf8/7Qu8i/kHygx+Dxgglf+C4gX0bjY6v8Fsebj1 86hbdKrokxiygF5IA4s6fNu/w9sLq8aAqLCCpN/b1IYACj+OfIJcwAP+gUOl9aDa5k2J 1uP/N2g8IpGIqXhmgkGFaIgYTMu/OU/CtzsKfAO9ZuJ/0/ZG7OBNTgl20y5JKJX6wkbq vc1nuPK6VDJdu065peFjpNvbrS5x8asuDKrWk2+oMZvHgHrFUNc8hNWU+HBFaGWIKRcM i3/0o/knftVO53279zL7aFcogl5SjmcDwYEgwnI4qt9EYcBJIHGHHA9/hhyGEkneZUdG IPNQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytfwVtGgEs7aRgpb540YM+tCj0bXlIbiAjp8Eu4WSZ0ywYkAud3+ vO/AhyfpwCb7sadPKqCbzfg= X-Google-Smtp-Source: ACJfBosDbnH+efx4YhUie8Qmr30qh9n2p2zFPULcxz+vzE8LDhP2oqdEvOndM5MMxanL/YnhnVRffA== X-Received: by 10.28.197.195 with SMTP id v186mr35066wmf.6.1516199770311; Wed, 17 Jan 2018 06:36:10 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.146.66 with SMTP id 60ls1699700wrj.9.gmail; Wed, 17 Jan 2018 06:36:09 -0800 (PST) X-Received: by 10.28.101.86 with SMTP id z83mr290886wmb.31.1516199769721; Wed, 17 Jan 2018 06:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516199769; cv=none; d=google.com; s=arc-20160816; b=JG89jhpauu7kKwhExkYhDMjJneDm3ZUQ+oLSCtOUSyzDiYQODNR1/zbbC/GY/SSICF xiV4PUJoRZZo0v36gZBZ6EKrjd0KpLpajX1l1893Z7TnfvwpQwguAQJdLizUHno+kWmP Xc1yYGR9gszrBf9GpeyDbWN8/5Z1TZlC0N9Eu6dp/jFw2xEtukzlWuQonlGa3xJn5SCv lKqB1KY9yjP5pIE84JY7gUewtqSuN+ewygApzPPgWY3+l7mHCut6Ayhp3DH21gIClf+u 49scnhIrRdiIHhCa5LBEpWiWmwQd9jJm0hRLoD7evE2fJOSNWG9xdGbkuYL4aoNZOjs8 4UmA== 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=jXAhyAWJEaVGAI0yyJ8gPyMidGVYyTgXNv8v065crVo=; b=NcPlGP8KeAJqTEsS3x6TBG+mYidhQo/6LFvd/qhh5qyyyjt70fpiQ7dp+znO+FWFDO h4T8qahaDU3G7gHWc4QfYwsB2tEeXqsIZg9ZJXNl9DJDMsQWOZ4532SVtmuR/+m0/hax NmIkO8SdDRSV8YDUJG1Zdks5mM2gN+qT5Qe/xfW4U6T/UI7YqrknMz37T6jIaxPHGlRY eT0Wmr/0wWflF5x5zvorawhT8L4QwVKO+FEoH7uxGWaBbSKlSnIzVV+bGQEyMXNO7pLm 1QvWJ8xdwQTbOPdJWZb2OoMOXrkvgIpKqik20uTvZ2JKsfJQg4etsV2cMN2mBNK2oyQK znVw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Received: from dd41138.kasserver.com (dd41138.kasserver.com. [85.13.157.12]) by gmr-mx.google.com with ESMTPS id v10si647190wrv.5.2018.01.17.06.36.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:36:09 -0800 (PST) Received-SPF: neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) client-ip=85.13.157.12; Received: from WS08941.weidmueller.com (unknown [217.244.7.16]) by dd41138.kasserver.com (Postfix) with ESMTPSA id 53C2311A0698; Wed, 17 Jan 2018 15:36:09 +0100 (CET) From: stefan@herbrechtsmeier.net To: swupdate@googlegroups.com Cc: Stefan Herbrechtsmeier Subject: [swupdate] [PATCH v2 4/5] Lua: Dump tables in Lua stack recursive Date: Wed, 17 Jan 2018 15:34:05 +0100 Message-Id: <1516199646-5607-4-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> References: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> X-Original-Sender: stefan@herbrechtsmeier.net X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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: , From: Stefan Herbrechtsmeier Signed-off-by: Stefan Herbrechtsmeier --- Changes in v3: - Replace -1 by ENOMEM_ASPRINTF define - Move declarations into the required blocks Changes in v2: None corelib/lua_interface.c | 89 +++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 36 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index b617f61..6b92cf0 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -61,6 +61,52 @@ static bool is_type(lua_State *L, uintptr_t type) } #endif +static void lua_dump_table(lua_State *L, char *str) +{ + /* Stack: table, ... */ + lua_pushnil(L); + /* Stack: nil, table, ... */ + while (lua_next(L, -2)) { + /* Stack: value, key, table, ... */ + lua_pushvalue(L, -2); + /* Stack: key, value, key, table, ... */ + switch(lua_type(L, -2)) { + case LUA_TSTRING: + case LUA_TNUMBER: + TRACE("%s %s = %s", str, + lua_tostring(L, -1), + lua_tostring(L, -2)); + break; + case LUA_TFUNCTION: + TRACE("%s %s()", str, + lua_tostring(L, -1)); + break; + case LUA_TTABLE: { + char *s; + + if (asprintf(&s, "%s %s:", str, lua_tostring(L, -1)) != ENOMEM_ASPRINTF) { + lua_pushvalue(L, -2); + lua_dump_table(L, s); + lua_pop(L, 1); + free(s); + } + break; + } + case LUA_TBOOLEAN: + TRACE("%s %s = %s", str, + lua_tostring(L, -1), + (lua_toboolean(L, -2) ? "true" : "false")); + break; + default: + TRACE("%s %s = ", str, + lua_tostring(L, -1)); + } + lua_pop(L, 2); + /* Stack: key, table, ... */ + } + /* Stack: table, ... */ +} + void LUAstackDump(lua_State *L) { int top = lua_gettop(L); @@ -84,43 +130,14 @@ void LUAstackDump(lua_State *L) break; } case LUA_TTABLE: { - lua_pushvalue(L, -1); - lua_pushnil(L); - /* Stack: nil, table */ - while (lua_next(L, -2)) { - /* Stack: value, key, table */ - lua_pushvalue(L, -2); - /* Stack: key, value, key, table */ - switch(lua_type(L, -2)) { - case LUA_TSTRING: - case LUA_TNUMBER: - TRACE("(%d) [table ] %s = %s", i, - lua_tostring(L, -1), - lua_tostring(L, -2)); - break; - case LUA_TFUNCTION: - TRACE("(%d) [table ] %s()", i, - lua_tostring(L, -1)); - break; - case LUA_TTABLE: - TRACE("(%d) [table ] %s ", i, - lua_tostring(L, -1)); - break; - case LUA_TBOOLEAN: - TRACE("(%d) [table ] %s = %s", i, - lua_tostring(L, -1), - (lua_toboolean(L, -2) ? "true" : "false")); - break; - default: - TRACE("(%d) [table ] %s = ", i, - lua_tostring(L, -1)); - } - lua_pop(L, 2); - /* Stack: key, table */ + char *s; + + if (asprintf(&s, "(%d) [table ]", i) != ENOMEM_ASPRINTF) { + lua_pushvalue(L, -1); + lua_dump_table(L, s); + lua_pop(L, 1); + free(s); } - /* Stack: table */ - lua_pop(L, 1); - /* Stack: */ break; } default: { From patchwork Wed Jan 17 14:34:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 862294 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+bncbdn7dbh5yqibbzv67xjakgqerb2b4cq@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="RIVb57/X"; 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 3zM8m93R1zz9s7f for ; Thu, 18 Jan 2018 01:36:25 +1100 (AEDT) Received: by mail-lf0-x239.google.com with SMTP id j185sf2517820lfe.13 for ; Wed, 17 Jan 2018 06:36:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1516199782; cv=pass; d=google.com; s=arc-20160816; b=kEswHgorucd3Nnyy8KebKlWUOJVqjtiWlQN17akYf2P7CFbR5AgPiZxlo/SBJrqagE JQo/7AXeLg3p4hZ/ibrPQzmUdjmDyoOLgF1o14YuIe0XS2gWpyq5IdzbNS4B/zsZbneK BUWrVVFZVbyxjtQL6Uh19FZX3evSBR7QSNulI7ZQyxIcTxSDlcrv9+T3l3FJq74iF24I uBDTtlHu58VkH0F30wlnQ9wki28H8J05eFA8dpzjcqWK6gR7bPMK+LApcDRXSZ712/b2 29tsllgxvsFyLhH3TGzeg4xWlJEKmMdjZMqwoc6+IRiy4chgvM/fN9IapuNOgB/ySOKe g3Ig== 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=UoaZ5rw5mQEhi0pfjCVQ5MLSQwkzOhDX6UD2+llpos4=; b=CGgekmbpYi1DMIO6lULNVu+9DVFUb41C0HgUln/DxWan9nrsM4RLkLviepyunzA6Tu 4i88ATn1lQXsmN8YGX/9tCTT1wQuRLNhhEVJIK2FAauVdC/7PxZfPe4uxyRGag4SPl28 fRucLi0voQcBKI+fRlaxDDZOLxo619dRgTqy+13bFHs3bVift7QBkiNq2IZU2kCXZe02 qflAsvB8JueN4g0Vm93avgOPAgv9YaMUCfyCvV31YFr43v5NdWc0ZAfMBJnEIH/jFq/W bfaK7CEnNM7iqUwjFq4MO7SqIh3I8juU5b3+OrXVkkIzeqWxmOD4G0CMQELg0+4frE/R ulxw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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=UoaZ5rw5mQEhi0pfjCVQ5MLSQwkzOhDX6UD2+llpos4=; b=RIVb57/X8oUMIi8cqcO15VZZJBxTGqvF9gzfmzBSmLzld7k/fctRvBBkK7kSxPF/hz ldpjperD+MFNhlLJi2tVm3k3BeW/BmnaLnBhZv3weNDfFEGN2tut0zwvMstW/CEDFoJd ABuWOPwR2gckawa1a/6BWYEVbMVlAlcZI2awkpt8qXkm47S+LbUjv4I/No8AaDQwUQZK se8MCfUReargBze+sBlmFAolORl0uMvcnkTIjOPef3EKKtlMxz9qOq8SrBB7hJBaW2q/ vqruUUcGN9+fPXh/UjD51tZPoKRzwmDfhgPy5UcguP2d8ho7DvfHv0493gHX5c0EOMso puvQ== 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=UoaZ5rw5mQEhi0pfjCVQ5MLSQwkzOhDX6UD2+llpos4=; b=A2PrjgiovfapTKrWAfcr7YCS14aW/y8Ajyb2Crtb4f8Jv/Z6TqT/N1/dnPhiUuZ5gU rUZgDBzgKr8kqffBh4cN7NMz8a7Gd6WPL51ADj5wUQtGCUq6mN86DzJTbUZnu72hLqtc hzxBZdkU4Q2YpP9oIlgxRdG2NyaHmUhqc5W+wV/QFWld+oKRSBbMGhDOtwVu4i5GQC77 H7HAFgs8ntU7xP6NJEmA8n8NQFIt2JVeCTfBhd1VHznbqo6milLM70kDASh3X9wXBaHH 3WqwOwoxYjI8Kxre7aEWn3WpGOl252r17o/vGMueqj56C903QzrcPKeMkmp8JYWdVZQA nBtg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytfi3wKikIoKpUibu3L2g5j6mRvWLiT59D20t4fQQXSEvbFJ16O7 QMug3C2/nJCEpOKTTCb0TQ4= X-Google-Smtp-Source: ACJfBotBK8KFVOB0Dds+czXS8Gu6h4a4H65947lwW2Y53/gPHBofRLG2f1OFj2EyJshmpRfJSd+7Dg== X-Received: by 10.25.190.68 with SMTP id o65mr22281lff.13.1516199782636; Wed, 17 Jan 2018 06:36:22 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.46.108.8 with SMTP id h8ls723623ljc.2.gmail; Wed, 17 Jan 2018 06:36:22 -0800 (PST) X-Received: by 10.25.225.213 with SMTP id l82mr912778lfk.3.1516199782055; Wed, 17 Jan 2018 06:36:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516199782; cv=none; d=google.com; s=arc-20160816; b=K1bicEO5A0bd8r0/Az3AiK9CjM7vy0VqLydp8wqyqZYxape8s9duqyHAFTSgvH8Bg3 4sOyygF3ayrBCD8NnYnXNu+1vwSYp3ED6A2Df0T3sDs+u19x9YJrbPU7d/Z6771v3Eou 4Fi+WOpVLwCn7rfWULmcMJ1kcrMaSG0N6gtutdGy2n9DI99oTnTjn5/Tp4+6M/jl/DD6 UbnGsxv0zzzT7Pi/tKHabeOXESr7+k898heRFQTkuN6aD3ImktxSFL5MX5f1LSSlOWmu Ruj20esqHXcI/fK3pwrX3N+Zy7aVgyRHD482OoOnPpvxf51eSxFfEtfPmwdQMCjJW4QX OL0w== 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=biambvGSpsMnodQaVwdVWotTOzzHDnQudQG8gTXQKbI=; b=XGj41AGIRfubIDjbLOwNgyrVFaRFYYd/o+YZXnapddQvWvPyMpgFz27NN61LGq1+aM lnwz9CThKFQv9g7H2Kg7FZxYqsf0P71weqYnWFERlTOug0eI76zTGtFnZHA7V0r7G+IR W5RXPklV7JcpJiTopj5AZJ3tV0J2S5axTGFj/JkZgZolZDZFIDjvTAzX275r6IoWtOi/ +AIjkVYpjVeBtDLU0PcBLoxykv1gwAUzkUfMJZeXzLyytFafV8bJ7uDDx5jX2DFqvhW0 w+PLBXGQHCmrqEIyGXv7EkhfwFrcnd/0nV82kbledgaHZ76LXgE/Sc3i/k/2GdlRfkW5 iEeA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net Received: from dd41138.kasserver.com (dd41138.kasserver.com. [85.13.157.12]) by gmr-mx.google.com with ESMTPS id y16si556524lje.2.2018.01.17.06.36.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 06:36:22 -0800 (PST) Received-SPF: neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) client-ip=85.13.157.12; Received: from WS08941.weidmueller.com (unknown [217.244.7.16]) by dd41138.kasserver.com (Postfix) with ESMTPSA id 5F68711A0698; Wed, 17 Jan 2018 15:36:21 +0100 (CET) From: stefan@herbrechtsmeier.net To: swupdate@googlegroups.com Cc: Stefan Herbrechtsmeier Subject: [swupdate] [PATCH v2 5/5] Lua: Forward image properties via table to scripts Date: Wed, 17 Jan 2018 15:34:06 +0100 Message-Id: <1516199646-5607-5-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> References: <1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net> X-Original-Sender: stefan@herbrechtsmeier.net X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 85.13.157.12 is neither permitted nor denied by best guess record for domain of stefan@herbrechtsmeier.net) smtp.mailfrom=stefan@herbrechtsmeier.net 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: , From: Stefan Herbrechtsmeier Signed-off-by: Stefan Herbrechtsmeier --- Changes in v3: - Move declarations into the required group Changes in v2: None corelib/lua_interface.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 6b92cf0..25d84e6 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -429,6 +429,8 @@ static int l_istream_read(lua_State* L) static void update_table(lua_State* L, struct img_type *img) { if (L && img) { + struct dict_entry *property; + luaL_checktype(L, -1, LUA_TTABLE); LUA_PUSH_IMG_STRING(img, "name", id.name); @@ -453,6 +455,28 @@ static void update_table(lua_State* L, struct img_type *img) LUA_PUSH_IMG_NUMBER(img, "size", size); LUA_PUSH_IMG_NUMBER(img, "checksum", checksum); + lua_pushstring(L, "properties"); + lua_newtable (L); + LIST_FOREACH(property, &img->properties, next) { + struct dict_list_elem *elem = LIST_FIRST(&property->list); + + lua_pushstring(L, dict_entry_get_key(property)); + if (LIST_NEXT(elem, next) == LIST_END(&property->list)) { + lua_pushstring(L, elem->value); + } else { + int i = 1; + + lua_newtable (L); + LIST_FOREACH(elem, &property->list, next) { + lua_pushnumber(L, i++); + lua_pushstring(L, elem->value); + lua_settable(L, -3); + } + } + lua_settable(L, -3); + } + lua_settable(L, -3); + #ifdef CONFIG_HANDLER_IN_LUA if (is_type(L, LUA_TYPE_HANDLER)) { lua_pushstring(L, "copy2file");