当前位置: 首页>>代码示例>>C++>>正文


C++ config_setting_length函数代码示例

本文整理汇总了C++中config_setting_length函数的典型用法代码示例。如果您正苦于以下问题:C++ config_setting_length函数的具体用法?C++ config_setting_length怎么用?C++ config_setting_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了config_setting_length函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: configure_cgi_handlers

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);
    }
}
开发者ID:peplin,项目名称:spade,代码行数:29,代码来源:config.c

示例2: pc_group_can_use_command

/**
 * Checks if player group can use @/#command
 * @param group_id ID of the group
 * @param command Command name without @/# and params
 * @param type enum AtCommanndType { COMMAND_ATCOMMAND = 1, COMMAND_CHARCOMMAND = 2 }
 */
bool pc_group_can_use_command(int group_id, const char *command, AtCommandType type)
{
	int result = 0;
	config_setting_t *commands = NULL;
	GroupSettings *group = NULL;

	if (pc_group_has_permission(group_id, PC_PERM_USE_ALL_COMMANDS))
		return true;

	if ((group = id2group(group_id)) == NULL)
		return false;

	commands = group->commands;
	if (commands != NULL) {
		config_setting_t *cmd = NULL;
		
		// <commandname> : <bool> (only atcommand)
		if (type == COMMAND_ATCOMMAND && config_setting_lookup_bool(commands, command, &result))
			return (bool)result;

		// <commandname> : [ <bool>, <bool> ] ([ atcommand, charcommand ])
		if ((cmd = config_setting_get_member(commands, command)) != NULL &&
		    config_setting_is_aggregate(cmd) && config_setting_length(cmd) == 2)
			return (bool)config_setting_get_bool_elem(cmd, AtCommandType2idx(type));
	}
	return false;
}
开发者ID:AsaK,项目名称:rathena,代码行数:33,代码来源:pc_groups.c

示例3: zcfg_load_client_rules

/**
 * Load client rules list.
 * @param[in] option Configuration option.
 * @param[in,out] rules Resulting rules.
 * @return <0 - error. 0 - success. >0 - not found.
 */
static int zcfg_load_client_rules(const config_setting_t *option, zclient_rules_t *rules)
{
    zclient_rules_init(rules);

    if (!option) {
        return 1;
    }

    if (CONFIG_TYPE_LIST != option->type) {
        return -1;
    }

    int count = config_setting_length(option);

    zclient_rule_parser_t *rule_parser = zclient_rule_parser_new();

    for (int i = 0; i < count; i++) {
        const char *str = config_setting_get_string_elem(option, i);
        if (!zclient_rule_parse(rule_parser, rules, str)) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid client rule: %s", option->parent->name, option->name, str);
            zclient_rule_parser_free(rule_parser);
            return -1;
        }
    }

    zclient_rule_parser_free(rule_parser);
    return 0;
}
开发者ID:intersvyaz,项目名称:zerod,代码行数:34,代码来源:config.c

示例4: zcfg_load_uint16_array

/**
 * Load uint16 array.
 * @param[in] option Configuration option.
 * @param[in,out] array Resulting array.
 * @return <0 - error. 0 - success. >0 - not found.
 */
static int zcfg_load_uint16_array(const config_setting_t *option, UT_array *array)
{
    utarray_init(array, &ut_uint16_icd);

    if (!option) {
        return 1;
    }

    if (CONFIG_TYPE_ARRAY != option->type) {
        return -1;
    }

    int count = config_setting_length(option);

    for (int i = 0; i < count; i++) {
        int item = config_setting_get_int_elem(option, i);

        if ((item < 0) || (item > UINT16_MAX)) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid port: %d", option->parent->name, option->name, item);
            utarray_done(array);
            return -1;
        }

        uint16_t port = (uint16_t) item;
        utarray_push_back(array, &port);
    }

    if (utarray_len(array)) {
        utarray_sort(array, uint16_cmp);
    }

    return 0;
}
开发者ID:intersvyaz,项目名称:zerod,代码行数:39,代码来源:config.c

示例5: processRequest

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;
}
开发者ID:therealmuffin,项目名称:synchronator,代码行数:60,代码来源:processAscii.c

示例6: upd8_config_parse

// 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;
}
开发者ID:shalecraig,项目名称:updatemgr,代码行数:33,代码来源:config.c

示例7: assert

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;
}
开发者ID:eatnumber1,项目名称:macspoof,代码行数:25,代码来源:macspoof.c

示例8: configureTuner

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;
        }
    }
}
开发者ID:psawmora,项目名称:couldhopper-gpu,代码行数:31,代码来源:smpp_codec.c

示例9: parse_hw_compatibility

/*
 * 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;
}
开发者ID:pombredanne,项目名称:swupdate,代码行数:38,代码来源:parse_config.c

示例10: print_layouts

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);
}
开发者ID:ChiaraCaiazza,项目名称:collageMaker,代码行数:26,代码来源:layout.c

示例11: configure_clay_handlers

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);
    }
}
开发者ID:peplin,项目名称:spade,代码行数:34,代码来源:config.c

示例12: load_mods

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;
}
开发者ID:MarkusPfundstein,项目名称:Network-HTTP-Server,代码行数:59,代码来源:main.c

示例13: typecheck_config_ifgrouplist

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);
	}
}
开发者ID:eatnumber1,项目名称:macspoof,代码行数:9,代码来源:macspoof.c

示例14: channel_read_sub

/**
 * Attempt to create a global channel from the channel config
 * @param chan: Channel list
 * @param tmp_chan: Temporary channel data
 * @param i: Index
 * @return True on success or false on failure
 */
bool channel_read_sub(config_setting_t *chan, struct Channel *tmp_chan, uint8 i) {
	config_setting_t  *group_list = NULL;
	int delay = 1000, autojoin = 0, leave = 1, chat = 1, color_override = 0,
		self_notif = 1, join_notif = 0, leave_notif = 0;
	int type = CHAN_TYPE_PUBLIC, group_count = 0;
	const char *name = NULL, *password = NULL, *alias = NULL, *color_str = "Default", *type_str = NULL;

	if (tmp_chan == NULL)
		return false;

	if (!config_setting_lookup_string(chan, "name", &name)) {
		ShowError("Please input channel 'name' at '%s' line '%d'! Skipping...\n", chan->file, chan->line);
		return false;
	}
	if (config_setting_lookup_string(chan, "type", &type_str) && !script_get_constant(type_str, &type)) {
		ShowError("Invalid channel type %s at '%s' line '%d'! Skipping...\n", type_str, chan->file, chan->line);
		return false;
	}
	config_setting_lookup_string(chan, "password", &password);
	config_setting_lookup_string(chan, "alias", &alias);
	config_setting_lookup_string(chan, "color", &color_str);
	config_setting_lookup_int(chan, "delay", &delay);
	config_setting_lookup_bool(chan, "autojoin", &autojoin);
	config_setting_lookup_bool(chan, "leave", &leave);
	config_setting_lookup_bool(chan, "chat", &chat);
	config_setting_lookup_bool(chan, "color_override", &color_override);
	config_setting_lookup_bool(chan, "self_notif", &self_notif);
	config_setting_lookup_bool(chan, "join_notif", &join_notif);
	config_setting_lookup_bool(chan, "leave_notif", &leave_notif);

	safestrncpy(tmp_chan->name,name+1,sizeof(tmp_chan->name));
	if (password)
		safestrncpy(tmp_chan->pass,password,sizeof(tmp_chan->pass));
	else
		tmp_chan->pass[0] = '\0';
	safestrncpy(tmp_chan->alias,alias?alias:name,sizeof(tmp_chan->alias));
	tmp_chan->msg_delay = delay;
	tmp_chan->type = (enum Channel_Type)type;
	tmp_chan->color = channel_getColor(color_str);

	tmp_chan->opt = (autojoin ? CHAN_OPT_AUTOJOIN : 0) |
		(leave ? CHAN_OPT_CAN_LEAVE : 0) |
		(chat ? CHAN_OPT_CAN_CHAT : 0) |
		(color_override ? CHAN_OPT_COLOR_OVERRIDE : 0) |
		(self_notif ? CHAN_OPT_ANNOUNCE_SELF : 0) |
		(join_notif ? CHAN_OPT_ANNOUNCE_JOIN : 0) |
		(leave_notif ? CHAN_OPT_ANNOUNCE_LEAVE : 0);

	if ((group_list = config_setting_get_member(chan, "groupid")) && (group_count = config_setting_length(group_list)) > 0) {
		int j;
		CREATE(tmp_chan->groups, unsigned short, group_count);
		tmp_chan->group_count = group_count;
		for (j = 0; j < group_count; j++) {
			int groupid = config_setting_get_int_elem(group_list, j);
			tmp_chan->groups[j] = groupid;
		}
	}
开发者ID:Atemo,项目名称:rathena,代码行数:64,代码来源:channel.cpp

示例15: zconfig_load_sections

/**
 * @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;
}
开发者ID:intersvyaz,项目名称:zerod,代码行数:60,代码来源:config.c


注:本文中的config_setting_length函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。