Example #1
0
cfg_t *parse_conf(char *conf)
{
	cfg_opt_t provider_opts[] = {
		CFG_STR     ("username",  0, CFGF_NONE),
		CFG_STR     ("password",  0, CFGF_NONE),
		CFG_STR_LIST("alias",     0, CFGF_NONE),
		CFG_END()
	};
	cfg_opt_t opts[] = {
		CFG_BOOL("syslog",	  cfg_false, CFGF_NONE),
		CFG_BOOL("wildcard",	  cfg_false, CFGF_NONE),
		CFG_STR ("bind",	  0, CFGF_NONE),
		CFG_INT ("period",	  60, CFGF_NONE),
		CFG_INT ("startup-delay", 0, CFGF_NONE),
		CFG_INT ("forced-update", 720000, CFGF_NONE),
		CFG_SEC ("provider", provider_opts, CFGF_MULTI | CFGF_TITLE),
		CFG_END()
	};
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	switch (cfg_parse(cfg, conf)) {
	case CFG_FILE_ERROR:
		fprintf(stderr, "Cannot read configuration file %s: %s\n", conf, strerror(errno));

	case CFG_PARSE_ERROR:
		return NULL;

	case CFG_SUCCESS:
		break;
	}

    return cfg;
}
Example #2
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;
}
Example #3
0
cfg_t *parse_conf(const char *filename)
{
    cfg_opt_t bookmark_opts[] = {
        CFG_STR("host", 0, CFGF_NODEFAULT),
        CFG_INT("port", 21, CFGF_NONE),
        CFG_STR("login", "anonymous", CFGF_NONE),
        CFG_STR("password", "anonymous@", CFGF_NONE),
        CFG_STR("directory", 0, CFGF_NONE),
        CFG_END()
    };

    cfg_opt_t opts[] = {
        CFG_SEC("bookmark", bookmark_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_BOOL("reverse-dns", cfg_true, CFGF_NONE),
        CFG_BOOL("passive-mode", cfg_false, CFGF_NONE),
        CFG_BOOL("remote-completion", cfg_true, CFGF_NONE),
        CFG_FUNC("alias", conf_alias),
        CFG_STR_LIST("xterm-terminals", "{xterm, rxvt}", CFGF_NONE),
        CFG_INT_CB("auto-create-bookmark", ACB_YES, CFGF_NONE, conf_parse_acb),
        CFG_FUNC("include-file", cfg_include),
        CFG_END()
    };

    cfg_t *cfg = cfg_init(opts, CFGF_NONE);
    cfg_set_validate_func(cfg, "bookmark|port", conf_validate_port);
    cfg_set_validate_func(cfg, "bookmark", conf_validate_bookmark);

    switch(cfg_parse(cfg, filename))
    {
        case CFG_FILE_ERROR:
            printf("warning: configuration file '%s' could not be read: %s\n",
                    filename, strerror(errno));
            printf("continuing with default values...\n\n");
        case CFG_SUCCESS:
            break;
        case CFG_PARSE_ERROR:
            return 0;
    }

    return cfg;
}
Example #4
0
int main(void)
{
	char *comment;
	char *expect = "Now, is it this comment that goes with the option?";
	cfg_t *cfg;
	cfg_opt_t *opt;
	cfg_opt_t section_opts[] = {
		CFG_INT("key", 0, CFGF_NONE),
		CFG_BOOL("bool", 0, CFGF_NONE),
		CFG_STR("option", NULL, CFGF_NONE),
		CFG_END()
	};
	cfg_opt_t opts[] = {
		CFG_STR("option", NULL, CFGF_NONE),
		CFG_SEC("section", section_opts, CFGF_MULTI),
		CFG_END()
	};

	cfg = cfg_init(opts, CFGF_COMMENTS);
	fail_unless(cfg != NULL);

	fail_unless(cfg_parse(cfg, SRC_DIR "/annotate.conf") == CFG_SUCCESS);

	/* Verify the parser read the correct comment for this tricky option */
	opt = cfg_getopt(cfg, "section|option");
	fail_unless(opt != NULL);
	comment = cfg_opt_getcomment(opt);
	fail_unless(comment != NULL);
	fail_unless(strcmp(comment, expect) == 0);

	expect = "But what's the worst poetry in the universe?";
	fail_unless(cfg_opt_setcomment(opt, expect) == CFG_SUCCESS);

	cfg_opt_setnstr(opt, "Paula Nancy Millstone Jennings was a poet who wrote the worst poetry in "
			"the universe. In fact, her poetry is still considered to be the worst in "
			"the Galaxy, closely followed by that of the Azgoths of Kria and the "
			"Vogons, in that order.", 0);

	/* Verify that the comment is not reset when changing option value */
	comment = cfg_opt_getcomment(opt);
	fail_unless(comment != NULL);
	fail_unless(strcmp(comment, expect) == 0);

	cfg_print(cfg, stdout);
	fail_unless(cfg_free(cfg) == CFG_SUCCESS);

	return 0;
}
Example #5
0
int
handle_config_file(char **oor_conf_file)
{
    int ret;
    cfg_t *cfg;
    char *mode;
    char *log_file;

    /* xTR specific */
    static cfg_opt_t map_server_opts[] = {
            CFG_STR("address",              0, CFGF_NONE),
            CFG_INT("key-type",             0, CFGF_NONE),
            CFG_STR("key",                  0, CFGF_NONE),
            CFG_BOOL("proxy-reply", cfg_false, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t rloc_address_opts[] = {
            CFG_STR("address",       0, CFGF_NONE),
            CFG_INT("priority",      0, CFGF_NONE),
            CFG_INT("weight",        0, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t rloc_iface_opts[] = {
            CFG_STR("interface",     0, CFGF_NONE),
            CFG_INT("ip_version",    0, CFGF_NONE),
            CFG_INT("priority",      0, CFGF_NONE),
            CFG_INT("weight",        0, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t db_mapping_opts[] = {
            CFG_STR("eid-prefix",           0, CFGF_NONE),
            CFG_INT("iid",                  0, CFGF_NONE),
            CFG_SEC("rloc-address",         rloc_address_opts, CFGF_MULTI),
            CFG_SEC("rloc-iface",           rloc_iface_opts, CFGF_MULTI),
            CFG_END()
    };

    static cfg_opt_t map_cache_mapping_opts[] = {
            CFG_STR("eid-prefix",           0, CFGF_NONE),
            CFG_INT("iid",                  0, CFGF_NONE),
            CFG_SEC("rloc-address",         rloc_address_opts, CFGF_MULTI),
            CFG_END()
    };

    static cfg_opt_t petr_mapping_opts[] = {
            CFG_STR("address",              0, CFGF_NONE),
            CFG_INT("priority",           255, CFGF_NONE),
            CFG_INT("weight",               0, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t rtr_iface_opts[] = {
            CFG_STR("iface",                0, CFGF_NONE),
            CFG_INT("ip_version",           0, CFGF_NONE),
            CFG_INT("priority",             255, CFGF_NONE),
            CFG_INT("weight",               0, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t rtr_ifaces_opts[] = {
            CFG_SEC("rtr-iface",    rtr_iface_opts, CFGF_MULTI),
            CFG_END()
    };

    static cfg_opt_t nat_traversal_opts[] = {
            CFG_BOOL("nat_aware",   cfg_false, CFGF_NONE),
            CFG_STR("site_ID",              0, CFGF_NONE),
            CFG_STR("xTR_ID",               0, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t rloc_probing_opts[] = {
            CFG_INT("rloc-probe-interval",           0, CFGF_NONE),
            CFG_INT("rloc-probe-retries",            0, CFGF_NONE),
            CFG_INT("rloc-probe-retries-interval",   0, CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t elp_node_opts[] = {
            CFG_STR("address",      0,          CFGF_NONE),
            CFG_BOOL("strict",      cfg_false,  CFGF_NONE),
            CFG_BOOL("probe",       cfg_false,  CFGF_NONE),
            CFG_BOOL("lookup",      cfg_false,  CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t elp_opts[] = {
            CFG_STR("elp-name",     0,              CFGF_NONE),
            CFG_SEC("elp-node",     elp_node_opts,  CFGF_MULTI),
            CFG_END()
    };

    static cfg_opt_t rle_node_opts[] = {
            CFG_STR("address",      0,          CFGF_NONE),
            CFG_INT("level",        0,          CFGF_NONE),
            CFG_END()
    };

    static cfg_opt_t rle_opts[] = {
            CFG_STR("rle-name",     0,              CFGF_NONE),
            CFG_SEC("rle-node",     rle_node_opts,  CFGF_MULTI),
            CFG_END()
    };

    static cfg_opt_t mc_info_opts[] = {
            CFG_STR("mc-info-name",     0,              CFGF_NONE),
            CFG_STR("source",           0,              CFGF_NONE),
            CFG_INT("source-mask-length", 0,            CFGF_NONE),
            CFG_STR("group",            0,              CFGF_NONE),
            CFG_INT("group-mask-length", 0,             CFGF_NONE),
            CFG_INT("iid",              0,              CFGF_NONE),
            CFG_END()
    };

    /* Map-Server specific */
    static cfg_opt_t lisp_site_opts[] = {
            CFG_STR("eid-prefix",               0, CFGF_NONE),
            CFG_INT("iid",                      0, CFGF_NONE),
            CFG_INT("key-type",                 0, CFGF_NONE),
            CFG_STR("key",                      0, CFGF_NONE),
            CFG_BOOL("accept-more-specifics",   cfg_false, CFGF_NONE),
            CFG_BOOL("proxy-reply",             cfg_false, CFGF_NONE),
            CFG_BOOL("merge",                   cfg_false, CFGF_NONE),
            CFG_END()
    };

    cfg_opt_t opts[] = {
            CFG_SEC("database-mapping",     db_mapping_opts,        CFGF_MULTI),
            CFG_SEC("ms-static-registered-site", db_mapping_opts, CFGF_MULTI),
            CFG_SEC("rtr-database-mapping", db_mapping_opts,    CFGF_MULTI),
            CFG_SEC("static-map-cache",     map_cache_mapping_opts, CFGF_MULTI),
            CFG_SEC("map-server",           map_server_opts,        CFGF_MULTI),
            CFG_SEC("rtr-ifaces",           rtr_ifaces_opts,        CFGF_MULTI),
            CFG_SEC("proxy-etr",            petr_mapping_opts,      CFGF_MULTI),
            CFG_SEC("nat-traversal",        nat_traversal_opts,     CFGF_MULTI),
            CFG_STR("encapsulation",        0,                      CFGF_NONE),
            CFG_SEC("rloc-probing",         rloc_probing_opts,      CFGF_MULTI),
            CFG_INT("map-request-retries",  0, CFGF_NONE),
            CFG_INT("control-port",         0, CFGF_NONE),
            CFG_INT("debug",                0, CFGF_NONE),
            CFG_STR("log-file",             0, CFGF_NONE),
            CFG_INT("rloc-probing-interval",0, CFGF_NONE),
            CFG_STR_LIST("map-resolver",    0, CFGF_NONE),
            CFG_STR_LIST("proxy-itrs",      0, CFGF_NONE),
#ifdef ANDROID
            CFG_BOOL("override-dns",            cfg_false, CFGF_NONE),
            CFG_STR("override-dns-primary",     0, CFGF_NONE),
            CFG_STR("override-dns-secondary",   0, CFGF_NONE),
#endif
            CFG_STR("operating-mode",       0, CFGF_NONE),
            CFG_STR("control-iface",        0, CFGF_NONE),
            CFG_STR("rtr-data-iface",        0, CFGF_NONE),
            CFG_SEC("lisp-site",            lisp_site_opts,         CFGF_MULTI),
            CFG_SEC("explicit-locator-path", elp_opts,              CFGF_MULTI),
            CFG_SEC("replication-list",     rle_opts,               CFGF_MULTI),
            CFG_SEC("multicast-info",       mc_info_opts,           CFGF_MULTI),
            CFG_END()
    };

    if (*oor_conf_file == NULL){
        *oor_conf_file = strdup("/etc/oor.conf");
    }

    /*
     *  parse config_file
     */

    cfg = cfg_init(opts, CFGF_NOCASE);
    ret = cfg_parse(cfg, *oor_conf_file);


    if (ret == CFG_FILE_ERROR) {
        OOR_LOG(LCRIT, "Couldn't find config file %s, exiting...", config_file);
        exit_cleanup();
    } else if(ret == CFG_PARSE_ERROR) {
        OOR_LOG(LCRIT, "Parse error in file %s, exiting. Check conf file (see oor.conf.example)", config_file);
        exit_cleanup();
    }

    /*
     *  oor config options
     */

    /* Debug level */
    if (debug_level == -1){
        ret = cfg_getint(cfg, "debug");
        if (ret > 0)
            debug_level = ret;
        else
            debug_level = 0;
        if (debug_level > 3)
            debug_level = 3;
    }

    if (debug_level == 1){
        OOR_LOG (LINF, "Log level: Low debug");
    }else if (debug_level == 2){
        OOR_LOG (LINF, "Log level: Medium debug");
    }else if (debug_level == 3){
        OOR_LOG (LINF, "Log level: High Debug");
    }

    /*
     * Log file
     */

    log_file = cfg_getstr(cfg, "log-file");
    if (daemonize == TRUE){
        open_log_file(log_file);
    }

    mode = cfg_getstr(cfg, "operating-mode");
    if (mode) {
        if (strcmp(mode, "xTR") == 0) {
            ret=configure_xtr(cfg);
        } else if (strcmp(mode, "MS") == 0) {
            ret=configure_ms(cfg);
        } else if (strcmp(mode, "RTR") == 0) {
            ret=configure_rtr(cfg);
        }else if (strcmp(mode, "MN") == 0) {
            ret=configure_mn(cfg);
        }
    }

    cfg_free(cfg);
    return(GOOD);
}
Example #6
0
r_dev_list_t *config_parse(char *filename)
{
   cfg_t *cfg;
   r_dev_list_t *list; 
   unsigned int i;

   if (!filename)
       filename = "rpcap.conf";

   cfg = NULL;
   
   if(!(list = rdev_list_init()))
       return NULL;

   cfg_opt_t server_opts[] = {
       CFG_STR("output-dev", "rpcap0", CFGF_NONE),
       CFG_STR("bpf", NULL, CFGF_NONE),
       CFG_INT("snaplen", 512, CFGF_NONE),
       CFG_INT("compression-level", 0, CFGF_NONE),
       CFG_INT("server-port", 1025, CFGF_NONE),
       CFG_STR("interface", "eth0", CFGF_NONE),
       CFG_STR("server", NULL, CFGF_NONE),
       CFG_BOOL("ignore-rpcap-traffic", 0, CFGF_NONE),
       CFG_END()
   };

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

   cfg = cfg_init(opts, CFGF_NOCASE);

   if (cfg_parse(cfg, filename) == CFG_PARSE_ERROR)
   {
       cfg_free(cfg);
       exit(1);
   }

   for (i = 0; i < cfg_size(cfg, "rpcap"); i++)
   {
       cfg_t *rule;
       r_dev_t *dev;
       char *bpf;
       int no_rp_traf = 0;

       bpf = NULL;
       dev = rdev_init();
       rule = cfg_getnsec(cfg, "rpcap", i);

       if (!cfg_getstr(rule, "server"))
       {
	   fprintf(stderr, "No server found in rule %s\n",
		   cfg_title(rule));
	   exit(1);
       }

       if((bpf = cfg_getstr(rule, "bpf")))
	   dev->bpf = strdup(bpf);

       dev->iface   = strdup(cfg_getstr(rule, "interface"));
       dev->port    = cfg_getint(rule, "server-port");
       dev->serv    = strdup(cfg_getstr(rule, "server"));
       dev->snaplen = cfg_getint(rule, "snaplen");
       dev->virtual_iface = strdup(cfg_getstr(rule, "output-dev"));

       no_rp_traf = cfg_getbool(rule, "ignore-rpcap-traffic");

       rdev_list_add(list, dev);

   
       if (no_rp_traf)
       {
	   char mbuf[2048];

	   memset(mbuf, 0, sizeof(mbuf));

	   snprintf(mbuf, sizeof(mbuf)-1, 
	       "(!(host %s && port %d)) %s %s", 
	       dev->serv, dev->port, dev->bpf?"&&":"",
	       dev->bpf?dev->bpf:"");

	   free(dev->bpf);
	   dev->bpf = strdup(mbuf);
       }
       printf("HI THERE %s\n", dev->bpf);
   }
   cfg_free(cfg);
   return list;
}
Example #7
0
/* Forward */
static int cb_loglevel(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);

/* general section structure */
static cfg_opt_t sec_general[] =
  {
    CFG_STR("uid", "nobody", CFGF_NONE),
    CFG_STR("admin_password", NULL, CFGF_NONE),
    CFG_STR("logfile", STATEDIR "/log/" PACKAGE ".log", CFGF_NONE),
    CFG_STR("db_path", STATEDIR "/cache/" PACKAGE "/songs3.db", CFGF_NONE),
    CFG_INT("db_pragma_cache_size", -1, CFGF_NONE),
    CFG_STR("db_pragma_journal_mode", NULL, CFGF_NONE),
    CFG_INT("db_pragma_synchronous", -1, CFGF_NONE),
    CFG_INT_CB("loglevel", E_LOG, CFGF_NONE, &cb_loglevel),
    CFG_BOOL("ipv6", cfg_false, CFGF_NONE),
    CFG_STR("cache_path", STATEDIR "/cache/" PACKAGE "/cache.db", CFGF_NONE),
    CFG_INT("cache_daap_threshold", 1000, CFGF_NONE),
    CFG_END()
  };

/* library section structure */
static cfg_opt_t sec_library[] =
  {
    CFG_STR("name", "My Music on %h", CFGF_NONE),
    CFG_INT("port", 3689, CFGF_NONE),
    CFG_STR("password", NULL, CFGF_NONE),
    CFG_STR_LIST("directories", NULL, CFGF_NONE),
    CFG_STR_LIST("podcasts", NULL, CFGF_NONE),
    CFG_STR_LIST("audiobooks", NULL, CFGF_NONE),
    CFG_STR_LIST("compilations", NULL, CFGF_NONE),
static cfg_opt_t cluster_opts[] = {
  CFG_STR("name", "unspecified", CFGF_NONE ),
  CFG_STR("owner", "unspecified", CFGF_NONE ),
  CFG_STR("latlong", "unspecified", CFGF_NONE ),
  CFG_STR("url", "unspecified", CFGF_NONE ),
  CFG_END()
};

static cfg_opt_t host_opts[] = {
  CFG_STR("location", "unspecified", CFGF_NONE ),
  CFG_END()
};

static cfg_opt_t globals_opts[] = {
  CFG_BOOL("daemonize", 1, CFGF_NONE),
  CFG_BOOL("setuid", 1 - NO_SETUID, CFGF_NONE),
  CFG_STR("user", SETUID_USER, CFGF_NONE),
  /* later i guess we should add "group" as well */
  CFG_INT("debug_level", 0, CFGF_NONE),
  CFG_INT("max_udp_msg_len", 1472, CFGF_NONE),
  CFG_BOOL("mute", 0, CFGF_NONE),
  CFG_BOOL("deaf", 0, CFGF_NONE),
  CFG_BOOL("allow_extra_data", 1, CFGF_NONE),
  CFG_INT("host_dmax", 0, CFGF_NONE),
  CFG_INT("host_tmax", 20, CFGF_NONE),
  CFG_INT("cleanup_threshold", 300, CFGF_NONE),
  CFG_BOOL("gexec", 0, CFGF_NONE),
  CFG_INT("send_metadata_interval", 0, CFGF_NONE),
  CFG_STR("module_dir", NULL, CFGF_NONE),
  CFG_END()
Example #9
0
  CFG_INT("port", 0, CFGF_NONE),
  CFG_END()
};

/**
 * \var opts
 * \brief Options recognized.
 */
static cfg_opt_t opts[]=
{
  CFG_STR("listen_address", NULL, CFGF_LIST),
  CFG_STR("listen_addressv6", NULL, CFGF_LIST),
  CFG_INT("udp_port", 3478, CFGF_NONE),
  CFG_INT("tcp_port", 3478, CFGF_NONE),
  CFG_INT("tls_port", 5349, CFGF_NONE),
  CFG_BOOL("tls", cfg_false, CFGF_NONE),
  CFG_BOOL("dtls", cfg_false, CFGF_NONE),
  CFG_INT("max_port", 65535, CFGF_NONE),
  CFG_INT("min_port", 49152, CFGF_NONE),
  CFG_BOOL("turn_tcp", cfg_false, CFGF_NONE),
  CFG_BOOL("tcp_buffer_userspace", cfg_true, CFGF_NONE),
  CFG_INT("tcp_buffer_size", 1500, CFGF_NONE),
  CFG_INT("restricted_bandwidth", 10, CFGF_NONE),
  CFG_BOOL("daemon", cfg_false, CFGF_NONE),
  CFG_STR("unpriv_user", NULL, CFGF_NONE),
  CFG_INT("max_client", 50, CFGF_NONE),
  CFG_INT("max_relay_per_username", 10, CFGF_NONE),
  CFG_INT("allocation_lifetime", 1800, CFGF_NONE),
  CFG_STR("nonce_key", NULL, CFGF_NONE),
  CFG_STR("ca_file", NULL, CFGF_NONE),
  CFG_STR("cert_file", NULL, CFGF_NONE),
Example #10
0
#include "misc.h"
#include "conffile.h"


/* Forward */
static int cb_loglevel(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);

/* general section structure */
static cfg_opt_t sec_general[] =
  {
    CFG_STR("uid", "nobody", CFGF_NONE),
    CFG_STR("admin_password", NULL, CFGF_NONE),
    CFG_STR("logfile", STATEDIR "/log/" PACKAGE ".log", CFGF_NONE),
    CFG_STR("db_path", STATEDIR "/cache/" PACKAGE "/songs3.db", CFGF_NONE),
    CFG_INT_CB("loglevel", E_LOG, CFGF_NONE, &cb_loglevel),
    CFG_BOOL("ipv6", cfg_true, CFGF_NONE),
    CFG_END()
  };

/* library section structure */
static cfg_opt_t sec_library[] =
  {
    CFG_STR("name", "My Music on %h", CFGF_NONE),
    CFG_INT("port", 3689, CFGF_NONE),
    CFG_STR("password", NULL, CFGF_NONE),
    CFG_STR_LIST("directories", NULL, CFGF_NONE),
    CFG_STR_LIST("compilations", NULL, CFGF_NONE),
    CFG_STR_LIST("artwork_basenames", "{artwork,cover}", CFGF_NONE),
    CFG_BOOL("itunes_overrides", cfg_false, CFGF_NONE),
    CFG_STR_LIST("no_transcode", NULL, CFGF_NONE),
    CFG_STR_LIST("force_transcode", NULL, CFGF_NONE),
Example #11
0
// EDF libConfuse option structures
//

// cast call
static cfg_opt_t cast_sound_opts[] =
{
   CFG_STR(ITEM_CAST_SOUNDFRAME, "S_NULL", CFGF_NONE),
   CFG_STR(ITEM_CAST_SOUNDNAME,  "none",   CFGF_NONE),
   CFG_END()
};

static cfg_opt_t cast_opts[] =
{
   CFG_STR(ITEM_CAST_TYPE,  NULL,            CFGF_NONE),
   CFG_STR(ITEM_CAST_NAME,  "unknown",       CFGF_NONE),
   CFG_BOOL(ITEM_CAST_SA,   false,           CFGF_NONE),
   CFG_SEC(ITEM_CAST_SOUND, cast_sound_opts, CFGF_MULTI|CFGF_NOCASE),
   CFG_END()
};

//=============================================================================
//
// EDF Root Options
//

#define EDF_TSEC_FLAGS (CFGF_MULTI | CFGF_TITLE | CFGF_NOCASE)
#define EDF_NSEC_FLAGS (CFGF_MULTI | CFGF_NOCASE)

static cfg_opt_t edf_opts[] =
{
   CFG_STR(SEC_SPRITE,          0,                 CFGF_LIST),
Example #12
0
int main(int argc, char *argv[])
{
    /*
    configuration options
    */
    cfg_opt_t opts[] =
    {
        CFG_INT("vendor_id", 0, 0),
        CFG_INT("product_id", 0, 0),
        CFG_BOOL("self_powered", cfg_true, 0),
        CFG_BOOL("remote_wakeup", cfg_true, 0),
        CFG_BOOL("in_is_isochronous", cfg_false, 0),
        CFG_BOOL("out_is_isochronous", cfg_false, 0),
        CFG_BOOL("suspend_pull_downs", cfg_false, 0),
        CFG_BOOL("use_serial", cfg_false, 0),
        CFG_BOOL("change_usb_version", cfg_false, 0),
        CFG_INT("usb_version", 0, 0),
        CFG_INT("default_pid", 0x6001, 0),
        CFG_INT("max_power", 0, 0),
        CFG_STR("manufacturer", "Acme Inc.", 0),
        CFG_STR("product", "USB Serial Converter", 0),
        CFG_STR("serial", "08-15", 0),
        CFG_INT("eeprom_type", 0x00, 0),
        CFG_STR("filename", "", 0),
        CFG_BOOL("flash_raw", cfg_false, 0),
        CFG_BOOL("high_current", cfg_false, 0),
        CFG_STR_LIST("cbus0", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0),
        CFG_STR_LIST("cbus1", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0),
        CFG_STR_LIST("cbus2", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0),
        CFG_STR_LIST("cbus3", "{TXDEN,PWREN,RXLED,TXLED,TXRXLED,SLEEP,CLK48,CLK24,CLK12,CLK6,IO_MODE,BITBANG_WR,BITBANG_RD,SPECIAL}", 0),
        CFG_STR_LIST("cbus4", "{TXDEN,PWRON,RXLED,TXLED,TX_RX_LED,SLEEP,CLK48,CLK24,CLK12,CLK6}", 0),
        CFG_BOOL("invert_txd", cfg_false, 0),
        CFG_BOOL("invert_rxd", cfg_false, 0),
        CFG_BOOL("invert_rts", cfg_false, 0),
        CFG_BOOL("invert_cts", cfg_false, 0),
        CFG_BOOL("invert_dtr", cfg_false, 0),
        CFG_BOOL("invert_dsr", cfg_false, 0),
        CFG_BOOL("invert_dcd", cfg_false, 0),
        CFG_BOOL("invert_ri", cfg_false, 0),
        CFG_END()
    };
    cfg_t *cfg;

    /*
    normal variables
    */
    int _read = 0, _erase = 0, _flash = 0;

    const int max_eeprom_size = 256;
    int my_eeprom_size = 0;
    unsigned char *eeprom_buf = NULL;
    char *filename;
    int size_check;
    int i, argc_filename;
    FILE *fp;

    struct ftdi_context *ftdi = NULL;

    printf("\nFTDI eeprom generator v%s\n", EEPROM_VERSION_STRING);
    printf ("(c) Intra2net AG and the libftdi developers <*****@*****.**>\n");

    if (argc != 2 && argc != 3)
    {
        printf("Syntax: %s [commands] config-file\n", argv[0]);
        printf("Valid commands:\n");
        printf("--read-eeprom  Read eeprom and write to -filename- from config-file\n");
        printf("--erase-eeprom  Erase eeprom\n");
        printf("--flash-eeprom  Flash eeprom\n");
        exit (-1);
    }

    if (argc == 3)
    {
        if (strcmp(argv[1], "--read-eeprom") == 0)
            _read = 1;
        else if (strcmp(argv[1], "--erase-eeprom") == 0)
            _erase = 1;
        else if (strcmp(argv[1], "--flash-eeprom") == 0)
            _flash = 1;
        else
        {
            printf ("Can't open configuration file\n");
            exit (-1);
        }
        argc_filename = 2;
    }
    else
    {
        argc_filename = 1;
    }

    if ((fp = fopen(argv[argc_filename], "r")) == NULL)
    {
        printf ("Can't open configuration file\n");
        exit (-1);
    }
    fclose (fp);

    cfg = cfg_init(opts, 0);
    cfg_parse(cfg, argv[argc_filename]);
    filename = cfg_getstr(cfg, "filename");

    if (cfg_getbool(cfg, "self_powered") && cfg_getint(cfg, "max_power") > 0)
        printf("Hint: Self powered devices should have a max_power setting of 0.\n");

    if ((ftdi = ftdi_new()) == 0)
    {
        fprintf(stderr, "Failed to allocate ftdi structure :%s \n",
                ftdi_get_error_string(ftdi));
        return EXIT_FAILURE;
    }

    if (_read > 0 || _erase > 0 || _flash > 0)
    {
        int vendor_id = cfg_getint(cfg, "vendor_id");
        int product_id = cfg_getint(cfg, "product_id");

        i = ftdi_usb_open(ftdi, vendor_id, product_id);

        if (i != 0)
        {
            int default_pid = cfg_getint(cfg, "default_pid");
            printf("Unable to find FTDI devices under given vendor/product id: 0x%X/0x%X\n", vendor_id, product_id);
            printf("Error code: %d (%s)\n", i, ftdi_get_error_string(ftdi));
            printf("Retrying with default FTDI pid=%#04x.\n", default_pid);

            i = ftdi_usb_open(ftdi, 0x0403, default_pid);
            if (i != 0)
            {
                printf("Error: %s\n", ftdi->error_str);
                exit (-1);
            }
        }
    }
    ftdi_eeprom_initdefaults (ftdi, cfg_getstr(cfg, "manufacturer"), 
                              cfg_getstr(cfg, "product"), 
                              cfg_getstr(cfg, "serial"));

    printf("FTDI read eeprom: %d\n", ftdi_read_eeprom(ftdi));
    eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);
    printf("EEPROM size: %d\n", my_eeprom_size);

    if (_read > 0)
    {
        ftdi_eeprom_decode(ftdi, 1);

        eeprom_buf = malloc(my_eeprom_size);
        ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);

        if (eeprom_buf == NULL)
        {
            fprintf(stderr, "Malloc failed, aborting\n");
            goto cleanup;
        }
        if (filename != NULL && strlen(filename) > 0)
        {

            FILE *fp = fopen (filename, "wb");
            fwrite (eeprom_buf, 1, my_eeprom_size, fp);
            fclose (fp);
        }
        else
        {
            printf("Warning: Not writing eeprom, you must supply a valid filename\n");
        }

        goto cleanup;
    }

    eeprom_set_value(ftdi, VENDOR_ID, cfg_getint(cfg, "vendor_id"));
    eeprom_set_value(ftdi, PRODUCT_ID, cfg_getint(cfg, "product_id"));

    eeprom_set_value(ftdi, SELF_POWERED, cfg_getbool(cfg, "self_powered"));
    eeprom_set_value(ftdi, REMOTE_WAKEUP, cfg_getbool(cfg, "remote_wakeup"));
    eeprom_set_value(ftdi, MAX_POWER, cfg_getint(cfg, "max_power"));

    eeprom_set_value(ftdi, IN_IS_ISOCHRONOUS, cfg_getbool(cfg, "in_is_isochronous"));
    eeprom_set_value(ftdi, OUT_IS_ISOCHRONOUS, cfg_getbool(cfg, "out_is_isochronous"));
    eeprom_set_value(ftdi, SUSPEND_PULL_DOWNS, cfg_getbool(cfg, "suspend_pull_downs"));

    eeprom_set_value(ftdi, USE_SERIAL, cfg_getbool(cfg, "use_serial"));
    eeprom_set_value(ftdi, USE_USB_VERSION, cfg_getbool(cfg, "change_usb_version"));
    eeprom_set_value(ftdi, USB_VERSION, cfg_getint(cfg, "usb_version"));
    eeprom_set_value(ftdi, CHIP_TYPE, cfg_getint(cfg, "eeprom_type"));

    eeprom_set_value(ftdi, HIGH_CURRENT, cfg_getbool(cfg, "high_current"));
    eeprom_set_value(ftdi, CBUS_FUNCTION_0, str_to_cbus(cfg_getstr(cfg, "cbus0"), 13));
    eeprom_set_value(ftdi, CBUS_FUNCTION_1, str_to_cbus(cfg_getstr(cfg, "cbus1"), 13));
    eeprom_set_value(ftdi, CBUS_FUNCTION_2, str_to_cbus(cfg_getstr(cfg, "cbus2"), 13));
    eeprom_set_value(ftdi, CBUS_FUNCTION_3, str_to_cbus(cfg_getstr(cfg, "cbus3"), 13));
    eeprom_set_value(ftdi, CBUS_FUNCTION_4, str_to_cbus(cfg_getstr(cfg, "cbus4"), 9));
    int invert = 0;
    if (cfg_getbool(cfg, "invert_rxd")) invert |= INVERT_RXD;
    if (cfg_getbool(cfg, "invert_txd")) invert |= INVERT_TXD;
    if (cfg_getbool(cfg, "invert_rts")) invert |= INVERT_RTS;
    if (cfg_getbool(cfg, "invert_cts")) invert |= INVERT_CTS;
    if (cfg_getbool(cfg, "invert_dtr")) invert |= INVERT_DTR;
    if (cfg_getbool(cfg, "invert_dsr")) invert |= INVERT_DSR;
    if (cfg_getbool(cfg, "invert_dcd")) invert |= INVERT_DCD;
    if (cfg_getbool(cfg, "invert_ri")) invert |= INVERT_RI;
    eeprom_set_value(ftdi, INVERT, invert);

    eeprom_set_value(ftdi, CHANNEL_A_DRIVER, DRIVER_VCP);
    eeprom_set_value(ftdi, CHANNEL_B_DRIVER, DRIVER_VCP);
    eeprom_set_value(ftdi, CHANNEL_C_DRIVER, DRIVER_VCP);
    eeprom_set_value(ftdi, CHANNEL_D_DRIVER, DRIVER_VCP);
    eeprom_set_value(ftdi, CHANNEL_A_RS485, 0);
    eeprom_set_value(ftdi, CHANNEL_B_RS485, 0);
    eeprom_set_value(ftdi, CHANNEL_C_RS485, 0);
    eeprom_set_value(ftdi, CHANNEL_D_RS485, 0);

    if (_erase > 0)
    {
        printf("FTDI erase eeprom: %d\n", ftdi_erase_eeprom(ftdi));
    }

    size_check = ftdi_eeprom_build(ftdi);
    eeprom_get_value(ftdi, CHIP_SIZE, &my_eeprom_size);

    if (size_check == -1)
    {
        printf ("Sorry, the eeprom can only contain 128 bytes (100 bytes for your strings).\n");
        printf ("You need to short your string by: %d bytes\n", size_check);
        goto cleanup;
    } else if (size_check < 0) {
        printf ("ftdi_eeprom_build(): error: %d\n", size_check);
    }
    else
    {
        printf ("Used eeprom space: %d bytes\n", my_eeprom_size-size_check);
    }

    if (_flash > 0)
    {
        if (cfg_getbool(cfg, "flash_raw"))
        {
            if (filename != NULL && strlen(filename) > 0)
            {
                eeprom_buf = malloc(max_eeprom_size);
                FILE *fp = fopen(filename, "rb");
                if (fp == NULL)
                {
                    printf ("Can't open eeprom file %s.\n", filename);
                    exit (-1);
                }
                my_eeprom_size = fread(eeprom_buf, 1, max_eeprom_size, fp);
                fclose(fp);
                if (my_eeprom_size < 128)
                {
                    printf ("Can't read eeprom file %s.\n", filename);
                    exit (-1);
                }

                ftdi_set_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);
            }
        }
        printf ("FTDI write eeprom: %d\n", ftdi_write_eeprom(ftdi));
        libusb_reset_device(ftdi->usb_dev);
    }

    // Write to file?
    if (filename != NULL && strlen(filename) > 0 && !cfg_getbool(cfg, "flash_raw"))
    {
        fp = fopen(filename, "w");
        if (fp == NULL)
        {
            printf ("Can't write eeprom file.\n");
            exit (-1);
        }
        else
            printf ("Writing to file: %s\n", filename);

        if (eeprom_buf == NULL)
            eeprom_buf = malloc(my_eeprom_size);
        ftdi_get_eeprom_buf(ftdi, eeprom_buf, my_eeprom_size);

        fwrite(eeprom_buf, my_eeprom_size, 1, fp);
        fclose(fp);
    }

cleanup:
    if (eeprom_buf)
        free(eeprom_buf);
    if (_read > 0 || _erase > 0 || _flash > 0)
    {
        printf("FTDI close: %d\n", ftdi_usb_close(ftdi));
    }

    ftdi_deinit (ftdi);
    ftdi_free (ftdi);

    cfg_free(cfg);

    printf("\n");
    return 0;
}
Example #13
0
int main(int argc, char *argv[])
{
	uint8_t threadid_main = 0;
	pthread_key_create(&threadid_key, NULL);
	pthread_setspecific(threadid_key, &threadid_main);

	mprintf("University of Wisconsin IPMI MicroTCA System Manager\n");
	if (argc > 1 && strcmp(argv[1], "--version") == 0) {
		mprintf("\nCompiled from %s@%s\n", (GIT_BRANCH[0] ? GIT_BRANCH : "git-archive"), (GIT_COMMIT[0] ? GIT_COMMIT : "27868b9b800d107fbb53b68c2fce207144f97a98"));
		if (strlen(GIT_DIRTY) > 1)
			mprintf("%s", GIT_DIRTY);
		mprintf("\n");
		return 0;
	}

	/*
	 * Parse Configuration
	 */

	cfg_opt_t opts_auth[] =
	{
		CFG_STR_LIST(const_cast<char *>("raw"), const_cast<char *>("{}"), CFGF_NONE),
		CFG_STR_LIST(const_cast<char *>("manage"), const_cast<char *>("{}"), CFGF_NONE),
		CFG_STR_LIST(const_cast<char *>("read"), const_cast<char *>("{}"), CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts_crate[] =
	{
		CFG_STR(const_cast<char *>("host"), const_cast<char *>(""), CFGF_NONE),
		CFG_STR(const_cast<char *>("description"), const_cast<char *>(""), CFGF_NONE),
		CFG_STR(const_cast<char *>("username"), const_cast<char *>(""), CFGF_NONE),
		CFG_STR(const_cast<char *>("password"), const_cast<char *>(""), CFGF_NONE),
		CFG_INT_CB(const_cast<char *>("authtype"), 0, CFGF_NONE, cfg_parse_authtype),
		CFG_INT_CB(const_cast<char *>("mch"), 0, CFGF_NONE, cfg_parse_MCH),
		CFG_BOOL(const_cast<char *>("enabled"), cfg_true, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts_cardmodule[] =
	{
		CFG_STR(const_cast<char *>("module"), const_cast<char *>(""), CFGF_NONE),
		CFG_STR_LIST(const_cast<char *>("config"), const_cast<char *>("{}"), CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] =
	{
		CFG_SEC(const_cast<char *>("authentication"), opts_auth, CFGF_NONE),
		CFG_SEC(const_cast<char *>("crate"), opts_crate, CFGF_MULTI),
		CFG_SEC(const_cast<char *>("cardmodule"), opts_cardmodule, CFGF_MULTI),
		CFG_INT(const_cast<char *>("socket_port"), 4681, CFGF_NONE),
		CFG_INT(const_cast<char *>("ratelimit_delay"), 0, CFGF_NONE),
		CFG_BOOL(const_cast<char *>("daemonize"), cfg_false, CFGF_NONE),
		CFG_END()
	};
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);
	cfg_set_validate_func(cfg, "crate|host", &cfg_validate_hostname);
	cfg_set_validate_func(cfg, "socket_port", &cfg_validate_port);

	if (argc >= 2 && access(argv[1], R_OK) == 0) {
		if(cfg_parse(cfg, argv[1]) == CFG_PARSE_ERROR)
			exit(1);
	}
	else if (access(CONFIG_PATH "/" CONFIG_FILE, R_OK) == 0) {
		if(cfg_parse(cfg, CONFIG_PATH "/" CONFIG_FILE) == CFG_PARSE_ERROR)
			exit(1);
	}
	else {
		printf("Config file %s not found, and no argument supplied.\n", CONFIG_PATH "/" CONFIG_FILE);
		printf("Try: %s sysmgr.conf\n", argv[0]);
		exit(1);
	}

	bool crate_found = false;
	bool crate_enabled = false;

	cfg_t *cfgauth = cfg_getsec(cfg, "authentication");
	for(unsigned int i = 0; i < cfg_size(cfgauth, "raw"); i++)
		config_authdata.raw.push_back(std::string(cfg_getnstr(cfgauth, "raw", i)));
	for(unsigned int i = 0; i < cfg_size(cfgauth, "manage"); i++)
		config_authdata.manage.push_back(std::string(cfg_getnstr(cfgauth, "manage", i)));
	for(unsigned int i = 0; i < cfg_size(cfgauth, "read"); i++)
		config_authdata.read.push_back(std::string(cfg_getnstr(cfgauth, "read", i)));

	for(unsigned int i = 0; i < cfg_size(cfg, "crate"); i++) {
		cfg_t *cfgcrate = cfg_getnsec(cfg, "crate", i);
		crate_found = true;

		enum Crate::Mfgr MCH;
		switch (cfg_getint(cfgcrate, "mch")) {
			case Crate::VADATECH: MCH = Crate::VADATECH; break;
			case Crate::NAT: MCH = Crate::NAT; break;
		}

		const char *user = cfg_getstr(cfgcrate, "username");
		const char *pass = cfg_getstr(cfgcrate, "password");

		Crate *crate = new Crate(i+1, MCH, cfg_getstr(cfgcrate, "host"), (user[0] ? user : NULL), (pass[0] ? pass : NULL), cfg_getint(cfgcrate, "authtype"), cfg_getstr(cfgcrate, "description"));

		bool enabled = (cfg_getbool(cfgcrate, "enabled") == cfg_true);
		if (enabled)
			crate_enabled = true;
		threadlocal.push_back(threadlocaldata_t(crate, enabled));
	}

	for(unsigned int i = 0; i < cfg_size(cfg, "cardmodule"); i++) {
		cfg_t *cfgmodule = cfg_getnsec(cfg, "cardmodule", i);

		const char *module = cfg_getstr(cfgmodule, "module");

		std::vector<std::string> configdata;
		for(unsigned int i = 0; i < cfg_size(cfgmodule, "config"); i++)
			configdata.push_back(std::string(cfg_getnstr(cfgmodule, "config", i)));

		std::string default_module_path = DEFAULT_MODULE_PATH;
	   	if (getenv("SYSMGR_MODULE_PATH") != NULL)
			default_module_path = getenv("SYSMGR_MODULE_PATH");

		std::string modulepath = module;
		if (modulepath.find("/") == std::string::npos)
			modulepath = default_module_path +"/"+ modulepath;

		cardmodule_t cm;
		cm.dl_addr = dlopen(modulepath.c_str(), RTLD_NOW|RTLD_GLOBAL);
		if (cm.dl_addr == NULL) {
			printf("Error loading module %s:\n\t%s\n", module, dlerror());
			exit(2);
		}

		void *sym;
#define LOAD_SYM(name, type) \
		sym = dlsym(cm.dl_addr, #name); \
		if (sym == NULL) { \
			mprintf("Error loading module %s " type " " #name ":\n\t%s\n", module, dlerror()); \
			exit(2); \
		}

		LOAD_SYM(APIVER, "variable");
		cm.APIVER = *reinterpret_cast<uint32_t*>(sym);

		LOAD_SYM(MIN_APIVER, "variable");
		cm.MIN_APIVER = *reinterpret_cast<uint32_t*>(sym);

		if (cm.APIVER < 2 || cm.MIN_APIVER > 2) {
			mprintf("Error loading module %s: Incompatible API version %u\n", module, cm.APIVER);
		}

		LOAD_SYM(initialize_module, "function");
		cm.initialize_module = reinterpret_cast<bool (*)(std::vector<std::string>)>(sym);

		LOAD_SYM(instantiate_card, "function");
		cm.instantiate_card = reinterpret_cast<Card* (*)(Crate*, std::string, void*, uint8_t)>(sym);

#undef LOAD_SYM

		if (!cm.initialize_module(configdata)) {
			printf("Error loading module %s: initialize_module() returned false\n", module);
			exit(2);
		}

		card_modules.insert(card_modules.begin(), cm);
	}

	uint16_t port = cfg_getint(cfg, "socket_port");
	config_ratelimit_delay = cfg_getint(cfg, "ratelimit_delay");
	bool daemonize = (cfg_getbool(cfg, "daemonize") == cfg_true);

	cfg_free(cfg);

	if (!crate_found) {
		printf("No crate specified in the configuration file.\n");
		exit(1);
	}
	if (!crate_enabled) {
		printf("No crates are enabled in the configuration file.\n");
		printf("No crates to service.\n");
		exit(1);
	}

	if (daemonize) {
		do_fork();
		stdout_use_syslog = true;
		mprintf("University of Wisconsin IPMI MicroTCA System Manager\n");
	}

	/*
	 * Initialize library crypto routines before spawning threads.
	 * This connect will fail due to hostname too long, after running the crypt init functions.
	 *
	 * Max Hostname Limit: 64
	 */
	ipmi_ctx_t dummy_ipmi_ctx = ipmi_ctx_create();
	if (ipmi_ctx_open_outofband_2_0(dummy_ipmi_ctx,
				".................................................................",			// hostname
				NULL,					// username
				NULL,					// password
				NULL,						// k_g
				0,							// k_g_len,
				4,							// privilege_level
				0,							// cipher_suite_id
				0,							// session_timeout
				5,							// retransmission_timeout
				IPMI_WORKAROUND_FLAGS_OUTOFBAND_2_0_OPEN_SESSION_PRIVILEGE,	// workaround_flags
				IPMI_FLAGS_DEFAULT			// flags
				) == 0) {
		ipmi_ctx_close(dummy_ipmi_ctx);
	}
	ipmi_ctx_destroy(dummy_ipmi_ctx);

	/*
	 * Instantiate Worker Threads
	 */

	for (std::vector<threadlocaldata_t>::iterator it = threadlocal.begin(); it != threadlocal.end(); it++)
		if (it->enabled)
			pthread_create(&it->thread, NULL, crate_monitor, (void *)it->crate->get_number());

#ifndef DEBUG_ONESHOT
	protocol_server(port);
#endif

	for (std::vector<threadlocaldata_t>::iterator it = threadlocal.begin(); it != threadlocal.end(); it++)
		if (it->enabled)
			pthread_join(it->thread, NULL);
}
Example #14
0
bool TryGetSNESDevConfig(const char *fileName, const int argc, char **argv, SNESDevConfig *const config) {
    const Arguments arguments = ParseArguments(argc, argv);

    cfg_opt_t GamepadOpts[] = {
            CFG_BOOL(CFG_ENABLED, cfg_false, CFGF_NONE),
            CFG_INT(CFG_GPIO, 0, CFGF_NONE),
            CFG_END()
    };

    cfg_opt_t GamepadsOpts[] = {
            CFG_SEC(CFG_GAMEPAD, GamepadOpts, CFGF_MULTI | CFGF_TITLE),
            CFG_INT_CB(CFG_GAMEPAD_TYPE, 0, CFGF_NONE, &VerifyGamepadType),
            CFG_INT(CFG_CLOCK_GPIO, 0, CFGF_NONE),
            CFG_INT(CFG_LATCH_GPIO, 0, CFGF_NONE),
            CFG_INT(CFG_POLL_FREQ, 0, CFGF_NONE),
            CFG_END()
    };

    cfg_opt_t ButtonOpts[] = {
            CFG_BOOL(CFG_ENABLED, cfg_false, CFGF_NONE),
            CFG_INT_CB(CFG_KEY, 0, CFGF_NONE, &VerifyInputKey),
            CFG_INT(CFG_GPIO, 0, CFGF_NONE),
            CFG_END()
    };

    cfg_opt_t ButtonsOpts[] = {
            CFG_SEC(CFG_BUTTON, ButtonOpts, CFGF_MULTI | CFGF_TITLE),
            CFG_INT(CFG_POLL_FREQ, 0, CFGF_NONE),
            CFG_END()
    };

    cfg_opt_t opts[] = {
            CFG_SEC(CFG_GAMEPADS, GamepadsOpts, CFGF_NONE),
            CFG_SEC(CFG_BUTTONS, ButtonsOpts, CFGF_NONE),
            CFG_END()
    };

    cfg_t *cfg;
    cfg = cfg_init(opts, CFGF_NOCASE);

    if (access(fileName, F_OK) == -1 || cfg_parse(cfg, fileName) != CFG_SUCCESS) {
        fprintf(stderr, "Cannot read config file %s\n", fileName);
        return false;
    }

    // Initialize from arguments.
    memset(config, 0, sizeof(SNESDevConfig));
    config->RunAsDaemon = !arguments.DebugEnabled && arguments.RunAsDaemon;
    config->DebugEnabled = arguments.DebugEnabled;
    config->Verbose = config->RunAsDaemon ? 0 : arguments.Verbose;

    // PidFile came from argv so will be way down teh stack :-)
    config->PidFile = arguments.PidFile;

    // Parse gamepad section
    GamepadsConfig *gamepadsConfig = &config->Gamepads;
    cfg_t *gamepadsSection = cfg_getsec(cfg, CFG_GAMEPADS);
    gamepadsConfig->ClockGpio = (uint8_t) SafeToUnsigned(cfg_getint(gamepadsSection, CFG_CLOCK_GPIO));
    gamepadsConfig->LatchGpio = (uint8_t) SafeToUnsigned(cfg_getint(gamepadsSection, CFG_LATCH_GPIO));

    unsigned int pollFrequency = SafeToUnsigned(cfg_getint(gamepadsSection, CFG_POLL_FREQ));
    if(pollFrequency > 0) {
        gamepadsConfig->PollFrequency = (unsigned int)(1000 / (double)pollFrequency);
    }
    gamepadsConfig->Type = (GamepadType)cfg_getint(gamepadsSection, CFG_GAMEPAD_TYPE);
    unsigned int numberOfGamepads = cfg_size(gamepadsSection, CFG_GAMEPAD);

    // Parse gamepads
    // TODO: Sort by gamepad id.
    for(unsigned int i = 0; i < numberOfGamepads; i++) {
        cfg_t *gamepadSection = cfg_getnsec(gamepadsSection, CFG_GAMEPAD, i);

        bool enabled = cfg_getbool(gamepadSection, CFG_ENABLED) ? true : false;
        if(!enabled) {
            continue;
        }

        GamepadConfig *gamepadConfig = gamepadsConfig->Gamepads + gamepadsConfig->Total;
        gamepadConfig->Id = (unsigned int) atoi(cfg_title(gamepadSection));
        gamepadConfig->DataGpio = (uint8_t) SafeToUnsigned(cfg_getint(gamepadSection, CFG_GPIO));
        gamepadsConfig->Total++;

        if(gamepadsConfig->Total > SNESDEV_MAX_GAMEPADS) {
            break;
        }
    }

    // Parse buttons section.
    ButtonsConfig *buttonsConfig = &config->Buttons;
    cfg_t *buttonsSection = cfg_getsec(cfg, CFG_BUTTONS);
    pollFrequency = SafeToUnsigned(cfg_getint(buttonsSection, CFG_POLL_FREQ));
    if(pollFrequency > 0) {
        buttonsConfig->PollFrequency = (unsigned int) (1000 / (double)pollFrequency);
    }
    unsigned int numberOfButtons = cfg_size(buttonsSection, CFG_BUTTON);

    // Parse buttons
    // TODO: Sort by button id.
    for (unsigned int i = 0; i < numberOfButtons; i++) {
        cfg_t *buttonSection = cfg_getnsec(buttonsSection, CFG_BUTTON, i);

        bool enabled = cfg_getbool(buttonSection, CFG_ENABLED) ? true : false;
        if(!enabled) {
            continue;
        }

        ButtonConfig *buttonConfig = buttonsConfig->Buttons + buttonsConfig->Total;
        buttonConfig->Id = (unsigned int) atoi(cfg_title(buttonSection));
        buttonConfig->Key = (InputKey) cfg_getint(buttonSection, CFG_KEY);
        buttonConfig->DataGpio = (uint8_t) SafeToUnsigned(cfg_getint(buttonSection, CFG_GPIO));
        buttonsConfig->Total++;

        if(buttonsConfig->Total > SNESDEV_MAX_BUTTONS) {
            break;
        }
    }

    cfg_free(cfg);

    if(!ValidateConfig(config)) {
        return false;
    }

    return true;
}
Example #15
0
/* Forward */
static int cb_loglevel(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);

/* general section structure */
static cfg_opt_t sec_general[] =
  {
    CFG_STR("uid", "nobody", CFGF_NONE),
    CFG_STR("admin_password", NULL, CFGF_NONE),
    CFG_STR("logfile", STATEDIR "/log/" PACKAGE ".log", CFGF_NONE),
    CFG_STR("db_path", STATEDIR "/cache/" PACKAGE "/songs3.db", CFGF_NONE),
    CFG_INT("db_pragma_cache_size", -1, CFGF_NONE),
    CFG_STR("db_pragma_journal_mode", NULL, CFGF_NONE),
    CFG_INT("db_pragma_synchronous", -1, CFGF_NONE),
    CFG_INT_CB("loglevel", E_LOG, CFGF_NONE, &cb_loglevel),
    CFG_BOOL("ipv6", cfg_false, CFGF_NONE),
    CFG_STR("cache_path", STATEDIR "/cache/" PACKAGE "/cache.db", CFGF_NONE),
    CFG_INT("cache_daap_threshold", 1000, CFGF_NONE),
    CFG_END()
  };

/* library section structure */
static cfg_opt_t sec_library[] =
  {
    CFG_STR("name", "My Music on %h", CFGF_NONE),
    CFG_INT("port", 3689, CFGF_NONE),
    CFG_STR("password", NULL, CFGF_NONE),
    CFG_STR_LIST("directories", NULL, CFGF_NONE),
    CFG_STR_LIST("podcasts", NULL, CFGF_NONE),
    CFG_STR_LIST("audiobooks", NULL, CFGF_NONE),
    CFG_STR_LIST("compilations", NULL, CFGF_NONE),
Example #16
0
File: cfg.c Project: Bagarre/RProxy
#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),
    CFG_INT("context-timeout",    172800,          CFGF_NONE),
    CFG_BOOL("cache-enabled",     cfg_true,        CFGF_NONE),
    CFG_INT("cache-timeout",      1024,            CFGF_NONE),
    CFG_INT("cache-size",         65535,           CFGF_NONE),
    CFG_SEC("crl",                ssl_crl_opts,    CFGF_NODEFAULT),
Example #17
0
//	Author: PCMan (HZY) 2004/07/22	07:51 AM
//	I finally came up with a really smart way to maintain ini file.
//	Every time I add a variable to CAppConfig, all I need to do is
//	adding the variable in my "Config Table," and all the data will
//	be load and save automatically.  This is not the most efficient way.
//	In my first version I use some more efficient method, but at last I change
//	my code to what it is now.  Because I think in a program not time-critical,
//	easy-maintaining is much more important.
bool CAppConfig::DoDataExchange(bool bLoad)
{
	BEGIN_CONFIG_SECT(Window)
		CFG_INT( MainWndX )
		CFG_INT( MainWndY )
		CFG_INT( MainWndW )
		CFG_INT( MainWndH )
/*		CFG_INT( EditorX )
		CFG_INT( EditorY )
		CFG_INT( EditorW )
		CFG_INT( EditorH )
*/
	END_CONFIG_SECT()

	BEGIN_CONFIG_SECT(General)
//		CFG_STR ( Shadow )
		CFG_BOOL( QueryOnExit)
		CFG_BOOL( QueryOnCloseCon)
		CFG_BOOL( CancelSelAfterCopy)
		CFG_BOOL( CopyTrimTail)
		CFG_BOOL( BeepOnBell )
#ifdef USE_MOUSE
		CFG_BOOL( MouseSupport )
#endif
#ifdef USE_DOCKLET
		CFG_BOOL( ShowTrayIcon )
#endif
		CFG_BOOL( ShowStatusBar )
#ifdef USE_WGET
		CFG_BOOL( UseWgetFiles )
#endif
		CFG_STR ( WebBrowser )
		CFG_STR ( MailClient )
		CFG_BOOL( PopupNotifier )
		CFG_INT ( PopupTimeout )
		CFG_BOOL ( MidClickAsClose )
	END_CONFIG_SECT()

	BEGIN_CONFIG_SECT(Display)
		CFG_STR ( FontFamily )
		CFG_INT ( FontSize )
		CFG_STR ( FontFamilyEn )
		CFG_INT ( FontSizeEn )
		CFG_BOOL( AntiAliasFont )
		CFG_BOOL( CompactLayout )
		_CFG_BOOL ( "HorizontalCenterAlign", m_DefaultSite.m_bHorizontalCenterAlign )
		_CFG_BOOL ( "VerticalCenterAlign", m_DefaultSite.m_bVerticalCenterAlign )
		CFG_INT ( CharPaddingX)
		CFG_INT ( CharPaddingY)
	END_CONFIG_SECT()

	BEGIN_CONFIG_SECT(Color)
		_CFG_CLR( "Black", CTermCharAttr::m_DefaultColorTable[0] )
		_CFG_CLR( "DarkRed", CTermCharAttr::m_DefaultColorTable[1] )
		_CFG_CLR( "DarkGreen", CTermCharAttr::m_DefaultColorTable[2] )
		_CFG_CLR( "Brown", CTermCharAttr::m_DefaultColorTable[3] )
		_CFG_CLR( "DarkBlue", CTermCharAttr::m_DefaultColorTable[4] )
		_CFG_CLR( "DarkMagenta", CTermCharAttr::m_DefaultColorTable[5] )
		_CFG_CLR( "DarkCyan", CTermCharAttr::m_DefaultColorTable[6] )
		_CFG_CLR( "LightGray", CTermCharAttr::m_DefaultColorTable[7] )
		_CFG_CLR( "Gray", CTermCharAttr::m_DefaultColorTable[8] )
		_CFG_CLR( "Red", CTermCharAttr::m_DefaultColorTable[9] )
		_CFG_CLR( "Green", CTermCharAttr::m_DefaultColorTable[10] )
		_CFG_CLR( "Yellow", CTermCharAttr::m_DefaultColorTable[11] )
		_CFG_CLR( "Blue", CTermCharAttr::m_DefaultColorTable[12] )
		_CFG_CLR( "Magenta", CTermCharAttr::m_DefaultColorTable[13] )
		_CFG_CLR( "Cyan", CTermCharAttr::m_DefaultColorTable[14] )
		_CFG_CLR( "White", CTermCharAttr::m_DefaultColorTable[15] )
		CFG_CLR( HyperLinkColor )
	END_CONFIG_SECT()

	BEGIN_CONFIG_SECT(Site)
		_CFG_INT ( "AutoReconnect", m_DefaultSite.m_AutoReconnect )
		_CFG_INT ( "AntiIdle", m_DefaultSite.m_AntiIdle )
		_CFG_STR ( "AntiIdleStr", m_DefaultSite.m_AntiIdleStr )
		_CFG_INT ( "Cols", m_DefaultSite.m_ColsPerPage )
		_CFG_INT ( "Rows", m_DefaultSite.m_RowsPerPage )
		_CFG_STR ( "TermType", m_DefaultSite.m_TermType )
		_CFG_STR ( "Encoding", m_DefaultSite.m_Encoding )
		_CFG_INT ( "CRLF", m_DefaultSite.m_CRLF )
		_CFG_STR ( "ESCConv", m_DefaultSite.m_ESCConv )
		_CFG_INT ( "DetectDBChar", m_DefaultSite.m_DetectDBChar )
#ifdef USE_EXTERNAL
		_CFG_BOOL ( "UseExternalSSH",
			m_DefaultSite.m_UseExternalSSH )
		_CFG_BOOL ( "UseExternalTelnet",
			m_DefaultSite.m_UseExternalTelnet )
#endif
		CFG_INT  ( SocketTimeout )
#ifdef USE_PROXY
		_CFG_INT ( "ProxyType", m_DefaultSite.m_ProxyType )
		_CFG_STR ( "ProxyAddr", m_DefaultSite.m_ProxyAddr )
		_CFG_STR ( "ProxyPort", m_DefaultSite.m_ProxyPort )
		_CFG_STR ( "ProxyUser", m_DefaultSite.m_ProxyUser )
		_CFG_STR ( "ProxyPass", m_DefaultSite.m_ProxyPass )
#endif
	END_CONFIG_SECT()

	BEGIN_CONFIG_FILE( ConfigFile )
		CFG_SECT( Window )
		CFG_SECT( General )
		CFG_SECT( Display )
		CFG_SECT( Color )
		CFG_SECT( Site )
	END_CONFIG_FILE()

	SetRoot(ConfigFile);

	bool ret = CConfigFile::DoDataExchange(bLoad);

	if( bLoad )
		AfterLoad();

	return ret;
}
Example #18
0
int init_ac_cfgd_config(char *conf_path, struct ac_cfgd_config_t *config)
{
    int ret;

    cfg_opt_t opts[] = {
        CFG_BOOL("background", cfg_false, CFGF_NONE),
        CFG_BOOL("debug_mode", cfg_false, CFGF_NONE),

        CFG_STR("svc_name", SVC_TEST_NAME, CFGF_NONE),
        CFG_INT("svc_gameid", SVC_TEST_GAMEID, CFGF_NONE),
        CFG_STR("cc_ip", "localhost", CFGF_NONE),
        CFG_INT("cc_port", 3306, CFGF_NONE),

        CFG_STR("cc_my_user", "root", CFGF_NONE),
        CFG_STR("cc_my_passwd", "ta0mee", CFGF_NONE),
        CFG_STR("cc_my_dbname", "anticheat", CFGF_NONE),
        CFG_STR("cc_my_tw_tab_basename", "tw_config", CFGF_NONE),
        CFG_STR("cc_my_sw_tab_basename", "sw_config", CFGF_NONE),

        CFG_END()
    };

    cfg_t *cfg = cfg_init(opts, CFGF_NONE);
    ret = cfg_parse(cfg, conf_path ? conf_path : DEF_CFG_PATH);
    if(ret == CFG_FILE_ERROR) {
        DP("Access error, conf: %s, err: %s",
           conf_path ? conf_path : DEF_CFG_PATH, strerror(errno));
        return -1;
    } else if(ret == CFG_PARSE_ERROR) {
        DP("Parse error, conf: %s", conf_path ? conf_path : DEF_CFG_PATH);
        return -1;
    }

    memset(config, 0, sizeof(*config));

    config->background = cfg_getbool(cfg, "background");
    config->debug_mode = cfg_getbool(cfg, "debug_mode");
    snprintf(config->svc_name, sizeof(config->svc_name), "%s", cfg_getstr(cfg, "svc_name"));
    config->svc_gameid = cfg_getint(cfg, "svc_gameid");
    snprintf(config->cc_ip, sizeof(config->cc_ip), "%s", cfg_getstr(cfg, "cc_ip"));
    config->cc_port = cfg_getint(cfg, "cc_port");

    snprintf(config->cc_my_user, sizeof(config->cc_my_user),
             "%s", cfg_getstr(cfg, "cc_my_user"));
    snprintf(config->cc_my_passwd, sizeof(config->cc_my_passwd),
             "%s", cfg_getstr(cfg, "cc_my_passwd"));
    snprintf(config->cc_my_dbname, sizeof(config->cc_my_dbname),
             "%s", cfg_getstr(cfg, "cc_my_dbname"));
    snprintf(config->cc_my_tw_tab_basename, sizeof(config->cc_my_tw_tab_basename),
             "%s", cfg_getstr(cfg, "cc_my_tw_tab_basename"));
    snprintf(config->cc_my_sw_tab_basename, sizeof(config->cc_my_sw_tab_basename),
             "%s", cfg_getstr(cfg, "cc_my_sw_tab_basename"));

    if (config->svc_gameid > MAX_SVC_GAMEID) {
        DP("Invalid svc_gameid: %u for svc: %s", config->svc_gameid, config->svc_name);
        return -1;
    }


    cfg_free(cfg);

    return 0;
}
Example #19
0
int handle_lispd_config_file()
{
    cfg_t           *cfg   = 0;
    unsigned int    i      = 0;
    unsigned        n      = 0;
    int             ret    = 0;

    static cfg_opt_t map_server_opts[] = {
    CFG_STR("address",      0, CFGF_NONE),
    CFG_INT("key-type",     0, CFGF_NONE),
    CFG_STR("key",          0, CFGF_NONE),
    CFG_BOOL("proxy-reply", cfg_false, CFGF_NONE),
    CFG_BOOL("verify",      cfg_false, CFGF_NONE),
    CFG_END()
    };

    static cfg_opt_t db_mapping_opts[] = {
        CFG_STR("eid-prefix",           0, CFGF_NONE),
        CFG_INT("iid",                  -1, CFGF_NONE),
        CFG_STR("interface",            0, CFGF_NONE),
        CFG_INT("priority_v4",          0, CFGF_NONE),
        CFG_INT("weight_v4",            0, CFGF_NONE),
        CFG_INT("priority_v6",          0, CFGF_NONE),
        CFG_INT("weight_v6",            0, CFGF_NONE),
        CFG_END()
    };

    static cfg_opt_t mc_mapping_opts[] = {
        CFG_STR("eid-prefix",           0, CFGF_NONE),
        CFG_INT("iid",                  0, CFGF_NONE),
        CFG_STR("rloc",                 0, CFGF_NONE),
        CFG_INT("priority",             0, CFGF_NONE),
        CFG_INT("weight",               0, CFGF_NONE),
        CFG_END()
    };

    static cfg_opt_t petr_mapping_opts[] = {
            CFG_STR("address",              0, CFGF_NONE),
            CFG_INT("priority",           255, CFGF_NONE),
            CFG_INT("weight",               0, CFGF_NONE),
            CFG_END()
    };

    cfg_opt_t opts[] = {
        CFG_SEC("database-mapping",     db_mapping_opts, CFGF_MULTI),
        CFG_SEC("static-map-cache",     mc_mapping_opts, CFGF_MULTI),
        CFG_SEC("map-server",           map_server_opts, CFGF_MULTI),
        CFG_SEC("proxy-etr",            petr_mapping_opts, CFGF_MULTI),
        CFG_INT("map-request-retries",  0, CFGF_NONE),
        CFG_INT("control-port",         0, CFGF_NONE),
        CFG_BOOL("debug",               cfg_false, CFGF_NONE),
        CFG_STR("map-resolver",         0, CFGF_NONE),
        CFG_STR_LIST("proxy-itrs",      0, CFGF_NONE),
        CFG_END()
    };

    /*
     *  parse config_file
     */

    cfg = cfg_init(opts, CFGF_NOCASE);
    ret = cfg_parse(cfg, config_file);

    if (ret == CFG_FILE_ERROR) {
        syslog(LOG_DAEMON, "Couldn't find config file %s, exiting...", config_file);
        exit(EXIT_FAILURE);
    } else if(ret == CFG_PARSE_ERROR) {
        syslog(LOG_DAEMON, "NOTE: Version 0.2.4 changed the format of the 'proxy-etr' element.");
        syslog(LOG_DAEMON, "      Check the 'lispd.conf.example' file for an example entry in");
        syslog(LOG_DAEMON, "      the new format.");
        syslog(LOG_DAEMON, "Parse error in file %s, exiting...", config_file);
        exit(EXIT_FAILURE);
    }

    
    /*
     *  lispd config options
     */

    ret = cfg_getint(cfg, "map-request-retries");
    if (ret != 0)
        map_request_retries = ret;

    cfg_getbool(cfg, "debug") ? (debug = 1) : (debug = 0); 

    /*
     *  LISP config options
     */

    /*
     *  handle map-resolver config
     */

    map_resolver = cfg_getstr(cfg, "map-resolver");
    if (!add_server(map_resolver, &map_resolvers))
        return(0); 
#ifdef DEBUG
    syslog(LOG_DAEMON, "Added %s to map-resolver list", map_resolver);
#endif

    /*
     *  handle proxy-etr config
     */


    n = cfg_size(cfg, "proxy-etr");
    for(i = 0; i < n; i++) {
        cfg_t *petr = cfg_getnsec(cfg, "proxy-etr", i);
        if (!add_proxy_etr_entry(petr, &proxy_etrs)) {
            syslog(LOG_DAEMON, "Can't add proxy-etr %d (%s)", i, cfg_getstr(petr, "address"));
        }
    }

    if (!proxy_etrs){
        syslog(LOG_DAEMON, "WARNING: No Proxy-ETR defined. Packets to non-LISP destinations will be forwarded natively (no LISP encapsulation). This may prevent mobility in some scenarios.");
        sleep(3);
    }

    /*
     *  handle proxy-itr config
     */

    n = cfg_size(cfg, "proxy-itrs");
    for(i = 0; i < n; i++) {
        if ((proxy_itr = cfg_getnstr(cfg, "proxy-itrs", i)) != NULL) {
            if (!add_server(proxy_itr, &proxy_itrs))
                continue;
#ifdef DEBUG
            syslog(LOG_DAEMON, "Added %s to proxy-itr list", proxy_itr);
#endif
        }
    }

    /*
     *  handle database-mapping config
     */

    n = cfg_size(cfg, "database-mapping");
    for(i = 0; i < n; i++) {
        cfg_t *dm = cfg_getnsec(cfg, "database-mapping", i);
        if (!add_database_mapping(dm)) {
            syslog(LOG_DAEMON, "Can't add database-mapping %d (%s->%s)",
               i,
               cfg_getstr(dm, "eid-prefix"),
               cfg_getstr(dm, "interface"));
        }
    }

    /*
     *  handle map-server config
     */

    n = cfg_size(cfg, "map-server");
    for(i = 0; i < n; i++) {
        cfg_t *ms = cfg_getnsec(cfg, "map-server", i);
        if (!add_map_server(cfg_getstr(ms, "address"),
                                cfg_getint(ms, "key-type"),
                cfg_getstr(ms, "key"),
                (cfg_getbool(ms, "proxy-reply") ? 1:0),
                (cfg_getbool(ms, "verify")      ? 1:0)))

            return(0);
#ifdef DEBUG
        syslog(LOG_DAEMON, "Added %s to map-server list",
            cfg_getstr(ms, "address"));
#endif
    }

    /*
     *  handle static-map-cache config
     */

    n = cfg_size(cfg, "static-map-cache");
    for(i = 0; i < n; i++) {
        cfg_t *smc = cfg_getnsec(cfg, "static-map-cache", i);
            if (!add_static_map_cache_entry(smc)) {
        syslog(LOG_DAEMON,"Can't add static-map-cache %d (EID:%s -> RLOC:%s)",
               i,
               cfg_getstr(smc, "eid-prefix"),
               cfg_getstr(smc, "rloc"));
        }
    }


#if (DEBUG > 3)
    dump_tree(AF_INET,AF4_database);
    dump_tree(AF_INET6,AF6_database);
    dump_database();
    dump_map_servers();
    dump_servers(map_resolvers, "map-resolvers");
    dump_servers(proxy_etrs, "proxy-etrs");
    dump_servers(proxy_itrs, "proxy-itrs");
    dump_map_cache();
#endif

    cfg_free(cfg);
    return(0);
}
Example #20
0
static cfg_opt_t cluster_opts[] = {
  CFG_STR("name", "unspecified", CFGF_NONE ),
  CFG_STR("owner", "unspecified", CFGF_NONE ),
  CFG_STR("latlong", "unspecified", CFGF_NONE ),
  CFG_STR("url", "unspecified", CFGF_NONE ),
  CFG_END()
};

static cfg_opt_t host_opts[] = {
  CFG_STR("location", "unspecified", CFGF_NONE ),
  CFG_END()
};

static cfg_opt_t globals_opts[] = {
  CFG_BOOL("daemonize", 1, CFGF_NONE),
  CFG_BOOL("setuid", 1 - NO_SETUID, CFGF_NONE),
  CFG_STR("user", SETUID_USER, CFGF_NONE),
  /* later i guess we should add "group" as well */
  CFG_INT("debug_level", 0, CFGF_NONE),
  CFG_INT("max_udp_msg_len", 1472, CFGF_NONE),
  CFG_BOOL("mute", 0, CFGF_NONE),
  CFG_BOOL("deaf", 0, CFGF_NONE),
  CFG_BOOL("allow_extra_data", 1, CFGF_NONE),
  CFG_INT("host_dmax", 86400, CFGF_NONE),
  CFG_INT("host_tmax", 20, CFGF_NONE),
  CFG_INT("cleanup_threshold", 300, CFGF_NONE),
  CFG_BOOL("gexec", 0, CFGF_NONE),
  CFG_INT("send_metadata_interval", 0, CFGF_NONE),
  CFG_STR("module_dir", NULL, CFGF_NONE),
  CFG_STR("override_hostname", NULL, CFGF_NONE),
Example #21
0
File: initend.c Project: xdave/xbps
int
xbps_init(struct xbps_handle *xhp)
{
    cfg_opt_t vpkg_opts[] = {
        CFG_STR_LIST(__UNCONST("targets"), NULL, CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t opts[] = {
        /* Defaults if not set in configuration file */
        CFG_STR(__UNCONST("rootdir"), __UNCONST("/"), CFGF_NONE),
        CFG_STR(__UNCONST("cachedir"),
        __UNCONST(XBPS_CACHE_PATH), CFGF_NONE),
        CFG_INT(__UNCONST("FetchCacheConnections"),
        XBPS_FETCH_CACHECONN, CFGF_NONE),
        CFG_INT(__UNCONST("FetchCacheConnectionsPerHost"),
        XBPS_FETCH_CACHECONN_HOST, CFGF_NONE),
        CFG_INT(__UNCONST("FetchTimeoutConnection"),
        XBPS_FETCH_TIMEOUT, CFGF_NONE),
        CFG_INT(__UNCONST("TransactionFrequencyFlush"),
        XBPS_TRANS_FLUSH, CFGF_NONE),
        CFG_BOOL(__UNCONST("syslog"), true, CFGF_NONE),
        CFG_STR_LIST(__UNCONST("repositories"), NULL, CFGF_MULTI),
        CFG_STR_LIST(__UNCONST("PackagesOnHold"), NULL, CFGF_MULTI),
        CFG_SEC(__UNCONST("virtual-package"),
        vpkg_opts, CFGF_MULTI|CFGF_TITLE),
        CFG_FUNC(__UNCONST("include"), &cfg_include),
        CFG_END()
    };
    struct utsname un;
    int rv, cc, cch;
    bool syslog_enabled = false;

    assert(xhp != NULL);

    if (xhp->initialized)
        return 0;

    if (xhp->conffile == NULL)
        xhp->conffile = XBPS_CONF_DEF;

    /* parse configuration file */
    xhp->cfg = cfg_init(opts, CFGF_NOCASE);
    cfg_set_validate_func(xhp->cfg, "virtual-package", &cb_validate_virtual);

    if ((rv = cfg_parse(xhp->cfg, xhp->conffile)) != CFG_SUCCESS) {
        if (rv == CFG_FILE_ERROR) {
            /*
             * Don't error out if config file not found.
             * If a default repository is set, use it; otherwise
             * use defaults (no repos and no virtual packages).
             */
            if (errno != ENOENT)
                return rv;

            xhp->conffile = NULL;
            if (xhp->repository) {
                char *buf;

                buf = xbps_xasprintf("repositories = { %s }",
                                     xhp->repository);
                assert(buf);
                if ((rv = cfg_parse_buf(xhp->cfg, buf)) != 0)
                    return rv;
                free(buf);
            }
        } else if (rv == CFG_PARSE_ERROR) {
            /*
             * Parser error from configuration file.
             */
            return ENOTSUP;
        }
    }
    xbps_dbg_printf(xhp, "Configuration file: %s\n",
                    xhp->conffile ? xhp->conffile : "not found");
    /*
     * Respect client setting in struct xbps_handle for {root,cache}dir;
     * otherwise use values from configuration file or defaults if unset.
     */
    if (xhp->rootdir == NULL) {
        if (xhp->cfg == NULL)
            xhp->rootdir = "/";
        else
            xhp->rootdir = cfg_getstr(xhp->cfg, "rootdir");
    }
    if (xhp->cachedir == NULL) {
        if (xhp->cfg == NULL)
            xhp->cachedir = XBPS_CACHE_PATH;
        else
            xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir");
    }
    if ((xhp->cachedir_priv = set_cachedir(xhp)) == NULL)
        return ENOMEM;
    xhp->cachedir = xhp->cachedir_priv;

    if ((xhp->metadir_priv = set_metadir(xhp)) == NULL)
        return ENOMEM;
    xhp->metadir = xhp->metadir_priv;

    uname(&un);
    xhp->un_machine = strdup(un.machine);
    assert(xhp->un_machine);

    if (xhp->cfg == NULL) {
        xhp->flags |= XBPS_FLAG_SYSLOG;
        xhp->fetch_timeout = XBPS_FETCH_TIMEOUT;
        xhp->transaction_frequency_flush = XBPS_TRANS_FLUSH;
        cc = XBPS_FETCH_CACHECONN;
        cch = XBPS_FETCH_CACHECONN_HOST;
    } else {
        if (cfg_getbool(xhp->cfg, "syslog"))
            xhp->flags |= XBPS_FLAG_SYSLOG;
        xhp->fetch_timeout = cfg_getint(xhp->cfg, "FetchTimeoutConnection");
        cc = cfg_getint(xhp->cfg, "FetchCacheConnections");
        cch = cfg_getint(xhp->cfg, "FetchCacheConnectionsPerHost");
        xhp->transaction_frequency_flush =
            cfg_getint(xhp->cfg, "TransactionFrequencyFlush");
    }
    if (xhp->flags & XBPS_FLAG_SYSLOG)
        syslog_enabled = true;

    xbps_fetch_set_cache_connection(cc, cch);

    xbps_dbg_printf(xhp, "Rootdir=%s\n", xhp->rootdir);
    xbps_dbg_printf(xhp, "Metadir=%s\n", xhp->metadir);
    xbps_dbg_printf(xhp, "Cachedir=%s\n", xhp->cachedir);
    xbps_dbg_printf(xhp, "FetchTimeout=%u\n", xhp->fetch_timeout);
    xbps_dbg_printf(xhp, "FetchCacheconn=%u\n", cc);
    xbps_dbg_printf(xhp, "FetchCacheconnHost=%u\n", cch);
    xbps_dbg_printf(xhp, "Syslog=%u\n", syslog_enabled);
    xbps_dbg_printf(xhp, "TransactionFrequencyFlush=%u\n",
                    xhp->transaction_frequency_flush);
    xbps_dbg_printf(xhp, "Architecture: %s\n", xhp->un_machine);

    xhp->initialized = true;

    return 0;
}
Example #22
0
int main(int argc, char **argv)
{
	//Check if user == root
	if(geteuid() != 0)
	{
	  puts("Please run this software as root!");
	  exit(EXIT_FAILURE);
	}

	// check for non-daemon mode for debugging
	for(int i = 1; i < argc; i++) {
		if (str_is(argv[i], "nodaemon")) {
			start_daemon = 0;
			break;
		}
	}

	if (start_daemon) {
		//Init daemon, can be replaced with daemon() call
		pid_t pid;

		pid = fork();
		if (pid < 0)
		{
			exit(EXIT_FAILURE);
		}
		if (pid > 0)
		{
			exit(EXIT_SUCCESS);
		}

		umask(0);

		//We are now running as the forked child process.
		openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER);

		pid_t sid;
		sid = setsid();
		if (sid < 0)
		{
			syslog(LOG_ERR, "Could not create process group\n");
			exit(EXIT_FAILURE);
		}

		if ((chdir("/")) < 0)
		{
			syslog(LOG_ERR, "Could not change working directory to /\n");
			exit(EXIT_FAILURE);
		}
	}
	else {
		// open syslog for non-daemon mode
		openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER);
	}

	//Read configuration file
	cfg_opt_t opts[] =
	{
		CFG_INT("i2cbus", 1, CFGF_NONE),
		CFG_INT("frequency", 99800, CFGF_NONE),
		CFG_BOOL("stereo", 1, CFGF_NONE),
		CFG_BOOL("rdsenable", 1, CFGF_NONE),
		CFG_BOOL("poweron", 1, CFGF_NONE),
		CFG_BOOL("tcpbindlocal", 1, CFGF_NONE),
		CFG_INT("tcpport", 42516, CFGF_NONE),
		CFG_INT("txpower", 3, CFGF_NONE),
		CFG_BOOL("gain", 0, CFGF_NONE),
		CFG_INT("volume", 3, CFGF_NONE),
		CFG_INT("rdspin", 17, CFGF_NONE),
		CFG_STR("rdsid", "", CFGF_NONE),
		CFG_STR("rdstext", "", CFGF_NONE),
		CFG_INT("ledpin", 27, CFGF_NONE),
		CFG_END()
	};

	cfg = cfg_init(opts, CFGF_NONE);
	if (cfg_parse(cfg, "/etc/fmberry.conf") == CFG_PARSE_ERROR)
		return 1;

	// get LED pin number
	int led = 1; // led state
	ledpin = cfg_getint(cfg, "ledpin");
	rdsint = cfg_getint(cfg, "rdspin");

	// Init I2C bus and transmitter with initial frequency and state
	if (ns741_init(cfg_getint(cfg, "i2cbus"), cfg_getint(cfg, "frequency")) == -1)
	{
		syslog(LOG_ERR, "Init failed! Double-check hardware and try again!\n");
		exit(EXIT_FAILURE);
	}
	syslog(LOG_NOTICE, "Successfully initialized ns741 transmitter.\n");

	int nfds;
	struct pollfd  polls[2];

	// open TCP listener socket, will exit() in case of error
	int lst = ListenTCP(cfg_getint(cfg, "tcpport"));
	polls[0].fd = lst;
	polls[0].events = POLLIN;
	nfds = 1;

	// initialize data structure for 'status' command
	bzero(&mmr70, sizeof(mmr70));
	mmr70.frequency = cfg_getint(cfg, "frequency");
	mmr70.power     = cfg_getbool(cfg, "poweron");
	mmr70.txpower   = cfg_getint(cfg, "txpower");
	mmr70.mute      = 0;
	mmr70.gain      = cfg_getbool(cfg, "gain");
	mmr70.volume    = cfg_getint(cfg, "volume");
	mmr70.stereo    = cfg_getbool(cfg, "stereo");
	mmr70.rds       = cfg_getbool(cfg, "rdsenable");
	strncpy(mmr70.rdsid, cfg_getstr(cfg, "rdsid"), 8);
	strncpy(mmr70.rdstext, cfg_getstr(cfg, "rdstext"), 64);

	// apply configuration parameters
	ns741_txpwr(mmr70.txpower);
	ns741_mute(mmr70.mute);
	ns741_stereo(mmr70.stereo);
	ns741_rds_set_progname(mmr70.rdsid);
	ns741_rds_set_radiotext(mmr70.rdstext);
	ns741_power(mmr70.power);
	ns741_input_gain(mmr70.gain);
    ns741_volume(mmr70.volume);
	// Use RPI_REV1 for earlier versions of Raspberry Pi
	rpi_pin_init(RPI_REVISION);

	// Get file descriptor for RDS handler
	polls[1].revents = 0;
	if (mmr70.rds)
	{
		int rds = rpi_pin_poll_enable(rdsint, EDGE_FALLING);
	    if (rds < 0) {
	        printf("Couldn't enable RDS support\n");
	        run = 0;
	    }
		polls[1].fd = rds;
		polls[1].events = POLLPRI;
		nfds = 2;
		if (ledpin > 0) {
			rpi_pin_export(ledpin, RPI_OUTPUT);
			rpi_pin_set(ledpin, led);
		}

		ns741_rds(1);
		ns741_rds_isr(); // send first two bytes
	}

	// main polling loop
	int ledcounter = 0;
	while(run) {
		if (poll(polls, nfds, -1) < 0)
			break;

		if (polls[1].revents) {
			rpi_pin_poll_clear(polls[1].fd);
			ns741_rds_isr();
			// flash LED if enabled on every other RDS refresh cycle
			if (ledpin > 0) {
				ledcounter++;
				if (!(ledcounter % 80)) {
					led ^= 1;
					rpi_pin_set(ledpin, led);
				}
			}
		}

		if (polls[0].revents)
			ProcessTCP(lst, &mmr70);
	}

	// clean up at exit
	ns741_power(0);
	if (mmr70.rds)
		rpi_pin_unexport(rdsint);

	if (ledpin > 0) {
		rpi_pin_set(ledpin, 0);
		rpi_pin_unexport(ledpin);
	}

	close(lst);
	closelog();

	return 0;
}
Example #23
0
File: conf.c Project: noushi/bmon
 */

#include <bmon/bmon.h>
#include <bmon/conf.h>
#include <bmon/unit.h>
#include <bmon/attr.h>
#include <bmon/element.h>
#include <bmon/element_cfg.h>
#include <bmon/history.h>
#include <bmon/utils.h>

cfg_t *cfg;

static cfg_opt_t element_opts[] = {
	CFG_STR("description", NULL, CFGF_NONE),
	CFG_BOOL("show", cfg_true, CFGF_NONE),
	CFG_INT("rxmax", 0, CFGF_NONE),
	CFG_INT("txmax", 0, CFGF_NONE),
	CFG_INT("max", 0, CFGF_NONE),
	CFG_END()
};

static cfg_opt_t history_opts[] = {
	CFG_FLOAT("interval", 1.0f, CFGF_NONE),
	CFG_INT("size", 60, CFGF_NONE),
	CFG_STR("type", "64bit", CFGF_NONE),
	CFG_END()
};

static cfg_opt_t attr_opts[] = {
	CFG_STR("description", "", CFGF_NONE),
Example #24
0
   CFG_INT(ITEM_FONT_CY,     0,           CFGF_NONE),
   CFG_INT(ITEM_FONT_SPACE,  0,           CFGF_NONE),
   CFG_INT(ITEM_FONT_DW,     0,           CFGF_NONE),
   CFG_INT(ITEM_FONT_ABSH,   0,           CFGF_NONE),
   CFG_INT(ITEM_FONT_CW,     0,           CFGF_NONE),
   CFG_STR(ITEM_FONT_LFMT,   "linear",    CFGF_NONE),
   CFG_STR(ITEM_FONT_LLUMP,  "",          CFGF_NONE),
   CFG_INT(ITEM_FONT_POFFS,  0,           CFGF_NONE),
   CFG_SEC(ITEM_FONT_FILTER, filter_opts, CFGF_MULTI|CFGF_NOCASE),
   CFG_SEC(ITEM_FONT_COLORS, color_opts,  CFGF_NOCASE),
   CFG_STR(ITEM_FONT_COLORD, "",          CFGF_NONE),
   CFG_STR(ITEM_FONT_COLORN, "",          CFGF_NONE),
   CFG_STR(ITEM_FONT_COLORH, "",          CFGF_NONE),
   CFG_STR(ITEM_FONT_COLORE, "",          CFGF_NONE),

   CFG_BOOL(ITEM_FONT_COLOR,  false,      CFGF_NONE),
   CFG_BOOL(ITEM_FONT_UPPER,  false,      CFGF_NONE),
   CFG_BOOL(ITEM_FONT_CENTER, false,      CFGF_NONE),
   CFG_BOOL(ITEM_FONT_REQUAN, false,      CFGF_NONE),
   
   CFG_END()
};

// linear font formats
enum
{
   FONT_FMT_LINEAR,
   FONT_FMT_PATCH,
   FONT_FMT_PNG,
   NUM_FONT_FMTS
};
Example #25
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);
}
Example #26
0
/* Forward */
static int cb_loglevel(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result);

/* general section structure */
static cfg_opt_t sec_general[] =
  {
    CFG_STR("uid", "nobody", CFGF_NONE),
    CFG_STR("admin_password", NULL, CFGF_NONE),
    CFG_STR("logfile", STATEDIR "/log/" PACKAGE ".log", CFGF_NONE),
    CFG_STR("db_path", STATEDIR "/cache/" PACKAGE "/songs3.db", CFGF_NONE),
    CFG_INT("db_pragma_cache_size", -1, CFGF_NONE),
    CFG_STR("db_pragma_journal_mode", NULL, CFGF_NONE),
    CFG_INT("db_pragma_synchronous", -1, CFGF_NONE),
    CFG_INT_CB("loglevel", E_LOG, CFGF_NONE, &cb_loglevel),
    CFG_BOOL("ipv6", cfg_true, CFGF_NONE),
    CFG_STR("cache_path", STATEDIR "/cache/" PACKAGE "/cache.db", CFGF_NONE),
    CFG_INT("cache_daap_threshold", 1000, CFGF_NONE),
    CFG_END()
  };

/* library section structure */
static cfg_opt_t sec_library[] =
  {
    CFG_STR("name", "My Music on %h", CFGF_NONE),
    CFG_INT("port", 3689, CFGF_NONE),
    CFG_STR("password", NULL, CFGF_NONE),
    CFG_STR_LIST("directories", NULL, CFGF_NONE),
    CFG_STR_LIST("podcasts", NULL, CFGF_NONE),
    CFG_STR_LIST("audiobooks", NULL, CFGF_NONE),
    CFG_STR_LIST("compilations", NULL, CFGF_NONE),
Example #27
0
int main(int argc, char **argv)
{
    unsigned int i;
    cfg_t *cfg;
    unsigned n;
    int ret;
    cfg_opt_t proxy_opts[] = {
        CFG_INT("type", 0, CFGF_NONE),
        CFG_STR("host", 0, CFGF_NONE),
        CFG_STR_LIST("exclude", "{localhost, .localnet}", CFGF_NONE),
        CFG_INT("port", 21, CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t bookmark_opts[] = {
        CFG_STR("machine", 0, CFGF_NONE),
        CFG_INT("port", 21, CFGF_NONE),
        CFG_STR("login", 0, CFGF_NONE),
        CFG_STR("password", 0, CFGF_NONE),
        CFG_STR("directory", 0, CFGF_NONE),
        CFG_BOOL("passive-mode", cfg_false, CFGF_NONE),
        CFG_SEC("proxy", proxy_opts, CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t opts[] = {
        CFG_INT("backlog", 42, CFGF_NONE),
        CFG_STR("probe-device", "eth2", CFGF_NONE),
        CFG_SEC("bookmark", bookmark_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_FLOAT_LIST("delays", "{3.567e2, 0.2, -47.11}", CFGF_NONE),
        CFG_FUNC("func", &cb_func),
        CFG_INT_CB("ask-quit", 3, CFGF_NONE, &cb_verify_ask),
        CFG_INT_LIST_CB("ask-quit-array", "{maybe, yes, no}",
                        CFGF_NONE, &cb_verify_ask),
        CFG_FUNC("include", &cfg_include),
        CFG_END()
    };

#ifndef _WIN32
    /* for some reason, MS Visual C++ chokes on this (?) */
    printf("Using %s\n\n", confuse_copyright);
#endif

    cfg = cfg_init(opts, CFGF_NOCASE);

    /* set a validating callback function for bookmark sections */
    cfg_set_validate_func(cfg, "bookmark", &cb_validate_bookmark);

    ret = cfg_parse(cfg, argc > 1 ? argv[1] : "test.conf");
    printf("ret == %d\n", ret);
    if(ret == CFG_FILE_ERROR) {
        perror("test.conf");
        return 1;
    } else if(ret == CFG_PARSE_ERROR) {
        fprintf(stderr, "parse error\n");
        return 2;
    }

    printf("backlog == %ld\n", cfg_getint(cfg, "backlog"));

    printf("probe device is %s\n", cfg_getstr(cfg, "probe-device"));
    cfg_setstr(cfg, "probe-device", "lo");
    printf("probe device is %s\n", cfg_getstr(cfg, "probe-device"));

    n = cfg_size(cfg, "bookmark");
    printf("%d configured bookmarks:\n", n);
    for(i = 0; i < n; i++) {
        cfg_t *pxy;
        cfg_t *bm = cfg_getnsec(cfg, "bookmark", i);
        printf("  bookmark #%u (%s):\n", i+1, cfg_title(bm));
        printf("    machine = %s\n", cfg_getstr(bm, "machine"));
        printf("    port = %d\n", (int)cfg_getint(bm, "port"));
        printf("    login = %s\n", cfg_getstr(bm, "login"));
        printf("    passive-mode = %s\n",
               cfg_getbool(bm, "passive-mode") ? "true" : "false");
        printf("    directory = %s\n", cfg_getstr(bm, "directory"));
        printf("    password = %s\n", cfg_getstr(bm, "password"));

        pxy = cfg_getsec(bm, "proxy");
        if(pxy) {
            int j, m;
            if(cfg_getstr(pxy, "host") == 0) {
                printf("      no proxy host is set, setting it to 'localhost'...\n");
                /* For sections without CFGF_MULTI flag set, there is
                 * also an extended syntax to get an option in a
                 * subsection:
                 */
                cfg_setstr(bm, "proxy|host", "localhost");
            }
            printf("      proxy host is %s\n", cfg_getstr(pxy, "host"));
            printf("      proxy type is %ld\n", cfg_getint(pxy, "type"));
            printf("      proxy port is %ld\n", cfg_getint(pxy, "port"));

            m = cfg_size(pxy, "exclude");
            printf("      got %d hosts to exclude from proxying:\n", m);
            for(j = 0; j < m; j++) {
                printf("        exclude %s\n", cfg_getnstr(pxy, "exclude", j));
            }
        } else
            printf("    no proxy settings configured\n");
    }

    printf("delays are (%d):\n", cfg_size(cfg, "delays"));
    for(i = 0; i < cfg_size(cfg, "delays"); i++)
        printf(" %G\n", cfg_getnfloat(cfg, "delays", i));

    printf("ask-quit == %ld\n", cfg_getint(cfg, "ask-quit"));

    /* Using cfg_setint(), the integer value for the option ask-quit
     * is not verified by the value parsing callback.
     *
     *
     cfg_setint(cfg, "ask-quit", 4);
     printf("ask-quit == %ld\n", cfg_getint(cfg, "ask-quit"));
    */

    /* The following commented line will generate a failed assertion
     * and abort, since the option "foo" is not declared
     *
     *
     printf("foo == %ld\n", cfg_getint(cfg, "foo"));
    */

    cfg_addlist(cfg, "ask-quit-array", 2, 1, 2);

    for(i = 0; i < cfg_size(cfg, "ask-quit-array"); i++)
        printf("ask-quit-array[%d] == %ld\n",
               i, cfg_getnint(cfg, "ask-quit-array", i));

    /* print the parsed values to another file */
    {
        FILE *fp = fopen("test.conf.out", "w");
        cfg_set_print_func(cfg, "func", print_func);
        cfg_set_print_func(cfg, "ask-quit", print_ask);
        cfg_set_print_func(cfg, "ask-quit-array", print_ask);
        cfg_print(cfg, fp);
        fclose(fp);
    }

    cfg_free(cfg);
    return 0;
}