Exemplo n.º 1
0
int main(void)
{
	cfg_opt_t sub_opts[] = {
		CFG_BOOL("bool", cfg_false, CFGF_NONE),
		CFG_STR("string", NULL, CFGF_NONE),
		CFG_INT("int", 0, CFGF_NONE),
		CFG_FLOAT("float", 0.0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_BOOL_LIST("bool", cfg_false, CFGF_NONE),
		CFG_STR_LIST("string", NULL, CFGF_NONE),
		CFG_INT_LIST("int", 0, CFGF_NONE),
		CFG_FLOAT_LIST("float", "0.0", CFGF_NONE),
		CFG_SEC("sub", sub_opts,
			CFGF_MULTI | CFGF_TITLE | CFGF_NO_TITLE_DUPES),
		CFG_END()
	};

	char *cmd = NULL;
	const char *reply;
	int res;
	int i;

	cfg = cfg_init(opts, CFGF_NONE);

	for (;;) {
		printf("cli> ");
		fflush(stdout);

		if (cmd)
			free(cmd);
		cmd = input_cmd();
		if (!cmd)
			exit(0);
		res = split_cmd(cmd);
		if (res < 0) {
			printf("Parse error\n");
			continue;
		}
		if (cmdc == 0)
			continue;
		for (i = 0; cmds[i].cmd; ++i) {
			if (strcmp(cmdv[0], cmds[i].cmd))
				continue;
			reply = cmds[i].handler(cmdc, cmdv);
			if (!reply)
				exit(0);
			printf("%s", reply);
			break;
		}
		if (!cmds[i].cmd)
			printf("Unknown command\n");
	}

	cfg_free(cfg);
	return 0;
}
Exemplo n.º 2
0
void validate_setup(void)
{
	cfg_opt_t *opt = 0;

	static cfg_opt_t action_opts[] = {
		CFG_INT("speed", 0, CFGF_NONE),
		CFG_STR("name", 0, CFGF_NONE),
		CFG_INT("xspeed", 0, CFGF_NONE),
		CFG_END()
	};

	static cfg_opt_t multi_opts[] = {
		CFG_INT_LIST("speeds", 0, CFGF_NONE),
		CFG_SEC("options", action_opts, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_STR_LIST("ip-address", 0, CFGF_NONE),
		CFG_INT_CB("action", ACTION_NONE, CFGF_NONE, parse_action),
		CFG_SEC("options", action_opts, CFGF_NONE),
		CFG_SEC("multi_options", multi_opts, CFGF_MULTI),
		CFG_END()
	};

	cfg = cfg_init(opts, 0);

	cfg_set_validate_func(cfg, "ip-address", validate_ip);
	fail_unless(cfg_set_validate_func(cfg, "ip-address", validate_ip) == validate_ip);
	opt = cfg_getopt(cfg, "ip-address");
	fail_unless(opt != 0);
	fail_unless(opt->validcb == validate_ip);

	cfg_set_validate_func(cfg, "options", validate_action);
	fail_unless(cfg_set_validate_func(cfg, "options", validate_action) == validate_action);
	opt = cfg_getopt(cfg, "options");
	fail_unless(opt != 0);
	fail_unless(opt->validcb == validate_action);

	cfg_set_validate_func(cfg, "options|speed", validate_speed);
	fail_unless(cfg_set_validate_func(cfg, "options|speed", validate_speed) == validate_speed);
	opt = cfg_getopt(cfg, "options|speed");
	fail_unless(opt != 0);
	fail_unless(opt->validcb == validate_speed);

	cfg_set_validate_func(cfg, "multi_options|speeds", validate_speed);
	fail_unless(cfg_set_validate_func(cfg, "multi_options|speeds", validate_speed) == validate_speed);

	cfg_set_validate_func(cfg, "multi_options|options|xspeed", validate_speed);
	fail_unless(cfg_set_validate_func(cfg, "multi_options|options|xspeed", validate_speed) == validate_speed);

	/* Validate callbacks for *set*() functions, i.e. not when parsing file content */
	cfg_set_validate_func2(cfg, "multi_options|speed", validate_speed2);
	cfg_set_validate_func2(cfg, "multi_options|options|name", validate_name2);
}
Exemplo n.º 3
0
/**
 * Parses the config file
 *
 * @return a pointer to the configuration data structure, NULL on failure
 */
static cfg_t * parse_config(void) {
	cfg_t * cfg = NULL;

	cfg_opt_t target_opts[] = {
	                              CFG_STR("comment", 0, CFGF_NONE),
	                              CFG_INT("strip", 0, CFGF_NONE),
	                              CFG_STR("rewrite_prefix", 0, CFGF_NONE),
	                              CFG_FLOAT("prob", 0, CFGF_NONE),
	                              CFG_INT("hash_index", 0, CFGF_NONE),
	                              CFG_STR("rewrite_suffix", 0, CFGF_NONE),
	                              CFG_INT("status", 1, CFGF_NONE),
	                              CFG_INT_LIST("backed_up", NULL, CFGF_NONE),
	                              CFG_INT("backup", -1, CFGF_NONE),
	                              CFG_END()
	                          };

	cfg_opt_t prefix_opts[] = {
	                              CFG_SEC("target", target_opts, CFGF_MULTI | CFGF_TITLE),
	                              CFG_INT("max_targets", -1, CFGF_NONE),
	                              CFG_END()
	                          };

	cfg_opt_t domain_opts[] = {
	                              CFG_SEC("prefix", prefix_opts, CFGF_MULTI | CFGF_TITLE),
	                              CFG_END()
	                          };

	cfg_opt_t opts[] = {
	                       CFG_SEC("domain", domain_opts, CFGF_MULTI | CFGF_TITLE),
	                       CFG_END()
	                   };

	cfg = cfg_init(opts, CFGF_NONE);

	cfg_set_error_function(cfg, conf_error);

	switch (cfg_parse(cfg, config_file)) {
		case CFG_FILE_ERROR: LM_ERR("file not found: %s\n", config_file);
			return NULL;
		case CFG_PARSE_ERROR: LM_ERR("error while parsing %s in line %i, section %s\n",
			                          cfg->filename, cfg->line, cfg->name);
			return NULL;
		case CFG_SUCCESS: break;
	}
	return cfg;
}
Exemplo n.º 4
0
Arquivo: pk2dft.c Projeto: GBert/misc
    CFG_INT("unused1b", 0, CFGF_NONE),
    CFG_INT("unused2", 0, CFGF_NONE),
    CFG_STR("notes", "", CFGF_NONE),
    CFG_STR_LIST("families", "", CFGF_NONE),
    CFG_STR_LIST("devices", "", CFGF_NONE),
    CFG_STR_LIST("scripts", "", CFGF_NONE),
    CFG_END()
};

cfg_opt_t script_opts[] = {
    CFG_STR("org_name", "", CFGF_NONE),
    CFG_STR("name", "NO_SCRIPT", CFGF_NONE),
    CFG_INT("id", 0, CFGF_NONE),
    CFG_INT("version", 0, CFGF_NONE),
    CFG_INT("unused1", 0, CFGF_NONE),
    CFG_INT_LIST("script", 0, CFGF_NONE),
    CFG_STR("comment", "", CFGF_NONE)
};

cfg_opt_t family_opts[] = {
    CFG_STR("name", "NO_FAM", CFGF_NONE),
    CFG_INT("fam_id", 0, CFGF_NONE),
    CFG_INT("fam_type", 0, CFGF_NONE),
    CFG_INT("search_prio", 0, CFGF_NONE),
    CFG_STR("prg_entry_script", "NO_SCRIPT", CFGF_NONE),
    CFG_STR("prg_exit_script", "NO_SCRIPT", CFGF_NONE),
    CFG_STR("rd_devid_script", "NO_SCRIPT", CFGF_NONE),
/*	CFG_INT("devid_mask"          ,           0, CFGF_NONE), */
/*	CFG_INT("blank_value"         ,           0, CFGF_NONE), */
    CFG_STR("devid_mask", "0", CFGF_NONE),	/* because libconfuse does not support 0xffffffff via */
    CFG_STR("blank_value", "0", CFGF_NONE),	/* the integer option */
Exemplo n.º 5
0
Arquivo: cfg.c Projeto: Bagarre/RProxy
#include <sys/stat.h>
#include <unistd.h>

#include "rproxy.h"

#define DEFAULT_CIPHERS "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:RC4-SHA:RC4-MD5:ECDHE-RSA-AES256-SHA:AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:DES-CBC3-SHA:AES128-SHA"

/* used to keep track of to-be-needed rlimit information, to be used later to
 * determine if the system settings can handle what is configured.
 */
static rproxy_rusage_t _rusage = { 0, 0, 0 };

static cfg_opt_t       ssl_crl_opts[] = {
    CFG_STR("file",        NULL,         CFGF_NONE),
    CFG_STR("dir",         NULL,         CFGF_NONE),
    CFG_INT_LIST("reload", "{ 10, 0  }", CFGF_NONE),
    CFG_END()
};

static cfg_opt_t       ssl_opts[] = {
    CFG_BOOL("enabled",           cfg_false,       CFGF_NONE),
    CFG_STR_LIST("protocols-on",  "{ALL}",         CFGF_NONE),
    CFG_STR_LIST("protocols-off", NULL,            CFGF_NONE),
    CFG_STR("cert",               NULL,            CFGF_NONE),
    CFG_STR("key",                NULL,            CFGF_NONE),
    CFG_STR("ca",                 NULL,            CFGF_NONE),
    CFG_STR("capath",             NULL,            CFGF_NONE),
    CFG_STR("ciphers",            DEFAULT_CIPHERS, CFGF_NONE),
    CFG_BOOL("verify-peer",       cfg_false,       CFGF_NONE),
    CFG_BOOL("enforce-peer-cert", cfg_false,       CFGF_NONE),
    CFG_INT("verify-depth",       0,               CFGF_NONE),
Exemplo n.º 6
0
settings *load_settings (const char *conffile)
{
	/* load settings from conffile */

	/* generic purpose counters */
	unsigned int i, j;

	/* declare and initialize the first event */
	event *event_first = calloc(1, sizeof(event));
	event_first->next = NULL;
	event *event_cur = event_first;

	settings *conf = calloc(1, sizeof(settings));

	cfg_opt_t ebk_event_opts[] =
	{
		CFG_INT_LIST("keys", "", CFGF_NONE),
		CFG_STR("action", "", CFGF_NONE),
		CFG_BOOL("onrelease", 0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t ebk_opts[] =
	{
		CFG_BOOL("daemon", 1, CFGF_NONE),
		CFG_STR("dev", "", CFGF_NONE | CFGF_NODEFAULT),
		CFG_SEC("event", ebk_event_opts, CFGF_MULTI),
		CFG_END()
	};

	cfg_t *cfg, *cfg_section;

	cfg = cfg_init(ebk_opts, CFGF_NONE);

	if (cfg_parse(cfg, conffile) == CFG_PARSE_ERROR)
		exit(1);

	conf->dev = strdup(cfg_getstr(cfg, "dev"));

	if ( ! cfg_getbool(cfg, "daemon") )
		conf->opts |= EBK_NODAEMON;

	for (i=0; i < cfg_size(cfg, "event"); i++)
	{
		cfg_section = cfg_getnsec(cfg, "event", i);

		/* easy peasy, set the action */
		event_cur->action = strdup(cfg_getstr(cfg_section, "action"));

		/* set the bool that determines if the action should fire on press or release  */
		/* if it's absent the value will be set to cfg_false */
		event_cur->bindToReleaseEvent = cfg_getbool(cfg_section, "onrelease");

		/* set key_count */
		event_cur->key_count = cfg_size(cfg_section, "keys");

		/* set key array */
		event_cur->keys = calloc(sizeof(short), event_cur->key_count);
		for (j=0; j < event_cur->key_count; j++)
		{
			if ( cfg_getnint(cfg_section, "keys", j) == 0 )
			{
				fprintf(stderr, "%s: Invalid key name: %s\n", conffile, cfg_getnstr(cfg_section, "keys", j));
				exit(2);
			}
			event_cur->keys[j] =  cfg_getnint(cfg_section, "keys", j);
		}

		/* prep the next event list item */
		event_cur->next = calloc(1, sizeof(event));
		event_cur = event_cur->next;
		event_cur->next = NULL;
	}


    /*
	 //print the parsed values to another file
    {
        FILE *fp = fopen("/etc/ebindkeys.conf.out", "w");
        cfg_print(cfg, fp);
        fclose(fp);
    }
	*/

	cfg_free(cfg);

	conf->event_first = event_first;

	return(conf);
}