Message ID | 1516199646-5607-1-git-send-email-stefan@herbrechtsmeier.net |
---|---|
State | Accepted |
Headers | show |
Series | [v2,1/5] dict: Rename dictionary struct and its key to distinguish it from simple lists | expand |
On 17/01/2018 15:34, stefan@herbrechtsmeier.net wrote: > From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> > > Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> > --- > > 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 <bsdqueue.h> > > 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; > Reviewed-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
On 17/01/2018 15:34, stefan@herbrechtsmeier.net wrote: > From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> > > Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> > --- > Applied to -master, thanks ! Best regards, Stefano Babic
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 <bsdqueue.h> 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;