浏览代码

Add config type for 3-state values

bel2125 7 年之前
父节点
当前提交
b5896bd5df
共有 3 个文件被更改,包括 11 次插入3 次删除
  1. 2 1
      include/civetweb.h
  2. 1 2
      src/civetweb.c
  3. 8 0
      src/main.c

+ 2 - 1
include/civetweb.h

@@ -663,7 +663,8 @@ enum {
 	MG_CONFIG_TYPE_BOOLEAN = 0x5,
 	MG_CONFIG_TYPE_EXT_PATTERN = 0x6,
 	MG_CONFIG_TYPE_STRING_LIST = 0x7,
-	MG_CONFIG_TYPE_STRING_MULTILINE = 0x8
+	MG_CONFIG_TYPE_STRING_MULTILINE = 0x8,
+	MG_CONFIG_TYPE_YES_NO_OPTIONAL = 0x9
 };
 
 /* Return array of struct mg_option, representing all valid configuration

+ 1 - 2
src/civetweb.c

@@ -2233,8 +2233,7 @@ static struct mg_option config_options[] = {
     {"url_rewrite_patterns", MG_CONFIG_TYPE_STRING_LIST, NULL},
     {"hide_files_patterns", MG_CONFIG_TYPE_EXT_PATTERN, NULL},
 
-    /* TODO(Feature): this is no longer a boolean, but yes/no/optional */
-    {"ssl_verify_peer", MG_CONFIG_TYPE_BOOLEAN, "no"},
+    {"ssl_verify_peer", MG_CONFIG_TYPE_YES_NO_OPTIONAL, "no"},
 
     {"ssl_ca_path", MG_CONFIG_TYPE_DIRECTORY, NULL},
     {"ssl_ca_file", MG_CONFIG_TYPE_FILE, NULL},

+ 8 - 0
src/main.c

@@ -564,6 +564,14 @@ set_option(char **options, const char *name, const char *value)
 			return 0;
 		}
 		break;
+	case MG_CONFIG_TYPE_YES_NO_OPTIONAL:
+		/* boolean value, yes or no */
+		if ((0 != strcmp(value, "yes")) && (0 != strcmp(value, "no"))
+		    && (0 != strcmp(value, "optional"))) {
+			/* invalid boolean */
+			return 0;
+		}
+		break;
 	case MG_CONFIG_TYPE_FILE:
 	case MG_CONFIG_TYPE_DIRECTORY:
 		/* TODO (low): check this option when it is set, instead of calling