Exemplo n.º 1
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;
}
Exemplo n.º 2
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");
    }
}
Exemplo n.º 3
0
Arquivo: pk2dft.c Projeto: GBert/misc
int parse_script(char *filename, script_ent_t * script) {
    cfg_t *pcfg;
    int i;

    memset(script, 0, sizeof(script_ent_t));

    printf("eins\n");
    pcfg = cfg_init(script_opts, CFGF_NONE);
    printf("zwei\n");
    if (cfg_parse(pcfg, filename) == CFG_PARSE_ERROR)
	return -1;

    strcpy(script->name, cfg_getstr(pcfg, "name"));	/* max 28 chars !!! */
    strcpy(script->org_name, cfg_getstr(pcfg, "org_name"));	/* max 64 chars !!! */
    strcpy(script->comment, cfg_getstr(pcfg, "comment"));	/* max 128 chars !!! */

    script->script_num = cfg_getint(pcfg, "id");
    script->version = cfg_getint(pcfg, "version");
    script->unused1 = cfg_getint(pcfg, "unused1");

    script->script_length = cfg_size(pcfg, "script");
    if (script->script_length & 1) {
	printf("WARNING: odd number of bytes in script ... truncating\n");
    }
    script->script_length >>= 1;
    for (i = 0; i < (script->script_length << 1); i++)
	script->script[i] = (uint8_t) cfg_getnint(pcfg, "script", i);

    cfg_free(pcfg);
    return 0;
}
Exemplo n.º 4
0
Arquivo: cfg.c Projeto: Bagarre/RProxy
/**
 * @brief parses a downstream {} config entry from a server { } config.
 *
 * @param cfg
 *
 * @return
 */
downstream_cfg_t *
downstream_cfg_parse(cfg_t * cfg) {
    downstream_cfg_t * dscfg;

    assert(cfg != NULL);

    dscfg                        = downstream_cfg_new();
    assert(dscfg != NULL);

    dscfg->name                  = strdup(cfg_title(cfg));
    dscfg->enabled               = cfg_getbool(cfg, "enabled");
    dscfg->host                  = strdup(cfg_getstr(cfg, "addr"));
    dscfg->port                  = cfg_getint(cfg, "port");
    dscfg->n_connections         = cfg_getint(cfg, "connections");
    dscfg->high_watermark        = cfg_getint(cfg, "high-watermark");

    dscfg->read_timeout.tv_sec   = cfg_getnint(cfg, "read-timeout", 0);
    dscfg->read_timeout.tv_usec  = cfg_getnint(cfg, "read-timeout", 1);
    dscfg->write_timeout.tv_sec  = cfg_getnint(cfg, "write-timeout", 0);
    dscfg->write_timeout.tv_usec = cfg_getnint(cfg, "write-timeout", 1);
    dscfg->retry_ival.tv_sec     = cfg_getnint(cfg, "retry", 0);
    dscfg->retry_ival.tv_usec    = cfg_getnint(cfg, "retry", 1);

    if (dscfg->enabled == true) {
        _rusage.total_num_connections += dscfg->n_connections;
    }

    return dscfg;
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
0
/*
Function to parse the server config file.
@param Config file location in the file system.
@param Struct to write results into.
@return -1 on failure, 0 on success.
*/
int parse_config(char * config_file, struct config_struct * running_config)
{
  print_to_log("Parsing config file", LOG_INFO);
  cfg_opt_t opts[] =
	{
	  CFG_STR("domain", "", CFGF_NONE),
    CFG_INT("connection_timeout_in_seconds", 0, CFGF_NONE),
    CFG_INT("max_connections", 0, CFGF_NONE),
	  CFG_END()
	};
	cfg_t *cfg;
	cfg = cfg_init(opts, CFGF_NONE);
	 if(cfg_parse(cfg, config_file) == CFG_PARSE_ERROR)
   {
     printf("Reading config %s has failed\n", config_file);
     return -1;
   }
   if (strcmp(cfg_getstr(cfg, "domain"),"")!=0)
   {
     //Load domain into struct here.
   }
   if (cfg_getint(cfg, "connection_timeout_in_seconds")<=60)
   {
     //load connection_timeout_in_seconds into struct here.
     running_config->connection_timeout_in_seconds = cfg_getint(cfg, "connection_timeout_in_seconds");
   }
   if (cfg_getint(cfg, "max_connections")<=1000)
   {
     //load connection_timeout_in_seconds into struct here.
     running_config->max_connections = cfg_getint(cfg, "max_connections");
   }
   return 0;
}
Exemplo n.º 7
0
//
// E_ProcessMiscVars
//
// Miscellaneous optional EDF settings.
//
static void E_ProcessMiscVars(cfg_t *cfg)
{
   // allow setting of title length for DOOM II
   if(cfg_size(cfg, ITEM_D2TITLETICS) > 0)
      GameModeInfoObjects[commercial]->titleTics = cfg_getint(cfg, ITEM_D2TITLETICS);

   // allow setting a pause time for the intermission
   if(cfg_size(cfg, ITEM_INTERPAUSE) > 0)
      wi_pause_time = cfg_getint(cfg, ITEM_INTERPAUSE);

   if(cfg_size(cfg, ITEM_INTERFADE) > 0)
   {
      wi_fade_color = cfg_getint(cfg, ITEM_INTERFADE);
      if(wi_fade_color < 0)
         wi_fade_color = 0;
      else if(wi_fade_color > 255)
         wi_fade_color = 255;
   }

   if(cfg_size(cfg, ITEM_INTERTL) > 0)
   {
      wi_tl_level = cfg_getint(cfg, ITEM_INTERTL);
      if(wi_tl_level < 0)
         wi_tl_level = 0;
      else if(wi_tl_level > 65536)
         wi_tl_level = 65536;
   }
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
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);

    return 0;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
//
// Process an individual switch
//
static void E_processSwitch(cfg_t *cfg)
{
   const char *title    = cfg_title(cfg);
   ESwitchDef *def      = e_switch_namehash.objectForKey(title);
   const bool  modified = !!def;
   if(!def)
   {
      def = new ESwitchDef;
      def->offpic = title;
      e_switch_namehash.addObject(def);
      eswitches.add(def);
      E_EDFLogPrintf("\t\tDefined switch %s\n", title);
   }
   else
      E_EDFLogPrintf("\t\tModified switch %s\n", title);

   auto isset = [modified, cfg](const char *field) {
      return !modified || cfg_size(cfg, field) > 0;
   };

   if(isset(ITEM_SWITCH_ONPIC))
      def->onpic    = cfg_getstr(cfg, ITEM_SWITCH_ONPIC);
   if(isset(ITEM_SWITCH_ONSOUND))
      def->onsound  = cfg_getstr(cfg, ITEM_SWITCH_ONSOUND);
   if(isset(ITEM_SWITCH_OFFSOUND))
      def->offsound = cfg_getstr(cfg, ITEM_SWITCH_OFFSOUND);
   if(isset(ITEM_SWITCH_GAMEINDEX))
      def->episode  = cfg_getint(cfg, ITEM_SWITCH_GAMEINDEX);
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
Arquivo: svc.c Projeto: Zhanyin/taomee
/* return: -1: invalid, 0: valid */
int cb_validate_svcinfo(cfg_t *cfg, cfg_opt_t *opt)
{
	char *name;
	/* only validate the last svcinfo */
	cfg_t *sec = cfg_opt_getnsec(opt, cfg_opt_size(opt) - 1);
	if(!sec) {
		cfg_error(cfg, "section is NULL?!");
		return -1;
	}

	if (cfg_title(sec) == NULL) {
		cfg_error(cfg, "every svcinfo must have a name, but %d seems not",
				cfg_opt_size(opt) - 1);
		return -1;
	}

	name = cfg_getstr(sec, "name");
	if(name == 0 || strlen(name) >= MAX_SVC_NAME_LEN) {
		cfg_error(cfg, "name option must be set for svcinfo '%s'"
				" or strlen(name)(%zd) >= len(%u)",
				cfg_title(sec), strlen(name), MAX_SVC_NAME_LEN);
		return -1;
	}

	if(cfg_getint(sec, "gameid") <= 0) {
		cfg_error(cfg, "gameid option must be set for svcinfo '%s'",
				cfg_title(sec));
		return -1;
	}

	return 0;
}
Exemplo n.º 16
0
db_info * get_db_info(const char * filename){

   cfg_opt_t * opts = get_opt();

   cfg_t *cfg;

   cfg = cfg_init(opts, CFGF_NONE);
   cfg_parse(cfg, filename);

   db_info * info;
   info = (db_info*)malloc(sizeof(db_info));

   char * user = cfg_getstr(cfg, "user");
   char * password = cfg_getstr(cfg,"password");
   char * dbname = cfg_getstr(cfg,"dbname");
   char * ip = cfg_getstr(cfg,"ip");
   
   info->user = (char*)malloc(strlen(user)*sizeof(char));
   info->password = (char*)malloc(strlen(user)*sizeof(char));
   info->dbname = (char*)malloc(strlen(user)*sizeof(char));
   info->ip = (char*)malloc(strlen(user)*sizeof(char));
   
   strcpy(info->user,user);
   strcpy(info->password,password);
   strcpy(info->dbname,dbname);
   strcpy(info->ip,ip);
   info->port = cfg_getint(cfg,"port");

   cfg_free(cfg);

   return info;
}
Exemplo n.º 17
0
long int
get_max_space_tier(struct program_params *pp, const char *lv_name,
    int tier)
{
    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 (cfg_getint(pv_cfg, "tier") == tier) {
            return cfg_getint(pv_cfg, "maxUsedSpace");
        }
    }

    return -1;
}
Exemplo n.º 18
0
int Settings::getIntSetting(Node type, int intDeviceId, const std::wstring &name, bool parameter) const {
	// already locked
	if (d->cfg == 0) {
		return 0;
	}
	std::string strType = getNodeString(type);
	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") == intDeviceId) {
			if (parameter) {
				cfg_node = cfg_getsec(cfg_node, "parameters");
			}
			return cfg_getint(cfg_node, TelldusCore::wideToString(name).c_str());
		}
	}
	return 0;
}
Exemplo n.º 19
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;
}
Exemplo n.º 20
0
svm_model_info * get_svm_model_info(const char * filename){
  cfg_opt_t * opts = get_opt();
  cfg_t *cfg;

  cfg = cfg_init(opts, CFGF_NONE);
  cfg_parse(cfg, filename);

  svm_model_info * info;
  info = (svm_model_info*)malloc(sizeof(svm_model_info));

  info->svm_type = cfg_getint(cfg,"svm_type");
  info->kernel_type = cfg_getint(cfg,"kernel_type");
  info->C = cfg_getfloat(cfg,"C");
  info->gamma = cfg_getfloat(cfg,"gamma");

  cfg_free(cfg);

   return info;
}
Exemplo n.º 21
0
/*
* Get next available node id
*/
int Settings::getNextNodeId(Node type) const {
	// Private, no locks needed
	int intNodeId = 0;
	cfg_t *cfg_node;
	std::string strType;
	if (type == Device) {
		strType = "device";
	} else if (type == Controller) {
		strType = "controller";
	}
	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)  {
			intNodeId = cfg_getint(cfg_node, "id");
		}
	}
	intNodeId++;
	return intNodeId;
}
Exemplo n.º 22
0
gint config_getint (const gchar *key)
{
	gint temp;

	config_mutex_lock ();
	temp = cfg_getint (tc, key);
	config_mutex_unlock ();

	return temp;
}
Exemplo n.º 23
0
/** Initializer for this "SOM" */
void som_init(cfg_t *som_config) {
	if (!som_config) return;

	const char *protocol = cfg_getstr(som_config, "protocol");
	channel = cfg_getstr(som_config, "channel");

	info("Scheduler is initializing protocol [ \"%s\" ] on channel %s",
			protocol,channel);

	chunkbuffer = chbInit("size=256,time=now");
	if (!chunkbuffer) 
		fatal("Error initialising the Chunk Buffer");
	chbRegisterNotifier(chunkbuffer, chunkbuffer_notifier, NULL);

	int publishPeerIDPeriod =  cfg_getint(som_config,
			"publishPeerIDPeriod");
	if (publishPeerIDPeriod) 
		napaSchedulePeriodic(NULL, 1.0/(float)publishPeerIDPeriod,
				publish_PeerID, NULL);

	/* If we are passive, we need to figure out who is the server, and send
	 * a message to it for ML to be able to work... Sigh... */
	if (!strcmp(protocol, "passive")) {
		struct timeval t = { 0, 0 };
		event_base_once(eventbase, -1, EV_TIMEOUT, &findServer, NULL, &t);
	}

	/* If the string "neighborlist" is present in the protocol name, we
	 * launch a neighborlist instance */
	if (strstr(protocol, "neighborlist")) {
		cfg_t *nlist_cfg = cfg_getsec(som_config, "neighborlist");
		neighbors_size = cfg_getint(nlist_cfg, "size");

		neighbors = calloc(sizeof(NeighborListEntry), neighbors_size);

		neighborlist = neighborlist_init(repository, 
			neighbors_size,
			cfg_getint(nlist_cfg, "refreshPeriod"),
			channel,
			neighborlist_cb, NULL);
	}
}
Exemplo n.º 24
0
void read_cfg_section(section_t *section, cfg_t *cfg_sec, std::stringstream &errors)
{
   static const char *funcname = "conf::read_cfg_section";

   for (auto &entry : *section)
   {
      char *name = const_cast<char *>(entry.first.c_str());
      bool required = entry.second.is_required();

      switch (entry.second.what_type())
      {
         case val_type::integer:
         {
            integer_t val;
            if (0 == (val = cfg_getint(cfg_sec, name))) {
               if (required) errors << "Required int-option '" << name << "' is not set." << std::endl; }
            else entry.second.set(val);
            break;
         }

         case val_type::string:
         {
            char *val;
            if (nullptr == (val = cfg_getstr(cfg_sec, name))) {
               if (required) errors << "Required str-option '" << name << "' is not set." << std::endl; }
            else entry.second.set(val);
            break;
         }

         case val_type::multistring:
         {
            if (nullptr == cfg_getstr(cfg_sec, name)) {
               if (required) errors << "Required multistr-option '" << name << "' is not set." << std::endl; }
            else
            {
               int count = cfg_size(cfg_sec, name);
               multistring_t strs;

               for (int i = 0; i < count; i++) 
                  strs.push_back(std::move(string_t(cfg_getnstr(cfg_sec, name, i))));
               entry.second.set(strs);
            }
            break;
         }

         case val_type::section:
            read_cfg_section(entry.second.get<conf::section_t *>(), cfg_getsec(cfg_sec, name), errors);
            break;

         case val_type::unknown:
            throw logging::error(funcname, "Val with unknown type in section: %s", name);   
      }
   }
}
Exemplo n.º 25
0
Arquivo: conf.c Projeto: noushi/bmon
void conf_init(void)
{
	cfg_read_interval = cfg_getfloat(cfg, "read_interval");
	cfg_rate_interval = cfg_getfloat(cfg, "rate_interval");
	cfg_rate_variance = cfg_getfloat(cfg, "variance") * cfg_rate_interval;
	cfg_history_variance = cfg_getfloat(cfg, "history_variance");
	cfg_show_all = cfg_getbool(cfg, "show_all");
	cfg_unit_exp = cfg_getint(cfg, "unit_exp");

	element_parse_policy(cfg_getstr(cfg, "policy"));
}
Exemplo n.º 26
0
static inline
void init_listen_socket(void)
{
	LOG_TRACEME

	int port = cfg_getint(cfg, "port");
	const char *host = cfg_getstr(cfg, "host");

	if ((sfd = tcp_listen(host, port, 20)) == -1)
		log_perror_and_die("tcp_listen(%s,%hu)", host, port);

	log_info("accepting incomming connections on %s:%d", host, port);
}
Exemplo n.º 27
0
Arquivo: conf.c Projeto: noushi/bmon
static void configfile_read_element_cfg(void)
{
	int i, nelement;

	nelement = cfg_size(cfg, "element");

	for (i = 0; i < nelement; i++) {
		struct element_cfg *ec;
		cfg_t *element;
		const char *name, *description;
		long max;

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

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

		ec = element_cfg_alloc(name);

		if ((description = cfg_getstr(element, "description")))
			ec->ec_description = strdup(description);

		if ((max = cfg_getint(element, "max")))
			ec->ec_rxmax = ec->ec_txmax = max;

		if ((max = cfg_getint(element, "rxmax")))
			ec->ec_rxmax = max;

		if ((max = cfg_getint(element, "txmax")))
			ec->ec_txmax = max;

		if (cfg_getbool(element, "show"))
			ec->ec_flags |= ELEMENT_CFG_SHOW;
		else
			ec->ec_flags |= ELEMENT_CFG_HIDE;
	}
}
Exemplo n.º 28
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;
}
Exemplo n.º 29
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;
}
Exemplo n.º 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;
}