aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemontest_long_header.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemontest_long_header.c')
-rw-r--r--src/daemon/daemontest_long_header.c321
1 files changed, 135 insertions, 186 deletions
diff --git a/src/daemon/daemontest_long_header.c b/src/daemon/daemontest_long_header.c
index 48635704..d0e26484 100644
--- a/src/daemon/daemontest_long_header.c
+++ b/src/daemon/daemontest_long_header.c
@@ -41,247 +41,196 @@
41 41
42static int oneone; 42static int oneone;
43 43
44static int apc_all(void * cls, 44static int
45 const struct sockaddr * addr, 45apc_all (void *cls, const struct sockaddr *addr, socklen_t addrlen)
46 socklen_t addrlen) { 46{
47 return MHD_YES; 47 return MHD_YES;
48} 48}
49 49
50struct CBC { 50struct CBC
51 char * buf; 51{
52 char *buf;
52 size_t pos; 53 size_t pos;
53 size_t size; 54 size_t size;
54}; 55};
55 56
56static size_t copyBuffer(void * ptr, 57static size_t
57 size_t size, 58copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
58 size_t nmemb, 59{
59 void * ctx) {
60 return size * nmemb; 60 return size * nmemb;
61} 61}
62 62
63static int ahc_echo(void * cls, 63static int
64 struct MHD_Connection * connection, 64ahc_echo (void *cls,
65 const char * url, 65 struct MHD_Connection *connection,
66 const char * method, 66 const char *url,
67 const char * version, 67 const char *method,
68 const char * upload_data, 68 const char *version,
69 unsigned int * upload_data_size) { 69 const char *upload_data, unsigned int *upload_data_size)
70 const char * me = cls; 70{
71 struct MHD_Response * response; 71 const char *me = cls;
72 struct MHD_Response *response;
72 int ret; 73 int ret;
73 74
74 if (0 != strcmp(me, method)) 75 if (0 != strcmp (me, method))
75 return MHD_NO; /* unexpected method */ 76 return MHD_NO; /* unexpected method */
76 response = MHD_create_response_from_data(strlen(url), 77 response = MHD_create_response_from_data (strlen (url),
77 (void*) url, 78 (void *) url, MHD_NO, MHD_YES);
78 MHD_NO, 79 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
79 MHD_YES); 80 MHD_destroy_response (response);
80 ret = MHD_queue_response(connection,
81 MHD_HTTP_OK,
82 response);
83 MHD_destroy_response(response);
84 return ret; 81 return ret;
85} 82}
86 83
87 84
88static int testLongUrlGet() { 85static int
89 struct MHD_Daemon * d; 86testLongUrlGet ()
90 CURL * c; 87{
88 struct MHD_Daemon *d;
89 CURL *c;
91 char buf[2048]; 90 char buf[2048];
92 struct CBC cbc; 91 struct CBC cbc;
93 char * url; 92 char *url;
94 long code; 93 long code;
95 94
96 cbc.buf = buf; 95 cbc.buf = buf;
97 cbc.size = 2048; 96 cbc.size = 2048;
98 cbc.pos = 0; 97 cbc.pos = 0;
99 d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */, 98 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
100 1080, 99 1080,
101 &apc_all, 100 &apc_all,
102 NULL, 101 NULL,
103 &ahc_echo, 102 &ahc_echo,
104 "GET", 103 "GET",
105 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 104 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
106 VERY_LONG / 2, 105 VERY_LONG / 2, MHD_OPTION_END);
107 MHD_OPTION_END);
108 if (d == NULL) 106 if (d == NULL)
109 return 1; 107 return 1;
110 c = curl_easy_init(); 108 c = curl_easy_init ();
111 url = malloc(VERY_LONG); 109 url = malloc (VERY_LONG);
112 memset(url, 110 memset (url, 'a', VERY_LONG);
113 'a', 111 url[VERY_LONG - 1] = '\0';
114 VERY_LONG); 112 memcpy (url, "http://localhost:1080/", strlen ("http://localhost:1080/"));
115 url[VERY_LONG-1] = '\0'; 113 curl_easy_setopt (c, CURLOPT_URL, url);
116 memcpy(url, 114 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
117 "http://localhost:1080/", 115 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
118 strlen("http://localhost:1080/")); 116 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
119 curl_easy_setopt(c, 117 curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L);
120 CURLOPT_URL, 118 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 2L);
121 url);
122 curl_easy_setopt(c,
123 CURLOPT_WRITEFUNCTION,
124 &copyBuffer);
125 curl_easy_setopt(c,
126 CURLOPT_WRITEDATA,
127 &cbc);
128 curl_easy_setopt(c,
129 CURLOPT_FAILONERROR,
130 1);
131 curl_easy_setopt(c,
132 CURLOPT_TIMEOUT,
133 2L);
134 curl_easy_setopt(c,
135 CURLOPT_CONNECTTIMEOUT,
136 2L);
137 if (oneone) 119 if (oneone)
138 curl_easy_setopt(c, 120 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
139 CURLOPT_HTTP_VERSION,
140 CURL_HTTP_VERSION_1_1);
141 else 121 else
142 curl_easy_setopt(c, 122 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
143 CURLOPT_HTTP_VERSION, 123 // NOTE: use of CONNECTTIMEOUT without also
144 CURL_HTTP_VERSION_1_0);
145 // NOTE: use of CONNECTTIMEOUT without also
146 // setting NOSIGNAL results in really weird 124 // setting NOSIGNAL results in really weird
147 // crashes on my system! 125 // crashes on my system!
148 curl_easy_setopt(c, 126 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
149 CURLOPT_NOSIGNAL, 127 if (CURLE_OK == curl_easy_perform (c))
150 1); 128 {
151 if (CURLE_OK == curl_easy_perform(c)) { 129 curl_easy_cleanup (c);
152 curl_easy_cleanup(c); 130 MHD_stop_daemon (d);
153 MHD_stop_daemon(d); 131 free (url);
154 free(url); 132 return 2;
155 return 2; 133 }
156 } 134 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
157 if (CURLE_OK != curl_easy_getinfo(c, 135 {
158 CURLINFO_RESPONSE_CODE, 136 curl_easy_cleanup (c);
159 &code)) { 137 MHD_stop_daemon (d);
160 curl_easy_cleanup(c); 138 free (url);
161 MHD_stop_daemon(d); 139 return 4;
162 free(url); 140 }
163 return 4; 141 curl_easy_cleanup (c);
164 } 142 MHD_stop_daemon (d);
165 curl_easy_cleanup(c); 143 free (url);
166 MHD_stop_daemon(d);
167 free(url);
168 if (code != MHD_HTTP_REQUEST_URI_TOO_LONG) 144 if (code != MHD_HTTP_REQUEST_URI_TOO_LONG)
169 return 8; 145 return 8;
170 return 0; 146 return 0;
171} 147}
172 148
173 149
174static int testLongHeaderGet() { 150static int
175 struct MHD_Daemon * d; 151testLongHeaderGet ()
176 CURL * c; 152{
153 struct MHD_Daemon *d;
154 CURL *c;
177 char buf[2048]; 155 char buf[2048];
178 struct CBC cbc; 156 struct CBC cbc;
179 char * url; 157 char *url;
180 long code; 158 long code;
181 struct curl_slist * header = NULL; 159 struct curl_slist *header = NULL;
182 160
183 cbc.buf = buf; 161 cbc.buf = buf;
184 cbc.size = 2048; 162 cbc.size = 2048;
185 cbc.pos = 0; 163 cbc.pos = 0;
186 d = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */, 164 d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ ,
187 1080, 165 1080,
188 &apc_all, 166 &apc_all,
189 NULL, 167 NULL,
190 &ahc_echo, 168 &ahc_echo,
191 "GET", 169 "GET",
192 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 170 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
193 VERY_LONG / 2, 171 VERY_LONG / 2, MHD_OPTION_END);
194 MHD_OPTION_END);
195 if (d == NULL) 172 if (d == NULL)
196 return 16; 173 return 16;
197 c = curl_easy_init(); 174 c = curl_easy_init ();
198 url = malloc(VERY_LONG); 175 url = malloc (VERY_LONG);
199 memset(url, 176 memset (url, 'a', VERY_LONG);
200 'a', 177 url[VERY_LONG - 1] = '\0';
201 VERY_LONG); 178 url[VERY_LONG / 2] = ':';
202 url[VERY_LONG-1] = '\0'; 179 url[VERY_LONG / 2 + 1] = ':';
203 url[VERY_LONG/2] = ':'; 180 header = curl_slist_append (header, url);
204 url[VERY_LONG/2+1] = ':'; 181
205 header = curl_slist_append(header, 182 curl_easy_setopt (c, CURLOPT_HTTPHEADER, header);
206 url); 183 curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world");
207 184 curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, &copyBuffer);
208 curl_easy_setopt(c, 185 curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
209 CURLOPT_HTTPHEADER, 186 curl_easy_setopt (c, CURLOPT_FAILONERROR, 1);
210 header); 187 curl_easy_setopt (c, CURLOPT_TIMEOUT, 2L);
211 curl_easy_setopt(c, 188 curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 2L);
212 CURLOPT_URL,
213 "http://localhost:1080/hello_world");
214 curl_easy_setopt(c,
215 CURLOPT_WRITEFUNCTION,
216 &copyBuffer);
217 curl_easy_setopt(c,
218 CURLOPT_WRITEDATA,
219 &cbc);
220 curl_easy_setopt(c,
221 CURLOPT_FAILONERROR,
222 1);
223 curl_easy_setopt(c,
224 CURLOPT_TIMEOUT,
225 2L);
226 curl_easy_setopt(c,
227 CURLOPT_CONNECTTIMEOUT,
228 2L);
229 if (oneone) 189 if (oneone)
230 curl_easy_setopt(c, 190 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
231 CURLOPT_HTTP_VERSION,
232 CURL_HTTP_VERSION_1_1);
233 else 191 else
234 curl_easy_setopt(c, 192 curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
235 CURLOPT_HTTP_VERSION, 193 // NOTE: use of CONNECTTIMEOUT without also
236 CURL_HTTP_VERSION_1_0);
237 // NOTE: use of CONNECTTIMEOUT without also
238 // setting NOSIGNAL results in really weird 194 // setting NOSIGNAL results in really weird
239 // crashes on my system! 195 // crashes on my system!
240 curl_easy_setopt(c, 196 curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1);
241 CURLOPT_NOSIGNAL, 197 if (CURLE_OK == curl_easy_perform (c))
242 1); 198 {
243 if (CURLE_OK == curl_easy_perform(c)) { 199 curl_easy_cleanup (c);
244 curl_easy_cleanup(c); 200 MHD_stop_daemon (d);
245 MHD_stop_daemon(d); 201 curl_slist_free_all (header);
246 curl_slist_free_all(header); 202 free (url);
247 free(url); 203 return 32;
248 return 32; 204 }
249 } 205 if (CURLE_OK != curl_easy_getinfo (c, CURLINFO_RESPONSE_CODE, &code))
250 if (CURLE_OK != curl_easy_getinfo(c, 206 {
251 CURLINFO_RESPONSE_CODE, 207 curl_slist_free_all (header);
252 &code)) { 208 curl_easy_cleanup (c);
253 curl_slist_free_all(header); 209 MHD_stop_daemon (d);
254 curl_easy_cleanup(c); 210 free (url);
255 MHD_stop_daemon(d); 211 return 64;
256 free(url); 212 }
257 return 64; 213 curl_slist_free_all (header);
258 } 214 curl_easy_cleanup (c);
259 curl_slist_free_all(header); 215 MHD_stop_daemon (d);
260 curl_easy_cleanup(c); 216 free (url);
261 MHD_stop_daemon(d);
262 free(url);
263 if (code != MHD_HTTP_REQUEST_ENTITY_TOO_LARGE) 217 if (code != MHD_HTTP_REQUEST_ENTITY_TOO_LARGE)
264 return 128; 218 return 128;
265 return 0; 219 return 0;
266} 220}
267 221
268 222int
269 223main (int argc, char *const *argv)
270 224{
271
272int main(int argc,
273 char * const * argv) {
274 unsigned int errorCount = 0; 225 unsigned int errorCount = 0;
275 226
276 oneone = NULL != strstr(argv[0], "11"); 227 oneone = NULL != strstr (argv[0], "11");
277 if (0 != curl_global_init(CURL_GLOBAL_WIN32)) 228 if (0 != curl_global_init (CURL_GLOBAL_WIN32))
278 return 2; 229 return 2;
279 errorCount += testLongUrlGet(); 230 errorCount += testLongUrlGet ();
280 errorCount += testLongHeaderGet(); 231 errorCount += testLongHeaderGet ();
281 if (errorCount != 0) 232 if (errorCount != 0)
282 fprintf(stderr, 233 fprintf (stderr, "Error (code: %u)\n", errorCount);
283 "Error (code: %u)\n", 234 curl_global_cleanup ();
284 errorCount); 235 return errorCount != 0; /* 0 == pass */
285 curl_global_cleanup();
286 return errorCount != 0; /* 0 == pass */
287} 236}