Browse Source

Parameter checking for the standalone server

bel 11 năm trước cách đây
mục cha
commit
ae69114e2a
2 tập tin đã thay đổi với 16 bổ sung6 xóa
  1. 3 2
      src/civetweb.c
  2. 13 4
      src/main.c

+ 3 - 2
src/civetweb.c

@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014 the civetweb developers
+/* Copyright (c) 2013-2014 the Civetweb developers
  * Copyright (c) 2004-2013 Sergey Lyubka
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -683,6 +683,7 @@ enum {
     NUM_OPTIONS
 };
 
+/* TODO: replace 12345 by proper config types */
 static struct mg_option config_options[] = {
     {"cgi_pattern",                 CONFIG_TYPE_EXT_PATTERN,   "**.cgi$|**.pl$|**.php$"},
     {"cgi_environment",             CONFIG_TYPE_STRING,        NULL},
@@ -709,7 +710,7 @@ static struct mg_option config_options[] = {
     {"document_root",               CONFIG_TYPE_DIRECTORY,     NULL},
     {"ssl_certificate",             CONFIG_TYPE_FILE,          NULL},
     {"num_threads",                 CONFIG_TYPE_NUMBER,        "50"},
-    {"run_as_user",                 12345,                     NULL},
+    {"run_as_user",                 CONFIG_TYPE_STRING,        NULL},
     {"url_rewrite_patterns",        12345,                     NULL},
     {"hide_files_patterns",         12345,                     NULL},
     {"request_timeout_ms",          CONFIG_TYPE_NUMBER,        "30000"},

+ 13 - 4
src/main.c

@@ -1,4 +1,5 @@
-/* Copyright (c) 2004-2013 Sergey Lyubka
+/* Copyright (c) 2013-2014 the Civetweb developers
+ * Copyright (c) 2004-2013 Sergey Lyubka
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -142,9 +143,14 @@ static void show_usage_and_exit(void)
 
     options = mg_get_valid_options();
     for (i = 0; options[i].name != NULL; i++) {
-        fprintf(stderr, "  -%s %s\n",
-                options[i].name[i], options[i].default_value == NULL ? "<empty>" : options[i].default_value);
+        fprintf(stderr, "  -%s %s\n", options[i].name, ((options[i].default_value == NULL) ? "<empty>" : options[i].default_value));
     }
+
+    options = main_config_options;
+    for (i = 0; options[i].name != NULL; i++) {
+        fprintf(stderr, "  -%s %s\n", options[i].name, ((options[i].default_value == NULL) ? "<empty>" : options[i].default_value));
+    }
+
     exit(EXIT_FAILURE);
 }
 
@@ -373,7 +379,10 @@ static void process_command_line_arguments(char *argv[], char **options)
             if (argv[i][0] != '-' || argv[i + 1] == NULL) {
                 show_usage_and_exit();
             }
-            set_option(options, &argv[i][1], argv[i + 1]);
+            if (!set_option(options, &argv[i][1], argv[i + 1])) {
+                printf("command line option is invalid, ignoring it:\n %s %s\n",
+                       argv[i], argv[i + 1]);
+            }
         }
     }
 }