Esempio n. 1
0
DLLIMPORT int cfg_parse(cfg_t *cfg, const char *filename)
{
	int ret;
	FILE *fp;

	assert(cfg && filename);

	if (cfg->path) {
		char *f;

		if ((f = cfg_searchpath(cfg->path, filename)) == NULL)
			return CFG_FILE_ERROR;

		free(cfg->filename);
		cfg->filename = f;

	} else {
		free(cfg->filename);
		cfg->filename = cfg_tilde_expand(filename);
	}

	if ((fp = fopen(cfg->filename, "r")) == 0)
		return CFG_FILE_ERROR;

	ret = cfg_parse_fp(cfg, fp);
	fclose(fp);

	return ret;
}
Esempio n. 2
0
bool
gimmix_config_exists ()
{
	FILE *fp;
	char *rcfile = cfg_tilde_expand ("~/.gimmixrc");
	
	if (fp = fopen(rcfile, "r"))
	{
		fclose (fp);
		return true;
	}
	
	return false;
}
Esempio n. 3
0
DLLIMPORT int cfg_parse(cfg_t *cfg, const char *filename)
{
    int ret;
    FILE *fp;

    assert(cfg && filename);

    free(cfg->filename);
    cfg->filename = cfg_tilde_expand(filename);
    fp = fopen(cfg->filename, "r");
    if(fp == 0)
        return CFG_FILE_ERROR;
    ret = cfg_parse_fp(cfg, fp);
    fclose(fp);
    return ret;
}
Esempio n. 4
0
Ganglia_gmond_config
Ganglia_gmond_config_create(char *path, int fallback_to_default)
{
  cfg_t *config = NULL;
  /* Make sure we process ~ in the filename if the shell doesn't */
  char *tilde_expanded = cfg_tilde_expand( path );
  config = cfg_init( gmond_opts, CFGF_NOCASE );

  switch( cfg_parse( config, tilde_expanded ) )
    {
    case CFG_FILE_ERROR:
      /* Unable to open file so we'll go with the configuration defaults */
      err_msg("Configuration file '%s' not found.\n", tilde_expanded);
      if(!fallback_to_default)
        {
          /* Don't fallback to the default configuration.. just exit. */
          exit(1);
        }
      /* .. otherwise use our default configuration */
      if(cfg_parse_buf(config, default_gmond_configuration) == CFG_PARSE_ERROR)
        {
          err_msg("Your default configuration buffer failed to parse. Exiting.\n");
          exit(1);
        }
      break;
    case CFG_PARSE_ERROR:
      err_msg("Parse error for '%s'\n", tilde_expanded );
      exit(1);
    case CFG_SUCCESS:
      break;
    default:
      /* I have no clue whats goin' on here... */
      exit(1);
    }

  if(tilde_expanded)
    free(tilde_expanded);

#if 0
  atexit(cleanup_configuration_file);
#endif
  return (Ganglia_gmond_config)config;
}
Esempio n. 5
0
DLLIMPORT int cfg_add_searchpath(cfg_t *cfg, const char *dir)
{
	cfg_searchpath_t *p;
	char *d;

	assert(cfg && dir);

	if ((d = cfg_tilde_expand(dir)) == NULL)
		return CFG_PARSE_ERROR;

	if ((p = malloc(sizeof(cfg_searchpath_t))) == NULL) {
		free(d);
		return CFG_PARSE_ERROR;
	}

	p->next = cfg->path;
	p->dir = d;

	cfg->path = p;

	return CFG_SUCCESS;
}
Esempio n. 6
0
void
gimmix_config_save (Conf *conf)
{
	FILE *fp;
	cfg_t *cfg;
	cfg_opt_t *sopts;
	
	cfg_opt_t opts[] = {
		CFG_SIMPLE_STR ("mpd_hostname", NULL),
		CFG_SIMPLE_INT ("mpd_port", 0),
		CFG_SIMPLE_STR ("mpd_password", NULL),
		CFG_SIMPLE_BOOL ("enable_systray", false),
		CFG_SIMPLE_BOOL ("enable_notify", false),
		CFG_END()
	};

	cfg = cfg_init(opts, 0);
	char *rcfile = cfg_tilde_expand ("~/.gimmixrc");
	
	if((fp = fopen(rcfile, "w")))
	{	
		fprintf (fp, "# Gimmix configuration\n");
		fprintf (fp, "\n# MPD hostname (default: localhost)\n");
		if (conf->hostname)
			cfg_setstr(cfg, "mpd_hostname", conf->hostname);
		sopts = cfg_getopt (cfg, "mpd_hostname");
		cfg_opt_print (sopts, fp);

		fprintf (fp, "\n# MPD port (default: 6600)\n");
		if (conf->port > 0)
			cfg_setint(cfg, "mpd_port", conf->port);
		else
			cfg_setint(cfg, "mpd_port", 0);
		sopts = cfg_getopt (cfg, "mpd_port");
		cfg_opt_print (sopts, fp);
		
		fprintf (fp, "\n# MPD password (leave blank for no password) \n");
		if (conf->password)
			cfg_setstr(cfg, "mpd_password", conf->password);
		sopts = cfg_getopt (cfg, "mpd_password");
		cfg_opt_print (sopts, fp);

		fprintf (fp, "\n# Enable/Disable systray icon (Enable = true, Disable = false)\n");
		if (conf->systray_enable == 1)
			cfg_setbool(cfg, "enable_systray", true);
		else
			cfg_setbool(cfg, "enable_systray", false);
		sopts = cfg_getopt (cfg, "enable_systray");
		cfg_opt_print (sopts, fp);
		
		fprintf (fp, "\n# Enable/Disable system tray notifications (Enable = true, Disable = false) \n");
		if (conf->notify_enable == 1)
			cfg_setbool(cfg, "enable_notify", true);
		else
			cfg_setbool(cfg, "enable_notify", false);
		sopts = cfg_getopt (cfg, "enable_notify");
		cfg_opt_print (sopts, fp);

		free (rcfile);
		fclose (fp);
	}
	else
	{	
		fprintf (stderr, "Error while saving config.\n");
	}

	cfg_free_value (opts);
	cfg_free (cfg);
	
	return;
}
Esempio n. 7
0
Conf *
gimmix_config_init (void)
{
	cfg_t 		*cfg = NULL;
	char		*rcfile;
	Conf 		*conf;
	int 		ret;
	int		port = 1;
	cfg_bool_t	systray_enable = true;
	cfg_bool_t	notify_enable = true;
	
	conf = (Conf*)malloc(sizeof(Conf));
	char	*host = NULL;
	char	*pass = NULL;

	cfg_opt_t opts[] = {
		CFG_SIMPLE_STR ("mpd_hostname", &host),
		CFG_SIMPLE_INT ("mpd_port", &port),
		CFG_SIMPLE_STR ("mpd_password", &pass),
		CFG_SIMPLE_BOOL ("enable_systray", &systray_enable),
		CFG_SIMPLE_BOOL ("enable_notify", &notify_enable),
		CFG_END()
	};
	
	cfg = cfg_init (opts, 0);
	rcfile = cfg_tilde_expand ("~/.gimmixrc");
	ret = cfg_parse (cfg, rcfile);
	free (rcfile);
	
	if (ret == CFG_PARSE_ERROR)
	{
		free (conf);
		return NULL;
	}
	
	if (host != NULL)
		strncpy (conf->hostname, host, 255);
	
	if (pass != NULL)	
		strncpy (conf->password, pass, 255);
	
	conf->port = port;
	
	if (systray_enable == true)
	{	
		conf->systray_enable = 1;
	}
	else
	{	
		conf->systray_enable = 0;
	}
		
	if (notify_enable == true)
	{	
		conf->notify_enable = 1;
	}
	else
	{
		conf->notify_enable = 0;
	}

	/* Free the memory */
	cfg_free_value (opts);
	
	if (cfg)
		cfg_free (cfg);
	
	return conf;
}