diff options
author | lv-426 <oxcafebaby@yahoo.com> | 2008-07-21 03:50:54 +0000 |
---|---|---|
committer | lv-426 <oxcafebaby@yahoo.com> | 2008-07-21 03:50:54 +0000 |
commit | c49560c8117f8dd593bf84a337455bbe5415ced4 (patch) | |
tree | 6aaf73b605e0bd35c1be72db06c4be6ec20e931f /src | |
parent | 075c3c42032e2e279987d21fb646c4f8302e1f93 (diff) | |
download | libmicrohttpd-c49560c8117f8dd593bf84a337455bbe5415ced4.tar.gz libmicrohttpd-c49560c8117f8dd593bf84a337455bbe5415ced4.zip |
curl version testing support
Diffstat (limited to 'src')
-rw-r--r-- | src/testcurl/Makefile.am | 1 | ||||
-rw-r--r-- | src/testcurl/curl_version_check.c | 136 | ||||
-rw-r--r-- | src/testcurl/https/Makefile.am | 16 | ||||
-rw-r--r-- | src/testcurl/https/mhds_get_test.c | 13 | ||||
-rw-r--r-- | src/testcurl/https/mhds_multi_daemon_test.c | 7 | ||||
-rw-r--r-- | src/testcurl/https/mhds_session_info_test.c | 7 | ||||
-rw-r--r-- | src/testcurl/https/tls_alert_test.c | 13 | ||||
-rw-r--r-- | src/testcurl/https/tls_authentication_test.c | 7 |
8 files changed, 183 insertions, 17 deletions
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am index a95723dd..bedeb068 100644 --- a/src/testcurl/Makefile.am +++ b/src/testcurl/Makefile.am | |||
@@ -5,7 +5,6 @@ SUBDIRS += https | |||
5 | endif | 5 | endif |
6 | 6 | ||
7 | AM_CPPFLAGS = \ | 7 | AM_CPPFLAGS = \ |
8 | -I$(top_srcdir)/src/daemon/https \ | ||
9 | -I$(top_srcdir)/src/daemon \ | 8 | -I$(top_srcdir)/src/daemon \ |
10 | -I$(top_srcdir)/src/include | 9 | -I$(top_srcdir)/src/include |
11 | 10 | ||
diff --git a/src/testcurl/curl_version_check.c b/src/testcurl/curl_version_check.c new file mode 100644 index 00000000..c7cf97d4 --- /dev/null +++ b/src/testcurl/curl_version_check.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Christian Grothoff | ||
4 | |||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file curl_version_check.c | ||
23 | * @brief verify required cURL version is available to run tests | ||
24 | * @author Sagie Amir | ||
25 | */ | ||
26 | |||
27 | #include "config.h" | ||
28 | #include <curl/curl.h> | ||
29 | #include <microhttpd.h> | ||
30 | #include <stdlib.h> | ||
31 | #include <string.h> | ||
32 | #include "internal.h" | ||
33 | |||
34 | #ifndef WINDOWS | ||
35 | #include <unistd.h> | ||
36 | #endif | ||
37 | |||
38 | static int | ||
39 | parse_version_number (const char **s) | ||
40 | { | ||
41 | int i = 0; | ||
42 | char num[16]; | ||
43 | |||
44 | while (i < 16 && ((**s >= '0') & (**s <= '9'))) | ||
45 | { | ||
46 | num[i] = **s; | ||
47 | (*s)++; | ||
48 | i++; | ||
49 | } | ||
50 | |||
51 | num[i] = '\0'; | ||
52 | |||
53 | return atoi (num); | ||
54 | } | ||
55 | |||
56 | const char * | ||
57 | parse_version_string (const char *s, int *major, int *minor, int *micro) | ||
58 | { | ||
59 | *major = parse_version_number (&s); | ||
60 | if (!s || *s != '.') | ||
61 | return NULL; | ||
62 | s++; | ||
63 | *minor = parse_version_number (&s); | ||
64 | if (!s || *s != '.') | ||
65 | return NULL; | ||
66 | s++; | ||
67 | *micro = parse_version_number (&s); | ||
68 | if (!s) | ||
69 | return NULL; | ||
70 | return s; | ||
71 | } | ||
72 | |||
73 | |||
74 | /* | ||
75 | * check local libcurl version matches required version | ||
76 | */ | ||
77 | int | ||
78 | curl_check_version (const char *req_version, ...) | ||
79 | { | ||
80 | va_list ap; | ||
81 | const char *ver; | ||
82 | const char *curl_ver; | ||
83 | const char *ssl_ver; | ||
84 | const char *req_ssl_ver; | ||
85 | |||
86 | int loc_major, loc_minor, loc_micro; | ||
87 | int rq_major, rq_minor, rq_micro; | ||
88 | |||
89 | ver = curl_version (); | ||
90 | /* | ||
91 | * this call relies on the cURL string to be of the format : | ||
92 | * 'libcurl/7.16.4 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/0.6.5' | ||
93 | */ | ||
94 | curl_ver = strchr (ver, '/') + 1; | ||
95 | ssl_ver = strchr (curl_ver, '/') + 1; | ||
96 | |||
97 | /* Parse version numbers */ | ||
98 | parse_version_string (req_version, &rq_major, &rq_minor, &rq_micro); | ||
99 | parse_version_string (curl_ver, &loc_major, &loc_minor, &loc_micro); | ||
100 | |||
101 | /* Compare version numbers. */ | ||
102 | if ((loc_major > rq_major | ||
103 | || (loc_major == rq_major && loc_minor > rq_minor) | ||
104 | || (loc_major == rq_major && loc_minor == rq_minor | ||
105 | && loc_micro > rq_micro) || (loc_major == rq_major | ||
106 | && loc_minor == rq_minor | ||
107 | && loc_micro == rq_micro)) == 0) | ||
108 | { | ||
109 | fprintf (stderr, | ||
110 | "Error: running curl test depends on local libcurl version > %s\n", | ||
111 | req_version); | ||
112 | return -1; | ||
113 | } | ||
114 | |||
115 | #if HTTPS_SUPPORT | ||
116 | va_start (ap, req_version); | ||
117 | req_ssl_ver = va_arg (ap, void *); | ||
118 | |||
119 | parse_version_string (req_ssl_ver, &rq_major, &rq_minor, &rq_micro); | ||
120 | parse_version_string (ssl_ver, &loc_major, &loc_minor, &loc_micro); | ||
121 | |||
122 | if ((loc_major > rq_major | ||
123 | || (loc_major == rq_major && loc_minor > rq_minor) | ||
124 | || (loc_major == rq_major && loc_minor == rq_minor | ||
125 | && loc_micro > rq_micro) || (loc_major == rq_major | ||
126 | && loc_minor == rq_minor | ||
127 | && loc_micro == rq_micro)) == 0) | ||
128 | { | ||
129 | fprintf (stderr, | ||
130 | "Error: running curl test depends on local libcurl-openssl version > %s\n", | ||
131 | req_ssl_ver); | ||
132 | return -1; | ||
133 | } | ||
134 | #endif | ||
135 | return 0; | ||
136 | } | ||
diff --git a/src/testcurl/https/Makefile.am b/src/testcurl/https/Makefile.am index b4a4c99d..e9397c7e 100644 --- a/src/testcurl/https/Makefile.am +++ b/src/testcurl/https/Makefile.am | |||
@@ -8,7 +8,6 @@ AM_CPPFLAGS = \ | |||
8 | -I$(top_srcdir)/src/daemon/https/x509 \ | 8 | -I$(top_srcdir)/src/daemon/https/x509 \ |
9 | -I$(top_srcdir)/src/daemon | 9 | -I$(top_srcdir)/src/daemon |
10 | 10 | ||
11 | |||
12 | check_PROGRAMS = \ | 11 | check_PROGRAMS = \ |
13 | mhds_get_test \ | 12 | mhds_get_test \ |
14 | tls_authentication_test \ | 13 | tls_authentication_test \ |
@@ -18,31 +17,36 @@ check_PROGRAMS = \ | |||
18 | TESTS = $(check_PROGRAMS) | 17 | TESTS = $(check_PROGRAMS) |
19 | 18 | ||
20 | tls_alert_test_SOURCES = \ | 19 | tls_alert_test_SOURCES = \ |
21 | tls_alert_test.c | 20 | tls_alert_test.c \ |
21 | $(top_builddir)/src/testcurl/curl_version_check.c | ||
22 | tls_alert_test_LDADD = \ | 22 | tls_alert_test_LDADD = \ |
23 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 23 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
24 | @LIBCURL@ | 24 | @LIBCURL@ |
25 | 25 | ||
26 | tls_authentication_test_SOURCES = \ | 26 | tls_authentication_test_SOURCES = \ |
27 | tls_authentication_test.c | 27 | tls_authentication_test.c \ |
28 | $(top_builddir)/src/testcurl/curl_version_check.c | ||
28 | tls_authentication_test_LDADD = \ | 29 | tls_authentication_test_LDADD = \ |
29 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 30 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
30 | @LIBCURL@ | 31 | @LIBCURL@ |
31 | 32 | ||
32 | mhds_get_test_SOURCES = \ | 33 | mhds_get_test_SOURCES = \ |
33 | mhds_get_test.c | 34 | mhds_get_test.c \ |
35 | $(top_builddir)/src/testcurl/curl_version_check.c | ||
34 | mhds_get_test_LDADD = \ | 36 | mhds_get_test_LDADD = \ |
35 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 37 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
36 | @LIBCURL@ | 38 | @LIBCURL@ |
37 | 39 | ||
38 | mhds_session_info_test_SOURCES = \ | 40 | mhds_session_info_test_SOURCES = \ |
39 | mhds_session_info_test.c | 41 | mhds_session_info_test.c \ |
42 | $(top_builddir)/src/testcurl/curl_version_check.c | ||
40 | mhds_session_info_test_LDADD = \ | 43 | mhds_session_info_test_LDADD = \ |
41 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 44 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
42 | @LIBCURL@ | 45 | @LIBCURL@ |
43 | 46 | ||
44 | mhds_multi_daemon_test_SOURCES = \ | 47 | mhds_multi_daemon_test_SOURCES = \ |
45 | mhds_multi_daemon_test.c | 48 | mhds_multi_daemon_test.c \ |
49 | $(top_builddir)/src/testcurl/curl_version_check.c | ||
46 | mhds_multi_daemon_test_LDADD = \ | 50 | mhds_multi_daemon_test_LDADD = \ |
47 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 51 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
48 | @LIBCURL@ | 52 | @LIBCURL@ |
diff --git a/src/testcurl/https/mhds_get_test.c b/src/testcurl/https/mhds_get_test.c index f69ed7d0..6a905df1 100644 --- a/src/testcurl/https/mhds_get_test.c +++ b/src/testcurl/https/mhds_get_test.c | |||
@@ -51,6 +51,8 @@ | |||
51 | const char *test_file_name = "https_test_file"; | 51 | const char *test_file_name = "https_test_file"; |
52 | const char test_file_data[] = "Hello World\n"; | 52 | const char test_file_data[] = "Hello World\n"; |
53 | 53 | ||
54 | extern int curl_check_version (const char *req_version, ...); | ||
55 | |||
54 | struct CBC | 56 | struct CBC |
55 | { | 57 | { |
56 | char *buf; | 58 | char *buf; |
@@ -416,7 +418,10 @@ main (int argc, char *const *argv) | |||
416 | FILE *test_fd; | 418 | FILE *test_fd; |
417 | unsigned int errorCount = 0; | 419 | unsigned int errorCount = 0; |
418 | 420 | ||
419 | // gnutls_global_set_log_level(11); | 421 | if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION)) |
422 | { | ||
423 | return -1; | ||
424 | } | ||
420 | 425 | ||
421 | if ((test_fd = setupTestFile ()) == NULL) | 426 | if ((test_fd = setupTestFile ()) == NULL) |
422 | { | 427 | { |
@@ -443,10 +448,10 @@ main (int argc, char *const *argv) | |||
443 | test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3); | 448 | test_kx_option (test_fd, "EDH-RSA-DES-CBC3-SHA", CURL_SSLVERSION_SSLv3); |
444 | 449 | ||
445 | 450 | ||
446 | curl_global_cleanup (); | 451 | curl_global_cleanup (); |
447 | fclose (test_fd); | 452 | fclose (test_fd); |
448 | 453 | ||
449 | remove (test_file_name); | 454 | remove (test_file_name); |
450 | 455 | ||
451 | return errorCount != 0; | 456 | return errorCount != 0; |
452 | } | 457 | } |
diff --git a/src/testcurl/https/mhds_multi_daemon_test.c b/src/testcurl/https/mhds_multi_daemon_test.c index 71858fa4..67f5d631 100644 --- a/src/testcurl/https/mhds_multi_daemon_test.c +++ b/src/testcurl/https/mhds_multi_daemon_test.c | |||
@@ -48,6 +48,8 @@ | |||
48 | const char *test_file_name = "https_test_file"; | 48 | const char *test_file_name = "https_test_file"; |
49 | const char test_file_data[] = "Hello World\n"; | 49 | const char test_file_data[] = "Hello World\n"; |
50 | 50 | ||
51 | extern int curl_check_version (const char *req_version, ...); | ||
52 | |||
51 | struct CBC | 53 | struct CBC |
52 | { | 54 | { |
53 | char *buf; | 55 | char *buf; |
@@ -300,6 +302,11 @@ main (int argc, char *const *argv) | |||
300 | FILE *test_fd; | 302 | FILE *test_fd; |
301 | unsigned int errorCount = 0; | 303 | unsigned int errorCount = 0; |
302 | 304 | ||
305 | if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION)) | ||
306 | { | ||
307 | return -1; | ||
308 | } | ||
309 | |||
303 | if ((test_fd = setupTestFile ()) == NULL) | 310 | if ((test_fd = setupTestFile ()) == NULL) |
304 | { | 311 | { |
305 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | 312 | 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 index 3b869913..1da67fe5 100644 --- a/src/testcurl/https/mhds_session_info_test.c +++ b/src/testcurl/https/mhds_session_info_test.c | |||
@@ -40,6 +40,8 @@ | |||
40 | 40 | ||
41 | #include "tls_test_keys.h" | 41 | #include "tls_test_keys.h" |
42 | 42 | ||
43 | extern int curl_check_version (const char *req_version, ...); | ||
44 | |||
43 | struct MHD_Daemon *d; | 45 | struct MHD_Daemon *d; |
44 | 46 | ||
45 | struct CBC | 47 | struct CBC |
@@ -213,6 +215,11 @@ main (int argc, char *const *argv) | |||
213 | FILE *test_fd; | 215 | FILE *test_fd; |
214 | unsigned int errorCount = 0; | 216 | unsigned int errorCount = 0; |
215 | 217 | ||
218 | if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION)) | ||
219 | { | ||
220 | return -1; | ||
221 | } | ||
222 | |||
216 | if (0 != curl_global_init (CURL_GLOBAL_ALL)) | 223 | if (0 != curl_global_init (CURL_GLOBAL_ALL)) |
217 | { | 224 | { |
218 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 225 | 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 index 29d5559c..3dcede26 100644 --- a/src/testcurl/https/tls_alert_test.c +++ b/src/testcurl/https/tls_alert_test.c | |||
@@ -48,6 +48,8 @@ | |||
48 | #include "gnutls_datum.h" | 48 | #include "gnutls_datum.h" |
49 | #include "tls_test_keys.h" | 49 | #include "tls_test_keys.h" |
50 | 50 | ||
51 | extern int curl_check_version (const char *req_version, ...); | ||
52 | |||
51 | const char *ca_cert_file_name = "ca_cert_pem"; | 53 | const char *ca_cert_file_name = "ca_cert_pem"; |
52 | const char *test_file_name = "https_test_file"; | 54 | const char *test_file_name = "https_test_file"; |
53 | const char test_file_data[] = "Hello World\n"; | 55 | const char test_file_data[] = "Hello World\n"; |
@@ -79,8 +81,6 @@ http_ahc (void *cls, struct MHD_Connection *connection, | |||
79 | static int | 81 | static int |
80 | test_alert_response () | 82 | test_alert_response () |
81 | { | 83 | { |
82 | |||
83 | |||
84 | int sd, ret; | 84 | int sd, ret; |
85 | char *err_pos; | 85 | char *err_pos; |
86 | struct sockaddr_in sa; | 86 | struct sockaddr_in sa; |
@@ -88,13 +88,11 @@ test_alert_response () | |||
88 | gnutls_session_t session; | 88 | gnutls_session_t session; |
89 | gnutls_certificate_credentials_t xcred; | 89 | gnutls_certificate_credentials_t xcred; |
90 | 90 | ||
91 | |||
92 | gnutls_global_init (); | 91 | gnutls_global_init (); |
93 | 92 | ||
94 | gnutls_datum_t key; | 93 | gnutls_datum_t key; |
95 | gnutls_datum_t cert; | 94 | gnutls_datum_t cert; |
96 | 95 | ||
97 | |||
98 | gnutls_certificate_allocate_credentials (&xcred); | 96 | gnutls_certificate_allocate_credentials (&xcred); |
99 | 97 | ||
100 | _gnutls_set_datum_m (&key, srv_key_pem, strlen (srv_key_pem), &malloc); | 98 | _gnutls_set_datum_m (&key, srv_key_pem, strlen (srv_key_pem), &malloc); |
@@ -157,14 +155,17 @@ test_alert_response () | |||
157 | 155 | ||
158 | } | 156 | } |
159 | 157 | ||
160 | |||
161 | |||
162 | int | 158 | int |
163 | main (int argc, char *const *argv) | 159 | main (int argc, char *const *argv) |
164 | { | 160 | { |
165 | int ret, errorCount = 0;; | 161 | int ret, errorCount = 0;; |
166 | struct MHD_Daemon *d; | 162 | struct MHD_Daemon *d; |
167 | 163 | ||
164 | if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION)) | ||
165 | { | ||
166 | return -1; | ||
167 | } | ||
168 | |||
168 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | | 169 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL | |
169 | MHD_USE_DEBUG, 42433, | 170 | MHD_USE_DEBUG, 42433, |
170 | NULL, NULL, &http_ahc, NULL, | 171 | NULL, NULL, &http_ahc, NULL, |
diff --git a/src/testcurl/https/tls_authentication_test.c b/src/testcurl/https/tls_authentication_test.c index af5ba348..fc0ae2f0 100644 --- a/src/testcurl/https/tls_authentication_test.c +++ b/src/testcurl/https/tls_authentication_test.c | |||
@@ -46,6 +46,8 @@ | |||
46 | 46 | ||
47 | #include "tls_test_keys.h" | 47 | #include "tls_test_keys.h" |
48 | 48 | ||
49 | extern int curl_check_version (const char *req_version, ...); | ||
50 | |||
49 | const char *ca_cert_file_name = "ca_cert_pem"; | 51 | const char *ca_cert_file_name = "ca_cert_pem"; |
50 | const char *test_file_name = "https_test_file"; | 52 | const char *test_file_name = "https_test_file"; |
51 | const char test_file_data[] = "Hello World\n"; | 53 | const char test_file_data[] = "Hello World\n"; |
@@ -315,6 +317,11 @@ main (int argc, char *const *argv) | |||
315 | FILE *test_fd; | 317 | FILE *test_fd; |
316 | unsigned int errorCount = 0; | 318 | unsigned int errorCount = 0; |
317 | 319 | ||
320 | if (curl_check_version (MHD_REQ_CURL_VERSION, MHD_REQ_CURL_SSL_VERSION)) | ||
321 | { | ||
322 | return -1; | ||
323 | } | ||
324 | |||
318 | if ((test_fd = setupTestFile ()) == NULL) | 325 | if ((test_fd = setupTestFile ()) == NULL) |
319 | { | 326 | { |
320 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); | 327 | fprintf (stderr, MHD_E_TEST_FILE_CREAT); |