static void typecheck_config_ifgrouplist(config_setting_t *list) { assert(config_setting_is_list(list)); for (int i = 0; i < config_setting_length(list); i++) { config_setting_t *ifgroup = config_setting_get_elem(list, i); if (!config_setting_is_group(ifgroup)) die("Interface group lists must only contain groups."); typecheck_config_ifgroup(ifgroup); } }
/** * @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 config_setting_copy(config_setting_t *parent, const config_setting_t *src) { if (!config_setting_is_group(parent) && !config_setting_is_list(parent)) return CONFIG_FALSE; if (config_setting_is_aggregate(src)) { libconfig->setting_copy_aggregate(parent, src); } else { libconfig->setting_copy_simple(parent, src); } return CONFIG_TRUE; }
common_type_error_t fieldbus_mac_init(config_setting_t* configuration) { const char* interface; assert(configuration != NULL); if (!config_setting_is_group(configuration)) { logging_adapter_info("The MAC configuration isn't a group"); return COMMON_TYPE_ERR_CONFIG; } if (!config_setting_lookup_string(configuration, DLOGG_MAC_CONFIG_INTERFACE, &interface)) { logging_adapter_info("Can't find the \"%s\" string configuration directive " "inside MAC group", DLOGG_MAC_CONFIG_INTERFACE); return COMMON_TYPE_ERR_CONFIG; } return dlogg_mac_initTTY(interface); }
void config_setting_copy_aggregate (config_setting_t *parent, const config_setting_t *src) { config_setting_t *newAgg; int i, n; newAgg = config_setting_add (parent, config_setting_name (src), config_setting_type (src)); if (newAgg == NULL) return; n = config_setting_length (src); for (i = 0; i < n; i++) { if (config_setting_is_group (src)) { config_setting_copy_simple (newAgg, config_setting_get_elem (src, i)); } else { config_setting_copy_elem (newAgg, config_setting_get_elem (src, i)); } } }
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); }
/** * @details Assumes that the channelConf reference isn't null. */ int pfm_addChannel(config_setting_t* channelConf) { const char* driver = ""; config_setting_t *address; int appIndex = -1; assert(channelConf != NULL); if (!config_setting_is_group(channelConf)) { logging_adapter_info("The given channel configuration isn't a valid group " "of directives"); return -1; } if (!config_setting_lookup_string(channelConf, PFM_CONFIG_TYPE, &driver)) { logging_adapter_info("Can't load the \"%s\" string configuration " "directive.", PFM_CONFIG_TYPE); return -1; } address = config_setting_get_member(channelConf, PFM_CONFIG_ADDRESS); if (address == NULL ) { logging_adapter_info("Can't obtain the \"%s\" channel configuration's " "\"%s\" member", driver, PFM_CONFIG_ADDRESS); return -1; } // obtain the device driver appIndex = pfm_getAppIndex(driver); if (appIndex < 0 ) { logging_adapter_debug("Try to load application module \"%s\"", driver); appIndex = pfm_loadAppModule(driver); } if (appIndex < 0 ) { return -1; } return pfm_newChannel(appIndex, address); }
/** * @brief Extracts the MAC module's names and loads the modules. * @param configuration The root configuration containing the mac member. The * root configuration has to be a group setting always. * @return The status of the operation */ common_type_error_t pfm_init(config_setting_t* configuration) { config_setting_t *mac; common_type_error_t err; int i; assert(config_setting_is_group(configuration)); // Fetch and check the MAC module configuration sections mac = config_setting_get_member(configuration, PFM_CONFIG_MAC); if (mac == NULL ) { logging_adapter_info("Can't locate the \"%s\" list directive.", PFM_CONFIG_MAC); return COMMON_TYPE_ERR_CONFIG; } if (!config_setting_is_list(mac)) { logging_adapter_info("The \"%s\" directive isn't a list.", PFM_CONFIG_MAC); return COMMON_TYPE_ERR_CONFIG; } // Allocate the mac module vector. pfm_macVectorLength = config_setting_length(mac); assert(pfm_macVectorLength >= 0); pfm_macVector = malloc(pfm_macVectorLength * sizeof(pfm_macVector[0])); if (pfm_macVector == NULL ) { return COMMON_TYPE_ERR; } memset(pfm_macVector, 0, pfm_macVectorLength * sizeof(pfm_macVector[0])); // Load the mac modules for (i = 0; i < pfm_macVectorLength; i++) { err = pfm_installMacModule(config_setting_get_elem(mac, i), i); if (err != COMMON_TYPE_SUCCESS) { return err; } } return COMMON_TYPE_SUCCESS; }
/** * Reads and parses an entry from the quest_db. * * @param cs The config setting containing the entry. * @param n The sequential index of the current config setting. * @param source The source configuration file. * @return The parsed quest entry. * @retval NULL in case of errors. */ struct quest_db *quest_read_db_sub(struct config_setting_t *cs, int n, const char *source) { struct quest_db *entry = NULL; struct config_setting_t *t = NULL; int i32 = 0, quest_id; const char *str = NULL; /* * Id: Quest ID [int] * Name: Quest Name [string] * TimeLimit: Time Limit (seconds) [int, optional] * Targets: ( [array, optional] * { * MobId: Mob ID [int] * Count: [int] * }, * ... (can repeated up to MAX_QUEST_OBJECTIVES times) * ) * Drops: ( * { * ItemId: Item ID to drop [int] * Rate: Drop rate [int] * MobId: Mob ID to match [int, optional] * }, * ... (can be repeated) * ) */ if (!libconfig->setting_lookup_int(cs, "Id", &quest_id)) { ShowWarning("quest_read_db: Missing id in \"%s\", entry #%d, skipping.\n", source, n); return NULL; } if (quest_id < 0 || quest_id >= MAX_QUEST_DB) { ShowWarning("quest_read_db: Invalid quest ID '%d' in \"%s\", entry #%d (min: 0, max: %d), skipping.\n", quest_id, source, n, MAX_QUEST_DB); return NULL; } if (!libconfig->setting_lookup_string(cs, "Name", &str) || !*str) { ShowWarning("quest_read_db_sub: Missing Name in quest %d of \"%s\", skipping.\n", quest_id, source); return NULL; } CREATE(entry, struct quest_db, 1); entry->id = quest_id; //safestrncpy(entry->name, str, sizeof(entry->name)); if (libconfig->setting_lookup_int(cs, "TimeLimit", &i32)) // This is an unsigned value, do not check for >= 0 entry->time = (unsigned int)i32; if ((t=libconfig->setting_get_member(cs, "Targets")) && config_setting_is_list(t)) { int i, len = libconfig->setting_length(t); for (i = 0; i < len && entry->objectives_count < MAX_QUEST_OBJECTIVES; i++) { // Note: We ensure that objectives_count < MAX_QUEST_OBJECTIVES because // quest_log (as well as the client) expect this maximum size. struct config_setting_t *tt = libconfig->setting_get_elem(t, i); int mob_id = 0, count = 0; if (!tt) break; if (!config_setting_is_group(tt)) continue; if (!libconfig->setting_lookup_int(tt, "MobId", &mob_id) || mob_id <= 0) continue; if (!libconfig->setting_lookup_int(tt, "Count", &count) || count <= 0) continue; RECREATE(entry->objectives, struct quest_objective, ++entry->objectives_count); entry->objectives[entry->objectives_count-1].mob = mob_id; entry->objectives[entry->objectives_count-1].count = count; } }
/** * @brief Loads the given module, adds its handler to the list of known modules * and initializes it. * @details If the configuration is invalid, an appropriate error message will * be reported. * @param modConfig The module's group configuration. * @param index The index within the MAC vector structure to populate. * @return The status of the operation */ static inline common_type_error_t pfm_installMacModule( config_setting_t *modConfig, const unsigned int index) { const char* name = ""; char* errStr; /* Used to fix the POSIX - C99 conflict */ union { void* vPtr; fieldbus_mac_init_t initPtr; fieldbus_mac_sync_t syncPtr; fieldbus_mac_free_t freePtr; } ptrWorkaround; common_type_error_t err; fieldbus_mac_init_t init; assert(modConfig != NULL); assert(index < pfm_macVectorLength); if (!config_setting_is_group(modConfig)) { logging_adapter_info("The \"%s\" directive contains an invalid list entry", PFM_CONFIG_MAC); return COMMON_TYPE_ERR_CONFIG; } if (!config_setting_lookup_string(modConfig, PFM_CONFIG_NAME, &name)) { logging_adapter_info( "Can't find the \"%s\" string directive inside the MAC " "module directive", PFM_CONFIG_NAME); return COMMON_TYPE_ERR_CONFIG; } assert(name != NULL); logging_adapter_debug("Try to load MAC module \"%s\"", name); pfm_macVector[index].handler = dlopen(name, RTLD_NOW | RTLD_GLOBAL); if (pfm_macVector[index].handler == NULL ) { logging_adapter_info("Can't load \"%s\": %s", name, dlerror()); return COMMON_TYPE_ERR_LOAD_MODULE; } // Load end execute init function (void) dlerror(); ptrWorkaround.vPtr = dlsym(pfm_macVector[index].handler, "fieldbus_mac_init"); init = ptrWorkaround.initPtr; errStr = dlerror(); if (errStr != NULL ) { logging_adapter_info("Can't successfully load the \"%s\" " "function: %s", FIELDBUS_MAC_INIT_NAME, errStr); return COMMON_TYPE_ERR_LOAD_MODULE; } err = init(modConfig); if (err != COMMON_TYPE_SUCCESS) { return err; } // Load free and sync (void) dlerror(); ptrWorkaround.vPtr = dlsym(pfm_macVector[index].handler, FIELDBUS_MAC_SYNC_NAME); pfm_macVector[index].sync = ptrWorkaround.syncPtr; errStr = dlerror(); if (errStr != NULL ) { logging_adapter_info("Can't successfully load the \"%s\" " "function: %s", FIELDBUS_MAC_SYNC_NAME, errStr); return COMMON_TYPE_ERR_LOAD_MODULE; } (void) dlerror(); ptrWorkaround.vPtr = dlsym(pfm_macVector[index].handler, FIELDBUS_MAC_FREE_NAME); pfm_macVector[index].free = ptrWorkaround.freePtr; errStr = dlerror(); if (errStr != NULL ) { logging_adapter_info("Can't successfully load the \"%s\" " "function: %s", FIELDBUS_MAC_FREE_NAME, errStr); return COMMON_TYPE_ERR_LOAD_MODULE; } assert(pfm_macVector[index].free != NULL); assert(pfm_macVector[index].sync != NULL); return COMMON_TYPE_SUCCESS; }
/** * @brief Parses the given configuration structure * @details The parameters set will be stored into the address structure but * availability of addresses will remain unchecked. * @param addr The address structure to store the results * @param addressConfig The configuration to read * @return The status of the operation */ static inline common_type_error_t dlogg_stdval_parseAddress( dlogg_stdval_addr_t * addr, config_setting_t *addressConfig) { common_type_error_t err; int lineID = 0, channel, controller = 1; const char * prefix; assert(addressConfig != NULL); assert(addr != NULL); if (!config_setting_is_group(addressConfig)) { logging_adapter_info("The address setting is not a group directive"); return COMMON_TYPE_ERR_CONFIG; } // Use default value, if not set config_setting_lookup_int(addressConfig, DLOGG_STDVAL_CONFIG_LINE, &lineID); if (lineID < 0 || lineID > 255) { logging_adapter_info("Value of %s, %i out of range [0,255]", DLOGG_STDVAL_CONFIG_LINE, (int) lineID); return COMMON_TYPE_ERR_CONFIG; } if (!config_setting_lookup_int(addressConfig, DLOGG_STDVAL_CONFIG_CHN_NR, &channel)) { logging_adapter_info("Cant find the \"%s\" int directive within the " "address group", DLOGG_STDVAL_CONFIG_CHN_NR); return COMMON_TYPE_ERR_CONFIG; } if (channel < 1 || channel > 256) { logging_adapter_info("Value of %s, %i out of range [1,256]", DLOGG_STDVAL_CONFIG_CHN_NR, (int) channel); return COMMON_TYPE_ERR_CONFIG; } // Use default value, if not set config_setting_lookup_int(addressConfig, DLOGG_STDVAL_CONFIG_CONTROLLER, &controller); if (controller < 1 || controller > 2) { logging_adapter_info("Value of %s, %i out of range [1,2]", DLOGG_STDVAL_CONFIG_CONTROLLER, (int) controller); return COMMON_TYPE_ERR_CONFIG; } if (!config_setting_lookup_string(addressConfig, DLOGG_STDVAL_CONFIG_CHN_PREFIX, &prefix)) { logging_adapter_info("Can't find the \"%s\" string directive within the " "address group", DLOGG_STDVAL_CONFIG_CHN_PREFIX); return COMMON_TYPE_ERR_CONFIG; } err = dlogg_stdval_getPrefixID(&addr->prefixID, prefix); if (err != COMMON_TYPE_SUCCESS) return err; addr->lineID = lineID; addr->channelID = channel - 1; addr->controllerID = controller - 1; // May be needed for detailed debugging ... // logging_adapter_debug("Parsed address: lineID=%u, channelID=%u, " // "controllerID=%u, prefix=0x%02x", (unsigned) addr->lineID, // (unsigned) addr->channelID, (unsigned) addr->controllerID, // (unsigned) addr->prefixID); return COMMON_TYPE_SUCCESS; }
/********************* return RET_NOK on error *********************/ ret_code_t entry_copy_config(config_setting_t * source, config_setting_t * dest) { config_setting_t * new_source; config_setting_t * new_dest; int index = -1; int int_value; long long long_value; double double_value; const char * string; while((new_source=config_setting_get_elem(source,index+1))!= NULL ) { index++; if(config_setting_is_group(new_source)) { if(!entry_copy_aggregate(new_source,dest,CONFIG_TYPE_GROUP)) { return RET_NOK; } } else if(config_setting_is_array(new_source)) { if(!entry_copy_aggregate(new_source,dest,CONFIG_TYPE_ARRAY)) { return RET_NOK; } } else if(config_setting_is_list(new_source)) { if(!entry_copy_aggregate(new_source,dest,CONFIG_TYPE_LIST)) { return RET_NOK; } } else { switch(config_setting_type(new_source)) { case CONFIG_TYPE_INT: int_value = config_setting_get_int(new_source); new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_INT); config_setting_set_int(new_dest,int_value); continue; case CONFIG_TYPE_INT64: long_value = config_setting_get_int64(new_source); new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_INT64); config_setting_set_int64(new_dest,long_value); continue; case CONFIG_TYPE_FLOAT: double_value = config_setting_get_float(new_source); new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_FLOAT); config_setting_set_float(new_dest,double_value); continue; case CONFIG_TYPE_BOOL: int_value = config_setting_get_bool(new_source); new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_BOOL); config_setting_set_bool(new_dest,int_value); continue; case CONFIG_TYPE_STRING: string = config_setting_get_string(new_source); new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_STRING); config_setting_set_string(new_dest,string); continue; default: return RET_NOK; } } } return RET_OK; }
static const char *test_libconfig_setting_types(void) { struct config_t config; struct config_setting_t *t; const char *input = "/* Test File */\n" "Setting_Int: 1;\n" "Setting_Int64: 1L;\n" "Setting_Float: 1.0;\n" "Setting_Bool: true;\n" "Setting_String: \"1\";\n" "Setting_Array: [ ];\n" "Setting_Group: { };\n" "Setting_List: ( );\n" "/* End test file */\n"; if (libconfig->read_string(&config, input) == CONFIG_FALSE) { libconfig->destroy(&config); return "Unable to parse configuration."; } if (config_setting_type(config.root) != CONFIG_TYPE_GROUP) { libconfig->destroy(&config); return "CONFIG_TYPE_GROUP failed."; } if ((t = libconfig->lookup(&config, "Setting_Int")) == NULL || config_setting_type(t) != CONFIG_TYPE_INT || config_setting_is_group(t) || config_setting_is_array(t) || config_setting_is_list(t) || config_setting_is_aggregate(t) || !config_setting_is_scalar(t) || !config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_INT failed."; } if ((t = libconfig->lookup(&config, "Setting_Int64")) == NULL || config_setting_type(t) != CONFIG_TYPE_INT64 || config_setting_is_group(t) || config_setting_is_array(t) || config_setting_is_list(t) || config_setting_is_aggregate(t) || !config_setting_is_scalar(t) || !config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_INT64 failed."; } if ((t = libconfig->lookup(&config, "Setting_Float")) == NULL || config_setting_type(t) != CONFIG_TYPE_FLOAT || config_setting_is_group(t) || config_setting_is_array(t) || config_setting_is_list(t) || config_setting_is_aggregate(t) || !config_setting_is_scalar(t) || !config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_FLOAT failed."; } if ((t = libconfig->lookup(&config, "Setting_Bool")) == NULL || config_setting_type(t) != CONFIG_TYPE_BOOL || config_setting_is_group(t) || config_setting_is_array(t) || config_setting_is_list(t) || config_setting_is_aggregate(t) || !config_setting_is_scalar(t) || config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_BOOL failed."; } if ((t = libconfig->lookup(&config, "Setting_String")) == NULL || config_setting_type(t) != CONFIG_TYPE_STRING || config_setting_is_group(t) || config_setting_is_array(t) || config_setting_is_list(t) || config_setting_is_aggregate(t) || !config_setting_is_scalar(t) || config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_STRING failed."; } if ((t = libconfig->lookup(&config, "Setting_Array")) == NULL || config_setting_type(t) != CONFIG_TYPE_ARRAY || config_setting_is_group(t) || !config_setting_is_array(t) || config_setting_is_list(t) || !config_setting_is_aggregate(t) || config_setting_is_scalar(t) || config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_ARRAY failed."; } if ((t = libconfig->lookup(&config, "Setting_Group")) == NULL || config_setting_type(t) != CONFIG_TYPE_GROUP || !config_setting_is_group(t) || config_setting_is_array(t) || config_setting_is_list(t) || !config_setting_is_aggregate(t) || config_setting_is_scalar(t) || config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_GROUP failed."; } if ((t = libconfig->lookup(&config, "Setting_List")) == NULL || config_setting_type(t) != CONFIG_TYPE_LIST || config_setting_is_group(t) || config_setting_is_array(t) || !config_setting_is_list(t) || !config_setting_is_aggregate(t) || config_setting_is_scalar(t) || config_setting_is_number(t) ) { libconfig->destroy(&config); return "CONFIG_TYPE_LIST failed."; } libconfig->destroy(&config); return NULL; }
static int processCommand(void *event_header, void *event) { int count = 0; int entry_count = 0; int total_root_entries = 0; int total_child_entries = 0; config_setting_t *config_root = NULL; config_setting_t *config_child = NULL; config_setting_t *config_entry = NULL; const char *current_header = NULL; const char *current_event = NULL; int int_setting = 0; int status_file; char status_file_path[MSQ_SIZE]; config_root = config_root_setting(&config); total_root_entries = config_setting_length(config_root); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&lockConfig); for(count = 0; count < total_root_entries; count++) { config_child = config_setting_get_elem(config_root, count); if(!config_setting_is_group(config_child) || !config_setting_lookup_bool(config_child, "register", &int_setting) || int_setting == 0 || !(config_entry = config_setting_get_member(config_child, "header")) || (current_header = config_setting_get_string_elem(config_entry, common_data.diff_commands)) == NULL || strcmp(current_header, (char *)event_header) != 0) continue; current_header = config_setting_name(config_child); total_child_entries = config_setting_length(config_child); for(entry_count = 0; entry_count < total_child_entries; entry_count++) { config_entry = config_setting_get_elem(config_child, entry_count); if((current_event = config_setting_get_string_elem(config_entry, common_data.diff_commands)) == 0 || strcmp(current_event, (char *)event) != 0) continue; snprintf(status_file_path, MAX_PATH_LENGTH, "%s/%s.%s", TEMPLOCATION, PROGRAM_NAME, current_header); if((status_file = open(status_file_path, O_RDWR|O_CREAT|O_CLOEXEC, LOCKMODE)) < 0) { pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); return EXIT_FAILURE; } current_event = config_setting_name(config_entry); ftruncate(status_file, 0); write(status_file, current_event, strlen(current_event)); close(status_file); statusInfo.update(current_header, current_event); syslog(LOG_DEBUG, "Status update event (header): %s (%s)", current_event, current_header); pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); return EXIT_SUCCESS; } } pthread_mutex_unlock(&lockConfig); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); return EXIT_SUCCESS; } /* serial_process_ascii */
void load_he_item(const char * filename, struct lt_db_t * db) { int i = 0; int cnt = 0; int status = 0; /* error reporting */ int offset = 0; char error[4096]; /* libconfig */ config_t * cfg = calloc(1, sizeof(config_t)); config_setting_t * item_db = NULL; config_setting_t * item_row = NULL; config_setting_t * item_sub = NULL; /* item_db */ he_item_t item; config_init(cfg); /* read item_db.conf */ status = config_read_file(cfg, filename); if(status != CONFIG_TRUE) { offset = sprintf(error, "%s;%d;%s", config_error_file(cfg), config_error_line(cfg), config_error_text(cfg)); error[offset] = '\0'; /*exit_abt(error);*/ } /* retrieve data */ item_db = config_lookup(cfg, "item_db"); if(config_setting_is_list(item_db)) { cnt = config_setting_length(item_db); sqlite3_exec(db->db, "BEGIN IMMEDIATE TRANSACTION;", NULL, NULL, NULL); for(i = 0; i < cnt; i++) { item_row = config_setting_get_elem(item_db, i); memset(&item, 0, sizeof(he_item_t)); config_setting_lookup_int(item_row, "Id", &item.id); config_setting_lookup_string(item_row, "AegisName", &item.aegis); config_setting_lookup_string(item_row, "Name", &item.name); config_setting_lookup_int(item_row, "Type", &item.type); config_setting_lookup_int(item_row, "Buy", &item.buy); config_setting_lookup_int(item_row, "Sell", &item.sell); config_setting_lookup_int(item_row, "Weight", &item.weight); config_setting_lookup_int(item_row, "Atk", &item.atk); config_setting_lookup_int(item_row, "Matk", &item.matk); config_setting_lookup_int(item_row, "Def", &item.def); config_setting_lookup_int(item_row, "Range", &item.range); config_setting_lookup_int(item_row, "Slots", &item.slots); config_setting_lookup_int(item_row, "Job", &item.job); config_setting_lookup_int(item_row, "Upper", &item.upper); config_setting_lookup_int(item_row, "Gender", &item.gender); config_setting_lookup_int(item_row, "Loc", &item.loc); config_setting_lookup_int(item_row, "WeaponLv", &item.weaponlv); item_sub = config_setting_get_member(item_row, "EquipLv"); if(item_sub != NULL && config_setting_is_list(item_sub) == CONFIG_TRUE) { item.equiplv[EQUIP_MIN] = config_setting_get_int_elem(item_sub, EQUIP_MIN); item.equiplv[EQUIP_MAX] = config_setting_get_int_elem(item_sub, EQUIP_MAX); } else if(item_sub != NULL) { config_setting_lookup_int(item_sub, "EquipLv", &item.equiplv[EQUIP_MIN]); item.equiplv[EQUIP_MAX] = item.equiplv[EQUIP_MIN]; } config_setting_lookup_bool(item_row, "Refine", &item.refine); config_setting_lookup_int(item_row, "View", &item.view); config_setting_lookup_bool(item_row, "BindOnEquip", &item.bindonequip); config_setting_lookup_bool(item_row, "BuyingStore", &item.buyingstore); config_setting_lookup_int(item_row, "Delay", &item.delay); item_sub = config_setting_get_member(item_row, "Trade"); if(item_sub != NULL && config_setting_is_group(item_sub) == CONFIG_TRUE) { config_setting_lookup_int(item_row, "override", &item.trade[TRADE_OVERRIDE]); config_setting_lookup_bool(item_row, "nodrop", &item.trade[TRADE_NODROP]); config_setting_lookup_bool(item_row, "notrade", &item.trade[TRADE_NOTRADE]); config_setting_lookup_bool(item_row, "partneroverride", &item.trade[TRADE_PARTNEROVERRIDE]); config_setting_lookup_bool(item_row, "noselltonpc", &item.trade[TRADE_NOSELLTONPC]); config_setting_lookup_bool(item_row, "nocart", &item.trade[TRADE_NOCART]); config_setting_lookup_bool(item_row, "nostorage", &item.trade[TRADE_NOSTORAGE]); config_setting_lookup_bool(item_row, "nogstorage", &item.trade[TRADE_NOGSTORAGE]); config_setting_lookup_bool(item_row, "nomail", &item.trade[TRADE_NOMAIL]); config_setting_lookup_bool(item_row, "noauction", &item.trade[TRADE_NOAUCTION]); } item_sub = config_setting_get_member(item_row, "Nouse"); if(item_sub != NULL && config_setting_is_group(item_sub) == CONFIG_TRUE) { config_setting_lookup_int(item_row, "override", &item.trade[NOUSE_OVERRIDE]); config_setting_lookup_bool(item_row, "sitting", &item.trade[NOUSE_SITTING]); } item_sub = config_setting_get_member(item_row, "Stack"); if(item_sub != NULL && config_setting_is_list(item_sub) == CONFIG_TRUE) { item.equiplv[STACK_AMOUNT] = config_setting_get_int_elem(item_sub, STACK_AMOUNT); item.equiplv[STACK_TYPE] = config_setting_get_int_elem(item_sub, STACK_TYPE); } config_setting_lookup_string(item_row, "Script", &item.script); config_setting_lookup_string(item_row, "OnEquipScript", &item.onequipscript); config_setting_lookup_string(item_row, "OnUnequipScript", &item.onunequipscript); if(item.script == NULL) item.script = ""; if(item.onequipscript == NULL) item.onequipscript = ""; if(item.onunequipscript == NULL) item.onunequipscript = ""; he_item_db_insert(db, &item); } sqlite3_exec(db->db, "COMMIT TRANSACTION;", NULL, NULL, NULL); } else { /*exit_abt("item configuration file root setting.");*/ } config_destroy(cfg); free(cfg); }