Example #1
0
void initConfig() {
	_config_param = parameter_new();

	/* config-dir */
	char *home = getenv("HOME");
	if (home == NULL) {
		error_set(ERROR_CONFIG_HOME, "Unable to get home directory.");
		return;
	}

	STRINGBUFFER *tmp_cfg = stringbuffer_new();

	/* config-directory */
	stringbuffer_append(tmp_cfg, home);
	stringbuffer_append(tmp_cfg, SEPARATOR);
	stringbuffer_append(tmp_cfg, CONFIG_DIRECTORY);
	_config_directory = stringbuffer_clone(tmp_cfg);

	/* config-file */
	stringbuffer_append(tmp_cfg, SEPARATOR);
	stringbuffer_append(tmp_cfg, CONFIG_FILE);
	_config_file = stringbuffer_clone(tmp_cfg);
	printf ( "CONFIGFILE:\t%s\n", stringbuffer_getTextPointer(_config_file) );

	stringbuffer_free(tmp_cfg);

	/* load config */
	_config_param = parameter_new();
	parameter_loadFromFile(_config_param, stringbuffer_getTextPointer(_config_file));
	checkParameter(CONFIG_DIRECTORY_STORE_KEY, CONFIG_DIRECTORY_STORE_VALUE);
	checkParameter(CONFIG_DIRECTORY_RESTORE_KEY, CONFIG_DIRECTORY_RESTORE_VALUE);
	checkParameter(CONFIG_DIRECTORY_KEY_KEY, CONFIG_DIRECTORY_KEY_VALUE);

	/* make directories */
	char *tmp_dir;

	/* make store directory */
	tmp_dir = parameter_get(_config_param, CONFIG_DIRECTORY_STORE_KEY);
	assert(tmp_dir);
	if (!directory_exists(tmp_dir))
		directory_create(tmp_dir);
	free(tmp_dir);

	/* make restore directory */
	tmp_dir = parameter_get(_config_param, CONFIG_DIRECTORY_RESTORE_KEY);
	assert(tmp_dir);
	if (!directory_exists(tmp_dir))
		directory_create(tmp_dir);
	free(tmp_dir);

	/* make key directory */
	tmp_dir = parameter_get(_config_param, CONFIG_DIRECTORY_KEY_KEY);
	assert(tmp_dir);
	if (!directory_exists(tmp_dir))
		directory_create(tmp_dir);
	free(tmp_dir);
}
Example #2
0
static VALUE parameter_alloc(VALUE cls) {
  struct svm_parameter *n;
  n = parameter_new();
  if(n == NULL)
    rb_raise(rb_eNoMemError, "Not enough memory for allocating SvmParameter.");
  
  return Data_Wrap_Struct(cls, 0, parameter_free, n);
}
Example #3
0
void config_save(const char *filename) {
	char *tmp;
	PARAMETER *param = parameter_new();

	/* root */
	parameter_add(param, "root", _config.root);

	/* data */
	parameter_add(param, "data", _config.data);

	/* exec */
	parameter_add(param, "exec", _config.exec);

	/* temp */
	parameter_add(param, "temp", _config.temp);

	/* pipe */
	parameter_add(param, "pipe", _config.pipe);

	/* address */
	parameter_add(param, "address", _config.address);

	/* port */
	tmp = number_integerToString(_config.port);
	parameter_add(param, "port", tmp);
	free(tmp);

	/* timeout */
	tmp = number_integerToString(_config.timeout);
	parameter_add(param, "timeout", tmp);
	free(tmp);

	/* challenge */
	parameter_add(param, "challenge", _config.challenge);

	/* debug */
	tmp = boolean_toString(_config.debug);
	parameter_add(param, "debug", tmp);
	free(tmp);

	parameter_saveToFile(param, filename);
	parameter_free(param);
}
Example #4
0
void config_load(const char *filename) {
	if (!file_exists(filename))
		message_error("properties-file not found");

	memset(&_config, '\0', sizeof(config_t));

	char *tmp;
	PARAMETER *param = parameter_new();
	parameter_loadFromFile(param, filename);

	/* root */
	tmp = parameter_get(param, "root");
	if (tmp == NULL)
		_config.root[0] = '\0';
	else {
		strcpy(_config.root, tmp);
		free(tmp);
	}

	/* data */
	tmp = parameter_get(param, "data");
	if (tmp == NULL)
		_config.data[0] = '\0';
	else {
		strcpy(_config.data, tmp);
		free(tmp);
	}

	/* exec */
	tmp = parameter_get(param, "exec");
	if (tmp == NULL)
		_config.exec[0] = '\0';
	else {
		strcpy(_config.exec, tmp);
		free(tmp);
	}

	/* temp */
	tmp = parameter_get(param, "temp");
	if (tmp == NULL)
		_config.temp[0] = '\0';
	else {
		strcpy(_config.temp, tmp);
		free(tmp);
	}

	/* pipe */
	tmp = parameter_get(param, "pipe");
	if (tmp == NULL)
		_config.pipe[0] = '\0';
	else {
		strcpy(_config.pipe, tmp);
		free(tmp);
	}

	/* address */
	tmp = parameter_get(param, "address");
	if (tmp == NULL)
		_config.address[0] = '\0';
	else {
		strcpy(_config.address, tmp);
		free(tmp);
	}

	/* port */
	tmp = parameter_get(param, "port");
	if (tmp == NULL)
		_config.port = -1;
	else {
		_config.port = number_toInteger(tmp);
		free(tmp);
	}

	/* timeout */
	tmp = parameter_get(param, "timeout");
	if (tmp == NULL)
		_config.timeout = -1;
	else {
		_config.timeout = number_toInteger(tmp);
		free(tmp);
	}

	/* challenge */
	tmp = parameter_get(param, "challenge");
	if (tmp == NULL)
		_config.challenge[0] = '\0';
	else {
		strcpy(_config.challenge, tmp);
		free(tmp);
	}

	/* debug */
	tmp = parameter_get(param, "debug");
	if (tmp == NULL)
		_config.debug = FALSE;
	else {
		_config.debug = boolean_toBoolean(tmp);
		free(tmp);
	}

	parameter_free(param);
}