Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
  CFG_BOOL("multiple_memcache_instances", 0, CFGF_NONE ),
  CFG_BOOL("accept_jvm_metrics", 1, CFGF_NONE ),
  CFG_BOOL("multiple_jvm_instances", 0, CFGF_NONE ),
  CFG_END()
};
#endif

static cfg_opt_t gmond_opts[] = {
  CFG_SEC("cluster",   cluster_opts, CFGF_NONE),
  CFG_SEC("host",      host_opts, CFGF_NONE),
  CFG_SEC("globals",     globals_opts, CFGF_NONE), 
  CFG_SEC("udp_send_channel", udp_send_channel_opts, CFGF_MULTI),
  CFG_SEC("udp_recv_channel", udp_recv_channel_opts, CFGF_MULTI),
  CFG_SEC("tcp_accept_channel", tcp_accept_channel_opts, CFGF_MULTI),
  CFG_SEC("collection_group",  collection_group_opts, CFGF_MULTI),
  CFG_FUNC("include", Ganglia_cfg_include),
  CFG_SEC("modules",  metric_modules_opts, CFGF_NONE),
#ifdef SFLOW
CFG_SEC("sflow", sflow_opts, CFGF_NONE),
#endif
  CFG_END()
}; 

char *
Ganglia_default_collection_groups(void)
{
  return COLLECTION_GROUP_LIST;
}

void
build_default_gmond_configuration(Ganglia_pool p)
Ejemplo n.º 3
0
 CFG_INT(ITEM_D2TITLETICS,    0,                 CFGF_NONE),
 CFG_INT(ITEM_INTERPAUSE,     0,                 CFGF_NONE),
 CFG_INT(ITEM_INTERFADE,     -1,                 CFGF_NONE),
 CFG_INT_CB(ITEM_INTERTL,     0,                 CFGF_NONE, E_TranslucCB),
 CFG_STR(ITEM_MN_EPISODE,     NULL,              CFGF_NONE),
 CFG_STR(ITEM_FONT_HUD,       "ee_smallfont",    CFGF_NONE),
 CFG_STR(ITEM_FONT_HUDO,      "ee_hudfont",      CFGF_NONE),
 CFG_STR(ITEM_FONT_MENU,      "ee_menufont",     CFGF_NONE),
 CFG_STR(ITEM_FONT_BMENU,     "ee_bigfont",      CFGF_NONE),
 CFG_STR(ITEM_FONT_NMENU,     "ee_smallfont",    CFGF_NONE),
 CFG_STR(ITEM_FONT_FINAL,     "ee_finalefont",   CFGF_NONE),
 CFG_STR(ITEM_FONT_INTR,      "ee_smallfont",    CFGF_NONE),
 CFG_STR(ITEM_FONT_INTRB,     "ee_bigfont",      CFGF_NONE),
 CFG_STR(ITEM_FONT_INTRBN,    "ee_bignumfont",   CFGF_NONE),
 CFG_STR(ITEM_FONT_CONS,      "ee_consolefont",  CFGF_NONE),
 CFG_FUNC("setdialect",       E_SetDialect),
 CFG_FUNC("include",          E_Include),
 CFG_FUNC("lumpinclude",      E_LumpInclude),
 CFG_FUNC("include_prev",     E_IncludePrev),    // DEPRECATED
 CFG_FUNC("stdinclude",       E_StdInclude),
 CFG_FUNC("userinclude",      E_UserInclude),
 CFG_FUNC("bexinclude",       bex_include),      // DEPRECATED
 CFG_FUNC("bexoverride",      bex_override),
 CFG_FUNC("ifenabled",        edf_ifenabled),
 CFG_FUNC("ifenabledany",     edf_ifenabledany),
 CFG_FUNC("ifdisabled",       edf_ifdisabled),
 CFG_FUNC("ifdisabledany",    edf_ifdisabledany),
 CFG_FUNC("endif",            E_Endif),
 CFG_FUNC("enable",           edf_enable),
 CFG_FUNC("disable",          edf_disable),
 CFG_FUNC("includeifenabled", edf_includeifenabled),
Ejemplo n.º 4
0
/* Test cfg_include when called from a buffer
 */

#include <string.h>
#include "check_confuse.h"

/* reuse suite_dup.c profile so that a.conf could be used for testing */
cfg_opt_t sec_opts[] = {
    CFG_INT("a", 1, CFGF_NONE),
    CFG_INT("b", 2, CFGF_NONE),
    CFG_END()
};

cfg_opt_t opts[] = {
    CFG_SEC("sec", sec_opts, CFGF_MULTI | CFGF_TITLE),
    CFG_FUNC("include", &cfg_include),
    CFG_END()
};

int main(void)
{
    char *buf = "include (\"" SRC_DIR "/a.conf\")\n";
    cfg_t *cfg = cfg_init(opts, CFGF_NONE);

    fail_unless(cfg);
    fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);
    fail_unless(cfg_size(cfg, "sec") == 1);
    fail_unless(cfg_getint(cfg, "sec|a") == 5);
    fail_unless(cfg_getint(cfg, "sec|b") == 2);
    cfg_free(cfg);
Ejemplo n.º 5
0
int parse_input(char* file, globals* vars) {
	cfg_opt_t operation_opts[] =
		{
		CFG_STR_LIST("in","{}", CFGF_NONE),
	CFG_STR("out", 0, CFGF_NONE),
CFG_END() };

	cfg_opt_t opts[] =
		{ CFG_STR_LIST("sorts", "{}", CFGF_NONE),
	CFG_SEC("op", operation_opts, CFGF_MULTI | CFGF_TITLE),
CFG_FUNC("include", &cfg_include), CFG_END() };

	cfg_t *cfg;

	int i, j, N, err;

	char *found, *sortname, *opname;
	op_signature *ops = malloc(sizeof(op_signature)+sizeof(char*)*MAX_OP_INPUTS);

	assert(ops);

	cfg = cfg_init(opts, CFGF_NONE);

	assert(cfg);

	if (cfg_parse(cfg, file) == CFG_PARSE_ERROR)
		return 1;

	/**
	 * add new sort names to the sorts trie
	 */

	N = cfg_size(cfg, "sorts");

	for (i = 0; i < N; i++)
	{
		sortname = cfg_getnstr(cfg, "sorts", i);
		found = cp_trie_exact_match(vars->sorts, sortname);
		if (!found)
		{
			sortname = strdup(sortname);
			cp_trie_add(vars->sorts, sortname, sortname);
			vars->sorts_N += 1;
		}
	}

	/**
	 * the the operations to the operation list
	 */

	N = cfg_size(cfg, "op");
	for (i = 0; i < N; i++)
	{

		cfg_t *op = cfg_getnsec(cfg, "op", i);
		opname = strdup(cfg_title(op));

		cp_vector_add_element(vars->op_names, opname);


		sortname = cfg_getstr(op,"out");

		assert(sortname);

		found = cp_trie_exact_match(vars->sorts,sortname);
		if (! found) {
			fputs("Operation ",stderr);
			fputs(opname,stderr);
			fputs(" uses undeclared output sort ",stderr);
			fputs(sortname,stderr);
			fputs("\n",stderr);
			/** fix it */
			sortname = strdup(sortname);
			cp_trie_add(vars->sorts, sortname, sortname);
			vars->sorts_N += 1;
			found = sortname;
		}

		ops->id = vars->ops_N;
		ops->out = found;
		ops->in_N = cfg_size(op, "in");

		assert(ops->in_N <= MAX_OP_INPUTS);

		for (j=0;j<ops->in_N; ++j) {
			sortname = cfg_getnstr(op,"in",j);
			assert(sortname);

			found = cp_trie_exact_match(vars->sorts,sortname);
			if (! found) {
				fputs("Operation ",stderr);
				fputs(opname,stderr);
				fputs(" uses undeclared input sort ",stderr);
				fputs(sortname,stderr);
				fputs("\n",stderr);
				/** fix it */
				sortname = strdup(sortname);
				cp_trie_add(vars->sorts, sortname, sortname);
				vars->sorts_N += 1;
				found = sortname;
			}
			ops->in[j] = found;
		}

		err = 0;

		cp_multimap_insert(vars->ops, ops, &err);
		if (err) {
			fputs("Operation ",stderr);
			fputs(opname,stderr);
			fputs(": cannot add to multimap ",stderr);
			fprintf(stderr,"%d",err);
			fputs("\n",stderr);
		}
		vars->ops_N += 1;

	}



	cfg_free(cfg);
	free(ops);
	return 0;
}
Ejemplo n.º 6
0
Archivo: initend.c Proyecto: 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;
}
Ejemplo n.º 7
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;
}