示例#1
0
void read_config(void)
{
    static cfg_opt_t arg_opts[] = {
        CFG_STR("value", "default", CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t opts[] = {
        CFG_INT("delay", 3, CFGF_NONE),
        CFG_STR("message", "This is a message", CFGF_NONE),
        CFG_SEC("argument", arg_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_END()
    };

    char *buf = "" \
        " delay = 3\n" \
        "# message = \"asdfasfasfd tersf\"\n" \
        " argument one { value = 1 }\n" \
        " argument two { value=foo}\n";

    cfg_free(cfg);

    cfg = cfg_init(opts, 0);
    cfg_parse_buf(cfg, buf);
    cfg_parse(cfg, config_filename);
}
示例#2
0
bool SyncLogger::ParseFile(const char* pszHash)
{
	if (strcmp(m_szCurShare, pszHash) == 0)
	{
		// File is currently parsed, there is no need to parse it again.
		return true;
	}

    cfg_opt_t modEntry[] =
    {
        // Parses within the group.
        CFG_STR(FILE_PATH_VARNAME, FILE_PATH_DEFAULT, CFGF_NONE),
        CFG_STR(MOD_TIME_VARNAME, MOD_TIME_DEFAULT, CFGF_NONE),
        CFG_STR(MOD_TYPE_VARNAME, MOD_TYPE_DEFAULT, CFGF_NONE),
        CFG_END()
    };
    cfg_opt_t entries[] =
    {
        // Parses the single groups.
        CFG_SEC(MOD_NUMBER_VARNAME, modEntry, CFGF_TITLE | CFGF_MULTI),
        CFG_END()
    };

    // Initializes the parser.
    m_pCFG = cfg_init(entries, CFGF_NONE);

    // Parses the file.
	char szLogName[MAX_PATH];
	CalcLogFileName(pszHash, szLogName);
    if (cfg_parse(m_pCFG, szLogName) == CFG_PARSE_ERROR)
        return false;
    return true;
}
示例#3
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;
}
示例#4
0
cfg_t *parse_conf(const char *filename)
{
    cfg_opt_t process_opts[] = {
        CFG_STR("comm", 0, CFGF_NODEFAULT),
        CFG_STR("args", 0, CFGF_NODEFAULT),
        CFG_STR("pre", 0, CFGF_NONE),
        CFG_END()
    };

    cfg_opt_t opts[] = {
        CFG_SEC("process", process_opts, CFGF_MULTI | CFGF_TITLE),
        CFG_INT("frequency", 10, CFGF_NONE),
        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;
}
示例#5
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;
}
示例#6
0
文件: config.cpp 项目: oioi/zbx_tools
cfg_opt_t * build_section(section_t *section, section_ptrs &ptrs)
{
   static const char *funcname = "conf::build_section";

   cfg_opt_t *ptr = new cfg_opt_t[section->size() + 1];
   ptrs.push_back(std::unique_ptr<cfg_opt_t []>(ptr));

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

      switch (entry.second.what_type())
      {
         case val_type::integer:     *ptr = CFG_INT(name, 0, CFGF_NODEFAULT); break;
         case val_type::string:      *ptr = CFG_STR(name, 0, CFGF_NODEFAULT); break;
         case val_type::multistring: *ptr = CFG_STR_LIST(name, 0, CFGF_NODEFAULT); break;
         case val_type::section:     *ptr = CFG_SEC(name, build_section(entry.second.get<conf::section_t *>(), ptrs), CFGF_NONE); break;

         case val_type::unknown:
            throw logging::error(funcname, "Val with unknown type in section: %s", name);
      }
      ptr++;
   }

   *ptr = CFG_END();
   return ptrs.back().get();
}
示例#7
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";

	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);

	fail_unless(cfg_addtsec(cfg, "section", "title_three"));
	fail_unless(cfg_size(cfg, "section") == 3);
	fail_unless(cfg_title(cfg_gettsec(cfg, "section", "title_three")));

	/* attempt to add a pre-existing section should fail */
	fail_unless(!cfg_addtsec(cfg, "section", "title_three"));

	cfg_free(cfg);

	return 0;
}
示例#8
0
bool readVarConfig(cfg_t **cfg) {
	cfg_opt_t device_opts[] = {
		CFG_INT(const_cast<char *>("state"), 0, CFGF_NONE),
		CFG_STR(const_cast<char *>("stateValue"), const_cast<char *>(""), CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_SEC(const_cast<char *>("device"), device_opts, CFGF_MULTI | CFGF_TITLE),
		CFG_END()
	};

	FILE *fp = fopen(VAR_CONFIG_FILE, "re");  // e for setting O_CLOEXEC on the file handle
	if (!fp) {
		Log::warning("Unable to open var config file, %s", VAR_CONFIG_FILE);
		return false;
	}
	(*cfg) = cfg_init(opts, CFGF_NOCASE);
	if (cfg_parse_fp((*cfg), fp) == CFG_PARSE_ERROR) {
		(*cfg) = 0;
		fclose(fp);
		Log::warning("Unable to parse var config file, %s", VAR_CONFIG_FILE);
		return false;
	}

	fclose(fp);
	return true;
}
示例#9
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;
}
示例#10
0
文件: cli.c 项目: peda-r/libconfuse
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;
}
示例#11
0
/**
 * Parses the config file
 *
 * @return a pointer to the configuration data structure, NULL on failure
 */
static cfg_t * parse_config(void) {
	cfg_t * cfg = NULL;

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

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

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

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

	cfg = cfg_init(opts, CFGF_NONE);

	cfg_set_error_function(cfg, conf_error);

	switch (cfg_parse(cfg, config_file)) {
		case CFG_FILE_ERROR: LM_ERR("file not found: %s\n", config_file);
			return NULL;
		case CFG_PARSE_ERROR: LM_ERR("error while parsing %s in line %i, section %s\n",
			                          cfg->filename, cfg->line, cfg->name);
			return NULL;
		case CFG_SUCCESS: break;
	}
	return cfg;
}
示例#12
0
BOOL saveConfFile(user_input_data *user_dat)
{
    FILE *U2Mconf_file = fopen(cfg_filename, "w");

    if (!U2Mconf_file) return FALSE;

    cfg_opt_t email_opts[] = {
        CFG_STR("From", user_dat->FROM, CFGF_NONE),
        CFG_STR("To", user_dat->TO, CFGF_NONE),
        CFG_STR("Cc", user_dat->CC, CFGF_NONE),
        CFG_STR("Subject", user_dat->SUBJECT, CFGF_NONE),
        CFG_STR("Body", user_dat->BODY, CFGF_NONE),
        CFG_STR("Password", user_dat->pass, CFGF_NONE),
        CFG_STR("SMTP_server", user_dat->SMTP_SERVER, CFGF_NONE),
        CFG_INT("Port_number", (int)user_dat->PORT, CFGF_NONE),
        CFG_END()
    };

    cfg_t *U2MConf = cfg_init(email_opts, CFGF_NONE);
    cfg_print(U2MConf, U2Mconf_file);

    fclose(U2Mconf_file);
    cfg_free(U2MConf);

    return TRUE;
}
示例#13
0
void validate_setup(void)
{
	cfg_opt_t *opt = 0;

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

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

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

	cfg = cfg_init(opts, 0);

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

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

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

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

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

	/* Validate callbacks for *set*() functions, i.e. not when parsing file content */
	cfg_set_validate_func2(cfg, "multi_options|speed", validate_speed2);
	cfg_set_validate_func2(cfg, "multi_options|options|name", validate_name2);
}
示例#14
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;
}
示例#15
0
文件: unagi.c 项目: ehntoo/unagi
/** Parse the configuration file with confuse
 *
 * \param config_fp The configuration file stream
 * \return Return true if parsing succeeded
 */
static bool
parse_configuration_file(FILE *config_fp)
{
  cfg_opt_t opts[] = {
    CFG_STR("rendering", "render", CFGF_NONE),
    CFG_STR_LIST("plugins", "{}", CFGF_NONE),
    CFG_END()
  };

  globalconf.cfg = cfg_init(opts, CFGF_NONE);
  if(cfg_parse_fp(globalconf.cfg, config_fp) == CFG_PARSE_ERROR)
    return false;

  return true;
}
示例#16
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;
}
示例#17
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;
}
示例#18
0
cfg_opt_t * get_opt(){
  static cfg_opt_t opts[] = {
                         CFG_STR("user", "root", CFGF_NONE),
                         CFG_STR("password", "", CFGF_NONE),
                         CFG_STR("dbname", "", CFGF_NONE),
                         CFG_STR("ip", "127.0.0.1", CFGF_NONE),
                         CFG_INT("port", 5432, CFGF_NONE),
                         CFG_STR("db_query", "", CFGF_NONE),
                         CFG_INT("svm_type",0, CFGF_NONE),
                         CFG_INT("kernel_type",0,CFGF_NONE),
                         CFG_FLOAT("gamma",0,CFGF_NONE),
                         CFG_FLOAT("C",1,CFGF_NONE),
                         CFG_STR("model_filename", "file.model", CFGF_NONE),
                         CFG_STR("model_list_path","",CFGF_NONE),
                         CFG_STR_LIST("model_list","{}",CFGF_NONE),
                         CFG_STR_LIST("query_list","{}",CFGF_NONE),
                         CFG_STR_LIST("model_label_list","{}",CFGF_NONE),
                         CFG_END()
                        };
      return opts;                  
}
示例#19
0
文件: conf.c 项目: hoong/turnserver
 * \brief Free the resources used by the lex parser.
 *
 * This function comes from libconfuse and is not called
 * in cfg_free(), that's why call it here.
 * \note Require libconfuse >= 2.6.
 * \return 0
 */
extern int cfg_yylex_destroy(void);

/**
 * \var denied_address_opts
 * \brief Denied address option.
 */
static cfg_opt_t denied_address_opts[] =
{
  CFG_STR("address", "", CFGF_NONE),
  CFG_INT("mask", 24, CFGF_NONE),
  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),
示例#20
0
#include <stdio.h>
#include <stdlib.h> /* atoi */
#include <unistd.h> /* fsync */

#include "configsys.h"

static cfg_t *tc;

/* CONFIGURATION OPTIONS
 * In this array we set the default configuration options for the
 * configuration file.
 */
static cfg_opt_t config_opts[] = {

    /* strings */
    CFG_STR("tilda_config_version", PACKAGE_VERSION, CFGF_NONE),
    CFG_STR("image", NULL, CFGF_NONE),
    CFG_STR("command", "", CFGF_NONE),
    CFG_STR("font", "Monospace 11", CFGF_NONE),
    CFG_STR("key", NULL, CFGF_NONE),
    CFG_STR("addtab_key", "<Shift><Control>t", CFGF_NONE),
    CFG_STR("fullscreen_key", "F11", CFGF_NONE),
    CFG_STR("closetab_key", "<Shift><Control>w", CFGF_NONE),
    CFG_STR("nexttab_key", "<Control>Page_Down", CFGF_NONE),
    CFG_STR("prevtab_key", "<Control>Page_Up", CFGF_NONE),
    CFG_STR("movetableft_key", "<Shift><Control>Page_Up", CFGF_NONE),
    CFG_STR("movetabright_key", "<Shift><Control>Page_Down", CFGF_NONE),
    CFG_STR("gototab_1_key", "<Alt>1", CFGF_NONE),
    CFG_STR("gototab_2_key", "<Alt>2", CFGF_NONE),
    CFG_STR("gototab_3_key", "<Alt>3", CFGF_NONE),
    CFG_STR("gototab_4_key", "<Alt>4", CFGF_NONE),
示例#21
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;
}
示例#22
0
#include <netinet/in.h>
#include <sys/socket.h>
#include <time.h>

#include "peer.h"

#include <chunk.h>
#include <mon.h>
#include <ul.h>

#define MAX_PACKET_SIZE			2048
#define INITIAL_PKTBUFFER_NUM	10

/** Configuration options for the Source */
cfg_opt_t cfg_source[] = {
	CFG_STR("stream", NULL, CFGF_NONE),
	CFG_FLOAT("chunk_duration", 1.0, CFGF_NONE),
	CFG_END()
};

/** This function gets called periodically and arranges the publishing of a
 * MeasurementRecord with SrcLag = 0.0 
 */
void periodicPublishSrcLag(HANDLE h, void *arg) {
	MeasurementRecord mr;
	memset(&mr, 0, sizeof(mr));
	mr.published_name = "SrcLag";
	mr.value = 0.0;
	mr.originator = mr.targetA = mr.targetB = LocalPeerID;
	mr.channel = channel;
	publishMeasurementRecord(&mr, "SrcLag");
示例#23
0
/*
 * read configuration file
 */
int
read_config(struct program_params *pp)
{
    static cfg_opt_t pv_opts[] = {
        CFG_INT("tier", 0, CFGF_NONE),
        CFG_FLOAT("pinningScore", 0, CFGF_NONE),
        CFG_STR("path", NULL, CFGF_NONE),
        CFG_INT_CB("maxUsedSpace", -1, CFGF_NONE, parse_size_value),
        CFG_END()
    };

    static cfg_opt_t volume_opts[] = {
        CFG_STR("LogicalVolume", NULL, CFGF_NONE),
        CFG_STR("VolumeGroup",   NULL, CFGF_NONE),
        CFG_FLOAT("timeExponent",  1.0/(2<<14), CFGF_NONE),
        CFG_FLOAT("hitScore",      16, CFGF_NONE),
        CFG_FLOAT("readMultiplier", 1, CFGF_NONE),
        CFG_FLOAT("writeMultiplier", 4, CFGF_NONE),
        CFG_INT_CB("pvmoveWait",     5*60, CFGF_NONE, parse_time_value),
        CFG_INT_CB("checkWait",      15*60, CFGF_NONE, parse_time_value),
        CFG_SEC("pv", pv_opts, CFGF_TITLE | CFGF_MULTI),
        CFG_END()
    };

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

    cfg_t *cfg;

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

    // add verification functions
    cfg_set_validate_func(cfg, "volume|timeExponent",
        validate_require_positive);
    cfg_set_validate_func(cfg, "volume|hitScore",
        validate_require_positive);
    cfg_set_validate_func(cfg, "volume|readMultiplier",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|writeMultiplier",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|pv|pinningScore",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|pv|tier",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|pv|maxUsedSpace",
        validate_require_nonnegative);
    // TODO cfg_set_validate_func(cfg, "volume", validate_pv); // do they belong to volume, is there enough space

    switch(cfg_parse(cfg, pp->conf_file_path)) {
      case CFG_FILE_ERROR:
        fprintf(stderr, "Configuration file \"%s\" could not be read: %s\n",
            pp->conf_file_path, strerror(errno));
        return 1;
      case CFG_SUCCESS:
        break;
      case CFG_PARSE_ERROR:
        fprintf(stderr, "Configuration file errors, aborting\n");
        return 1;
      default:
        fprintf(stderr, "Internal error");
        assert(0);
    }

    pp->cfg = cfg;

    return 0;
}
示例#24
0
文件: pk2dft.c 项目: GBert/misc
    int num_scripts;
    uint8_t compat;
    uint8_t unused1a;
    uint16_t unused1b;
    uint32_t unused2;
} dat_hdr_t;

cfg_opt_t config_opts[] = {
    CFG_INT("ver_major", 0, CFGF_NONE),
    CFG_INT("ver_minor", 0, CFGF_NONE),
    CFG_INT("ver_dot", 0, CFGF_NONE),
    CFG_INT("compat", 0, CFGF_NONE),
    CFG_INT("unused1a", 0, CFGF_NONE),
    CFG_INT("unused1b", 0, CFGF_NONE),
    CFG_INT("unused2", 0, CFGF_NONE),
    CFG_STR("notes", "", CFGF_NONE),
    CFG_STR_LIST("families", "", CFGF_NONE),
    CFG_STR_LIST("devices", "", CFGF_NONE),
    CFG_STR_LIST("scripts", "", CFGF_NONE),
    CFG_END()
};

cfg_opt_t script_opts[] = {
    CFG_STR("org_name", "", CFGF_NONE),
    CFG_STR("name", "NO_SCRIPT", CFGF_NONE),
    CFG_INT("id", 0, CFGF_NONE),
    CFG_INT("version", 0, CFGF_NONE),
    CFG_INT("unused1", 0, CFGF_NONE),
    CFG_INT_LIST("script", 0, CFGF_NONE),
    CFG_STR("comment", "", CFGF_NONE)
};
示例#25
0
/* Test cfg_include when called from a buffer
 */

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

cfg_opt_t opts[] =
{
        CFG_STR("parameter", NULL, CFGF_NONE),
        CFG_END()
};

static int
testconfig(const char *buf, const char *parameter)
{
	cfg_t *cfg = cfg_init(opts, CFGF_NONE);
        if (!cfg)
            return 0;

	if (cfg_parse_buf(cfg, buf) != CFG_SUCCESS)
            return 0;

        char *param = cfg_getstr(cfg, "parameter");
        if (!param)
            return 0;

        if (strcmp(param, parameter) != 0)
            return 0;
int
configuration(struct app_parent *app_p,
              const char *configfile,
              char **policy_file,
              char **syslog_ident,
              int *syslog_flags,
              int *syslog_facility) {
    unsigned int i, j;
    struct tq_listener_s *p_listener = NULL;
    struct tq_service_s *p_service = NULL;
    char *buf = NULL;
    cfg_t *cfg;
    cfg_t *syslog_sec;
    unsigned n_listener, n_services;
    int ret;
    static cfg_opt_t syslog_opts[] = {
        CFG_STR("ident", NULL, CFGF_NONE),
        CFG_INT_CB("facility", NONE, CFGF_NONE, &cb_syslog_facility),
        CFG_INT_LIST_CB("options", NULL, CFGF_NONE, &cb_syslog_options),
        CFG_END()
    };
    static cfg_opt_t service_opts[] = {
        CFG_INT_CB("type", NONE, CFGF_NONE, &cb_service_type),
        CFG_STR("uri", 0, CFGF_NONE),
        CFG_INT("threads", 4, CFGF_NONE),
        CFG_END()
    };
    static cfg_opt_t listener_opts[] = {
        CFG_STR("bindaddress", 0, CFGF_NONE),
        CFG_INT("port", 9001, CFGF_NONE),
        CFG_INT("backlog", 1024, CFGF_NONE),
        CFG_STR("cert", 0, CFGF_NONE),
        CFG_STR("key", 0, CFGF_NONE),
        CFG_STR("cafile", 0, CFGF_NONE),
        CFG_STR("capath", 0, CFGF_NONE),
        CFG_STR("crlpath", 0, CFGF_NONE),
        CFG_STR("password", 0, CFGF_NONE),
        CFG_STR("cipherlist", 0, CFGF_NONE),
        CFG_INT_CB("clientauth", NONE, CFGF_NONE, &cb_answer),
        CFG_INT_CB("rfc3820", NONE, CFGF_NONE, &cb_answer),
        CFG_STR("whitelist", 0, CFGF_NONE),
        CFG_STR("blacklist", 0, CFGF_NONE),
        CFG_SEC("service", service_opts, CFGF_MULTI),
        CFG_END()
    };
    cfg_opt_t opts[] = {
        CFG_INT_CB("debug", NONE, CFGF_NONE, &cb_answer),
        CFG_STR("policyfile", 0, CFGF_NONE),
        CFG_SEC("syslog", syslog_opts, CFGF_NONE),
        CFG_SEC("listener", listener_opts, CFGF_MULTI),
        CFG_END()
    };

    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, configfile);
    if (ret == CFG_FILE_ERROR) {
        fprintf(stderr, "Error: could not open or read the configuration file "
               "\"%s\".\n", configfile);
        return GA_BAD;
    } else if (ret == CFG_PARSE_ERROR) {
        fprintf(stderr, "Error: parse error in the configuration file "
               "\"%s\".\n", configfile);
        return GA_BAD;
    }

    /* Generic */
    app_p->debug = cfg_getint(cfg, "debug");
    if (app_p->debug == MAYBE || app_p->debug == OPTIONAL) {
        printf("Overriding debug setting to 'yes'\n");
        app_p->debug = YES;
    } else if (app_p->debug == YES) {
        printf("= Service running in DEBUG mode =\n");
    }

    /* XACML Rules file */
    *policy_file = strdup(cfg_getstr(cfg, "policyfile"));
    if (*policy_file == NULL) {
        fprintf(stderr, "Error: no \"policyfile\" set in the configuration file\n");
        return GA_BAD;
    } else {
        if (app_p->verbose) {
            printf("Using XACML Policy file: \"%s\"\n", *policy_file);
        }
    }

    /* Syslog */
    syslog_sec = cfg_getsec(cfg, "syslog");
    if (syslog_sec == NULL) {
        fprintf(stderr, "Error: no \"syslog\" section found in the "
                        "configuration file \"%s\"\n", configfile);
    } else {
        *syslog_ident = strdup(cfg_getstr(syslog_sec, "ident"));
        *syslog_facility = cfg_getint(syslog_sec, "facility");

        if (app_p->debug == YES) {
            printf("found syslog\n");
            printf("    ident = %s\n", cfg_getstr(syslog_sec, "ident"));
            printf("    facility = %ld\n", cfg_getint(syslog_sec, "facility"));
            printf("BUG\n");

            for (i = 0; i < cfg_size(syslog_sec, "options"); i++) {
                printf("options[%d] == %ld\n", i, cfg_getnint(syslog_sec, "options", i));
            }
            printf("BUG\n");
        }

        /* Hardwired the settings */
        *syslog_flags = LOG_PID|LOG_NDELAY;

        if (app_p->verbose > 1) {
            *syslog_flags |= LOG_PERROR;
        }
    }

    /* Listeners */
    n_listener = cfg_size(cfg, "listener");
    if (app_p->verbose) {
        printf("%d configured listeners:\n", n_listener);
    }
    for (i = 0; i < n_listener; i++) {
        cfg_t *ls = cfg_getnsec(cfg, "listener", i);
        if (ls == NULL) {
            goto cleanup;
        }

        p_listener = malloc(sizeof(struct tq_listener_s));
        if (p_listener == NULL) {
            fprintf(stderr, "Error: memory allocation problem, couldn't allocate %lu bytes\n",
                    sizeof(struct tq_listener_s));
            goto cleanup;
        }
        memset(p_listener, 0, sizeof(struct tq_listener_s));
        TAILQ_INIT(&(p_listener->services_head));

        /* Settings */
        STRDUP_OR_GOTO_CLEANUP(p_listener->bindip,          cfg_getstr(ls, "bindaddress"));
        p_listener->port                           = (short)cfg_getint(ls, "port");
        p_listener->backlog                        = (short)cfg_getint(ls, "backlog");
        STRDUP_OR_GOTO_CLEANUP(p_listener->cert,            cfg_getstr(ls, "cert"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->key,             cfg_getstr(ls, "key"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->cafile,          cfg_getstr(ls, "cafile"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->capath,          cfg_getstr(ls, "capath"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->crlpath,         cfg_getstr(ls, "crlpath"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->cipherlist,      cfg_getstr(ls, "cipherlist") ?
                                                                cfg_getstr(ls, "cipherlist") :
                                                                "HIGH");
        STRDUP_OR_GOTO_CLEANUP(p_listener->cert_password,   cfg_getstr(ls, "password"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->whitelist_path,  cfg_getstr(ls, "whitelist"));
        STRDUP_OR_GOTO_CLEANUP(p_listener->blacklist_path,  cfg_getstr(ls, "blacklist"));
        p_listener->clientauth                     = (short)cfg_getint(ls, "clientauth");
        p_listener->rfc3820                        = (short)cfg_getint(ls, "rfc3820");

        /* Normalizer */
        if (p_listener->clientauth == MAYBE)
            p_listener->clientauth = OPTIONAL;
        if (p_listener->rfc3820 == MAYBE || p_listener->rfc3820 == OPTIONAL)
            p_listener->rfc3820 = YES;

        /* Create evhtp_ssl_cfg_t */
        if (create_evhtp_ssl_cfg_from_tq_listener(p_listener) == GA_BAD) {
            goto cleanup;
        }


        /* Services per listener */
        n_services = cfg_size(ls, "service");
        if (app_p->verbose) {
            printf("      %d\n", n_services);
        }
        for (j = 0; j < n_services; j++) {
            cfg_t *serv = cfg_getnsec(ls, "service", j);
            if (serv == NULL) {
                goto cleanup;
            }

            p_service = malloc(sizeof(struct tq_service_s));
            if (p_service == NULL) {
                fprintf(stderr, "Error: memory allocation problem, couldn't allocate %lu bytes\n",
                        sizeof(struct tq_service_s));
                goto cleanup;
            }
            memset(p_service, 0, sizeof(struct tq_service_s));

            p_service->parent_listener = p_listener;

            /* Thread count override in Debug mode - max is 1 worker thread */
            if (app_p->debug == YES) {
                p_service->thread_cnt = 1;
            } else {
                p_service->thread_cnt = (short)cfg_getint(serv, "threads");
            }

            p_service->ltype = cfg_getint(serv, "type");
            p_service->uri = cfg_getstr(serv, "uri");
            if (p_service->uri && p_service->uri[0] == '/') {
                p_service->uri = strdup(p_service->uri);
            } else {
                buf = malloc(strlen(p_service->uri) + 2);
                if (buf == NULL) {
                    goto cleanup;
                }
                snprintf(buf, strlen(p_service->uri) + 2, "/%s", p_service->uri);
                p_service->uri = buf;
            }
            if (app_p->verbose) {
                printf("       uri = %s\n", p_service->uri);
                printf("       type = %s\n", p_service->ltype == PDP ? "PDP" : p_service->ltype == PAP ? "PAP" : p_service->ltype == PEP ? "PEP" : "unknown");
            }

            TAILQ_INSERT_TAIL(&(p_listener->services_head), p_service, next);
        }

        TAILQ_INSERT_TAIL(&(app_p->listener_head), p_listener, next);
    }

    cfg_free(cfg);
    return GA_GOOD;
cleanup:
    cfg_free(cfg);
    return GA_BAD;

}
示例#27
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);
}
示例#28
0
#include "e_edf.h"
#include "e_lib.h"
#include "e_string.h"

// 03/27/05: EDF strings!

// String section keywords
#define ITEM_STRING_NUM    "num"
#define ITEM_STRING_VAL    "val"
#define ITEM_STRING_BEXDST "bexdest"
#define ITEM_STRING_BEXSRC "bexsource"

// String Options
cfg_opt_t edf_string_opts[] =
{
   CFG_STR(ITEM_STRING_VAL,    "", CFGF_NONE),
   CFG_INT(ITEM_STRING_NUM,    -1, CFGF_NONE),
   CFG_STR(ITEM_STRING_BEXDST, "", CFGF_NONE),
   CFG_STR(ITEM_STRING_BEXSRC, "", CFGF_NONE),
   CFG_END()
};

#define NUM_EDFSTR_CHAINS 257

static edf_string_t             *edf_str_chains[NUM_EDFSTR_CHAINS];
static DLListItem<edf_string_t> *edf_str_numchains[NUM_EDFSTR_CHAINS];

//
// haleyjd 08/05/05: To support editing the numeric keys of existing
// string objects, the numeric hash has to become a double-linked list.
// See the code in m_dllist.h to see how a generic double-linked list
示例#29
0
#include <errno.h>

#include <confuse.h>

#include "logger.h"
#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("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[] =
示例#30
0
文件: svc.c 项目: Zhanyin/taomee
/**
 * @brief 根据 conf 文件加载业务名称与gameid的对应关系;
 * @load_count 本次被加载的条数;
 * @return -1: failed, 0: succ
 */
int load_svc_gameid_map(const char *conf_path, uint32_t *load_count)
{
	uint32_t n, last;
	int i, ret;
	cfg_t *si;
	struct svc_gameid_map_t *sg;

    static cfg_opt_t svcinfo_opts[] = {
        CFG_STR("name", 0, CFGF_NONE),
        CFG_INT("gameid", 0, CFGF_NONE),
        CFG_END()
    };

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

	cfg_t *cfg = cfg_init(opts, CFGF_NONE);

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

	ret = cfg_parse(cfg, conf_path ? conf_path : DEF_SVC_CFG_PATH);
	if(ret == CFG_FILE_ERROR) {
		fprintf(stderr, "Access error, conf: %s, err: %s\n",
				conf_path ? conf_path : DEF_SVC_CFG_PATH, strerror(errno));
		return -1;
	} else if(ret == CFG_PARSE_ERROR) {
		fprintf(stderr, "Parse error, conf: %s\n",
				conf_path ? conf_path : DEF_SVC_CFG_PATH);
		return -1;
	}

	memset(sg_map_shadow, 0, sizeof(sg_map_shadow));

	n = cfg_size(cfg, "svcinfo");
	for(i = 0; i < n; i++) {
		if (i == MAX_SVC_NUM) break;

		si = cfg_getnsec(cfg, "svcinfo", i);
		sg = &(sg_map_shadow[i]);
		snprintf(sg->name, sizeof(sg->name), "%s", cfg_getstr(si, "name"));
		sg->gameid = cfg_getint(si, "gameid");
		cur_svcinfo_count_shadow++;
	}
	cfg_free(cfg);

	/* sort sg */
	qsort(sg_map_shadow, cur_svcinfo_count_shadow, sizeof(sg_map_shadow[0]), svcinfocmp);
	last = 0;
	for (i = 0; i < cur_svcinfo_count_shadow; i++) {
		sg = &(sg_map_shadow[i]);
		if (sg->gameid == last) {
			fprintf(stderr, "dup gameid: %u in conf: %s\n", last,
					conf_path ? conf_path : DEF_SVC_CFG_PATH);
			return -1;
		}

		if (sg->gameid > MAX_SVC_NUM) {
			fprintf(stderr, "gameid: %u > max(%u) in conf: %s\n",
					sg->gameid, MAX_SVC_NUM,
					conf_path ? conf_path : DEF_SVC_CFG_PATH);
			return -1;
		}
		last = sg->gameid;
	}

	svcinfo_enable = 0;
	memcpy(sg_map, sg_map_shadow, sizeof(sg_map));
	cur_svcinfo_count = cur_svcinfo_count_shadow;
	if (load_count) {
		*load_count = cur_svcinfo_count;
	}
	svcinfo_enable = 1;

	return 0;
}