/* * Callback to be used to put a section of configuration * into a dictionary */ int settings_into_dict(void *settings, void *data) { void *elem; int count, i; char name[80], value[80]; struct dict *dictionary = (struct dict *) data; count = get_array_length(LIBCFG_PARSER, settings); for(i = 0; i < count; ++i) { elem = get_elem_from_idx(LIBCFG_PARSER, settings, i); if (!elem) continue; if(!(exist_field_string(LIBCFG_PARSER, elem, "name"))) continue; if(!(exist_field_string(LIBCFG_PARSER, elem, "value"))) continue; GET_FIELD_STRING(LIBCFG_PARSER, elem, "name", name); GET_FIELD_STRING(LIBCFG_PARSER, elem, "value", value); dict_set_value(dictionary, name, value); TRACE("Identify for configData: %s --> %s\n", name, value); } return 0; }
/* * Check if the software can run on the hardware */ static int parse_hw_compatibility(parsertype p, void *cfg, struct swupdate_cfg *swcfg) { void *setting, *hw; int count, i; char s[SWUPDATE_GENERAL_STRING_SIZE]; struct hw_type *hwrev; setting = find_node(p, cfg, "hardware-compatibility", swcfg); if (setting == NULL) { ERROR("HW compatibility not found\n"); return -1; } count = get_array_length(p, setting); for(i = 0; i < count; ++i) { hw = get_elem_from_idx(p, setting, i); if (!hw) continue; s[0] = '\0'; GET_FIELD_STRING(p, hw, NULL, s); if (!strlen(s)) continue; hwrev = (struct hw_type *)calloc(1, sizeof(struct hw_type)); if (!hwrev) { ERROR("No memory: malloc failed\n"); return -1; } strncpy(hwrev->revision, s, sizeof(hwrev->revision)); LIST_INSERT_HEAD(&swcfg->hardware, hwrev, next); TRACE("Accepted Hw Revision : %s", hwrev->revision); } return 0; }
static int read_processes_settings(void *settings, void *data) { struct swupdate_cfg *sw = (struct swupdate_cfg *)data; void *elem; int count, i; struct extproc *proc, *last = NULL; count = get_array_length(LIBCFG_PARSER, settings); for(i = 0; i < count; ++i) { elem = get_elem_from_idx(LIBCFG_PARSER, settings, i); if (!elem) continue; if(!(exist_field_string(LIBCFG_PARSER, elem, "name"))) continue; if(!(exist_field_string(LIBCFG_PARSER, elem, "exec"))) continue; proc = (struct extproc *)calloc(1, sizeof(struct extproc)); GET_FIELD_STRING(LIBCFG_PARSER, elem, "name", proc->name); GET_FIELD_STRING(LIBCFG_PARSER, elem, "exec", proc->exec); if (!last) LIST_INSERT_HEAD(&sw->extprocs, proc, next); else LIST_INSERT_AFTER(last, proc, next); last = proc; TRACE("External process \"%s\": \"%s %s\" will be started", proc->name, proc->exec, proc->options); } return 0; }