bel преди 9 години
родител
ревизия
914ad2256d
променени са 4 файла, в които са добавени 75 реда и са изтрити 21 реда
  1. 2 1
      include/civetweb.h
  2. 15 12
      src/civetweb.c
  3. 16 2
      test/public_func.c
  4. 42 6
      test/public_server.c

+ 2 - 1
include/civetweb.h

@@ -1007,7 +1007,8 @@ CIVETWEB_API int mg_get_response(struct mg_connection *conn,
         16  support WebSocket (USE_WEBSOCKET set)
         32  support Lua scripts and Lua server pages (USE_LUA is set)
         64  support server side JavaScript (USE_DUKTAPE is set)
-        The result is undefined for all other feature values.
+       128  support caching (NO_CACHING not set)
+       The result is undefined for all other feature values.
 
    Return:
      If feature is available > 0

+ 15 - 12
src/civetweb.c

@@ -13099,43 +13099,46 @@ mg_check_feature(unsigned feature)
  * This bit mask is created at compile time, according to the active
  * preprocessor defines. It is a single const value at runtime. */
 #if !defined(NO_FILES)
-	                                    | 1
+	                                    | 0x0001u
 #endif
 #if !defined(NO_SSL)
-	                                    | 2
+	                                    | 0x0002u
 #endif
 #if !defined(NO_CGI)
-	                                    | 4
+	                                    | 0x0004u
 #endif
 #if defined(USE_IPV6)
-	                                    | 8
+	                                    | 0x0008u
 #endif
 #if defined(USE_WEBSOCKET)
-	                                    | 16
+	                                    | 0x0010u
 #endif
 #if defined(USE_LUA)
-	                                    | 32
+	                                    | 0x0020u
 #endif
 #if defined(USE_DUKTAPE)
-	                                    | 64
+	                                    | 0x0040u
+#endif
+#if !defined(NO_CACHING)
+	                                    | 0x0080u
 #endif
 
 /* Set some extra bits not defined in the API documentation.
  * These bits may change without further notice. */
 #if defined(MG_LEGACY_INTERFACE)
-	                                    | 128
+	                                    | 0x8000u
 #endif
 #if defined(MEMORY_DEBUGGING)
-	                                    | 256
+	                                    | 0x0100u
 #endif
 #if defined(USE_TIMERS)
-	                                    | 512
+	                                    | 0x0200u
 #endif
 #if !defined(NO_NONCE_CHECK)
-	                                    | 1024
+	                                    | 0x0400u
 #endif
 #if !defined(NO_POPEN)
-	                                    | 2048
+	                                    | 0x0800u
 #endif
 	    ;
 	return (feature & feature_set);

+ 16 - 2
test/public_func.c

@@ -41,9 +41,10 @@ START_TEST(test_mg_version)
 	const char *ver = mg_version();
 	unsigned major = 0, minor = 0;
 	unsigned feature_files, feature_https, feature_cgi, feature_ipv6,
-	    feature_websocket, feature_lua;
+	    feature_websocket, feature_lua, feature_duktape, feature_caching;
 	unsigned expect_files = 0, expect_https = 0, expect_cgi = 0,
-	         expect_ipv6 = 0, expect_websocket = 0, expect_lua = 0;
+	         expect_ipv6 = 0, expect_websocket = 0, expect_lua = 0,
+	         expect_duktape = 0, expect_caching = 0;
 	int ret;
 
 	ck_assert(ver != NULL);
@@ -53,6 +54,9 @@ START_TEST(test_mg_version)
 	ret = sscanf(ver, "%u.%u", &major, &minor);
 	ck_assert_int_eq(ret, 2);
 	ck_assert_uint_ge(major, 1);
+	if (major == 1) {
+		ck_assert_uint_ge(minor, 8); /* current version is 1.8 */
+	}
 
 	/* check feature */
 	feature_files = mg_check_feature(1);
@@ -61,6 +65,8 @@ START_TEST(test_mg_version)
 	feature_ipv6 = mg_check_feature(8);
 	feature_websocket = mg_check_feature(16);
 	feature_lua = mg_check_feature(32);
+	feature_duktape = mg_check_feature(64);
+	feature_caching = mg_check_feature(128);
 
 #if !defined(NO_FILES)
 	expect_files = 1;
@@ -80,6 +86,12 @@ START_TEST(test_mg_version)
 #if defined(USE_LUA)
 	expect_lua = 1;
 #endif
+#if defined(USE_DUKTAPE)
+	expect_duktape = 1;
+#endif
+#if !defined(NO_CACHING)
+	expect_caching = 1;
+#endif
 
 	ck_assert_uint_eq(expect_files, !!feature_files);
 	ck_assert_uint_eq(expect_https, !!feature_https);
@@ -87,6 +99,8 @@ START_TEST(test_mg_version)
 	ck_assert_uint_eq(expect_ipv6, !!feature_ipv6);
 	ck_assert_uint_eq(expect_websocket, !!feature_websocket);
 	ck_assert_uint_eq(expect_lua, !!feature_lua);
+	ck_assert_uint_eq(expect_duktape, !!feature_duktape);
+	ck_assert_uint_eq(expect_caching, !!feature_caching);
 }
 END_TEST
 

+ 42 - 6
test/public_server.c

@@ -1606,6 +1606,8 @@ START_TEST(test_request_handlers)
 END_TEST
 
 
+static int field_found_return = 0;
+
 static int
 field_found(const char *key,
             const char *filename,
@@ -1619,6 +1621,14 @@ field_found(const char *key,
 	(void)pathlen;
 	(void)user_data;
 
+    ck_assert_ptr_eq(user_data, (void*)&field_found_return);
+
+    ck_assert((field_found_return == FORM_FIELD_STORAGE_GET) ||
+              (field_found_return == FORM_FIELD_STORAGE_STORE) ||
+              (field_found_return == FORM_FIELD_STORAGE_SKIP) ||
+              (field_found_return == FORM_FIELD_STORAGE_ABORT)
+              );
+
 	return FORM_FIELD_STORAGE_GET;
 }
 
@@ -1633,7 +1643,8 @@ field_get(const char *key, const char *value, size_t valuelen, void *user_data)
 	(void)valuelen;
 	(void)user_data;
 
-	ck_assert(user_data == (void *)0x12345);
+	ck_assert_ptr_eq(user_data, (void*)&field_found_return);
+    ck_assert_int_ge(g_field_step, 0);
 
 	++g_field_step;
 	switch (g_field_step) {
@@ -1757,7 +1768,7 @@ field_get(const char *key, const char *value, size_t valuelen, void *user_data)
 
 
 static int
-FormHandler(struct mg_connection *conn, void *cbdata)
+FormGet(struct mg_connection *conn, void *cbdata)
 {
 	const struct mg_request_info *req_info = mg_get_request_info(conn);
 	int ret;
@@ -1768,7 +1779,7 @@ FormHandler(struct mg_connection *conn, void *cbdata)
 	ck_assert(req_info != NULL);
 
 	mg_printf(conn, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n");
-	fdh.user_data = (void *)0x12345;
+	fdh.user_data = (void*)&field_found_return;
 
 	/* Call the form handler */
 	g_field_step = 0;
@@ -1781,6 +1792,31 @@ FormHandler(struct mg_connection *conn, void *cbdata)
 }
 
 
+static int
+FormStore(struct mg_connection *conn, void *cbdata)
+{
+	const struct mg_request_info *req_info = mg_get_request_info(conn);
+	int ret;
+	struct mg_form_data_handler fdh = {field_found, field_get, field_store, NULL};
+
+	(void)cbdata;
+
+	ck_assert(req_info != NULL);
+
+	mg_printf(conn, "HTTP/1.0 200 OK\r\nContent-Type: text/plain\r\n\r\n");
+	fdh.user_data = (void*)&field_found_return;
+
+	/* Call the form handler */
+	g_field_step = -999;
+	ret = mg_handle_form_request(conn, &fdh);
+	ck_assert_int_eq(ret, 22);
+	ck_assert_int_eq(g_field_step, 22);
+	mg_printf(conn, "%i\r\n", ret);
+
+	return 1;
+}
+
+
 START_TEST(test_handle_form)
 {
 	struct mg_context *ctx;
@@ -1809,7 +1845,7 @@ START_TEST(test_handle_form)
 	opt = mg_get_option(ctx, "listening_ports");
 	ck_assert_str_eq(opt, "8884");
 
-	mg_set_request_handler(ctx, "/handle_form", FormHandler, (void *)0);
+	mg_set_request_handler(ctx, "/handle_form", FormGet, (void *)0);
 
 	test_sleep(1);
 
@@ -2407,8 +2443,8 @@ MAIN_PUBLIC_SERVER(void)
 	    test_mg_start_stop_https_server(0);
 	    test_request_handlers(0);
 	    test_mg_server_and_client_tls(0);
-	    test_handle_form(0);
-	*/
+    */
+    test_handle_form(0);
 	test_http_auth(0);
 
 	printf("\nok: %i\nfailed: %i\n\n", chk_ok, chk_failed);