HTP 0.5
htp_multipart.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (c) 2009-2010 Open Information Security Foundation
3 * Copyright (c) 2010-2013 Qualys, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16
17 * - Neither the name of the Qualys, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
33
39#ifndef _HTP_MULTIPART_H
40#define _HTP_MULTIPART_H
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#include "bstr.h"
47#include "htp.h"
48#include "htp_table.h"
49
50
51// Constants and enums.
52
58#define HTP_MULTIPART_LF_LINE 0x0001
59
61#define HTP_MULTIPART_CRLF_LINE 0x0002
62
64#define HTP_MULTIPART_BBOUNDARY_LWS_AFTER 0x0004
65
67#define HTP_MULTIPART_BBOUNDARY_NLWS_AFTER 0x0008
68
72#define HTP_MULTIPART_HAS_PREAMBLE 0x0010
73
77#define HTP_MULTIPART_HAS_EPILOGUE 0x0020
78
85#define HTP_MULTIPART_SEEN_LAST_BOUNDARY 0x0040
86
91#define HTP_MULTIPART_PART_AFTER_LAST_BOUNDARY 0x0080
92
99#define HTP_MULTIPART_INCOMPLETE 0x0100
100
102#define HTP_MULTIPART_HBOUNDARY_INVALID 0x0200
103
109#define HTP_MULTIPART_HBOUNDARY_UNUSUAL 0x0400
110
115#define HTP_MULTIPART_HBOUNDARY_QUOTED 0x0800
116
118#define HTP_MULTIPART_PART_HEADER_FOLDING 0x1000
119
124#define HTP_MULTIPART_PART_UNKNOWN 0x2000
125
127#define HTP_MULTIPART_PART_HEADER_REPEATED 0x4000
128
130#define HTP_MULTIPART_PART_HEADER_UNKNOWN 0x8000
131
133#define HTP_MULTIPART_PART_HEADER_INVALID 0x10000
134
136#define HTP_MULTIPART_CD_TYPE_INVALID 0x20000
137
139#define HTP_MULTIPART_CD_PARAM_REPEATED 0x40000
140
142#define HTP_MULTIPART_CD_PARAM_UNKNOWN 0x80000
143
145#define HTP_MULTIPART_CD_SYNTAX_INVALID 0x100000
146
152#define HTP_MULTIPART_PART_INCOMPLETE 0x200000
153
155#define HTP_MULTIPART_NUL_BYTE 0x400000
156
158#define HTP_MULTIPART_CD_INVALID ( \
159 HTP_MULTIPART_CD_TYPE_INVALID | \
160 HTP_MULTIPART_CD_PARAM_REPEATED | \
161 HTP_MULTIPART_CD_PARAM_UNKNOWN | \
162 HTP_MULTIPART_CD_SYNTAX_INVALID )
163
165#define HTP_MULTIPART_PART_INVALID ( \
166 HTP_MULTIPART_CD_INVALID | \
167 HTP_MULTIPART_NUL_BYTE | \
168 HTP_MULTIPART_PART_UNKNOWN | \
169 HTP_MULTIPART_PART_HEADER_REPEATED | \
170 HTP_MULTIPART_PART_INCOMPLETE | \
171 HTP_MULTIPART_PART_HEADER_UNKNOWN | \
172 HTP_MULTIPART_PART_HEADER_INVALID )
173
175#define HTP_MULTIPART_INVALID ( \
176 HTP_MULTIPART_PART_INVALID | \
177 HTP_MULTIPART_PART_AFTER_LAST_BOUNDARY | \
178 HTP_MULTIPART_INCOMPLETE | \
179 HTP_MULTIPART_HBOUNDARY_INVALID )
180
182#define HTP_MULTIPART_UNUSUAL ( \
183 HTP_MULTIPART_INVALID | \
184 HTP_MULTIPART_PART_HEADER_FOLDING | \
185 HTP_MULTIPART_BBOUNDARY_NLWS_AFTER | \
186 HTP_MULTIPART_HAS_EPILOGUE | \
187 HTP_MULTIPART_HBOUNDARY_UNUSUAL \
188 HTP_MULTIPART_HBOUNDARY_QUOTED )
189
191#define HTP_MULTIPART_UNUSUAL_PARANOID ( \
192 HTP_MULTIPART_UNUSUAL | \
193 HTP_MULTIPART_LF_LINE | \
194 HTP_MULTIPART_BBOUNDARY_LWS_AFTER | \
195 HTP_MULTIPART_HAS_PREAMBLE )
196
197#define HTP_MULTIPART_MIME_TYPE "multipart/form-data"
198
216
217
218// Structures
219
224
228typedef struct htp_multipart_t {
230 char *boundary;
231
234
237
240
242 uint64_t flags;
244
278
279
280// Functions
281
291htp_mpartp_t *htp_mpartp_create(htp_cfg_t *cfg, bstr *boundary, uint64_t flags);
292
305htp_status_t htp_mpartp_find_boundary(bstr *content_type, bstr **boundary, uint64_t *multipart_flags);
306
314
320void htp_mpartp_destroy(htp_mpartp_t *parser);
321
329
339htp_status_t htp_mpartp_parse(htp_mpartp_t *parser, const void *data, size_t len);
340
341#ifdef __cplusplus
342}
343#endif
344
345#endif /* _HTP_MULTIPART_H */
int htp_status_t
Definition htp_core.h:46
#define htp_list_t
Definition htp_list.h:48
htp_status_t htp_mpartp_finalize(htp_mpartp_t *parser)
Definition htp_multipart.c:1080
htp_multipart_type_t
Definition htp_multipart.h:199
@ MULTIPART_PART_UNKNOWN
Definition htp_multipart.h:202
@ MULTIPART_PART_PREAMBLE
Definition htp_multipart.h:211
@ MULTIPART_PART_TEXT
Definition htp_multipart.h:205
@ MULTIPART_PART_FILE
Definition htp_multipart.h:208
@ MULTIPART_PART_EPILOGUE
Definition htp_multipart.h:214
struct htp_multipart_t htp_multipart_t
htp_mpartp_t * htp_mpartp_create(htp_cfg_t *cfg, bstr *boundary, uint64_t flags)
Definition htp_multipart.c:885
htp_status_t htp_mpartp_find_boundary(bstr *content_type, bstr **boundary, uint64_t *multipart_flags)
Definition htp_multipart.c:1472
htp_status_t htp_mpartp_parse(htp_mpartp_t *parser, const void *data, size_t len)
Definition htp_multipart.c:1099
void htp_mpartp_destroy(htp_mpartp_t *parser)
Definition htp_multipart.c:944
htp_multipart_t * htp_mpartp_get_multipart(htp_mpartp_t *parser)
Definition htp_multipart.c:61
struct htp_multipart_part_t htp_multipart_part_t
Definition bstr.h:57
Definition htp_config_private.h:123
Definition htp.h:111
Definition htp_multipart_private.h:85
Definition htp_multipart.h:248
size_t len
Definition htp_multipart.h:256
htp_table_t * headers
Definition htp_multipart.h:273
enum htp_multipart_type_t type
Definition htp_multipart.h:253
htp_mpartp_t * parser
Definition htp_multipart.h:250
htp_file_t * file
Definition htp_multipart.h:276
bstr * content_type
Definition htp_multipart.h:270
bstr * value
Definition htp_multipart.h:267
bstr * name
Definition htp_multipart.h:259
Definition htp_multipart.h:228
uint64_t flags
Definition htp_multipart.h:242
char * boundary
Definition htp_multipart.h:230
htp_list_t * parts
Definition htp_multipart.h:239
size_t boundary_len
Definition htp_multipart.h:233
int boundary_count
Definition htp_multipart.h:236
Definition htp_table_private.h:63