2 * ModSecurity for Apache 2.x, http://www.modsecurity.org/
3 * Copyright (c) 2004-2009 Breach Security, Inc. (http://www.breach.com/)
5 * This product is released under the terms of the General Public Licence,
6 * version 2 (GPLv2). Please refer to the file LICENSE (included with this
7 * distribution) which contains the complete text of the licence.
9 * There are special exceptions to the terms and conditions of the GPL
10 * as it is applied to this software. View the full text of the exception in
11 * file MODSECURITY_LICENSING_EXCEPTION in the directory of this software
14 * If any of the files related to licensing are missing or if you have any
15 * other questions related to licensing please contact Breach Security, Inc.
16 * directly using the email address support@breach.com.
19 #ifndef _MSC_MULTIPART_H_
20 #define _MSC_MULTIPART_H_
22 #define MULTIPART_BUF_SIZE 4096
24 #define MULTIPART_FORMDATA 1
25 #define MULTIPART_FILE 2
27 typedef struct multipart_part multipart_part;
28 typedef struct multipart_data multipart_data;
30 #include "apr_general.h"
31 #include "apr_tables.h"
32 #include "modsecurity.h"
34 typedef struct value_part_t value_part_t;
40 struct multipart_part {
41 /* part type, can be MULTIPART_FORMDATA or MULTIPART_FILE */
46 /* variables only, variable value */
48 apr_array_header_t *value_parts;
50 /* files only, the content type (where available) */
53 /* files only, the name of the temporary file holding data */
56 unsigned int tmp_file_size;
57 /* files only, filename as supplied by the browser */
60 char *last_header_name;
67 struct multipart_data {
68 /* this array keeps parts */
69 apr_array_header_t *parts;
71 /* mime boundary used to detect when
77 /* internal buffer and other variables
80 char buf[MULTIPART_BUF_SIZE + 2];
81 int buf_contains_line;
85 unsigned int buf_offset;
87 /* pointer that keeps track of a part while
93 /* part parsing state; 0 means we are reading
94 * headers, 1 means we are collecting data
98 /* because of the way this parsing algorithm
99 * works we hold back the last two bytes of
100 * each data chunk so that we can discard it
101 * later if the next data chunk proves to be
102 * a boundary; the first byte is an indicator
103 * 0 - no content, 1 - two data bytes available
111 int flag_data_before;
113 int flag_header_folding;
114 int flag_boundary_quoted;
117 int flag_unmatched_boundary;
118 int flag_boundary_whitespace;
119 int flag_missing_semicolon;
120 int flag_invalid_quoting;
126 int DSOLOCAL multipart_init(modsec_rec *msr, char **error_msg);
128 int DSOLOCAL multipart_complete(modsec_rec *msr, char **error_msg);
130 int DSOLOCAL multipart_process_chunk(modsec_rec *msr, const char *buf,
131 unsigned int size, char **error_msg);
133 apr_status_t DSOLOCAL multipart_cleanup(modsec_rec *msr);
135 int DSOLOCAL multipart_get_arguments(modsec_rec *msr, char *origin, apr_table_t *arguments);
137 char DSOLOCAL *multipart_reconstruct_urlencoded_body_sanitise(modsec_rec *msr);