Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 271 lines (220 sloc) 7.844 kB
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
1 /*
2 * Copyright (C) 2006, 2008 Valery Kholodkov
3 */
4
5 #ifndef _NGX_HTTP_UPLOAD_H_INCLUDED_
6 #define _NGX_HTTP_UPLOAD_H_INCLUDED_
7
8 #if (NGX_HAVE_OPENSSL_MD5_H)
9 #include <openssl/md5.h>
10 #else
11 #include <md5.h>
12 #endif
13
14 #if (NGX_OPENSSL_MD5)
15 #define MD5Init MD5_Init
16 #define MD5Update MD5_Update
17 #define MD5Final MD5_Final
18 #endif
19
20 #if (NGX_HAVE_OPENSSL_SHA1_H)
21 #include <openssl/sha.h>
22 #else
23 #include <sha.h>
24 #endif
25
26 #define MULTIPART_FORM_DATA_STRING "multipart/form-data"
27 #define BOUNDARY_STRING "boundary="
28 #define CONTENT_DISPOSITION_STRING "Content-Disposition:"
29 #define CONTENT_TYPE_STRING "Content-Type:"
30 #define FORM_DATA_STRING "form-data"
31 #define ATTACHMENT_STRING "attachment"
32 #define FILENAME_STRING "filename=\""
33 #define FIELDNAME_STRING "name=\""
34
35 #define NGX_UPLOAD_SUBMODULE 0x444c5055 // UPLD
36
37 #define NGX_UPLOAD_MALFORMED -1
38 #define NGX_UPLOAD_NOMEM -2
39 #define NGX_UPLOAD_IOERROR -3
40 #define NGX_UPLOAD_SCRIPTERROR -4
7b7f947 @vkholodkov Merged changes from version 2.0.7
vkholodkov authored
41 #define NGX_UPLOAD_TOOLARGE -5
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
42
43 /*
44 * State of multipart/form-data parser
45 */
46 typedef enum {
47 upload_state_boundary_seek,
48 upload_state_after_boundary,
49 upload_state_headers,
50 upload_state_data,
51 upload_state_finish
52 } upload_state_t;
53
54 /*
55 * Template for a field to generate in output form
56 */
57 typedef struct {
58 ngx_table_elt_t value;
59 ngx_array_t *field_lengths;
60 ngx_array_t *field_values;
61 ngx_array_t *value_lengths;
62 ngx_array_t *value_values;
63 } ngx_http_upload_field_template_t;
64
65 /*
66 * Filter for fields in output form
67 */
68 typedef struct {
69 #if (NGX_PCRE)
70 ngx_regex_t *regex;
71 ngx_int_t ncaptures;
72 #else
73 ngx_str_t text;
74 #endif
75 } ngx_http_upload_field_filter_t;
76
77 struct ngx_http_upload_ctx_s;
78
79 /*
80 * Filter for content of certain type
81 */
82 typedef struct {
83 ngx_int_t (*start)(struct ngx_http_upload_ctx_s *upload_ctx);
84 void (*finish)(struct ngx_http_upload_ctx_s *upload_ctx);
85 void (*abort)(struct ngx_http_upload_ctx_s *upload_ctx);
07406fe @vkholodkov Uploaded data is now being processed in nginx chains
vkholodkov authored
86 ngx_int_t (*process_chain)(struct ngx_http_upload_ctx_s *upload_ctx, ngx_chain_t *chain);
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
87 } ngx_upload_content_filter_t;
88
aaa500a @vkholodkov Added field filters and decompression memory preallocation
vkholodkov authored
89 typedef ngx_upload_content_filter_t ngx_upload_field_filter_t;
90
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
91 /*
92 * Mapping of a content type to slave location config
93 */
94 struct ngx_http_upload_loc_conf_s;
95
96 typedef struct {
97 ngx_str_t content_type;
9a613f7 @vkholodkov Implemented configuration switching
vkholodkov authored
98 ngx_http_core_loc_conf_t *conf;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
99 } ngx_upload_content_type_map_t;
100
101 /*
a378f00 @vkholodkov Merged changes from branch 2.0; added resolution of content type for …
vkholodkov authored
102 * Upload cleanup record
103 */
104 typedef struct ngx_http_upload_cleanup_s {
105 ngx_fd_t fd;
106 u_char *filename;
107 ngx_http_headers_out_t *headers_out;
108 ngx_array_t *cleanup_statuses;
109 ngx_log_t *log;
110 unsigned int aborted:1;
111 } ngx_upload_cleanup_t;
112
113 /*
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
114 * Upload configuration for specific location
115 */
116 typedef struct ngx_http_upload_loc_conf_s {
117 struct ngx_http_upload_loc_conf_s *parent;
118
119 ngx_str_t url;
120 ngx_path_t *store_path;
121 ngx_uint_t store_access;
122 size_t buffer_size;
123 size_t max_header_len;
7b7f947 @vkholodkov Merged changes from version 2.0.7
vkholodkov authored
124 size_t max_output_body_len;
125 off_t max_file_size;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
126 ngx_array_t *field_templates;
127 ngx_array_t *aggregate_field_templates;
128 ngx_array_t *field_filters;
a378f00 @vkholodkov Merged changes from branch 2.0; added resolution of content type for …
vkholodkov authored
129 ngx_array_t *cleanup_statuses;
7b7f947 @vkholodkov Merged changes from version 2.0.7
vkholodkov authored
130 ngx_flag_t forward_args;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
131
132 ngx_array_t *content_filters;
133 ngx_array_t *content_type_map;
7b7f947 @vkholodkov Merged changes from version 2.0.7
vkholodkov authored
134 ngx_array_t *void_content_types;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
135
1059c24 @vkholodkov Added support for archive element paths
vkholodkov authored
136 ngx_str_t archive_elm_separator;
137 ngx_str_t archive_path_separator;
138
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
139 unsigned int md5:1;
140 unsigned int sha1:1;
a378f00 @vkholodkov Merged changes from branch 2.0; added resolution of content type for …
vkholodkov authored
141 unsigned int crc32:1;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
142 } ngx_http_upload_loc_conf_t;
143
144 typedef struct ngx_http_upload_md5_ctx_s {
145 MD5_CTX md5;
146 u_char md5_digest[MD5_DIGEST_LENGTH * 2];
147 } ngx_http_upload_md5_ctx_t;
148
149 typedef struct ngx_http_upload_sha1_ctx_s {
150 SHA_CTX sha1;
151 u_char sha1_digest[SHA_DIGEST_LENGTH * 2];
152 } ngx_http_upload_sha1_ctx_t;
153
154 /*
155 * Upload module context
156 */
157 typedef struct ngx_http_upload_ctx_s {
158 ngx_str_t boundary;
159 u_char *boundary_start;
160 u_char *boundary_pos;
161
162 upload_state_t state;
163
164 u_char *header_accumulator;
165 u_char *header_accumulator_end;
166 u_char *header_accumulator_pos;
167
168 ngx_str_t field_name;
169 ngx_str_t file_name;
170 ngx_str_t content_type;
1059c24 @vkholodkov Added support for archive element paths
vkholodkov authored
171 ngx_str_t archive_elm;
07406fe @vkholodkov Uploaded data is now being processed in nginx chains
vkholodkov authored
172 ngx_str_t archive_path;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
173
07406fe @vkholodkov Uploaded data is now being processed in nginx chains
vkholodkov authored
174 ngx_buf_t *output_buffer;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
175
176 ngx_int_t (*start_part_f)(struct ngx_http_upload_ctx_s *upload_ctx);
177 void (*finish_part_f)(struct ngx_http_upload_ctx_s *upload_ctx);
178 void (*abort_part_f)(struct ngx_http_upload_ctx_s *upload_ctx);
07406fe @vkholodkov Uploaded data is now being processed in nginx chains
vkholodkov authored
179 ngx_int_t (*process_chain_f)(struct ngx_http_upload_ctx_s *upload_ctx, ngx_chain_t *chain);
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
180
181 ngx_http_request_t *request;
182 ngx_log_t *log;
9a613f7 @vkholodkov Implemented configuration switching
vkholodkov authored
183 void **original_loc_conf;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
184
185 ngx_file_t output_file;
186 ngx_chain_t *chain;
187 ngx_chain_t *last;
188 ngx_chain_t *checkpoint;
189 size_t output_body_len;
190
191 ngx_pool_cleanup_t *cln;
192
193 ngx_http_upload_md5_ctx_t *md5_ctx;
194 ngx_http_upload_sha1_ctx_t *sha1_ctx;
a378f00 @vkholodkov Merged changes from branch 2.0; added resolution of content type for …
vkholodkov authored
195 uint32_t crc32;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
196
197 ngx_array_t *current_content_filter_chain;
198 ngx_uint_t current_content_filter_idx;
199
200 unsigned int first_part:1;
201 unsigned int discard_data:1;
202 unsigned int is_file:1;
a378f00 @vkholodkov Merged changes from branch 2.0; added resolution of content type for …
vkholodkov authored
203 unsigned int calculate_crc32:1;
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
204 } ngx_http_upload_ctx_t;
205
206 ngx_module_t ngx_http_upload_module;
207
a378f00 @vkholodkov Merged changes from branch 2.0; added resolution of content type for …
vkholodkov authored
208 ngx_int_t ngx_upload_set_exten(ngx_http_upload_ctx_t *u, ngx_str_t *file_name, ngx_str_t *exten);
209 ngx_int_t ngx_upload_resolve_content_type(ngx_http_upload_ctx_t *u, ngx_str_t *exten, ngx_str_t *content_type);
1059c24 @vkholodkov Added support for archive element paths
vkholodkov authored
210
211 #define ngx_upload_set_file_name(ctx, fn) \
212 do{ \
213 (ctx)->file_name.data = (fn)->data; \
214 (ctx)->file_name.len = (fn)->len; \
215 }while(0); \
216
217 #define ngx_upload_get_file_name(ctx, fn) \
218 do{ \
219 (fn)->data = (ctx)->file_name.data; \
220 (fn)->len = (ctx)->file_name.len; \
221 }while(0); \
222
223 #define ngx_upload_set_content_type(ctx, ct) \
224 do{ \
225 (ctx)->content_type.data = (ct)->data; \
226 (ctx)->content_type.len = (ct)->len; \
227 }while(0); \
228
229 #define ngx_upload_get_content_type(ctx, ct) \
230 do{ \
231 (ct)->data = (ctx)->content_type.data; \
232 (ct)->len = (ctx)->content_type.len; \
233 }while(0); \
234
235 #define ngx_upload_set_archive_elm(ctx, ae) \
236 do{ \
237 (ctx)->archive_elm.data = (ae)->data; \
238 (ctx)->archive_elm.len = (ae)->len; \
239 }while(0); \
240
241 #define ngx_upload_get_archive_elm(ctx, ae) \
242 do{ \
243 (ae)->data = (ctx)->archive_elm.data; \
244 (ae)->len = (ctx)->archive_elm.len; \
245 }while(0); \
246
247 #define ngx_upload_set_archive_path(ctx, ap) \
248 do{ \
249 (ctx)->archive_path.data = (ap)->data; \
250 (ctx)->archive_path.len = (ap)->len; \
251 }while(0); \
252
253 #define ngx_upload_get_archive_path(ctx, ap) \
254 do{ \
255 (ap)->data = (ctx)->archive_path.data; \
256 (ap)->len = (ctx)->archive_path.len; \
257 }while(0); \
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
258
aaa500a @vkholodkov Added field filters and decompression memory preallocation
vkholodkov authored
259 ngx_upload_field_filter_t*
260 ngx_upload_get_next_field_filter(ngx_http_upload_ctx_t *ctx);
261
3cec90a @vkholodkov Added support for submodules and unzip submodule
vkholodkov authored
262 ngx_upload_content_filter_t*
263 ngx_upload_get_next_content_filter(ngx_http_upload_ctx_t *ctx);
264
265 ngx_int_t
266 ngx_http_upload_add_filter(ngx_http_upload_loc_conf_t *ulcf,
267 ngx_upload_content_filter_t *cflt, ngx_pool_t *pool);
268
269 #endif //_NGX_HTTP_UPLOAD_H_INCLUDED_
270
Something went wrong with that request. Please try again.