forked from github/server
BUG 2301: validate [game] section in eressea.ini
load_inifile is old stuff, should use config_get instead.
This commit is contained in:
parent
7b4550b9d6
commit
4b88a5abc7
2 changed files with 28 additions and 8 deletions
|
@ -732,6 +732,17 @@ bool config_changed(int *cache_key) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char * valid_keys[] = {
|
||||||
|
"game.id",
|
||||||
|
"game.name",
|
||||||
|
"game.locale",
|
||||||
|
"game.verbose",
|
||||||
|
"game.email",
|
||||||
|
"game.mailcmd",
|
||||||
|
"game.sender",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#define MAXKEYS 16
|
#define MAXKEYS 16
|
||||||
void config_set_from(const dictionary *d)
|
void config_set_from(const dictionary *d)
|
||||||
{
|
{
|
||||||
|
@ -742,6 +753,8 @@ void config_set_from(const dictionary *d)
|
||||||
int k, nkeys = iniparser_getsecnkeys(d, sec);
|
int k, nkeys = iniparser_getsecnkeys(d, sec);
|
||||||
const char *keys[MAXKEYS];
|
const char *keys[MAXKEYS];
|
||||||
size_t slen = strlen(sec);
|
size_t slen = strlen(sec);
|
||||||
|
bool check = strcmp(sec, "game") == 0;
|
||||||
|
|
||||||
assert(nkeys <= MAXKEYS);
|
assert(nkeys <= MAXKEYS);
|
||||||
assert(slen<sizeof(key));
|
assert(slen<sizeof(key));
|
||||||
memcpy(key, sec, slen);
|
memcpy(key, sec, slen);
|
||||||
|
@ -756,6 +769,15 @@ void config_set_from(const dictionary *d)
|
||||||
val = iniparser_getstring(d, keys[k], NULL);
|
val = iniparser_getstring(d, keys[k], NULL);
|
||||||
if (!orig) {
|
if (!orig) {
|
||||||
if (val) {
|
if (val) {
|
||||||
|
if (check) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; valid_keys[i]; ++i) {
|
||||||
|
if (strcmp(key, valid_keys[i]) == 0) break;
|
||||||
|
}
|
||||||
|
if (!valid_keys[i]) {
|
||||||
|
log_error("unknown key in ini-section %s: %s = %s", sec, key, val);
|
||||||
|
}
|
||||||
|
}
|
||||||
config_set(key, val);
|
config_set(key, val);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
14
src/main.c
14
src/main.c
|
@ -68,8 +68,13 @@ static void load_inifile(dictionary * d)
|
||||||
}
|
}
|
||||||
|
|
||||||
lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0;
|
lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0;
|
||||||
|
|
||||||
verbosity = iniparser_getint(d, "game:verbose", 2);
|
verbosity = iniparser_getint(d, "game:verbose", 2);
|
||||||
|
memdebug = iniparser_getint(d, "game:memcheck", memdebug);
|
||||||
|
#ifdef USE_CURSES
|
||||||
|
/* only one value in the [editor] section */
|
||||||
|
force_color = iniparser_getint(d, "editor:color", force_color);
|
||||||
|
gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static dictionary *parse_config(const char *filename)
|
static dictionary *parse_config(const char *filename)
|
||||||
|
@ -89,13 +94,6 @@ static dictionary *parse_config(const char *filename)
|
||||||
if (d) {
|
if (d) {
|
||||||
load_inifile(d);
|
load_inifile(d);
|
||||||
config_set_from(d);
|
config_set_from(d);
|
||||||
|
|
||||||
memdebug = iniparser_getint(d, "game:memcheck", memdebug);
|
|
||||||
#ifdef USE_CURSES
|
|
||||||
/* only one value in the [editor] section */
|
|
||||||
force_color = iniparser_getint(d, "editor:color", force_color);
|
|
||||||
gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
str = config_get("game.locales");
|
str = config_get("game.locales");
|
||||||
make_locales(str ? str : "de,en");
|
make_locales(str ? str : "de,en");
|
||||||
|
|
Loading…
Reference in a new issue