Exemplo n.º 1
0
void MysqlWriter::connect()
{
	const char *server;
	const char *user;
	const char *password;
	const char *database;
	
	if(!config_lookup_string(&this->cfg, "db.host", &server)) {
		throw "MySQL host is not defined";
	}
	if(!config_lookup_string(&this->cfg, "db.username", &user)) {
		throw "MySQL username is not defined";
	}
	if(!config_lookup_string(&this->cfg, "db.password", &password)) {
		throw "MySQL password is not defined";
	}
	if(!config_lookup_string(&this->cfg, "db.database", &database)) {
		throw "MySQL database is not defined";
	}

	this->conn = mysql_init(NULL);
	if (!mysql_real_connect(this->conn, server,
	                        user, password, database, 0, NULL, 0)) {
		throw mysql_error(this->conn);
	}
	
	time_t rawtime;
	struct tm *timeinfo;
	time (&rawtime);
	timeinfo = localtime(&rawtime);
	strftime(this->numeric_table_name, sizeof(this->numeric_table_name), "archive_numeric_%Y_%m", timeinfo);
}
Exemplo n.º 2
0
Arquivo: sally.c Projeto: yangke/sally
/**
 * 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);

}
Exemplo n.º 3
0
/**
 * Initializes the similarity measure
 */
void kern_distance_config()
{
    const char *str;

    /* Distance measure */
    config_lookup_string(&cfg, "measures.kern_distance.dist", &str);
    dist = measure_match(str);
    func[dist].measure_config();

    /* Substitution type */
    config_lookup_string(&cfg, "measures.kern_distance.type", &str);
    if (!strcasecmp(str, "linear")) {
        subst = DS_LINEAR;
    } else if (!strcasecmp(str, "poly")) {
        subst = DS_POLY;
    } else if (!strcasecmp(str, "neg")) {
        subst = DS_NEG;
    } else if (!strcasecmp(str, "rbf")) {
        subst = DS_RBF;
    } else {
        warning("Unknown substitution type '%s'. Using 'linear'.", str);
        subst = DS_LINEAR;
    }

    /* Parameters */
    config_lookup_float(&cfg, "measures.kern_distance.fgamma", &fgamma);
    config_lookup_float(&cfg, "measures.kern_distance.degree", &degree);

    /* Normalization */
    config_lookup_string(&cfg, "measures.kern_distance.norm", &str);
    norm = knorm_get(str);

}
Exemplo n.º 4
0
/**
 * Parses the configuration file, specifically the 
 * ldap section. This function will produce a tree, 
 * or really a linked list, tree sounds cooler, of 
 * ldap_query_t structures. This will allow a series 
 * of events to happen sequentially just by adding a
 * few lines to the configuration file. The returned 
 * node is the head of the tree/list.
 */
slack_ldap_query_t
build_query_tree() { 
    syslog(LOG_INFO, "Building query event tree..."); 
    static slack_ldap_query_t head; 
    slack_ldap_query_t *tail = &head; 
    config_setting_t *setting = config_lookup(&config, "ldap.queries"); 
    int i = 0; 
    do { /* The caveat, and requirement, is that there be at least
            one ldap query parameter, otherwise you just shouldn't
            include the ldap module...*/
        const char *query = config_setting_get_string_elem(setting, i);
        if(query != NULL) { 
            char query_param[strlen("ldap.query") //GCC/clang will optimize
                + strlen(query)+1]; // +1 for dot op
            sprintf(query_param, "ldap.query.%s", query);
            syslog(LOG_INFO, "Parsed LDAP query %s", query_param); 
            syslog(LOG_INFO, "Building LDAP query node..."); 

            /* Each of the string must have a +1 for dot operator */
            char basednstr[strlen(query_param) + 8]; //length of 'basedn'
            sprintf(basednstr, "%s.%s", query_param, "basedn"); 
            syslog(LOG_INFO, "Parsing %s", basednstr); 
            char filterstr[strlen(query_param) + 6]; //length of 'filter'
            sprintf(filterstr, "%s.%s", query_param, "filter"); 
            syslog(LOG_INFO, "Parsing %s", filterstr); 
            char eventstr[strlen(query_param) + 5]; //length of 'event'
            sprintf(eventstr, "%s.%s", query_param, "event"); 
            syslog(LOG_INFO, "Parsing %s", eventstr); 

            syslog(LOG_INFO, "Building query node..."); 
            config_lookup_string(&config, basednstr, 
                    (const char **)&(tail->basednstr)); 
            config_lookup_string(&config, filterstr, 
                    (const char **)&(tail->filterstr)); 
            config_lookup_string(&config, eventstr, 
                    (const char **)&(tail->eventstr)); 
            tail->next = malloc(sizeof(slack_ldap_query_t));

            /* By this point the new node, TODO: write a failure method 
             * if we don't make it to this point. I beleive the only 
             * alternative to correct configuration is segfault :(
             */
            syslog(LOG_INFO, "Success, New Node:"); 
            syslog(LOG_INFO, "--->basedn = %s", tail->basednstr); 
            syslog(LOG_INFO, "--->filter = %s", tail->filterstr); 
            syslog(LOG_INFO, "--->event = %s", tail->eventstr); 
            /* Move onto the next node */ 
            tail = tail->next; 

            i++;
        } else { 
            syslog(LOG_INFO, "Parsed all ldap queries.");
            i = -1; 
            tail->next = NULL;
        } 
    } while(i != -1);

    return head;
}
Exemplo n.º 5
0
Arquivo: fvec.c Projeto: MLDroid/sally
/**
 * 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;
}
Exemplo n.º 6
0
/**
 * 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;
}
Exemplo n.º 7
0
/**
 * 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;
}
Exemplo n.º 8
0
bool configfile_get_string( const char *path, const char **str ) {
	if( config_lookup_string(config, path, str) == CONFIG_FALSE ) {
		pline("Config setting %s not found or wrong type", path);
		return false;
	}
	return true;
}
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
Arquivo: main.c Projeto: analani/tg
void parse_config_val (config_t *conf, char **s, char *param_name, const char *default_name, const char *path) {
  static char buf[1000]; 
  int l = 0;
  if (prefix) {
    l = strlen (prefix);
    memcpy (buf, prefix, l);
    buf[l ++] = '.';
  }
  *s = 0;
  const char *r = 0;
  strcpy (buf + l, param_name);
  config_lookup_string (conf, buf, &r);
  if (r) {
    if (path && *r != '/') {
      tasprintf (s, "%s/%s", path, r);
    } else {
      *s = tstrdup (r);
    }
  } else {
    if (path && default_name) {
      tasprintf (s, "%s/%s", path, default_name);
    } else {
      *s  = default_name ? tstrdup (default_name) : 0;
    }
  }
}
Exemplo n.º 11
0
/**
 * Initializes the similarity measure
 */
void dist_kernel_config()
{
    const char *str;

    /* Kernel measure */
    config_lookup_string(&cfg, "measures.dist_kernel.kern", &str);
    kern = measure_match(str);
    func[kern].measure_config();

    /* Parameters */
    config_lookup_bool(&cfg, "measures.dist_kernel.squared", &squared);

    /* Normalization */
    config_lookup_string(&cfg, "measures.dist_kernel.norm", &str);
    norm = knorm_get(str);
}
Exemplo n.º 12
0
short parse_rarity(obj_t *o, char *name)
{
        const char *value;
        short rarity;

        config_lookup_string(cf, name, &value);
        if(!strcmp(value, "very common"))
                rarity = VERYCOMMON;
        else if(!strcmp(value, "common"))
                rarity = COMMON;
        else if(!strcmp(value, "uncommon"))
                rarity = UNCOMMON;
        else if(!strcmp(value, "rare"))
                rarity = RARE;
        else if(!strcmp(value, "very rare"))
                rarity = VERYRARE;
        else {                                          // assume it's common if nothing else is specified
                if(!hasbit(o->flags, OF_UNIQUE))
                        rarity = COMMON;
                else
                        rarity = UNIQUE;
        }

        return rarity;
}
Exemplo n.º 13
0
/*********************
return RET_NOK on error
res MUST BE FREED by caller
*********************/
static ret_code_t __read_string(const char * table, const char * file, char ** res, va_list ap)
{
	const config_t * config = NULL;
	char * path;
	const char * result;

	*res = NULL;

	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_string (config, path, &result)==CONFIG_FALSE) {
//		g_warning("%s: Can't read %s/%s/%s",__func__,table,file,path);
		SDL_UnlockMutex(entry_mutex);
		free(path);
		return RET_NOK;
	}
	free(path);
	SDL_UnlockMutex(entry_mutex);

	*res = strdup(result);

	return RET_OK;
}
Exemplo n.º 14
0
/**
 * Cluster feature vectors using linkage clustering. The function uses
 * the feature vectors for computing a linkage clustering
 * @param fa Array of prototypes
 * @param r Run of clustering
 * @return clustering structure
 */
cluster_t *cluster_linkage(farray_t *fa, int r)
{
    assert(fa);
    double dmin;
    const char *mode;

    /* Get cluster configuration */
    config_lookup_float(&cfg, "cluster.min_dist", (double *) &dmin);
    config_lookup_string(&cfg, "cluster.link_mode", &mode);

    /* Allocate cluster structure */
    cluster_t *c = cluster_create(fa->len, r);

    /* Allocate distances */
    double *dist = malloc(sizeof(double) * tria_size(fa->len));
    if (!dist) {
        error("Could not allocate distance matrix.");
        return NULL;
    }

    /* Compute distances */
    farray_dist_tria(fa, dist);

    if (verbose > 0)
        printf("Clustering (%s linkage) with minimum distance %4.2f.\n",
               mode, dmin);

    /* Run clustering */
    cluster_murtagh(c, dist, dmin, mode[0]);

    free(dist);
    return c;
}
Exemplo n.º 15
0
/**
 * Opens a file for reading text lines. 
 * @param name File name
 * @return number of lines or -1 on error
 */
int input_lines_open(char *name)
{
    assert(name);
    const char *pattern;

    in = gzopen(name, "r");
    if (!in) {
        error("Could not open '%s' for reading", name);
        return -1;
    }

    /* Compile regular expression for label */
    config_lookup_string(&cfg, "input.lines_regex", &pattern);
    if (regcomp(&re, pattern, REG_EXTENDED) != 0) {
        error("Could not compile regex for label");
        return -1;
    }

    /* Count lines in file (I hope this is buffered)*/
    int c = -1, prev, num_lines = 0;
    do {
        prev = c;
        c = gzgetc(in);
        if (c == '\n')
            num_lines++;
    } while(c != -1);

    if (prev >= 0 && prev != '\n') num_lines++;

    /* Prepare reading */
    gzrewind(in);
    line_num = 0;

    return num_lines;
}
Exemplo n.º 16
0
/**
 * @brief Read module configure options
 *
 * This function will read CALLCONF file and fill app_call_conf
 * structure. Most of these values are using during call action process
 * @see call_exec
 *
 * @param cfile Full path to configuration file
 * @return 0 in case of read success, -1 otherwise
 */
int
read_call_config(const char *cfile)
{
    config_t cfg;
    const char *value;
    long int intvalue;

    // Initialize configuration
    config_init(&cfg);

    // Read configuraiton file
    if (config_read_file(&cfg, cfile) == CONFIG_FALSE) {
        isaac_log(LOG_ERROR, "Error parsing configuration file %s on line %d: %s\n", cfile,
                config_error_line(&cfg), config_error_text(&cfg));
        config_destroy(&cfg);
        return -1;
    }

    // Incoming context for first call leg in Originate @see call_exec
    if (config_lookup_string(&cfg, "originate.incontext", &value) == CONFIG_TRUE) {
        strcpy(call_config.incontext, value);
    }
    // Outgoing context for second call leg in Originate @see call_exec
    if (config_lookup_string(&cfg, "originate.outcontext", &value) == CONFIG_TRUE) {
        strcpy(call_config.outcontext, value);
    }
    // Rol variable (AGENTE, USUARIO) for incontext dialplan process
    //if (config_lookup_string(&cfg, "originate.rol", &value) == CONFIG_TRUE) {
    //    strcpy(call_config.rol, value);
    //}

    // Autoanwer variable (0,1) for incontext dialplan process
    if (config_lookup_int(&cfg, "originate.autoanswer", &intvalue) == CONFIG_TRUE) {
        call_config.autoanswer = intvalue;
    }

    // Filepat to store the recordings
    if (config_lookup_string(&cfg, "record.filepath", &value) == CONFIG_TRUE) {
        strcpy(call_config.record_path, value);
    }

    // Dealloc libconfig structure
    config_destroy(&cfg);

    isaac_log(LOG_VERBOSE_3, "Readed configuration from %s\n", cfile);
    return 0;
}
Exemplo n.º 17
0
/**
 * Initializes the similarity measure
 */
void dist_bag_config()
{
    const char *str;

    /* Normalization */
    config_lookup_string(&cfg, "measures.dist_bag.norm", &str);
    n = lnorm_get(str);
}
Exemplo n.º 18
0
static char* config_get_string(config_t* cfg, const char* name, const char* def_value)
{
    const char* value;
    if (!config_lookup_string(cfg, name, &value))
        value = def_value;

    return strndup(value, BUFSIZE);
}
Exemplo n.º 19
0
Arquivo: fvec.c Projeto: MLDroid/sally
/**
 * Internal post-processing of feature vectors.
 * @param fv feature vector
 */
void fvec_postprocess(fvec_t *fv)
{
    const char *cfg_str;
    double flt1, flt2;

    /* Compute embedding and normalization */
    config_lookup_string(&cfg, "features.vect_embed", &cfg_str);
    fvec_embed(fv, cfg_str);
    config_lookup_string(&cfg, "features.vect_norm", &cfg_str);
    fvec_norm(fv, cfg_str);

    /* Apply thresholding */
    config_lookup_float(&cfg, "features.thres_low", &flt1);
    config_lookup_float(&cfg, "features.thres_high", &flt2);
    if (flt1 != 0.0 || flt2 != 0.0) {
        fvec_thres(fv, flt1, flt2);
    }
}
Exemplo n.º 20
0
static const char *read_db_setting(char* path) {
  const char *str;
  if(config_lookup_string(&config, path, &str) != CONFIG_TRUE) {
    fprintf(stderr, "Missing setting: %s\n", path);
    config_destroy(&config);
    exit(EXIT_FAILURE);
  }
  return str;
}
Exemplo n.º 21
0
void
loadconfig() {
	config_init(&config);
	config_set_include_dir(&config, configdir);
	config_read_file(&config, configpath);
	
	const char *dev = device;
	config_lookup_string(&config, "joystick.device", &dev);
	commands = config_lookup(&config, "commands");
}
Exemplo n.º 22
0
Arquivo: sally.c Projeto: yangke/sally
/**
 * 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);
}
Exemplo n.º 23
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);
}
Exemplo n.º 24
0
int lamb_get_string(const config_t *cfg, const char *key, char *val, size_t len) {
    const char *buff;

    if (!config_lookup_string(cfg, key, &buff)) {
        return -1;
    }

    strncpy(val, buff, len);

    return 0;
}
Exemplo n.º 25
0
/**
 * Initializes the similarity measure
 */
void kern_wdegree_config()
{
    const char *str;

    config_lookup_int(&cfg, "measures.kern_wdegree.degree", &degree);
    config_lookup_int(&cfg, "measures.kern_wdegree.shift", &shift);

    /* Normalization */
    config_lookup_string(&cfg, "measures.kern_wdegree.norm", &str);
    n = knorm_get(str);
}
Exemplo n.º 26
0
/**
 * 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);
}
Exemplo n.º 27
0
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);
  }
}
Exemplo n.º 28
0
void dhcp_edit_read_cfg(void)
{
        config_t cfg, *cf;
        int i, r;
        char token[MAX_LEN];
        const char *file = NULL;
        const char *name = NULL;

        cf = &cfg;
        config_init(cf);
 
        if (!config_read_file(cf, "configuracion.cfg"))
		goto error;

        /* Buscamos redes de hosts para leer desde configuracion.cfg */
        for (i=0;i<MAX_N_REDES;i++) {

        	sprintf(token,"dhcpdconf%i", i);
		r = config_lookup_string(cf, token, &file);
                if (r == 0)
                        break;

        	sprintf(token,"network%i", i);
		r = config_lookup_string(cf, token, &name);
                if (r == 0)
                        goto error;

		strcpy(redes[i].file, file);
		strcpy(redes[i].name, name);
        }

        config_destroy(cf);
        return;
                
error:
        perror("Error al leer la configuracion\n");
        config_destroy(cf);

        exit(1);
}
Exemplo n.º 29
0
/**
 * Reads config value from cfg present at path and returns it. If no path found
 * default_value is used.
 *
 * @param cfg config file structure
 * @param path key to look for
 * @param default_value string returned if no value found
 * @returns value of key or default_value if no path found
 */
char *read_in_string(config_t *cfg, char *path, char *default_value)
{

	const char *value;
	char *dest;
	
	value = config_lookup_string(cfg, path);
	if (value == NULL)
		value = default_value;
	dest = malloc(sizeof(char) * strlen(value));
	strcpy(dest, value);
	return dest;
}
Exemplo n.º 30
0
Arquivo: main.c Projeto: hannenz/busy
/* Read configuration
 */
static gboolean read_config(AppData *app_data){
	Host *host;
	gint i = 0;
	config_setting_t *cs;
	GString *string;
	const gchar *name, *mysql_login, *mysql_password;

	app_data->hosts = NULL;
	string = g_string_new(NULL);

	config_init(&app_data->config);
	if (config_read_file(&app_data->config, CONFIG_FILE) == CONFIG_FALSE){
		syslog(LOG_ERR, "Failed to read configuration\n");
		return (FALSE);
	}

	if (config_lookup_string(&app_data->config, "mysql_login", &mysql_login) && config_lookup_string(&app_data->config, "mysql_password", &mysql_password)){
		app_data->mysql = db_connect(mysql_login, mysql_password);
	}

	for (i = 0; 1 ; i++){
		g_string_printf(string, "hosts.[%u]", i);
		cs = config_lookup(&app_data->config, string->str);

		if (cs){
			config_setting_lookup_string(cs, "name", &name);
			if ((host = host_new_from_config_setting(&app_data->config, cs)) != NULL){
				app_data->hosts = g_list_append(app_data->hosts, host);
			}
			else {
				syslog(LOG_WARNING, "Failed to read Host from config\n");
			}
		}
		else break;
	}

	db_hosts_store(app_data->hosts, app_data->mysql);
	return (TRUE);
}