1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-09-04 12:42:09 +03:00

Check option type

This commit is contained in:
bel
2014-02-22 10:17:03 +01:00
parent 96bfe243d5
commit aa4ebb5e9d

View File

@@ -199,18 +199,31 @@ static char *sdup(const char *str)
static int set_option(char **options, const char *name, const char *value) static int set_option(char **options, const char *name, const char *value)
{ {
int i, found; int i, type;
const struct mg_option *default_options = mg_get_valid_options(); const struct mg_option *default_options = mg_get_valid_options();
found = 0; type = CONFIG_TYPE_UNKNOWN;
for (i = 0; default_options[i].name != 0; i++) { for (i = 0; default_options[i].name != 0; i++) {
if (!strcmp(default_options[i].name, name)) { if (!strcmp(default_options[i].name, name)) {
found = 1; type = default_options[i].type;
} }
} }
if (!found) { switch (type) {
/* unknown option */ case CONFIG_TYPE_UNKNOWN:
return 0; /* unknown option */
return 0;
case CONFIG_TYPE_NUMBER:
if (atol(value)<1) {
/* invalid number */
return 0;
}
break;
case CONFIG_TYPE_BOOLEAN:
if ((0!=strcmp(value,"yes")) && (0!=strcmp(value,"no"))) {
/* invalid boolean */
return 0;
}
break;
} }
for (i = 0; i < MAX_OPTIONS - 3; i++) { for (i = 0; i < MAX_OPTIONS - 3; i++) {