/* * Return the number of stored devices */ int Settings::getNumberOfNodes(Node node) const { TelldusCore::MutexLocker locker(&mutex); if (d->cfg > 0) { if (node == Device) { return cfg_size(d->cfg, "device"); } else if (node == Controller) { return cfg_size(d->cfg, "controller"); } } return 0; }
int parse_mapping_cfg_params(cfg_t *map, conf_mapping_t *conf_mapping, uint8_t is_local) { int ctr; cfg_t *rl; conf_loc_t *conf_loc; conf_loc_iface_t *conf_loc_iface; int afi; strcpy(conf_mapping->eid_prefix,cfg_getstr(map, "eid-prefix")); conf_mapping->iid = cfg_getint(map, "iid"); for (ctr = 0; ctr < cfg_size(map, "rloc-address"); ctr++){ rl = cfg_getnsec(map, "rloc-address", ctr); conf_loc = conf_loc_new_init( cfg_getstr(rl, "address"), cfg_getint(rl, "priority"), cfg_getint(rl, "weight"), 255,0); glist_add_tail(conf_loc,conf_mapping->conf_loc_list); } if (is_local){ for (ctr = 0; ctr < cfg_size(map, "rloc-iface"); ctr++){ rl = cfg_getnsec(map, "rloc-iface", ctr); afi = cfg_getint(rl, "ip_version"); if (afi == 4){ afi = AF_INET; }else if (afi == 6){ afi = AF_INET6; }else{ OOR_LOG(LERR,"Configuration file: The conf_loc_iface->ip_version of the locator should be 4 (IPv4) or 6 (IPv6)"); return (BAD); } conf_loc_iface = conf_loc_iface_new_init( cfg_getstr(rl, "interface"), afi, cfg_getint(rl, "priority"), cfg_getint(rl, "weight"), 255,0); glist_add_tail(conf_loc_iface,conf_mapping->conf_loc_iface_list); } } return (GOOD); }
int main(void) { static cfg_opt_t section_opts[] = { CFG_STR("prop", 0, CFGF_NONE), CFG_END() }; cfg_opt_t opts[] = { CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI), CFG_END() }; const char *config_data = "section title_one { prop = 'value_one' }\n" "section title_two { prop = 'value_two' }\n"; int rc; cfg_t *cfg = cfg_init(opts, CFGF_NONE); fail_unless(cfg); rc = cfg_parse_buf(cfg, config_data); fail_unless(rc == CFG_SUCCESS); fail_unless(cfg_addtsec(cfg, "section", "title_three")); fail_unless(cfg_size(cfg, "section") == 3); fail_unless(cfg_title(cfg_gettsec(cfg, "section", "title_three"))); /* attempt to add a pre-existing section should fail */ fail_unless(!cfg_addtsec(cfg, "section", "title_three")); cfg_free(cfg); return 0; }
/* Checks if the file path is configured to be ignored */ static int file_path_ignore(const char *path) { cfg_t *lib; regex_t regex; int n; int i; int ret; lib = cfg_getsec(cfg, "library"); n = cfg_size(lib, "filepath_ignore"); for (i = 0; i < n; i++) { ret = regcomp(®ex, cfg_getnstr(lib, "filepath_ignore", i), 0); if (ret != 0) { DPRINTF(E_LOG, L_SCAN, "Could not compile regex for matching with file path\n"); return 0; } ret = regexec(®ex, path, 0, NULL, 0); regfree(®ex); if (ret == 0) { DPRINTF(E_DBG, L_SCAN, "Regex match: %s\n", path); return 1; } } return 0; }
static void print_systems(cfg_t *cfg) { size_t i; for (i = 0; i < cfg_size(cfg, "provider"); i++) print_system(cfg_getnsec(cfg, "provider", i)); }
// // E_ProcessInventoryDefs // // Resolves and loads all information for the inventory structures. // void E_ProcessInventoryDefs(cfg_t *cfg) { unsigned int i, numInventory; E_EDFLogPuts("\t* Processing inventory data\n"); if(!(numInventory = cfg_size(cfg, EDF_SEC_INVENTORY))) return; // allocate inheritance stack and hitlist inv_pstack = ecalloc(inventory_t **, numInventoryDefs, sizeof(inventory_t *)); // TODO: any first-time-only processing? for(i = 0; i < numInventory; i++) { cfg_t *invsec = cfg_getnsec(cfg, EDF_SEC_INVENTORY, i); const char *name = cfg_title(invsec); inventory_t *inv = E_InventoryForName(name); // reset the inheritance stack E_ResetInventoryPStack(); // add this def to the stack E_AddInventoryToPStack(inv); E_ProcessInventory(inv, invsec, cfg, true); E_EDFLogPrintf("\t\tFinished inventory %s(#%d)\n", inv->name, inv->numkey); } // free tables efree(inv_pstack); }
int parse_script(char *filename, script_ent_t * script) { cfg_t *pcfg; int i; memset(script, 0, sizeof(script_ent_t)); printf("eins\n"); pcfg = cfg_init(script_opts, CFGF_NONE); printf("zwei\n"); if (cfg_parse(pcfg, filename) == CFG_PARSE_ERROR) return -1; strcpy(script->name, cfg_getstr(pcfg, "name")); /* max 28 chars !!! */ strcpy(script->org_name, cfg_getstr(pcfg, "org_name")); /* max 64 chars !!! */ strcpy(script->comment, cfg_getstr(pcfg, "comment")); /* max 128 chars !!! */ script->script_num = cfg_getint(pcfg, "id"); script->version = cfg_getint(pcfg, "version"); script->unused1 = cfg_getint(pcfg, "unused1"); script->script_length = cfg_size(pcfg, "script"); if (script->script_length & 1) { printf("WARNING: odd number of bytes in script ... truncating\n"); } script->script_length >>= 1; for (i = 0; i < (script->script_length << 1); i++) script->script[i] = (uint8_t) cfg_getnint(pcfg, "script", i); cfg_free(pcfg); return 0; }
// // E_MetaTableFromCfg // // haleyjd 06/30/13: Convert a cfg_t to fields in a MetaTable, with optional // inheritance from a prototype table. // void E_MetaTableFromCfg(cfg_t *cfg, MetaTable *table, MetaTable *prototype) { table->clearTable(); if(prototype) { table->copyTableFrom(prototype); table->setString("super", prototype->getKey()); } for(auto opt = cfg->opts; opt->type != CFGT_NONE; opt++) { if(cfg_size(cfg, opt->name) == 0) continue; switch(opt->type) { case CFGT_INT: E_MetaIntFromCfgInt(table, cfg, opt->name); break; case CFGT_STR: E_MetaStringFromCfgString(table, cfg, opt->name); break; case CFGT_BOOL: E_MetaIntFromCfgBool(table, cfg, opt->name); break; case CFGT_FLAG: E_MetaIntFromCfgFlag(table, cfg, opt->name); break; default: break; } } }
int Settings::setIntSetting(Node type, int intDeviceId, const std::wstring &name, int value, bool parameter) { // already locked if (d->cfg == 0) { return TELLSTICK_ERROR_PERMISSION_DENIED; } std::string strType = getNodeString(type); cfg_t *cfg_device; for (int i = 0; i < cfg_size(d->cfg, strType.c_str()); ++i) { cfg_device = cfg_getnsec(d->cfg, strType.c_str(), i); if (cfg_getint(cfg_device, "id") == intDeviceId) { if (parameter) { cfg_t *cfg_parameters = cfg_getsec(cfg_device, "parameters"); cfg_setint(cfg_parameters, TelldusCore::wideToString(name).c_str(), value); } else { cfg_setint(cfg_device, TelldusCore::wideToString(name).c_str(), value); } FILE *fp = fopen(CONFIG_FILE, "we"); // e for setting O_CLOEXEC on the file handle if (!fp) { return TELLSTICK_ERROR_PERMISSION_DENIED; } cfg_print(d->cfg, fp); fclose(fp); return TELLSTICK_SUCCESS; } } return TELLSTICK_ERROR_DEVICE_NOT_FOUND; }
int main(void) { unsigned int i; read_config(); signal(SIGHUP, sighandler); signal(SIGUSR1, usr1handler); while(loop) { printf("Message: %s", cfg_getstr(cfg, "message")); for(i = 0; i < cfg_size(cfg, "argument"); i++) { cfg_t *arg = cfg_getnsec(cfg, "argument", i); printf(", %s", cfg_getstr(arg, "value")); } printf("\n"); sleep(cfg_getint(cfg, "delay")); } cfg_free(cfg); cfg = 0; return 0; }
// // E_ProcessSpriteVars // // Sets the sprite numbers to be used for the player and blank // sprites by looking up a provided name in the sprite hash // table. // static void E_ProcessSpriteVars(cfg_t *cfg) { static bool firsttime = true; int sprnum; const char *str; E_EDFLogPuts("\t* Processing sprite variables\n"); // haleyjd 11/11/09: removed processing of obsolete playersprite variable // haleyjd 11/21/11: on subsequent runs, only replace if changed if(!firsttime && cfg_size(cfg, ITEM_BLANKSPRITE) == 0) return; firsttime = false; // load blank sprite number str = cfg_getstr(cfg, ITEM_BLANKSPRITE); sprnum = E_SpriteNumForName(str); if(sprnum == -1) { E_EDFLoggedErr(2, "E_ProcessSpriteVars: invalid blank sprite name: '%s'\n", str); } E_EDFLogPrintf("\t\tSet sprite %s(#%d) as blank sprite\n", str, sprnum); blankSpriteNum = sprnum; }
int parse_database_mapping(cfg_t *cfg, lisp_xtr_t *xtr, shash_t *lcaf_ht) { int n,i; mapping_t *mapping; map_local_entry_t *map_loc_e; void *fwd_map_inf; n = cfg_size(cfg, "database-mapping"); for (i = 0; i < n; i++) { mapping = parse_mapping(cfg_getnsec(cfg, "database-mapping", i),&(xtr->super),lcaf_ht,TRUE); if (mapping == NULL){ continue; } map_loc_e = map_local_entry_new_init(mapping); if (map_loc_e == NULL){ mapping_del(mapping); continue; } fwd_map_inf = xtr->fwd_policy->new_map_loc_policy_inf(xtr->fwd_policy_dev_parm,mapping,NULL); if (fwd_map_inf == NULL){ OOR_LOG(LERR, "Couldn't create forward information for mapping with EID: %s. Discarding it...", lisp_addr_to_char(mapping_eid(mapping))); map_local_entry_del(map_loc_e); continue; } map_local_entry_set_fwd_info(map_loc_e, fwd_map_inf, xtr->fwd_policy->del_map_loc_policy_inf); if (add_local_db_map_local_entry(map_loc_e,xtr) != GOOD){ map_local_entry_del(map_loc_e); continue; } } return (GOOD); }
static void parse_mcinfo_list(cfg_t *cfg, shash_t *ht) { mc_t *mc; lisp_addr_t *laddr; char *name; int i, count; count = 0; for (i = 0; i < cfg_size(cfg, "multicast-info"); i++) { cfg_t *mcnode = cfg_getnsec(cfg, "multicast-info", i); name = cfg_getstr(mcnode, "mc-info-name"); laddr = lisp_addr_new_lafi(LM_AFI_LCAF); lisp_addr_lcaf_set_type(laddr, LCAF_MCAST_INFO); mc = mc_type_new(); lisp_addr_ip_from_char(cfg_getstr(mcnode, "source"), mc->src); mc->src_plen = cfg_getint(mcnode, "source-mask-length"); lisp_addr_ip_from_char(cfg_getstr(mcnode, "group"), mc->grp); mc->src_plen = cfg_getint(mcnode, "group-mask-length"); mc->iid = cfg_getint(mcnode, "iid"); lisp_addr_lcaf_set_addr(laddr, mc); OOR_LOG(LDBG_1, "Configuration file: parsed multicast-info: %s", lisp_addr_to_char(laddr)); shash_insert(ht, strdup(name), laddr); count ++; } if (count != 0) { OOR_LOG(LINF, "Parsed configured multicast addresses"); } }
static cfg_t* find_module_config(char *modname) { cfg_t *modules_cfg; int j; modules_cfg = cfg_getsec(python_module.config_file, "modules"); for (j = 0; j < cfg_size(modules_cfg, "module"); j++) { char *modName, *modLanguage; int modEnabled; cfg_t *pymodule = cfg_getnsec(modules_cfg, "module", j); /* Check the module language to make sure that the language designation is python. */ modLanguage = cfg_getstr(pymodule, "language"); if (!modLanguage || strcasecmp(modLanguage, "python")) continue; modName = cfg_getstr(pymodule, "name"); if (strcasecmp(modname, modName)) { continue; } /* Check to make sure that the module is enabled. */ modEnabled = cfg_getbool(pymodule, "enabled"); if (!modEnabled) continue; return pymodule; } return NULL; }
static void add_filter_restrictions(filter *f, cfg_t *sec) { for (int i = 0; i < NUM_FILTER_OPTIONS; ++i) { filter_option *opt = &filter_options[i]; if (cfg_size(sec, opt->config_name)) { switch (opt->type) { case FILTER_OPTION_TYPE_BOOL: { int value = cfg_getbool(sec, opt->config_name) == cfg_true ? 1 : 0; filter_add_restriction_bool(f, opt->data.property_name, value); break; } case FILTER_OPTION_TYPE_STRING: { const char *value = cfg_getstr(sec, opt->config_name); filter_add_restriction_string(f, opt->data.property_name, value); break; } case FILTER_OPTION_TYPE_CUSTOM: { intptr_t value = cfg_getbool(sec, opt->config_name) == cfg_true ? 1 : 0; filter_add_restriction_custom(f, opt->data.custom.match_func, opt->data.custom.free_func, opt->data.custom.cookie, value); break; } default: assert(0); break; } } } }
// // Process an individual switch // static void E_processSwitch(cfg_t *cfg) { const char *title = cfg_title(cfg); ESwitchDef *def = e_switch_namehash.objectForKey(title); const bool modified = !!def; if(!def) { def = new ESwitchDef; def->offpic = title; e_switch_namehash.addObject(def); eswitches.add(def); E_EDFLogPrintf("\t\tDefined switch %s\n", title); } else E_EDFLogPrintf("\t\tModified switch %s\n", title); auto isset = [modified, cfg](const char *field) { return !modified || cfg_size(cfg, field) > 0; }; if(isset(ITEM_SWITCH_ONPIC)) def->onpic = cfg_getstr(cfg, ITEM_SWITCH_ONPIC); if(isset(ITEM_SWITCH_ONSOUND)) def->onsound = cfg_getstr(cfg, ITEM_SWITCH_ONSOUND); if(isset(ITEM_SWITCH_OFFSOUND)) def->offsound = cfg_getstr(cfg, ITEM_SWITCH_OFFSOUND); if(isset(ITEM_SWITCH_GAMEINDEX)) def->episode = cfg_getint(cfg, ITEM_SWITCH_GAMEINDEX); }
// // E_ProcessFontFilter // // Patch fonts can specify any number of filter objects (at least one is // required), which have two methods for specifying the lump that belongs // to a given character or range of characters. The filters use mask strings // that are C format strings, but the validity of these are checked at load // by the routine above. // static void E_ProcessFontFilter(cfg_t *sec, vfontfilter_t *f) { unsigned int numchars; const char *tempstr; char *pos = nullptr; int tempnum = 0; // the filter works in one of two ways: // 1. specifies a list of characters to which it applies // 2. specifies a range of characters from start to end // is it a list? if((numchars = cfg_size(sec, ITEM_FILTER_CHARS)) > 0) { f->chars = ecalloc(unsigned int *, numchars, sizeof(unsigned int)); f->numchars = numchars; for(unsigned int i = 0; i < numchars; i++) { pos = nullptr; tempstr = cfg_getnstr(sec, ITEM_FILTER_CHARS, i); if(strlen(tempstr) > 1) tempnum = strtol(tempstr, &pos, 0); if(pos && *pos == '\0') f->chars[i] = tempnum; else f->chars[i] = *tempstr; } }
static HV* build_params_hash(cfg_t *plmodule) { int k; HV *params_hash; params_hash = newHV(); if (plmodule && params_hash) { for (k = 0; k < cfg_size(plmodule, "param"); k++) { cfg_t *param; char *name, *value; SV *sv_value; param = cfg_getnsec(plmodule, "param", k); name = apr_pstrdup(pool, param->title); value = apr_pstrdup(pool, cfg_getstr(param, "value")); sv_value = newSVpv(value, 0); if (name && sv_value) { /* Silence "value computed is not used" warning */ (void)hv_store(params_hash, name, strlen(name), sv_value, 0); } } } return params_hash; }
/* * Remove a device */ int Settings::removeNode(Node type, int intNodeId) { TelldusCore::MutexLocker locker(&mutex); FILE *fp = fopen(CONFIG_FILE, "we"); // e for setting O_CLOEXEC on the file handle if (!fp) { return TELLSTICK_ERROR_PERMISSION_DENIED; } std::string strType = getNodeString(type); // Print all opts for(int i = 0; d->cfg->opts[i].name; i++) { // Check if it isn't a device section if (strcmp(d->cfg->opts[i].name, strType.c_str()) != 0) { cfg_opt_print(&d->cfg->opts[i], fp); } else { // Print all sections except the one to remove cfg_t *cfg_node; for (int i = 0; i < cfg_size(d->cfg, strType.c_str()); ++i) { cfg_node = cfg_getnsec(d->cfg, strType.c_str(), i); if (cfg_getint(cfg_node, "id") != intNodeId) { // This isn't the one to skip fprintf(fp, "%s {\n", strType.c_str()); cfg_print_indent(cfg_node, fp, 1); fprintf(fp, "}\n"); } } } } fclose(fp); // Re-read config-file cfg_free(d->cfg); readConfig(&d->cfg); return TELLSTICK_SUCCESS; }
int parse_proxy_etrs(cfg_t *cfg, lisp_xtr_t *xtr) { int n,i; void *fwd_map_inf; /* PROXY-ETR CONFIG */ n = cfg_size(cfg, "proxy-etr"); for(i = 0; i < n; i++) { cfg_t *petr = cfg_getnsec(cfg, "proxy-etr", i); if (add_proxy_etr_entry(xtr->petrs, cfg_getstr(petr, "address"), cfg_getint(petr, "priority"), cfg_getint(petr, "weight")) == GOOD) { OOR_LOG(LDBG_1, "Added %s to proxy-etr list", cfg_getstr(petr, "address")); } else{ OOR_LOG(LERR, "Can't add proxy-etr %s", cfg_getstr(petr, "address")); } } /* Calculate forwarding info for petrs */ fwd_map_inf = xtr->fwd_policy->new_map_cache_policy_inf(xtr->fwd_policy_dev_parm,mcache_entry_mapping(xtr->petrs)); if (fwd_map_inf == NULL){ OOR_LOG(LDBG_1, "xtr_ctrl_construct: Couldn't create routing info for PeTRs!."); mcache_entry_del(xtr->petrs); return(BAD); } mcache_entry_set_routing_info(xtr->petrs,fwd_map_inf,xtr->fwd_policy->del_map_cache_policy_inf); return (GOOD); }
int main(void) { static cfg_opt_t section_opts[] = { CFG_STR("prop", 0, CFGF_NONE), CFG_END() }; cfg_opt_t opts[] = { CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI), CFG_END() }; const char *config_data = "section title_one { prop = 'value_one' }\n" "section title_two { prop = 'value_two' }\n" "section title_one { prop = 'value_one' }\n"; int rc; cfg_t *cfg = cfg_init(opts, CFGF_NONE); fail_unless(cfg); rc = cfg_parse_buf(cfg, config_data); fail_unless(rc == CFG_SUCCESS); cfg_rmtsec(cfg, "section", "title_two"); fail_unless(cfg_size(cfg, "section") == 1); fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0); cfg_free(cfg); cfg = cfg_init(opts, CFGF_NONE); fail_unless(cfg); rc = cfg_parse_buf(cfg, config_data); fail_unless(rc == CFG_SUCCESS); cfg_rmsec(cfg, "section"); fail_unless(cfg_size(cfg, "section") == 1); fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_two") == 0); cfg_free(cfg); return 0; }
// // E_ProcessGameProperties // // Main routine for this module. Process all gameproperties blocks. // void E_ProcessGameProperties(cfg_t *cfg) { unsigned int numProps = cfg_size(cfg, EDF_SEC_GAMEPROPS); E_EDFLogPuts("\t* Processing gameproperties\n"); for(unsigned int i = 0; i < numProps; i++) E_processGamePropsBlock(cfg_getnsec(cfg, EDF_SEC_GAMEPROPS, i)); }
static void configfile_read_units(void) { int i, nunits; struct unit *u; nunits = cfg_size(cfg, "unit"); for (i = 0; i < nunits; i++) { int nvariants, n; cfg_t *unit; const char *name; if (!(unit = cfg_getnsec(cfg, "unit", i))) BUG(); if (!(name = cfg_title(unit))) BUG(); if (!(nvariants = cfg_size(unit, "variant"))) continue; if (!(u = unit_add(name))) continue; for (n = 0; n < nvariants; n++) { cfg_t *variant; const char *vtitle; if (!(variant = cfg_getnsec(unit, "variant", n))) BUG(); if (!(vtitle = cfg_title(variant))) BUG(); if (!strcasecmp(vtitle, "default")) add_div(u, UNIT_DEFAULT, variant); else if (!strcasecmp(vtitle, "si")) add_div(u, UNIT_SI, variant); else quit("Unknown unit variant \'%s\'\n", vtitle); } } }
// // Processes "switch" blocks // void E_ProcessSwitches(cfg_t *cfg) { unsigned numswitches = cfg_size(cfg, EDF_SEC_SWITCH); E_EDFLogPrintf("\t* Processing switches\n" "\t\t%u switch(es) defined\n", numswitches); for(unsigned i = 0; i < numswitches; ++i) E_processSwitch(cfg_getnsec(cfg, EDF_SEC_SWITCH, i)); }
int main(void) { cfg_opt_t group_opts[] = { CFG_INT("number", 0, CFGF_NONE), CFG_INT("total", 0, CFGF_NONE), CFG_END() }; cfg_opt_t groups_opts[] = { CFG_STR("name", "Esmé", CFGF_NONE), CFG_SEC("group", group_opts, CFGF_TITLE | CFGF_MULTI), CFG_END() }; cfg_opt_t opts[] = { CFG_SEC("groups", groups_opts, CFGF_NONE), CFG_END() }; cfg_t *cfg, *sec; size_t i, j; cfg = cfg_init(opts, CFGF_NONE); if (!cfg || cfg_parse(cfg, CONF) == CFG_PARSE_ERROR) { perror("Failed parsing " CONF); return 1; } /* Iterate over the sections and print fields from each section. */ for (i = 0; i < cfg_size(cfg, "groups"); i++) { sec = cfg_getnsec(cfg, "groups", i); for (j = 0; j < cfg_size(sec, "group"); j++) { cfg_t *opt = cfg_getnsec(sec, "group", j); printf("group title: '%s'\n", cfg_title(opt)); printf("group number: %ld\n", cfg_getint(opt, "number")); printf("group total: %ld\n", cfg_getint(opt, "total")); printf("\n"); } } cfg_free(cfg); return 0; }
/* validates a bookmark section (host option required) */ int conf_validate_bookmark(cfg_t *cfg, cfg_opt_t *opt) { cfg_t *bookmark = cfg_opt_getnsec(opt, cfg_opt_size(opt) - 1); if(cfg_size(bookmark, "host") == 0) { cfg_error(cfg, "missing required option 'host' in bookmark"); return -1; } return 0; }
static void print_system(cfg_t *provider) { size_t i; printf("\n"); printf("system %s\n", cfg_title(provider)); print_string(provider, "username", 1); print_string(provider, "password", 1); if (cfg_size(provider, "alias")) { printf(" alias "); for (i = 0; i < cfg_size(provider, "alias"); i++) printf("%s%s", i != 0 ? ", " : "", cfg_getnstr(provider, "alias", i)); printf("\n"); } }
static void parse_elp_list(cfg_t *cfg, shash_t *ht) { elp_node_t *enode; elp_t *elp; lisp_addr_t *laddr; char *name; int i, j; for(i = 0; i < cfg_size(cfg, "explicit-locator-path"); i++) { cfg_t *selp = cfg_getnsec(cfg, "explicit-locator-path", i); name = cfg_getstr(selp, "elp-name"); elp = elp_type_new(); for (j = 0; j < cfg_size(selp, "elp-node");j++) { cfg_t *senode = cfg_getnsec(selp, "elp-node", j); enode = xzalloc(sizeof(elp_node_t)); enode->addr = lisp_addr_new(); if (lisp_addr_ip_from_char(cfg_getstr(senode, "address"), enode->addr) != GOOD) { elp_node_del(enode); OOR_LOG(LDBG_1, "parse_elp_list: Couldn't parse ELP node %s", cfg_getstr(senode, "address")); continue; } enode->L = cfg_getbool(senode, "lookup") ? 1 : 0; enode->P = cfg_getbool(senode, "probe") ? 1 : 0; enode->S = cfg_getbool(senode, "strict") ? 1: 0; glist_add_tail(enode, elp->nodes); } laddr = lisp_addr_new_lafi(LM_AFI_LCAF); lisp_addr_lcaf_set_type(laddr, LCAF_EXPL_LOC_PATH); lisp_addr_lcaf_set_addr(laddr, elp); OOR_LOG(LDBG_1, "Configuration file: parsed explicit-locator-path: %s", lisp_addr_to_char(laddr)); shash_insert(ht, strdup(name), laddr); } }
void read_cfg_section(section_t *section, cfg_t *cfg_sec, std::stringstream &errors) { static const char *funcname = "conf::read_cfg_section"; for (auto &entry : *section) { char *name = const_cast<char *>(entry.first.c_str()); bool required = entry.second.is_required(); switch (entry.second.what_type()) { case val_type::integer: { integer_t val; if (0 == (val = cfg_getint(cfg_sec, name))) { if (required) errors << "Required int-option '" << name << "' is not set." << std::endl; } else entry.second.set(val); break; } case val_type::string: { char *val; if (nullptr == (val = cfg_getstr(cfg_sec, name))) { if (required) errors << "Required str-option '" << name << "' is not set." << std::endl; } else entry.second.set(val); break; } case val_type::multistring: { if (nullptr == cfg_getstr(cfg_sec, name)) { if (required) errors << "Required multistr-option '" << name << "' is not set." << std::endl; } else { int count = cfg_size(cfg_sec, name); multistring_t strs; for (int i = 0; i < count; i++) strs.push_back(std::move(string_t(cfg_getnstr(cfg_sec, name, i)))); entry.second.set(strs); } break; } case val_type::section: read_cfg_section(entry.second.get<conf::section_t *>(), cfg_getsec(cfg_sec, name), errors); break; case val_type::unknown: throw logging::error(funcname, "Val with unknown type in section: %s", name); } } }
// // E_CollectInventory // // Pre-creates and hashes by name the inventory definitions, for purpose // of mutual and forward references. // void E_CollectInventory(cfg_t *cfg) { static int currentID = 1; unsigned int i; unsigned int numInventory; // number of inventory defs defined by the cfg inventory_t *newInvDefs = NULL; // get number of inventory definitions defined by the cfg numInventory = cfg_size(cfg, EDF_SEC_INVENTORY); // echo counts E_EDFLogPrintf("\t\t%u inventory items defined\n", numInventory); if(numInventory) { // allocate inventory structures for the new thingtypes newInvDefs = estructalloc(inventory_t, numInventory); numInventoryDefs += numInventory; // create metatables for(i = 0; i < numInventory; i++) newInvDefs[i].meta = new MetaTable("inventory"); } // build hash tables E_EDFLogPuts("\t\tBuilding inventory hash tables\n"); // cycle through the thingtypes defined in the cfg for(i = 0; i < numInventory; i++) { cfg_t *invcfg = cfg_getnsec(cfg, EDF_SEC_INVENTORY, i); const char *name = cfg_title(invcfg); // This is a new inventory, whether or not one already exists by this name // in the hash table. For subsequent addition of EDF inventory defs at // runtime, the hash table semantics of "find newest first" take care of // overriding, while not breaking objects that depend on the original // definition of the inventory type for inheritance purposes. inventory_t *inv = &newInvDefs[i]; // initialize name inv->name = estrdup(name); // add to name hash inv_namehash.addObject(inv); // create ID number and add to hash table inv->numkey = currentID++; inv_numhash.addObject(inv); } }