libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit f1bf7918364c4b6dd33ebefa4814ec28dbbe08b0
parent dc4af6f6001a35f965a088d9b20d6a26cd94254a
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun, 26 May 2019 17:43:47 +0300

curl tests: fixed detection of "11" marker on w32

Diffstat:
Msrc/testcurl/Makefile.am | 46+++++++++++++++++++++++-----------------------
Asrc/testcurl/mhd_has_in_name.h | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/testcurl/perf_get.c | 6++++--
Msrc/testcurl/test_delete.c | 6++++--
Msrc/testcurl/test_get.c | 6++++--
Msrc/testcurl/test_get_response_cleanup.c | 7+++++--
Msrc/testcurl/test_get_sendfile.c | 6++++--
Msrc/testcurl/test_iplimit.c | 6++++--
Msrc/testcurl/test_long_header.c | 6++++--
Msrc/testcurl/test_parse_cookies.c | 6++++--
Msrc/testcurl/test_post.c | 7+++++--
Msrc/testcurl/test_post_loop.c | 8+++++---
Msrc/testcurl/test_postform.c | 7+++++--
Msrc/testcurl/test_process_arguments.c | 6++++--
Msrc/testcurl/test_process_headers.c | 6++++--
Msrc/testcurl/test_put.c | 6++++--
Msrc/testcurl/test_timeout.c | 6++++--
Msrc/testcurl/test_urlparse.c | 6++++--
18 files changed, 156 insertions(+), 56 deletions(-)

diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am @@ -109,7 +109,7 @@ test_concurrent_stop_LDADD = \ $(PTHREAD_LIBS) @LIBCURL@ test_get_SOURCES = \ - test_get.c + test_get.c mhd_has_in_name.h test_get_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ @@ -138,7 +138,7 @@ test_callback_LDADD = \ perf_get_SOURCES = \ perf_get.c \ - gauger.h + gauger.h mhd_has_in_name.h perf_get_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ @@ -180,19 +180,19 @@ test_digestauth_with_arguments_LDADD = \ @LIBGCRYPT_LIBS@ @LIBCURL@ test_get_sendfile_SOURCES = \ - test_get_sendfile.c + test_get_sendfile.c mhd_has_in_name.h test_get_sendfile_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_urlparse_SOURCES = \ - test_urlparse.c + test_urlparse.c mhd_has_in_name.h test_urlparse_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_get_response_cleanup_SOURCES = \ - test_get_response_cleanup.c + test_get_response_cleanup.c mhd_has_in_name.h test_get_response_cleanup_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la @@ -203,49 +203,49 @@ test_get_chunked_LDADD = \ @LIBCURL@ test_post_SOURCES = \ - test_post.c + test_post.c mhd_has_in_name.h test_post_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_process_headers_SOURCES = \ - test_process_headers.c + test_process_headers.c mhd_has_in_name.h test_process_headers_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_parse_cookies_SOURCES = \ - test_parse_cookies.c + test_parse_cookies.c mhd_has_in_name.h test_parse_cookies_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_process_arguments_SOURCES = \ - test_process_arguments.c + test_process_arguments.c mhd_has_in_name.h test_process_arguments_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_postform_SOURCES = \ - test_postform.c + test_postform.c mhd_has_in_name.h test_postform_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBGCRYPT_LIBS@ @LIBCURL@ test_post_loop_SOURCES = \ - test_post_loop.c + test_post_loop.c mhd_has_in_name.h test_post_loop_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_delete_SOURCES = \ - test_delete.c + test_delete.c mhd_has_in_name.h test_delete_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_put_SOURCES = \ - test_put.c + test_put.c mhd_has_in_name.h test_put_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ @@ -257,37 +257,37 @@ test_put_chunked_LDADD = \ @LIBCURL@ test_get11_SOURCES = \ - test_get.c + test_get.c mhd_has_in_name.h test_get11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_get_sendfile11_SOURCES = \ - test_get_sendfile.c + test_get_sendfile.c mhd_has_in_name.h test_get_sendfile11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_post11_SOURCES = \ - test_post.c + test_post.c mhd_has_in_name.h test_post11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_postform11_SOURCES = \ - test_postform.c + test_postform.c mhd_has_in_name.h test_postform11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBGCRYPT_LIBS@ @LIBCURL@ test_post_loop11_SOURCES = \ - test_post_loop.c + test_post_loop.c mhd_has_in_name.h test_post_loop11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_put11_SOURCES = \ - test_put.c + test_put.c mhd_has_in_name.h test_put11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ @@ -311,19 +311,19 @@ test_large_put_inc11_LDADD = \ @LIBCURL@ test_long_header_SOURCES = \ - test_long_header.c + test_long_header.c mhd_has_in_name.h test_long_header_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_long_header11_SOURCES = \ - test_long_header.c + test_long_header.c mhd_has_in_name.h test_long_header11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ test_iplimit11_SOURCES = \ - test_iplimit.c + test_iplimit.c mhd_has_in_name.h test_iplimit11_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ @@ -335,7 +335,7 @@ test_termination_LDADD = \ @LIBCURL@ test_timeout_SOURCES = \ - test_timeout.c + test_timeout.c mhd_has_in_name.h test_timeout_LDADD = \ $(top_builddir)/src/microhttpd/libmicrohttpd.la \ @LIBCURL@ diff --git a/src/testcurl/mhd_has_in_name.h b/src/testcurl/mhd_has_in_name.h @@ -0,0 +1,65 @@ +/* + This file is part of libmicrohttpd + Copyright (C) 2016-2019 Karlson2k (Evgeny Grin) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/** + * @file testcurl/mhd_has_in_name.h + * @brief Static functions and macros helpers for testsuite. + * @author Karlson2k (Evgeny Grin) + */ + +#include <string.h> + +/** + * Check whether program name contains specific @a marker string. + * Only last component in pathname is checked for marker presence, + * all leading directories names (if any) are ignored. Directories + * separators are handled correctly on both non-W32 and W32 + * platforms. + * @param prog_name program name, may include path + * @param marker marker to look for. + * @return zero if any parameter is NULL or empty string or + * @prog_name ends with slash or @marker is not found in + * program name, non-zero if @maker is found in program + * name. + */ +static int +has_in_name(const char *prog_name, const char *marker) +{ + size_t name_pos; + size_t pos; + + if (!prog_name || !marker || !prog_name[0] || !marker[0]) + return 0; + + pos = 0; + name_pos = 0; + while (prog_name[pos]) + { + if ('/' == prog_name[pos]) + name_pos = pos + 1; +#if defined(_WIN32) || defined(__CYGWIN__) + else if ('\\' == prog_name[pos]) + name_pos = pos + 1; +#endif /* _WIN32 || __CYGWIN__ */ + pos++; + } + if (name_pos == pos) + return 0; + return strstr(prog_name + name_pos, marker) != (char*)0; +} diff --git a/src/testcurl/perf_get.c b/src/testcurl/perf_get.c @@ -44,6 +44,7 @@ #include <string.h> #include <time.h> #include "gauger.h" +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -579,8 +580,9 @@ main (int argc, char *const *argv) int port = 1130; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (oneone) port += 15; if (0 != curl_global_init (CURL_GLOBAL_WIN32)) diff --git a/src/testcurl/test_delete.c b/src/testcurl/test_delete.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -508,8 +509,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c @@ -30,6 +30,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #include "mhd_sockets.h" /* only macros used */ @@ -804,8 +805,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void) argc; /* Unused. Silence compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; global_port = 0; diff --git a/src/testcurl/test_get_response_cleanup.c b/src/testcurl/test_get_response_cleanup.c @@ -51,6 +51,8 @@ #include <windows.h> #endif +#include "mhd_has_in_name.h" + #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 #undef CPU_COUNT #endif @@ -415,8 +417,9 @@ main (int argc, char *const *argv) } #endif /* _WIN32 */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) { errorCount += testInternalGet (); diff --git a/src/testcurl/test_get_sendfile.c b/src/testcurl/test_get_sendfile.c @@ -33,6 +33,7 @@ #include <sys/types.h> #include <fcntl.h> #include "mhd_sockets.h" +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <sys/socket.h> @@ -576,8 +577,9 @@ main (int argc, char *const *argv) FILE *f; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if ( (NULL == (tmp = getenv ("TMPDIR"))) && (NULL == (tmp = getenv ("TMP"))) && diff --git a/src/testcurl/test_iplimit.c b/src/testcurl/test_iplimit.c @@ -32,6 +32,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -339,8 +340,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; errorCount |= testMultithreadedGet (); diff --git a/src/testcurl/test_long_header.c b/src/testcurl/test_long_header.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -282,8 +283,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; errorCount += testLongUrlGet (); diff --git a/src/testcurl/test_parse_cookies.c b/src/testcurl/test_parse_cookies.c @@ -32,6 +32,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -274,8 +275,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; errorCount += testExternalGet (); diff --git a/src/testcurl/test_post.c b/src/testcurl/test_post.c @@ -43,6 +43,8 @@ #include <windows.h> #endif +#include "mhd_has_in_name.h" + #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 #undef CPU_COUNT #endif @@ -770,8 +772,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) diff --git a/src/testcurl/test_post_loop.c b/src/testcurl/test_post_loop.c @@ -31,7 +31,8 @@ #include <stdlib.h> #include <string.h> #include <time.h> -#include <gauger.h> +#include "gauger.h" +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -579,8 +580,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) diff --git a/src/testcurl/test_postform.c b/src/testcurl/test_postform.c @@ -41,6 +41,8 @@ #include <unistd.h> #endif +#include "mhd_has_in_name.h" + #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 #undef CPU_COUNT #endif @@ -585,8 +587,9 @@ main (int argc, char *const *argv) #endif #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) diff --git a/src/testcurl/test_process_arguments.c b/src/testcurl/test_process_arguments.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -274,8 +275,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; errorCount += testExternalGet (); diff --git a/src/testcurl/test_process_headers.c b/src/testcurl/test_process_headers.c @@ -32,6 +32,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -518,8 +519,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) { errorCount += testInternalGet (); diff --git a/src/testcurl/test_put.c b/src/testcurl/test_put.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -517,8 +518,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) diff --git a/src/testcurl/test_timeout.c b/src/testcurl/test_timeout.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifndef WINDOWS #include <unistd.h> @@ -318,8 +319,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 16; errorCount += testWithoutTimeout (); diff --git a/src/testcurl/test_urlparse.c b/src/testcurl/test_urlparse.c @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include "mhd_has_in_name.h" #ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN @@ -201,8 +202,9 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - oneone = (NULL != strrchr (argv[0], (int) '/')) ? - (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; + if (NULL == argv || 0 == argv[0]) + return 99; + oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; errorCount += testInternalGet (0);