aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_postprocessor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_postprocessor.c')
-rw-r--r--src/microhttpd/test_postprocessor.c68
1 files changed, 36 insertions, 32 deletions
diff --git a/src/microhttpd/test_postprocessor.c b/src/microhttpd/test_postprocessor.c
index acbb5b02..e1a167e7 100644
--- a/src/microhttpd/test_postprocessor.c
+++ b/src/microhttpd/test_postprocessor.c
@@ -48,13 +48,15 @@ const char *want[] = {
48 "x", NULL, NULL, NULL, "5", 48 "x", NULL, NULL, NULL, "5",
49#define URL_END (URL_START + 10) 49#define URL_END (URL_START + 10)
50 NULL, NULL, NULL, NULL, NULL, 50 NULL, NULL, NULL, NULL, NULL,
51#define FORM_DATA "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJoe Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata\r\n--AaB03x--\r\n" 51#define FORM_DATA \
52 "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJoe Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata\r\n--AaB03x--\r\n"
52#define FORM_START (URL_END + 5) 53#define FORM_START (URL_END + 5)
53 "field1", NULL, NULL, NULL, "Joe Blow", 54 "field1", NULL, NULL, NULL, "Joe Blow",
54 "pics", "file1.txt", "text/plain", "binary", "filedata", 55 "pics", "file1.txt", "text/plain", "binary", "filedata",
55#define FORM_END (FORM_START + 10) 56#define FORM_END (FORM_START + 10)
56 NULL, NULL, NULL, NULL, NULL, 57 NULL, NULL, NULL, NULL, NULL,
57#define FORM_NESTED_DATA "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJane Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"\r\nContent-type: multipart/mixed, boundary=BbC04y\r\n\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\n\r\nfiledata1\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file2.gif\"\r\nContent-type: image/gif\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata2\r\n--BbC04y--\r\n--AaB03x--" 58#define FORM_NESTED_DATA \
59 "--AaB03x\r\ncontent-disposition: form-data; name=\"field1\"\r\n\r\nJane Blow\r\n--AaB03x\r\ncontent-disposition: form-data; name=\"pics\"\r\nContent-type: multipart/mixed, boundary=BbC04y\r\n\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file1.txt\"\r\nContent-Type: text/plain\r\n\r\nfiledata1\r\n--BbC04y\r\nContent-disposition: attachment; filename=\"file2.gif\"\r\nContent-type: image/gif\r\nContent-Transfer-Encoding: binary\r\n\r\nfiledata2\r\n--BbC04y--\r\n--AaB03x--"
58#define FORM_NESTED_START (FORM_END + 5) 60#define FORM_NESTED_START (FORM_END + 5)
59 "field1", NULL, NULL, NULL, "Jane Blow", 61 "field1", NULL, NULL, NULL, "Jane Blow",
60 "pics", "file1.txt", "text/plain", NULL, "filedata1", 62 "pics", "file1.txt", "text/plain", NULL, "filedata1",
@@ -91,7 +93,7 @@ value_checker (void *cls,
91{ 93{
92 int *want_off = cls; 94 int *want_off = cls;
93 int idx = *want_off; 95 int idx = *want_off;
94 (void)kind; /* Unused. Silent compiler warning. */ 96 (void) kind; /* Unused. Silent compiler warning. */
95 97
96 98
97#if 0 99#if 0
@@ -110,10 +112,10 @@ value_checker (void *cls,
110 (mismatch (content_type, want[idx + 2])) || 112 (mismatch (content_type, want[idx + 2])) ||
111 (mismatch (transfer_encoding, want[idx + 3])) || 113 (mismatch (transfer_encoding, want[idx + 3])) ||
112 (0 != memcmp (data, &want[idx + 4][off], size))) 114 (0 != memcmp (data, &want[idx + 4][off], size)))
113 { 115 {
114 *want_off = -1; 116 *want_off = -1;
115 return MHD_NO; 117 return MHD_NO;
116 } 118 }
117 if (off + size == strlen (want[idx + 4])) 119 if (off + size == strlen (want[idx + 4]))
118 *want_off = idx + 5; 120 *want_off = idx + 5;
119 return MHD_YES; 121 return MHD_YES;
@@ -137,19 +139,20 @@ test_urlencoding (void)
137 connection.headers_received = &header; 139 connection.headers_received = &header;
138 header.header = MHD_HTTP_HEADER_CONTENT_TYPE; 140 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
139 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED; 141 header.value = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
140 header.header_size = MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONTENT_TYPE); 142 header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
141 header.value_size = MHD_STATICSTR_LEN_(MHD_HTTP_POST_ENCODING_FORM_URLENCODED); 143 header.value_size = MHD_STATICSTR_LEN_ (
144 MHD_HTTP_POST_ENCODING_FORM_URLENCODED);
142 header.kind = MHD_HEADER_KIND; 145 header.kind = MHD_HEADER_KIND;
143 pp = MHD_create_post_processor (&connection, 146 pp = MHD_create_post_processor (&connection,
144 1024, &value_checker, &want_off); 147 1024, &value_checker, &want_off);
145 i = 0; 148 i = 0;
146 size = strlen (URL_DATA); 149 size = strlen (URL_DATA);
147 while (i < size) 150 while (i < size)
148 { 151 {
149 delta = 1 + MHD_random_ () % (size - i); 152 delta = 1 + MHD_random_ () % (size - i);
150 MHD_post_process (pp, &URL_DATA[i], delta); 153 MHD_post_process (pp, &URL_DATA[i], delta);
151 i += delta; 154 i += delta;
152 } 155 }
153 MHD_destroy_post_processor (pp); 156 MHD_destroy_post_processor (pp);
154 if (want_off != URL_END) 157 if (want_off != URL_END)
155 return 1; 158 return 1;
@@ -183,8 +186,9 @@ test_multipart_garbage (void)
183 header.header = MHD_HTTP_HEADER_CONTENT_TYPE; 186 header.header = MHD_HTTP_HEADER_CONTENT_TYPE;
184 header.value = 187 header.value =
185 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"; 188 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x";
186 header.header_size = MHD_STATICSTR_LEN_(MHD_HTTP_HEADER_CONTENT_TYPE); 189 header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_CONTENT_TYPE);
187 header.value_size = MHD_STATICSTR_LEN_(MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x"); 190 header.value_size = MHD_STATICSTR_LEN_ (
191 MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA ", boundary=AaB03x");
188 header.kind = MHD_HEADER_KIND; 192 header.kind = MHD_HEADER_KIND;
189 pp = MHD_create_post_processor (&connection, 193 pp = MHD_create_post_processor (&connection,
190 1024, &value_checker, &want_off); 194 1024, &value_checker, &want_off);
@@ -258,11 +262,11 @@ test_multipart (void)
258 i = 0; 262 i = 0;
259 size = strlen (FORM_DATA); 263 size = strlen (FORM_DATA);
260 while (i < size) 264 while (i < size)
261 { 265 {
262 delta = 1 + MHD_random_ () % (size - i); 266 delta = 1 + MHD_random_ () % (size - i);
263 MHD_post_process (pp, &FORM_DATA[i], delta); 267 MHD_post_process (pp, &FORM_DATA[i], delta);
264 i += delta; 268 i += delta;
265 } 269 }
266 MHD_destroy_post_processor (pp); 270 MHD_destroy_post_processor (pp);
267 if (want_off != FORM_END) 271 if (want_off != FORM_END)
268 return 2; 272 return 2;
@@ -295,11 +299,11 @@ test_nested_multipart (void)
295 i = 0; 299 i = 0;
296 size = strlen (FORM_NESTED_DATA); 300 size = strlen (FORM_NESTED_DATA);
297 while (i < size) 301 while (i < size)
298 { 302 {
299 delta = 1 + MHD_random_ () % (size - i); 303 delta = 1 + MHD_random_ () % (size - i);
300 MHD_post_process (pp, &FORM_NESTED_DATA[i], delta); 304 MHD_post_process (pp, &FORM_NESTED_DATA[i], delta);
301 i += delta; 305 i += delta;
302 } 306 }
303 MHD_destroy_post_processor (pp); 307 MHD_destroy_post_processor (pp);
304 if (want_off != FORM_NESTED_END) 308 if (want_off != FORM_NESTED_END)
305 return 4; 309 return 4;
@@ -331,11 +335,11 @@ test_empty_value (void)
331 i = 0; 335 i = 0;
332 size = strlen (URL_EMPTY_VALUE_DATA); 336 size = strlen (URL_EMPTY_VALUE_DATA);
333 while (i < size) 337 while (i < size)
334 { 338 {
335 delta = 1 + MHD_random_ () % (size - i); 339 delta = 1 + MHD_random_ () % (size - i);
336 MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta); 340 MHD_post_process (pp, &URL_EMPTY_VALUE_DATA[i], delta);
337 i += delta; 341 i += delta;
338 } 342 }
339 MHD_destroy_post_processor (pp); 343 MHD_destroy_post_processor (pp);
340 if (want_off != URL_EMPTY_VALUE_END) 344 if (want_off != URL_EMPTY_VALUE_END)
341 return 8; 345 return 8;
@@ -349,7 +353,7 @@ int
349main (int argc, char *const *argv) 353main (int argc, char *const *argv)
350{ 354{
351 unsigned int errorCount = 0; 355 unsigned int errorCount = 0;
352 (void)argc; (void)argv; /* Unused. Silent compiler warning. */ 356 (void) argc; (void) argv; /* Unused. Silent compiler warning. */
353 357
354 errorCount += test_multipart_splits (); 358 errorCount += test_multipart_splits ();
355 errorCount += test_multipart_garbage (); 359 errorCount += test_multipart_garbage ();