示例#1
0
int main(void)
{
	cfg_t *acfg, *bcfg;
	cfg_t *sec;

	acfg = create_config();
	fail_unless(cfg_parse(acfg, SRC_DIR "/a.conf") == 0);

	bcfg = create_config();
	fail_unless(cfg_parse(bcfg, SRC_DIR "/b.conf") == 0);

	sec = cfg_getnsec(acfg, "sec", 0);
	fail_unless(sec != 0);
	fail_unless(cfg_size(acfg, "sec") == 1);
	fail_unless(strcmp(cfg_title(sec), "acfg") == 0);
	fail_unless(cfg_getint(sec, "a") == 5);
	fail_unless(cfg_getint(sec, "b") == 2);

	sec = cfg_getnsec(bcfg, "sec", 0);
	fail_unless(sec != 0);
	fail_unless(cfg_size(bcfg, "sec") == 1);
	fail_unless(strcmp(cfg_title(sec), "bcfg") == 0);
	fail_unless(cfg_getint(sec, "a") == 1);
	fail_unless(cfg_getint(sec, "b") == 9);

	cfg_free(acfg);
	cfg_free(bcfg);

	return 0;
}
示例#2
0
int Settings::getNodeId(Node type, int intDeviceIndex) const {
	if (intDeviceIndex >= getNumberOfNodes(type)) {  // Out of bounds
		return -1;
	}
	TelldusCore::MutexLocker locker(&mutex);
	cfg_t *cfg_node;
	if (type == Device) {
		cfg_node = cfg_getnsec(d->cfg, "device", intDeviceIndex);
	} else if (type == Controller) {
		cfg_node = cfg_getnsec(d->cfg, "controller", intDeviceIndex);
	}
	int id = cfg_getint(cfg_node, "id");
	return id;
}
示例#3
0
int
parse_mapping_cfg_params(cfg_t *map, conf_mapping_t *conf_mapping, uint8_t is_local)
{

    int ctr;
    cfg_t *rl;
    conf_loc_t *conf_loc;
    conf_loc_iface_t *conf_loc_iface;
    int afi;

    strcpy(conf_mapping->eid_prefix,cfg_getstr(map, "eid-prefix"));
    conf_mapping->iid = cfg_getint(map, "iid");

    for (ctr = 0; ctr < cfg_size(map, "rloc-address"); ctr++){
        rl = cfg_getnsec(map, "rloc-address", ctr);
        conf_loc = conf_loc_new_init(
                cfg_getstr(rl, "address"),
                cfg_getint(rl, "priority"),
                cfg_getint(rl, "weight"),
                255,0);
        glist_add_tail(conf_loc,conf_mapping->conf_loc_list);
    }

    if (is_local){

        for (ctr = 0; ctr < cfg_size(map, "rloc-iface"); ctr++){
            rl = cfg_getnsec(map, "rloc-iface", ctr);
            afi = cfg_getint(rl, "ip_version");
            if (afi == 4){
                afi = AF_INET;
            }else if (afi == 6){
                afi = AF_INET6;
            }else{
                OOR_LOG(LERR,"Configuration file: The conf_loc_iface->ip_version of the locator should be 4 (IPv4) or 6 (IPv6)");
                return (BAD);
            }
            conf_loc_iface = conf_loc_iface_new_init(
                    cfg_getstr(rl, "interface"),
                    afi,
                    cfg_getint(rl, "priority"),
                    cfg_getint(rl, "weight"),
                    255,0);
            glist_add_tail(conf_loc_iface,conf_mapping->conf_loc_iface_list);
        }
    }

    return (GOOD);
}
示例#4
0
int cb_validate_conffile(cfg_t *cfg)
{
	char LaunchString[255];
	cfg_t *cfg_greet;
	
	if(cfg_size(cfg, "Channel") == 0)
	{
		cfg_error(cfg, "no \"Channel\" section found");
		return -1;
	}
	
	printf("\t%d Channel setions found\n", cfg_size(cfg, "Channel"));
	
	int j;
	for(j = 0; j < cfg_size(cfg, "Channel"); j++)
	{
		cfg_greet = cfg_getnsec(cfg, "Channel", j);
		sprintf(LaunchString, "%s", cfg_getstr(cfg_greet, "LaunchString"));
		if(!(strlen(LaunchString) > 0))
		{
			cfg_error(cfg, "invalid LaunchString for Channel[%d]", j);
			return -1;
		}
		printf("\tChannel[%d].LaunchString = %s\n", j, LaunchString);
		printf("\tChannel[%d].AudioChannels = %ld\n", j, cfg_getint(cfg_greet, "AudioChannels"));
		printf("\tChannel[%d].SampleRate = %ld\n", j, cfg_getint(cfg_greet, "SampleRate"));
		printf("\tChannel[%d].Width = %ld\n", j, cfg_getint(cfg_greet, "Width"));
		printf("\tChannel[%d].Height = %ld\n", j, cfg_getint(cfg_greet, "Height"));
		printf("\tChannel[%d].Bitrate = %ld\n", j, cfg_getint(cfg_greet, "Bitrate"));
		printf("\tChannel[%d].Ratio = %s\n", j, cfg_getstr(cfg_greet, "Ratio"));
	}
    return 0;
}
示例#5
0
SyncLogEntry SyncLogger::ReadFirstEntry(const char* pszHash)
{
	ParseFile(pszHash);

	// Assures the correct parsing of the file.
	assert(m_pCFG != NULL);

//	cfg_t* pEntryCFG = cfg_getnsec(m_pCFG, MOD_NUMBER_VARNAME, 0);
	return ReadEntry(cfg_getnsec(m_pCFG, MOD_NUMBER_VARNAME, 0));
/*
	// Assures that the section has been found, which means there is at least one section.
    assert(pEntryCFG != NULL);

	// TODO: Copy values
	SyncLogEntry sle;
	sle.m_strFilePath = cfg_getstr(pEntryCFG, FILE_PATH_VARNAME);
	sle.m_strModTime = cfg_getstr(pEntryCFG, MOD_TIME_VARNAME);
	string strModType = cfg_getstr(pEntryCFG, MOD_TYPE_VARNAME);
	if (strModType.length() != 1)
	{
		// The log entry does not meet the standard.
		return NULL;
	}
	sle.m_chModType = strModType.c_str()[0];

    return sle;
*/
}
示例#6
0
static void
parse_mcinfo_list(cfg_t *cfg, shash_t *ht)
{
    mc_t *mc;
    lisp_addr_t *laddr;
    char *name;
    int i, count;

    count = 0;
    for (i = 0; i < cfg_size(cfg, "multicast-info"); i++) {
        cfg_t *mcnode = cfg_getnsec(cfg, "multicast-info", i);
        name = cfg_getstr(mcnode, "mc-info-name");

        laddr = lisp_addr_new_lafi(LM_AFI_LCAF);
        lisp_addr_lcaf_set_type(laddr, LCAF_MCAST_INFO);

        mc = mc_type_new();
        lisp_addr_ip_from_char(cfg_getstr(mcnode, "source"), mc->src);
        mc->src_plen = cfg_getint(mcnode, "source-mask-length");
        lisp_addr_ip_from_char(cfg_getstr(mcnode, "group"), mc->grp);
        mc->src_plen = cfg_getint(mcnode, "group-mask-length");
        mc->iid = cfg_getint(mcnode, "iid");

        lisp_addr_lcaf_set_addr(laddr, mc);
        OOR_LOG(LDBG_1, "Configuration file: parsed multicast-info: %s",
                lisp_addr_to_char(laddr));

        shash_insert(ht, strdup(name), laddr);
        count ++;
    }

    if (count != 0) {
        OOR_LOG(LINF, "Parsed configured multicast addresses");
    }
}
示例#7
0
int main(int argc, char **argv)
{
    int i;
    cfg_t *cfg = parse_conf(argc > 1 ? argv[1] : "ftp.conf");

    /* print the parsed configuration options */
    if(cfg)
    {
        printf("reverse-dns = %s\n", cfg_getbool(cfg, "reverse-dns") ? "true" : "false");
        printf("passive-mode = %s\n", cfg_getbool(cfg, "passive-mode") ? "true" : "false");
        printf("remote-completion = %s\n", cfg_getbool(cfg, "remote-completion") ? "true" : "false");

        printf("number of bookmarks: %d\n", cfg_size(cfg, "bookmark"));
        for(i = 0; i < cfg_size(cfg, "bookmark"); i++)
        {
            cfg_t *bookmark = cfg_getnsec(cfg, "bookmark", i);
            printf("  bookmark #%d: %s:%s@%s:%ld%s\n", i+1,
                    cfg_getstr(bookmark, "login"),
                    cfg_getstr(bookmark, "password"),
                    cfg_getstr(bookmark, "host"),
                    cfg_getint(bookmark, "port"),
                    cfg_getstr(bookmark, "directory"));
        }

        for(i = 0; i < cfg_size(cfg, "xterm-terminals"); i++)
            printf("xterm-terminal #%d: %s\n", i+1, cfg_getnstr(cfg, "xterm-terminals", i));

        printf("auto-create-bookmark = %ld\n", cfg_getint(cfg, "auto-create-bookmark"));
        cfg_free(cfg);
    }

    return 0;
}
示例#8
0
/*
* Remove a device
*/
int Settings::removeNode(Node type, int intNodeId) {
	TelldusCore::MutexLocker locker(&mutex);
	FILE *fp = fopen(CONFIG_FILE, "we");  // e for setting O_CLOEXEC on the file handle
	if (!fp) {
		return TELLSTICK_ERROR_PERMISSION_DENIED;
	}

	std::string strType = getNodeString(type);

	// Print all opts
	for(int i = 0; d->cfg->opts[i].name; i++) {
		// Check if it isn't a device section
		if (strcmp(d->cfg->opts[i].name, strType.c_str()) != 0) {
			cfg_opt_print(&d->cfg->opts[i], fp);
		} else {
			// Print all sections except the one to remove
			cfg_t *cfg_node;
			for (int i = 0; i < cfg_size(d->cfg, strType.c_str()); ++i) {
				cfg_node = cfg_getnsec(d->cfg, strType.c_str(), i);
				if (cfg_getint(cfg_node, "id") != intNodeId) {  // This isn't the one to skip
					fprintf(fp, "%s {\n", strType.c_str());
					cfg_print_indent(cfg_node, fp, 1);
					fprintf(fp, "}\n");
				}
			}
		}
	}
	fclose(fp);

	// Re-read config-file
	cfg_free(d->cfg);
	readConfig(&d->cfg);

	return TELLSTICK_SUCCESS;
}
示例#9
0
int Settings::setIntSetting(Node type, int intDeviceId, const std::wstring &name, int value, bool parameter) {
	// already locked
	if (d->cfg == 0) {
		return TELLSTICK_ERROR_PERMISSION_DENIED;
	}
	std::string strType = getNodeString(type);
	cfg_t *cfg_device;
	for (int i = 0; i < cfg_size(d->cfg, strType.c_str()); ++i) {
		cfg_device = cfg_getnsec(d->cfg, strType.c_str(), i);
		if (cfg_getint(cfg_device, "id") == intDeviceId)  {
			if (parameter) {
				cfg_t *cfg_parameters = cfg_getsec(cfg_device, "parameters");
				cfg_setint(cfg_parameters, TelldusCore::wideToString(name).c_str(), value);
			} else {
				cfg_setint(cfg_device, TelldusCore::wideToString(name).c_str(), value);
			}
			FILE *fp = fopen(CONFIG_FILE, "we");  // e for setting O_CLOEXEC on the file handle
			if (!fp) {
				return TELLSTICK_ERROR_PERMISSION_DENIED;
			}
			cfg_print(d->cfg, fp);
			fclose(fp);
			return TELLSTICK_SUCCESS;
		}
	}
	return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
示例#10
0
int
parse_proxy_etrs(cfg_t *cfg, lisp_xtr_t *xtr)
{
    int n,i;
    void *fwd_map_inf;
    /* 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(xtr->petrs,
                cfg_getstr(petr, "address"),
                cfg_getint(petr, "priority"),
                cfg_getint(petr, "weight")) == GOOD) {
            OOR_LOG(LDBG_1, "Added %s to proxy-etr list", cfg_getstr(petr, "address"));
        } else{
            OOR_LOG(LERR, "Can't add proxy-etr %s", cfg_getstr(petr, "address"));
        }
    }

    /* Calculate forwarding info for petrs */
    fwd_map_inf = xtr->fwd_policy->new_map_cache_policy_inf(xtr->fwd_policy_dev_parm,mcache_entry_mapping(xtr->petrs));
    if (fwd_map_inf == NULL){
        OOR_LOG(LDBG_1, "xtr_ctrl_construct: Couldn't create routing info for PeTRs!.");
        mcache_entry_del(xtr->petrs);
        return(BAD);
    }
    mcache_entry_set_routing_info(xtr->petrs,fwd_map_inf,xtr->fwd_policy->del_map_cache_policy_inf);
    return (GOOD);
}
示例#11
0
//
// E_ProcessInventoryDeltas
//
// Does processing for inventorydelta sections, which allow cascading editing
// of existing inventory items. The inventorydelta shares most of its fields
// and processing code with the thingtype section.
//
void E_ProcessInventoryDeltas(cfg_t *cfg)
{
   int i, numdeltas;

   E_EDFLogPuts("\t* Processing inventory deltas\n");

   numdeltas = cfg_size(cfg, EDF_SEC_INVDELTA);

   E_EDFLogPrintf("\t\t%d inventorydelta(s) defined\n", numdeltas);

   for(i = 0; i < numdeltas; i++)
   {
      cfg_t       *deltasec = cfg_getnsec(cfg, EDF_SEC_INVDELTA, i);
      inventory_t *inv;

      // get thingtype to edit
      if(!cfg_size(deltasec, ITEM_DELTA_NAME))
         E_EDFLoggedErr(2, "E_ProcessInventoryDeltas: inventorydelta requires name field\n");

      inv = E_GetInventoryForName(cfg_getstr(deltasec, ITEM_DELTA_NAME));

      E_ProcessInventory(inv, deltasec, cfg, false);

      E_EDFLogPrintf("\t\tApplied inventorydelta #%d to %s(#%d)\n",
                     i, inv->name, inv->numkey);
   }
}
示例#12
0
static void print_systems(cfg_t *cfg)
{
	size_t i;

	for (i = 0; i < cfg_size(cfg, "provider"); i++)
		print_system(cfg_getnsec(cfg, "provider", i));
}
示例#13
0
static cfg_t* find_module_config(char *modname)
{
    cfg_t *modules_cfg;
    int j;

    modules_cfg = cfg_getsec(python_module.config_file, "modules");
    for (j = 0; j < cfg_size(modules_cfg, "module"); j++) {
        char *modName, *modLanguage;
        int modEnabled;

        cfg_t *pymodule = cfg_getnsec(modules_cfg, "module", j);

        /* Check the module language to make sure that
           the language designation is python.
        */
        modLanguage = cfg_getstr(pymodule, "language");
        if (!modLanguage || strcasecmp(modLanguage, "python")) 
            continue;

        modName = cfg_getstr(pymodule, "name");
        if (strcasecmp(modname, modName)) {
            continue;
        }

        /* Check to make sure that the module is enabled.
        */
        modEnabled = cfg_getbool(pymodule, "enabled");
        if (!modEnabled) 
            continue;

        return pymodule;
    }
    return NULL; 
}
示例#14
0
//
// E_ProcessInventoryDefs
//
// Resolves and loads all information for the inventory structures.
//
void E_ProcessInventoryDefs(cfg_t *cfg)
{
   unsigned int i, numInventory;

   E_EDFLogPuts("\t* Processing inventory data\n");

   if(!(numInventory = cfg_size(cfg, EDF_SEC_INVENTORY)))
      return;

   // allocate inheritance stack and hitlist
   inv_pstack = ecalloc(inventory_t **, numInventoryDefs, sizeof(inventory_t *));

   // TODO: any first-time-only processing?

   for(i = 0; i < numInventory; i++)
   {
      cfg_t       *invsec = cfg_getnsec(cfg, EDF_SEC_INVENTORY, i);
      const char  *name   = cfg_title(invsec);
      inventory_t *inv    = E_InventoryForName(name);

      // reset the inheritance stack
      E_ResetInventoryPStack();

      // add this def to the stack
      E_AddInventoryToPStack(inv);

      E_ProcessInventory(inv, invsec, cfg, true);

      E_EDFLogPrintf("\t\tFinished inventory %s(#%d)\n", inv->name, inv->numkey);
   }

   // free tables
   efree(inv_pstack);
}
示例#15
0
static HV* build_params_hash(cfg_t *plmodule)
{
    int k;
    HV *params_hash;

    params_hash = newHV();

    if (plmodule && params_hash) {
        for (k = 0; k < cfg_size(plmodule, "param"); k++) {
            cfg_t *param;
            char *name, *value;
            SV *sv_value;

            param = cfg_getnsec(plmodule, "param", k);
            name = apr_pstrdup(pool, param->title);
            value = apr_pstrdup(pool, cfg_getstr(param, "value"));
            sv_value = newSVpv(value, 0);
            if (name && sv_value) {
                /* Silence "value computed is not used" warning */
                (void)hv_store(params_hash, name, strlen(name), sv_value, 0);
            }
        }
    }
    return params_hash;
} 
示例#16
0
int main(void)
{
    unsigned int i;

    read_config();
    signal(SIGHUP, sighandler);
    signal(SIGUSR1, usr1handler);

    while(loop)
    {
        printf("Message: %s", cfg_getstr(cfg, "message"));
        for(i = 0; i < cfg_size(cfg, "argument"); i++)
        {
            cfg_t *arg = cfg_getnsec(cfg, "argument", i);
            printf(", %s", cfg_getstr(arg, "value"));
        }
        printf("\n");

        sleep(cfg_getint(cfg, "delay"));
    }

    cfg_free(cfg);
    cfg = 0;

    return 0;
}
示例#17
0
int
parse_database_mapping(cfg_t *cfg, lisp_xtr_t *xtr, shash_t *lcaf_ht)
{
    int n,i;
    mapping_t *mapping;
    map_local_entry_t *map_loc_e;
    void *fwd_map_inf;

    n = cfg_size(cfg, "database-mapping");
    for (i = 0; i < n; i++) {
        mapping = parse_mapping(cfg_getnsec(cfg, "database-mapping", i),&(xtr->super),lcaf_ht,TRUE);
        if (mapping == NULL){
            continue;
        }
        map_loc_e = map_local_entry_new_init(mapping);
        if (map_loc_e == NULL){
            mapping_del(mapping);
            continue;
        }
        fwd_map_inf = xtr->fwd_policy->new_map_loc_policy_inf(xtr->fwd_policy_dev_parm,mapping,NULL);
        if (fwd_map_inf == NULL){
            OOR_LOG(LERR, "Couldn't create forward information for mapping with EID: %s. Discarding it...",
                    lisp_addr_to_char(mapping_eid(mapping)));
            map_local_entry_del(map_loc_e);
            continue;
        }
        map_local_entry_set_fwd_info(map_loc_e, fwd_map_inf, xtr->fwd_policy->del_map_loc_policy_inf);
        if (add_local_db_map_local_entry(map_loc_e,xtr) != GOOD){
            map_local_entry_del(map_loc_e);
            continue;
        }
    }

    return (GOOD);
}
示例#18
0
int main(void)
{
	static cfg_opt_t section_opts[] = {
		CFG_STR("prop", 0, CFGF_NONE),
		CFG_END()
	};

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

	const char *config_data =
		"section title_one { prop = 'value_one' }\n"
		"section title_two { prop = 'value_two' }\n"
		"section title_one { prop = 'value_one' }\n";

	int rc;
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	cfg_rmtsec(cfg, "section", "title_two");
	fail_unless(cfg_size(cfg, "section") == 1);
	fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0);

	cfg_free(cfg);

	cfg = cfg_init(opts, CFGF_NONE);
	fail_unless(cfg);

	rc = cfg_parse_buf(cfg, config_data);
	fail_unless(rc == CFG_SUCCESS);

	cfg_rmsec(cfg, "section");
	fail_unless(cfg_size(cfg, "section") == 1);
	fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_two") == 0);

	cfg_free(cfg);

	return 0;
}
示例#19
0
//
// E_ProcessGameProperties
//
// Main routine for this module. Process all gameproperties blocks.
//
void E_ProcessGameProperties(cfg_t *cfg)
{
   unsigned int numProps = cfg_size(cfg, EDF_SEC_GAMEPROPS);

   E_EDFLogPuts("\t* Processing gameproperties\n");

   for(unsigned int i = 0; i < numProps; i++)
      E_processGamePropsBlock(cfg_getnsec(cfg, EDF_SEC_GAMEPROPS, i));
}
示例#20
0
//
// Processes "switch" blocks
//
void E_ProcessSwitches(cfg_t *cfg)
{
   unsigned numswitches = cfg_size(cfg, EDF_SEC_SWITCH);

   E_EDFLogPrintf("\t* Processing switches\n"
                  "\t\t%u switch(es) defined\n", numswitches);

   for(unsigned i = 0; i < numswitches; ++i)
      E_processSwitch(cfg_getnsec(cfg, EDF_SEC_SWITCH, i));
}
示例#21
0
文件: conf.c 项目: noushi/bmon
static void configfile_read_units(void)
{
	int i, nunits;
	struct unit *u;

	nunits = cfg_size(cfg, "unit");

	for (i = 0; i < nunits; i++) {
		int nvariants, n;
		cfg_t *unit;
		const char *name;

		if (!(unit = cfg_getnsec(cfg, "unit", i)))
			BUG();

		if (!(name = cfg_title(unit)))
			BUG();

		if (!(nvariants = cfg_size(unit, "variant")))
			continue;

		if (!(u = unit_add(name)))
			continue;

		for (n = 0; n < nvariants; n++) {
			cfg_t *variant;
			const char *vtitle;

			if (!(variant = cfg_getnsec(unit, "variant", n)))
				BUG();

			if (!(vtitle = cfg_title(variant)))
				BUG();

			if (!strcasecmp(vtitle, "default"))
				add_div(u, UNIT_DEFAULT, variant);
			else if (!strcasecmp(vtitle, "si"))
				add_div(u, UNIT_SI, variant);
			else
				quit("Unknown unit variant \'%s\'\n", vtitle);
		}
	}
}
示例#22
0
int main(void)
{
	cfg_opt_t group_opts[] = {
		CFG_INT("number", 0, CFGF_NONE),
		CFG_INT("total", 0, CFGF_NONE),
		CFG_END()
	};
	cfg_opt_t groups_opts[] = {
		CFG_STR("name", "Esmé", CFGF_NONE),
		CFG_SEC("group", group_opts, CFGF_TITLE | CFGF_MULTI),
		CFG_END()
	};
	cfg_opt_t opts[] = {
		CFG_SEC("groups", groups_opts, CFGF_NONE),
		CFG_END()
	};
	cfg_t *cfg, *sec;
	size_t i, j;

	cfg = cfg_init(opts, CFGF_NONE);
	if (!cfg || cfg_parse(cfg, CONF) == CFG_PARSE_ERROR) {
		perror("Failed parsing " CONF);
		return 1;
	}

	/* Iterate over the sections and print fields from each section. */
	for (i = 0; i < cfg_size(cfg, "groups"); i++) {
		sec = cfg_getnsec(cfg, "groups", i);

		for (j = 0; j < cfg_size(sec, "group"); j++) {
			cfg_t *opt = cfg_getnsec(sec, "group", j);

			printf("group title:  '%s'\n", cfg_title(opt));
			printf("group number:  %ld\n", cfg_getint(opt, "number"));
			printf("group total:   %ld\n", cfg_getint(opt, "total"));
			printf("\n");
		}
	}

	cfg_free(cfg);

	return 0;
}
示例#23
0
static void
parse_elp_list(cfg_t *cfg, shash_t *ht)
{
    elp_node_t *enode;
    elp_t *elp;
    lisp_addr_t *laddr;
    char *name;
    int i, j;

    for(i = 0; i < cfg_size(cfg, "explicit-locator-path"); i++) {
        cfg_t *selp = cfg_getnsec(cfg, "explicit-locator-path", i);
        name = cfg_getstr(selp, "elp-name");

        elp = elp_type_new();

        for (j = 0; j < cfg_size(selp, "elp-node");j++) {
            cfg_t *senode = cfg_getnsec(selp, "elp-node", j);
            enode = xzalloc(sizeof(elp_node_t));
            enode->addr = lisp_addr_new();
            if (lisp_addr_ip_from_char(cfg_getstr(senode, "address"),
                    enode->addr) != GOOD) {
                elp_node_del(enode);
                OOR_LOG(LDBG_1, "parse_elp_list: Couldn't parse ELP node %s",
                        cfg_getstr(senode, "address"));
                continue;
            }
            enode->L = cfg_getbool(senode, "lookup") ? 1 : 0;
            enode->P = cfg_getbool(senode, "probe") ? 1 : 0;
            enode->S = cfg_getbool(senode, "strict") ? 1: 0;

            glist_add_tail(enode, elp->nodes);
        }

        laddr = lisp_addr_new_lafi(LM_AFI_LCAF);
        lisp_addr_lcaf_set_type(laddr, LCAF_EXPL_LOC_PATH);
        lisp_addr_lcaf_set_addr(laddr, elp);
        OOR_LOG(LDBG_1, "Configuration file: parsed explicit-locator-path: %s",
                lisp_addr_to_char(laddr));

        shash_insert(ht, strdup(name), laddr);
    }
}
示例#24
0
//
// E_CollectInventory
//
// Pre-creates and hashes by name the inventory definitions, for purpose 
// of mutual and forward references.
//
void E_CollectInventory(cfg_t *cfg)
{
   static int currentID = 1;
   unsigned int i;
   unsigned int numInventory;    // number of inventory defs defined by the cfg
   inventory_t *newInvDefs  = NULL;

   // get number of inventory definitions defined by the cfg
   numInventory = cfg_size(cfg, EDF_SEC_INVENTORY);

   // echo counts
   E_EDFLogPrintf("\t\t%u inventory items defined\n", numInventory);

   if(numInventory)
   {
      // allocate inventory structures for the new thingtypes
      newInvDefs = estructalloc(inventory_t, numInventory);

      numInventoryDefs += numInventory;

      // create metatables
      for(i = 0; i < numInventory; i++)
         newInvDefs[i].meta = new MetaTable("inventory");
   }

   // build hash tables
   E_EDFLogPuts("\t\tBuilding inventory hash tables\n");
   
   // cycle through the thingtypes defined in the cfg
   for(i = 0; i < numInventory; i++)
   {
      cfg_t *invcfg = cfg_getnsec(cfg, EDF_SEC_INVENTORY, i);
      const char *name = cfg_title(invcfg);

      // This is a new inventory, whether or not one already exists by this name
      // in the hash table. For subsequent addition of EDF inventory defs at 
      // runtime, the hash table semantics of "find newest first" take care of 
      // overriding, while not breaking objects that depend on the original 
      // definition of the inventory type for inheritance purposes.
      inventory_t *inv = &newInvDefs[i];

      // initialize name
      inv->name = estrdup(name);

      // add to name hash
      inv_namehash.addObject(inv);

      // create ID number and add to hash table
      inv->numkey = currentID++;
      inv_numhash.addObject(inv);
   }
}
示例#25
0
int filters_init(cfg_t *cfg)
{
    filters = g_hash_table_new_full(&g_str_hash, &g_str_equal, &g_free, (GDestroyNotify)&filter_free);

    int index = cfg_size(cfg, "filter");
    while (index--) {
        cfg_t *sec = cfg_getnsec(cfg, "filter", index);
        filter *f = filter_create();
        add_filter_restrictions(f, sec);
        g_hash_table_insert(filters, g_strdup(cfg_title(sec)), f);
    }
    return 1;
}
示例#26
0
static void
parse_rle_list(cfg_t *cfg, shash_t *ht)
{
    rle_node_t *rnode;
    rle_t *rle;
    lisp_addr_t *laddr;
    char *name;
    int i, j;

    for (i = 0; i < cfg_size(cfg, "replication-list"); i++) {
        cfg_t *selp = cfg_getnsec(cfg, "replication-list", i);
        name = cfg_getstr(selp, "rle-name");

        laddr = lisp_addr_new_lafi(LM_AFI_LCAF);
        lisp_addr_lcaf_set_type(laddr, LCAF_RLE);

        rle = rle_type_new();

        for (j = 0; j < cfg_size(selp, "rle-node"); j++) {
            cfg_t *rlenode = cfg_getnsec(selp, "rle-node", j);
            rnode = rle_node_new();
            if (lisp_addr_ip_from_char(cfg_getstr(rlenode, "address"),
                    rnode->addr) != GOOD) {
                rle_node_del(rnode);
                OOR_LOG(LDBG_1, "parse_rle_list: Couldn't parse RLE node %s",
                        cfg_getstr(rlenode, "address"));
            }
            rnode->level = cfg_getint(rlenode, "level");

            glist_add_tail(rnode, rle->nodes);
        }
        lisp_addr_lcaf_set_addr(laddr, (void *)rle);
        OOR_LOG(LDBG_1, "Configuration file: parsed replication-list: %s",
                lisp_addr_to_char(laddr));

        shash_insert(ht, strdup(name), laddr);
    }

}
示例#27
0
int
higher_tiers_exist(struct program_params *pp, const char *lv_name, int tier)
{
    cfg_t *tmp = cfg_gettsec(pp->cfg, "volume", lv_name);
    assert(tmp);

    int lowest_tier;
    cfg_t *pv_cfg = cfg_getnsec(tmp, "pv", 0);
    lowest_tier = cfg_getint(pv_cfg, "tier");
    if (lowest_tier < tier)
        return 1;

    for (size_t i=1; i < cfg_size(tmp, "pv"); i++) {
        pv_cfg = cfg_getnsec(tmp, "pv", i);
        if (cfg_getint(pv_cfg, "tier") < lowest_tier)
            lowest_tier = cfg_getint(pv_cfg, "tier");
    }

    if (lowest_tier < tier)
        return 1;

    return 0;
}
示例#28
0
文件: conf.c 项目: noushi/bmon
static void configfile_read_attrs(void)
{
	int i, nattrs, t;

	nattrs = cfg_size(cfg, "attr");

	for (i = 0; i < nattrs; i++) {
		struct unit *u;
		cfg_t *attr;
		const char *name, *description, *unit, *type;
		int flags = 0;

		if (!(attr = cfg_getnsec(cfg, "attr", i)))
			BUG();

		if (!(name = cfg_title(attr)))
			BUG();

		description = cfg_getstr(attr, "description");
		unit = cfg_getstr(attr, "unit");
		type = cfg_getstr(attr, "type");

		if (!unit)
			quit("Attribute '%s' is missing unit specification\n",
			     name);

		if (!type)
			quit("Attribute '%s' is missing type specification\n",
			     name);

		if (!(u = unit_lookup(unit)))
			quit("Unknown unit \'%s\' attribute '%s'\n",
				unit, name);

		if (!strcasecmp(type, "counter"))
			t = ATTR_TYPE_COUNTER;
		else if (!strcasecmp(type, "rate"))
			t = ATTR_TYPE_RATE;
		else if (!strcasecmp(type, "percent"))
			t = ATTR_TYPE_PERCENT;
		else
			quit("Unknown type \'%s\' in attribute '%s'\n",
				type, name);

		if (cfg_getbool(attr, "history"))
			flags |= ATTR_DEF_FLAG_HISTORY;

		attr_def_add(name, description, u, t, flags);
	}
}
示例#29
0
void validate_test(void)
{
	char *buf;
	unsigned int i;

	buf = "action = wlak";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);

	buf = "action = walk";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);

	buf = "action = run" " options { speed = 6 }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);

	buf = "action = jump" " options { speed = 2 name = 'Joe' }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);

	buf = "action = crawl" " options { speed = -2 name = 'Smith' }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);

	buf = "ip-address = { 0.0.0.0 , 1.2.3.4 , 192.168.0.254 , 10.0.0.255 , 20.30.40.256}";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);
	buf = "ip-address = { 0.0.0.0 , 1.2.3.4 , 192.168.0.254 , 10.0.0.255 , 20.30.40.250}";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);
	buf = "ip-address = { 1.2.3. }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);

	buf = "action = run" " multi_options { speeds = {1, 2, 3, 4, 5} }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);
	for (i = 0; i < cfg_size(cfg, "multi_options"); i++) {
		cfg_t *multisec = cfg_getnsec(cfg, "multi_options", i);
		cfg_opt_t *speeds_opt = cfg_getopt(multisec, "speeds");

		fail_unless(speeds_opt != 0);
		fail_unless(speeds_opt->validcb == validate_speed);
	}

	buf = "action = run" " multi_options { speeds = {1, 2, 3, -4, 5} }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);

	buf = "action = run" " multi_options { speeds = {1, 2, 3, 4, 0} }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);

	buf = "action = run" " multi_options { options { xspeed = 3 } }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_SUCCESS);

	buf = "action = run" " multi_options { options { xspeed = -3 } }";
	fail_unless(cfg_parse_buf(cfg, buf) == CFG_PARSE_ERROR);
}
示例#30
0
int
get_device_tier(struct program_params *pp, const char *lv_name, const char *dev)
{
    cfg_t *tmp = cfg_gettsec(pp->cfg, "volume", lv_name);
    assert(tmp);

    cfg_t *pv_cfg;

    for (size_t i=0; i < cfg_size(tmp, "pv"); i++) {
        pv_cfg = cfg_getnsec(tmp, "pv", i);
        if (!strcmp(cfg_getstr(pv_cfg, "path"), dev))
            return cfg_getint(pv_cfg, "tier");
    }
    return -1;
}