Пример #1
0
int main(int argc, char **argv)
{
  static const char *output_file = "updated.cfg";
  config_t cfg;
  config_setting_t *root, *setting, *movie;

  config_init(&cfg);

  /* Read the file. If there is an error, report it and exit. */
  if(! config_read_file(&cfg, "example.cfg"))
  {
    fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
            config_error_line(&cfg), config_error_text(&cfg));
    config_destroy(&cfg);
    return(EXIT_FAILURE);
  }

  /* Find the 'movies' setting. Add intermediate settings if they don't yet
  * exist.
  */
  root = config_root_setting(&cfg);

  setting = config_setting_get_member(root, "inventory");
  if(!setting)
    setting = config_setting_add(root, "inventory", CONFIG_TYPE_GROUP);

  setting = config_setting_get_member(setting, "movies");
  if(!setting)
    setting = config_setting_add(setting, "movies", CONFIG_TYPE_LIST);

  /* Create the new movie entry. */
  movie = config_setting_add(setting, NULL, CONFIG_TYPE_GROUP);

  setting = config_setting_add(movie, "title", CONFIG_TYPE_STRING);
  config_setting_set_string(setting, "Buckaroo Banzai");

  setting = config_setting_add(movie, "media", CONFIG_TYPE_STRING);
  config_setting_set_string(setting, "DVD");

  setting = config_setting_add(movie, "price", CONFIG_TYPE_FLOAT);
  config_setting_set_float(setting, 12.99);

  setting = config_setting_add(movie, "qty", CONFIG_TYPE_INT);
  config_setting_set_float(setting, 20);

  /* Write out the updated configuration. */
  if(! config_write_file(&cfg, output_file))
  {
    fprintf(stderr, "Error while writing file.\n");
    config_destroy(&cfg);
    return(EXIT_FAILURE);
  }

  fprintf(stderr, "Updated configuration successfully written to: %s\n",
          output_file);

  config_destroy(&cfg);
  return(EXIT_SUCCESS);
}
Пример #2
0
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int general_settings_save_configuration (config_setting_t *setting) 
{
		config_setting_t *s = NULL ;
		
		s = config_setting_add(setting, "path_1_wire_directory", CONFIG_TYPE_STRING) ;
		if (s != NULL) config_setting_set_string(s, path_1_wire_directory->str);
		s = config_setting_add(setting, "path_data_directory", CONFIG_TYPE_STRING) ;
		if (s != NULL) config_setting_set_string(s, path_data_directory->str);
		s = config_setting_add(setting, "write_samples_interval", CONFIG_TYPE_INT) ;
		if (s != NULL) config_setting_set_int(s, write_samples_interval);
		
		return 0 ;
} ;
Пример #3
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);
}
Пример #4
0
void config_setting_copy_simple(config_setting_t *parent, const config_setting_t *src)
{
	if (config_setting_is_aggregate(src)) {
		config_setting_copy_aggregate(parent, src);
	}
	else {
		config_setting_t *set;
		
		if( config_setting_get_member(parent, config_setting_name(src)) != NULL )
			return;
		
		if ((set = config_setting_add(parent, config_setting_name(src), config_setting_type(src))) == NULL)
			return;

		if (CONFIG_TYPE_INT == config_setting_type(src)) {
			config_setting_set_int(set, config_setting_get_int(src));
			config_setting_set_format(set, src->format);
		} else if (CONFIG_TYPE_INT64 == config_setting_type(src)) {
			config_setting_set_int64(set, 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(set, config_setting_get_float(src));
		} else if (CONFIG_TYPE_STRING == config_setting_type(src)) {
			config_setting_set_string(set, config_setting_get_string(src));
		} else if (CONFIG_TYPE_BOOL == config_setting_type(src)) {
			config_setting_set_bool(set, config_setting_get_bool(src));
		}
	}
}
Пример #5
0
int main(int argc, char **argv)
{
  static const char *output_file = "newconfig.cfg";
  config_t cfg;
  config_setting_t *root, *setting, *group, *array;
  int i;

  config_init(&cfg);
  root = config_root_setting(&cfg);

  /* Add some settings to the configuration. */
  group = config_setting_add(root, "address", CONFIG_TYPE_GROUP);

  setting = config_setting_add(group, "street", CONFIG_TYPE_STRING);
  config_setting_set_string(setting, "1 Woz Way");

  setting = config_setting_add(group, "city", CONFIG_TYPE_STRING);
  config_setting_set_string(setting, "San Jose");

  setting = config_setting_add(group, "state", CONFIG_TYPE_STRING);
  config_setting_set_string(setting, "CA");

  setting = config_setting_add(group, "zip", CONFIG_TYPE_INT);
  config_setting_set_int(setting, 95110);

  array = config_setting_add(root, "numbers", CONFIG_TYPE_ARRAY);

  for(i = 0; i < 10; ++i)
  {
    setting = config_setting_add(array, NULL, CONFIG_TYPE_INT);
    config_setting_set_int(setting, 10 * i);
  }

  /* Write out the new configuration. */
  if(! config_write_file(&cfg, output_file))
  {
    fprintf(stderr, "Error while writing file.\n");
    config_destroy(&cfg);
    return(EXIT_FAILURE);
  }

  fprintf(stderr, "New configuration successfully written to: %s\n",
          output_file);

  config_destroy(&cfg);
  return(EXIT_SUCCESS);
}
Пример #6
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;
}
Пример #7
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");
        }
    }
}
Пример #8
0
// {{{ session_store_session()
int session_store_session(const char* user, const char* sessid)
{
	if(strlen(user)==0 || strlen(sessid)==0)
		return -1;

   char var[256];
   struct config_t cfg;
   config_init(&cfg);

   char date[255];
   util_get_date(date, sizeof(date), "%Y%m%d%H%M%S");

   config_setting_t *cs;
   config_setting_t *us;

   if(!config_read_file(&cfg, OD_SESSION_FILE))
      config_write_file(&cfg, OD_SESSION_FILE);


	if( !(us = config_lookup(&cfg, user)) )
	{
		us = config_setting_add(cfg.root, user, CONFIG_TYPE_GROUP);
		cs = config_setting_add(us, "sessid", CONFIG_TYPE_STRING);
		cs = config_setting_add(us, "timestamp", CONFIG_TYPE_STRING);
	}

	snprintf(var, sizeof(var), "%s.sessid", user);
	if( !(cs = config_lookup(&cfg, var)) )
		return 0;
	config_setting_set_string(cs, sessid);

	snprintf(var, sizeof(var), "%s.timestamp", user);
	if( !(cs = config_lookup(&cfg, var)) )
		return 0;
	config_setting_set_string(cs, date);

	config_write_file(&cfg, OD_SESSION_FILE);
	config_destroy(&cfg);
	return 0;
}
Пример #9
0
/*******************************************************************************
 函数名称  : webauth_rdx_set_str_setting
 功能描述  : 向配置结构中增加字符串类型的属性
 输入参数  : config_setting_t * setting  配置结构
               char* attr                  配置属性名
               char* val                   配置属性值
 输出参数  :
 返 回 值  :
--------------------------------------------------------------------------------
 最近一次修改记录 :
 修改作者   :      王群
 修改目的   :      新添加函数
 修改日期   :      2010-08-16
*******************************************************************************/
void webauth_rdx_set_str_setting (config_setting_t * setting, char *attr, char *val)
{
    config_setting_t *s;

    if (0 != strlen (val))
    {
        s = config_setting_add (setting, attr, CONFIG_TYPE_STRING);
        if (NULL != s)
        {
            config_setting_set_string (s, val);
        }
    }

    return;
}
Пример #10
0
config_setting_t *cfgSetString(config_setting_t *parent, const TCHAR *name, const TCHAR *value)
{
	config_setting_t *setting;
	char *cfgStr;
	char uName[CONFIG_UTF8_MAXSTRING];

	UTF8_Encode(name, uName, CONFIG_UTF8_MAXSTRING);

	setting = config_setting_add(parent, uName, CONFIG_TYPE_STRING);

	cfgStr = UTF8_Encode_Dyn(value);
	config_setting_set_string(setting, cfgStr);
	free(cfgStr);

	return setting;
}
Пример #11
0
/*********************
return RET_NOK on error
*********************/
static ret_code_t __write_string(const char * table, const char * file, const char * data, va_list ap)
{
	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 RET_NOK;
	}

	setting = create_tree(config,NULL,NULL,NULL,CONFIG_TYPE_STRING,ap);

	/* update string */
	if(config_setting_set_string(setting, data)==CONFIG_FALSE) {
		SDL_UnlockMutex(entry_mutex);
		return RET_NOK;
	}

	write_config(config,table,file);
	SDL_UnlockMutex(entry_mutex);
	return RET_OK;
}
Пример #12
0
/**
 * Loads group configuration from config file into memory.
 * @private
 */
static void read_config(void)
{
	config_setting_t *groups = NULL;
	const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name
	int group_count = 0;
	
	if (conf_read_file(&pc_group_config, config_filename))
		return;

	groups = config_lookup(&pc_group_config, "groups");

	if (groups != NULL) {
		GroupSettings *group_settings = NULL;
		DBIterator *iter = NULL;
		int i, loop = 0;

		group_count = config_setting_length(groups);
		for (i = 0; i < group_count; ++i) {
			int id = 0, level = 0;
			const char *groupname = NULL;
			int log_commands = 0;
			config_setting_t *group = config_setting_get_elem(groups, i);

			if (!config_setting_lookup_int(group, "id", &id)) {
				ShowConfigWarning(group, "pc_groups:read_config: \"groups\" list member #%d has undefined id, removing...", i);
				config_setting_remove_elem(groups, i);
				--i;
				--group_count;
				continue;
			}

			if (id2group(id) != NULL) {
				ShowConfigWarning(group, "pc_groups:read_config: duplicate group id %d, removing...", i);
				config_setting_remove_elem(groups, i);
				--i;
				--group_count;
				continue;
			}

			config_setting_lookup_int(group, "level", &level);
			config_setting_lookup_bool(group, "log_commands", &log_commands);

			if (!config_setting_lookup_string(group, "name", &groupname)) {
				char temp[20];
				config_setting_t *name = NULL;
				snprintf(temp, sizeof(temp), "Group %d", id);
				if ((name = config_setting_add(group, "name", CONFIG_TYPE_STRING)) == NULL ||
				    !config_setting_set_string(name, temp)) {
					ShowError("pc_groups:read_config: failed to set missing group name, id=%d, skipping... (%s:%d)\n",
					          id, config_setting_source_file(group), config_setting_source_line(group));
					continue;
				}
				config_setting_lookup_string(group, "name", &groupname); // Retrieve the pointer
			}

			if (name2group(groupname) != NULL) {
				ShowConfigWarning(group, "pc_groups:read_config: duplicate group name %s, removing...", groupname);
				config_setting_remove_elem(groups, i);
				--i;
				--group_count;
				continue;
			}

			CREATE(group_settings, GroupSettings, 1);
			group_settings->id = id;
			group_settings->level = level;
			group_settings->name = groupname;
			group_settings->log_commands = (bool)log_commands;
			group_settings->inherit = config_setting_get_member(group, "inherit");
			group_settings->commands = config_setting_get_member(group, "commands");
			group_settings->permissions = config_setting_get_member(group, "permissions");
			group_settings->inheritance_done = false;
			group_settings->root = group;
			group_settings->group_pos = i;

			strdb_put(pc_groupname_db, groupname, group_settings);
			idb_put(pc_group_db, id, group_settings);
			
		}
		group_count = config_setting_length(groups); // Save number of groups
		
		// Check if all commands and permissions exist
		iter = db_iterator(pc_group_db);
		for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
			config_setting_t *commands = group_settings->commands, *permissions = group_settings->permissions;
			int count = 0, j;

			// Make sure there is "commands" group
			if (commands == NULL)
				commands = group_settings->commands = config_setting_add(group_settings->root, "commands", CONFIG_TYPE_GROUP);
			count = config_setting_length(commands);

			for (j = 0; j < count; ++j) {
				config_setting_t *command = config_setting_get_elem(commands, j);
				const char *name = config_setting_name(command);
				if (!atcommand_exists(name)) {
					ShowConfigWarning(command, "pc_groups:read_config: non-existent command name '%s', removing...", name);
					config_setting_remove(commands, name);
					--j;
					--count;
				}
			}

			// Make sure there is "permissions" group
			if (permissions == NULL)
				permissions = group_settings->permissions = config_setting_add(group_settings->root, "permissions", CONFIG_TYPE_GROUP);
			count = config_setting_length(permissions);

			for(j = 0; j < count; ++j) {
				config_setting_t *permission = config_setting_get_elem(permissions, j);
				const char *name = config_setting_name(permission);
				int p;

				ARR_FIND(0, ARRAYLENGTH(pc_g_permission_name), p, strcmp(pc_g_permission_name[p].name, name) == 0);
				if (p == ARRAYLENGTH(pc_g_permission_name)) {
					ShowConfigWarning(permission, "pc_groups:read_config: non-existent permission name '%s', removing...", name);
					config_setting_remove(permissions, name);
					--p;
					--count;
				}
			}
		}
		dbi_destroy(iter);

		// Apply inheritance
		i = 0; // counter for processed groups
		while (i < group_count) {
			iter = db_iterator(pc_group_db);
			for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
				config_setting_t *inherit = NULL,
				                 *commands = group_settings->commands,
					             *permissions = group_settings->permissions;
				int j, inherit_count = 0, done = 0;
				
				if (group_settings->inheritance_done) // group already processed
					continue; 

				if ((inherit = group_settings->inherit) == NULL ||
				    (inherit_count = config_setting_length(inherit)) <= 0) { // this group does not inherit from others
					++i;
					group_settings->inheritance_done = true;
					continue;
				}
				
				for (j = 0; j < inherit_count; ++j) {
					GroupSettings *inherited_group = NULL;
					const char *groupname = config_setting_get_string_elem(inherit, j);

					if (groupname == NULL) {
						ShowConfigWarning(inherit, "pc_groups:read_config: \"inherit\" array member #%d is not a name, removing...", j);
						config_setting_remove_elem(inherit,j);
						continue;
					}
					if ((inherited_group = name2group(groupname)) == NULL) {
						ShowConfigWarning(inherit, "pc_groups:read_config: non-existent group name \"%s\", removing...", groupname);
						config_setting_remove_elem(inherit,j);
						continue;
					}
					if (!inherited_group->inheritance_done)
						continue; // we need to do that group first

					// Copy settings (commands/permissions) that are not defined yet
					if (inherited_group->commands != NULL) {
						int l = 0, commands_count = config_setting_length(inherited_group->commands);
						for (l = 0; l < commands_count; ++l)
							config_setting_copy(commands, config_setting_get_elem(inherited_group->commands, l));
					}

					if (inherited_group->permissions != NULL) {
						int l = 0, permissions_count = config_setting_length(inherited_group->permissions);
						for (l = 0; l < permissions_count; ++l)
							config_setting_copy(permissions, config_setting_get_elem(inherited_group->permissions, l));
					}

					++done; // copied commands and permissions from one of inherited groups
				}
				
				if (done == inherit_count) { // copied commands from all of inherited groups
					++i;
					group_settings->inheritance_done = true; // we're done with this group
				}
			}
			dbi_destroy(iter);

			if (++loop > group_count) {
				ShowWarning("pc_groups:read_config: Could not process inheritance rules, check your config '%s' for cycles...\n",
				            config_filename);
				break;
			}
		} // while(i < group_count)

		// Pack permissions into GroupSettings.e_permissions for faster checking
		iter = db_iterator(pc_group_db);
		for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
			config_setting_t *permissions = group_settings->permissions;
			int c, count = config_setting_length(permissions);

			for (c = 0; c < count; ++c) {
				config_setting_t *perm = config_setting_get_elem(permissions, c);
				const char *name = config_setting_name(perm);
				int val = config_setting_get_bool(perm);
				int j;

				if (val == 0) // does not have this permission
					continue;
				ARR_FIND(0, ARRAYLENGTH(pc_g_permission_name), j, strcmp(pc_g_permission_name[j].name, name) == 0);
				group_settings->e_permissions |= pc_g_permission_name[j].permission;
			}
		}
		dbi_destroy(iter);
	}

	ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' groups in '"CL_WHITE"%s"CL_RESET"'.\n", group_count, config_filename);

	
	if( ( pc_group_max = group_count ) ) {
		DBIterator *iter = db_iterator(pc_group_db);
		GroupSettings *group_settings = NULL;
		int* group_ids = aMalloc( pc_group_max * sizeof(int) );
		int i = 0;
		for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
			group_ids[i++] = group_settings->id;
		}
		
		atcommand_db_load_groups(group_ids);
		
		aFree(group_ids);
		
		dbi_destroy(iter);
	}
}
Пример #13
0
int iteliec_soap_register (char *username, char *password) {
    herror_t err;
    SoapCtx *request;
    SoapCtx *response;

    config_t cfg;
    config_setting_t *setting, *root;
    const char *cfile;

    cfile = iteliec_config_file ();
    
    config_init (&cfg);

    /* Read the file. If there is an error, report it and exit. */
    if (!config_read_file (&cfg, cfile)) {
        iteliec_log (ITELIEC_ERR, "Please ensure configuration file %s exists and is valid", cfile);
        //printf ("\n%s:%d - %s", config_error_file (&cfg), config_error_line (&cfg), config_error_text (&cfg));
        
        config_destroy (&cfg);
        
        return;
    }

    root = config_root_setting (&cfg);

    /* Init */
    err = soap_client_init_args (0, NULL);
    if (err != H_OK)  {
        err_soap (err);
        
        return ITELIEC_ERR;
    }

    err = soap_ctx_new_with_method ("", "sendAuth", &request);
    if (err != H_OK) {
        err_soap (err);
        soap_client_destroy ();

        return ITELIEC_ERR;
    }

    /* Add login details */
    soap_env_add_item (request->env, "xsd:string", "username", username);
    soap_env_add_item (request->env, "xsd:string", "password", password);

    /* Trade for response */
    err = soap_client_invoke (request, &response, "http://api.iteliec.com/register/auth/ws/", "");
    if (err != H_OK)  {
        err_soap (err);
        soap_ctx_free (request);
        soap_client_destroy ();
        
        return ITELIEC_ERR;
    }

    /* Parse response */
    auth_type* ret = parse_auth_response (response);
    if (ret->auth == true) {
        printf ("Success\n");
        
        setting = config_setting_get_member (root, "api");
        if(!setting) {
            setting = config_setting_add (root, "api", CONFIG_TYPE_GROUP);        
        }

        setting = config_setting_add (setting, "hash", CONFIG_TYPE_STRING);
        config_setting_set_string (setting, ret->token);

        /* Write out the updated configuration. */
        if(! config_write_file(&cfg, cfile)) {
            fprintf (stderr, "Error while writing file.\n");
            config_destroy (&cfg);
            
            return (ITELIEC_OK);
        }

        printf("\nConfiguration file updated. Server is ready to run.\n");

    } else {
        printf("Auth failed\n");
    }

    /* Destroy */
    soap_ctx_free (request);
    soap_ctx_free (response);
    
    soap_client_destroy ();
    config_destroy (&cfg);

    return ITELIEC_OK;
}
Пример #14
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;
}
Пример #15
0
// load the default configuration in cfg
static void set_default_config(config_t * cfg) {
	static const unsigned AACCESSES = 4 * 1024 * 1024;
	static const unsigned BEGIN = BEGIN_INIT;
	static const char SPAWN[] = "linear";
	static const long long END = END_INIT;
	static const float FREQUENCY = 1;
	static const bool LOGGING = false;
	static const char LOGFILE[] = "adhd_log";
	static const char PATTERN[] = "random";
	static const unsigned PROCESSES = 1;
	static const unsigned REPETITIONS = 50;
	static const long long STEP = STEP_INIT;
	static const char SCALING[] = "linear";
	static const bool SILENT = false;
	static const unsigned THREADS = 1;

	static const long long STREAM_STEP = 10 * (1 << 20);
	static const long long STREAM_END = 100 * (1 << 20);

	static const long long FLOPS_STEP = 10 * (1 << 10);
	static const long long FLOPS_END = 1 * (1 << 20);
	static const long long FLOPS_CALCULATIONS = 1000 * 1000 * 1000;

	config_setting_t *setting;
	config_setting_t *root;
	root = config_root_setting(cfg);

	// generic group
	{
		config_setting_t *generic =
			config_setting_add(root, FLD_GENERIC_GROUP, CONFIG_TYPE_GROUP);

		// array of names of enabled programs (uses corresponding group names for
		// the sake of simplicity)
		{
			config_setting_t *programs =
				config_setting_add(generic, FLD_PROGRAMS_GROUP, CONFIG_TYPE_ARRAY);

			static const char *names[] = {
				FLD_WALKARRAY_GROUP,
				FLD_STREAMARRAY_GROUP,
				FLD_FLOPSARRAY_GROUP,
				NULL // mark end of list
			};

			for (size_t i = 0; names[i]; ++i) {
				setting = config_setting_add(programs, NULL, CONFIG_TYPE_STRING);
				config_setting_set_string(setting, names[i]);
			}
		}

		// CPU frequency to calculate cycle estimate
		// TODO: use actual cycle counter in the CPU
		// (this is a feature with a design impact, as SMP complicates matters ... :))
		setting = config_setting_add(generic, FLD_GENERIC_GPU_FREQUENCY, CONFIG_TYPE_FLOAT);
		config_setting_set_float(setting, FREQUENCY);

		// logging enabled?
		setting = config_setting_add(generic, FLD_GENERIC_LOGGING, CONFIG_TYPE_BOOL);
		config_setting_set_bool(setting, LOGGING);

		// base filename to log process timings to
		setting = config_setting_add(generic, FLD_GENERIC_LOGFILE, CONFIG_TYPE_STRING);
		config_setting_set_string(setting, LOGFILE);

		// process spawn method
		setting = config_setting_add(generic, FLD_GENERIC_SPAWN, CONFIG_TYPE_STRING);
		config_setting_set_string(setting, SPAWN);

		// number of processes to run: begin
		// TODO: just like arrays we could have a linear or exponential increment
		setting = config_setting_add(generic, FLD_GENERIC_PROCESSES_BEGIN, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, PROCESSES);

		// number of processes to run: end
		setting = config_setting_add(generic, FLD_GENERIC_PROCESSES_END, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, PROCESSES);

		// number of threads per process to run: begin
		// TODO: just like arrays we could have a linear or exponential increment
		setting = config_setting_add(generic, FLD_GENERIC_THREADS_BEGIN, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, THREADS);

		// number of threads per process to run: end
		setting = config_setting_add(generic, FLD_GENERIC_THREADS_END, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, THREADS);

		// silent mode
		setting = config_setting_add(generic, FLD_GENERIC_SILENT, CONFIG_TYPE_BOOL);
		config_setting_set_bool(setting, SILENT);
	}

	// walking array group
	{
		config_setting_t *array =
			config_setting_add(root, FLD_WALKARRAY_GROUP, CONFIG_TYPE_GROUP);

		// array accesses
		setting = config_setting_add(array, FLD_WALKARRAY_ACCESSES, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, AACCESSES);

		// repetitions of a single test, to be able to calculate an average
		// and a standard deviation, indicating run precision
		setting = config_setting_add(array, FLD_WALKARRAY_REPEAT, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, REPETITIONS);

		// initial array size
		setting = config_setting_add(array, FLD_WALKARRAY_BEGINLENGTH, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, BEGIN);

		// maximal array size
		setting = config_setting_add(array, FLD_WALKARRAY_ENDLENGTH, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, END);

		// increment factor
		setting = config_setting_add(array, FLD_WALKARRAY_INCREMENT, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, STEP);

		// increment type
		// (linear adds the increment, exponential multiplies the previous length)
		setting = config_setting_add(array, FLD_WALKARRAY_SCALING, CONFIG_TYPE_STRING);
		config_setting_set_string(setting, SCALING);

		// walking pattern
		// (sequentially increasing/decreasing or random)
		setting = config_setting_add(array, FLD_WALKARRAY_PATTERN, CONFIG_TYPE_STRING);
		config_setting_set_string(setting, PATTERN);
	}

	// streaming array group
	{
		config_setting_t *array =
			config_setting_add(root, FLD_STREAMARRAY_GROUP, CONFIG_TYPE_GROUP);

		// initial array size
		setting = config_setting_add(array, FLD_STREAMARRAY_BEGINLENGTH, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, BEGIN);

		// maximal array size
		setting = config_setting_add(array, FLD_STREAMARRAY_ENDLENGTH, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, STREAM_END);

		// increment factor
		setting = config_setting_add(array, FLD_STREAMARRAY_INCREMENT, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, STREAM_STEP);

		// increment type
		// (linear adds the increment, exponential multiplies the previous length)
		setting = config_setting_add(array, FLD_STREAMARRAY_SCALING, CONFIG_TYPE_STRING);
		config_setting_set_string(setting, SCALING);
	}

	// flops array group
	{
		config_setting_t *array =
			config_setting_add(root, FLD_FLOPSARRAY_GROUP, CONFIG_TYPE_GROUP);

		// initial array size
		setting = config_setting_add(array, FLD_FLOPSARRAY_BEGINLENGTH, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, BEGIN);

		// maximal array size
		setting = config_setting_add(array, FLD_FLOPSARRAY_ENDLENGTH, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, FLOPS_END);

		// increment factor
		setting = config_setting_add(array, FLD_FLOPSARRAY_INCREMENT, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, FLOPS_STEP);

		// increment type
		// (linear adds the increment, exponential multiplies the previous length)
		setting = config_setting_add(array, FLD_FLOPSARRAY_SCALING, CONFIG_TYPE_STRING);
		config_setting_set_string(setting, SCALING);

		// number of calculations to perform
		setting = config_setting_add(array, FLD_FLOPSARRAY_CALCULATIONS, CONFIG_TYPE_INT64);
		config_setting_set_int64(setting, FLOPS_CALCULATIONS);
	}
}
Пример #16
0
void settings_add_to_config(config_t *config)
{

    int i;

    char value[256];

    config_setting_t *root;
    config_setting_t *ps2;
    config_setting_t *group;

    config_setting_t *setting;

    if (config == NULL)
    {
        return;
    }

    root = config_root_setting(config);

    ps2 = config_setting_add(root,"PS2", CONFIG_TYPE_GROUP);
    {

        group = config_setting_add(ps2,"Home",CONFIG_TYPE_GROUP);
        {

            setting = config_setting_add(group,"Partition",CONFIG_TYPE_STRING);
            config_setting_set_string(setting,settings.home.partition);

            setting = config_setting_add(group,"Directory",CONFIG_TYPE_STRING);
            config_setting_set_string(setting,settings.home.directory);

        }

        group = config_setting_add(ps2,"Display", CONFIG_TYPE_GROUP);
        {


            setting = config_setting_add(group,"OffsetX",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.display.x);
            config_setting_set_string(setting,value);

            setting = config_setting_add(group,"OffsetY",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.display.y);
            config_setting_set_string(setting,value);

            setting = config_setting_add(group,"Mode",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.display.mode);
            config_setting_set_string(setting,value);

            setting = config_setting_add(group,"Interlace",CONFIG_TYPE_BOOL);
            config_setting_set_bool(setting,settings.display.interlace);

        }

        group = config_setting_add(ps2,"Sound",CONFIG_TYPE_GROUP);
        {

            setting = config_setting_add(group,"Stereo",CONFIG_TYPE_BOOL);
            config_setting_set_bool(setting,settings.sound.stereo);

            setting = config_setting_add(group,"Volume",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.sound.volume);
            config_setting_set_string(setting,value);

        }

        group = config_setting_add(ps2,"Font",CONFIG_TYPE_GROUP);
        {

            setting = config_setting_add(group,"Height",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.font.height);
            config_setting_set_string(setting,value);

            setting = config_setting_add(group,"Color",CONFIG_TYPE_ARRAY);
            for (i = 0; i < 4; i++)
            {
                cfg_int_to_string(value,settings.font.color[i]);
                config_setting_set_string_elem(setting,-1,value);
            }

            setting = config_setting_add(group,"Highlight",CONFIG_TYPE_ARRAY);
            for (i = 0; i < 4; i++)
            {
                cfg_int_to_string(value,settings.font.highlight[i]);
                config_setting_set_string_elem(setting,-1,value);
            }
        }

        group = config_setting_add(ps2,"Input",CONFIG_TYPE_GROUP);
        {

            setting = config_setting_add(group,"Port",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.input.port);
            config_setting_set_string(setting,value);

            setting = config_setting_add(group,"Slot",CONFIG_TYPE_STRING);
            cfg_int_to_string(value,settings.input.slot);
            config_setting_set_string(setting,value);

            setting = config_setting_add(group,"Confirm",CONFIG_TYPE_STRING);
            if (settings.input.confirm == PAD_CROSS)
            {
                config_setting_set_string(setting,"X");
            }
            else
            {
                config_setting_set_string(setting,"O");
            }

        }

        group = config_setting_add(ps2,"Devices",CONFIG_TYPE_GROUP);
        {

            setting = config_setting_add(group,"Mass",CONFIG_TYPE_BOOL);
            config_setting_set_bool(setting,settings.devices.mass);

            setting = config_setting_add(group,"HDD",CONFIG_TYPE_BOOL);
            config_setting_set_bool(setting,settings.devices.hdd);

        }

    }

}