Example #1
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;
        }
    }
}
Example #2
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);
}
Example #3
0
LIBCONFIG_API config_setting_t *config_setting_set_bool_elem(
  config_setting_t *vector, int index, int value)
{
  config_setting_t *element = NULL;

  if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST))
    return(NULL);

  if(index < 0)
  {
    if(! __config_vector_checktype(vector, CONFIG_TYPE_BOOL))
      return(NULL);
    
    element = config_setting_create(vector, NULL, CONFIG_TYPE_BOOL);
  }
  else
    element = config_setting_get_elem(vector, index);

  if(! element)
    return(NULL);

  if(! config_setting_set_bool(element, value))
    return(NULL);
  
  return(element);
}
Example #4
0
LIBCONFIG_API double config_setting_get_float_elem(
  const config_setting_t *vector, int index)
{
  config_setting_t *element = config_setting_get_elem(vector, index);

  return(element ? config_setting_get_float(element) : 0.0);
}
Example #5
0
LIBCONFIG_API long config_setting_get_int_elem(const config_setting_t *vector,
                                               int index)
{
  const config_setting_t *element = config_setting_get_elem(vector, index);

  return(element ? config_setting_get_int(element) : 0);
}
Example #6
0
/*
 * Check if the software can run on the hardware
 */
static int parse_hw_compatibility(config_t *cfg, struct swupdate_cfg *swcfg)
{
	const config_setting_t *setting, *hw;
	int count, i;
	const char *s;
	struct hw_type *hwrev;

	setting = get_setting(cfg, "hardware-compatibility", swcfg);
	if (setting == NULL) {
		ERROR("HW compatibility not found\n");
		return -1;
	}

	count = config_setting_length(setting);

	for(i = 0; i < count; ++i) {
		hw = config_setting_get_elem(setting, i);

		s = config_setting_get_string(hw);
		if (!s)
			continue;

		hwrev = (struct hw_type *)calloc(1, sizeof(struct hw_type));
		if (!hwrev) {
			ERROR("No memory: malloc failed\n");
			return -1;
		}

		strncpy(hwrev->revision, s, sizeof(hwrev->revision));
		LIST_INSERT_HEAD(&swcfg->hardware, hwrev, next);
		TRACE("Accepted Hw Revision : %s", hwrev->revision);
	}

	return 0;
}
Example #7
0
// {{{ session_is_valid_sessid()
int session_is_valid_sessid(const char *sessid)
{
	// TODO use timestamp: session not expires.
	
   struct config_t cfg;
   config_init(&cfg);
   config_setting_t *cs;
   config_setting_t *vs;

   if(!config_read_file(&cfg, OD_SESSION_FILE))
      return 0;

   int i=0;
   for(i=0; ;i++)
   {
      if( !(cs = config_setting_get_elem(cfg.root, i)) )
         break;

      if( !(vs = config_setting_get_member(cs, "sessid")) )
         continue;

      const char *res = config_setting_get_string(vs);
      if(res)
         if(strcmp(res, sessid)==0)
         {
            config_destroy(&cfg);
            return 1;
         }

   }

   config_destroy(&cfg);
   return 0;
}
Example #8
0
config_setting_t *config_setting_set_string_elem(config_setting_t *vector,
                                                 int idx, const char *value)
{
  config_setting_t *element = NULL;

  if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST))
    return(NULL);

  if(idx < 0)
  {
    if(! __config_vector_checktype(vector, CONFIG_TYPE_STRING))
      return(NULL);

    element = config_setting_create(vector, NULL, CONFIG_TYPE_STRING);
  }
  else
    element = config_setting_get_elem(vector, idx);

  if(! element)
    return(NULL);

  if(! config_setting_set_string(element, value))
    return(NULL);

  return(element);
}
Example #9
0
config_setting_t *config_setting_set_int64_elem(config_setting_t *vector,
                                                int idx, long long value)
{
  config_setting_t *element = NULL;

  if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST))
    return(NULL);

  if(idx < 0)
  {
    if(! __config_vector_checktype(vector, CONFIG_TYPE_INT64))
      return(NULL);

    element = config_setting_create(vector, NULL, CONFIG_TYPE_INT64);
  }
  else
  {
    element = config_setting_get_elem(vector, idx);

    if(! element)
      return(NULL);
  }

  if(! config_setting_set_int64(element, value))
    return(NULL);

  return(element);
}
Example #10
0
long long config_setting_get_int64_elem(const config_setting_t *vector,
                                        int idx)
{
  const config_setting_t *element = config_setting_get_elem(vector, idx);

  return(element ? config_setting_get_int64(element) : 0);
}
Example #11
0
static config_setting_t *interface_group_for(const char *ifname) {
	assert(config_setting_is_list(app_config));

	config_setting_t *default_if_conf = NULL;
	for (int i = 0; i < config_setting_length(app_config); i++) {
		config_setting_t *cur = config_setting_get_elem(app_config, i);

		config_setting_t *cur_ifname = config_setting_get_member(cur, "interface");
		if (cur_ifname != NULL) {
			const char *cur_ifname_str = config_setting_get_string(cur_ifname);
			assert(cur_ifname_str != NULL);
			if (strcmp(cur_ifname_str, ifname) == 0) return cur;
		}

		config_setting_t *cur_is_default = config_setting_get_member(cur, "default");
		if (
			default_if_conf == NULL &&
			cur_is_default != NULL &&
			config_setting_get_bool(cur_is_default)
		) {
			default_if_conf = cur;
		}
	}
	return default_if_conf;
}
Example #12
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);
    }
}
Example #13
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;
}
Example #14
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;
}
Example #15
0
config_setting_t *config_setting_set_float_elem(config_setting_t *vector,
                                                int idx, double value)
{
  config_setting_t *element = NULL;

  if((vector->type != CONFIG_TYPE_ARRAY) && (vector->type != CONFIG_TYPE_LIST))
    return(NULL);

  if(idx < 0)
  {
    if(! __config_vector_checktype(vector, CONFIG_TYPE_FLOAT))
      return(NULL);

    element = config_setting_create(vector, NULL, CONFIG_TYPE_FLOAT);
  }
  else
    element = config_setting_get_elem(vector, idx);

  if(! element)
    return(NULL);

  if(! config_setting_set_float(element, value))
    return(NULL);

  return(element);
}
Example #16
0
/*! \brief read volume tree node settings */
static int read_volume_tree_node_setting(config_setting_t * node_setting)
{
	int rv;
	const char * node_key;

	rv = config_setting_lookup_string(node_setting, "node", &node_key);
	if (rv != CONFIG_TRUE)
	{
		message(LOG_INFO, FACILITY_CONFIG, "No node key in hierarchy tree in shared config found.\n");
		return rv;
	}

	config_setting_t * children = config_setting_get_member(node_setting, "children");
	if (children == NULL)
		return CONFIG_TRUE;

	int i;
	config_setting_t * child;
	
	for (i = 0; (child = config_setting_get_elem(children, i)) != NULL; ++i)
	{
		rv = read_volume_tree_node_setting(child);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_INFO, FACILITY_CONFIG, "Failed to read hierarchy tree from shared config.\n"); 
			return rv;
		}
	}

	return CONFIG_TRUE;
}
Example #17
0
/*! \brief read pair setting */
static int read_pairs_setting(config_setting_t * setting, add_pair_mapping add, void * data)
{
	int i;
	config_setting_t * pair;
	for (i = 0; (pair = config_setting_get_elem(setting, i)) != NULL; ++i)
	{
		int rv;
		const char * local;
		const char * remote;

		rv = config_setting_lookup_string(pair, "local", &local);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Failed to read local key from pairs in shared config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_string(pair, "remote", &remote);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Failed to read remote key from pairs in shared config.\n");
			return CONFIG_FALSE;
		}

		add(data, local, remote);
	}

	return CONFIG_TRUE;
}
Example #18
0
int read_mapping_setting(config_setting_t * setting, add_mapping add, void * data)
{
	int i;
	config_setting_t * pair;
	for (i = 0; (pair = config_setting_get_elem(setting, i)) != NULL; ++i)
	{
		int rv;
		uint64_t id;

		rv = config_setting_lookup_uint64_t(pair, "id", &id);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Id config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		const char * name;
		rv = config_setting_lookup_string(pair, "name", &name);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Name config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		string str_name;
		xmkstring(&str_name, name);
		add(data, id, &str_name);	
	}

	return CONFIG_TRUE;
}
Example #19
0
//------------------------------------------------------------------------------
// UWAGA - istniejaca lista czujnikow JEST czyszczona !
// Dzieki temu kolejnosc czujnikow na liscie jest zgodna z kolejnoscia z pliku.
int sensors_load_configuration (config_setting_t *setting)
{
		config_setting_t *sensor_list = NULL, *sensor = NULL, *s = NULL ;
		unsigned int i ;
		const char *s_id = NULL, *s_name = NULL ;
		unsigned int s_res = 9, s_interval = 5 ;
		gboolean s_cached = FALSE ;
		
		sensor_list = config_setting_get_member(setting, "Sensor_List") ;
		
		clear_sensor_list() ;
		
		i=0 ;
		while ((sensor = config_setting_get_elem(sensor_list,i)) != NULL) {
				
				// ten kod powinien chyba byc w t_sensor.c
						s = config_setting_get_member(sensor, "sensor_id") ;
				if (s != NULL) s_id = config_setting_get_string(s) ;
				s = config_setting_get_member(sensor, "name") ;
				if (s != NULL) s_name = config_setting_get_string(s) ;
				s = config_setting_get_member(sensor, "resolution") ;
				if (s != NULL) s_res = config_setting_get_int(s) ;
				s = config_setting_get_member(sensor, "read_interval") ;
				if (s != NULL) s_interval = config_setting_get_int(s) ;
				s = config_setting_get_member(sensor, "cached") ;
				if (s != NULL) s_cached = config_setting_get_bool(s) ;
				
				add_sensor (s_name, s_id, s_res, s_interval, s_cached) ;
				
				i++ ;
		} ;	
		
		rebuild_sensors_tree(FALSE) ;
		return 0 ;
} ;
Example #20
0
config_setting_t *config_lookup_from(config_setting_t *setting,
                                     const char *path)
{
  const char *p = path;
  config_setting_t *found;

  for(;;)
  {
    while(*p && strchr(PATH_TOKENS, *p))
      p++;

    if(! *p)
      break;

    if(*p == '[')
      found = config_setting_get_elem(setting, atoi(++p));
    else
      found = config_setting_get_member(setting, p);

    if(! found)
      break;

    setting = found;

    while(! strchr(PATH_TOKENS, *p))
      p++;
  }

  return(*p ? NULL : setting);
}
Example #21
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);
    }
}
Example #22
0
int get_layout(struct layout_t* out, int num_frame, int id_layout)
{
	config_setting_t *category_list, *category, *layout_list, *layout, *frame_list, *frame;
	config_setting_t *pos, *size;
	config_t layout_config;
	int frame_length, i;

	out->num_frames = num_frame;
	out->perc_to_pixel = 0; 
	out->frames = (struct frame_t*) malloc (num_frame * sizeof(struct frame_t));

	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 = config_setting_get_elem(layout_list, id_layout);

	frame_list = config_setting_get_member(layout, "frame");
	frame_length = config_setting_length(frame_list);
	for(i = 0; i < frame_length; i++)
	{
		frame = config_setting_get_elem(frame_list, i);
		pos= config_setting_get_member(frame, "pos");
		size = config_setting_get_member(frame, "size");
		if (config_setting_lookup_float(pos, "x", &(out->frames[i].pos_x))==CONFIG_FALSE)
			printf("pos.x:\tONFIG_FALSE\n");

if ( config_setting_lookup_float(pos, "y", &(out->frames[i].pos_y))==CONFIG_FALSE)
			printf("pos.y:\tONFIG_FALSE\n");
		
if ( config_setting_lookup_float(size, "w", &(out->frames[i].width))==CONFIG_FALSE)
			printf("size.w:\tONFIG_FALSE\n");

if ( config_setting_lookup_float(size, "h", &(out->frames[i].height))==CONFIG_FALSE)
			printf("size.h:\tONFIG_FALSE\n");

		
		config_setting_lookup_float(frame, "rot", &(out->frames[i].rot));
	}

	
	config_destroy(&layout_config);
	return 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;
}
Example #24
0
gboolean config_setting_remove_elem(config_setting_t * parent, unsigned int index)
{
    config_setting_t *s = config_setting_get_elem(parent, index);
    if (s == NULL)
        return FALSE;
    _config_setting_t_remove(s);
    return TRUE;
}
Example #25
0
static void typecheck_config_ifgrouplist(config_setting_t *list) {
	assert(config_setting_is_list(list));
	for (int i = 0; i < config_setting_length(list); i++) {
		config_setting_t *ifgroup = config_setting_get_elem(list, i);
		if (!config_setting_is_group(ifgroup))
			die("Interface group lists must only contain groups.");
		typecheck_config_ifgroup(ifgroup);
	}
}
Example #26
0
void config_setting_copy_aggregate (config_setting_t *parent, const config_setting_t *src)
{
	config_setting_t *newAgg;
	int i, n;
	newAgg = config_setting_add (parent, config_setting_name (src), config_setting_type (src));

	if (newAgg == NULL)
		return;

	n = config_setting_length (src);

	for (i = 0; i < n; i++) {
		if (config_setting_is_group (src)) {
			config_setting_copy_simple (newAgg, config_setting_get_elem (src, i));
		} else {
			config_setting_copy_elem (newAgg, config_setting_get_elem (src, i));
		}
	}
}
Example #27
0
/**
 * @param[in] root Root section of config.
 * @param[in] zconf Config handle.
 * @return True on success.
 */
bool zconfig_load_sections(const config_setting_t *root, zconfig_t *zconf)
{
    // global section
    config_setting_t *section = config_setting_get_member(root, ZCFG_SECTION_GLOBAL);
    if (!section) {
        ZLOG(LOG_ERR, "config: %s section not found", ZCFG_SECTION_GLOBAL);
        return false;
    }
    if (0 != zconfig_global_load(section, zconf)) {
        ZLOG(LOG_ERR, "config: failed to load %s section", ZCFG_SECTION_GLOBAL);
        return false;
    }

    // all other sections parse as scopes
    u_int sections_count = (u_int) config_setting_length(root);

    // global section + minimum one scope section
    if (sections_count < 2) {
        ZLOG(LOG_ERR, "config: no scopes found");
        return false;
    }

    utarray_init(&zconf->scopes, &ut_ptr_icd);
    for (u_int i = 0; i < sections_count; i++) {
        section = config_setting_get_elem(root, i);

        if (!config_setting_is_group(section)) {
            continue;
        }
        if (0 == strcmp(section->name, ZCFG_SECTION_GLOBAL)) {
            continue;
        }

        for (size_t j = 0; j < utarray_len(&zconf->scopes); j++) {
            zconfig_scope_t *sc = *(zconfig_scope_t **) utarray_eltptr(&zconf->scopes, j);
            if (0 == strcasecmp(sc->name, section->name)) {
                ZLOG(LOG_ERR, "config: duplicate scope %s", section->name);
                return false;
            }
        }

        zconfig_scope_t *scope = malloc(sizeof(*scope));
        if (0 == zconfig_scope_load(section, scope)) {
            utarray_push_back(&zconf->scopes, &scope);
            ZLOG(LOG_DEBUG, "config: loaded scope %s", scope->name);
        } else {
            zconfig_scope_destroy(scope);
            free(scope);
            ZLOG(LOG_ERR, "config: failed to load scope %s", section->name);
            return false;
        }
    }

    return true;
}
Example #28
0
int read_node_list_shared_config(config_t * config)
{
	config_setting_t * node_list = config_lookup(config, "node:list");
	if (node_list == NULL)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "No node list section in shared config was found.\n");
		return CONFIG_FALSE;
	}

	config_setting_t * node_entry;
	int i;

	for (i = 0; (node_entry = config_setting_get_elem(node_list, i)) != NULL; ++i)
	{
		
		uint64_t id;
		const char * name;
		const char * address;
		int rv;

		rv = config_setting_lookup_uint64_t(node_entry, "id", &id);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Id config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_string(node_entry, "name", &name);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Name config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_string(node_entry, "address", &address);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Addres config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		string str_name;
		string str_address;

		xmkstring(&str_name, name);
		xmkstring(&str_address, address);

		node nod = try_create_node(id, &str_name, &str_name, read_tcp_port_setting(node_entry));
		if (nod)
			zfsd_mutex_unlock(&nod->mutex);
	}

	return CONFIG_TRUE;
}
Example #29
0
void *get_elem_from_idx(parsertype p, void *node, int idx)
{
	switch (p) {
	case LIBCFG_PARSER:
		return config_setting_get_elem(node, idx);
	case JSON_PARSER:
		return json_object_array_get_idx(node, idx);
	}

	return NULL;
}
Example #30
0
int config_setting_get_bool_elem(const config_setting_t *vector, int idx)
{
  config_setting_t *element = config_setting_get_elem(vector, idx);

  if(! element)
    return(CONFIG_FALSE);

  if(element->type != CONFIG_TYPE_BOOL)
    return(CONFIG_FALSE);

  return(element->value.ival);
}