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;