Jelajahi Sumber

Remove MG_LEGACY_INTERFACE functions, release some experimental functions

Some functions have been marked as MG_LEGACY_INTERFACE since 2017.
These functions have been removed.

Some of the functions labeled as MG_EXPERIMENTAL_INTERFACES are well tested now.
They have been released (i.e., the "experimental" label was removed).
bel2125 3 tahun lalu
induk
melakukan
b6781c79be
5 mengubah file dengan 54 tambahan dan 175 penghapusan
  1. 5 2
      RELEASE_NOTES.md
  2. 22 84
      include/civetweb.h
  3. 4 46
      src/civetweb.c
  4. 1 1
      unittest/build_and_test_minimal.sh
  5. 22 42
      unittest/public_server.c

+ 5 - 2
RELEASE_NOTES.md

@@ -1,14 +1,17 @@
 Release Notes v1.15 (work in progress)
 ===
-### Objectives: *various fixes, domain sockets*
+### Objectives: *bug fixes, remove legacy interfaces*
 
 Changes
 -------
 
-- New configuraton for URL decoding
+- New configuration for URL decoding
 - Sanitize filenames in handle form
 - Example "embedded_c.c": Do not overwrite files (possible security issue) 
 - Remove obsolete examples
+- Remove "experimental" label for some features
+- Remove MG_LEGACY_INTERFACE that have been declared obsolete in 2017 or earlier
+- Modifications to build scripts, required due to changes in the test environment
 - Unix domain socket support fixed
 - Fixes for NO_SSL_DL
 - Fixes for some warnings / static code analysis

+ 22 - 84
include/civetweb.h

@@ -148,25 +148,22 @@ struct mg_header {
 
 /* This structure contains information about the HTTP request. */
 struct mg_request_info {
-	const char *request_method;  /* "GET", "POST", etc */
-	const char *request_uri;     /* URL-decoded URI (absolute or relative,
-	                              * as in the request) */
-	const char *local_uri_raw;   /* URL-decoded URI (relative). Can be NULL
-	                              * if the request_uri does not address a
-	                              * resource at the server host. */
-	const char *local_uri;       /* Same as local_uri_raw, however, cleaned
-	                              * so a path like
-	                              *   allowed_dir/../forbidden_file
-	                              * is not possible. */
-#if defined(MG_LEGACY_INTERFACE) /* 2017-02-04, deprecated 2014-09-14 */
-	const char *uri;             /* Deprecated: use local_uri instead */
-#endif
-	const char *http_version; /* E.g. "1.0", "1.1" */
-	const char *query_string; /* URL part after '?', not including '?', or
-	                             NULL */
-	const char *remote_user;  /* Authenticated user, or NULL if no auth
-	                             used */
-	char remote_addr[48];     /* Client's IP address as a string. */
+	const char *request_method; /* "GET", "POST", etc */
+	const char *request_uri;    /* URL-decoded URI (absolute or relative,
+	                             * as in the request) */
+	const char *local_uri_raw;  /* URL-decoded URI (relative). Can be NULL
+	                             * if the request_uri does not address a
+	                             * resource at the server host. */
+	const char *local_uri;      /* Same as local_uri_raw, however, cleaned
+	                             * so a path like
+	                             *   allowed_dir/../forbidden_file
+	                             * is not possible. */
+	const char *http_version;   /* E.g. "1.0", "1.1" */
+	const char *query_string;   /* URL part after '?', not including '?', or
+	                               NULL */
+	const char *remote_user;    /* Authenticated user, or NULL if no auth
+	                               used */
+	char remote_addr[48];       /* Client's IP address as a string. */
 
 	long long content_length; /* Length (in bytes) of the request body,
 	                             can be -1 if no length was given. */
@@ -206,7 +203,6 @@ struct mg_response_info {
 
 
 /* Client certificate information (part of mg_request_info) */
-/* New nomenclature. */
 struct mg_client_cert {
 	void *peer_cert;
 	const char *subject;
@@ -215,16 +211,6 @@ struct mg_client_cert {
 	const char *finger;
 };
 
-#if defined(MG_LEGACY_INTERFACE) /* 2017-10-05 */
-/* Old nomenclature. */
-struct client_cert {
-	const char *subject;
-	const char *issuer;
-	const char *serial;
-	const char *finger;
-};
-#endif
-
 
 /* This structure needs to be passed to mg_start(), to let civetweb know
    which callbacks to invoke. For a detailed description, see
@@ -470,7 +456,6 @@ CIVETWEB_API struct mg_context *mg_start(const struct mg_callbacks *callbacks,
 CIVETWEB_API void mg_stop(struct mg_context *);
 
 
-#if defined(MG_EXPERIMENTAL_INTERFACES)
 /* Add an additional domain to an already running web server.
  *
  * Parameters:
@@ -490,7 +475,6 @@ CIVETWEB_API void mg_stop(struct mg_context *);
  */
 CIVETWEB_API int mg_start_domain(struct mg_context *ctx,
                                  const char **configuration_options);
-#endif
 
 
 /* mg_request_handler
@@ -704,22 +688,8 @@ struct mg_option {
 	const char *default_value;
 };
 
-/* Old nomenclature */
-#if defined(MG_LEGACY_INTERFACE) /* 2017-10-05 */
-enum {
-	CONFIG_TYPE_UNKNOWN = 0x0,
-	CONFIG_TYPE_NUMBER = 0x1,
-	CONFIG_TYPE_STRING = 0x2,
-	CONFIG_TYPE_FILE = 0x3,
-	CONFIG_TYPE_DIRECTORY = 0x4,
-	CONFIG_TYPE_BOOLEAN = 0x5,
-	CONFIG_TYPE_EXT_PATTERN = 0x6,
-	CONFIG_TYPE_STRING_LIST = 0x7,
-	CONFIG_TYPE_STRING_MULTILINE = 0x8
-};
-#endif
 
-/* New nomenclature */
+/* Configuration types */
 enum {
 	MG_CONFIG_TYPE_UNKNOWN = 0x0,
 	MG_CONFIG_TYPE_NUMBER = 0x1,
@@ -764,15 +734,6 @@ CIVETWEB_API int mg_get_server_ports(const struct mg_context *ctx,
                                      struct mg_server_port *ports);
 
 
-#if defined(MG_LEGACY_INTERFACE) /* 2017-04-02 */
-/* Deprecated: Use mg_get_server_ports instead. */
-CIVETWEB_API size_t mg_get_ports(const struct mg_context *ctx,
-                                 size_t size,
-                                 int *ports,
-                                 int *ssl);
-#endif
-
-
 /* Add, edit or delete the entry in the passwords file.
  *
  * This function allows an application to manipulate .htpasswd files on the
@@ -892,19 +853,7 @@ CIVETWEB_API void mg_lock_context(struct mg_context *ctx);
 CIVETWEB_API void mg_unlock_context(struct mg_context *ctx);
 
 
-/* Opcodes, from http://tools.ietf.org/html/rfc6455 */
-#if defined(MG_LEGACY_INTERFACE) /* 2017-10-05 */
-enum {
-	WEBSOCKET_OPCODE_CONTINUATION = 0x0,
-	WEBSOCKET_OPCODE_TEXT = 0x1,
-	WEBSOCKET_OPCODE_BINARY = 0x2,
-	WEBSOCKET_OPCODE_CONNECTION_CLOSE = 0x8,
-	WEBSOCKET_OPCODE_PING = 0x9,
-	WEBSOCKET_OPCODE_PONG = 0xa
-};
-#endif
-
-/* New nomenclature */
+/* WebSocket OpcCodes, from http://tools.ietf.org/html/rfc6455 */
 enum {
 	MG_WEBSOCKET_OPCODE_CONTINUATION = 0x0,
 	MG_WEBSOCKET_OPCODE_TEXT = 0x1,
@@ -914,6 +863,7 @@ enum {
 	MG_WEBSOCKET_OPCODE_PONG = 0xa
 };
 
+
 /* Macros for enabling compiler-specific checks for printf-like arguments. */
 #undef PRINTF_FORMAT_STRING
 #if defined(_MSC_VER) && _MSC_VER >= 1400
@@ -1317,20 +1267,6 @@ struct mg_form_data_handler {
 
 /* Return values definition for the "field_found" callback in
  * mg_form_data_handler. */
-#if defined(MG_LEGACY_INTERFACE) /* 2017-10-05 */
-enum {
-	/* Skip this field (neither get nor store it). Continue with the
-	 * next field. */
-	FORM_FIELD_STORAGE_SKIP = 0x0,
-	/* Get the field value. */
-	FORM_FIELD_STORAGE_GET = 0x1,
-	/* Store the field value into a file. */
-	FORM_FIELD_STORAGE_STORE = 0x2,
-	/* Stop parsing this request. Skip the remaining fields. */
-	FORM_FIELD_STORAGE_ABORT = 0x10
-};
-#endif
-/* New nomenclature */
 enum {
 	/* Skip this field (neither get nor store it). Continue with the
 	 * next field. */
@@ -1758,6 +1694,8 @@ mg_connect_client2(const char *host,
 CIVETWEB_API int mg_get_response2(struct mg_connection *conn,
                                   struct mg_error_data *error,
                                   int timeout);
+#endif
+
 
 CIVETWEB_API struct mg_context *mg_start2(struct mg_init_data *init,
                                           struct mg_error_data *error);
@@ -1765,7 +1703,7 @@ CIVETWEB_API struct mg_context *mg_start2(struct mg_init_data *init,
 CIVETWEB_API int mg_start_domain2(struct mg_context *ctx,
                                   const char **configuration_options,
                                   struct mg_error_data *error);
-#endif
+
 
 #ifdef __cplusplus
 }

+ 4 - 46
src/civetweb.c

@@ -3203,24 +3203,6 @@ mg_get_user_connection_data(const struct mg_connection *conn)
 }
 
 
-#if defined(MG_LEGACY_INTERFACE)
-/* Deprecated: Use mg_get_server_ports instead. */
-size_t
-mg_get_ports(const struct mg_context *ctx, size_t size, int *ports, int *ssl)
-{
-	size_t i;
-	if (!ctx) {
-		return 0;
-	}
-	for (i = 0; i < size && i < ctx->num_listening_sockets; i++) {
-		ssl[i] = ctx->listening_sockets[i].is_ssl;
-		ports[i] = ntohs(USA_IN_PORT_UNSAFE(&(ctx->listening_sockets[i].lsa)));
-	}
-	return i;
-}
-#endif
-
-
 int
 mg_get_server_ports(const struct mg_context *ctx,
                     int size,
@@ -16896,11 +16878,6 @@ reset_per_request_attributes(struct mg_connection *conn)
 #if defined(USE_SERVER_STATS)
 	conn->processing_time = 0;
 #endif
-
-#if defined(MG_LEGACY_INTERFACE)
-	/* Legacy before split into local_uri and request_uri */
-	conn->request_info.uri = NULL;
-#endif
 }
 
 
@@ -17994,11 +17971,7 @@ mg_get_response(struct mg_connection *conn,
 	ret = get_response(conn, ebuf, ebuf_len, &err);
 	conn->dom_ctx->config[REQUEST_TIMEOUT] = save_timeout;
 
-#if defined(MG_LEGACY_INTERFACE)
-	/* TODO: 1) uri is deprecated;
-	 *       2) here, ri.uri is the http response code */
-	conn->request_info.uri = conn->request_info.request_uri;
-#endif
+	/* TODO: here, the URI is the http response code */
 	conn->request_info.local_uri_raw = conn->request_info.request_uri;
 	conn->request_info.local_uri = conn->request_info.local_uri_raw;
 
@@ -18045,11 +18018,7 @@ mg_download(const char *host,
 			conn->data_len = 0;
 			get_response(conn, ebuf, ebuf_len, &reqerr);
 
-#if defined(MG_LEGACY_INTERFACE)
-			/* TODO: 1) uri is deprecated;
-			 *       2) here, ri.uri is the http response code */
-			conn->request_info.uri = conn->request_info.request_uri;
-#endif
+			/* TODO: here, the URI is the http response code */
 			conn->request_info.local_uri = conn->request_info.request_uri;
 		}
 	}
@@ -18582,11 +18551,6 @@ process_new_connection(struct mg_connection *conn)
 			}
 			conn->request_info.local_uri =
 			    (char *)conn->request_info.local_uri_raw;
-
-#if defined(MG_LEGACY_INTERFACE)
-			/* Legacy before split into local_uri and request_uri */
-			conn->request_info.uri = conn->request_info.local_uri;
-#endif
 		}
 
 		if (ebuf[0] != '\0') {
@@ -19598,11 +19562,8 @@ legacy_init(const char **options)
 }
 
 
-#if !defined(MG_EXPERIMENTAL_INTERFACES)
-static
-#endif
-    struct mg_context *
-    mg_start2(struct mg_init_data *init, struct mg_error_data *error)
+struct mg_context *
+mg_start2(struct mg_init_data *init, struct mg_error_data *error)
 {
 	struct mg_context *ctx;
 	const char *name, *value, *default_value;
@@ -20287,7 +20248,6 @@ mg_start(const struct mg_callbacks *callbacks,
 }
 
 
-#if defined(MG_EXPERIMENTAL_INTERFACES)
 /* Add an additional domain to an already running web server. */
 int
 mg_start_domain2(struct mg_context *ctx,
@@ -20484,8 +20444,6 @@ mg_start_domain(struct mg_context *ctx, const char **options)
 	return mg_start_domain2(ctx, options, NULL);
 }
 
-#endif
-
 
 /* Feature check API function */
 unsigned

+ 1 - 1
unittest/build_and_test_minimal.sh

@@ -2,7 +2,7 @@
 
 
 if test -f "./unittest/build_and_test_minimal.sh" ; then
-  echo "Unit test will run on a local Debian system."
+  echo "Unit test (minimal features) will run on a local Debian system."
   rm -rf output
 else
   echo "This script must be started from the civetweb root directory using ./unittest/build_and_test_minimal.sh"

+ 22 - 42
unittest/public_server.c

@@ -328,6 +328,12 @@ test_mg_start(const struct mg_callbacks *callbacks,
 {
 	struct mg_context *ctx;
 	struct mg_callbacks cb;
+	struct mg_init_data init;
+	struct mg_error_data error;
+	char error_buffer[256];
+
+	memset(&init, 0, sizeof(init));
+	memset(&error, 0, sizeof(error));
 
 	if (callbacks) {
 		memcpy(&cb, callbacks, sizeof(cb));
@@ -339,21 +345,33 @@ test_mg_start(const struct mg_callbacks *callbacks,
 		cb.log_message = test_log_message;
 	}
 
+	init.callbacks = &cb;
+	init.user_data = user_data;
+	init.configuration_options = configuration_options;
+
+	error.text = error_buffer;
+	error.text_buffer_size = sizeof(error_buffer);
+
 	mark_point();
 	test_sleep(SLEEP_BEFORE_MG_START);
 	mark_point();
-	ctx = mg_start(&cb, user_data, configuration_options);
+	ctx = mg_start2(&init, &error);
 	mark_point();
 	if (ctx) {
 		/* Give the server some time to start in the test VM. */
 		/* Don't need to do this if mg_start failed. */
 		test_sleep(SLEEP_AFTER_MG_START);
+		ck_assert_int_eq(error.code, 0);
+		ck_assert_str_eq(error.text, "");
 	} else if (line > 0) {
 		/* mg_start is not supposed to fail anywhere, except for
 		 * special tests (for them, line is 0). */
-		ck_abort_msg("mg_start failed in line %u, message %s",
-		             line,
-		             (lastMessage ? lastMessage : "<NULL>"));
+		ck_abort_msg(
+		    "mg_start failed in line %u\nerror %u: %s\nlast message %s\n",
+		    line,
+		    error.code,
+		    error.text,
+		    (lastMessage ? lastMessage : "<NULL>"));
 	}
 	mark_point();
 
@@ -391,11 +409,6 @@ test_mg_start_stop_http_server_impl(int ipv6, int bound)
 	int optcnt = 0;
 	const char *localhost_name = ((ipv6) ? "[::1]" : "127.0.0.1");
 
-#if defined(MG_LEGACY_INTERFACE)
-	size_t ports_cnt;
-	int ports[16];
-	int ssl[16];
-#endif
 	struct mg_callbacks callbacks;
 	char errmsg[256];
 
@@ -427,10 +440,6 @@ test_mg_start_stop_http_server_impl(int ipv6, int bound)
 
 	OPTIONS[optcnt] = 0;
 
-#if defined(MG_LEGACY_INTERFACE)
-	memset(ports, 0, sizeof(ports));
-	memset(ssl, 0, sizeof(ssl));
-#endif
 	memset(portinfo, 0, sizeof(portinfo));
 	memset(&callbacks, 0, sizeof(callbacks));
 	memset(errmsg, 0, sizeof(errmsg));
@@ -442,15 +451,6 @@ test_mg_start_stop_http_server_impl(int ipv6, int bound)
 	ck_assert_str_eq(errmsg, "");
 	ck_assert(ctx != NULL);
 
-#if defined(MG_LEGACY_INTERFACE)
-	ports_cnt = mg_get_ports(ctx, 16, ports, ssl);
-	ck_assert_uint_eq(ports_cnt, 1);
-	ck_assert_int_eq(ports[0], 8080);
-	ck_assert_int_eq(ssl[0], 0);
-	ck_assert_int_eq(ports[1], 0);
-	ck_assert_int_eq(ssl[1], 0);
-#endif
-
 	ret = mg_get_server_ports(ctx, 0, portinfo);
 	ck_assert_int_lt(ret, 0);
 	ck_assert_int_eq(portinfo[0].protocol, 0);
@@ -628,11 +628,6 @@ START_TEST(test_mg_start_stop_https_server)
 
 	struct mg_context *ctx;
 
-#if defined(MG_LEGACY_INTERFACE)
-	size_t ports_cnt;
-	int ports[16];
-	int ssl[16];
-#endif
 	struct mg_callbacks callbacks;
 	char errmsg[256];
 
@@ -662,10 +657,6 @@ START_TEST(test_mg_start_stop_https_server)
 	ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 1] == NULL);
 	ck_assert(OPTIONS[sizeof(OPTIONS) / sizeof(OPTIONS[0]) - 2] == NULL);
 
-#if defined(MG_LEGACY_INTERFACE)
-	memset(ports, 0, sizeof(ports));
-	memset(ssl, 0, sizeof(ssl));
-#endif
 	memset(portinfo, 0, sizeof(portinfo));
 	memset(&callbacks, 0, sizeof(callbacks));
 	memset(errmsg, 0, sizeof(errmsg));
@@ -677,17 +668,6 @@ START_TEST(test_mg_start_stop_https_server)
 	ck_assert_str_eq(errmsg, "");
 	ck_assert(ctx != NULL);
 
-#if defined(MG_LEGACY_INTERFACE)
-	ports_cnt = mg_get_ports(ctx, 16, ports, ssl);
-	ck_assert_uint_eq(ports_cnt, 2);
-	ck_assert_int_eq(ports[0], 8080);
-	ck_assert_int_eq(ssl[0], 0);
-	ck_assert_int_eq(ports[1], 8443);
-	ck_assert_int_eq(ssl[1], 1);
-	ck_assert_int_eq(ports[2], 0);
-	ck_assert_int_eq(ssl[2], 0);
-#endif
-
 	ret = mg_get_server_ports(ctx, 0, portinfo);
 	ck_assert_int_lt(ret, 0);
 	ck_assert_int_eq(portinfo[0].protocol, 0);