aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/microhttpd/Makefile.am2
-rw-r--r--src/microhttpd/postprocessor.c216
-rw-r--r--src/microhttpd/postprocessor.h246
-rw-r--r--w32/common/libmicrohttpd-files.vcxproj1
-rw-r--r--w32/common/libmicrohttpd-filters.vcxproj3
5 files changed, 252 insertions, 216 deletions
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index 14ee6c23..c70fb605 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -158,7 +158,7 @@ endif
158 158
159if HAVE_POSTPROCESSOR 159if HAVE_POSTPROCESSOR
160libmicrohttpd_la_SOURCES += \ 160libmicrohttpd_la_SOURCES += \
161 postprocessor.c 161 postprocessor.c postprocessor.h
162endif 162endif
163 163
164if HAVE_ANYAUTH 164if HAVE_ANYAUTH
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 8249fc35..f8f4fb27 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -24,6 +24,7 @@
24 * @author Karlson2k (Evgeny Grin) 24 * @author Karlson2k (Evgeny Grin)
25 */ 25 */
26 26
27#include "postprocessor.h"
27#include "internal.h" 28#include "internal.h"
28#include "mhd_str.h" 29#include "mhd_str.h"
29#include "mhd_compat.h" 30#include "mhd_compat.h"
@@ -36,221 +37,6 @@
36 */ 37 */
37#define XBUF_SIZE 512 38#define XBUF_SIZE 512
38 39
39/**
40 * States in the PP parser's state machine.
41 */
42enum PP_State
43{
44 /* general states */
45 PP_Error,
46 PP_Done,
47 PP_Init,
48 PP_NextBoundary,
49
50 /* url encoding-states */
51 PP_ProcessKey,
52 PP_ProcessValue,
53 PP_Callback,
54
55 /* post encoding-states */
56 PP_ProcessEntryHeaders,
57 PP_PerformCheckMultipart,
58 PP_ProcessValueToBoundary,
59 PP_PerformCleanup,
60
61 /* nested post-encoding states */
62 PP_Nested_Init,
63 PP_Nested_PerformMarking,
64 PP_Nested_ProcessEntryHeaders,
65 PP_Nested_ProcessValueToBoundary,
66 PP_Nested_PerformCleanup
67
68};
69
70
71enum RN_State
72{
73 /**
74 * No RN-preprocessing in this state.
75 */
76 RN_Inactive = 0,
77
78 /**
79 * If the next character is CR, skip it. Otherwise,
80 * just go inactive.
81 */
82 RN_OptN = 1,
83
84 /**
85 * Expect LFCR (and only LFCR). As always, we also
86 * expect only LF or only CR.
87 */
88 RN_Full = 2,
89
90 /**
91 * Expect either LFCR or '--'LFCR. If '--'LFCR, transition into dash-state
92 * for the main state machine
93 */
94 RN_Dash = 3,
95
96 /**
97 * Got a single dash, expect second dash.
98 */
99 RN_Dash2 = 4
100};
101
102
103/**
104 * Bits for the globally known fields that
105 * should not be deleted when we exit the
106 * nested state.
107 */
108enum NE_State
109{
110 NE_none = 0,
111 NE_content_name = 1,
112 NE_content_type = 2,
113 NE_content_filename = 4,
114 NE_content_transfer_encoding = 8
115};
116
117
118/**
119 * Internal state of the post-processor. Note that the fields
120 * are sorted by type to enable optimal packing by the compiler.
121 */
122struct MHD_PostProcessor
123{
124
125 /**
126 * The connection for which we are doing
127 * POST processing.
128 */
129 struct MHD_Connection *connection;
130
131 /**
132 * Function to call with POST data.
133 */
134 MHD_PostDataIterator ikvi;
135
136 /**
137 * Extra argument to ikvi.
138 */
139 void *cls;
140
141 /**
142 * Encoding as given by the headers of the connection.
143 */
144 const char *encoding;
145
146 /**
147 * Primary boundary (points into encoding string)
148 */
149 const char *boundary;
150
151 /**
152 * Nested boundary (if we have multipart/mixed encoding).
153 */
154 char *nested_boundary;
155
156 /**
157 * Pointer to the name given in disposition.
158 */
159 char *content_name;
160
161 /**
162 * Pointer to the (current) content type.
163 */
164 char *content_type;
165
166 /**
167 * Pointer to the (current) filename.
168 */
169 char *content_filename;
170
171 /**
172 * Pointer to the (current) encoding.
173 */
174 char *content_transfer_encoding;
175
176 /**
177 * Value data left over from previous iteration.
178 */
179 char xbuf[2];
180
181 /**
182 * Size of our buffer for the key.
183 */
184 size_t buffer_size;
185
186 /**
187 * Current position in the key buffer.
188 */
189 size_t buffer_pos;
190
191 /**
192 * Current position in @e xbuf.
193 */
194 size_t xbuf_pos;
195
196 /**
197 * Current offset in the value being processed.
198 */
199 uint64_t value_offset;
200
201 /**
202 * strlen(boundary) -- if boundary != NULL.
203 */
204 size_t blen;
205
206 /**
207 * strlen(nested_boundary) -- if nested_boundary != NULL.
208 */
209 size_t nlen;
210
211 /**
212 * Do we have to call the 'ikvi' callback when processing the
213 * multipart post body even if the size of the payload is zero?
214 * Set to #MHD_YES whenever we parse a new multiparty entry header,
215 * and to #MHD_NO the first time we call the 'ikvi' callback.
216 * Used to ensure that we do always call 'ikvi' even if the
217 * payload is empty (but not more than once).
218 */
219 bool must_ikvi;
220
221 /**
222 * Set if we still need to run the unescape logic
223 * on the key allocated at the end of this struct.
224 */
225 bool must_unescape_key;
226
227 /**
228 * State of the parser.
229 */
230 enum PP_State state;
231
232 /**
233 * Side-state-machine: skip LRCR (or just LF).
234 * Set to 0 if we are not in skip mode. Set to 2
235 * if a LFCR is expected, set to 1 if a CR should
236 * be skipped if it is the next character.
237 */
238 enum RN_State skip_rn;
239
240 /**
241 * If we are in skip_rn with "dash" mode and
242 * do find 2 dashes, what state do we go into?
243 */
244 enum PP_State dash_state;
245
246 /**
247 * Which headers are global? (used to tell which
248 * headers were only valid for the nested multipart).
249 */
250 enum NE_State have;
251
252};
253
254 40
255_MHD_EXTERN struct MHD_PostProcessor * 41_MHD_EXTERN struct MHD_PostProcessor *
256MHD_create_post_processor (struct MHD_Connection *connection, 42MHD_create_post_processor (struct MHD_Connection *connection,
diff --git a/src/microhttpd/postprocessor.h b/src/microhttpd/postprocessor.h
new file mode 100644
index 00000000..df681ce9
--- /dev/null
+++ b/src/microhttpd/postprocessor.h
@@ -0,0 +1,246 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2022 Daniel Pittman, Christian Grothoff, and Evgeny Grin
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20/**
21 * @file postprocessor.h
22 * @brief Declarations for parsing POST data
23 * @author Christian Grothoff
24 * @author Karlson2k (Evgeny Grin)
25 */
26
27#ifndef MHD_POSTPROCESSOR_H
28#define MHD_POSTPROCESSOR_H 1
29#include "internal.h"
30
31/**
32 * States in the PP parser's state machine.
33 */
34enum PP_State
35{
36 /* general states */
37 PP_Error,
38 PP_Done,
39 PP_Init,
40 PP_NextBoundary,
41
42 /* url encoding-states */
43 PP_ProcessKey,
44 PP_ProcessValue,
45 PP_Callback,
46
47 /* post encoding-states */
48 PP_ProcessEntryHeaders,
49 PP_PerformCheckMultipart,
50 PP_ProcessValueToBoundary,
51 PP_PerformCleanup,
52
53 /* nested post-encoding states */
54 PP_Nested_Init,
55 PP_Nested_PerformMarking,
56 PP_Nested_ProcessEntryHeaders,
57 PP_Nested_ProcessValueToBoundary,
58 PP_Nested_PerformCleanup
59
60};
61
62
63enum RN_State
64{
65 /**
66 * No RN-preprocessing in this state.
67 */
68 RN_Inactive = 0,
69
70 /**
71 * If the next character is CR, skip it. Otherwise,
72 * just go inactive.
73 */
74 RN_OptN = 1,
75
76 /**
77 * Expect LFCR (and only LFCR). As always, we also
78 * expect only LF or only CR.
79 */
80 RN_Full = 2,
81
82 /**
83 * Expect either LFCR or '--'LFCR. If '--'LFCR, transition into dash-state
84 * for the main state machine
85 */
86 RN_Dash = 3,
87
88 /**
89 * Got a single dash, expect second dash.
90 */
91 RN_Dash2 = 4
92};
93
94
95/**
96 * Bits for the globally known fields that
97 * should not be deleted when we exit the
98 * nested state.
99 */
100enum NE_State
101{
102 NE_none = 0,
103 NE_content_name = 1,
104 NE_content_type = 2,
105 NE_content_filename = 4,
106 NE_content_transfer_encoding = 8
107};
108
109
110/**
111 * Internal state of the post-processor. Note that the fields
112 * are sorted by type to enable optimal packing by the compiler.
113 */
114struct MHD_PostProcessor
115{
116
117 /**
118 * The connection for which we are doing
119 * POST processing.
120 */
121 struct MHD_Connection *connection;
122
123 /**
124 * Function to call with POST data.
125 */
126 MHD_PostDataIterator ikvi;
127
128 /**
129 * Extra argument to ikvi.
130 */
131 void *cls;
132
133 /**
134 * Encoding as given by the headers of the connection.
135 */
136 const char *encoding;
137
138 /**
139 * Primary boundary (points into encoding string)
140 */
141 const char *boundary;
142
143 /**
144 * Nested boundary (if we have multipart/mixed encoding).
145 */
146 char *nested_boundary;
147
148 /**
149 * Pointer to the name given in disposition.
150 */
151 char *content_name;
152
153 /**
154 * Pointer to the (current) content type.
155 */
156 char *content_type;
157
158 /**
159 * Pointer to the (current) filename.
160 */
161 char *content_filename;
162
163 /**
164 * Pointer to the (current) encoding.
165 */
166 char *content_transfer_encoding;
167
168 /**
169 * Value data left over from previous iteration.
170 */
171 char xbuf[2];
172
173 /**
174 * Size of our buffer for the key.
175 */
176 size_t buffer_size;
177
178 /**
179 * Current position in the key buffer.
180 */
181 size_t buffer_pos;
182
183 /**
184 * Current position in @e xbuf.
185 */
186 size_t xbuf_pos;
187
188 /**
189 * Current offset in the value being processed.
190 */
191 uint64_t value_offset;
192
193 /**
194 * strlen(boundary) -- if boundary != NULL.
195 */
196 size_t blen;
197
198 /**
199 * strlen(nested_boundary) -- if nested_boundary != NULL.
200 */
201 size_t nlen;
202
203 /**
204 * Do we have to call the 'ikvi' callback when processing the
205 * multipart post body even if the size of the payload is zero?
206 * Set to #MHD_YES whenever we parse a new multiparty entry header,
207 * and to #MHD_NO the first time we call the 'ikvi' callback.
208 * Used to ensure that we do always call 'ikvi' even if the
209 * payload is empty (but not more than once).
210 */
211 bool must_ikvi;
212
213 /**
214 * Set if we still need to run the unescape logic
215 * on the key allocated at the end of this struct.
216 */
217 bool must_unescape_key;
218
219 /**
220 * State of the parser.
221 */
222 enum PP_State state;
223
224 /**
225 * Side-state-machine: skip LRCR (or just LF).
226 * Set to 0 if we are not in skip mode. Set to 2
227 * if a LFCR is expected, set to 1 if a CR should
228 * be skipped if it is the next character.
229 */
230 enum RN_State skip_rn;
231
232 /**
233 * If we are in skip_rn with "dash" mode and
234 * do find 2 dashes, what state do we go into?
235 */
236 enum PP_State dash_state;
237
238 /**
239 * Which headers are global? (used to tell which
240 * headers were only valid for the nested multipart).
241 */
242 enum NE_State have;
243
244};
245
246#endif /* ! MHD_POSTPROCESSOR_H */
diff --git a/w32/common/libmicrohttpd-files.vcxproj b/w32/common/libmicrohttpd-files.vcxproj
index 391e1cec..982227c0 100644
--- a/w32/common/libmicrohttpd-files.vcxproj
+++ b/w32/common/libmicrohttpd-files.vcxproj
@@ -48,6 +48,7 @@
48 <ClInclude Include="$(MhdSrc)microhttpd\mhd_limits.h" /> 48 <ClInclude Include="$(MhdSrc)microhttpd\mhd_limits.h" />
49 <ClInclude Include="$(MhdSrc)microhttpd\mhd_mono_clock.h" /> 49 <ClInclude Include="$(MhdSrc)microhttpd\mhd_mono_clock.h" />
50 <ClInclude Include="$(MhdSrc)microhttpd\response.h" /> 50 <ClInclude Include="$(MhdSrc)microhttpd\response.h" />
51 <ClInclude Include="$(MhdSrc)microhttpd\postprocessor.h" />
51 <ClInclude Include="$(MhdSrc)microhttpd\tsearch.h" /> 52 <ClInclude Include="$(MhdSrc)microhttpd\tsearch.h" />
52 <ClInclude Include="$(MhdSrc)microhttpd\sysfdsetsize.h" /> 53 <ClInclude Include="$(MhdSrc)microhttpd\sysfdsetsize.h" />
53 <ClInclude Include="$(MhdSrc)microhttpd\mhd_str.h" /> 54 <ClInclude Include="$(MhdSrc)microhttpd\mhd_str.h" />
diff --git a/w32/common/libmicrohttpd-filters.vcxproj b/w32/common/libmicrohttpd-filters.vcxproj
index 16c6b085..7bc1fe3c 100644
--- a/w32/common/libmicrohttpd-filters.vcxproj
+++ b/w32/common/libmicrohttpd-filters.vcxproj
@@ -67,6 +67,9 @@
67 <ClInclude Include="$(MhdSrc)microhttpd\memorypool.h"> 67 <ClInclude Include="$(MhdSrc)microhttpd\memorypool.h">
68 <Filter>Internal Headers</Filter> 68 <Filter>Internal Headers</Filter>
69 </ClInclude> 69 </ClInclude>
70 <ClInclude Include="$(MhdSrc)microhttpd\postprocessor.h">
71 <Filter>Internal Headers</Filter>
72 </ClInclude>
70 <ClInclude Include="$(MhdSrc)microhttpd\response.h"> 73 <ClInclude Include="$(MhdSrc)microhttpd\response.h">
71 <Filter>Internal Headers</Filter> 74 <Filter>Internal Headers</Filter>
72 </ClInclude> 75 </ClInclude>