aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/test_postprocessor_md.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/test_postprocessor_md.c')
-rw-r--r--src/microhttpd/test_postprocessor_md.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/microhttpd/test_postprocessor_md.c b/src/microhttpd/test_postprocessor_md.c
new file mode 100644
index 00000000..1e9e4143
--- /dev/null
+++ b/src/microhttpd/test_postprocessor_md.c
@@ -0,0 +1,132 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2020 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 3, 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file test_postprocessor.c
22 * @brief Testcase for postprocessor, keys with no value
23 * @author Markus Doppelbauer
24 */
25#include "MHD_config.h"
26#include <stdio.h>
27#include <stdlib.h>
28#include <microhttpd.h>
29
30/**
31 * Handler for fatal errors.
32 */
33MHD_PanicCallback mhd_panic;
34
35/**
36 * Closure argument for #mhd_panic.
37 */
38void *mhd_panic_cls;
39
40
41enum MHD_Result
42MHD_lookup_connection_value_n (struct MHD_Connection *connection,
43 enum MHD_ValueKind kind,
44 const char *key,
45 size_t key_size,
46 const char **value_ptr,
47 size_t *value_size_ptr)
48{
49 return MHD_NO;
50}
51
52
53#include "mhd_str.c"
54#include "internal.c"
55#include "postprocessor.c"
56
57
58static unsigned int found;
59
60
61static enum MHD_Result
62post_data_iterator (void *cls,
63 enum MHD_ValueKind kind,
64 const char *key,
65 const char *filename,
66 const char *content_type,
67 const char *transfer_encoding,
68 const char *data,
69 uint64_t off,
70 size_t size)
71{
72 fprintf (stderr,
73 "%s\t%s\n",
74 key,
75 data);
76 if (0 == strcmp (key, "xxxx"))
77 {
78 if ( (4 != size) ||
79 (0 != memcmp (data, "xxxx", 4)) )
80 exit (1);
81 found |= 1;
82 }
83 if (0 == strcmp (key, "yyyy"))
84 {
85 if ( (4 != size) ||
86 (0 != memcmp (data, "yyyy", 4)) )
87 exit (1);
88 found |= 2;
89 }
90 if (0 == strcmp (key, "zzzz"))
91 {
92 if (0 != size)
93 exit (1);
94 found |= 4;
95 }
96 if (0 == strcmp (key, "aaaa"))
97 {
98 if (0 != size)
99 exit (1);
100 found |= 8;
101 }
102 return MHD_YES;
103}
104
105
106int
107main (int argc, char *argv[])
108{
109 struct MHD_PostProcessor *postprocessor;
110
111 postprocessor = malloc (sizeof (struct MHD_PostProcessor)
112 + 0x1000 + 1);
113 if (NULL == postprocessor)
114 return 77;
115 memset (postprocessor,
116 0,
117 sizeof (struct MHD_PostProcessor) + 0x1000 + 1);
118 postprocessor->ikvi = &post_data_iterator;
119 postprocessor->encoding = MHD_HTTP_POST_ENCODING_FORM_URLENCODED;
120 postprocessor->buffer_size = 0x1000;
121 postprocessor->state = PP_Init;
122 postprocessor->skip_rn = RN_Inactive;
123 MHD_post_process (postprocessor, "xxxx=xxxx", 9);
124 MHD_post_process (postprocessor, "&yyyy=yyyy&zzzz=&aaaa=", 22);
125 MHD_post_process (postprocessor, "", 0);
126 if (MHD_YES !=
127 MHD_destroy_post_processor (postprocessor))
128 exit (3);
129 if (found != 15)
130 exit (2);
131 return EXIT_SUCCESS;
132}