diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/connection.c | 12 | ||||
-rw-r--r-- | src/testcurl/Makefile.am | 7 | ||||
-rw-r--r-- | src/testcurl/daemontest_urlparse.c | 187 |
3 files changed, 205 insertions, 1 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index 00188a84..5c2106ee 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -1056,7 +1056,17 @@ parse_arguments (enum MHD_ValueKind kind, | |||
1056 | { | 1056 | { |
1057 | equals = strstr (args, "="); | 1057 | equals = strstr (args, "="); |
1058 | if (equals == NULL) | 1058 | if (equals == NULL) |
1059 | return MHD_NO; /* invalid, ignore */ | 1059 | { |
1060 | /* add with 'value' NULL */ | ||
1061 | connection->daemon->unescape_callback (connection->daemon->unescape_callback_cls, | ||
1062 | connection, | ||
1063 | args); | ||
1064 | |||
1065 | return connection_add_header (connection, | ||
1066 | args, | ||
1067 | NULL, | ||
1068 | kind); | ||
1069 | } | ||
1060 | equals[0] = '\0'; | 1070 | equals[0] = '\0'; |
1061 | equals++; | 1071 | equals++; |
1062 | amper = strstr (equals, "&"); | 1072 | amper = strstr (equals, "&"); |
diff --git a/src/testcurl/Makefile.am b/src/testcurl/Makefile.am index 5a8d07cc..73c6840b 100644 --- a/src/testcurl/Makefile.am +++ b/src/testcurl/Makefile.am | |||
@@ -29,6 +29,7 @@ endif | |||
29 | check_PROGRAMS = \ | 29 | check_PROGRAMS = \ |
30 | daemontest_get \ | 30 | daemontest_get \ |
31 | daemontest_get_sendfile \ | 31 | daemontest_get_sendfile \ |
32 | daemontest_urlparse \ | ||
32 | daemontest_post \ | 33 | daemontest_post \ |
33 | daemontest_postform \ | 34 | daemontest_postform \ |
34 | daemontest_post_loop \ | 35 | daemontest_post_loop \ |
@@ -114,6 +115,12 @@ daemontest_get_sendfile_LDADD = \ | |||
114 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | 115 | $(top_builddir)/src/daemon/libmicrohttpd.la \ |
115 | @LIBCURL@ | 116 | @LIBCURL@ |
116 | 117 | ||
118 | daemontest_urlparse_SOURCES = \ | ||
119 | daemontest_urlparse.c | ||
120 | daemontest_urlparse_LDADD = \ | ||
121 | $(top_builddir)/src/daemon/libmicrohttpd.la \ | ||
122 | @LIBCURL@ | ||
123 | |||
117 | daemontest_get_response_cleanup_SOURCES = \ | 124 | daemontest_get_response_cleanup_SOURCES = \ |
118 | daemontest_get_response_cleanup.c | 125 | daemontest_get_response_cleanup.c |
119 | daemontest_get_response_cleanup_LDADD = \ | 126 | daemontest_get_response_cleanup_LDADD = \ |
diff --git a/src/testcurl/daemontest_urlparse.c b/src/testcurl/daemontest_urlparse.c new file mode 100644 index 00000000..9e0c9d30 --- /dev/null +++ b/src/testcurl/daemontest_urlparse.c | |||
@@ -0,0 +1,187 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007, 2009, 2011 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 daemontest_urlparse.c | ||
23 | * @brief Testcase for libmicrohttpd url parsing | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "MHD_config.h" | ||
28 | #include "platform.h" | ||
29 | #include <curl/curl.h> | ||
30 | #include <microhttpd.h> | ||
31 | #include <stdlib.h> | ||
32 | #include <string.h> | ||
33 | #include <time.h> | ||
34 | |||
35 | #ifdef __MINGW32__ | ||
36 | #define usleep(usec) (Sleep ((usec) / 1000),0) | ||
37 | #endif | ||
38 | |||
39 | #ifndef WINDOWS | ||
40 | #include <unistd.h> | ||
41 | #include <sys/socket.h> | ||
42 | #endif | ||
43 | |||
44 | static int oneone; | ||
45 | |||
46 | static int matches; | ||
47 | |||
48 | struct CBC | ||
49 | { | ||
50 | char *buf; | ||
51 | size_t pos; | ||
52 | size_t size; | ||
53 | }; | ||
54 | |||
55 | static size_t | ||
56 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | ||
57 | { | ||
58 | struct CBC *cbc = ctx; | ||
59 | |||
60 | if (cbc->pos + size * nmemb > cbc->size) | ||
61 | return 0; /* overflow */ | ||
62 | memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | ||
63 | cbc->pos += size * nmemb; | ||
64 | return size * nmemb; | ||
65 | } | ||
66 | |||
67 | static int | ||
68 | test_values (void *cls, | ||
69 | enum MHD_ValueKind kind, | ||
70 | const char *key, | ||
71 | const char *value) | ||
72 | { | ||
73 | if ( (0 == strcmp (key, "a")) && | ||
74 | (0 == strcmp (value, "b")) ) | ||
75 | matches += 1; | ||
76 | if ( (0 == strcmp (key, "c")) && | ||
77 | (0 == strcmp (value, "")) ) | ||
78 | matches += 2; | ||
79 | if ( (0 == strcmp (key, "d")) && | ||
80 | (NULL == value) ) | ||
81 | matches += 4; | ||
82 | return MHD_YES; | ||
83 | } | ||
84 | |||
85 | static int | ||
86 | ahc_echo (void *cls, | ||
87 | struct MHD_Connection *connection, | ||
88 | const char *url, | ||
89 | const char *method, | ||
90 | const char *version, | ||
91 | const char *upload_data, size_t *upload_data_size, | ||
92 | void **unused) | ||
93 | { | ||
94 | static int ptr; | ||
95 | const char *me = cls; | ||
96 | struct MHD_Response *response; | ||
97 | int ret; | ||
98 | |||
99 | if (0 != strcmp (me, method)) | ||
100 | return MHD_NO; /* unexpected method */ | ||
101 | if (&ptr != *unused) | ||
102 | { | ||
103 | *unused = &ptr; | ||
104 | return MHD_YES; | ||
105 | } | ||
106 | MHD_get_connection_values (connection, | ||
107 | MHD_GET_ARGUMENT_KIND, | ||
108 | &test_values, | ||
109 | NULL); | ||
110 | *unused = NULL; | ||
111 | response = MHD_create_response_from_buffer (strlen (url), | ||
112 | (void *) url, | ||
113 | MHD_RESPMEM_MUST_COPY); | ||
114 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | ||
115 | MHD_destroy_response (response); | ||
116 | if (ret == MHD_NO) | ||
117 | abort (); | ||
118 | return ret; | ||
119 | } | ||
120 | |||
121 | |||
122 | static int | ||
123 | testInternalGet (int poll_flag) | ||
124 | { | ||
125 | struct MHD_Daemon *d; | ||
126 | CURL *c; | ||
127 | char buf[2048]; | ||
128 | struct CBC cbc; | ||
129 | CURLcode errornum; | ||
130 | |||
131 | cbc.buf = buf; | ||
132 | cbc.size = 2048; | ||
133 | cbc.pos = 0; | ||
134 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG | poll_flag, | ||
135 | 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | ||
136 | if (d == NULL) | ||
137 | return 1; | ||
138 | c = curl_easy_init (); | ||
139 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/hello_world?a=b&c=&d"); | ||
140 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
141 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
142 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
143 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
144 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
145 | if (oneone) | ||
146 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
147 | else | ||
148 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
149 | /* NOTE: use of CONNECTTIMEOUT without also | ||
150 | setting NOSIGNAL results in really weird | ||
151 | crashes on my system!*/ | ||
152 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
153 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
154 | { | ||
155 | fprintf (stderr, | ||
156 | "curl_easy_perform failed: `%s'\n", | ||
157 | curl_easy_strerror (errornum)); | ||
158 | curl_easy_cleanup (c); | ||
159 | MHD_stop_daemon (d); | ||
160 | return 2; | ||
161 | } | ||
162 | curl_easy_cleanup (c); | ||
163 | MHD_stop_daemon (d); | ||
164 | if (cbc.pos != strlen ("/hello_world")) | ||
165 | return 4; | ||
166 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
167 | return 8; | ||
168 | if (matches != 7) | ||
169 | return 16; | ||
170 | return 0; | ||
171 | } | ||
172 | |||
173 | |||
174 | int | ||
175 | main (int argc, char *const *argv) | ||
176 | { | ||
177 | unsigned int errorCount = 0; | ||
178 | |||
179 | oneone = NULL != strstr (argv[0], "11"); | ||
180 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | ||
181 | return 2; | ||
182 | errorCount += testInternalGet (0); | ||
183 | if (errorCount != 0) | ||
184 | fprintf (stderr, "Error (code: %u)\n", errorCount); | ||
185 | curl_global_cleanup (); | ||
186 | return errorCount != 0; /* 0 == pass */ | ||
187 | } | ||