commit c49560c8117f8dd593bf84a337455bbe5415ced4
parent 075c3c42032e2e279987d21fb646c4f8302e1f93
Author: lv-426 <oxcafebaby@yahoo.com>
Date: Mon, 21 Jul 2008 03:50:54 +0000
curl version testing support
Diffstat:
9 files changed, 190 insertions(+), 17 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -122,6 +122,13 @@ LIBCURL_CHECK_CONFIG(,,curl=1,curl=0)
AM_CONDITIONAL(HAVE_CURL, test x$curl = x1)
LIBS=$SAVE_LIBS
+# Lib cURL & cURL - OpenSSL versions
+MHD_REQ_CURL_VERSION=7.16.4
+MHD_REQ_CURL_SSL_VERSION=0.9.8
+AC_DEFINE_UNQUOTED([MHD_REQ_CURL_VERSION], "$MHD_REQ_CURL_VERSION", [required cURL version to run tests])
+AC_DEFINE_UNQUOTED([MHD_REQ_CURL_SSL_VERSION], "$MHD_REQ_CURL_SSL_VERSION", [required cURL SSL version to run tests])
+
+
# large file support (> 4 GB)
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am
@@ -5,7 +5,6 @@ SUBDIRS += https
endif
AM_CPPFLAGS = \
--I$(top_srcdir)/src/daemon/https \
-I$(top_srcdir)/src/daemon \
-I$(top_srcdir)/src/include
diff --git a/src/testcurl/curl_version_check.c b/src/testcurl/curl_version_check.c
@@ -0,0 +1,136 @@
+/*
+ This file is part of libmicrohttpd
+ (C) 2007 Christian Grothoff
+
+ libmicrohttpd is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ libmicrohttpd 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with libmicrohttpd; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file curl_version_check.c
+ * @brief verify required cURL version is available to run tests
+ * @author Sagie Amir
+ */
+
+#include "config.h"
+#include <curl/curl.h>
+#include <microhttpd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "internal.h"
+
+#ifndef WINDOWS
+#include <unistd.h>
+#endif
+
+static int
+parse_version_number (const char **s)
+{
+ int i = 0;
+ char num[16];
+
+ while (i < 16 && ((**s >= '0') & (**s <= '9')))
+ {
+ num[i] = **s;
+ (*s)++;
+ i++;
+ }
+
+ num[i] = '\0';
+
+ return atoi (num);
+}
+
+const char *
+parse_version_string (const char *s, int *major, int *minor, int *micro)
+{
+ *major = parse_version_number (&s);
+ if (!s || *s != '.')
+ return NULL;
+ s++;
+ *minor = parse_version_number (&s);
+ if (!s || *s != '.')
+ return NULL;
+ s++;
+ *micro = parse_version_number (&s);
+ if (!s)
+ return NULL;
+ return s;
+}
+
+
+/*
+ * check local libcurl version matches required version
+ */
+int
+curl_check_version (const char *req_version, ...)
+{
+ va_list ap;
+ const char *ver;
+ const char *curl_ver;
+ const char *ssl_ver;
+ const char *req_ssl_ver;
+
+ int loc_major, loc_minor, loc_micro;
+ int rq_major, rq_minor, rq_micro;
+
+ ver = curl_version ();
+ /*
+ * this call relies on the cURL string to be of the format :
+ * 'libcurl/7.16.4 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/0.6.5'
+ */
+ curl_ver = strchr (ver, '/') + 1;
+ ssl_ver = strchr (curl_ver, '/') + 1;
+
+ /* Parse version numbers */
+ parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro);
+ parse_version_string (curl_ver, &loc_major, &loc_minor, &loc_micro);
+
+ /* Compare version numbers. */
+ if ((loc_major > rq_major
+ || (loc_major == rq_major && loc_minor > rq_minor)
+ || (loc_major == rq_major && loc_minor == rq_minor
+ && loc_micro > rq_micro) || (loc_major == rq_major
+ && loc_minor == rq_minor
+ && loc_micro == rq_micro)) == 0)
+ {
+ fprintf (stderr,
+ "Error: running curl test depends on local libcurl version > %s\n",
+ req_version);
+ return -1;
+ }
+
+#if HTTPS_SUPPORT
+ va_start (ap, req_version);
+ req_ssl_ver = va_arg (ap, void *);
+
+ parse_version_string (req_ssl_ver, &rq_major, &rq_minor, &rq_micro);
+ parse_version_string (ssl_ver, &loc_major, &loc_minor, &loc_micro);
+
+ if ((loc_major > rq_major
+ || (loc_major == rq_major && loc_minor > rq_minor)
+ || (loc_major == rq_major && loc_minor == rq_minor
+ && loc_micro > rq_micro) || (loc_major == rq_major
+ && loc_minor == rq_minor
+ && loc_micro == rq_micro)) == 0)
+ {
+ fprintf (stderr,
+ "Error: running curl test depends on local libcurl-openssl version > %s\n",
+ req_ssl_ver);
+ return -1;
+ }
+#endif
+ return 0;
+}
diff --git a/src/testcurl/https/Makefile.am b/src/testcurl/https/Makefile.am
@@ -8,7 +8,6 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/src/daemon/https/x509 \
-I$(top_srcdir)/src/daemon
-
check_PROGRAMS = \
mhds_get_test \
tls_authentication_test \
@@ -18,31 +17,36 @@ check_PROGRAMS = \
TESTS = $(check_PROGRAMS)
tls_alert_test_SOURCES = \
- tls_alert_test.c
+ tls_alert_test.c \
+ $(top_builddir)/src/testcurl/curl_version_check.c
tls_alert_test_LDADD = \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@
tls_authentication_test_SOURCES = \
- tls_authentication_test.c
+ tls_authentication_test.c \
+ $(top_builddir)/src/testcurl/curl_version_check.c
tls_authentication_test_LDADD = \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@
mhds_get_test_SOURCES = \
- mhds_get_test.c
+ mhds_get_test.c \
+ $(top_builddir)/src/testcurl/curl_version_check.c
mhds_get_test_LDADD = \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@
mhds_session_info_test_SOURCES = \
- mhds_session_info_test.c
+ mhds_session_info_test.c \
+ $(top_builddir)/src/testcurl/curl_version_check.c
mhds_session_info_test_LDADD = \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@
mhds_multi_daemon_test_SOURCES = \
- mhds_multi_daemon_test.c
+ mhds_multi_daemon_test.c \
+ $(top_builddir)/src/testcurl/curl_version_check.c
mhds_multi_daemon_test_LDADD = \
$(top_builddir)/src/daemon/libmicrohttpd.la \
@LIBCURL@
diff --git a/src/testcurl/https/mhds_get_test.c b/src/testcurl/https/mhds_get_test.c
@@ -51,6 +51,8 @@
const char *test_file_name = "https_test_file";
const char test_file_data[] = "Hello World\n";
+extern int curl_check_version (const char *req_version, ...);
+
struct CBC
{
char *buf;
@@ -416,7 +418,10 @@ main (int argc, char *const *argv)
FILE *test_fd;
unsigned int errorCount = 0;
- // gnutls_global_set_log_level(11);
+ if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION))
+ {
+ return -1;
+ }
if ((test_fd = setupTestFile ()) == NULL)
{
@@ -443,10 +448,10 @@ main (int argc, char *const *argv)
test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3);
- curl_global_cleanup ();
- fclose (test_fd);
+ curl_global_cleanup ();
+ fclose (test_fd);
- remove (test_file_name);
+ remove (test_file_name);
return errorCount != 0;
}
diff --git a/src/testcurl/https/mhds_multi_daemon_test.c b/src/testcurl/https/mhds_multi_daemon_test.c
@@ -48,6 +48,8 @@
const char *test_file_name = "https_test_file";
const char test_file_data[] = "Hello World\n";
+extern int curl_check_version (const char *req_version, ...);
+
struct CBC
{
char *buf;
@@ -300,6 +302,11 @@ main (int argc, char *const *argv)
FILE *test_fd;
unsigned int errorCount = 0;
+ if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION))
+ {
+ return -1;
+ }
+
if ((test_fd = setupTestFile ()) == NULL)
{
fprintf (stderr, MHD_E_TEST_FILE_CREAT);
diff --git a/src/testcurl/https/mhds_session_info_test.c b/src/testcurl/https/mhds_session_info_test.c
@@ -40,6 +40,8 @@
#include "tls_test_keys.h"
+extern int curl_check_version (const char *req_version, ...);
+
struct MHD_Daemon *d;
struct CBC
@@ -213,6 +215,11 @@ main (int argc, char *const *argv)
FILE *test_fd;
unsigned int errorCount = 0;
+ if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION))
+ {
+ return -1;
+ }
+
if (0 != curl_global_init (CURL_GLOBAL_ALL))
{
fprintf (stderr, "Error (code: %u)\n", errorCount);
diff --git a/src/testcurl/https/tls_alert_test.c b/src/testcurl/https/tls_alert_test.c
@@ -48,6 +48,8 @@
#include "gnutls_datum.h"
#include "tls_test_keys.h"
+extern int curl_check_version (const char *req_version, ...);
+
const char *ca_cert_file_name = "ca_cert_pem";
const char *test_file_name = "https_test_file";
const char test_file_data[] = "Hello World\n";
@@ -79,8 +81,6 @@ http_ahc (void *cls, struct MHD_Connection *connection,
static int
test_alert_response ()
{
-
-
int sd, ret;
char *err_pos;
struct sockaddr_in sa;
@@ -88,13 +88,11 @@ test_alert_response ()
gnutls_session_t session;
gnutls_certificate_credentials_t xcred;
-
gnutls_global_init ();
gnutls_datum_t key;
gnutls_datum_t cert;
-
gnutls_certificate_allocate_credentials (&xcred);
_gnutls_set_datum_m (&key, srv_key_pem, strlen (srv_key_pem), &malloc);
@@ -157,14 +155,17 @@ test_alert_response ()
}
-
-
int
main (int argc, char *const *argv)
{
int ret, errorCount = 0;;
struct MHD_Daemon *d;
+ if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION))
+ {
+ return -1;
+ }
+
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL |
MHD_USE_DEBUG, 42433,
NULL, NULL, &http_ahc, NULL,
diff --git a/src/testcurl/https/tls_authentication_test.c b/src/testcurl/https/tls_authentication_test.c
@@ -46,6 +46,8 @@
#include "tls_test_keys.h"
+extern int curl_check_version (const char *req_version, ...);
+
const char *ca_cert_file_name = "ca_cert_pem";
const char *test_file_name = "https_test_file";
const char test_file_data[] = "Hello World\n";
@@ -315,6 +317,11 @@ main (int argc, char *const *argv)
FILE *test_fd;
unsigned int errorCount = 0;
+ if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION))
+ {
+ return -1;
+ }
+
if ((test_fd = setupTestFile ()) == NULL)
{
fprintf (stderr, MHD_E_TEST_FILE_CREAT);