1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-09-03 01:21:16 +03:00

Improve error handling in set_option

This commit is contained in:
bel
2014-08-16 01:12:22 +02:00
parent fc70af612a
commit de9870e7b9

View File

@@ -273,17 +273,32 @@ static int set_option(char **options, const char *name, const char *value)
/* unknown option */
return 0;
case CONFIG_TYPE_NUMBER:
/* integer number > 0, e.g. number of threads */
if (atol(value)<1) {
/* invalid number */
return 0;
}
break;
case CONFIG_TYPE_STRING:
/* any text */
break;
case CONFIG_TYPE_BOOLEAN:
/* boolean value, yes or no */
if ((0!=strcmp(value,"yes")) && (0!=strcmp(value,"no"))) {
/* invalid boolean */
return 0;
}
break;
case CONFIG_TYPE_FILE:
case CONFIG_TYPE_DIRECTORY:
/* TODO: check this option when it is set, instead of calling verify_existence later */
break;
case CONFIG_TYPE_EXT_PATTERN:
/* list of file extentions */
break;
default:
die("Unknown option type - option %s", name);
break;
}
for (i = 0; i < MAX_OPTIONS; i++) {
@@ -300,10 +315,14 @@ static int set_option(char **options, const char *name, const char *value)
}
if (i == MAX_OPTIONS) {
die("%s", "Too many options specified");
die("Too many options specified");
}
/* TODO: check if this option is defined and the correct data type, return 1 (OK) or 0 (false) */
if (options[2*i] == NULL || options[2*i + 1] == NULL) {
die("Out of memory");
}
/* option set correctly */
return 1;
}