示例#1
0
文件: config.c 项目: joshdk/muxd
int config_get_host(config_t *config,char **host){
	config_setting_t *cs_host=NULL;
	if((cs_host=config_lookup(config,"host"))==NULL){
		return 1;
	}
	if((*host=strdup(config_setting_get_string(cs_host)))==NULL){
		free(*host);
		*host=NULL;
		return 1;
	}
	return 0;
}
示例#2
0
文件: libconfig.c 项目: 274914765/C
int config_setting_lookup_string (const config_setting_t * setting, const char *name, const char **value)
{
    config_setting_t *member = config_setting_get_member (setting, name);
    if (!member)
        return (CONFIG_FALSE);

    if (config_setting_type (member) != CONFIG_TYPE_STRING)
        return (CONFIG_FALSE);

    *value = config_setting_get_string (member);
    return (CONFIG_TRUE);
}
示例#3
0
文件: vifset.c 项目: ikob/i-Path
int qtbl32_set(config_setting_t *cfsp, struct qtbl_e *qep, struct qtbl_e ifsnmpoid) {
	config_setting_t *tcfsp;
	if((tcfsp = config_setting_get_member(cfsp, "static")) != NULL){
		qep->data.val = config_setting_get_int(tcfsp);
		qep->flag = QSTATIC;
		return 1;
/* SNMP is default. if SNMP option is not found, to assume SNMP MIB */
	}else if((tcfsp = config_setting_get_member(cfsp, "snmp")) == NULL){
		tcfsp = cfsp;
	}
	if(ifsnmpoid.flag != QSNMPOID){
		printf("Not defined SNMP data\n");
		return 0;
	}
	if(strlen(config_setting_get_string(tcfsp)) == 0){
		printf("wrong OID data\n");
		return 0;
	}
	*qep = ifsnmpoid;
	strncpy(qep->data.snmp.oid, config_setting_get_string(tcfsp), MAX_OID_LEN);
	return 1;
}
示例#4
0
/*******************************************************************************
 函数名称  : webauth_rdx_get_str_setting
 功能描述  : 从配置结构中读取字符串类型的属性
 输入参数  : config_setting_t * setting  配置结构
               char* attr                  配置属性名
               size_t buf_len              缓冲区长度
 输出参数  : char *buf                   缓冲区
 返 回 值  :
--------------------------------------------------------------------------------
 最近一次修改记录 :
 修改作者   :      王群
 修改目的   :      新添加函数
 修改日期   :      2010-08-16
*******************************************************************************/
void webauth_rdx_get_str_setting (config_setting_t * setting, char *attr,
                              char *buf, size_t buf_len)
{
    config_setting_t *s;

    s = config_setting_get_member (setting, attr);
    if (NULL != s)
    {
        strncpy (buf, config_setting_get_string (s), buf_len);
    }

    return;
}
示例#5
0
文件: libconfig.c 项目: 274914765/C
int config_lookup_string (const config_t * config, const char *path, const char **value)
{
    const config_setting_t *s = config_lookup (config, path);
    if (!s)
        return (CONFIG_FALSE);

    if (config_setting_type (s) != CONFIG_TYPE_STRING)
        return (CONFIG_FALSE);

    *value = config_setting_get_string (s);

    return (CONFIG_TRUE);
}
示例#6
0
int get_server_config(s_config *c, char *config_path)
{
	config_t cfg;
	config_setting_t *modules_setting, *module_setting;
	unsigned int count, i;
	const char *module_name;

	config_init(&cfg);

	if (!config_read_file(&cfg, config_path)) {
		config_destroy(&cfg);
		return CONFIG_FILE_READ_ERROR;
	}

	if (config_lookup_int(&cfg, "port", &(c->port))
		&& config_lookup_string(&cfg, "host", &(c->host))
		&& config_lookup_string(&cfg, "web_root", &(c->web_root))
		&& config_lookup_string(&cfg, "web_prefix", &(c->web_prefix))
		&& config_lookup_string(&cfg, "api_prefix", &(c->api_prefix))
		&& config_lookup_string(&cfg, "index_file", &(c->index_file))
		&& config_lookup_string(&cfg, "api_modules_path", &(c->api_modules_path))
		&& config_lookup_int(&cfg, "buffer_size", &(c->buffer_size))
		&& config_lookup_int(&cfg, "api_modules_number", &(c->api_modules_number))
	) {
		c->buffer = (char*) calloc((size_t) c->buffer_size, sizeof(char));

		/* Output a list of all movies in the inventory. */
		modules_setting = config_lookup(&cfg, "api_modules");
		if (modules_setting != NULL) {
			count = (unsigned int) config_setting_length(modules_setting);
			if (count != (unsigned int) c->api_modules_number)
				return CONFIG_INCONSISTENT_DATA;
			else if (count == 0)
				return CONFIG_FILE_READ_OK;

			c->api_modules_names = malloc(count * sizeof(char*));
			for (i = 0; i < count; ++i) {
				module_setting = config_setting_get_elem(modules_setting, i);
				module_name = config_setting_get_string(module_setting);

				c->api_modules_names[i] = module_name;
			}

			map_init(&c->api_modules, c->api_modules_number);
		}

		return CONFIG_FILE_READ_OK;
	}
	else
		return CONFIG_MISSING_KEY;
}
示例#7
0
文件: config.c 项目: joshdk/muxd
int config_get_port(config_t *config,char **port){
	config_setting_t *cs_port=NULL;
	if((cs_port=config_lookup(config,"port"))==NULL){
		return 1;
	}
	switch(config_setting_type(cs_port)){
		case CONFIG_TYPE_INT:
			*port=calloc(16,sizeof(*port));
			sprintf(*port,"%lu",config_setting_get_int(cs_port));
			return 0;
		case CONFIG_TYPE_STRING:
			*port=strdup(config_setting_get_string(cs_port));
			return 0;
	}
	return 1;
}
示例#8
0
static int checkValues(struct JsonNode *jvalues) {
	double readonly = 0.0;
	char *platform = GPIO_PLATFORM;

	if(config_setting_get_string("gpio-platform", 0, &platform) != 0) {
		logprintf(LOG_ERR, "no gpio-platform configured");
		return -1;
	}
	if(strcmp(platform, "none") == 0) {
		FREE(platform);
		logprintf(LOG_ERR, "no gpio-platform configured");
		return -1;
	}
	if(wiringXSetup(platform, logprintf1) < 0) {
		FREE(platform);
		return -1;
	}
	FREE(platform);

	struct JsonNode *jid = NULL;
	if((jid = json_find_member(jvalues, "id"))) {
		struct JsonNode *jchild = NULL;
		struct JsonNode *jchild1 = NULL;

		jchild = json_first_child(jid);
		while(jchild) {
			jchild1 = json_first_child(jchild);
			while(jchild1) {
				if(strcmp(jchild1->key, "gpio") == 0) {
					if(wiringXValidGPIO((int)round(jchild1->number_)) != 0) {
						return -1;
					}
				}
				jchild1 = jchild1->next;
			}
			jchild = jchild->next;
		}
	}

	if(json_find_number(jvalues, "readonly", &readonly) == 0) {
		if((int)readonly != 1) {
			return -1;
		}
	}

	return 0;
}
示例#9
0
static int parse_rpms(struct config_t *config, struct manifest *manifest)
{
	config_setting_t *rpms = config_lookup(config, "manifest");
	config_setting_t *rpm_config;
	/*__free_rpms*/ struct rpm *rpmp = NULL;
	struct rpm *last = manifest->rpms;
	int i = 0;
	const char *name;

	if (!rpms)
		return 0;

	//printf("*-* *-*\n");
	/*
 	 * Load up all the individual repository urls
 	 */
	while ((rpm_config = config_setting_get_elem(rpms, i)) != NULL) {

		name = config_setting_get_string(rpm_config);
		if (!name)
			return -EINVAL;

		rpmp = calloc(1, sizeof(struct rpm));
		if (!rpmp)
			return -ENOMEM;

		rpmp->name = strdup(name);
		if (!rpmp->name)
			return -ENOMEM;

		//printf(" ** %s [%p %p %p]\n", rpmp->name, rpmp, last, rpmp->name);

		rpmp->next = NULL;
		if (last)
			last->next = rpmp;
		else
			manifest->rpms = rpmp;
		last = rpmp;
		
		i++;
	}

	//printf("*=* *=*\n");
	rpmp = NULL;

	return 0;
}
示例#10
0
void sub_shc_popexec(int value)
{
	shc_node *item = shc_root;
    config_setting_t *root = config_lookup(&CONFIG, "shortcuts");
    char bname[1024];
    int i = 0;
    memset(bname, 0, sizeof(bname));

	for (i = 0; item != NULL && i < shc_selection; item = item->next, i++);

    if (!item || !root)
        return;

    switch (value)
    {
    case 0:
        {
            for (i = config_setting_length(root); i--;)
            {
                config_setting_t *elem = config_setting_get_elem(root, i);
                config_setting_t *member =
                    config_setting_get_member(elem, "path");

                if (member)
                {
                    if (!strcmp(config_setting_get_string(member),item->path))
                    {
                        sub_game_remove_shortcut(root, i);
                        msgbox(SDL_GetVideoSurface(),NULL, "My Shortcuts",
                               "Shortcut has been deleted.", OK);
                        cfg_save();
                        msgbox_retval();
                        return;
                    }
                }
            }
            msgbox(SDL_GetVideoSurface(),NULL,"System Error","Unable to delete Shortcut.",
                   OK);
            msgbox_retval();
        }
        break;

    default:
        break;
    }
}
示例#11
0
文件: avrgpio.c 项目: pilight/pilight
void gpio_initpgm(PROGRAMMER *pgm)
{
#if defined(__arm__) || defined(__mips__)
  strcpy(pgm->type, "GPIO");
	char *platform = GPIO_PLATFORM;

	if(config_setting_get_string("gpio-platform", 0, &platform) != 0) {
		logprintf(LOG_ERR, "no gpio-platform configured");
		exit(EXIT_FAILURE);
	}
	if(strcmp(platform, "none") == 0) {
		FREE(platform);
		logprintf(LOG_ERR, "no gpio-platform configured");
		exit(EXIT_FAILURE);
	}
	if(wiringXSetup(platform, logprintf1) < 0) {
		FREE(platform);
		exit(EXIT_FAILURE);
	}
	FREE(platform);

  pgm->rdy_led        = bitbang_rdy_led;
  pgm->err_led        = bitbang_err_led;
  pgm->pgm_led        = bitbang_pgm_led;
  pgm->vfy_led        = bitbang_vfy_led;
  pgm->initialize     = bitbang_initialize;
  pgm->display        = gpio_display;
  pgm->enable         = gpio_enable;
  pgm->disable        = gpio_disable;
  pgm->powerup        = gpio_powerup;
  pgm->powerdown      = gpio_powerdown;
  pgm->program_enable = bitbang_program_enable;
  pgm->chip_erase     = bitbang_chip_erase;
  pgm->cmd            = bitbang_cmd;
  pgm->open           = gpio_open;
  pgm->close          = gpio_close;
  pgm->setpin         = gpio_setpin;
  pgm->getpin         = gpio_getpin;
  pgm->highpulsepin   = gpio_highpulsepin;
  pgm->read_byte      = avr_read_byte_default;
  pgm->write_byte     = avr_write_byte_default;
#else
	logprintf(LOG_WARNING, "gpio firmware flashing is not supported on this hardware");
	exit(EXIT_FAILURE);
#endif
}
示例#12
0
int jalu_config_lookup_string(const config_setting_t *setting,
	const char *name, char **field, int required) {
	if (!setting || !name || !field || *field) {
		//library error, should never happen
		fprintf(stderr, "Error: misuse of jalls_config_lookup_string\n");
		goto err_out;
	}
	config_setting_t *member = config_setting_get_member(setting, name);
	if (!member && required) {
		fprintf(stderr, "Config Error: line %d: missing required field \"%s\"\n",
			config_setting_source_line(setting), name);
		goto err_out;
	}
	if (!member) {
		goto out;
	}
	if(config_setting_type(member) != CONFIG_TYPE_STRING) {
		fprintf(stderr, "Config Error: line %d: field \"%s\" should be a string\n",
			config_setting_source_line(member), name);
		goto err_out;
	}
	const char *tmp = config_setting_get_string(member);
	if (!tmp && required) {
		fprintf(stderr, "Config Error: line %d: empty required field \"%s\"\n",
			config_setting_source_line(setting), name);
		goto err_out;
	}
	if (!tmp) {
		fprintf(stderr, "Config Warning: line %d: empty value for field \"%s\"\n",
			config_setting_source_line(setting), name);
		goto out;
	}
	*field = strdup(tmp);
	if (*field == NULL) {
		fprintf(stderr, "strdup failed: insufficient memory");
		goto err_out;
	}
out:
	return 0;

err_out:

	return -1;
}
示例#13
0
static int parse_container_opts(config_t *config, struct manifest *manifest)
{
	config_setting_t *copts = config_lookup(config, "container_opts");
	config_setting_t *tmp;

	if (!copts)
		return -ENOENT;

	tmp = config_setting_get_member(copts, "user");

	if (tmp) {
		manifest->copts.user = strdup(
			config_setting_get_string(tmp));
		if (!manifest->copts.user)
			return -ENOMEM;
	}

	return 0;	
}
示例#14
0
VOID * GetOverrides(config_setting_t * group, char * ValueName)
{
	char * ptr1;
	char * MultiString = NULL;
	char * ptr;
	int Count = 0;
	struct Override ** Value;
	char * Val;

	config_setting_t *setting;

	Value = zalloc(4);				// always NULL entry on end even if no values
	Value[0] = NULL;

	setting = config_setting_get_member (group, ValueName);
	
	if (setting)
	{
		ptr =  (char *)config_setting_get_string (setting);
	
		while (ptr && strlen(ptr))
		{
			ptr1 = strchr(ptr, '|');
			
			if (ptr1)
				*(ptr1++) = 0;

			Value = realloc(Value, (Count+2)*4);
			Value[Count] = zalloc(sizeof(struct Override));
			Val = strlop(ptr, ',');
			if (Val == NULL)
				break;

			Value[Count]->Call = _strupr(_strdup(ptr));
			Value[Count++]->Days = atoi(Val);
			ptr = ptr1;
		}
	}

	Value[Count] = NULL;
	return Value;
}
示例#15
0
int read_this_node_local_config(config_t * config)
{
	const char * local_node_name;

	config_setting_t * local_node_setting = config_lookup(config, "local_node");
	if (local_node_setting == NULL)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Local node section is missing, please add it to local config.\n");
		return CONFIG_FALSE;
	}

	config_setting_t * setting_node_id = config_setting_get_member(local_node_setting, "id");
	config_setting_t * setting_node_name = config_setting_get_member(local_node_setting, "name");
	
	if (setting_node_id == NULL || setting_node_name == NULL)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local node section node name or node id are missing, please add them to local config.\n");
		return CONFIG_FALSE;
	}

	if (config_setting_type(setting_node_id) != CONFIG_TYPE_INT)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local node section key id has wrong type, it should be int.\n");
		return CONFIG_FALSE;
	}

	if (config_setting_type(setting_node_name) != CONFIG_TYPE_STRING)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "In local node section key name has wrong type, it should be string.\n");
		return CONFIG_FALSE;
	}

	zfs_config.this_node.node_id = config_setting_get_int(setting_node_id);
	local_node_name = config_setting_get_string(setting_node_name);

	xmkstring(&(zfs_config.this_node.node_name), local_node_name);

	/*read port configuration*/
	zfs_config.this_node.host_port = read_tcp_port_setting(local_node_setting);

	return CONFIG_TRUE;
}
示例#16
0
static void get_value_libconfig(const config_setting_t *e, void *dest)
{
	int type = config_setting_type(e);
	switch (type) {
	case CONFIG_TYPE_INT:
		*(int *)dest = config_setting_get_int(e);
	case CONFIG_TYPE_INT64:
		*(long long *)dest = config_setting_get_int64(e);
		break;
	case CONFIG_TYPE_STRING:
		dest = (void *)config_setting_get_string(e);
		break;
	case CONFIG_TYPE_BOOL:
		*(int *)dest = config_setting_get_bool(e);
		break;
	case CONFIG_TYPE_FLOAT:
		*(double *)dest = config_setting_get_float(e);
		/* Do nothing, add if needed */
	}
}
示例#17
0
void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *src)
{
	config_setting_t *set = NULL;

	if (config_setting_is_aggregate(src))
		config_setting_copy_aggregate(parent, src);
	else if (CONFIG_TYPE_INT == config_setting_type(src)) {
		set = config_setting_set_int_elem(parent, -1, config_setting_get_int(src));
		config_setting_set_format(set, src->format);
	} else if (CONFIG_TYPE_INT64 == config_setting_type(src)) {
		set = config_setting_set_int64_elem(parent, -1, config_setting_get_int64(src));
		config_setting_set_format(set, src->format);   
	} else if (CONFIG_TYPE_FLOAT == config_setting_type(src)) {
		config_setting_set_float_elem(parent, -1, config_setting_get_float(src));
	} else if (CONFIG_TYPE_STRING == config_setting_type(src)) {
		config_setting_set_string_elem(parent, -1, config_setting_get_string(src));
	} else if (CONFIG_TYPE_BOOL == config_setting_type(src)) {
		config_setting_set_bool_elem(parent, -1, config_setting_get_bool(src));
	}
}
示例#18
0
void event_operator_init(void) {
	if(init == 1) {
		return;
	}
	init = 1;
	plua_init();

	char path[PATH_MAX];
	char *f = STRDUP(__FILE__);
	struct dirent *file = NULL;
	DIR *d = NULL;
	struct stat s;
	char *operator_root = OPERATOR_ROOT;

	if(f == NULL) {
		OUT_OF_MEMORY
	}

	config_setting_get_string("operators-root", 0, &operator_root);

	if((d = opendir(operator_root))) {
		while((file = readdir(d)) != NULL) {
			memset(path, '\0', PATH_MAX);
			sprintf(path, "%s%s", operator_root, file->d_name);
			if(stat(path, &s) == 0) {
				/* Check if file */
				if(S_ISREG(s.st_mode)) {
					if(strstr(file->d_name, ".lua") != NULL) {
						plua_module_load(path, OPERATOR);
					}
				}
			}
		}
	}
	closedir(d);
	FREE(f);

	if(operator_root != (void *)OPERATOR_ROOT) {
		FREE(operator_root);
	}
}
示例#19
0
文件: config.c 项目: intersvyaz/zerod
/**
 * Load string value from config.
 * @param[in] section Config section.
 * @param[in] option Option name.
 * @param[out] pvalue Value pointer.
 * @return <0 - error. 0 - success. >0 - not found.
 */
static int zcfg_load_string(const config_setting_t *option, char **pvalue)
{
    *pvalue = NULL;

    if (!option) {
        return 1;
    }

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

    const char *str_val = config_setting_get_string(option);
    if (NULL == str_val) {
        return -1;
    }

    *pvalue = strdup(str_val);

    return 0;
}
示例#20
0
static void get_field_string_libconfig(config_setting_t *e, const char *path, void *dest, size_t n)
{
	config_setting_t *elem;
	const char *str;

	if (path)
		elem = config_setting_lookup(e, path);
	else
		elem = e;

	if (!elem || config_setting_type(elem) != CONFIG_TYPE_STRING)
		return;

	if (path) {
		if (config_setting_lookup_string(e, path, &str))
			strncpy(dest, str, n);
	} else {
		if ((str = config_setting_get_string(e)) != NULL)
			strncpy(dest, str, n);
	}
}
示例#21
0
文件: mconfig.c 项目: MLDroid/malheur
/**
 * Print a configuration setting. 
 * @param f File stream to print to
 * @param cs Configuration setting
 * @param d Current depth.
 */
static void config_setting_fprint(FILE *f, config_setting_t * cs, int d)
{
    assert(cs && d >= 0);

    int i;
    for (i = 0; i < d; i++)
        fprintf(f, "  ");

    char *n = config_setting_name(cs);

    switch (config_setting_type(cs)) {
    case CONFIG_TYPE_GROUP:
        if (d > 0)
            fprintf(f, "%s = {\n", n);

        for (i = 0; i < config_setting_length(cs); i++)
            config_setting_fprint(f, config_setting_get_elem(cs, i), d + 1);

        if (d > 0) {
            for (i = 0; i < d; i++)
                fprintf(f, "  ");
            fprintf(f, "};\n");
        }
        break;
    case CONFIG_TYPE_STRING:
        fprintf(f, "%s\t= \"%s\";\n", n, config_setting_get_string(cs));
        break;
    case CONFIG_TYPE_FLOAT:
        fprintf(f, "%s\t= %7.5f;\n", n, config_setting_get_float(cs));
        break;
    case CONFIG_TYPE_INT:
        fprintf(f, "%s\t= %d;\n", n, config_setting_get_int(cs));
        break;
    default:
        error("Unsupported type for configuration setting '%s'", n);
    }
}
示例#22
0
// {{{ session_get_user()
int session_get_user(const char *sessid, char *user, size_t len)
{
   struct config_t cfg;
   config_init(&cfg);
   config_setting_t *cs;
   config_setting_t *vs;

   if(!config_read_file(&cfg, OD_SESSION_FILE))
      return -1;

   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;

      char *session_user = config_setting_name(cs);
      if(!session_user)
         continue;

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

   }

   config_destroy(&cfg);
   return -1;
}
示例#23
0
static int parse_yum_opts(struct config_t *config, struct manifest *manifest)
{
	if (!config || !manifest)
		return -EINVAL;

	config_setting_t *yum_opts = config_lookup(config, "yum_opts");
	config_setting_t *releasever;

	/*
 	 * yum opts aren't required
 	 */
	if (!yum_opts)
		return 0;

	releasever = config_setting_get_member(yum_opts, "releasever");
	if (releasever) {
		manifest->yum.releasever = strdup(
				config_setting_get_string(releasever));
		if (!manifest->yum.releasever) 
			return -ENOMEM;		
	}

	return 0;
}
示例#24
0
文件: lang.c 项目: Mateuus/brathena-1
// ----------------------------------------------------------------------------------------
// Sistema Multilinguagem
// ----------------------------------------------------------------------------------------
// read_message("Grupo.SubGrupo.String");
// ----------------------------------------------------------------------------------------
// http://www.hyperrealm.com/libconfig/libconfig_manual.html
// ----------------------------------------------------------------------------------------
char *read_message(const char *param)
{
	static char message[512];
	config_setting_t *str;
	config_t configLang;

	config_init(&configLang);

	if(!config_read_file(&configLang, (!strlen(bra_config.lang_file)?"conf/lang/pt_br.conf":bra_config.lang_file))) {
		ShowError("read_message erro: %s:%d - %s\n", config_error_file(&configLang), config_error_line(&configLang), config_error_text(&configLang));
		config_destroy(&configLang);
		return "";
	}

	if(!(str = config_lookup(&configLang, param))) {
		ShowError("read_message erro: %s\n", param);
		config_destroy(&configLang);
		return "";
	}
	
	strncpy(message, config_setting_get_string(str), sizeof(message));
	config_destroy(&configLang);
	return message;
}
示例#25
0
文件: ftm_debug.c 项目: xtra72/lora
FTM_RET	FTM_DEBUG_configLoad(FTM_DEBUG_CFG_PTR pCfg, FTM_UINT8_PTR pFileName)
{
	config_t		xLibConfig;
	config_setting_t	*pSection;
	config_setting_t	*pSubSection;
	config_setting_t	*pField;

	config_init(&xLibConfig);

	if (config_read_file(&xLibConfig, pFileName) == CONFIG_FALSE)
	{
		return	FTM_RET_INVALID_ARGUMENTS;	
	}

	pSection = config_lookup(&xLibConfig, "DEBUG");
	if (pSection != NULL)
	{
		pField = config_setting_get_member(pSection, "mode");
		if (pField != NULL)
		{
			pCfg->ulMode = (FTM_UINT32)config_setting_get_int(pField);
		}

		pSubSection = config_setting_get_member(pSection, "trace");
		if (pSubSection != NULL)
		{
			pField = config_setting_get_member(pSubSection, "path");
			if (pField != NULL)
			{
				strncpy(pCfg->xTrace.pPath, 
						config_setting_get_string(pField),
						sizeof(pCfg->xTrace.pPath) - 1);
			}
	
			pField = config_setting_get_member(pSubSection, "prefix");
			if (pField != NULL)
			{
				strncpy(pCfg->xTrace.pPrefix, 
						config_setting_get_string(pField),
						sizeof(pCfg->xTrace.pPath) - 1);
			}
	
			pField = config_setting_get_member(pSubSection, "to_file");
			if (pField != NULL)
			{
				pCfg->xTrace.bToFile = (FTM_BOOL)config_setting_get_int(pField);
			}
	
			pField = config_setting_get_member(pSubSection, "print_line");
			if (pField != NULL)
			{
				pCfg->xTrace.bLine = (FTM_BOOL)config_setting_get_int(pField);
			}
		}

		pSubSection = config_setting_get_member(pSection, "error");
		if (pSubSection != NULL)
		{
			pField = config_setting_get_member(pSubSection, "path");
			if (pField != NULL)
			{
				strncpy(pCfg->xError.pPath, 
						config_setting_get_string(pField),
						sizeof(pCfg->xError.pPath) - 1);
			}
	
			pField = config_setting_get_member(pSubSection, "prefix");
			if (pField != NULL)
			{
				strncpy(pCfg->xError.pPrefix, 
						config_setting_get_string(pField),
						sizeof(pCfg->xError.pPath) - 1);
			}
	
			pField = config_setting_get_member(pSubSection, "to_file");
			if (pField != NULL)
			{
				pCfg->xError.bToFile = (FTM_BOOL)config_setting_get_int(pField);
			}
	
			pField = config_setting_get_member(pSubSection, "print_line");
			if (pField != NULL)
			{
				pCfg->xError.bLine = (FTM_BOOL)config_setting_get_int(pField);
			}
		}

	}

	config_destroy(&xLibConfig);

	return	FTM_RET_OK;
}
示例#26
0
/*********************
return RET_NOK on error
*********************/
ret_code_t entry_copy_config(config_setting_t * source, config_setting_t * dest)
{
	config_setting_t * new_source;
	config_setting_t * new_dest;
	int index = -1;
	int int_value;
	long long long_value;
	double double_value;
	const char * string;

	while((new_source=config_setting_get_elem(source,index+1))!= NULL ) {
		index++;
		if(config_setting_is_group(new_source)) {
			if(!entry_copy_aggregate(new_source,dest,CONFIG_TYPE_GROUP)) {
				return RET_NOK;
			}
		}

		else if(config_setting_is_array(new_source)) {
			if(!entry_copy_aggregate(new_source,dest,CONFIG_TYPE_ARRAY)) {
				return RET_NOK;
			}
		}

		else if(config_setting_is_list(new_source)) {
			if(!entry_copy_aggregate(new_source,dest,CONFIG_TYPE_LIST)) {
				return RET_NOK;
			}
		}

		else {
			switch(config_setting_type(new_source)) {
			case CONFIG_TYPE_INT:
				int_value = config_setting_get_int(new_source);
				new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_INT);
				config_setting_set_int(new_dest,int_value);
				continue;
			case CONFIG_TYPE_INT64:
				long_value = config_setting_get_int64(new_source);
				new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_INT64);
				config_setting_set_int64(new_dest,long_value);
				continue;
			case CONFIG_TYPE_FLOAT:
				double_value = config_setting_get_float(new_source);
				new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_FLOAT);
				config_setting_set_float(new_dest,double_value);
				continue;
			case CONFIG_TYPE_BOOL:
				int_value = config_setting_get_bool(new_source);
				new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_BOOL);
				config_setting_set_bool(new_dest,int_value);
				continue;
			case CONFIG_TYPE_STRING:
				string = config_setting_get_string(new_source);
				new_dest = config_setting_add (dest, config_setting_name(new_source),CONFIG_TYPE_STRING);
				config_setting_set_string(new_dest,string);
				continue;
			default:
				return RET_NOK;
			}
		}
	}

	return RET_OK;
}
示例#27
0
static int parse_packaging(struct config_t *config, struct manifest *manifest)
{
	config_setting_t *pkg = config_lookup(config, "packaging");
	config_setting_t *tmp;
	int rc = -EINVAL;

	if (!pkg) {
		LOG(ERROR, "You must supply a packaging directive\n");
		goto out;
	}

	rc = -ENOMEM;
	tmp = config_setting_get_member(pkg, "name");
	if (!tmp) {
		LOG(ERROR, "You must specify a package name\n");
		goto out;
	}
	manifest->package.name = strdup(config_setting_get_string(tmp));
	if (!manifest->package.name)
		goto out;

	tmp = config_setting_get_member(pkg, "version");
	if (!tmp) {
		LOG(ERROR, "You must specify a package version\n");
		goto out_free;
	}
	manifest->package.version = strdup(config_setting_get_string(tmp));
	if (!manifest->package.version)
		goto out_free;

	tmp = config_setting_get_member(pkg, "release");
	if (!tmp) {
		LOG(ERROR, "You must specify a package release\n");
		goto out_free;
	}
	manifest->package.release = strdup(config_setting_get_string(tmp));
	if (!manifest->package.release)
		goto out_free;

	tmp = config_setting_get_member(pkg, "summary");
	if (!tmp) {
		LOG(ERROR, "You must specify a package summary\n");
		goto out_free;
	}
	manifest->package.summary = strdup(config_setting_get_string(tmp));
	if (!manifest->package.summary)
		goto out_free;

	tmp = config_setting_get_member(pkg, "license");
	if (!tmp) {
		LOG(ERROR, "You must specify a package license\n");
		goto out_free;
	}
	manifest->package.license = strdup(config_setting_get_string(tmp));
	if (!manifest->package.license)
		goto out_free;

	tmp = config_setting_get_member(pkg, "author");
	if (!tmp) {
		LOG(ERROR, "You must specify a package author\n");
		goto out_free;
	}
	manifest->package.author = strdup(config_setting_get_string(tmp));
	if (!manifest->package.author)
		goto out_free;
	
	tmp = config_setting_get_member(pkg, "post_script");
	if (tmp) {
		manifest->package.post_script = 
			strdup(config_setting_get_string(tmp));
		if (!manifest->package.post_script)
			goto out_free;
	}

	tmp = config_setting_get_member(pkg, "parent_container");
	if (tmp)
		manifest->package.parent_container = 
			strdup(config_setting_get_string(tmp));
	rc = 0;
	goto out;

out_free:
	free(manifest->package.license);
	free(manifest->package.summary);
	free(manifest->package.release);
	free(manifest->package.version);
	free(manifest->package.author);
	free(manifest->package.name);
	free(manifest->package.post_script);
	free(manifest->package.parent_container);
out:
	return rc;
}
示例#28
0
文件: emulator.c 项目: rpedde/6502
int load_memory(void) {
    config_setting_t *pmemory;
    config_setting_t *pblock;
    config_setting_t *args;
    config_setting_t *arg;

    int memory_items = 0;
    int arg_items = 0;
    char *name;
    const char *module;

    hw_config_t *hw_config = NULL;

    INFO("Loading memory");
    pmemory = config_lookup(&main_config, "memory");
    if(!pmemory) {
        INFO("No memory blocks to laod");
        return TRUE;
    }

    while(1) {
        pblock = config_setting_get_elem(pmemory, memory_items);
        memory_items++;
        if(!pblock)
            break;

        name = config_setting_name(pblock);

        INFO("Found memory element: %s", name);

        if(!config_setting_lookup_string(pblock, "module", &module)) {
            FATAL("Missing module entry for memory item %s", name);
            exit(1);
        }

        INFO("  Module name: %s", module);
        args = config_setting_get_member(pblock, "args");

        if (!args) {
            hw_config = malloc(sizeof(hw_config_t));
            if (!hw_config) {
                FATAL("malloc");
                exit(1);
            }

            arg_items = 0;
        } else {
            arg_items = config_setting_length(args);
            INFO("  %d arg items", arg_items);
            hw_config = malloc(sizeof(hw_config_t) +
                               (arg_items * sizeof(hw_config_item_t)));
            if(!hw_config) {
                FATAL("malloc");
                exit(1);
            }
        }

        /* now walk the args and put them in a
           config struct */
        hw_config->config_items = arg_items;
        for(int x = 0; x < arg_items; x++) {
            arg = config_setting_get_elem(args, x);
            const char *key = config_setting_name(arg);
            if(!key) {
                FATAL("Bad arg key in %s", name);
                exit(1);
            }
            const char *value = NULL;
            value = config_setting_get_string(arg);

            if(!value) {
                FATAL("Bad arg value for %s in %s",
                      key, name);
                exit(1);
            }

            hw_config->item[x].key = key;
            hw_config->item[x].value = value;

            INFO("    %s => %s", key, value);
        }

        /* now, let's load it */
        memory_load(name, module, hw_config);

        if (hw_config) {
            free(hw_config);
            hw_config = NULL;
        }
    }

    INFO("Memory loaded");
    return TRUE;
}
示例#29
0
文件: conf.c 项目: Hello71/umurmur
const char *getStrConf(param_t param)
{
	config_setting_t *setting = NULL;
	const char *strsetting = NULL;

	switch (param) {
		case CERTIFICATE:
			setting = config_lookup(&configuration, "certificate");
			if (!setting)
				return "/etc/umurmur/certificate.crt";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "/etc/umurmur/certificate.crt";
			}
			break;
		case KEY:
			setting = config_lookup(&configuration, "private_key");
			if (!setting)
				return "/etc/umurmur/private_key.key";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "/etc/umurmur/private_key.key";
			}
			break;
		case CAPATH:
			setting = config_lookup(&configuration, "ca_path");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case PASSPHRASE:
			setting = config_lookup(&configuration, "password");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case ADMIN_PASSPHRASE:
			setting = config_lookup(&configuration, "admin_password");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case BINDADDR:
			setting = config_lookup(&configuration, "bindaddr");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case BINDADDR6:
			setting = config_lookup(&configuration, "bindaddr6");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case WELCOMETEXT:
			setting = config_lookup(&configuration, "welcometext");
			if (!setting)
				return DEFAULT_WELCOME;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return DEFAULT_WELCOME;
			}
			break;
		case DEFAULT_CHANNEL:
			setting = config_lookup(&configuration, "default_channel");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case USERNAME:
			setting = config_lookup(&configuration, "username");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case GROUPNAME:
			setting = config_lookup(&configuration, "groupname");
			if (!setting)
				return "";
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return "";
			}
			break;
		case LOGFILE:
			setting = config_lookup(&configuration, "logfile");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		case BANFILE:
			setting = config_lookup(&configuration, "banfile");
			if (!setting)
				return NULL;
			else {
				if ((strsetting = config_setting_get_string(setting)) != NULL)
					return strsetting;
				else
					return NULL;
			}
			break;
		default:
			doAssert(false);
			break;
	}
	return NULL;
}
示例#30
0
static void dx_reload_cfg()
{
	int i, j;
	const char *s;

	config_setting_t *dxs = dxcfg_lookup("dx", CFG_REQUIRED);
	assert(config_setting_type(dxs) == CONFIG_TYPE_LIST);
	
	const config_setting_t *dxe;
	for (i=0; (dxe = config_setting_get_elem(dxs, i)) != NULL; i++) {
		assert(config_setting_type(dxe) == CONFIG_TYPE_GROUP);
	}
	int _dx_list_len = i-1;
	lprintf("%d dx entries\n", _dx_list_len);
	
	dx_t *_dx_list = (dx_t *) kiwi_malloc("dx_list", (_dx_list_len+1) * sizeof(dx_t));
	
	float f = 0;
	
	dx_t *dxp;
	for (i=0, dxp = _dx_list; i < _dx_list_len; i++, dxp++) {
		dxe = config_setting_get_elem(dxs, i);
		
		config_setting_t *e;
		assert((e = config_setting_get_member(dxe, "e")) != NULL);
		assert(config_setting_type(e) == CONFIG_TYPE_LIST);
		
		assert((dxp->freq = (float) config_setting_get_float_elem(e, 0)) != 0);
		if (dxp->freq < f)
			lprintf(">>>> DX: entry with freq %.2f < current freq %.2f\n", dxp->freq, f);
		else
			f = dxp->freq;

		assert((s = config_setting_get_string_elem(e, 1)) != NULL);
		dxcfg_mode(dxp, s);
		
		assert((s = config_setting_get_string_elem(e, 2)) != NULL);
		dxp->ident = str_encode((char *) s);
		
		if ((s = config_setting_get_string_elem(e, 3)) == NULL) {
			dxp->notes = NULL;
		} else {
			dxp->notes = str_encode((char *) s);
		}

		config_setting_t *flags;
		const char *flag;
		if ((flags = config_setting_get_member(dxe, "f")) != NULL) {
			if (config_setting_type(flags) == CONFIG_TYPE_ARRAY) {
				for (j=0; j < config_setting_length(flags); j++) {
					assert((flag = config_setting_get_string_elem(flags, j)) != NULL);
					dxcfg_flag(dxp, flag);
				}
			} else {
				assert((flag = config_setting_get_string(flags)) != NULL);
				dxcfg_flag(dxp, flag);
			}
		}

		config_setting_t *offset;
		if ((offset = config_setting_get_member(dxe, "o")) != NULL) {
			if (config_setting_type(offset) == CONFIG_TYPE_ARRAY) {
				assert((dxp->low_cut = (float) config_setting_get_int_elem(offset, 0)) != 0);
				assert((dxp->high_cut = (float) config_setting_get_int_elem(offset, 1)) != 0);
			} else {
				assert((dxp->offset = (float) config_setting_get_int(offset)) != 0);
			}
		}

		//printf("dxe %d f %.2f notes-%c off %.0f,%.0f\n", i, dxp->freq, dxp->notes? 'Y':'N', dxp->offset, dxp->high_cut);
	}
	
	switch_dx_list(_dx_list, _dx_list_len);

	// convert to json
	printf("### converting dx list to json\n");
	dx_save_as_json();
}