int read_scenario_master_file(char scenario_list[30][60], unsigned int scenario_reps[60]) { config_t cfg; // Returns all parameters in this structure char current_scenario[30]; const char *tmpS; int num_scenarios = 1; int tmpI; // Stores the value of Integer Parameters from Config file config_init(&cfg); // Read the file. If there is an error, report it and exit. if (!config_read_file(&cfg, "master_scenario_file.cfg")) { printf("Error reading master scenario file on line %i\n", config_error_line(&cfg)); exit(1); } // Read the parameter group if (config_lookup_int(&cfg, "NumberofScenarios", &tmpI)) num_scenarios = (int)tmpI; for (int i = 0; i < num_scenarios; i++) { sprintf(current_scenario, "scenario_%d", i + 1); if (config_lookup_string(&cfg, current_scenario, &tmpS)) strcpy(&scenario_list[i][0], tmpS); } for (int i = 0; i < num_scenarios; i++) { sprintf(current_scenario, "reps_scenario_%d", i + 1); if (config_lookup_int(&cfg, current_scenario, &tmpI)) scenario_reps[i] = tmpI; } config_destroy(&cfg); return num_scenarios; } // End readScMasterFile()
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 init(int argc, char **argv) { const char *str; int value; config.audio_backend_buffer_desired_length = 44100; // one second. config.audio_backend_latency_offset = 0; if (config.cfg != NULL) { /* Get the desired buffer size setting. */ if (config_lookup_int(config.cfg, "stdout.audio_backend_buffer_desired_length", &value)) { if ((value < 0) || (value > 132300)) die("Invalid stdout audio backend buffer desired length \"%d\". It should be between 0 and 132300, default is 44100", value); else config.audio_backend_buffer_desired_length = value; } /* Get the latency offset. */ if (config_lookup_int(config.cfg, "stdout.audio_backend_latency_offset", &value)) { if ((value < -66150) || (value > 66150)) die("Invalid stdout audio backend buffer latency offset \"%d\". It should be between -66150 and +66150, default is 0", value); else config.audio_backend_latency_offset = value; } } return 0; }
/** * Initializes the similarity measure */ void kern_wdegree_config() { const char *str; config_lookup_int(&cfg, "measures.kern_wdegree.degree", °ree); config_lookup_int(&cfg, "measures.kern_wdegree.shift", &shift); /* Normalization */ config_lookup_string(&cfg, "measures.kern_wdegree.norm", &str); n = knorm_get(str); }
/** * 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 get_server_config(s_config *c, char *config_path) { config_t cfg; config_setting_t *modules_setting, *module_setting; unsigned int count, i; const char *module_name; config_init(&cfg); if (!config_read_file(&cfg, config_path)) { config_destroy(&cfg); return CONFIG_FILE_READ_ERROR; } if (config_lookup_int(&cfg, "port", &(c->port)) && config_lookup_string(&cfg, "host", &(c->host)) && config_lookup_string(&cfg, "web_root", &(c->web_root)) && config_lookup_string(&cfg, "web_prefix", &(c->web_prefix)) && config_lookup_string(&cfg, "api_prefix", &(c->api_prefix)) && config_lookup_string(&cfg, "index_file", &(c->index_file)) && config_lookup_string(&cfg, "api_modules_path", &(c->api_modules_path)) && config_lookup_int(&cfg, "buffer_size", &(c->buffer_size)) && config_lookup_int(&cfg, "api_modules_number", &(c->api_modules_number)) ) { c->buffer = (char*) calloc((size_t) c->buffer_size, sizeof(char)); /* Output a list of all movies in the inventory. */ modules_setting = config_lookup(&cfg, "api_modules"); if (modules_setting != NULL) { count = (unsigned int) config_setting_length(modules_setting); if (count != (unsigned int) c->api_modules_number) return CONFIG_INCONSISTENT_DATA; else if (count == 0) return CONFIG_FILE_READ_OK; c->api_modules_names = malloc(count * sizeof(char*)); for (i = 0; i < count; ++i) { module_setting = config_setting_get_elem(modules_setting, i); module_name = config_setting_get_string(module_setting); c->api_modules_names[i] = module_name; } map_init(&c->api_modules, c->api_modules_number); } return CONFIG_FILE_READ_OK; } else return CONFIG_MISSING_KEY; }
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; }
void get_conf_int (char *key, int *value) { config_t *conf = &(config_t) {}; config_init (conf); config_read_file (conf, "TSECDecoder.conf"); config_lookup_int(conf, key, value); config_destroy (conf); }
int lamb_get_int(const config_t *cfg, const char *key, int *val) { if (!config_lookup_int(cfg, key, val)) { return -1; } 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()
/********************* return RET_NOK on error *********************/ static ret_code_t __read_int(const char * table, const char * file, int * res, va_list ap) { const config_t * config = NULL; char * path=NULL; int result; SDL_LockMutex(entry_mutex); config = get_config(table,file); if(config==NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } path = get_path(ap); if(path == NULL) { SDL_UnlockMutex(entry_mutex); return RET_NOK; } if(config_lookup_int (config, path, &result)==CONFIG_FALSE) { SDL_UnlockMutex(entry_mutex); free(path); return RET_NOK; } free(path); SDL_UnlockMutex(entry_mutex); *res = result; return RET_OK; }
/** * Exit Sally tool. Close open files and free memory. */ static void sally_exit() { int ehash; const char *cfg_str, *hash_file; info_msg(1, "Flushing. Closing input and output."); input_close(); output_close(); config_lookup_string(&cfg, "features.vect_embed", &cfg_str); if (!strcasecmp(cfg_str, "tfidf")) idf_destroy(input); config_lookup_string(&cfg, "input.stopword_file", &cfg_str); if (strlen(cfg_str) > 0) stopwords_destroy(); config_lookup_string(&cfg, "features.hash_file", &hash_file); if (strlen(hash_file) > 0) { info_msg(1, "Saving explicit hash table to '%s'.", hash_file); gzFile z = gzopen(hash_file, "w9"); if (!z) error("Could not open hash file '%s'", hash_file); fhash_write(z); gzclose(z); } config_lookup_int(&cfg, "features.explicit_hash", &ehash); if (ehash || strlen(hash_file) > 0) fhash_destroy(); /* Destroy configuration */ config_destroy(&cfg); }
/** * Initialize malheur tool * @param argc Number of arguments * @param argv Argument values */ static void malheur_init(int argc, char **argv) { int lookup; double shared; /* Load configuration */ load_config(argc, argv); /* Parse options */ parse_options(argc, argv); /* Prepare malheur files */ snprintf(mcfg.reject_file, MAX_PATH_LEN, "%s/%s", malheur_dir, REJECT_FILE); snprintf(mcfg.config_file, MAX_PATH_LEN,"%s/%s", malheur_dir, CONFIG_FILE); snprintf(mcfg.proto_file, MAX_PATH_LEN, "%s/%s", malheur_dir, PROTO_FILE); snprintf(mcfg.state_file, MAX_PATH_LEN, "%s/%s", malheur_dir, STATE_FILE); /* Init feature lookup table */ config_lookup_int(&cfg, "features.lookup_table", &lookup); config_lookup_float(&cfg, "cluster.shared_ngrams", &shared); if (lookup || shared > 0.0) { ftable_init(); } /* Reset current state */ if (reset) { unlink(mcfg.reject_file); unlink(mcfg.proto_file); unlink(mcfg.state_file); } memset(&mstate, 0, sizeof(mstate)); }
/** * Internal: Allocates and extracts a feature vector from a string without * postprocessing and no blended n-grams. * @param x String of bytes (with space delimiters) * @param l Length of sequence * @param n N-gram length * @return feature vector */ fvec_t *fvec_extract_intern2(char *x, int l, int n) { fvec_t *fv; int pos; cfg_int shift; const char *dlm_str; assert(x && l >= 0); /* Allocate feature vector */ fv = calloc(1, sizeof(fvec_t)); if (!fv) { error("Could not extract feature vector"); return NULL; } /* Get configuration */ config_lookup_string(&cfg, "features.ngram_delim", &dlm_str); config_lookup_bool(&cfg, "features.ngram_pos", &pos); config_lookup_int(&cfg, "features.pos_shift", &shift); /* Check for empty sequence */ if (l == 0) return fv; /* Sanitize shift value */ if (!pos) shift = 0; /* Allocate arrays */ int space = 2 * shift + 1; fv->dim = (feat_t *) malloc(l * sizeof(feat_t) * space); fv->val = (float *) malloc(l * sizeof(float) * space); if (!fv->dim || !fv->val) { error("Could not allocate feature vector contents"); fvec_destroy(fv); return NULL; } /* Get configuration */ config_lookup_string(&cfg, "features.ngram_delim", &dlm_str); /* Loop over position shifts (0 if pos is disabled) */ for (int s = -shift; s <= shift; s++) { if (!dlm_str || strlen(dlm_str) == 0) { extract_ngrams(fv, x, l, n, pos, s); } else { extract_wgrams(fv, x, l, n, pos, s); } } /* Sort extracted features */ qsort(fv->dim, fv->len, sizeof(feat_t), cmp_feat); /* Count features */ count_feat(fv); return fv; }
int init_config() { config_t cfg; config_init(&cfg); if (!config_read_file(&cfg, g_data.conf_path)) { return -1; } const char* ip; if (!config_lookup_string(&cfg, "server.ip", &ip)) { fprintf(stderr, "get server ip fail"); return -1; } snprintf(g_data.server.ip, TINY_STR_LEN, "%s", ip); if (!config_lookup_int(&cfg, "server.port", &g_data.server.port)) { fprintf(stderr, "get server port fail"); return -1; } if (!config_lookup_int(&cfg, "server.port", &g_data.server.port)) { fprintf(stderr, "get server port fail"); return -1; } if (!config_lookup_int(&cfg, "thread_num", &g_data.thread_num)) { fprintf(stderr, "get server port fail"); g_data.thread_num = 0; } fprintf(stdout, "threadnum:%d\n", g_data.thread_num); if (!config_lookup_int(&cfg, "per_thread_loop_num", &g_data.per_thread_loop_num)) { fprintf(stderr, "per_thread_loop_num error"); g_data.per_thread_loop_num = 0; } fprintf(stdout, "per_thread_loop_num:%d\n", g_data.per_thread_loop_num); config_destroy(&cfg); printf("server:%s, %d\n", g_data.server.ip, g_data.server.port); return 0; }
int read_stats_configuration(const char *filename, stats_options_t *options, shared_options_t *shared_options) { if (filename == NULL || options == NULL || shared_options == NULL) { return -1; } config_t *config = (config_t*) calloc (1, sizeof(config_t)); int ret_code = config_read_file(config, filename); if (ret_code == CONFIG_FALSE) { LOG_ERROR_F("config file error: %s\n", config_error_text(config)); return ret_code; } // Read number of threads that will make request to the web service ret_code = config_lookup_int(config, "vcf-tools.stats.num-threads", shared_options->num_threads->ival); if (ret_code == CONFIG_FALSE) { LOG_WARN("Number of threads not found in config file, must be set via command-line\n"); } else { LOG_DEBUG_F("num-threads = %ld\n", *(shared_options->num_threads->ival)); } // Read maximum number of batches that can be stored at certain moment ret_code = config_lookup_int(config, "vcf-tools.stats.max-batches", shared_options->max_batches->ival); if (ret_code == CONFIG_FALSE) { LOG_WARN("Maximum number of batches not found in configuration file, must be set via command-line\n"); } else { LOG_DEBUG_F("max-batches = %ld\n", *(shared_options->max_batches->ival)); } // Read size of every batch read ret_code = config_lookup_int(config, "vcf-tools.stats.batch-lines", shared_options->batch_lines->ival); ret_code |= config_lookup_int(config, "vcf-tools.stats.batch-bytes", shared_options->batch_bytes->ival); if (ret_code == CONFIG_FALSE) { LOG_WARN("Neither batch lines nor bytes found in configuration file, must be set via command-line\n"); } /*else { LOG_DEBUG_F("batch-lines = %ld\n", *(shared_options->batch_size->ival)); }*/ config_destroy(config); free(config); return 0; }
/** * Main processing routine of Sally. This function processes chunks of * strings. It might be suitable for OpenMP support in a later version. */ static void sally_process() { long read, i, j; int chunk; const char *hash_file; /* Check if a hash file is set */ config_lookup_string(&cfg, "features.hash_file", &hash_file); /* Get chunk size */ config_lookup_int(&cfg, "input.chunk_size", &chunk); /* Allocate space */ fvec_t **fvec = malloc(sizeof(fvec_t *) * chunk); string_t *strs = malloc(sizeof(string_t) * chunk); if (!fvec || !strs) fatal("Could not allocate memory for embedding"); info_msg(1, "Processing %d strings in chunks of %d.", entries, chunk); for (i = 0, read = 0; i < entries; i += read) { read = input_read(strs, chunk); if (read <= 0) fatal("Failed to read strings from input '%s'", input); /* Generic preprocessing of input */ input_preproc(strs, read); #ifdef ENABLE_OPENMP #pragma omp parallel for #endif for (j = 0; j < read; j++) { fvec[j] = fvec_extract(strs[j].str, strs[j].len); fvec_set_label(fvec[j], strs[j].label); fvec_set_source(fvec[j], strs[j].src); } if (!output_write(fvec, read)) fatal("Failed to write vectors to output '%s'", output); /* Free memory */ input_free(strs, read); output_free(fvec, read); /* Reset hash if enabled but no hash file is set */ if (fhash_enabled() && !strlen(hash_file) > 0) fhash_reset(); prog_bar(0, entries, i + read); } free(fvec); free(strs); }
int read_tdt_configuration(const char *filename, tdt_options_t *tdt_options, shared_options_t *shared_options) { if (filename == NULL || tdt_options == NULL || shared_options == NULL) { return -1; } config_t *config = (config_t*) calloc (1, sizeof(config_t)); int ret_code = config_read_file(config, filename); if (ret_code == CONFIG_FALSE) { LOG_ERROR_F("Configuration file error: %s\n", config_error_text(config)); return CANT_READ_CONFIG_FILE; } const char *tmp_string; // Read number of threads that will make request to the web service ret_code = config_lookup_int(config, "gwas.tdt.num-threads", shared_options->num_threads->ival); if (ret_code == CONFIG_FALSE) { LOG_WARN("Number of threads not found in config file, must be set via command-line"); } else { LOG_DEBUG_F("num-threads = %ld\n", *(shared_options->num_threads->ival)); } // Read maximum number of batches that can be stored at certain moment ret_code = config_lookup_int(config, "gwas.tdt.max-batches", shared_options->max_batches->ival); if (ret_code == CONFIG_FALSE) { LOG_WARN("Maximum number of batches not found in configuration file, must be set via command-line"); } else { LOG_DEBUG_F("max-batches = %ld\n", *(shared_options->max_batches->ival)); } // Read size of a batch (in lines or bytes) ret_code = config_lookup_int(config, "gwas.tdt.batch-lines", shared_options->batch_lines->ival); ret_code |= config_lookup_int(config, "gwas.tdt.batch-bytes", shared_options->batch_bytes->ival); if (ret_code == CONFIG_FALSE) { LOG_WARN("Neither batch lines nor bytes found in configuration file, must be set via command-line"); } config_destroy(config); free(config); return 0; }
/* create default configuration file */ void SWS_get_config() { config_t cfg; config_init(&cfg); if (!config_read_file(&cfg, DEFAULT_FILE)) { SWS_log_fatal("%s", config_error_line(&cfg)); } if (!config_lookup_int(&cfg, "SWS_port", &SWS_port)) { SWS_log_fatal("default configuration file has been changed," "No port!"); } if (!config_lookup_int(&cfg, "SWS_process_num", &SWS_process_num)) { SWS_log_fatal("default configuration file has been changed," "No address!"); } if (!config_lookup_int(&cfg, "SWS_request_header", &SWS_request_header)) { SWS_log_fatal("default configuration file has been changed," "No url_length!"); } if (!config_lookup_int(&cfg, "SWS_request_body", &SWS_request_body)) { SWS_log_fatal("default configuration file has been changed," "No url_length!"); } if (!config_lookup_string(&cfg, "SWS_address", &SWS_addr)) { SWS_log_fatal("default configuration file has been changed," "No address!"); } if (!config_lookup_string(&cfg, "SWS_error_log", &SWS_error_log)) { SWS_log_fatal("default configuration file has been changed," "No error_log!"); } if (!config_lookup_string(&cfg, "SWS_web_root", &SWS_web_root)) { SWS_log_fatal("default configuration file has been changed," "No web_root!"); } config_destroy(&cfg); }
ModBusReader::ModBusReader(config_t cfg) { if(!config_lookup_bool(&cfg, "main.debug", &this->debug)) { this->debug = false; } if(!config_lookup_string(&cfg, "reader.port", &this->_address)) { throw "Reader port is not defined"; } if(!config_lookup_int(&cfg, "reader.baud_rate", &this->baud)) { baud = 115200; } if(!config_lookup_int(&cfg, "reader.slave_id", &this->slave_id)) { throw "Reader slave_id is not defined"; } if(!config_lookup_int(&cfg, "reader.register_number", &this->register_number)) { throw "Reader register_number is not defined"; } }
/** * Initializes the similarity measure */ void kern_spectrum_config() { const char *str; /* Length parameter */ config_lookup_int(&cfg, "measures.kern_spectrum.length", &len); /* Normalization */ config_lookup_string(&cfg, "measures.kern_spectrum.norm", &str); n = knorm_get(str); }
void parse_config (void) { config_filename = make_full_path (config_filename); config_t conf; config_init (&conf); if (config_read_file (&conf, config_filename) != CONFIG_TRUE) { fprintf (stderr, "Can not read config '%s': error '%s' on the line %d\n", config_filename, config_error_text (&conf), config_error_line (&conf)); exit (2); } if (!prefix) { config_lookup_string (&conf, "default_profile", (void *)&prefix); } static char buf[1000]; int l = 0; if (prefix) { l = strlen (prefix); memcpy (buf, prefix, l); buf[l ++] = '.'; } test_dc = 0; strcpy (buf + l, "test"); config_lookup_bool (&conf, buf, &test_dc); strcpy (buf + l, "log_level"); long long t = log_level; config_lookup_int (&conf, buf, (void *)&t); log_level = t; if (!msg_num_mode) { strcpy (buf + l, "msg_num"); config_lookup_bool (&conf, buf, &msg_num_mode); } parse_config_val (&conf, &config_directory, "config_directory", CONFIG_DIRECTORY, 0); config_directory = make_full_path (config_directory); parse_config_val (&conf, &auth_file_name, "auth_file", AUTH_KEY_FILE, config_directory); parse_config_val (&conf, &state_file_name, "state_file", STATE_FILE, config_directory); parse_config_val (&conf, &secret_chat_file_name, "secret", SECRET_CHAT_FILE, config_directory); parse_config_val (&conf, &downloads_directory, "downloads", DOWNLOADS_DIRECTORY, config_directory); parse_config_val (&conf, &binlog_file_name, "binlog", BINLOG_FILE, config_directory); strcpy (buf + l, "binlog_enabled"); config_lookup_bool (&conf, buf, &binlog_enabled); if (!mkdir (config_directory, CONFIG_DIRECTORY_MODE)) { printf ("[%s] created\n", config_directory); } if (!mkdir (downloads_directory, CONFIG_DIRECTORY_MODE)) { printf ("[%s] created\n", downloads_directory); } }
int readCfgCond (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_cond_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, "minTemp", &minTemp)) printf("\nNo 'minTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "maxTemp", &maxTemp)) printf("\nNo 'maxTemp' setting in configuration file."); if (!config_lookup_int(&cfg, "minHum", &minHum)) printf("\nNo 'minHum' setting in configuration file."); if (!config_lookup_int(&cfg, "maxHum", &maxHum)) printf("\nNo 'maxHum' setting in configuration file."); if (!config_lookup_int(&cfg, "webOR", &webOR)) printf("\nNo 'webOR' setting in configuration file."); config_destroy(&cfg); return 0; }
/** * Trim a clustering by rejecting small clusters. The provided clustering * structure is updated by assigning reports of rejected clusters to the * cluster label 0. * @param c Clustering structure */ void cluster_trim(cluster_t *c) { assert(c); count_t *counts = NULL, *entry; unsigned int i, j; int rej; config_lookup_int(&cfg, "cluster.reject_num", &rej); for (i = 0; i < c->len; i++) { /* Look for cluster in hash table */ HASH_FIND_INT(counts, &(c->cluster[i]), entry); if (!entry) { entry = malloc(sizeof(count_t)); if (!entry) { error("Could not allocate cluster bin"); return; } /* Create new entry */ entry->label = c->cluster[i]; entry->count = 0; /* Add entry */ HASH_ADD_INT(counts, label, entry); } entry->count++; } /* Update cluster assignments */ for (i = 0; i < c->len; i++) { /* Look for cluster in hash table */ HASH_FIND_INT(counts, &(c->cluster[i]), entry); if (entry->count >= rej) c->cluster[i] = entry->label; else c->cluster[i] = 0; } /* Delete hash table */ for (j = 0; counts;) { /* Count rejected clusters */ entry = counts; if (entry->count < rej) j++; HASH_DEL(counts, entry); free(entry); } /* Correct cluster number */ c->num -= j; }
/** * Load the ldap modules, passing in any arguments * given initially, which are to be used in the * ldap module. */ int load_ldap_module( arguments *args ) { syslog(LOG_INFO, "LDAP Module initalizing"); /* Sets the protocol version based on ldap.version */ config_lookup_int(&config, "ldap.version", &version); switch(version) { case 1: ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version); syslog(LOG_INFO, "LDAP Protocol Version: 1"); break; case 2: ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version); syslog(LOG_INFO, "LDAP Protocol Version: 2"); break; case 3: ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version); syslog(LOG_INFO, "LDAP Protocol Version: 3"); break; default: version = 3; ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &version); syslog(LOG_INFO, "Invalid value, setting LDAP Protocol\ Version to 3"); break; } config_lookup_string(&config, "ldap.uri", &uri); syslog(LOG_INFO, "LDAP URI: %s\n", uri); config_lookup_string(&config, "ldap.binddn", &binddn); syslog(LOG_INFO, "LDAP BINDDN: %s\n", binddn); config_lookup_string(&config, "ldap.password", &password); // Removed displaying password syslog(LOG_INFO, "Initializing LDAP Connection...%s\n", ldap_err2string(ldap_initialize(&ldap, uri))); syslog(LOG_INFO, "Binding to URI...%s\n", ldap_err2string(ldap_simple_bind_s(ldap, binddn, password))); syslog(LOG_INFO, "Building LDAP query tree..."); head = build_query_tree(); log_query_tree(&head); timeout.tv_sec = 10; timeout.tv_usec = 0; slack_ldap_search("slackwill"); return 0; }
int cfg_int(const char *name, int *val, u4_t flags) { int num; if (!config_lookup_int(&cfg, name, &num)) { if (config_error_line(&cfg)) cfg_error("cfg_int"); if (!(flags & CFG_REQUIRED)) return 0; lprintf("kiwi.cfg: required parameter not found: %s\n", name); panic("cfg_int"); } if (flags & CFG_PRINT) lprintf("kiwi.cfg: %s = %d\n", name, num); if (val) *val = num; return num; }
void initSocket() { int portno, n; struct sockaddr_in serv_addr; struct hostent *server; const char *host; /* Check if re-init case */ if (fd >= 0) close(fd); /* Create a non-blocking socket point */ fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { perror("ERROR opening socket"); exit(1); } /* Construct the server address structure */ memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; /* check settings in the config file */ if (!config_lookup_string(cf, "host", &host)) { DEBUG(LOG_ERR,"No host specified"); printf("No host specified"); exit(EXIT_FAILURE); } if (!config_lookup_int(cf, "port", &portno)) { DEBUG(LOG_ERR,"No port specified"); printf("No port specified"); exit(EXIT_FAILURE); } DEBUG(LOG_NOTICE,"Opening %s:%d",host,portno); serv_addr.sin_addr.s_addr = inet_addr(host); serv_addr.sin_port = htons(portno); /* Now connect to the server */ if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { perror("ERROR connecting"); exit(1); } /* Switch the socket to non blocking */ if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK) <0) { perror("calling fcntl"); exit(1); } }
int mst_read_version(config_t *pconfig) { int rv = -1; int val = 0; rv = config_lookup_int(pconfig, "version", &val); if (CONFIG_FALSE == rv) { fprintf(stderr, "No version info is found: %d\n", rv); return rv; } g_mst_conf.version = val; return CONFIG_TRUE; }
/** * Using libconfig a config file is parsed and options are extracted to global * struct aids_conf. If config file is malformed a description of the error * is returned. * * @param filename name of config file * @returns description of error in case of failure or NULL if everything goes ok */ const char *read_conf(const char *filename) { int r; config_t cfg; int network_sleep_time, processor_sleep_time, network_recent, processor_recent; r = config_read_file(&cfg, filename); if (r == CONFIG_TRUE) { aids_conf.pid_file = read_in_string(&cfg, "pid_file", "aids.pid"); aids_conf.network_global_data_filename = read_in_string(&cfg, "network:global_data_filename", "data/network.dat"); aids_conf.processor_global_data_filename = read_in_string(&cfg, "processor:global_data_filename", "data/processor.dat"); aids_conf.jabber_id = read_in_string(&cfg, "jabber_id", "*****@*****.**"); aids_conf.jabber_pass = read_in_string(&cfg, "jabber_pass", "systemowe"); aids_conf.jabber_receiver_id = read_in_string(&cfg, "jabber_receiver_id", "*****@*****.**"); network_sleep_time = config_lookup_int(&cfg, "network:sleep_time"); if (network_sleep_time <= 0) network_sleep_time = 10; aids_conf.network_sleep_time = network_sleep_time; processor_sleep_time = config_lookup_int(&cfg, "processor:sleep_time"); if (processor_sleep_time <= 0) processor_sleep_time = 10; aids_conf.processor_sleep_time = processor_sleep_time; network_recent = config_lookup_int(&cfg, "network:recent_data"); if (network_recent <= 0) network_recent = 100; aids_conf.network_recent = network_recent; processor_recent = config_lookup_int(&cfg, "processor:recent_data"); if (processor_recent <= 0) processor_recent = 100; aids_conf.processor_recent = processor_recent; return NULL; } else return config_error_text(&cfg); }
/** * Exits the malheur tool. */ static void malheur_exit() { int lookup; /* Destroy feature lookup table */ config_lookup_int(&cfg, "features.lookup_table", &lookup); if (lookup) { if (verbose > 0) ftable_print(); ftable_destroy(); } /* Destroy configuration */ config_destroy(&cfg); }