From patchwork Fri Jan 12 14:58:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 859992 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23e; helo=mail-wr0-x23e.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbj434pjakgqezepku7q@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="fbUyrS6M"; dkim-atps=neutral Received: from mail-wr0-x23e.google.com (mail-wr0-x23e.google.com [IPv6:2a00:1450:400c:c0c::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zJ5Xp35bYz9sNw for ; Sat, 13 Jan 2018 02:00:58 +1100 (AEDT) Received: by mail-wr0-x23e.google.com with SMTP id y18sf392411wrh.12 for ; Fri, 12 Jan 2018 07:00:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515769255; cv=pass; d=google.com; s=arc-20160816; b=bBFoeKik7yLa5Ei9EsfXuJPgQ98RNt9aBH6J0WXAJx25QXwNWhNJtbBiaxJ9dCZ0CP Gvn1ZvTBeZkA4insFj0axCVcAgmO+eiVvgf9G98lqcwHqmqnkMGR+BjjCOvnjsVoP37j El2GFqbhwEnFGQlxY0m7z9jghAXsKRaxroSA5epw26ZiggdHZre2k3YEqHPE1/TXPLJz nm8w4yGIzHO1qNTbjKqIfom6USp/5tgn7i7415iywUP9DrKmQw11KCRzAa6+cSTsjydC z0IMhX1qLX6LSmnY1sIirMIywUjI8BL8B5sBiYYCmkJoI/iaE3Iy5emN9Ajhi6jYmM/c jJ2Q== 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=SR8FuTfHyqU1WYLv8sPP9c+UoBE++MPjM2+w47Ie5KM=; b=EY3TyfUPnN4CeDLT8jbejK2E+wJmUgNSCZOcBOhA4P5UVpV1jm9dN/Rssd7kYh4+dR jLE9KA0NsS5wNlmafDZEKZOpy5VNMzVWBPW1AHRACkUzXlskUoVnyQghkSUEP/ZZniw+ lHvDtGw/kOo8nAh8xjU0SQdplYU5+P4i0ZvCN9b7LLPYKLdc6r4BJCvBP5Q4PEbJNUDA ZLiv5V+YRTJnuTejtU1D+7paQRBRgrDkpDcPtvmS3NsaMZdYbx+xmeCLPsVJMD8zjICI WGnU6HcrwksXBk+L+AH6mKKoFTrzeW9pKDqOm86YhrxP9NmCX8rkIdMqb4RtwIHSy1/D PJNw== 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=SR8FuTfHyqU1WYLv8sPP9c+UoBE++MPjM2+w47Ie5KM=; b=fbUyrS6MGz8L2NjGHF9xV6pFjFlpEvNqzH+IULrfAHh0yjf5pm8sW5GzfpKHWSx4vE Tt7OXRGHFxhFUEeUlRA45FsvEhIilSbgBJ9QZ3dul+OtQ/iatTJvJfySJo63bu0vUhbQ e6z4NMuT3JcQwa85t4Z5GrWIvYQLgGHYey2p0W9mF+O9wnin9T66Nt96/qyd+qXZT6Lx HRNmh5KSeurZYOhJVshCxAcFvs4EmBOSvwY3nx7xgFnT0NHytiqZE2MxakGA4zKS2qwQ oHBiI28BpTIqHxoKlJkMf4uvTd+JN6s3k6/tnramIGrwozQejK2jRQxml4X3WtYqtoOY qDpw== 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=SR8FuTfHyqU1WYLv8sPP9c+UoBE++MPjM2+w47Ie5KM=; b=DN70MUPQewF6AvwrqRTVyC5sOWQdZp9iMqRrHbcVe9dPY54dHAaT/VvH8CjZKH7WRa dh4MulCuvORs4g03UcK2FNV3l6trpvVLQa3Sm9Qd8Yx/2SvjiITCg+bv2zkk7j/XUjdb LLDRE7yMk+t+Z5dnMnnMuK7Xw7Ix/t3zhTc5vLfDpDKODSKx3GJCEWhAnVb7SIlezUSq +m5pW8+gxt0eaAQGxZAHEq5tGrMvPHwk5xjjJcUOHsREcIBIkpybEs6QGgyQQFsyzsEF gob42KSOCt3OlHVz8OT+n2a3tTb4RCRyfMHz6VY/EZwXIQEVvDz0rTHuWqvkAB9FUHz6 CPcA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytcUyARRtkkx4KZ1ALS1TA/VrfebB/Hb/2aNfmqC2eT01efx2JkW glS/V1ZiTtgLJILCWkwYpls= X-Google-Smtp-Source: ACJfBovHlZybt09cE4gD+yAUI6caUv6MlklVaaEqIVwLTl1sNC3MgEgST5ronmIVkSCSQPQTk88XhA== X-Received: by 10.28.111.219 with SMTP id c88mr54378wmi.3.1515769255343; Fri, 12 Jan 2018 07:00:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.223.130.75 with SMTP id 69ls1137040wrb.8.gmail; Fri, 12 Jan 2018 07:00:54 -0800 (PST) X-Received: by 10.28.202.26 with SMTP id a26mr322023wmg.1.1515769254772; Fri, 12 Jan 2018 07:00:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515769254; cv=none; d=google.com; s=arc-20160816; b=ya+xLodlc0sb0nPCNccDxCN2TFJSBfAiC7iwkIoyIasdHJ5bHnEaEhbGV8UC8rjP5T 6HBfumOwt1Q0yU718P1CNNWTAmCV1X2oYS8W8VZw+bFLDGF98wsei0TOVkSkm8ch1FZm UroQ1hLzFmC4EffyKebt1hvOg2j5ZBMevhr8/q190IViaMh8ebH9/nt2gWLlV4CZdvHT pdEngsiL0vVj+zSm+dlNIeBh3q4i2oizdOfgFh6v3blzXxGJtCHLjBc0eCspMB1N3o5e Ybu8rQUgMS+iLpz7WP/ldMoJW2JUN1JPq4bFs024AAfjMHrp85MdDztHHe6KqEr5baDf lF8g== 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=AyqifRD9BsibCiZ3jDP9xz8aHN1trWQoKONSTIyHuz8=; b=Dzo5b0lYHbnMsZG10v1/UujNWKxya81sehD/ejCQbxXPQZAv9ngiP9cPaUCYyt98MH 7NPM7ZMl2O1MfNwScqOjr+aq0lxaAmPhE7PU8ZCe9a0GQvXFEu7Hk4p/wK5MNTrFAxQ9 b42Itf85CjBYD8795lZTG12fZuHxEs0gK5ZzZoN6/NuSoQSUT2bsFzVbJm3wpDAG+DMw 5J6tihrZXsznEnZgjCh6ev28ILHs/6hkT4k0yCBH31K+EV8xrg/rbBSwEOiIbrQ8Tlqu u8NZXdcjUqT6X3VaVxR4gxLI6nTChC2DLH9UEHJkqVFcRFs/Gtrf7j43SS1v1D/Tqc8L x6LQ== 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 b4si877639wrf.4.2018.01.12.07.00.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 07:00:54 -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 EB2E411A033E; Fri, 12 Jan 2018 16:00:53 +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: Fri, 12 Jan 2018 15:58:44 +0100 Message-Id: <1515769128-29657-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 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 70bfef2..93682f0 100644 --- a/bootloader/grub.c +++ b/bootloader/grub.c @@ -125,7 +125,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 @@ -165,7 +165,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); @@ -206,9 +206,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); } @@ -252,7 +252,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); } } @@ -332,7 +332,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 d7b2195..6fde318 100644 --- a/bootloader/grub.h +++ b/bootloader/grub.h @@ -41,7 +41,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 fc3011e..e25c30c 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -218,10 +218,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 4c8fb44..352c13a 100644 --- a/corelib/swupdate_dict.c +++ b/corelib/swupdate_dict.c @@ -31,19 +31,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)); @@ -51,7 +51,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); @@ -59,7 +59,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); @@ -69,7 +69,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); @@ -88,12 +88,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); @@ -104,7 +104,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 61a3346..54aef4b 100644 --- a/handlers/swuforward_handler.c +++ b/handlers/swuforward_handler.c @@ -339,7 +339,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 b065f7e..2e79817 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -78,7 +78,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 */ @@ -134,7 +134,7 @@ struct swupdate_cfg { struct imglist images; struct imglist partitions; struct imglist scripts; - 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 d8edb63..f8b696f 100644 --- a/include/swupdate_dict.h +++ b/include/swupdate_dict.h @@ -24,18 +24,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 670c7ae..51ed32f 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -1348,7 +1348,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; @@ -1382,14 +1382,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 0655980..33f4afb 100644 --- a/suricatta/server_hawkbit.h +++ b/suricatta/server_hawkbit.h @@ -40,7 +40,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 Fri Jan 12 14:58:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 859994 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::238; helo=mail-lf0-x238.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbl434pjakgqe77forka@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="jXXwMkt5"; dkim-atps=neutral Received: from mail-lf0-x238.google.com (mail-lf0-x238.google.com [IPv6:2a00:1450:4010:c07::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 3zJ5Xy53Scz9t3G for ; Sat, 13 Jan 2018 02:01:06 +1100 (AEDT) Received: by mail-lf0-x238.google.com with SMTP id c184sf1560695lfc.17 for ; Fri, 12 Jan 2018 07:01:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515769263; cv=pass; d=google.com; s=arc-20160816; b=kTe3Q/nVbeQ7B/1hrI/N1q88JpWhzTUSbVeXKIBL84v+PKXPRcHg5UxkwKRbeV9Ivf C4oGldI8JAiY1enBy711H58ly3Wi5XgdkrOZG/PdSssLIp0dS1LkGSdiYIt7BJNvZX9w 4prIux3wh7kao1VF3ZcG/iNeM0B/K5J6qAp8J3EvVfyAuwoXdkfyJoPLEecaFYnzyb21 bL7ApGg4Qe7Wrrks11t8oi6Xaf3fYz1r1cq+n94IDGX6mLkn3HiO8bYGqT4N+6UTFnZD xB5rL9nFfg6E7ZS3z/CLzYQqqLGj6tZ/BfsBL5Zp6KRNJcNhy/0R4K+clDX3ibI1uC05 ec0g== 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=RQAKkxiOMKengnnn5/9doTOIyBZyDAg6wBdAakYUfS0=; b=sY3j3+/I2Fm9Xc4Y7UbrhbeAUGJ53aIHiDnnRh0OV8kRGm47VUkD4lzJ0w3Rqxk8VB TND4kcFz0uRbaq/cLNNyrxPEU8aOJD8Nmzeh3R26xtK8jBfoXwxYzZv7RMsmTf4hJrk1 kWdB7SkqXOY3AQkeAOQN4a5ucw8JyqDzMcCUwySOCYfZDqT24Z/GpyNH52mizbHpKHV/ MnHNJ43pfeWlaiipDCMwL3fWI8OGFK6UjJfaScDwPwY6moaZYgfH2OV7D92HFN2J68n5 gQeWebgxF9MdSDvBTtX4p/CV5PVz/D0b6k0wz0mWzj2U9ftNzIWSsqoEq2rGHUXBS6a0 pIlg== 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=RQAKkxiOMKengnnn5/9doTOIyBZyDAg6wBdAakYUfS0=; b=jXXwMkt5gi3Y1L55ZhSsSQbdU5DWq9GBPsND61ZBHhwU78qedON/HJs/Smw2/sVj9P uIo6oTsAp86MsxQ8qgHAKHj6U7PR5YlWmLBnmXSL5ASxuS8gZe1Bu52Q1j/s53ZWmb/Y eKWOnrsPOmkgS8kAsjFz5fkV/nIdB4jqQgVTmAHHh4qzDq6xMmX4Ml+YWsxoidARafz4 9TdddkzKnwsTFZMrFObjCBQOf0oJD1AZQCZ+PGdQdZLDHwDU7E4TpixgHdePAeni+0Fr v1GKOJg1+26tRgIkUylX1s2hdddw4UB7sSWgxke/nhQEyVIKb9M39yaXDvAyJlz3kbkF 67GA== 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=RQAKkxiOMKengnnn5/9doTOIyBZyDAg6wBdAakYUfS0=; b=mbVU7R4MYjF1lFeR2JNtZ4kLZqLn1pEA5PoR1whsJtZh+EqdIK3Iugk+DXJ/wlJedl F3oaXR6HfPfCLuJQgBIH+k+CdlE+Hm0qK7aQ/KkjzIf6Iw7DOK+LX6r+bAewqf3ZXdCT 6TsGkAQjnFIb2EwMtCGgICeZjI8qtthlAnu3SlSkH1j3f/qr9ZFvDVhnnPwADyqOQCXA uptboRN4RI4/w2BE55LT3wBFHoruIOIYRPzeh3EW7eUbJU71dmwOKMiNCsFMpLxL/BEZ BaTy3F4iMTgEr5T2WScNqs8zjeCmqubeIyZ1q6RtYjiITnQujdN8Oq5ERfeZ2hDvSAAb 6Q4Q== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKGB3mIOCG1ZtBnJ60Mjv3CQYalmM61DB97qU7vf4qaL6CJtYnRTSSQx gemP84ja7RTh1GNwijvu7Vk= X-Google-Smtp-Source: ACJfBotCsLuPwlyGFudpJCufKJxAzZgz15BUDRl83lmFHv8/hiXJnrBFQ8G9YfzLAbsJaINkSjhTLw== X-Received: by 10.46.44.8 with SMTP id s8mr67551ljs.6.1515769263764; Fri, 12 Jan 2018 07:01:03 -0800 (PST) X-BeenThere: swupdate@googlegroups.com Received: by 10.25.74.214 with SMTP id x205ls93203lfa.4.gmail; Fri, 12 Jan 2018 07:01:02 -0800 (PST) X-Received: by 10.46.91.199 with SMTP id m68mr1910870lje.42.1515769262690; Fri, 12 Jan 2018 07:01:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515769262; cv=none; d=google.com; s=arc-20160816; b=ZyqhvypJymNwgwPb1Qq/dgsOxSJPdBVpmBrsea0P94gs6/LD2dZ9pquGEaGQ71hTtK 50Gh+rCfXC32gr2Q0JjWnkoNzRAMaunYrVhWAYpefLqd7aB9JYAKT3OOCNmgzk6FpCnp A51rnn++3J1mssf6nOZHKJJ88xfD2msrlvgNl93C6kzKgsbs/nplgjv16uQmMCwIdIeH oO/uPpZlhxwtmTpYG6UgLwISLCjfPQvSRcB8TT8Cz/BYReDO76V7A40dQmqLKP6CIFkN 0UazI13F3IkEDRBaw+bGuvaDKFnhUu1chDnr8nMbc8V/Id10/67AmMlV1SgRycSqhrdJ wLfg== 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=Pj5R/Hn2ktr0vsS8b6FwtSp1SbMXy7xdBHW6YTXvcp4=; b=LwvLcLxg70S9AHOvtx9eUZFZsD/vgYcuk0fvsYLb9hqWkJfUtloY8+5wOMLwQVuG5s i6T7bu1FvzfWS3KiLD5rGNlq7uM1ihsLSWJb/KCDjet7g6BJPSZCSJMfn+vD9A74pXxQ MTAazBbpP4dsaPNuVgVi/SDbB6jSBia4q3vqTzPK3FPAkd8Z0HE5i1tJ9pbkk/O/omrh QJUVyUD9PHUcJWNcB4ZYnkVB3nuW+XnCX9bt7ra6B46Bg0xullKAZudFECXWx5vLrRTT jJNFIGGcOsz3ZnDL9OG8LXfZ2gtKmkO3w0/tE1YfIHa20nhXMWPG+5zs6u/+l1QpUeG2 Zt0g== 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 v124si526627lfa.2.2018.01.12.07.01.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 07:01:02 -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 A80EF11A033E; Fri, 12 Jan 2018 16:01:01 +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: Fri, 12 Jan 2018 15:58:45 +0100 Message-Id: <1515769128-29657-2-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515769128-29657-1-git-send-email-stefan@herbrechtsmeier.net> References: <1515769128-29657-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 --- Changes in v2: None bootloader/grub.c | 20 +++---- corelib/installer.c | 8 +-- corelib/swupdate_dict.c | 124 ++++++++++++++++++++++++++++++++---------- handlers/swuforward_handler.c | 6 +- include/swupdate_dict.h | 16 +++++- parser/parser.c | 2 +- suricatta/server_hawkbit.c | 14 +++-- 7 files changed, 138 insertions(+), 52 deletions(-) diff --git a/bootloader/grub.c b/bootloader/grub.c index 93682f0..966498f 100644 --- a/bootloader/grub.c +++ b/bootloader/grub.c @@ -165,8 +165,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; @@ -206,10 +208,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); } @@ -249,11 +253,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 e25c30c..7da49b2 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -218,11 +218,11 @@ 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 352c13a..46137a0 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 + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of @@ -31,6 +34,51 @@ #include "util.h" #include "swupdate_dict.h" +static int insert_list_elem(struct dict_list *list, 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, 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, char *key) { struct dict_entry *entry; @@ -43,20 +91,38 @@ 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; +} + +struct dict_list *dict_get_list(struct dict *dictionary, char *key) +{ + struct dict_entry *entry = get_entry(dictionary, key); + + if (!entry) + return NULL; + + return &entry->list; } char *dict_get_value(struct dict *dictionary, char *key) @@ -66,49 +132,51 @@ char *dict_get_value(struct dict *dictionary, char *key) if (!entry) return NULL; - return entry->value; + return dict_entry_get_value(entry); } -int dict_set_value(struct dict *dictionary, char *key, char *value) +int dict_insert_value(struct dict *dictionary, char *key, char *value) { 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) { + entry = insert_entry(dictionary, key); + if (!entry) + return -ENOMEM; } - return dict_insert_entry(dictionary, key, value); + return insert_list_elem(&entry->list, value); } -void dict_remove_entry(struct dict_entry *entry) +int dict_set_value(struct dict *dictionary, char *key, char *value) { - LIST_REMOVE(entry, next); - free(entry->key); - free(entry->value); - free(entry); + 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, 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 54aef4b..72d6cff 100644 --- a/handlers/swuforward_handler.c +++ b/handlers/swuforward_handler.c @@ -338,8 +338,10 @@ static int install_remote_swu(struct img_type *img, */ LIST_FOREACH(url, &img->properties, next) { char curlheader[SWUPDATE_GENERAL_STRING_SIZE + strlen(CUSTOM_HEADER)]; + char *key = dict_entry_get_key(url); + char *value = dict_entry_get_value(url); - if (!url->key || !url->value || strcmp(url->key, "url")) + if (!key || !value || strcmp(key, "url")) continue; conn = (struct curlconn *)calloc(1, sizeof(struct curlconn)); @@ -352,7 +354,7 @@ static int install_remote_swu(struct img_type *img, headerlist = NULL; conn->curl_handle = curl_easy_init(); - conn->url = url->value; + conn->url = value; if (!conn->curl_handle) { /* something very bad, it should never happen */ diff --git a/include/swupdate_dict.h b/include/swupdate_dict.h index f8b696f..cd6b80c 100644 --- a/include/swupdate_dict.h +++ b/include/swupdate_dict.h @@ -23,19 +23,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_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, 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); +int dict_insert_value(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 dict *dictionary); #endif diff --git a/parser/parser.c b/parser/parser.c index 3a1d6a5..3ecc2da 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -174,7 +174,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 51ed32f..b899715 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -1348,7 +1348,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; @@ -1379,17 +1382,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 Fri Jan 12 14:58:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 859995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c09::23e; helo=mail-wm0-x23e.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbp434pjakgqe44qkmui@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="tRyn1jGb"; dkim-atps=neutral Received: from mail-wm0-x23e.google.com (mail-wm0-x23e.google.com [IPv6:2a00:1450:400c:c09::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zJ5YF3Lmnz9sNw for ; Sat, 13 Jan 2018 02:01:21 +1100 (AEDT) Received: by mail-wm0-x23e.google.com with SMTP id b193sf3172032wmd.7 for ; Fri, 12 Jan 2018 07:01:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515769279; cv=pass; d=google.com; s=arc-20160816; b=f8jYlzmJHCO0JkWHJ7wTSum2cKTAc222ZLfU2zRZsc+5E/7NNmcrio6cxM8ak0tB+V DqEOmxL6l5NT8VLJwElvVumPnz+L13yEah9ZzO+t/UfQNKv8ADQxQWymnPcm6d3Gjfex yVw6XHBS39kyC/8+1j24q5YY0sorpjcUrx8lNEToJPGSJ3HIhzzfl44++a0Et429bJMS r2wVYitsDe7ZWKqyI4W5nc6OBZvicnAK/2a3/dKA8lYeu/uGVZI9va5r1t66CRSk/3Dm 42q6g8J5+Gun3fVQvlQQZB/j5Zn17zUJ6qy0Y5ey4qO33FHOAnS6i0RG+vrrYKcB4mhW C6lw== 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=dCe7mSypgBn00ycFLcS889HmyurtbPfPkL+tNblXnOs=; b=02dfIvzlwjVBmKT4HYxvcS7zBcqIsirmg6Fl2Bo42dKJEqtMAMKMXjShhXaOc0VluN hGNuz9HDtm1lUy89FNwAKdlONiZjjKQTc7tEHieNk1ra+ztoTK8+dypohAgq3YTnpcJS +EJ8IH1NE5Dt67SoL/xl9L8WvrSmfROMPMRumK7gOP7ggxcbL+KRMwQzjzQOLbdXQjp9 lLQzBuovOecWnMkbeAezV65DZYwYcpb0/XH1vMDqesyYO3Zh/tCWlObn/+dPZ/5OfGn5 FM5uOgEojErPPEyrEVsKC4Io9pVwrXRmTH3sYgVhLgEa0xwjZSZDVJuefR50xp5KCXbm URug== 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=dCe7mSypgBn00ycFLcS889HmyurtbPfPkL+tNblXnOs=; b=tRyn1jGboE8fpLpM2HJk2rnl4ax2BMUYXAXsuqL8Iccd0tPR1Z/KfvTHZf/qRV3riq dbPrwfll/oYXSJLrmvIh88XrN2fDSzbMDLYIHX9Rv2pt0ZF4RpZZmR5iWu167KeySdnl Bl3d6cYEH7Whp/RBQBKwvZgBzbdWsuLl6WRxC0varVdqhbrO0c2DR5jheoSnna29J54X UNU4mYlS4I+Pjh55Fr8LePQcOoc7qPCBdObFMks/H+inOf4hlLcxUKdD2Yp4GZAtgtJv 80OV+yK6jh6gTqXbdJqq8zAqTR7jJtfJa0VHg6rj94Dq1wq9jkOYXEt0/klN+6lfpWLp vPCA== 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=dCe7mSypgBn00ycFLcS889HmyurtbPfPkL+tNblXnOs=; b=uXRW7wlrqbcT1KIbUJ1b59zr1BEIB2ZLg1mv1+0y5pBSpOPGROhJ51fXK9FW6xJREa LbNFxCW1S6aJmqcqJzJrtpT2eMocNpkBZFPrtrccMHYDJpEV7nsak5HwDE8a0j1sWiot CPKNwBmF2iplNHpOI/4V+286DezV6EV5sso78/cVu9G+z26IhO7Z3udEhxqvMpb3/TjP M/diV33b4ljqdXbnq+DS7fIEry15Dn/cVDWk4ppdqbq9PXhUtGbaRO4KnuwljV84X7kd o1HgExG5ufOu0T/NDmeaC3msjIjMzIdOFJ7hbC3oJljktlxyycuwG1FYIPj3xh2W/pkI m2AA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytcO+gIDOJDr/pF1jL0oo7GwLeXpVQaBVlRtCzsw5In5tWMCzf3U n4IwqMx286M7qbH/Mcp4IqA= X-Google-Smtp-Source: ACJfBosTtmI/gg5nrrx5whLG6Ff6A0nm3Vj3Aakr/tElbYf1zmNA8REawLxc/1SKVOMWwkfE1Zem5A== X-Received: by 10.28.153.195 with SMTP id b186mr53674wme.7.1515769279272; Fri, 12 Jan 2018 07:01:19 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.206.77 with SMTP id e74ls239705wmg.4.gmail; Fri, 12 Jan 2018 07:01:18 -0800 (PST) X-Received: by 10.28.160.20 with SMTP id j20mr540629wme.6.1515769278657; Fri, 12 Jan 2018 07:01:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515769278; cv=none; d=google.com; s=arc-20160816; b=Yn6xCwuBxbgb6l5+z4ox11dyiw4Gk38Nu4U0UPWbhVVP7AmyTwYlvekjglLStLpyqv P1ewPI1yAxyNAXFdpi1rm1JPxatdQiLLFbBipKn9P/8EJx6EDykWi3xHkeaZ8m4eEO5g q1G6JJNgP+HWjTgdtMwXpRdC7GZpjiECoHnkknB2hE4pljN6NXcRLfWSD9Z0tKcHqbQM QnP2gFQvK6iETvyFR8LaYUiVVkI8jzExFch+DOFu6S4IyOYzJyZWkFo7rg2QKsiD0K00 cx6Pj/jj/BvSiMXoNhvJhZPbMLfjjJWbfwShIPWeaVxc0QucouRWDoBC/TknxoZvErCn YW7A== 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=emdjX6rYAeh8oDTxtbnQdvPWAVNXkKyepQnzY16qkHk=; b=faXVdOscsKTAS1DwChhReDvwKybRA2SGugc94n98LUABL/5t3n0yJBLLwX3AXJIDk2 lmwJs67WOiq3Sg0wklXcOYuI40Hn5+kZXXqsN50W0i6P2TANry3wCansCmlDec1szDTP 2sT6hddJbu2Vt9G8m/PQ/SSEkFH5acqwvBsX79mXOtMhoX5hagwT+dbPzxsAheTxf7Kv DYWek9TNWTLA/npQvdoZ5cnI0JwXhVUMbUxdhoPkbZbxN8hcbROzp6emybgbyhW051da rIfW2XJha0lMBwLdWu5AHXNC7d0la563ICaDmGFNaAYcF0AECBDAqhVH/N5KM5b8InuQ CR0Q== 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 j81si285673wmd.1.2018.01.12.07.01.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 07:01:18 -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 E09F111A033E; Fri, 12 Jan 2018 16:01:17 +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: Fri, 12 Jan 2018 15:58:46 +0100 Message-Id: <1515769128-29657-3-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515769128-29657-1-git-send-email-stefan@herbrechtsmeier.net> References: <1515769128-29657-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 v2: - Check name and value inside add_properties_cb function to skip NULL values - Add support for properties with value arrays corelib/installer.c | 1 + corelib/parsing_library.c | 15 +++++++++++++++ corelib/parsing_library_libconfig.c | 24 ++++++++++++++++++++++++ corelib/parsing_library_libjson.c | 31 +++++++++++++++++++++++++++++++ doc/source/handlers.rst | 8 +++----- include/parselib.h | 9 +++++++++ parser/parser.c | 35 +++++++++++++++-------------------- 7 files changed, 98 insertions(+), 25 deletions(-) diff --git a/corelib/installer.c b/corelib/installer.c index 7da49b2..5ccfb21 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -220,6 +220,7 @@ static int prepare_boot_script(struct swupdate_cfg *cfg, const char *script) LIST_FOREACH(bootvar, &cfg->bootloader, next) { 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", key, value); diff --git a/corelib/parsing_library.c b/corelib/parsing_library.c index 79f3886..8f4637d 100644 --- a/corelib/parsing_library.c +++ b/corelib/parsing_library.c @@ -74,6 +74,21 @@ 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)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 f0cfb38..ccd596b 100644 --- a/corelib/parsing_library_libconfig.c +++ b/corelib/parsing_library_libconfig.c @@ -59,6 +59,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 67cbc2c..e995b8f 100644 --- a/corelib/parsing_library_libjson.c +++ b/corelib/parsing_library_libjson.c @@ -63,6 +63,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..c07b215 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -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"; + }; }); diff --git a/include/parselib.h b/include/parselib.h index 7c44a5e..b63349c 100644 --- a/include/parselib.h +++ b/include/parselib.h @@ -27,6 +27,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) | \ @@ -38,6 +41,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 @@ -47,6 +52,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) (0) #define get_field_cfg(e, path, dest) #endif @@ -57,6 +63,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, @@ -68,6 +75,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) (0) #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) @@ -82,6 +90,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 3ecc2da..9a60181 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -152,32 +152,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 Fri Jan 12 14:58:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 859996 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::240; helo=mail-wr0-x240.google.com; envelope-from=swupdate+bncbdn7dbh5yqibbum34pjakgqe4ut2guy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="XMvoXjEe"; dkim-atps=neutral Received: from mail-wr0-x240.google.com (mail-wr0-x240.google.com [IPv6:2a00:1450:400c:c0c::240]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zJ5Yc3DmKz9sNw for ; Sat, 13 Jan 2018 02:01:40 +1100 (AEDT) Received: by mail-wr0-x240.google.com with SMTP id n13sf3580279wra.13 for ; Fri, 12 Jan 2018 07:01:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515769297; cv=pass; d=google.com; s=arc-20160816; b=amseXNZkOCCGYhON6Of/HZj+W/puQm2JJEl37HJUaRHiFD+NERCo8WGwkac50zdxMg dbrr6+7LJ+ajoD8kmR2/ytwlUdHgxUu/n71QZpoLCByk48C+HoF1IdmCzP1tsMyjs3EB /hK63Was2vreNkM67ey+uOVMZVo692rGgIwkfgnsunUuEElhbV62OtcNqBLdri/MNON6 TuUpOlaYPAmg0EgXrcONa+q0VakF4PKqBIjHjWTvyxGQuSp9o67eOOvORWJc3sxvGpTA wEaFO4+dLF0nnaG6YdPKr4VnTW5srM5bQDihhMRrQsSqOsfS5FyLXx4xda3z0zyqPqwv g3Bg== 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=N0CHUycAUuSZplIIETJI+CtdIsiYZ8SA2ZP6PFSiw8M=; b=VLrPpPa7+Mhsxj4fkZ30YZOs76AhR2bg3c6iF7sGIhwRpuHO4tnnWRc2tUgshjM7Rx yWCVQHmLeDOuRY9XyYtDvkrMIJpbnOskf4rDVsuTJE2oO+t2e5IVBfpGbUw9aLgnF/GK G+BYUANt3ZnIT+H3UUIP3JjUsNpvTYq/7VGB4Qz6q7hfUwfqQavCfHXfwH7tMsbdB8iC VVxV8S/XVinCzvuQMlR0rTv0k803b2tdEb0guxLL/wlqZMhq7qtuIE8LQXpSgdfhjX5C pKDylYH+G+IF+Mkbl6JGYFCEd414SnrKWxXbVT05CBJZOQifq/1zq5SSO/USDPu7nD7y 6lRQ== 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=N0CHUycAUuSZplIIETJI+CtdIsiYZ8SA2ZP6PFSiw8M=; b=XMvoXjEeYUwGk+VMPORiON0HGUWIeSuzj6wtsmaggwAYPB32uVH1m23Yil0ACM8OB3 qqm8AabILXxElB1zHslojR75RtjmHkc+HNRG0Hn7gwAIAgKZ894Bv1RRtT2BGXPvlJ/K wiJ4aCXw/G3VOXG2XFjRfXQZvdRIvQrzurwROJBXT8JmTYG9S+dZ9KZDl24oNRvJAHh8 pVmCuOuJauH2XCWbAtjXvYxuiteh+JkGxVQVKIIySoTNwH+MYk2dKfDRaH0kXrhb1Hof XTX1WDYRr4v9vKbNzDNEbJYNb+DJcZc53r91RctX5qGoa19wNjNKwxp2mWQBf0EA8A2Z DzyQ== 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=N0CHUycAUuSZplIIETJI+CtdIsiYZ8SA2ZP6PFSiw8M=; b=mnphrRxuZmyriiUbT7Ij7iP9FG66DkUaRL/zRa8lbuovCb2rbhD0RQ6MHjTj8pwpnC dr8h9FX51NUDEyPkqhrmP9yZI1KQaND3udx2f0iDpKwQhQGjM8WKKbSATYe6CBhz8FLG oEXgw4o60Kt1ay0WSB0LTOsUSJaZOzvAia8uamDX5KaaKuBMeVA/X21sawFUYDZpTy81 DpFmbaxzdOqdXqUcSnSI5iSmCrtm+zcCQgJpHZgv0mYogVVdv5jjonbxLAO98xavkVlW M7CHXzNPHDfvNGsAkbmEqjaOHowD4wlypaeSbZJ8HxnBJiazz9C6ZLFghw+eZAHjOhoN heLg== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxytfnPupcatQo4ktWwWSoq1Pvz1XtHv0CYH7JA7gqEiGJKHjsyTic JU0W1ZToXxP0E1bMU8kZnGU= X-Google-Smtp-Source: ACJfBou5T5EEr0cihvZUGh3Zd1bWWQkdceOWcTUO4iHTJSqz81t2Xs1/3X7XVgtdLDcg00BaE7AYug== X-Received: by 10.28.54.133 with SMTP id y5mr51997wmh.7.1515769297849; Fri, 12 Jan 2018 07:01:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.80.241.77 with SMTP id z13ls504039edl.1.gmail; Fri, 12 Jan 2018 07:01:37 -0800 (PST) X-Received: by 10.80.146.139 with SMTP id k11mr3050313eda.4.1515769297042; Fri, 12 Jan 2018 07:01:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515769297; cv=none; d=google.com; s=arc-20160816; b=QgLBf+0/JV8PVumYdp03pCZlDGzG9qdRB0ftbwAv/44J2S7ER3FCvg2mxX5ehRiJlj rqo7b3FOWHmcovZs5FyJKTKRNVbMydoqlh7gjXyFGPUM9BVj5zmjfBYekHBh1MGVDUYm oKkjWQx2YMzJAWVanR/HbLiB7LzsAGMrL3H3H0CAEn5UDH9H5gD0zxeTqTB7earVR7UJ q5A6dA6dvlMQax0ieiGVDXRjRlLRDxbBQOcfLvoBwEmVvRTEyFaFTUPtxzmNsMidJilG giB3S6ruSB6hxTP8aVeRZyl1LAwNRlNyfbSCDqhSi7SGCt/Gvpi5Q1SDsMY9JyGbAq9G RpRA== 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=2id0EEIp60L/xrL2pkQDFk+EGM3l2nSHcvtxm4t2KWE=; b=JjT5xShm8SY62WP0g7jI2RpKz9zGNzYhPlDsaiPVaM1zVR6KM41J/V+exZkLvOg7oC +WaTSRGzwn4/jJCrFZYSJHUk+TIQ1NgwSNVk1FdNLS7dB8nd2NrS5IKEQhhTnCUITl/V tf8/dIjbT6Ak/5u0PNy4kBZufY8gLtwIemR6aOCezmM1jc6G9NOBEkh935WYtABYMYvK GBsnF5+JqorYNqHoVXoq65+3ENUU/4hMRm2VNQjlpEQGa6zUc42ncHVqQcvfmIvxW5Vy GkArAseUGvS+RvI+NJVu4qOrfbnYcfvyv5aW6oiwMbou9t9e1Aq9cIJYzZHZypNJ59QM qdOA== 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 w21si368999edl.5.2018.01.12.07.01.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 07:01:37 -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 9A52B11A033E; Fri, 12 Jan 2018 16:01:36 +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: Fri, 12 Jan 2018 15:58:47 +0100 Message-Id: <1515769128-29657-4-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515769128-29657-1-git-send-email-stefan@herbrechtsmeier.net> References: <1515769128-29657-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 v2: None corelib/lua_interface.c | 87 +++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index b1a3a92..872cb2f 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -74,8 +74,54 @@ static bool is_type(lua_State *L, uintptr_t type) } #endif +static void lua_dump_table(lua_State *L, char *str) +{ + char *s; + + /* 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: + if (asprintf(&s, "%s %s:", str, lua_tostring(L, -1)) != -1) { + 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) { + char *s; int top = lua_gettop(L); for (int i = 1; i <= top; i++) { int t = lua_type(L, i); @@ -97,43 +143,12 @@ 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 */ + if (asprintf(&s, "(%d) [table ]", i) != -1) { + 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 Fri Jan 12 14:58:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Herbrechtsmeier X-Patchwork-Id: 859998 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23e; helo=mail-wr0-x23e.google.com; envelope-from=swupdate+bncbdn7dbh5yqibby434pjakgqe3y5n52i@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="pJgftT3u"; dkim-atps=neutral Received: from mail-wr0-x23e.google.com (mail-wr0-x23e.google.com [IPv6:2a00:1450:400c:c0c::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zJ5Yy1XcXz9sNw for ; Sat, 13 Jan 2018 02:01:58 +1100 (AEDT) Received: by mail-wr0-x23e.google.com with SMTP id v18sf3530250wrf.21 for ; Fri, 12 Jan 2018 07:01:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1515769315; cv=pass; d=google.com; s=arc-20160816; b=LPNXUh0eV7f3q7BbaOP+x923DYcY14TejB9KUtrbGS/8tVbDDAdWsgLhbEXoyCWpoK GzB1SdE7W1x1xGMv0bjOSf95PdHfMCJmWMbfFWHD5KJip6znn4E3/SibhMcgmHxY9W3g qw2OGUyLp805M+T926uc+F97s3xQ/m2dD6BySkc1RNXuDLj+FHnzpeApJ7xBSxKX2aLH fwR3j90JTu1l3waCytK3RQLgyV8hiLiwGj0mAqVs8nwN0vqc5EGYMgiSyKuNbyWnIqxv PE22xKuYcKzkwQJ14fBy3fvq8mYKKftuSaWuFtfAawR1MgtsLr8+D1/6U9GF+BMa5Wwa RKBw== 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=K+xT1LcKwdnrGnoW/n3XRe0LVwz1twEOMA8VgGqEy40=; b=gDYIge4z/SUeiYh/RCfCB+Cxzq8T0gZAFEXepvQbpuFN8z1n6yJ8/YgXdKQUcZZjb0 XU23OX1YK5ftujfTsAlVfJfndAfdM1MoMUkiWdCGoVC4dIMxoMyKTRqZ5tZQnX6RLJ8T QmrEaBocr7pJk5jXZFkd5gFxdBpbZBbXTyAvro/gp4s6rnis1UwVkYDhUEiLXR76Ctsw KL8jmysQ9i5iZEE1jlsQV8C6AVcnQ/sVYMOPW1aXKJmQ5JUdMEetBIFS+cqIzOcq9g0Q 0dG/zrBESNrJbVz+9/Hs3bBiKrhaDAr3Yh6Y0NkDj8hyWca+UYwFw48jJUONT6tNtKTe +s/g== 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=K+xT1LcKwdnrGnoW/n3XRe0LVwz1twEOMA8VgGqEy40=; b=pJgftT3uMpbDIqQWceIQ0sMemcvLbcvMfacSdD7NYQeeiPtL+Jq6m5+MOcGRSrkdjC K4uYq/n3rLLOQQ/3GlRSVcb4KrEXmwHYN7SBgZ/PJ4jra4MXoE6j+jpvktd5QJXZfgt9 XheD0OF3QYFOn05YSEY9DLk+Mm76GtBMe7GB+rKqQFzETZ389qO1FIveoit49thm4zH3 rFcvzMvBsQupoy6Hcju+1A2Mn+Np399q9W8YatLuX7N1SLQJU1RZGv2+2E00M/ZV6+eM MU7CYKhOp37cZ2zCtM70NNr1PgBJGxgx50/CV1oQ1uaMvMjbFcRHOqk347tp4mW58joe 16+Q== 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=K+xT1LcKwdnrGnoW/n3XRe0LVwz1twEOMA8VgGqEy40=; b=cI4DKzGSa6LcT083tLbyptZgLRjwbgcjFBMzztJp1zOSFw8hqeNvrAr0DCzkSrNu9a x64+Vrgd4K9+m9FjocmkrPdjwbKEtInUNNabaX+3aZ5gN/zK7uPSsMQjD0Yy1zpJppvy 1Ni1AlTzyjIkvRsGbGqtA1Xj8754TuIRgxyoA/galiKEIqv9rOAYkPB7YCCXqGvT6AJM nDpq+yKqPKIrzWpvcgdPPpgJeokD3TzbOc6keguztnTghkbPtTH/Ul5MTOlrcjhqph7o jziQXBaeISBLjn4GsY+wYjyGHbILgLfRYUlmzbps42kjmyM3V3bsKBlDyAH4HrqdY8l8 tN/A== Sender: swupdate@googlegroups.com X-Gm-Message-State: AKwxyte0Of/mZh62u9EOT6Nrn+H4RCg+wh4bIPqp/RPIn2bQ6o0X4Yuk r/VFkRdfmwDzvwngG5tVQZQ= X-Google-Smtp-Source: ACJfBovZtCM92BSf1VJqvXi8G3tPCwgltZk+pnRb5WgIOzTW2+7i28hpJtgI33bh9SNexk52mgyzWg== X-Received: by 10.28.144.198 with SMTP id s189mr51528wmd.6.1515769315898; Fri, 12 Jan 2018 07:01:55 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 10.28.28.11 with SMTP id c11ls244909wmc.2.gmail; Fri, 12 Jan 2018 07:01:55 -0800 (PST) X-Received: by 10.28.122.17 with SMTP id v17mr476925wmc.7.1515769315416; Fri, 12 Jan 2018 07:01:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515769315; cv=none; d=google.com; s=arc-20160816; b=hDAz/kxHqMK5LfqR+DlxsYIHKtZckBhNcVTa+cykSef01p7wiYW8nTL0uUbjs2DZnW KO5Z6EOV76N8hYDpVYQroBhpN9/hPC8EM43gl4s2AtCXmm17vbOxf9kZsZS19wiMZFdt ge/F9XkZ8NZ4mFtHknPDsX76G3jthE2X4SvY7ACWmx8HkXGp8mXsaR9E4gXTbHapTtnB x+dnROoBxjw39AZahiVJu51REITzpk7Up5v+OtvsCh2K5xxKjRWVLI/Td0E6tSrlwhP7 KAkEfWf+T3SVqhCDU7azbed4IaEbDDgWWAfvoivmrDLwcilmEto2YrQ+m/RMufHMSqwk qWrg== 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=O4PVL7IQgNpiKRxXODzzPsc6wcNVOvOUxu4j/Fcfjxo=; b=pfgeUY1i/F63m8vMT94kdZQ1oD3EAGJfCXq2203bmbHALXBOmxWiKTwNxVYFXjjHsb u2NGMJZG+Allf7mDNNo8YjJ/hy/y7jI98TF7xV3/iV23uU7koK+X4P4Et9EN2sW3ZKIk 1YZ8ga67Urw1J73UqFVGZ1WxY8bCZ+GOfqd3aPNhYIsyp6ytgXQi7ez9HPp6W6c+1Hgp /fzck77ND8XC/2vLYK3gtRTAcYx7Ltqm3jVa0Ip+bKgzPc6iezN6+tKhNvN14HFZLK20 NKld/tj3z8b20t5IFmBZxiqrYdLlqk0PlOBc1H3yqfz71dseAiTWOISE0MdvOqgvrUe1 7GPw== 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 h76si381006wmd.1.2018.01.12.07.01.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jan 2018 07:01:55 -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 1742411A0438; Fri, 12 Jan 2018 16:01:55 +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: Fri, 12 Jan 2018 15:58:48 +0100 Message-Id: <1515769128-29657-5-git-send-email-stefan@herbrechtsmeier.net> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515769128-29657-1-git-send-email-stefan@herbrechtsmeier.net> References: <1515769128-29657-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 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 872cb2f..28bb4f5 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -439,6 +439,10 @@ static int l_istream_read(lua_State* L) static void update_table(lua_State* L, struct img_type *img) { + struct dict_entry *property; + struct dict_list_elem *elem; + int i; + if (L && img) { luaL_checktype(L, -1, LUA_TTABLE); @@ -464,6 +468,26 @@ 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) { + lua_pushstring(L, dict_entry_get_key(property)); + elem = LIST_FIRST(&property->list); + if (LIST_NEXT(elem, next) == LIST_END(&property->list)) { + lua_pushstring(L, elem->value); + } else { + 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");