diff options
Diffstat (limited to 'src/testcurl/test_long_header.c')
-rw-r--r-- | src/testcurl/test_long_header.c | 168 |
1 files changed, 87 insertions, 81 deletions
diff --git a/src/testcurl/test_long_header.c b/src/testcurl/test_long_header.c index dc76a136..01d62d11 100644 --- a/src/testcurl/test_long_header.c +++ b/src/testcurl/test_long_header.c | |||
@@ -42,14 +42,14 @@ | |||
42 | * half of this value, so the actual value does not have | 42 | * half of this value, so the actual value does not have |
43 | * to be big at all... | 43 | * to be big at all... |
44 | */ | 44 | */ |
45 | #define VERY_LONG (1024*8) | 45 | #define VERY_LONG (1024 * 8) |
46 | 46 | ||
47 | static int oneone; | 47 | static int oneone; |
48 | 48 | ||
49 | static int | 49 | static int |
50 | apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) | 50 | apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
51 | { | 51 | { |
52 | (void)cls;(void)addr;(void)addrlen; /* Unused. Silent compiler warning. */ | 52 | (void) cls; (void) addr; (void) addrlen; /* Unused. Silent compiler warning. */ |
53 | return MHD_YES; | 53 | return MHD_YES; |
54 | } | 54 | } |
55 | 55 | ||
@@ -63,7 +63,7 @@ struct CBC | |||
63 | static size_t | 63 | static size_t |
64 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 64 | copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx) |
65 | { | 65 | { |
66 | (void)ptr;(void)ctx; /* Unused. Silent compiler warning. */ | 66 | (void) ptr; (void) ctx; /* Unused. Silent compiler warning. */ |
67 | return size * nmemb; | 67 | return size * nmemb; |
68 | } | 68 | } |
69 | 69 | ||
@@ -79,14 +79,14 @@ ahc_echo (void *cls, | |||
79 | const char *me = cls; | 79 | const char *me = cls; |
80 | struct MHD_Response *response; | 80 | struct MHD_Response *response; |
81 | int ret; | 81 | int ret; |
82 | (void)version;(void)upload_data; /* Unused. Silent compiler warning. */ | 82 | (void) version; (void) upload_data; /* Unused. Silent compiler warning. */ |
83 | (void)upload_data_size;(void)unused; /* Unused. Silent compiler warning. */ | 83 | (void) upload_data_size; (void) unused; /* Unused. Silent compiler warning. */ |
84 | 84 | ||
85 | if (0 != strcmp (me, method)) | 85 | if (0 != strcmp (me, method)) |
86 | return MHD_NO; /* unexpected method */ | 86 | return MHD_NO; /* unexpected method */ |
87 | response = MHD_create_response_from_buffer (strlen (url), | 87 | response = MHD_create_response_from_buffer (strlen (url), |
88 | (void *) url, | 88 | (void *) url, |
89 | MHD_RESPMEM_MUST_COPY); | 89 | MHD_RESPMEM_MUST_COPY); |
90 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 90 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
91 | MHD_destroy_response (response); | 91 | MHD_destroy_response (response); |
92 | return ret; | 92 | return ret; |
@@ -107,44 +107,47 @@ testLongUrlGet (size_t buff_size) | |||
107 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 107 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
108 | port = 0; | 108 | port = 0; |
109 | else | 109 | else |
110 | { | 110 | { |
111 | port = 1330 + buff_size % 20; | 111 | port = 1330 + buff_size % 20; |
112 | if (oneone) | 112 | if (oneone) |
113 | port += 5; | 113 | port += 5; |
114 | } | 114 | } |
115 | cbc.buf = buf; | 115 | cbc.buf = buf; |
116 | cbc.size = 2048; | 116 | cbc.size = 2048; |
117 | cbc.pos = 0; | 117 | cbc.pos = 0; |
118 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , | 118 | d = MHD_start_daemon ( |
119 | port, | 119 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */, |
120 | &apc_all, | 120 | port, |
121 | NULL, | 121 | &apc_all, |
122 | &ahc_echo, | 122 | NULL, |
123 | "GET", | 123 | &ahc_echo, |
124 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 124 | "GET", |
125 | (size_t) buff_size, MHD_OPTION_END); | 125 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
126 | (size_t) buff_size, MHD_OPTION_END); | ||
126 | if (d == NULL) | 127 | if (d == NULL) |
127 | return 1; | 128 | return 1; |
128 | if (0 == port) | 129 | if (0 == port) |
130 | { | ||
131 | const union MHD_DaemonInfo *dinfo; | ||
132 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
133 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
129 | { | 134 | { |
130 | const union MHD_DaemonInfo *dinfo; | 135 | MHD_stop_daemon (d); return 32; |
131 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
132 | if (NULL == dinfo || 0 == dinfo->port) | ||
133 | { MHD_stop_daemon (d); return 32; } | ||
134 | port = (int)dinfo->port; | ||
135 | } | 136 | } |
137 | port = (int) dinfo->port; | ||
138 | } | ||
136 | c = curl_easy_init (); | 139 | c = curl_easy_init (); |
137 | url = malloc (VERY_LONG); | 140 | url = malloc (VERY_LONG); |
138 | if (url == NULL) | 141 | if (url == NULL) |
139 | { | 142 | { |
140 | MHD_stop_daemon (d); | 143 | MHD_stop_daemon (d); |
141 | return 1; | 144 | return 1; |
142 | } | 145 | } |
143 | memset (url, 'a', VERY_LONG); | 146 | memset (url, 'a', VERY_LONG); |
144 | url[VERY_LONG - 1] = '\0'; | 147 | url[VERY_LONG - 1] = '\0'; |
145 | memcpy (url, "http://127.0.0.1/", strlen ("http://127.0.0.1/")); | 148 | memcpy (url, "http://127.0.0.1/", strlen ("http://127.0.0.1/")); |
146 | curl_easy_setopt (c, CURLOPT_URL, url); | 149 | curl_easy_setopt (c, CURLOPT_URL, url); |
147 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 150 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
148 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 151 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
149 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 152 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
150 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 153 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -159,19 +162,19 @@ testLongUrlGet (size_t buff_size) | |||
159 | crashes on my system! */ | 162 | crashes on my system! */ |
160 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 163 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
161 | if (CURLE_OK == curl_easy_perform (c)) | 164 | if (CURLE_OK == curl_easy_perform (c)) |
162 | { | 165 | { |
163 | curl_easy_cleanup (c); | 166 | curl_easy_cleanup (c); |
164 | MHD_stop_daemon (d); | 167 | MHD_stop_daemon (d); |
165 | free (url); | 168 | free (url); |
166 | return 2; | 169 | return 2; |
167 | } | 170 | } |
168 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) | 171 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) |
169 | { | 172 | { |
170 | curl_easy_cleanup (c); | 173 | curl_easy_cleanup (c); |
171 | MHD_stop_daemon (d); | 174 | MHD_stop_daemon (d); |
172 | free (url); | 175 | free (url); |
173 | return 4; | 176 | return 4; |
174 | } | 177 | } |
175 | curl_easy_cleanup (c); | 178 | curl_easy_cleanup (c); |
176 | MHD_stop_daemon (d); | 179 | MHD_stop_daemon (d); |
177 | free (url); | 180 | free (url); |
@@ -196,40 +199,43 @@ testLongHeaderGet (size_t buff_size) | |||
196 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) | 199 | if (MHD_NO != MHD_is_feature_supported (MHD_FEATURE_AUTODETECT_BIND_PORT)) |
197 | port = 0; | 200 | port = 0; |
198 | else | 201 | else |
199 | { | 202 | { |
200 | port = 1331 + buff_size % 20; | 203 | port = 1331 + buff_size % 20; |
201 | if (oneone) | 204 | if (oneone) |
202 | port += 5; | 205 | port += 5; |
203 | } | 206 | } |
204 | 207 | ||
205 | cbc.buf = buf; | 208 | cbc.buf = buf; |
206 | cbc.size = 2048; | 209 | cbc.size = 2048; |
207 | cbc.pos = 0; | 210 | cbc.pos = 0; |
208 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */ , | 211 | d = MHD_start_daemon ( |
209 | port, | 212 | MHD_USE_INTERNAL_POLLING_THREAD /* | MHD_USE_ERROR_LOG */, |
210 | &apc_all, | 213 | port, |
211 | NULL, | 214 | &apc_all, |
212 | &ahc_echo, | 215 | NULL, |
213 | "GET", | 216 | &ahc_echo, |
214 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, | 217 | "GET", |
215 | (size_t) buff_size, MHD_OPTION_END); | 218 | MHD_OPTION_CONNECTION_MEMORY_LIMIT, |
219 | (size_t) buff_size, MHD_OPTION_END); | ||
216 | if (d == NULL) | 220 | if (d == NULL) |
217 | return 16; | 221 | return 16; |
218 | if (0 == port) | 222 | if (0 == port) |
223 | { | ||
224 | const union MHD_DaemonInfo *dinfo; | ||
225 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
226 | if ((NULL == dinfo) ||(0 == dinfo->port) ) | ||
219 | { | 227 | { |
220 | const union MHD_DaemonInfo *dinfo; | 228 | MHD_stop_daemon (d); return 32; |
221 | dinfo = MHD_get_daemon_info (d, MHD_DAEMON_INFO_BIND_PORT); | ||
222 | if (NULL == dinfo || 0 == dinfo->port) | ||
223 | { MHD_stop_daemon (d); return 32; } | ||
224 | port = (int)dinfo->port; | ||
225 | } | 229 | } |
230 | port = (int) dinfo->port; | ||
231 | } | ||
226 | c = curl_easy_init (); | 232 | c = curl_easy_init (); |
227 | url = malloc (VERY_LONG); | 233 | url = malloc (VERY_LONG); |
228 | if (url == NULL) | 234 | if (url == NULL) |
229 | { | 235 | { |
230 | MHD_stop_daemon (d); | 236 | MHD_stop_daemon (d); |
231 | return 16; | 237 | return 16; |
232 | } | 238 | } |
233 | memset (url, 'a', VERY_LONG); | 239 | memset (url, 'a', VERY_LONG); |
234 | url[VERY_LONG - 1] = '\0'; | 240 | url[VERY_LONG - 1] = '\0'; |
235 | url[VERY_LONG / 2] = ':'; | 241 | url[VERY_LONG / 2] = ':'; |
@@ -238,7 +244,7 @@ testLongHeaderGet (size_t buff_size) | |||
238 | 244 | ||
239 | curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); | 245 | curl_easy_setopt (c, CURLOPT_HTTPHEADER, header); |
240 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); | 246 | curl_easy_setopt (c, CURLOPT_URL, "http://127.0.0.1/hello_world"); |
241 | curl_easy_setopt (c, CURLOPT_PORT, (long)port); | 247 | curl_easy_setopt (c, CURLOPT_PORT, (long) port); |
242 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 248 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
243 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 249 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
244 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); | 250 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L); |
@@ -253,21 +259,21 @@ testLongHeaderGet (size_t buff_size) | |||
253 | crashes on my system! */ | 259 | crashes on my system! */ |
254 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); | 260 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L); |
255 | if (CURLE_OK == curl_easy_perform (c)) | 261 | if (CURLE_OK == curl_easy_perform (c)) |
256 | { | 262 | { |
257 | curl_easy_cleanup (c); | 263 | curl_easy_cleanup (c); |
258 | MHD_stop_daemon (d); | 264 | MHD_stop_daemon (d); |
259 | curl_slist_free_all (header); | 265 | curl_slist_free_all (header); |
260 | free (url); | 266 | free (url); |
261 | return 32; | 267 | return 32; |
262 | } | 268 | } |
263 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) | 269 | if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code)) |
264 | { | 270 | { |
265 | curl_slist_free_all (header); | 271 | curl_slist_free_all (header); |
266 | curl_easy_cleanup (c); | 272 | curl_easy_cleanup (c); |
267 | MHD_stop_daemon (d); | 273 | MHD_stop_daemon (d); |
268 | free (url); | 274 | free (url); |
269 | return 64; | 275 | return 64; |
270 | } | 276 | } |
271 | curl_slist_free_all (header); | 277 | curl_slist_free_all (header); |
272 | curl_easy_cleanup (c); | 278 | curl_easy_cleanup (c); |
273 | MHD_stop_daemon (d); | 279 | MHD_stop_daemon (d); |
@@ -281,9 +287,9 @@ int | |||
281 | main (int argc, char *const *argv) | 287 | main (int argc, char *const *argv) |
282 | { | 288 | { |
283 | unsigned int errorCount = 0; | 289 | unsigned int errorCount = 0; |
284 | (void)argc; /* Unused. Silent compiler warning. */ | 290 | (void) argc; /* Unused. Silent compiler warning. */ |
285 | 291 | ||
286 | if (NULL == argv || 0 == argv[0]) | 292 | if ((NULL == argv)||(0 == argv[0])) |
287 | return 99; | 293 | return 99; |
288 | oneone = has_in_name (argv[0], "11"); | 294 | oneone = has_in_name (argv[0], "11"); |
289 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 295 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |