From ae69114e2a7bc67ac5a6f0551ccef83ca48a72ff Mon Sep 17 00:00:00 2001 From: bel Date: Fri, 7 Mar 2014 21:21:08 +0100 Subject: [PATCH] Parameter checking for the standalone server --- src/civetweb.c | 5 +++-- src/main.c | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/civetweb.c b/src/civetweb.c index c561f8c2..997fe752 100644 --- a/src/civetweb.c +++ b/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"}, diff --git a/src/main.c b/src/main.c index 0adfae20..429dc6c7 100644 --- a/src/main.c +++ b/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 ? "" : options[i].default_value); + fprintf(stderr, " -%s %s\n", options[i].name, ((options[i].default_value == NULL) ? "" : 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) ? "" : 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]); + } } } }