static config_setting_t *interface_group_for(const char *ifname) { assert(config_setting_is_list(app_config)); config_setting_t *default_if_conf = NULL; for (int i = 0; i < config_setting_length(app_config); i++) { config_setting_t *cur = config_setting_get_elem(app_config, i); config_setting_t *cur_ifname = config_setting_get_member(cur, "interface"); if (cur_ifname != NULL) { const char *cur_ifname_str = config_setting_get_string(cur_ifname); assert(cur_ifname_str != NULL); if (strcmp(cur_ifname_str, ifname) == 0) return cur; } config_setting_t *cur_is_default = config_setting_get_member(cur, "default"); if ( default_if_conf == NULL && cur_is_default != NULL && config_setting_get_bool(cur_is_default) ) { default_if_conf = cur; } } return default_if_conf; }
/*! \brief read interval setting from local config */ static int read_interval_setting(config_setting_t * setting_interval, int32_t * out_min, int32_t * out_max) { config_setting_t * setting_min = config_setting_get_member(setting_interval, "min"); config_setting_t * setting_max = config_setting_get_member(setting_interval, "max"); if (setting_min == NULL || setting_max == NULL) { message(LOG_ERROR, FACILITY_CONFIG, "In interval is missing one of theses keys: min or max\n"); return CONFIG_FALSE; } if ((config_setting_type(setting_min) != CONFIG_TYPE_INT) || (config_setting_type(setting_max) != CONFIG_TYPE_INT)) { message(LOG_ERROR, FACILITY_CONFIG, "In interval has one of these keys: min or max wrong type, is should be int.\n"); return CONFIG_FALSE; } *out_min = config_setting_get_int(setting_min); *out_max = config_setting_get_int(setting_max); if (*out_min > *out_max) { message(LOG_ERROR, FACILITY_CONFIG, "Limits of interval are invalid. (max=%d min=%d)\n", *out_min, *out_max); return CONFIG_FALSE; } return CONFIG_TRUE; }
int qtbl_if_set(config_setting_t *icsp, struct qtbl_t *qip, struct qtbl_e ifsnmpoid, struct qtbl_e iflocation) { config_setting_t *tcsp; int ret = 0; /* to determine default value for each if*/ if((tcsp = config_setting_get_member(icsp, "host")) != NULL){ if(strlen(config_setting_get_string(tcsp)) == 0){ printf("vifset Wrong hostname \n"); }else{ strncpy(ifsnmpoid.data.snmp.host, config_setting_get_string(tcsp), 128); } } if((tcsp = config_setting_get_member(icsp, "community")) != NULL){ if(strlen(config_setting_get_string(tcsp)) == 0){ printf("vifset Wrong community \n"); }else{ strncpy(ifsnmpoid.data.snmp.community, config_setting_get_string(tcsp), 128); } } if(strlen(ifsnmpoid.data.snmp.host) > 0 && strlen(ifsnmpoid.data.snmp.community) > 0) ifsnmpoid.flag = QSNMPOID; if((tcsp = config_setting_get_member(icsp, "location")) != NULL){ iflocation = qtblloc_set(tcsp); if(vifsetdebug && iflocation.flag == QSTATIC) printf("vifset if location: %08x\n", iflocation.data.val); } /* getting in/out configuration*/ if((tcsp = config_setting_get_member(icsp, "in")) != NULL){ ret += qtbl_if_io_set(tcsp, qip->in, ifsnmpoid, iflocation); } if((tcsp = config_setting_get_member(icsp, "out")) != NULL){ ret += qtbl_if_io_set(tcsp, qip->out, ifsnmpoid, iflocation); } return ret; }
/*! \brief read thread seetting from local config */ static int read_thread_setting(config_setting_t * setting, thread_limit * limit) { config_setting_t * config_max_total = config_setting_get_member(setting, "max_total"); config_setting_t * config_min_spare = config_setting_get_member(setting, "min_spare"); config_setting_t * config_max_spare = config_setting_get_member(setting, "max_spare"); if (config_max_total == NULL || config_min_spare == NULL || config_max_spare == NULL) { message(LOG_ERROR, FACILITY_CONFIG, "In thread setting is missing one of theses keys: max_total, min_spare or max_spare.\n"); return CONFIG_FALSE; } if ((config_setting_type(config_max_total) != CONFIG_TYPE_INT) || (config_setting_type(config_min_spare) != CONFIG_TYPE_INT) || (config_setting_type(config_max_spare) != CONFIG_TYPE_INT)) { message(LOG_ERROR, FACILITY_CONFIG, "In thread setting has on of theses keys: max_total, min_spare or max_spare wrong type, it should be int.\n"); return CONFIG_FALSE; } limit->max_total = config_setting_get_int(config_max_total); limit->min_spare = config_setting_get_int(config_min_spare); limit->max_spare = config_setting_get_int(config_max_spare); return (is_valid_thread_limit(limit, "") == true) ? CONFIG_TRUE : CONFIG_FALSE; }
int main(int argc, char **argv) { static const char *output_file = "updated.cfg"; config_t cfg; config_setting_t *root, *setting, *movie; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if(! config_read_file(&cfg, "example.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return(EXIT_FAILURE); } /* Find the 'movies' setting. Add intermediate settings if they don't yet * exist. */ root = config_root_setting(&cfg); setting = config_setting_get_member(root, "inventory"); if(!setting) setting = config_setting_add(root, "inventory", CONFIG_TYPE_GROUP); setting = config_setting_get_member(setting, "movies"); if(!setting) setting = config_setting_add(setting, "movies", CONFIG_TYPE_LIST); /* Create the new movie entry. */ movie = config_setting_add(setting, NULL, CONFIG_TYPE_GROUP); setting = config_setting_add(movie, "title", CONFIG_TYPE_STRING); config_setting_set_string(setting, "Buckaroo Banzai"); setting = config_setting_add(movie, "media", CONFIG_TYPE_STRING); config_setting_set_string(setting, "DVD"); setting = config_setting_add(movie, "price", CONFIG_TYPE_FLOAT); config_setting_set_float(setting, 12.99); setting = config_setting_add(movie, "qty", CONFIG_TYPE_INT); config_setting_set_float(setting, 20); /* Write out the updated configuration. */ if(! config_write_file(&cfg, output_file)) { fprintf(stderr, "Error while writing file.\n"); config_destroy(&cfg); return(EXIT_FAILURE); } fprintf(stderr, "Updated configuration successfully written to: %s\n", output_file); config_destroy(&cfg); return(EXIT_SUCCESS); }
int logging_setup(struct module *module, config_setting_t *conf) { config_setting_t *setting; const char *val; int num; if (config.debug < 2) skeeter_vlog = &skeeter_syslog; num = LOG_ERR; setting = config_setting_get_member(conf, "level"); if (setting) { struct level *level; val = config_setting_get_string(setting); for (level = level_table; level->name; level++) { if (!strcasecmp(val, level->name)) break; } if (!level->name) { skeeter_log(LOG_ERR, "Could not parse loglevel value '%s'", val); return 1; } num = level->level; } config.loglevel = num; num = LOG_MAIL; setting = config_setting_get_member(conf, "facility"); if (setting) { struct facility *facility; val = config_setting_get_string(setting); for (facility = facility_table; facility->name; facility++) { if (!strcasecmp(val, facility->name)) break; } if (!facility->name) { skeeter_log(LOG_ERR, "Could not parse log facility value '%s'", val); return 1; } num = facility->facility; } config.facility = num; openlog("skeeter", LOG_PID, config.facility); event_set_log_callback(skeeter_event_log); return 0; }
/*! \brief read volume tree node settings */ static int read_volume_tree_node_setting(config_setting_t * node_setting) { int rv; const char * node_key; rv = config_setting_lookup_string(node_setting, "node", &node_key); if (rv != CONFIG_TRUE) { message(LOG_INFO, FACILITY_CONFIG, "No node key in hierarchy tree in shared config found.\n"); return rv; } config_setting_t * children = config_setting_get_member(node_setting, "children"); if (children == NULL) return CONFIG_TRUE; int i; config_setting_t * child; for (i = 0; (child = config_setting_get_elem(children, i)) != NULL; ++i) { rv = read_volume_tree_node_setting(child); if (rv != CONFIG_TRUE) { message(LOG_INFO, FACILITY_CONFIG, "Failed to read hierarchy tree from shared config.\n"); return rv; } } return CONFIG_TRUE; }
config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } #if 0 /* https://github.com/HerculesWS/Hercules/pull/136#discussion_r6363319 * With this code, accidental duplicate keys would cause the file parsing to fail * (would cause several issues during runtime on file reloads), while libconfig's code * has no problems with duplicate members so it was ducked out -- TODO: looking now though * I'd think it could be useful to have it display a warning or error message when finding * duplicate keys instead of silently moving on. [Ind] */ if(config_setting_get_member(parent, name) != NULL) return(NULL); /* already exists */ #endif return(config_setting_create(parent, name, type)); }
void print_layouts(int num_frame) { config_setting_t *category_list, *category, *layout_list, *layout; config_t layout_config; int layout_length, i; const char* ascii_image; config_init(&layout_config); config_read_file(&layout_config, "./layout.cfg"); category_list = config_lookup(&layout_config, "application.layout_group"); category = config_setting_get_elem(category_list, num_frame - MIN_NUM_FRAME); layout_list = config_setting_get_member(category, "layout"); layout_length = config_setting_length(layout_list); for(i = 0; i < layout_length; i++) { layout = config_setting_get_elem(layout_list, i); config_setting_lookup_string(layout, "image", &ascii_image); printf(" %c)\n", 'a' + i); printf("%s\n", ascii_image); } config_destroy(&layout_config); }
void config_setting_copy_simple(config_setting_t *parent, const config_setting_t *src) { if (config_setting_is_aggregate(src)) { config_setting_copy_aggregate(parent, src); } else { config_setting_t *set; if( config_setting_get_member(parent, config_setting_name(src)) != NULL ) return; if ((set = config_setting_add(parent, config_setting_name(src), config_setting_type(src))) == NULL) return; if (CONFIG_TYPE_INT == config_setting_type(src)) { config_setting_set_int(set, config_setting_get_int(src)); config_setting_set_format(set, src->format); } else if (CONFIG_TYPE_INT64 == config_setting_type(src)) { config_setting_set_int64(set, config_setting_get_int64(src)); config_setting_set_format(set, src->format); } else if (CONFIG_TYPE_FLOAT == config_setting_type(src)) { config_setting_set_float(set, config_setting_get_float(src)); } else if (CONFIG_TYPE_STRING == config_setting_type(src)) { config_setting_set_string(set, config_setting_get_string(src)); } else if (CONFIG_TYPE_BOOL == config_setting_type(src)) { config_setting_set_bool(set, config_setting_get_bool(src)); } } }
LIBCONFIG_API config_setting_t *config_lookup(const config_t *config, const char *path) { const char *p = path; config_setting_t *setting = config->root, *found; for(;;) { while(*p && strchr(PATH_TOKENS, *p)) p++; if(! *p) break; found = config_setting_get_member(setting, p); if(! found) break; setting = found; while(! strchr(PATH_TOKENS, *p)) p++; } return(*p ? NULL : setting); }
config_setting_t *config_lookup_from(config_setting_t *setting, const char *path) { const char *p = path; config_setting_t *found; for(;;) { while(*p && strchr(PATH_TOKENS, *p)) p++; if(! *p) break; if(*p == '[') found = config_setting_get_elem(setting, atoi(++p)); else found = config_setting_get_member(setting, p); if(! found) break; setting = found; while(! strchr(PATH_TOKENS, *p)) p++; } return(*p ? NULL : setting); }
// {{{ session_is_valid_sessid() int session_is_valid_sessid(const char *sessid) { // TODO use timestamp: session not expires. struct config_t cfg; config_init(&cfg); config_setting_t *cs; config_setting_t *vs; if(!config_read_file(&cfg, OD_SESSION_FILE)) return 0; int i=0; for(i=0; ;i++) { if( !(cs = config_setting_get_elem(cfg.root, i)) ) break; if( !(vs = config_setting_get_member(cs, "sessid")) ) continue; const char *res = config_setting_get_string(vs); if(res) if(strcmp(res, sessid)==0) { config_destroy(&cfg); return 1; } } config_destroy(&cfg); return 0; }
config_setting_t *config_setting_add(config_setting_t *parent, const char *name, int type) { if((type < CONFIG_TYPE_NONE) || (type > CONFIG_TYPE_LIST)) return(NULL); if(! parent) return(NULL); if((parent->type == CONFIG_TYPE_ARRAY) || (parent->type == CONFIG_TYPE_LIST)) name = NULL; if(name) { if(! __config_validate_name(name)) return(NULL); } config_setting_t *setting = config_setting_get_member(parent, name); if (setting != NULL) { if ((setting->type != type && type != CONFIG_TYPE_NONE) || (setting->type != CONFIG_TYPE_GROUP && setting->type != CONFIG_TYPE_ARRAY && setting->type != CONFIG_TYPE_LIST)) return(NULL); /* already exists */ else return setting; /* merge with existing config */ } return(config_setting_create(parent, name, type)); }
/** * Checks if player group can use @/#command * @param group_id ID of the group * @param command Command name without @/# and params * @param type enum AtCommanndType { COMMAND_ATCOMMAND = 1, COMMAND_CHARCOMMAND = 2 } */ bool pc_group_can_use_command(int group_id, const char *command, AtCommandType type) { int result = 0; config_setting_t *commands = NULL; GroupSettings *group = NULL; if (pc_group_has_permission(group_id, PC_PERM_USE_ALL_COMMANDS)) return true; if ((group = id2group(group_id)) == NULL) return false; commands = group->commands; if (commands != NULL) { config_setting_t *cmd = NULL; // <commandname> : <bool> (only atcommand) if (type == COMMAND_ATCOMMAND && config_setting_lookup_bool(commands, command, &result)) return (bool)result; // <commandname> : [ <bool>, <bool> ] ([ atcommand, charcommand ]) if ((cmd = config_setting_get_member(commands, command)) != NULL && config_setting_is_aggregate(cmd) && config_setting_length(cmd) == 2) return (bool)config_setting_get_bool_elem(cmd, AtCommandType2idx(type)); } return false; }
bool parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u) { int rc = true; config_setting_t *ue_param_setting = NULL; ue_param_setting = config_setting_get_member(ue_setting, SIM); if (ue_param_setting == NULL) { printf("Check SIM section for UE%d. EXITING...\n", user_id); return false; } rc = config_setting_lookup_string(ue_param_setting, MSIN, &u->msin); if (rc != 1 || strlen(u->msin) > 10 || strlen(u->msin) < 9) { printf("Check SIM MSIN section for UE%d. Exiting\n", user_id); return false; } rc = config_setting_lookup_string(ue_param_setting, USIM_API_K, &u->usim_api_k); if (rc != 1) { printf("Check SIM USIM_API_K section for UE%d. Exiting\n", user_id); return false; } rc = config_setting_lookup_string(ue_param_setting, OPC, &u->opc); if (rc != 1) { printf("Check SIM OPC section for UE%d. Exiting\n", user_id); return false; } rc = config_setting_lookup_string(ue_param_setting, MSISDN, &u->msisdn); if (rc != 1) { printf("Check SIM MSISDN section for UE%d. Exiting\n", user_id); return false; } return true; }
int get_layout(struct layout_t* out, int num_frame, int id_layout) { config_setting_t *category_list, *category, *layout_list, *layout, *frame_list, *frame; config_setting_t *pos, *size; config_t layout_config; int frame_length, i; out->num_frames = num_frame; out->perc_to_pixel = 0; out->frames = (struct frame_t*) malloc (num_frame * sizeof(struct frame_t)); config_init(&layout_config); config_read_file(&layout_config, "./layout.cfg"); category_list = config_lookup(&layout_config, "application.layout_group"); category = config_setting_get_elem(category_list, num_frame - MIN_NUM_FRAME); layout_list = config_setting_get_member(category, "layout"); layout = config_setting_get_elem(layout_list, id_layout); frame_list = config_setting_get_member(layout, "frame"); frame_length = config_setting_length(frame_list); for(i = 0; i < frame_length; i++) { frame = config_setting_get_elem(frame_list, i); pos= config_setting_get_member(frame, "pos"); size = config_setting_get_member(frame, "size"); if (config_setting_lookup_float(pos, "x", &(out->frames[i].pos_x))==CONFIG_FALSE) printf("pos.x:\tONFIG_FALSE\n"); if ( config_setting_lookup_float(pos, "y", &(out->frames[i].pos_y))==CONFIG_FALSE) printf("pos.y:\tONFIG_FALSE\n"); if ( config_setting_lookup_float(size, "w", &(out->frames[i].width))==CONFIG_FALSE) printf("size.w:\tONFIG_FALSE\n"); if ( config_setting_lookup_float(size, "h", &(out->frames[i].height))==CONFIG_FALSE) printf("size.h:\tONFIG_FALSE\n"); config_setting_lookup_float(frame, "rot", &(out->frames[i].rot)); } config_destroy(&layout_config); return 0; }
int read_threads_config(config_t * config) { int rv; config_setting_t * setting_threads = config_lookup(config, "threads"); if (setting_threads == NULL) { message(LOG_INFO, FACILITY_CONFIG, "No threads section was found in local config.\n"); return CONFIG_TRUE; } config_setting_t * setting_thread; setting_thread = config_setting_get_member(setting_threads, "kernel_thread"); if (setting_thread != NULL) { rv = read_thread_setting(setting_thread, &zfs_config.threads.kernel_thread_limit); if (rv != CONFIG_TRUE) { message(LOG_ERROR, FACILITY_CONFIG, "In threads section failed to read thread limit for kernel thread.\n"); return CONFIG_FALSE; } } setting_thread = config_setting_get_member(setting_threads, "network_thread"); if (setting_thread != NULL) { rv = read_thread_setting(setting_thread, &zfs_config.threads.network_thread_limit); if (rv != CONFIG_TRUE) { message(LOG_ERROR, FACILITY_CONFIG, "In threads section failed to read thread limit for network thread.\n"); return CONFIG_FALSE; } } setting_thread = config_setting_get_member(setting_threads, "update_thread"); if (setting_thread != NULL) { rv = read_thread_setting(setting_thread, &zfs_config.threads.update_thread_limit); if (rv != CONFIG_TRUE) { message(LOG_ERROR, FACILITY_CONFIG, "In threads section failed to read thread limit for update thread.\n"); return CONFIG_FALSE; } } return CONFIG_TRUE; }
int config_setting_lookup_float (const config_setting_t * setting, const char *name, double *value) { config_setting_t *member = config_setting_get_member (setting, name); if (!member) return (CONFIG_FALSE); return (__config_setting_get_float (member, value)); }
gboolean config_setting_remove(config_setting_t * parent, const char * name) { config_setting_t *s = config_setting_get_member(parent, name); if (s == NULL) return FALSE; _config_setting_t_remove(s); return TRUE; }
int config_setting_lookup_int64 (const config_setting_t * setting, const char *name, long long *value) { config_setting_t *member = config_setting_get_member (setting, name); if (!member) return (CONFIG_FALSE); return (__config_setting_get_int64 (member, value)); }
int read_system_specific_config(config_t * config) { config_setting_t * system_settings = config_lookup(config, "system"); if (system_settings == NULL) { message(LOG_INFO, FACILITY_CONFIG, "System config section is missing in local config\n"); /* System config is optional section */ return CONFIG_TRUE; } config_setting_t * member; /*mlock*/ member = config_setting_get_member(system_settings, "mlock"); if (member != NULL) { if (config_setting_type(member) != CONFIG_TYPE_BOOL) { message(LOG_ERROR, FACILITY_CONFIG, "In system local config mlock key has wrong type, it should be bool.\n"); return CONFIG_FALSE; } zfs_config.mlock_zfsd = config_setting_get_bool(member); } /*metadata_tree_depth*/ member = config_setting_get_member(system_settings, "metadata_tree_depth"); if (member != NULL) { if (config_setting_type(member) != CONFIG_TYPE_INT) { message(LOG_ERROR, FACILITY_CONFIG, "In system local config metadata_tree_depth key has wrong type, it should be int.\n"); return CONFIG_FALSE; } zfs_config.metadata.metadata_tree_depth = config_setting_get_int(member); if (!is_valid_metadata_tree_depth(zfs_config.metadata.metadata_tree_depth)) { message(LOG_ERROR, FACILITY_CONFIG, "In system local config metadata_tree_depth key is out of range (min=%d max=%d current=%d).\n", MIN_METADATA_TREE_DEPTH, MAX_METADATA_TREE_DEPTH, zfs_config.metadata.metadata_tree_depth); return CONFIG_FALSE; } } return CONFIG_TRUE; }
int config_setting_lookup_int(const struct config_setting_t *setting, const char *name, int *value) { struct config_setting_t *member = config_setting_get_member(setting, name); if(! member) return(CONFIG_FALSE); return(__config_setting_get_int(member, value)); }
/** * Attempt to create a global channel from the channel config * @param chan: Channel list * @param tmp_chan: Temporary channel data * @param i: Index * @return True on success or false on failure */ bool channel_read_sub(config_setting_t *chan, struct Channel *tmp_chan, uint8 i) { config_setting_t *group_list = NULL; int delay = 1000, autojoin = 0, leave = 1, chat = 1, color_override = 0, self_notif = 1, join_notif = 0, leave_notif = 0; int type = CHAN_TYPE_PUBLIC, group_count = 0; const char *name = NULL, *password = NULL, *alias = NULL, *color_str = "Default", *type_str = NULL; if (tmp_chan == NULL) return false; if (!config_setting_lookup_string(chan, "name", &name)) { ShowError("Please input channel 'name' at '%s' line '%d'! Skipping...\n", chan->file, chan->line); return false; } if (config_setting_lookup_string(chan, "type", &type_str) && !script_get_constant(type_str, &type)) { ShowError("Invalid channel type %s at '%s' line '%d'! Skipping...\n", type_str, chan->file, chan->line); return false; } config_setting_lookup_string(chan, "password", &password); config_setting_lookup_string(chan, "alias", &alias); config_setting_lookup_string(chan, "color", &color_str); config_setting_lookup_int(chan, "delay", &delay); config_setting_lookup_bool(chan, "autojoin", &autojoin); config_setting_lookup_bool(chan, "leave", &leave); config_setting_lookup_bool(chan, "chat", &chat); config_setting_lookup_bool(chan, "color_override", &color_override); config_setting_lookup_bool(chan, "self_notif", &self_notif); config_setting_lookup_bool(chan, "join_notif", &join_notif); config_setting_lookup_bool(chan, "leave_notif", &leave_notif); safestrncpy(tmp_chan->name,name+1,sizeof(tmp_chan->name)); if (password) safestrncpy(tmp_chan->pass,password,sizeof(tmp_chan->pass)); else tmp_chan->pass[0] = '\0'; safestrncpy(tmp_chan->alias,alias?alias:name,sizeof(tmp_chan->alias)); tmp_chan->msg_delay = delay; tmp_chan->type = (enum Channel_Type)type; tmp_chan->color = channel_getColor(color_str); tmp_chan->opt = (autojoin ? CHAN_OPT_AUTOJOIN : 0) | (leave ? CHAN_OPT_CAN_LEAVE : 0) | (chat ? CHAN_OPT_CAN_CHAT : 0) | (color_override ? CHAN_OPT_COLOR_OVERRIDE : 0) | (self_notif ? CHAN_OPT_ANNOUNCE_SELF : 0) | (join_notif ? CHAN_OPT_ANNOUNCE_JOIN : 0) | (leave_notif ? CHAN_OPT_ANNOUNCE_LEAVE : 0); if ((group_list = config_setting_get_member(chan, "groupid")) && (group_count = config_setting_length(group_list)) > 0) { int j; CREATE(tmp_chan->groups, unsigned short, group_count); tmp_chan->group_count = group_count; for (j = 0; j < group_count; j++) { int groupid = config_setting_get_int_elem(group_list, j); tmp_chan->groups[j] = groupid; } }
//------------------------------------------------------------------------------ int general_settings_load_configuration (config_setting_t *setting) { config_setting_t *s = NULL ; init_general_settings() ; s = config_setting_get_member(setting, "path_1_wire_directory") ; if (s != NULL) { g_string_assign (path_1_wire_directory, config_setting_get_string(s)) ; } ; s = config_setting_get_member(setting, "path_data_directory") ; if (s != NULL) { g_string_assign (path_data_directory, config_setting_get_string(s)) ; } ; s = config_setting_get_member(setting, "write_samples_interval") ; if (s != NULL) write_samples_interval = config_setting_get_int(s) ; return 0 ; } ;
/** * @param[in] root Root section of config. * @param[in] zconf Config handle. * @return True on success. */ bool zconfig_load_sections(const config_setting_t *root, zconfig_t *zconf) { // global section config_setting_t *section = config_setting_get_member(root, ZCFG_SECTION_GLOBAL); if (!section) { ZLOG(LOG_ERR, "config: %s section not found", ZCFG_SECTION_GLOBAL); return false; } if (0 != zconfig_global_load(section, zconf)) { ZLOG(LOG_ERR, "config: failed to load %s section", ZCFG_SECTION_GLOBAL); return false; } // all other sections parse as scopes u_int sections_count = (u_int) config_setting_length(root); // global section + minimum one scope section if (sections_count < 2) { ZLOG(LOG_ERR, "config: no scopes found"); return false; } utarray_init(&zconf->scopes, &ut_ptr_icd); for (u_int i = 0; i < sections_count; i++) { section = config_setting_get_elem(root, i); if (!config_setting_is_group(section)) { continue; } if (0 == strcmp(section->name, ZCFG_SECTION_GLOBAL)) { continue; } for (size_t j = 0; j < utarray_len(&zconf->scopes); j++) { zconfig_scope_t *sc = *(zconfig_scope_t **) utarray_eltptr(&zconf->scopes, j); if (0 == strcasecmp(sc->name, section->name)) { ZLOG(LOG_ERR, "config: duplicate scope %s", section->name); return false; } } zconfig_scope_t *scope = malloc(sizeof(*scope)); if (0 == zconfig_scope_load(section, scope)) { utarray_push_back(&zconf->scopes, &scope); ZLOG(LOG_DEBUG, "config: loaded scope %s", scope->name); } else { zconfig_scope_destroy(scope); free(scope); ZLOG(LOG_ERR, "config: failed to load scope %s", section->name); return false; } } return true; }
int read_this_node_local_config(config_t * config) { const char * local_node_name; config_setting_t * local_node_setting = config_lookup(config, "local_node"); if (local_node_setting == NULL) { message(LOG_ERROR, FACILITY_CONFIG, "Local node section is missing, please add it to local config.\n"); return CONFIG_FALSE; } config_setting_t * setting_node_id = config_setting_get_member(local_node_setting, "id"); config_setting_t * setting_node_name = config_setting_get_member(local_node_setting, "name"); if (setting_node_id == NULL || setting_node_name == NULL) { message(LOG_ERROR, FACILITY_CONFIG, "In local node section node name or node id are missing, please add them to local config.\n"); return CONFIG_FALSE; } if (config_setting_type(setting_node_id) != CONFIG_TYPE_INT) { message(LOG_ERROR, FACILITY_CONFIG, "In local node section key id has wrong type, it should be int.\n"); return CONFIG_FALSE; } if (config_setting_type(setting_node_name) != CONFIG_TYPE_STRING) { message(LOG_ERROR, FACILITY_CONFIG, "In local node section key name has wrong type, it should be string.\n"); return CONFIG_FALSE; } zfs_config.this_node.node_id = config_setting_get_int(setting_node_id); local_node_name = config_setting_get_string(setting_node_name); xmkstring(&(zfs_config.this_node.node_name), local_node_name); /*read port configuration*/ zfs_config.this_node.host_port = read_tcp_port_setting(local_node_setting); return CONFIG_TRUE; }
static void typecheck_config_ifgroup(config_setting_t *ifgroup) { assert(config_setting_is_group(ifgroup)); config_setting_t *dflt = config_setting_get_member(ifgroup, "default"); config_setting_t *mac = config_setting_get_member(ifgroup, "mac"); config_setting_t *interface = config_setting_get_member(ifgroup, "interface"); if (dflt == NULL && interface == NULL) die("Interface group must contain either \"default\" or \"interface\" elements."); if (dflt != NULL && interface != NULL) die("Interface group must contain only one of \"default\" and \"interface\" elements."); if (mac == NULL) die("Interface group must contain a \"mac\" element."); if (dflt != NULL && config_setting_type(dflt) != CONFIG_TYPE_BOOL) die("Interface group element \"default\" must be a bool."); if (interface != NULL && config_setting_type(interface) != CONFIG_TYPE_STRING) die("Interface group element \"interface\" must be a string."); if (!config_setting_is_array(mac)) die("Interface group element \"mac\" must be an array."); typecheck_config_array(mac); }
/*! \brief read volume tree layout */ static int config_setting_read_vol_layout(config_setting_t * vol_layout, volume_entry * ve, const char * node_name) { config_setting_t * layout_tree = config_setting_get_member(vol_layout, "tree"); if (layout_tree == NULL) { message(LOG_ERROR, FACILITY_CONFIG, "Missing layout information of volume %s.", ve->name.str); return CONFIG_FALSE; } return config_setting_process_tree(layout_tree, ve, NULL, node_name); }
int qtbl_if_io_set(config_setting_t *iocsp, struct qtbl_e *qiop, struct qtbl_e ifsnmpoid, struct qtbl_e iflocation) { int ret = 0; config_setting_t *tcsp; if((tcsp = config_setting_get_member(iocsp, "bw")) != NULL){ ret += qtbl32_set(tcsp, &qiop[SIRENS_LINK], ifsnmpoid); } if((tcsp = config_setting_get_member(iocsp, "octets")) != NULL){ ret += qtbl32_set(tcsp, &qiop[SIRENS_OBYTES], ifsnmpoid); } if((tcsp = config_setting_get_member(iocsp, "queue")) != NULL){ ret += qtbl32_set(tcsp, &qiop[SIRENS_QLEN], ifsnmpoid); } if((tcsp = config_setting_get_member(iocsp, "location")) != NULL){ qiop[SIRENS_LOCATION] = qtblloc_set(tcsp); ret += 1; }else if(iflocation.flag == QSTATIC) { qiop[SIRENS_LOCATION] = iflocation; ret += 1; } return ret; }