libmicrohttpd

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

commit 23324164fb6fcc421a0bf081c50a00ce3f66f9b7
parent fd7d712823b6fd2d544a85a15f27f2a01989f29e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Wed, 15 Nov 2017 16:12:12 +0300

https tests: supported multi-TLS selection on libcurl >= 7.56.0,
fixed error report for failed initialisation of libcurl

Diffstat:
Msrc/testcurl/https/test_empty_response.c | 7++-----
Msrc/testcurl/https/test_https_get.c | 7++-----
Msrc/testcurl/https/test_https_get_parallel.c | 7++-----
Msrc/testcurl/https/test_https_get_parallel_threads.c | 7++-----
Msrc/testcurl/https/test_https_get_select.c | 7++-----
Msrc/testcurl/https/test_https_multi_daemon.c | 8++------
Msrc/testcurl/https/test_https_session_info.c | 7++-----
Msrc/testcurl/https/test_https_sni.c | 7++-----
Msrc/testcurl/https/test_tls_authentication.c | 7++-----
Msrc/testcurl/https/test_tls_extensions.c | 7++-----
Msrc/testcurl/https/test_tls_options.c | 7++-----
Msrc/testcurl/https/tls_test_common.c | 19+++++++++++++++++++
Msrc/testcurl/https/tls_test_common.h | 3+++
13 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/src/testcurl/https/test_empty_response.c b/src/testcurl/https/test_empty_response.c @@ -222,11 +222,8 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); diff --git a/src/testcurl/https/test_https_get.c b/src/testcurl/https/test_https_get.c @@ -139,11 +139,8 @@ main (int argc, char *const *argv) gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); diff --git a/src/testcurl/https/test_https_get_parallel.c b/src/testcurl/https/test_https_get_parallel.c @@ -150,11 +150,8 @@ main (int argc, char *const *argv) /* initialize random seed used by curl clients */ unsigned int iseed = (unsigned int) time (NULL); srand (iseed); - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { diff --git a/src/testcurl/https/test_https_get_parallel_threads.c b/src/testcurl/https/test_https_get_parallel_threads.c @@ -157,11 +157,8 @@ main (int argc, char *const *argv) #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ srand (iseed); - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; if (NULL == ssl_version) { diff --git a/src/testcurl/https/test_https_get_select.c b/src/testcurl/https/test_https_get_select.c @@ -250,11 +250,8 @@ main (int argc, char *const *argv) unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); diff --git a/src/testcurl/https/test_https_multi_daemon.c b/src/testcurl/https/test_https_multi_daemon.c @@ -136,12 +136,8 @@ main (int argc, char *const *argv) gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error (code: %u). l:%d f:%s\n", errorCount, __LINE__, - __FUNCTION__); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); diff --git a/src/testcurl/https/test_https_session_info.c b/src/testcurl/https/test_https_session_info.c @@ -199,11 +199,8 @@ main (int argc, char *const *argv) gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error (code: %u)\n", errorCount); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; ssl_version = curl_version_info (CURLVERSION_NOW)->ssl_version; if (NULL == ssl_version) diff --git a/src/testcurl/https/test_https_sni.c b/src/testcurl/https/test_https_sni.c @@ -269,11 +269,8 @@ main (int argc, char *const *argv) gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); diff --git a/src/testcurl/https/test_tls_authentication.c b/src/testcurl/https/test_tls_authentication.c @@ -94,11 +94,8 @@ main (int argc, char *const *argv) gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); #endif #endif /* MHD_HTTPS_REQUIRE_GRYPT */ - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error (code: %u)\n", errorCount); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; if (NULL == curl_version_info (CURLVERSION_NOW)->ssl_version) { fprintf (stderr, "Curl does not support SSL. Cannot run the test.\n"); diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c @@ -238,11 +238,8 @@ main (int argc, char *const *argv) return -1; } - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return -1; - } + if (!testsuite_curl_global_init ()) + return 99; d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_TLS | MHD_USE_ERROR_LOG, port, diff --git a/src/testcurl/https/test_tls_options.c b/src/testcurl/https/test_tls_options.c @@ -121,11 +121,8 @@ main (int argc, char *const *argv) return 77; } - if (0 != curl_global_init (CURL_GLOBAL_ALL)) - { - fprintf (stderr, "Error: %s\n", strerror (errno)); - return 99; - } + if (!testsuite_curl_global_init ()) + return 99; const char *aes128_sha = "AES128-SHA"; const char *aes256_sha = "AES256-SHA"; diff --git a/src/testcurl/https/tls_test_common.c b/src/testcurl/https/tls_test_common.c @@ -525,3 +525,22 @@ test_wrap (const char *test_name, int va_end (arg_list); return ret; } + +int testsuite_curl_global_init (void) +{ + CURLcode res; +#if LIBCURL_VERSION_NUM >= 0x07380 + if (CURLSSLSET_OK != curl_global_sslset(CURLSSLBACKEND_GNUTLS, NULL, NULL)) + { + if (CURLSSLSET_TOO_LATE == curl_global_sslset(CURLSSLBACKEND_OPENSSL, NULL, NULL)) + fprintf (stderr, "WARNING: libcurl was already initialised.\n"); + } +#endif /* LIBCURL_VERSION_NUM >= 0x07380 */ + res = curl_global_init (CURL_GLOBAL_ALL); + if (CURLE_OK != res) + { + fprintf (stderr, "libcurl initialisation error: %s\n", curl_easy_strerror(res)); + return 0; + } + return 1; +} diff --git a/src/testcurl/https/tls_test_common.h b/src/testcurl/https/tls_test_common.h @@ -149,4 +149,7 @@ test_wrap (const char *test_name, int int proto_version), void * cls, int port, int daemon_flags, const char *cipher_suite, int proto_version, ...); + +int testsuite_curl_global_init (void); + #endif /* TLS_TEST_COMMON_H_ */