int mst_config_load(const char *conf_path) { int rv = -1; config_init(&g_config); rv = config_read_file(&g_config, conf_path); if (CONFIG_FALSE == rv) { fprintf(stderr, "Failed to load config: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config)); return -1; } if (CONFIG_TRUE != (rv = mst_read_version(&g_config))) { fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config)); return -1; } if (CONFIG_TRUE != (rv = mst_read_type(&g_config))) { fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config)); return -1; } if (CONFIG_TRUE != (rv = mst_read_globals(&g_config))) { fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config)); return -1; } if (CONFIG_TRUE != (rv = mst_read_policy_details(&g_config))) { fprintf(stderr, "Error: %s @ %d\n", config_error_text(&g_config), config_error_line(&g_config)); return -1; } return 0; }
static void load_configuration_from_file(psOSCdSystem *s) { const char *cfname = get_configuration_filename_path(s); if (configuration_file_exists(cfname)) { config_t config_settings; int i = 0; /* * NOTE: the order in which configuration variables get evaluated is * extremely significant for proper initialization. Do not tamper with * it unless you know what you are doing. */ ConfigVar config_vars[] = { { "verbose", &s->is_verbose, int_handler }, { "slave", &s->is_slave, int_handler }, { "phasespace_server", &s->phasespace, string_handler }, { "osc_server", &s->osc_server_name, string_handler }, { "frequency", s, system_frequency_handler }, { "num_markers", &s->data.u.markers.num_markers, num_markers_handler }, { "rigids", &s->data.u.rigids, rigids_handler }, }; const int num_elems = sizeof(config_vars)/sizeof(ConfigVar); /* num_elems = number of elements in config vars */ int res = CONFIG_TRUE; config_init(&config_settings); if ((res = config_read_file(&config_settings, cfname)) == CONFIG_FALSE) fatal("configuration - line %d: %s (configuration error)", config_error_line(&config_settings), config_error_text(&config_settings)); for (i = 0; i < num_elems; ++i) { res = (*(config_vars[i].handler))(&config_settings, config_vars[i].path, &config_vars[i]); if (res == CONFIG_FALSE) { if (config_error_text(&config_settings) != (const char *) NULL) fatal("configuration - line %d: %s (configuration error)", config_error_line(&config_settings), config_error_text(&config_settings)); else psOSCd_debug("configuration: missing variable %s", config_vars[i].path); } } config_destroy(&config_settings); } }
static void read_config_from_file (const char *filename) { FILE *fp; fp = fopen (filename, "r"); if (fp != NULL) { config_t conf; config_init (&conf); /* if (verbose) fprintf (stderr, "%s: reading configuration from %s\n", guestfs_int_program_name, filename); */ if (config_read (&conf, fp) == CONFIG_FALSE) { fprintf (stderr, _("%s: %s: line %d: error parsing configuration file: %s\n"), guestfs_int_program_name, filename, config_error_line (&conf), config_error_text (&conf)); exit (EXIT_FAILURE); } if (fclose (fp) == -1) { perror (filename); exit (EXIT_FAILURE); } config_lookup_bool (&conf, "read_only", &read_only); config_destroy (&conf); } }
// TODO: audit exit routes to "unset"/"unalloc" values. int upd8_config_parse(upd8_config_t *config, const char *config_file) { // TODO: check that config is not null. config_t *cfg = malloc(sizeof(config_t)); config_init(cfg); if (!config_read_file(cfg, config_file)) { fprintf(stderr, "%s:%d - %s\n", config_error_file(cfg), config_error_line(cfg), config_error_text(cfg)); config_destroy(cfg); return EXIT_FAILURE; } config->cfg = cfg; config_setting_t *settings; settings = config_lookup(cfg, settings_path); if (settings == NULL) { fprintf(stderr, "Unable to find %s in %s\n", settings_path, config_file); config_destroy(cfg); return EXIT_FAILURE; } config->num_sources = config_setting_length(settings); config->sources = malloc(config->num_sources * sizeof(upd8_source_t)); for (int i = 0; i < config->num_sources; ++i) { config_setting_t *individual_config = config_setting_get_elem(settings, i); upd8_source_parse(&(config->sources[i]), individual_config); } return 0; }
int readCfg (void) { config_t cfg; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_read_file(&cfg, config_file_name)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } if (!config_lookup_int(&cfg, "onTemp", &onTemp)) printf("\nNo 'onTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "offTemp", &offTemp)) printf("\nNo 'offTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "highTemp", &highTemp)) printf("\nNo 'highTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "onHum", &onHum)) printf("\nNo 'onHum' setting in configuration file."); if (!config_lookup_int(&cfg, "offHum", &offHum)) printf("\nNo 'offHum' setting in configuration file."); if (!config_lookup_int(&cfg, "webOR", &webOR)) printf("\nNo 'webOR' setting in configuration file."); if (!config_lookup_int(&cfg, "tempState", &tempState)) printf("\nNo 'tempState' setting in configuration file."); if (!config_lookup_int(&cfg, "humState", &humState)) printf("\nNo 'humState' setting in configuration file."); config_destroy(&cfg); return 0; }
/*! \brief log error from config reader */ static void config_log_error(const config_t * config) { message(LOG_EMERG, FACILITY_CONFIG, "Failed to read config file at line %d (%s)\n", config_error_line(config), config_error_text(config)); }
int configure_server(spade_server* server, char* configuration_path, unsigned int override_port) { config_t configuration_struct, *configuration; configuration = &configuration_struct; config_init(configuration); if (!config_read_file(configuration, configuration_path)) { log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_ERROR, "Configuration error: %s:%d - %s", configuration_path, config_error_line(configuration), config_error_text(configuration)); config_destroy(configuration); return(EXIT_FAILURE); } configure_hostname(server, configuration); configure_port(server, override_port, configuration); configure_reverse_lookups(server, configuration); configure_static_file_path(server, configuration); configure_dynamic_file_paths(server, configuration); configure_dynamic_handlers(server, configuration); config_destroy(configuration); return 0; }
struct scenario_parameters read_scenario_parameters(char *scenario_file) { // configuration variable config_t cfg; config_init(&cfg); // string pointing to scenario file char scenario[100]; strcpy(scenario, "scenarios/"); strcat(scenario, scenario_file); // Read the file. If there is an error, report it and exit. if (!config_read_file(&cfg, scenario)) { printf("Error reading %s on line %i\n", scenario, config_error_line(&cfg)); printf("%s\n", config_error_text(&cfg)); config_destroy(&cfg); exit(1); } // Read scenario parameters struct scenario_parameters sp; int tmpI; double tmpD; config_lookup_int(&cfg, "num_nodes", &tmpI); sp.num_nodes = tmpI; config_lookup_float(&cfg, "run_time", &tmpD); sp.runTime = (time_t)tmpD; config_destroy(&cfg); return sp; } // End readScConfigFile()
void Init(HINSTANCE i_thisInstanceOfTheApplication, HINSTANCE i_thisIsNothing, char* i_commandLineArguments, int i_initialWindowDisplayState) { config_t cfg; int Screenwidth; int Screenheight; config_init(&cfg); if(! config_read_file(&cfg, "config.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); } config_lookup_int(&cfg, "ScreenWidth", &Screenwidth); config_lookup_int(&cfg, "ScreenHeight", &Screenheight); config_destroy(&cfg); Renderer::width=Screenwidth; Renderer::height=Screenheight; Singleton<Time>::getInstance().Init(); Singleton<Physics>::getInstance().Init(); Singleton<Renderer>::getInstance().Init( i_thisInstanceOfTheApplication, i_thisIsNothing, i_commandLineArguments, i_initialWindowDisplayState); Singleton<World>::getInstance().Init(); Singleton<Collision>::getInstance().Init(); Singleton<EventHandler>::getInstance().Init(); SoundManager::Manager().Init(); }
static int qdb_config() { config_t cfg; config_setting_t *cfg_qdb; config_setting_t *cfg_interfaces; int status = 0; config_init(&cfg); if (config_read_file(&cfg,CONFPATH) == CONFIG_FALSE) goto err; cfg_qdb = config_lookup(&cfg,"qdb"); if (cfg_qdb == NULL) goto err; cfg_interfaces = config_lookup(&cfg,"qdb/interfaces"); if (cfg_interfaces == NULL) goto err; goto done; err: printerr(config_error_text(&cfg)); status = -1; done: config_destroy(&cfg); return status; }
/** * Load the configuration of Sally * @param argc number of arguments * @param argv arguments */ static void sally_load_config(int argc, char **argv) { char* cfg_file = NULL; int ch; /* Check for config file in command line */ while ((ch = getopt_long(argc, argv, OPTSTRING, longopts, NULL)) != -1) { switch (ch) { case 'c': cfg_file = optarg; break; case '?': print_usage(); exit(EXIT_SUCCESS); break; default: /* empty */ break; } } /* Init and load configuration */ config_init(&cfg); if (cfg_file != NULL) { if (config_read_file(&cfg, cfg_file) != CONFIG_TRUE) fatal("Could not read configuration (%s in line %d)", config_error_text(&cfg), config_error_line(&cfg)); } /* Check configuration */ if (!config_check(&cfg)) { exit(EXIT_FAILURE); } }
int main () { config_t cfg; laser_container_t *lasers = NULL; config_init (&cfg); if(! config_read_file(&cfg, "test.cfg")) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); exit(EXIT_FAILURE); } lasers = laser_container_cfg_parse_ctor(&cfg); config_destroy (&cfg); if (lasers == NULL) { fprintf(stderr, "Failed to parse laser configuration.\n"); exit (EXIT_FAILURE); } printf ("nlasers: %d\n", lasers->nlasers); laser_container_dtor(lasers); return 0; }
int main(int argc, char **argv) { char SRVR[1000]; char *p=SRVR; config_t config; config_init(&config); if ( config_read_file(&config, "/etc/snowflake.conf") == CONFIG_TRUE ) { printf("PARt 1\n"); const config_setting_t *setting = config_lookup(&config, "server"); if( setting != NULL) { p = config_setting_get_string(setting); printf("opened file\n"); printf("SERVER ADDRESS = %s\n",p); } else { printf("ERROR\n"); } } else { fprintf(stderr, "%s:%d - %s\n", config_error_file(&config), config_error_line(&config), config_error_text(&config)); config_destroy(&config); return(1); } }
static void config_print_error(char * file, const config_t * config) { werr(LOGUSER,"libconfig error %s@%d : %s\n", file, config_error_line(config), config_error_text(config)); }
int readCfgState (void) { config_t cfg; config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ if (!config_read_file(&cfg, config_state_path)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* */ if (!config_lookup_int(&cfg, "tempState", &tempState)) printf("\nNo 'tempState' setting in configuration file."); if (!config_lookup_int(&cfg, "humState", &humState)) printf("\nNo 'humState' setting in configuration file."); if (!config_lookup_int(&cfg, "relay1o", &relay1o)) printf("\nNo 'relay1o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay2o", &relay2o)) printf("\nNo 'relay2o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay3o", &relay3o)) printf("\nNo 'relay3o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay4o", &relay4o)) printf("\nNo 'relay4o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay5o", &relay5o)) printf("\nNo 'relay5o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay6o", &relay6o)) printf("\nNo 'relay6o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay7o", &relay7o)) printf("\nNo 'relay7o' setting in configuration file."); if (!config_lookup_int(&cfg, "relay8o", &relay8o)) printf("\nNo 'relay8o' setting in configuration file."); if (!config_lookup_int(&cfg, "RHeatTS", &RHeatTS)) printf("\nNo 'RHeatTS' setting in configuration file."); if (!config_lookup_int(&cfg, "RHumTS", &RHumTS)) printf("\nNo 'RHumTS' setting in configuration file."); if (!config_lookup_int(&cfg, "RHepaTS", &RHepaTS)) printf("\nNo 'RHepaTS' setting in configuration file."); if (!config_lookup_int(&cfg, "RFanTS", &RFanTS)) printf("\nNo 'RFanTS' setting in configuration file."); if (!config_lookup_float(&cfg, "wfactor", &wfactor)) printf("\nNo 'wfactor' setting in configuration file."); config_destroy(&cfg); return 0; }
/** * Load configuration file. * @param[in] path Configuration file location. * @param[in,out] zconf Parsed configuration storage. * @return True on success. */ bool zconfig_load(const char *path, zconfig_t *zconf) { if (NULL == path) { ZLOG(LOG_ERR, "config: configuration file not specified"); return false; } bool loaded = false; config_t config; config_init(&config); if (!config_read_file(&config, path)) { ZLOG(LOG_ERR, "config: failed to parse %s (error: %s at %d line)", path, config_error_text(&config), config_error_line(&config)); goto end; } const config_setting_t *root = config_root_setting(&config); if (!zconfig_load_sections(root, zconf)) { zconfig_destroy(zconf); } else { loaded = true; } end: config_destroy(&config); return loaded; }
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); }
static int read_settings_file(config_t *cfg, const char *filename) { int ret; /* Read the file. If there is an error, report it and exit. */ ret = config_read_file(cfg, filename); if (ret != CONFIG_TRUE) { fprintf(stderr, "%s ", config_error_file(cfg)); fprintf(stderr, "%d ", config_error_line(cfg)); fprintf(stderr, "%s ", config_error_text(cfg)); fprintf(stderr, "%s:%d - %s\n", config_error_file(cfg), config_error_line(cfg), config_error_text(cfg)); } return ret; }
static void read_config(void) { char *filename = NULL; FILE *file = open_config_file(&filename); if (config_read(config, file) != CONFIG_TRUE) die("%s:%d %s", filename, config_error_line(config), config_error_text(config)); if (fclose(file) == EOF) perror_die("fclose"); }
int writeCfgCond(void) { config_t cfg; config_setting_t *tminTemp = 0; config_setting_t *tmaxTemp = 0; config_setting_t *tminHum = 0; config_setting_t *tmaxHum = 0; config_setting_t *twebOR = 0; config_init(&cfg); if (!config_read_file(&cfg, config_cond_path)) { printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } /* lookup variables in config file */ tminTemp = config_lookup(&cfg, "minTemp"); tmaxTemp = config_lookup(&cfg, "maxTemp"); tminHum = config_lookup(&cfg, "minHum"); tmaxHum = config_lookup(&cfg, "maxHum"); twebOR = config_lookup(&cfg, "webOR"); /* get variables from config file then print the variables that changed */ if (config_setting_get_int(tminTemp) != minTemp) { printf("\nminTemp: %i -> ", config_setting_get_int(tminTemp)); config_setting_set_int(tminTemp, minTemp); printf("%i", config_setting_get_int(tminTemp)); } if (config_setting_get_int(tmaxTemp) != maxTemp) { printf("\nmaxTemp: %i -> ", config_setting_get_int(tmaxTemp)); config_setting_set_int(tmaxTemp, maxTemp); printf("%i", config_setting_get_int(tmaxTemp)); } if (config_setting_get_int(tminHum) != minHum) { printf("\nminHum: %i -> ", config_setting_get_int(tminHum)); config_setting_set_int(tminHum, minHum); printf("%i", config_setting_get_int(tminHum)); } if (config_setting_get_int(tmaxHum) != maxHum) { printf("\nmaxHum: %i -> ", config_setting_get_int(tmaxHum)); config_setting_set_int(tmaxHum, maxHum); printf("%i", config_setting_get_int(tmaxHum)); } if (config_setting_get_int(twebOR) != webOR) { printf("\nwebOR: %i -> ", config_setting_get_int(twebOR)); config_setting_set_int(twebOR, webOR); printf("%i", config_setting_get_int(twebOR)); } /* write the modified config file */ config_write_file(&cfg, config_cond_path); config_destroy(&cfg); return 0; }
/** * Load configuration file. * @param[in] path Location of configuration file. * @param[in,out] zconf Loaded options will be stored here. * @return Zero on success. */ int zero_config_load(const char *path, struct zero_config *zconf) { int ret = 0; config_t config; config_init(&config); if (NULL == path) { path = ZCFG_DEFAULT_PATH; } if (config_read_file(&config, path)) { const config_setting_t *root = config_root_setting(&config); ret = ret || load_interfaces(root, ZCFG_INTERFACES, &zconf->interfaces) || load_uint_req(root, ZCFG_IFACE_WAIT_TIME, &zconf->iface_wait_time) || load_uint_req(root, ZCFG_OVERLORD_THREADS, &zconf->overlord_threads) || load_kmgt(root, ZCFG_UNAUTH_BW_LIMIT_DOWN, &zconf->unauth_bw_limit[DIR_DOWN], 1024) || load_kmgt(root, ZCFG_UNAUTH_BW_LIMIT_UP, &zconf->unauth_bw_limit[DIR_UP], 1024) || load_string_req(root, ZCFG_RADIUS_CONFIG_FILE, &zconf->radius_config_file) || load_string_req(root, ZCFG_RADIUS_NAS_IDENTIFIER, &zconf->radius_nas_identifier) || load_uint64_req(root, ZCFG_SESSION_TIMEOUT, &zconf->session_timeout) || load_uint64_req(root, ZCFG_SESSION_ACCT_INTERVAL, &zconf->session_acct_interval) || load_uint64_req(root, ZCFG_SESSION_AUTH_INTERVAL, &zconf->session_auth_interval) || load_string_req(root, ZCFG_RC_LISTEN_ADDR, &zconf->rc_listen_addr) || load_kmgt(root, ZCFG_UPSTREAM_P2P_BW_DOWN, &zconf->upstream_p2p_bw[DIR_DOWN], 1024) || load_kmgt(root, ZCFG_UPSTREAM_P2P_BW_UP, &zconf->upstream_p2p_bw[DIR_UP], 1024) || load_ip_mask_list(root, ZCFG_IP_WHITELIST, &zconf->ip_whitelist) || load_uint16_list(root, ZCFG_P2P_PORTS_WHITELIST, &zconf->p2p_ports_whitelist) || load_uint16_list(root, ZCFG_P2P_PORTS_BLACKLIST, &zconf->p2p_ports_blacklist) || load_kmgt(root, ZCFG_NON_CLIENT_BW_DOWN, &zconf->non_client_bw[DIR_DOWN], 1024) || load_kmgt(root, ZCFG_NON_CLIENT_BW_UP, &zconf->non_client_bw[DIR_UP], 1024) || load_kmgt(root, ZCFG_INITIAL_CLIENT_BUCKET_SIZE, &zconf->initial_client_bucket_size, 1024) ; // convert from bits to bytes zconf->unauth_bw_limit[DIR_DOWN] /= 8; zconf->unauth_bw_limit[DIR_UP] /= 8; zconf->upstream_p2p_bw[DIR_DOWN] /= 8; zconf->upstream_p2p_bw[DIR_UP] /= 8; zconf->non_client_bw[DIR_DOWN] /= 8; zconf->non_client_bw[DIR_UP] /= 8; // convert from seconds to microseconds zconf->session_timeout *= 1000000; zconf->session_acct_interval *= 1000000; zconf->session_auth_interval *= 1000000; } else { ZERO_LOG(LOG_ERR, "config: failed to parse %s (error:%s at %d line)", path, config_error_text(&config), config_error_line(&config)); ret = -1; } config_destroy(&config); return ret; }
void Conf_init(const char *conffile) { config_init(&configuration); if (conffile == NULL) conffile = defaultconfig; if (config_read_file(&configuration, conffile) != CONFIG_TRUE) { Log_fatal("Error in config file %s line %d: %s", conffile, config_error_line(&configuration), config_error_text(&configuration)); } }
int conf_read_file(config_t *config, const char *config_filename) { libconfig->init(config); if (!libconfig->read_file_src(config, config_filename)) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); libconfig->destroy(config); return 1; } return 0; }
/** * Initializes 'config' and loads a configuration file. * * Shows error and destroys 'config' in case of failure. * It is the caller's care to destroy 'config' in case of success. * * @param config The config file to initialize. * @param config_filename The file to read. * * @retval CONFIG_TRUE in case of success. * @retval CONFIG_FALSE in case of failure. */ int config_load_file(struct config_t *config, const char *config_filename) { libconfig->init(config); if (libconfig->read_file_src(config, config_filename) != CONFIG_TRUE) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); libconfig->destroy(config); return CONFIG_FALSE; } return CONFIG_TRUE; }
/** * Re-reads configuration from the given file */ int read_config() { config_t cfg; config_init(&cfg); if (config_read_file(&cfg, conf.config_file) == CONFIG_FALSE) { if (config_error_type(&cfg) == CONFIG_ERR_FILE_IO) { log_error("Configuration file not found: %s", conf.config_file); config_destroy(&cfg); return -1; } log_error("%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); return -1; } int intVal; const char* charVal; if (config_lookup_int(&cfg, "num_connections", &intVal) == CONFIG_TRUE) { conf.num_connections = intVal; } if (config_lookup_int(&cfg, "report_freq", &intVal) == CONFIG_TRUE) { conf.report_freq = intVal; } if (config_lookup_int(&cfg, "packet_size", &intVal) == CONFIG_TRUE) { if (intVal > MAXPACKET) { log_error("packet_size: %d exceeds maximal packet size (%d)", intVal, MAXPACKET); config_destroy(&cfg); return -1; } conf.packet_size = intVal; } if (config_lookup_int(&cfg, "packets_count", &intVal) == CONFIG_TRUE) { conf.packets_count = intVal; } if (config_lookup_string(&cfg, "reports_dir", &charVal) == CONFIG_TRUE) { free(conf.reports_dir); conf.reports_dir = strdup(charVal); } if (config_lookup_string(&cfg, "hosts_file", &charVal) == CONFIG_TRUE) { free(conf.hosts_file); conf.hosts_file = strdup(charVal); } if (config_lookup_string(&cfg, "log_file", &charVal) == CONFIG_TRUE) { free(conf.log_file); conf.log_file = strdup(charVal); } config_destroy(&cfg); if (read_hosts() == -1) { return -1; } return 0; }
int config_open(const char *path,config_t *config){ config_init(config); if(config_read_file(config,path)==CONFIG_FALSE){ fprintf(stderr,"[-] config_read_file (%s) on line (%d)\n",config_error_text(config),config_error_line(config)); config_destroy(config); config=NULL; return 1; } return 0; }
config_t *cfg_open(const char *path) { FILE *file = NULL; config_t *config = (config_t*)malloc(sizeof(config_t)); if (config == NULL) { return NULL; } if (path == NULL || path[0] == 0) { config_init(config); return config; } file = fopen(path,"r"); if (file == NULL) { config_init(config); return config; } // Not initializing produces a crash config_init(config); if (config_read(config,file) != CONFIG_TRUE) { #ifdef DEBUG if (config_error_type(config) == CONFIG_ERR_FILE_IO) { printf("Error opening configuration file.\n"); } else { printf("Error parsing configuration file.\n"); printf("Line: %d\n", config_error_line(config)); printf("Text: %s\n", config_error_text(config)); } #endif // Destroy the config and initialize a new one config_destroy(config); config_init(config); } fclose(file); config_set_tab_width(config,0); return config; }
int conf_read_file(config_t *config, const char *config_filename) { config_init(config); if (!config_read_file(config, config_filename)) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); config_destroy(config); return 1; } return 0; }
/** * Loads system default configuration! * */ int loadConfiguration(void){ config_init(&cfg); if(! config_read_file(&cfg, "iptv-analyzer.cfg")){ printf("Failed Loading cofiguration: %s", config_error_text(&cfg)); }else{ char msg[1024]; syslog(LOG_INFO,"Configuration Read OK [%s]","iptv-analyzer.cfg"); syslog(LOG_INFO,"Channel List File is [%s]",loadStringKey(&cfg,"server.channel-list-file")); return 0; } return 1; }
static int load_conf_file() { int status = -1, fd; struct config_t config; DEBUG_FUNCTION; config_init(&config); if ((fd = open(storaged_config_file, O_RDWR)) == -1) { fprintf(stderr, "can't load config file %s: %s\n", storaged_config_file, strerror(errno)); fatal("can't load config file %s: %s", storaged_config_file, strerror(errno)); status = -1; goto out; } close(fd); if (config_read_file(&config, storaged_config_file) == CONFIG_FALSE) { errno = EIO; fprintf(stderr, "can't read config file: %s at line: %d\n", config_error_text(&config), config_error_line(&config)); fatal("can't read config file: %s at line: %d", config_error_text(&config), config_error_line(&config)); goto out; } if (load_layout_conf(&config) != 0) { goto out; } if (load_storages_conf(&config) != 0) { goto out; } status = 0; out: config_destroy(&config); return status; }