Browse Source

Merge branch 'master' of https://github.com/civetweb/civetweb into cipher_list

Mateusz Gralka 9 years ago
parent
commit
b6dafff931
13 changed files with 323 additions and 166 deletions
  1. 28 27
      format.bat
  2. 2 0
      include/CivetServer.h
  3. 30 0
      resources/coverity_check.sh
  4. 26 0
      src/CivetServer.cpp
  5. 13 2
      src/civetweb.c
  6. 78 40
      src/mod_lua.inl
  7. 1 0
      test/bad_page.lp
  8. 1 0
      test/bad_script.lua
  9. 15 0
      test/exit.lua
  10. 41 32
      test/private.c
  11. 4 4
      test/private_exe.c
  12. 38 37
      test/public_func.c
  13. 46 24
      test/public_server.c

+ 28 - 27
format.bat

@@ -1,27 +1,28 @@
-clang-format -i src/civetweb.c
-clang-format -i src/main.c
-clang-format -i src/CivetServer.cpp
-clang-format -i src/civetweb_private_lua.h
-clang-format -i src/md5.inl
-clang-format -i src/mod_lua.inl
-clang-format -i src/mod_duktape.inl
-clang-format -i src/timer.inl
-
-clang-format -i src/third_party/civetweb_lua.h
-
-clang-format -i include/civetweb.h
-clang-format -i include/CivetServer.h
-
-clang-format -i test/public_func.h
-clang-format -i test/public_func.c
-clang-format -i test/public_server.h
-clang-format -i test/public_server.c
-clang-format -i test/private.h
-clang-format -i test/private.c
-clang-format -i test/private_exe.h
-clang-format -i test/private_exe.c
-clang-format -i test/shared.h
-clang-format -i test/shared.c
-clang-format -i test/civetweb_check.h
-clang-format -i test/main.c
-
+#!/bin/sh
+clang-format -i src/civetweb.c
+clang-format -i src/main.c
+clang-format -i src/CivetServer.cpp
+clang-format -i src/civetweb_private_lua.h
+clang-format -i src/md5.inl
+clang-format -i src/mod_lua.inl
+clang-format -i src/mod_duktape.inl
+clang-format -i src/timer.inl
+
+clang-format -i src/third_party/civetweb_lua.h
+
+clang-format -i include/civetweb.h
+clang-format -i include/CivetServer.h
+
+clang-format -i test/public_func.h
+clang-format -i test/public_func.c
+clang-format -i test/public_server.h
+clang-format -i test/public_server.c
+clang-format -i test/private.h
+clang-format -i test/private.c
+clang-format -i test/private_exe.h
+clang-format -i test/private_exe.c
+clang-format -i test/shared.h
+clang-format -i test/shared.c
+clang-format -i test/civetweb_check.h
+clang-format -i test/main.c
+

+ 2 - 0
include/CivetServer.h

@@ -170,6 +170,8 @@ class CIVETWEB_API CivetServer
 	 * @throws CivetException
 	 */
 	CivetServer(const char **options, const struct mg_callbacks *callbacks = 0);
+	CivetServer(std::vector<std::string> options,
+	            const struct mg_callbacks *callbacks = 0);
 
 	/**
 	 * Destructor

+ 30 - 0
resources/coverity_check.sh

@@ -0,0 +1,30 @@
+#! /bin/sh
+
+ls src/civetweb.c
+if [ "$?" = "0" ]; then
+	echo "Building files for coverity check ..."
+else
+	echo "Run this script from the root directory of project!" 1>&2
+	echo "username@hostname:/somewhere/civetweb$ resources/coverity_check.sh" 1>&2
+	exit 1
+fi
+
+rm -rf cov_int/
+make clean
+
+../cov-analysis-linux64-7.6.0/bin/cov-build  --dir cov-int make WITH_IPV6=1 WITH_WEBSOCKET=1 WITH_LUA_SHARED=1
+
+rm coverity_check.tgz
+tar czvf coverity_check.tgz cov-int
+
+ls coverity_check.tgz
+
+if [ "$?" = "0" ]; then
+	echo "... done"
+else
+	echo "No coverity_check.tgz file" 1>&2
+	exit 1
+fi
+
+exit 0
+

+ 26 - 0
src/CivetServer.cpp

@@ -237,6 +237,32 @@ CivetServer::CivetServer(const char **options,
 		throw CivetException("null context when constructing CivetServer. "
 		                     "Possible problem binding to port.");
 }
+CivetServer::CivetServer(std::vector<std::string> options,
+                         const struct mg_callbacks *_callbacks)
+    : context(0)
+{
+	struct mg_callbacks callbacks;
+	memset(&callbacks, 0, sizeof(callbacks));
+
+	if (_callbacks) {
+		callbacks = *_callbacks;
+		userCloseHandler = _callbacks->connection_close;
+	} else {
+		userCloseHandler = NULL;
+	}
+	callbacks.connection_close = closeHandler;
+
+	std::vector<const char *> pointers(options.size());
+	for (int i = 0; i < options.size(); i++) {
+		pointers.push_back(options[i].c_str());
+	}
+	pointers.push_back(0);
+
+	context = mg_start(&callbacks, this, &pointers[0]);
+	if (context == NULL)
+		throw CivetException("null context when constructing CivetServer. "
+		                     "Possible problem binding to port.");
+}
 
 CivetServer::~CivetServer()
 {

+ 13 - 2
src/civetweb.c

@@ -1279,7 +1279,8 @@ mg_atomic_inc(volatile int *addr)
 	 * (volatile unsigned int *) or (volatile LONG *),
 	 * so whatever you use, the other SDK is likely to raise a warning. */
 	ret = InterlockedIncrement((volatile long *)addr);
-#elif defined(__GNUC__)
+#elif defined(__GNUC__)                                                        \
+    && (__GNUC__ > 5 || (__GNUC__ == 4 && __GNUC_MINOR__ > 0))
 	ret = __sync_add_and_fetch(addr, 1);
 #else
 	ret = (++(*addr));
@@ -1296,7 +1297,8 @@ mg_atomic_dec(volatile int *addr)
 	 * (volatile unsigned int *) or (volatile LONG *),
 	 * so whatever you use, the other SDK is likely to raise a warning. */
 	ret = InterlockedDecrement((volatile long *)addr);
-#elif defined(__GNUC__)
+#elif defined(__GNUC__)                                                        \
+    && (__GNUC__ > 5 || (__GNUC__ == 4 && __GNUC_MINOR__ > 0))
 	ret = __sync_sub_and_fetch(addr, 1);
 #else
 	ret = (--(*addr));
@@ -2690,6 +2692,15 @@ mg_stat(struct mg_connection *conn, const char *path, struct file *filep)
 	memset(filep, 0, sizeof(*filep));
 
 	if (conn && is_file_in_memory(conn, path, filep)) {
+		/* filep->is_directory = 0; filep->gzipped = 0; .. already done by
+		 * memset */
+		last_modified = time(NULL);
+		/* last_modified = now ... assumes the file may change during runtime,
+		 * so every mg_fopen call may return different data */
+		/* last_modified = conn->ctx.start_time;
+		 * May be used it the data does not change during runtime. This allows
+		 * browser caching. Since we do not know, we have to assume the file
+		 * in memory may change. */
 		return 1;
 	}
 

+ 78 - 40
src/mod_lua.inl

@@ -922,11 +922,11 @@ lwebsock_write(lua_State *L)
 			}
 		}
 	} else {
-		(void)pthread_mutex_unlock(&ws->ws_mutex);
+		(void)pthread_mutex_unlock(&(ws->ws_mutex));
 		return luaL_error(L, "invalid websocket write() call");
 	}
 
-	(void)pthread_mutex_unlock(&ws->ws_mutex);
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
 
 #else
 	(void)(L);           /* unused */
@@ -1398,30 +1398,54 @@ handle_lsp_request(struct mg_connection *conn,
 	void *p = NULL;
 	lua_State *L = NULL;
 	int error = 1;
+	struct file filesize = STRUCT_FILE_INITIALIZER;
 
 	/* Assume the script does not support keep_alive. The script may change this
 	 * by calling mg.keep_alive(true). */
 	conn->must_close = 1;
 
 	/* We need both mg_stat to get file size, and mg_fopen to get fd */
-	if (!mg_stat(conn, path, filep) || !mg_fopen(conn, path, "r", filep)) {
-		/* File not found or not accessible */
+	if (!mg_stat(conn, path, &filesize)) {
+
+		/* File not found */
 		if (ls == NULL) {
-			send_http_error(
-			    conn,
-			    500,
-			    "Error: Cannot open script\nFile %s can not be read",
-			    path);
+			send_http_error(conn, 500, "Error: File %s not found", path);
 		} else {
 			luaL_error(ls, "File [%s] not found", path);
 		}
-	} else if (filep->membuf == NULL
-	           && (p = mmap(NULL,
-	                        (size_t)filep->size,
-	                        PROT_READ,
-	                        MAP_PRIVATE,
-	                        fileno(filep->fp),
-	                        0)) == MAP_FAILED) {
+
+		goto cleanup_handle_lsp_request;
+	}
+
+	if (!mg_fopen(conn, path, "r", filep)) {
+
+		/* File not found or not accessible */
+		if (ls == NULL) {
+			send_http_error(conn,
+			                500,
+			                "Error: Cannot open script file %s",
+			                path);
+		} else {
+			luaL_error(ls, "Cannot  [%s] not found", path);
+		}
+
+		goto cleanup_handle_lsp_request;
+	}
+
+	/* TODO: Operations mg_fopen and mg_stat should do what their names
+	 * indicate. They should not fill in different members of the same
+	 * struct file.
+	 * See Github issue #225 */
+	filep->size = filesize.size;
+
+	if (filep->membuf == NULL
+	    && (p = mmap(NULL,
+	                 (size_t)filep->size,
+	                 PROT_READ,
+	                 MAP_PRIVATE,
+	                 fileno(filep->fp),
+	                 0)) == MAP_FAILED) {
+
 		/* mmap failed */
 		if (ls == NULL) {
 			send_http_error(
@@ -1437,31 +1461,45 @@ handle_lsp_request(struct mg_connection *conn,
 			           fileno(filep->fp),
 			           strerror(errno));
 		}
-	} else if ((L = (ls != NULL ? ls : lua_newstate(lua_allocator, NULL)))
-	           == NULL) {
-		send_http_error(conn,
-		                500,
-		                "%s",
-		                "Error: Cannot execute script\nlua_newstate failed");
+
+		goto cleanup_handle_lsp_request;
+	}
+
+	if (ls != NULL) {
+		L = ls;
 	} else {
-		/* We're not sending HTTP headers here, Lua page must do it. */
-		if (ls == NULL) {
-			prepare_lua_environment(
-			    conn->ctx, conn, NULL, L, path, LUA_ENV_TYPE_LUA_SERVER_PAGE);
+		L = lua_newstate(lua_allocator, NULL);
+		if (L == NULL) {
+			send_http_error(
+			    conn,
+			    500,
+			    "%s",
+			    "Error: Cannot execute script\nlua_newstate failed");
+
+			goto cleanup_handle_lsp_request;
 		}
-		error = lsp(conn,
-		            path,
-		            (filep->membuf == NULL) ? (const char *)p
-		                                    : (const char *)filep->membuf,
-		            filep->size,
-		            L);
+		prepare_lua_environment(
+		    conn->ctx, conn, NULL, L, path, LUA_ENV_TYPE_LUA_SERVER_PAGE);
 	}
 
+	/* Lua state is ready to use */
+	/* We're not sending HTTP headers here, Lua page must do it. */
+	error = lsp(conn,
+	            path,
+	            (filep->membuf == NULL) ? (const char *)p
+	                                    : (const char *)filep->membuf,
+	            filep->size,
+	            L);
+
+
+cleanup_handle_lsp_request:
+
 	if (L != NULL && ls == NULL)
 		lua_close(L);
 	if (p != NULL)
 		munmap(p, filep->size);
 	mg_fclose(filep);
+
 	return error;
 }
 
@@ -1490,6 +1528,7 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
 		}
 		shared_websock_list = &((*shared_websock_list)->next);
 	}
+
 	if (*shared_websock_list == NULL) {
 		/* add ws to list */
 		*shared_websock_list = (struct mg_shared_lua_websocket_list *)
@@ -1502,7 +1541,7 @@ lua_websocket_new(const char *script, struct mg_connection *conn)
 		/* init ws list element */
 		ws = &(*shared_websock_list)->ws;
 		ws->script = mg_strdup(script); /* TODO (low): handle OOM */
-		pthread_mutex_init(&(ws->ws_mutex), NULL);
+		pthread_mutex_init(&(ws->ws_mutex), &pthread_mutex_attr);
 		(void)pthread_mutex_lock(&(ws->ws_mutex));
 		ws->state = lua_newstate(lua_allocator, NULL);
 		ws->conn[0] = conn;
@@ -1567,7 +1606,7 @@ lua_websocket_data(struct mg_connection *conn,
 	assert(ws != NULL);
 	assert(ws->state != NULL);
 
-	(void)pthread_mutex_lock(&ws->ws_mutex);
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
 
 	lua_getglobal(ws->state, "data");
 	lua_newtable(ws->state);
@@ -1593,7 +1632,7 @@ lua_websocket_data(struct mg_connection *conn,
 		}
 		lua_pop(ws->state, 1);
 	}
-	(void)pthread_mutex_unlock(&ws->ws_mutex);
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
 
 	return ok;
 }
@@ -1607,14 +1646,13 @@ lua_websocket_ready(struct mg_connection *conn, void *ws_arg)
 	assert(ws != NULL);
 	assert(ws->state != NULL);
 
-	(void)pthread_mutex_lock(&ws->ws_mutex);
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
 
 	lua_getglobal(ws->state, "ready");
 	lua_newtable(ws->state);
 	lua_pushstring(ws->state, "client");
 	lua_pushlightuserdata(ws->state, (void *)conn);
 	lua_rawset(ws->state, -3);
-
 	err = lua_pcall(ws->state, 1, 1, 0);
 	if (err != 0) {
 		lua_cry(conn, err, ws->state, ws->script, "ready handler");
@@ -1625,7 +1663,7 @@ lua_websocket_ready(struct mg_connection *conn, void *ws_arg)
 		lua_pop(ws->state, 1);
 	}
 
-	(void)pthread_mutex_unlock(&ws->ws_mutex);
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
 
 	return ok;
 }
@@ -1642,7 +1680,7 @@ lua_websocket_close(struct mg_connection *conn, void *ws_arg)
 	assert(ws != NULL);
 	assert(ws->state != NULL);
 
-	(void)pthread_mutex_lock(&ws->ws_mutex);
+	(void)pthread_mutex_lock(&(ws->ws_mutex));
 
 	lua_getglobal(ws->state, "close");
 	lua_newtable(ws->state);
@@ -1665,6 +1703,6 @@ lua_websocket_close(struct mg_connection *conn, void *ws_arg)
 	   asynchronous operations and timers are completed/expired. */
 	(void)shared_websock_list; /* shared_websock_list unused (see open TODO) */
 
-	(void)pthread_mutex_unlock(&ws->ws_mutex);
+	(void)pthread_mutex_unlock(&(ws->ws_mutex));
 }
 #endif

+ 1 - 0
test/bad_page.lp

@@ -0,0 +1 @@
+test <? bad_script ?> test

+ 1 - 0
test/bad_script.lua

@@ -0,0 +1 @@
+bad_script 

+ 15 - 0
test/exit.lua

@@ -0,0 +1,15 @@
+
+msg=[[<html><body>
+<p>Exit CivetWeb</p>
+</body></html>
+]]
+
+mg.write("HTTP/1.0 200 OK\r\n")
+mg.write("Connection: close\r\n")
+mg.write("Content-Length: " .. #msg .. "\r\n")
+mg.write("Content-Type: text/html\r\n")
+mg.write("\r\n")
+mg.write(msg)
+
+os.exit(0)
+

+ 41 - 32
test/private.c

@@ -465,10 +465,17 @@ END_TEST
 
 START_TEST(test_mask_data)
 {
+#if defined(USE_WEBSOCKET)
 	char in[1024];
 	char out[1024];
 	int i;
+#endif
+
+	uint32_t mask = 0x61626364;
+	/* TODO: adapt test for big endian */
+	ck_assert((*(unsigned char *)&mask) == 0x64u);
 
+#if defined(USE_WEBSOCKET)
 	memset(in, 0, sizeof(in));
 	memset(out, 99, sizeof(out));
 
@@ -497,6 +504,7 @@ START_TEST(test_mask_data)
 	ck_assert_uint_eq((unsigned char)out[2], 2u ^ 2u);
 	ck_assert_uint_eq((unsigned char)out[3], 3u ^ 1u);
 	ck_assert_uint_eq((unsigned char)out[4], 4u ^ 4u);
+#endif
 }
 END_TEST
 
@@ -506,38 +514,39 @@ make_private_suite(void)
 {
 	Suite *const suite = suite_create("Private");
 
-	TCase *const http_message = tcase_create("HTTP Message");
-	TCase *const url_parsing = tcase_create("URL Parsing");
-	TCase *const internal_parse = tcase_create("Internal Parsing");
-	TCase *const encode_decode = tcase_create("Encode Decode");
-	TCase *const mask_data = tcase_create("Mask Data");
-
-	tcase_add_test(http_message, test_parse_http_message);
-	tcase_add_test(http_message, test_should_keep_alive);
-	tcase_set_timeout(http_message, civetweb_min_test_timeout);
-	suite_add_tcase(suite, http_message);
-
-	tcase_add_test(url_parsing, test_match_prefix);
-	tcase_add_test(url_parsing, test_remove_double_dots_and_double_slashes);
-	tcase_add_test(url_parsing, test_is_valid_uri);
-	tcase_set_timeout(url_parsing, civetweb_min_test_timeout);
-	suite_add_tcase(suite, url_parsing);
-
-	tcase_add_test(internal_parse, test_next_option);
-	tcase_add_test(internal_parse, test_skip_quoted);
-	tcase_add_test(internal_parse, test_mg_strcasestr);
-	tcase_add_test(internal_parse, test_alloc_vprintf);
-	tcase_add_test(internal_parse, test_parse_port_string);
-	tcase_set_timeout(internal_parse, civetweb_min_test_timeout);
-	suite_add_tcase(suite, internal_parse);
-
-	tcase_add_test(encode_decode, test_encode_decode);
-	tcase_set_timeout(encode_decode, civetweb_min_test_timeout);
-	suite_add_tcase(suite, encode_decode);
-
-	tcase_add_test(mask_data, test_mask_data);
-	tcase_set_timeout(mask_data, civetweb_min_test_timeout);
-	suite_add_tcase(suite, mask_data);
+	TCase *const tcase_http_message = tcase_create("HTTP Message");
+	TCase *const tcase_url_parsing = tcase_create("URL Parsing");
+	TCase *const tcase_internal_parse = tcase_create("Internal Parsing");
+	TCase *const tcase_encode_decode = tcase_create("Encode Decode");
+	TCase *const tcase_mask_data = tcase_create("Mask Data");
+
+	tcase_add_test(tcase_http_message, test_parse_http_message);
+	tcase_add_test(tcase_http_message, test_should_keep_alive);
+	tcase_set_timeout(tcase_http_message, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_http_message);
+
+	tcase_add_test(tcase_url_parsing, test_match_prefix);
+	tcase_add_test(tcase_url_parsing,
+	               test_remove_double_dots_and_double_slashes);
+	tcase_add_test(tcase_url_parsing, test_is_valid_uri);
+	tcase_set_timeout(tcase_url_parsing, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_url_parsing);
+
+	tcase_add_test(tcase_internal_parse, test_next_option);
+	tcase_add_test(tcase_internal_parse, test_skip_quoted);
+	tcase_add_test(tcase_internal_parse, test_mg_strcasestr);
+	tcase_add_test(tcase_internal_parse, test_alloc_vprintf);
+	tcase_add_test(tcase_internal_parse, test_parse_port_string);
+	tcase_set_timeout(tcase_internal_parse, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_internal_parse);
+
+	tcase_add_test(tcase_encode_decode, test_encode_decode);
+	tcase_set_timeout(tcase_encode_decode, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_encode_decode);
+
+	tcase_add_test(tcase_mask_data, test_mask_data);
+	tcase_set_timeout(tcase_mask_data, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_mask_data);
 
 	return suite;
 }

+ 4 - 4
test/private_exe.c

@@ -67,11 +67,11 @@ make_private_exe_suite(void)
 {
 	Suite *const suite = suite_create("EXE");
 
-	TCase *const helper_funcs = tcase_create("Helper funcs");
+	TCase *const tcase_helper_funcs = tcase_create("Helper funcs");
 
-	tcase_add_test(helper_funcs, test_helper_funcs);
-	tcase_set_timeout(helper_funcs, civetweb_min_test_timeout);
-	suite_add_tcase(suite, helper_funcs);
+	tcase_add_test(tcase_helper_funcs, test_helper_funcs);
+	tcase_set_timeout(tcase_helper_funcs, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_helper_funcs);
 
 	return suite;
 }

+ 38 - 37
test/public_func.c

@@ -420,43 +420,44 @@ make_public_func_suite(void)
 {
 	Suite *const suite = suite_create("PublicFunc");
 
-	TCase *const version = tcase_create("Version");
-	TCase *const get_valid_options = tcase_create("Options");
-	TCase *const get_builtin_mime_type = tcase_create("MIME types");
-	TCase *const tstrncasecmp = tcase_create("strcasecmp");
-	TCase *const urlencodingdecoding = tcase_create("URL encoding decoding");
-	TCase *const cookies = tcase_create("Cookies and variables");
-	TCase *const md5 = tcase_create("MD5");
-
-	tcase_add_test(version, test_mg_version);
-	tcase_set_timeout(version, civetweb_min_test_timeout);
-	suite_add_tcase(suite, version);
-
-	tcase_add_test(get_valid_options, test_mg_get_valid_options);
-	tcase_set_timeout(get_valid_options, civetweb_min_test_timeout);
-	suite_add_tcase(suite, get_valid_options);
-
-	tcase_add_test(get_builtin_mime_type, test_mg_get_builtin_mime_type);
-	tcase_set_timeout(get_builtin_mime_type, civetweb_min_test_timeout);
-	suite_add_tcase(suite, get_builtin_mime_type);
-
-	tcase_add_test(tstrncasecmp, test_mg_strncasecmp);
-	tcase_set_timeout(tstrncasecmp, civetweb_min_test_timeout);
-	suite_add_tcase(suite, tstrncasecmp);
-
-	tcase_add_test(urlencodingdecoding, test_mg_url_encode);
-	tcase_add_test(urlencodingdecoding, test_mg_url_decode);
-	tcase_set_timeout(urlencodingdecoding, civetweb_min_test_timeout);
-	suite_add_tcase(suite, urlencodingdecoding);
-
-	tcase_add_test(cookies, test_mg_get_cookie);
-	tcase_add_test(cookies, test_mg_get_var);
-	tcase_set_timeout(cookies, civetweb_min_test_timeout);
-	suite_add_tcase(suite, cookies);
-
-	tcase_add_test(md5, test_mg_md5);
-	tcase_set_timeout(md5, civetweb_min_test_timeout);
-	suite_add_tcase(suite, md5);
+	TCase *const tcase_version = tcase_create("Version");
+	TCase *const tcase_get_valid_options = tcase_create("Options");
+	TCase *const tcase_get_builtin_mime_type = tcase_create("MIME types");
+	TCase *const tcase_strncasecmp = tcase_create("strcasecmp");
+	TCase *const tcase_urlencodingdecoding =
+	    tcase_create("URL encoding decoding");
+	TCase *const tcase_cookies = tcase_create("Cookies and variables");
+	TCase *const tcase_md5 = tcase_create("MD5");
+
+	tcase_add_test(tcase_version, test_mg_version);
+	tcase_set_timeout(tcase_version, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_version);
+
+	tcase_add_test(tcase_get_valid_options, test_mg_get_valid_options);
+	tcase_set_timeout(tcase_get_valid_options, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_get_valid_options);
+
+	tcase_add_test(tcase_get_builtin_mime_type, test_mg_get_builtin_mime_type);
+	tcase_set_timeout(tcase_get_builtin_mime_type, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_get_builtin_mime_type);
+
+	tcase_add_test(tcase_strncasecmp, test_mg_strncasecmp);
+	tcase_set_timeout(tcase_strncasecmp, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_strncasecmp);
+
+	tcase_add_test(tcase_urlencodingdecoding, test_mg_url_encode);
+	tcase_add_test(tcase_urlencodingdecoding, test_mg_url_decode);
+	tcase_set_timeout(tcase_urlencodingdecoding, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_urlencodingdecoding);
+
+	tcase_add_test(tcase_cookies, test_mg_get_cookie);
+	tcase_add_test(tcase_cookies, test_mg_get_var);
+	tcase_set_timeout(tcase_cookies, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_cookies);
+
+	tcase_add_test(tcase_md5, test_mg_md5);
+	tcase_set_timeout(tcase_md5, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_md5);
 
 	return suite;
 }

+ 46 - 24
test/public_server.c

@@ -100,8 +100,19 @@ wait_not_null(void *volatile *data)
 			return 1;
 		}
 	}
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+#endif
+
 	ck_abort_msg("wait_not_null failed");
+
 	return 0;
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 }
 
 START_TEST(test_the_test_environment)
@@ -613,8 +624,19 @@ websock_server_data(struct mg_connection *conn,
 		mg_websocket_write(conn, WEBSOCKET_OPCODE_TEXT, "ok - 3", 6);
 		mg_unlock_connection(conn);
 	} else {
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunreachable-code"
+#endif
+
 		ck_abort_msg("Got unexpected message from websocket client");
+
+
 		return 0;
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 	}
 
 	return 1; /* return 1 to keep the connetion open */
@@ -1307,36 +1329,36 @@ make_public_server_suite(void)
 {
 	Suite *const suite = suite_create("PublicServer");
 
-	TCase *const checktestenv = tcase_create("Check test environment");
-	TCase *const startthreads = tcase_create("Start threads");
-	TCase *const startstophttp = tcase_create("Start Stop HTTP Server");
-	TCase *const startstophttps = tcase_create("Start Stop HTTPS Server");
-	TCase *const serverandclienttls = tcase_create("TLS Server Client");
-	TCase *const serverrequests = tcase_create("Server Requests");
+	TCase *const tcase_checktestenv = tcase_create("Check test environment");
+	TCase *const tcase_startthreads = tcase_create("Start threads");
+	TCase *const tcase_startstophttp = tcase_create("Start Stop HTTP Server");
+	TCase *const tcase_startstophttps = tcase_create("Start Stop HTTPS Server");
+	TCase *const tcase_serverandclienttls = tcase_create("TLS Server Client");
+	TCase *const tcase_serverrequests = tcase_create("Server Requests");
 
-	tcase_add_test(checktestenv, test_the_test_environment);
-	tcase_set_timeout(checktestenv, civetweb_min_test_timeout);
-	suite_add_tcase(suite, checktestenv);
+	tcase_add_test(tcase_checktestenv, test_the_test_environment);
+	tcase_set_timeout(tcase_checktestenv, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_checktestenv);
 
-	tcase_add_test(startthreads, test_threading);
-	tcase_set_timeout(startthreads, civetweb_min_test_timeout);
-	suite_add_tcase(suite, startthreads);
+	tcase_add_test(tcase_startthreads, test_threading);
+	tcase_set_timeout(tcase_startthreads, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_startthreads);
 
-	tcase_add_test(startstophttp, test_mg_start_stop_http_server);
-	tcase_set_timeout(startstophttp, civetweb_min_test_timeout);
-	suite_add_tcase(suite, startstophttp);
+	tcase_add_test(tcase_startstophttp, test_mg_start_stop_http_server);
+	tcase_set_timeout(tcase_startstophttp, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_startstophttp);
 
-	tcase_add_test(startstophttps, test_mg_start_stop_https_server);
-	tcase_set_timeout(startstophttps, civetweb_min_test_timeout);
-	suite_add_tcase(suite, startstophttps);
+	tcase_add_test(tcase_startstophttps, test_mg_start_stop_https_server);
+	tcase_set_timeout(tcase_startstophttps, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_startstophttps);
 
-	tcase_add_test(serverandclienttls, test_mg_server_and_client_tls);
-	tcase_set_timeout(serverandclienttls, civetweb_min_test_timeout);
-	suite_add_tcase(suite, serverandclienttls);
+	tcase_add_test(tcase_serverandclienttls, test_mg_server_and_client_tls);
+	tcase_set_timeout(tcase_serverandclienttls, civetweb_min_test_timeout);
+	suite_add_tcase(suite, tcase_serverandclienttls);
 
-	tcase_add_test(serverrequests, test_request_handlers);
-	tcase_set_timeout(serverrequests, 120);
-	suite_add_tcase(suite, serverrequests);
+	tcase_add_test(tcase_serverrequests, test_request_handlers);
+	tcase_set_timeout(tcase_serverrequests, 120);
+	suite_add_tcase(suite, tcase_serverrequests);
 
 	return suite;
 }