Пример #1
0
bool_t getBoolConf(param_t param)
{
	config_setting_t *setting = NULL;

	switch (param) {
		case ALLOW_TEXTMESSAGE:
			setting = config_lookup(&configuration, "allow_textmessage");
			if (!setting)
				return true;
			else
				return config_setting_get_bool(setting);
			break;
		case ENABLE_BAN:
			setting = config_lookup(&configuration, "enable_ban");
			if (!setting)
				return false;
			else
				return config_setting_get_bool(setting);
			break;
		case SYNC_BANFILE:
			setting = config_lookup(&configuration, "sync_banfile");
			if (!setting)
				return false;
			else
				return config_setting_get_bool(setting);
			break;
		default:
			doAssert(false);
	}
}
Пример #2
0
int dvfs_read_from_config(void * vp, struct config_t * cfg, char * buffer, 
                          char * prefix) {
  config_setting_t *setting;
  struct dvfs_information * info = vp;
  int was_set = 0;
  info->freq_before = 0;
  info->freq_after = 0;
  sprintf(buffer, "%s.%s_freq_before", prefix, DVFS_CONFIG_STRING);
  setting = config_lookup(cfg, buffer);
  if (setting) {
    info->freq_before = config_setting_get_int(setting);
#ifdef VERBOSE
    fprintf(stderr,"%s = %" PRId32 "\n",buffer,info->freq_before);
#endif
    was_set = 1;
  }
  sprintf(buffer, "%s.%s_freq_after", prefix, DVFS_CONFIG_STRING);
  setting = config_lookup(cfg, buffer);
  if (setting) {
    info->freq_after = config_setting_get_int(setting);
#ifdef VERBOSE
    fprintf(stderr,"%s = %" PRId32 "\n",buffer,info->freq_after);
#endif
    was_set = 1;
  }
  return was_set;
}
Пример #3
0
void configureTuner(config_t *propConfig) {
    config_setting_t *blockSetting = config_lookup(propConfig, "tuner.block");
    config_setting_t *gridSetting = config_lookup(propConfig, "tuner.grid");

    if (blockSetting != NULL && gridSetting != NULL) {
        int length = config_setting_length(blockSetting); // Only need the length of one metric
        performanceMetricCount = length;
        performanceMetric.blockDimList = malloc(sizeof(CudaDim) * length);
        performanceMetric.gridDimList = malloc(sizeof(CudaDim) * length);
        int i;
        for (i = 0; i < length; ++i) {
            int x, y, z;
            config_setting_t *block = config_setting_get_elem(blockSetting, i);
            config_setting_t *grid = config_setting_get_elem(gridSetting, i);

            config_setting_lookup_int(block, "x", &x);
            config_setting_lookup_int(block, "y", &y);
            config_setting_lookup_int(block, "z", &z);
            performanceMetric.blockDimList[i].x = (uint32_t) x;
            performanceMetric.blockDimList[i].y = (uint32_t) y;
            performanceMetric.blockDimList[i].z = (uint32_t) z;

            config_setting_lookup_int(grid, "x", &x);
            config_setting_lookup_int(grid, "y", &y);
            config_setting_lookup_int(grid, "z", &z);
            performanceMetric.gridDimList[i].x = (uint32_t) x;
            performanceMetric.gridDimList[i].y = (uint32_t) y;
            performanceMetric.gridDimList[i].z = (uint32_t) z;
        }
    }
}
Пример #4
0
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;
}
Пример #5
0
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;
}
Пример #6
0
static config_setting_t *find_node_libconfig(config_t *cfg,
					const char *field, struct swupdate_cfg *swcfg)
{
	config_setting_t *setting;
	struct hw_type *hardware;

	char node[1024];

	if (!field)
		return NULL;

	hardware = &swcfg->hw;

	if (strlen(swcfg->running_mode) && strlen(swcfg->software_set)) {
		/* Try with both software set and board name */
		if (strlen(hardware->boardname)) {
			snprintf(node, sizeof(node), "%s.%s.%s.%s.%s",
				NODEROOT,
				hardware->boardname,
				swcfg->software_set,
				swcfg->running_mode,
				field);
			setting = config_lookup(cfg, node);
			if (setting)
				return setting;
		}
		/* still here, try with software set and mode */
		snprintf(node, sizeof(node), "%s.%s.%s.%s",
			NODEROOT,
			swcfg->software_set,
			swcfg->running_mode,
			field);
		setting = config_lookup(cfg, node);
		if (setting)
			return setting;

	}

	/* Try with board name */
	if (strlen(hardware->boardname)) {
		snprintf(node, sizeof(node), "%s.%s.%s",
			NODEROOT,
			hardware->boardname,
			field);
		setting = config_lookup(cfg, node);
		if (setting)
			return setting;
	}
	/* Fall back without board entry */
	snprintf(node, sizeof(node), "%s.%s",
		NODEROOT,
		field);
	return config_lookup(cfg, node);
}
Пример #7
0
static config_setting_t * create_tree(const config_t * config, config_setting_t * prev_setting, char * prev_entry, char * path, int type, va_list ap)
{
	char * entry = NULL;
	char * new_path;
	config_setting_t * setting = NULL;
	config_setting_t * ret = NULL;

	if( prev_setting == NULL) {
		prev_setting = config_root_setting(config);
	}

	entry = va_arg(ap,char*);

	/* no more leaf */
	if(entry == NULL) {
		/* check if leaf exists */
		setting = config_lookup(config, path);
		if( setting == NULL) {
			/* create the leaf */
			setting=config_setting_add(prev_setting, prev_entry,type);
		}
		return setting;
	}

	/* still not finished */
	/* check if we need to create a group */
	if( path ) {
		setting = config_lookup(config, path);
		if( setting == NULL ) {
			/* create a group with previous path */
			setting = config_setting_add(prev_setting, prev_entry, CONFIG_TYPE_GROUP);
			if(setting == NULL) {
				return NULL;
			}
		}
	}

	/* update path */
	if( path ) {
		new_path = strconcat(path,".",entry,NULL);
	} else {
		new_path = strdup(entry);
	}

	ret = create_tree(config,setting,entry,new_path,type,ap);
	free(new_path);

	return ret;
}
Пример #8
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);
	}
	
	
}
Пример #9
0
int mst_read_globals(config_t *pconfig)
{
    int rv = -1;
    config_setting_t *globals;
    int intval = 0;

    // Load default globals value
    g_mst_conf.mpool_size = 80; // 80 MB
    g_mst_conf.mbuf_size = 16; // 16 MB
    g_mst_conf.nw_streams = 10; // 10 outstreams

    globals = config_lookup(pconfig, "globals");

    if (!globals) {
        fprintf(stderr, "No globals sections was found. Proceeding with defaults.\n");
        return CONFIG_TRUE;
    }

    rv = config_setting_lookup_int(globals, "mpool", &intval);
    if (CONFIG_TRUE == rv) {
        g_mst_conf.mpool_size = intval; 
    }
    rv = config_setting_lookup_int(globals, "mbuf", &intval);
    if (CONFIG_TRUE == rv) {
        g_mst_conf.mbuf_size = intval; 
    }
    rv = config_setting_lookup_int(globals, "nw_streams", &intval);
    if (CONFIG_TRUE == rv) {
        g_mst_conf.nw_streams = intval; 
    }

    return CONFIG_TRUE;
}
Пример #10
0
// 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;
}
Пример #11
0
const char *config_get_string_elem(config_t *config, char *setting, int element, const char *initial)
{
	const char *value;
	config_setting_t *config_setting = config_lookup(config,setting);

	PRINT_SETTING;
	if (config_setting == NULL)
	{
		PRINT_NOT_FOUND;
		value = initial;
	}
	else
	{
		if ((value = config_setting_get_string_elem(config_setting,element)) == NULL)
		{
			PRINT_NOT_FOUND;
			value = initial;
		}
	}

	PRINT_VALUE_STR;

	return value;

}
Пример #12
0
int main()
{
  /* Initialize the configuration */
  config_init(&cfg);

  /* Load the file */
  printf("loading [sample.cfg]..");
  if (!config_read_file(&cfg, "sample.cfg"))
    printf("failed\n");
  else
  {
    printf("ok\n");
    
    /* Display the "values" array */
    printf("display \"values\"..");
    config_setting_t *array = config_lookup(&cfg, "values");
    if (!array)
      printf("failed\n");
    else
    {
      long value1,value2;
      value1 = config_setting_get_int_elem(array, 0);
      value2 = config_setting_get_int_elem(array, 1);
      printf("[%lu %lu]..ok\n", value1, value2);

      printf("Done!\n");
    }

  }

  /* Free the configuration */
  config_destroy(&cfg);

  return 0;
}
Пример #13
0
/**********************
__get_unused_group_on_path
find an unused group, DO NOT CREATE IT and return its name
returned string must be freed
return NULL on error
**********************/
char * __get_unused_group_on_path(const char * table, const char * file, char * path)
{
	char tag[7];
	int index = 0;
	config_setting_t * setting;
	const config_t * config;

	SDL_LockMutex(entry_mutex);
	config = get_config(table,file);
	if(config==NULL) {
		SDL_UnlockMutex(entry_mutex);
		return NULL;
	}

	sprintf(tag,"A%05x",index);

	if(path != NULL) {
		setting = config_lookup(config,path);
		free(path);
	} else {
		setting = config_root_setting(config);
	}

	while( config_setting_add(setting,tag,CONFIG_TYPE_GROUP) == NULL ) {
		index++;
		sprintf(tag,"A%05x",index);
	}

	config_setting_remove(setting,tag);
	SDL_UnlockMutex(entry_mutex);

	return strdup(tag);
}
Пример #14
0
config_setting_t *cfgLookup(const config_t *config, const TCHAR *path)
{
	char uPath[MAX_PATH];

	UTF8_Encode(path, uPath, MAX_PATH);
	return config_lookup(config, uPath);
}
Пример #15
0
/*********************
return true if entry or group exists
*********************/
static bool __exist(const char * table, const char * file, va_list ap)
{
	const config_t * config;
	char * path;
	config_setting_t * setting = NULL;

	SDL_LockMutex(entry_mutex);
	config = get_config(table,file);
	SDL_UnlockMutex(entry_mutex);
	if(config==NULL) {
		return false;
	}

	path = get_path(ap);
	if( path == NULL ) {
		return false;
	}

	setting = config_lookup (config, path);
	free(path);
	if( setting == NULL ) {
		return false;
	}

	return true;
}
Пример #16
0
static int processRequest(char *request) {
    int count = 0;
    int responseTotal = 0;
    
    config_setting_t *responseConfig = NULL;
    config_setting_t *responseCurrent = NULL;
    const char *responseValue = NULL;
    const char *requestName = NULL;
    const char *requestValue = NULL;
    long volume;
    
    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
    pthread_mutex_lock(&lockConfig);
    
    responseConfig = config_lookup(&config, "response");
    responseTotal = config_setting_length(responseConfig);
    
    for(count = 0; count < responseTotal; count++) {
        responseCurrent = config_setting_get_elem(responseConfig, count);
        if((responseValue = config_setting_get_string_elem(responseCurrent, 1)) != NULL &&
        strcmp(responseValue, request) == 0) {
            responseValue = config_setting_get_string_elem(responseCurrent, 2);
            if(config_setting_get_bool_elem(responseCurrent, 0) == 1) { // formulating default response
            
                pthread_mutex_unlock(&lockConfig);
                pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
                
                common_data.interface->reply(responseValue, strlen(responseValue));
            }
            else { // attempt to formulate custom response
                requestName = config_setting_name(responseCurrent);
                
                pthread_mutex_unlock(&lockConfig);
                pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
                
                if(strcmp(requestName, "volume") == 0) {
                    if(getMixer(&volume) == EXIT_FAILURE) {
                        return EXIT_FAILURE;
                    }
                    replyVolumeCommand(&volume);
                }
                else {
                    statusInfo.retrieve(requestName, &requestValue);
                    if(requestValue != NULL)
                        replyDeviceCommand((char *)requestName, (char *)requestValue);
                    else // custom response not possible, reverting to default value
                        replyDeviceCommand((char *)requestName, (char *)responseValue);
                }
            }
            syslog(LOG_DEBUG, "Successfully processed request: %s", request);
            return EXIT_SUCCESS; // command is matched, returning
        }
        else {
            pthread_mutex_unlock(&lockConfig);
            pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
        }
    }
    syslog(LOG_DEBUG, "Could not identify request: %s", request);
    return EXIT_SUCCESS;
}
Пример #17
0
void thread_manager_mod_init(na_module_t *module, void *userdata)
{
	char				**k_setting;
	config_setting_t	*k;
	char				tmpbuffer[256];

	assert( module != NULL );
	if ( module->object_new )
		module->data = (*module->object_new)(userdata);
	if ( module->data == NULL )
	{
		l_errorf("failed to initialize static module %s", module->name);
		return;
	}

	/* search and inject configuration
	 * noya.modules.<modulename>.<key> = <value>
	 */
	k_setting = module->settings;
	if ( k_setting )
	{
		while ( *k_setting != NULL )
		{
			snprintf(tmpbuffer, sizeof(tmpbuffer), "noya.modules.%s.%s",
				module->name, *k_setting);
			k = config_lookup(&g_config, tmpbuffer);
			if ( k != NULL )
				(*module->object_config)(module->data, *k_setting, k);
			k_setting++;
		}
	}

	if ( module->object_prepare )
		(*module->object_prepare)(module->data, NULL);
}
Пример #18
0
void configure_cgi_handlers(spade_server* server, config_t* configuration) {
    config_setting_t* handler_settings = config_lookup(configuration,
            "cgi.handlers");
    int cgi_handler_count = config_setting_length(handler_settings);

    for (int n = 0; n < cgi_handler_count; n++) {
        config_setting_t* handler_setting = config_setting_get_elem(
                handler_settings, n);
        const char* handler = NULL;
        config_setting_lookup_string(handler_setting, "handler", &handler);

        const char* url = NULL;
        config_setting_lookup_string(handler_setting, "url", &url);

        if(!register_cgi_handler(server, url, handler)) {
            log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                    "Registered CGI handler '%s' for URL prefix '%s'",
                    handler, url);
        }
    }
    if (server->cgi_handler_count == 0) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No CGI handlers registered");
    } else {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "Registered a total of %d CGI handlers",
                server->cgi_handler_count);
    }
}
Пример #19
0
void configure_clay_handlers(spade_server* server, config_t* configuration) {
    config_setting_t* handler_settings = config_lookup(configuration,
            "clay.handlers");
    if (!handler_settings) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No Clay handlers registered");
        return;
    }
    int clay_handler_count = config_setting_length(handler_settings);

    for (int n = 0; n < clay_handler_count; n++) {
        config_setting_t* handler_setting = config_setting_get_elem(
                handler_settings, n);
        const char* endpoint = NULL;
        config_setting_lookup_string(handler_setting, "endpoint", &endpoint);

        const char* url = NULL;
        config_setting_lookup_string(handler_setting, "url", &url);

        if(!register_clay_handler(server, url, endpoint)) {
            log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                    "Registered Clay handler for URL prefix '%s' at endpoint %s",
                    url, endpoint);
        }
    }
    if (server->clay_handler_count == 0) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No Clay handlers registered");
    } else {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "Registered a total of %d Clay handlers",
                server->clay_handler_count);
    }
}
Пример #20
0
void print_layouts(int num_frame)
{
	
	config_setting_t *category_list, *category, *layout_list, *layout;
	config_t layout_config;
	int layout_length, i;
	const char* ascii_image;

	config_init(&layout_config);
	config_read_file(&layout_config, "./layout.cfg");
	
	category_list = config_lookup(&layout_config, "application.layout_group");
	category = config_setting_get_elem(category_list, num_frame - MIN_NUM_FRAME);
	
	layout_list = config_setting_get_member(category, "layout");
	layout_length = config_setting_length(layout_list);
	for(i = 0; i < layout_length; i++)
	{
		layout = config_setting_get_elem(layout_list, i);
		config_setting_lookup_string(layout, "image", &ascii_image);
		printf(" %c)\n", 'a' + i);
		printf("%s\n", ascii_image);
	}
	
	config_destroy(&layout_config);
}
Пример #21
0
int privio_reader(config_t *cfg, const char **args){
  int in_file, n;
  void *buf;
  config_setting_t *read_block_size;
  long long block_size;

  privio_debug(cfg, DBG_INFO, "Reading from %s\n", args[0]);
  in_file = open(args[0], O_RDONLY);

  if (in_file == -1){
    privio_debug(cfg, DBG_VERBOSE, "Error opening file %s: %s\n", args[0], strerror(errno));
    return errno;
  }

  privio_debug(cfg, DBG_DEBUG3, "Opened %s as descriptor %d\n", args[0], in_file);

  read_block_size = config_lookup(cfg, "privio.io.reader_block_size");
  block_size = config_setting_get_int(read_block_size);

  buf = (void*)malloc(block_size);

  /* read from stdin, write to fp */
  while ((n = read(in_file, buf, block_size)) > 0){
    write(fileno(stdout), buf, n);
  }

  if (n == -1)
    privio_debug(cfg, DBG_VERBOSE, "Error reading file %s: %s\n", args[0], strerror(errno));

  privio_debug(cfg, DBG_INFO, "Closing %s\n", args[0]);

  close(in_file);
  
  return 0;
}
Пример #22
0
/*! \brief read dokan config from local config */
static int read_dokan_config(config_t * config)
{
	config_setting_t * dokan_setting = config_lookup(config, "dokan");
	if (dokan_setting == NULL)
	{
		message(LOG_INFO, FACILITY_CONFIG, "No dokan section was found in local config.\n");
		return CONFIG_TRUE;
	}

	int rv;
	const char * volume_name;
	/* dokan::volume_name */
	rv = config_setting_lookup_string(dokan_setting, "volume_name", &volume_name);
	if (rv == CONFIG_TRUE)
	{
		xmkstring(&(zfs_config.dokan.volume_name), volume_name);
	}

	const char * file_system_name;
	/* dokan::filesystem_name */
	rv = config_setting_lookup_string(dokan_setting, "file_system_name", &file_system_name);
	if (rv == CONFIG_TRUE)
	{
		xmkstring(&(zfs_config.dokan.file_system_name), file_system_name);
	}

	return CONFIG_TRUE;
}
Пример #23
0
static int
load_mods(config_t *config, config_setting_t *setting)
{
    int err;
    unsigned int mod_count;
    int i;
    const char* mod_name;
    const char* mod_so;
    const char* mod_ident;
    config_setting_t *mod_setting;
    err = 0;

    fprintf(stderr, "load mods from config\n");
    setting = config_lookup(config, "mods");
    if (setting != NULL) {
        mod_count = config_setting_length(setting);
        for (i = 0; i < mod_count; ++i) {
            mod_setting = config_setting_get_elem(setting, i);
            if (mod_setting) {
                if (!config_setting_lookup_string(mod_setting,
                                                  "name",
                                                  &mod_name) ||
                        !config_setting_lookup_string(mod_setting,
                                                      "so",
                                                      &mod_so)) {
                    continue;
                }
                if (!config_setting_lookup_string(mod_setting,
                                                  "ident",
                                                  &mod_ident)) {
                    mod_ident = NULL;
                }
                fprintf(stderr, "load module %s - %s - [%s]\n",
                        mod_name, mod_so, mod_ident);
                module_t *mod = module_open(mod_name,
                                            mod_ident,
                                            mod_so,
                                            RTLD_NOW);
                if (!mod) {
                    err = 1;
                    break;
                }
                if (module_map_insert(&g_config.module_root, mod) == NULL) {
                    err = 1;
                    module_close(mod);
                    break;
                }
                if (module_call_init_func(mod, &g_config)) {
                    fprintf(stderr, "ERROR %s returned not 0\n", mod->name);
                    err = 1;
                    module_close(mod);
                    break;
                }
            }
        }
    }

    return err;
}
Пример #24
0
/*********************************************
Update an entry from a network frame
return RET_NOK on error
*********************************************/
ret_code_t entry_update(char * data)
{
	char * elements[5] = {NULL,NULL,NULL,NULL,NULL};
	config_setting_t * setting;
	const config_t * config= NULL;
	int value;
	char * token;
	int index = 0;
	ret_code_t ret = RET_NOK;

	token = _strsep(&data,NETWORK_DELIMITER);
	while( token != NULL ) {
		elements[index] = strdup(token);
		index++;
		if(index>5) {
			werr(LOGDEV,"Split string error");
			goto entry_update_cleanup;
		}
		token = _strsep(&data,NETWORK_DELIMITER);
	}

	SDL_LockMutex(entry_mutex);
	config = get_config(elements[1],elements[2]);
	if(config==NULL) {
		goto entry_update_cleanup;
	}

	setting = config_lookup (config, elements[3]);
	if(setting==NULL) {
		goto entry_update_cleanup;
	}

	if( strcmp(elements[0],ENTRY_TYPE_INT) == 0 ) {
		value = atoll(elements[4]);
		if(config_setting_set_int (setting, value) == CONFIG_FALSE) {
			werr(LOGUSER,"Errror setting %s/%s/%s to %d",elements[1],elements[2],elements[3],value);
		} else {
			write_config(config,elements[1],elements[2]);
		}
	} else if( strcmp(elements[0],ENTRY_TYPE_STRING) == 0 ) {
		if(config_setting_set_string (setting,elements[4]) == CONFIG_FALSE) {
			werr(LOGUSER,"Errror setting %s/%s/%s to %s",elements[1],elements[2],elements[3],elements[4]);
		} else {
			write_config(config,elements[1],elements[2]);
		}
	}

	ret = RET_OK;

entry_update_cleanup:
	SDL_UnlockMutex(entry_mutex);
	for(index=0; index<5; index++) {
		if(elements[index]) {
			free(elements[index]);
		}
	}

	return ret;
}
Пример #25
0
/**
 * Checks if the configuration is valid. The function checks if all 
 * required parameters are set and adds default values if necessary.
 * @param cfg configuration
 */
void config_check(config_t *cfg)
{
    int i, j;
    const char *s;
    double f;
    config_setting_t *cs, *vs;

    for (i = 0; defaults[i].name; i++) {
        /* Lookup setting group */
        cs = config_lookup(cfg, defaults[i].group);
        if (!cs)
            cs = config_setting_add(config_root_setting(cfg),
                                    defaults[i].group, CONFIG_TYPE_GROUP);

        /* (1) Check for string */
        if (defaults[i].type == CONFIG_TYPE_STRING) {
            if (config_setting_lookup_string(cs, defaults[i].name, &s))
                continue;

            /* Add default value */
            vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_STRING);
            config_setting_set_string(vs, defaults[i].val.sval);
        /* (2) Check for float */            
        } else if (defaults[i].type == CONFIG_TYPE_FLOAT) {
            if (config_setting_lookup_float(cs, defaults[i].name, &f))
                continue;

            /* Check for mis-interpreted integer */
            if (config_setting_lookup_int(cs, defaults[i].name, &j)) {
                config_setting_remove(cs, defaults[i].name);
                vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_FLOAT);
                config_setting_set_float(vs, (double) j);
                continue;
            }

            /* Add default value */
            vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_FLOAT);
            config_setting_set_float(vs, defaults[i].val.fval);
        /* (3) Check for integer */            
        } else if (defaults[i].type == CONFIG_TYPE_INT) {
            if (config_setting_lookup_int(cs, defaults[i].name, &j))
                continue;

            /* Check for mis-interpreted float */
            if (config_setting_lookup_float(cs, defaults[i].name, &f)) {
                config_setting_remove(cs, defaults[i].name);
                vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_INT);
                config_setting_set_int(vs, (long) round(f));
                continue;
            }

            /* Add default value */
            vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_INT);
            config_setting_set_int(vs, defaults[i].val.ival);
        } else {
            error("Unknown configuration type");
        }
    }
}
Пример #26
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;
}
Пример #27
0
LIBCONFIG_API int config_lookup_bool(const config_t *config, const char *path)
{
  const config_setting_t *s = config_lookup(config, path);
  if(! s)
    return(0);

  return(config_setting_get_bool(s));
}
Пример #28
0
int config_lookup_float (const config_t * config, const char *path, double *value)
{
    const config_setting_t *s = config_lookup (config, path);
    if (!s)
        return (CONFIG_FALSE);

    return (__config_setting_get_float (s, value));
}
Пример #29
0
int config_lookup_int64 (const config_t * config, const char *path, long long *value)
{
    const config_setting_t *s = config_lookup (config, path);
    if (!s)
        return (CONFIG_FALSE);

    return (__config_setting_get_int64 (s, value));
}
Пример #30
0
void recording_initialise(config_t *config, int gfx_event_id)
{
	config_setting_t *setting_recording = config_lookup(config, CFG_RECORDING);
	if (setting_recording != NULL)
	{
		configure(setting_recording, gfx_event_id);
	}
}