182
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
|
11
|
286
|
12 #define NGX_HTTP_DAV_COPY_BLOCK 65536
|
|
13
|
|
14 #define NGX_HTTP_DAV_OFF 2
|
|
15
|
|
16
|
|
17 #define NGX_HTTP_DAV_NO_DEPTH -3
|
|
18 #define NGX_HTTP_DAV_INVALID_DEPTH -2
|
|
19 #define NGX_HTTP_DAV_INFINITY_DEPTH -1
|
|
20
|
182
|
21
|
|
22 typedef struct {
|
|
23 ngx_uint_t methods;
|
362
|
24 ngx_uint_t access;
|
|
25 ngx_uint_t min_delete_depth;
|
186
|
26 ngx_flag_t create_full_put_path;
|
182
|
27 } ngx_http_dav_loc_conf_t;
|
|
28
|
|
29
|
286
|
30 typedef struct {
|
|
31 ngx_str_t path;
|
|
32 size_t len;
|
|
33 } ngx_http_dav_copy_ctx_t;
|
|
34
|
|
35
|
182
|
36 static ngx_int_t ngx_http_dav_handler(ngx_http_request_t *r);
|
286
|
37
|
|
38 static void ngx_http_dav_put_handler(ngx_http_request_t *r);
|
|
39
|
|
40 static ngx_int_t ngx_http_dav_delete_handler(ngx_http_request_t *r);
|
362
|
41 static ngx_int_t ngx_http_dav_delete_path(ngx_http_request_t *r,
|
|
42 ngx_str_t *path, ngx_uint_t dir);
|
272
|
43 static ngx_int_t ngx_http_dav_delete_dir(ngx_tree_ctx_t *ctx, ngx_str_t *path);
|
|
44 static ngx_int_t ngx_http_dav_delete_file(ngx_tree_ctx_t *ctx, ngx_str_t *path);
|
362
|
45 static ngx_int_t ngx_http_dav_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path);
|
286
|
46
|
|
47 static ngx_int_t ngx_http_dav_mkcol_handler(ngx_http_request_t *r,
|
|
48 ngx_http_dav_loc_conf_t *dlcf);
|
|
49
|
|
50 static ngx_int_t ngx_http_dav_copy_move_handler(ngx_http_request_t *r);
|
|
51 static ngx_int_t ngx_http_dav_copy_dir(ngx_tree_ctx_t *ctx, ngx_str_t *path);
|
|
52 static ngx_int_t ngx_http_dav_copy_dir_time(ngx_tree_ctx_t *ctx,
|
|
53 ngx_str_t *path);
|
362
|
54 static ngx_int_t ngx_http_dav_copy_tree_file(ngx_tree_ctx_t *ctx,
|
|
55 ngx_str_t *path);
|
286
|
56
|
|
57 static ngx_int_t ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt);
|
|
58 static ngx_int_t ngx_http_dav_error(ngx_log_t *log, ngx_err_t err,
|
186
|
59 ngx_int_t not_found, char *failed, u_char *path);
|
|
60 static ngx_int_t ngx_http_dav_location(ngx_http_request_t *r, u_char *path);
|
182
|
61 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf);
|
|
62 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf,
|
|
63 void *parent, void *child);
|
230
|
64 static ngx_int_t ngx_http_dav_init(ngx_conf_t *cf);
|
182
|
65
|
|
66
|
|
67 static ngx_conf_bitmask_t ngx_http_dav_methods_mask[] = {
|
|
68 { ngx_string("off"), NGX_HTTP_DAV_OFF },
|
|
69 { ngx_string("put"), NGX_HTTP_PUT },
|
|
70 { ngx_string("delete"), NGX_HTTP_DELETE },
|
186
|
71 { ngx_string("mkcol"), NGX_HTTP_MKCOL },
|
286
|
72 { ngx_string("copy"), NGX_HTTP_COPY },
|
|
73 { ngx_string("move"), NGX_HTTP_MOVE },
|
182
|
74 { ngx_null_string, 0 }
|
|
75 };
|
|
76
|
|
77
|
|
78 static ngx_command_t ngx_http_dav_commands[] = {
|
|
79
|
|
80 { ngx_string("dav_methods"),
|
|
81 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
|
|
82 ngx_conf_set_bitmask_slot,
|
|
83 NGX_HTTP_LOC_CONF_OFFSET,
|
|
84 offsetof(ngx_http_dav_loc_conf_t, methods),
|
|
85 &ngx_http_dav_methods_mask },
|
|
86
|
186
|
87 { ngx_string("create_full_put_path"),
|
|
88 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
|
|
89 ngx_conf_set_flag_slot,
|
|
90 NGX_HTTP_LOC_CONF_OFFSET,
|
|
91 offsetof(ngx_http_dav_loc_conf_t, create_full_put_path),
|
|
92 NULL },
|
|
93
|
362
|
94 { ngx_string("min_delete_depth"),
|
|
95 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
96 ngx_conf_set_num_slot,
|
|
97 NGX_HTTP_LOC_CONF_OFFSET,
|
|
98 offsetof(ngx_http_dav_loc_conf_t, min_delete_depth),
|
|
99 NULL },
|
|
100
|
218
|
101 { ngx_string("dav_access"),
|
224
|
102 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
|
320
|
103 ngx_conf_set_access_slot,
|
218
|
104 NGX_HTTP_LOC_CONF_OFFSET,
|
320
|
105 offsetof(ngx_http_dav_loc_conf_t, access),
|
218
|
106 NULL },
|
|
107
|
182
|
108 ngx_null_command
|
|
109 };
|
|
110
|
|
111
|
216
|
112 static ngx_http_module_t ngx_http_dav_module_ctx = {
|
182
|
113 NULL, /* preconfiguration */
|
230
|
114 ngx_http_dav_init, /* postconfiguration */
|
182
|
115
|
|
116 NULL, /* create main configuration */
|
|
117 NULL, /* init main configuration */
|
|
118
|
|
119 NULL, /* create server configuration */
|
|
120 NULL, /* merge server configuration */
|
|
121
|
|
122 ngx_http_dav_create_loc_conf, /* create location configuration */
|
|
123 ngx_http_dav_merge_loc_conf /* merge location configuration */
|
|
124 };
|
|
125
|
|
126
|
|
127 ngx_module_t ngx_http_dav_module = {
|
|
128 NGX_MODULE_V1,
|
|
129 &ngx_http_dav_module_ctx, /* module context */
|
|
130 ngx_http_dav_commands, /* module directives */
|
|
131 NGX_HTTP_MODULE, /* module type */
|
|
132 NULL, /* init master */
|
230
|
133 NULL, /* init module */
|
182
|
134 NULL, /* init process */
|
|
135 NULL, /* init thread */
|
|
136 NULL, /* exit thread */
|
|
137 NULL, /* exit process */
|
|
138 NULL, /* exit master */
|
|
139 NGX_MODULE_V1_PADDING
|
|
140 };
|
|
141
|
|
142
|
|
143 static ngx_int_t
|
|
144 ngx_http_dav_handler(ngx_http_request_t *r)
|
|
145 {
|
|
146 ngx_int_t rc;
|
|
147 ngx_http_dav_loc_conf_t *dlcf;
|
|
148
|
|
149 if (r->zero_in_uri) {
|
|
150 return NGX_DECLINED;
|
|
151 }
|
|
152
|
|
153 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
|
154
|
|
155 if (!(r->method & dlcf->methods)) {
|
|
156 return NGX_DECLINED;
|
|
157 }
|
|
158
|
|
159 switch (r->method) {
|
|
160
|
|
161 case NGX_HTTP_PUT:
|
|
162
|
|
163 if (r->uri.data[r->uri.len - 1] == '/') {
|
362
|
164 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
165 "can not PUT to a collection");
|
|
166 return NGX_HTTP_CONFLICT;
|
182
|
167 }
|
|
168
|
|
169 r->request_body_in_file_only = 1;
|
|
170 r->request_body_in_persistent_file = 1;
|
278
|
171 r->request_body_in_clean_file = 1;
|
182
|
172 r->request_body_file_group_access = 1;
|
186
|
173 r->request_body_file_log_level = 0;
|
182
|
174
|
|
175 rc = ngx_http_read_client_request_body(r, ngx_http_dav_put_handler);
|
|
176
|
|
177 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
|
178 return rc;
|
|
179 }
|
|
180
|
|
181 return NGX_DONE;
|
|
182
|
|
183 case NGX_HTTP_DELETE:
|
|
184
|
286
|
185 return ngx_http_dav_delete_handler(r);
|
186
|
186
|
|
187 case NGX_HTTP_MKCOL:
|
|
188
|
286
|
189 return ngx_http_dav_mkcol_handler(r, dlcf);
|
186
|
190
|
286
|
191 case NGX_HTTP_COPY:
|
186
|
192
|
286
|
193 return ngx_http_dav_copy_move_handler(r);
|
186
|
194
|
286
|
195 case NGX_HTTP_MOVE:
|
186
|
196
|
286
|
197 return ngx_http_dav_copy_move_handler(r);
|
182
|
198 }
|
|
199
|
|
200 return NGX_DECLINED;
|
|
201 }
|
|
202
|
|
203
|
|
204 static void
|
|
205 ngx_http_dav_put_handler(ngx_http_request_t *r)
|
|
206 {
|
248
|
207 size_t root;
|
230
|
208 time_t date;
|
186
|
209 ngx_str_t *temp, path;
|
362
|
210 ngx_uint_t status;
|
186
|
211 ngx_file_info_t fi;
|
362
|
212 ngx_ext_rename_file_t ext;
|
186
|
213 ngx_http_dav_loc_conf_t *dlcf;
|
182
|
214
|
248
|
215 ngx_http_map_uri_to_path(r, &path, &root, 0);
|
182
|
216
|
|
217 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
218 "http put filename: \"%s\"", path.data);
|
|
219
|
|
220 temp = &r->request_body->temp_file->file.name;
|
|
221
|
484
|
222 if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) {
|
182
|
223 status = NGX_HTTP_CREATED;
|
|
224
|
|
225 } else {
|
|
226 status = NGX_HTTP_NO_CONTENT;
|
212
|
227
|
|
228 if (ngx_is_dir(&fi)) {
|
|
229 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_EISDIR,
|
|
230 "\"%s\" could not be created", path.data);
|
182
|
231
|
212
|
232 if (ngx_delete_file(temp->data) == NGX_FILE_ERROR) {
|
|
233 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
|
|
234 ngx_delete_file_n " \"%s\" failed",
|
|
235 temp->data);
|
|
236 }
|
|
237
|
|
238 ngx_http_finalize_request(r, NGX_HTTP_CONFLICT);
|
|
239 return;
|
210
|
240 }
|
186
|
241 }
|
|
242
|
218
|
243 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
|
244
|
362
|
245 ext.access = dlcf->access;
|
430
|
246 ext.path_access = dlcf->access;
|
362
|
247 ext.time = -1;
|
|
248 ext.create_path = dlcf->create_full_put_path;
|
366
|
249 ext.delete_file = 1;
|
362
|
250 ext.log = r->connection->log;
|
218
|
251
|
230
|
252 if (r->headers_in.date) {
|
|
253 date = ngx_http_parse_time(r->headers_in.date->value.data,
|
|
254 r->headers_in.date->value.len);
|
|
255
|
|
256 if (date != NGX_ERROR) {
|
362
|
257 ext.time = date;
|
|
258 ext.fd = r->request_body->temp_file->file.fd;
|
230
|
259 }
|
|
260 }
|
|
261
|
362
|
262 if (ngx_ext_rename_file(temp, &path, &ext) != NGX_OK) {
|
|
263 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
264 return;
|
186
|
265 }
|
|
266
|
182
|
267 if (status == NGX_HTTP_CREATED) {
|
186
|
268 if (ngx_http_dav_location(r, path.data) != NGX_OK) {
|
182
|
269 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
|
270 return;
|
|
271 }
|
188
|
272
|
|
273 r->headers_out.content_length_n = 0;
|
182
|
274 }
|
|
275
|
|
276 r->headers_out.status = status;
|
|
277 r->header_only = 1;
|
|
278
|
|
279 ngx_http_finalize_request(r, ngx_http_send_header(r));
|
|
280 return;
|
|
281 }
|
|
282
|
|
283
|
186
|
284 static ngx_int_t
|
286
|
285 ngx_http_dav_delete_handler(ngx_http_request_t *r)
|
|
286 {
|
362
|
287 size_t root;
|
|
288 ngx_err_t err;
|
|
289 ngx_int_t rc, depth;
|
|
290 ngx_uint_t i, d, dir;
|
|
291 ngx_str_t path;
|
|
292 ngx_file_info_t fi;
|
|
293 ngx_http_dav_loc_conf_t *dlcf;
|
286
|
294
|
|
295 if (r->headers_in.content_length_n > 0) {
|
362
|
296 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
297 "DELETE with body is unsupported");
|
286
|
298 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
|
|
299 }
|
|
300
|
362
|
301 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
|
302
|
|
303 if (dlcf->min_delete_depth) {
|
|
304 d = 0;
|
286
|
305
|
362
|
306 for (i = 0; i < r->uri.len; /* void */) {
|
|
307 if (r->uri.data[i++] == '/') {
|
|
308 if (++d >= dlcf->min_delete_depth && i < r->uri.len) {
|
|
309 goto ok;
|
|
310 }
|
|
311 }
|
|
312 }
|
|
313
|
|
314 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
315 "insufficient URI depth:%i to DELETE", d);
|
|
316 return NGX_HTTP_CONFLICT;
|
286
|
317 }
|
|
318
|
362
|
319 ok:
|
|
320
|
286
|
321 ngx_http_map_uri_to_path(r, &path, &root, 0);
|
|
322
|
|
323 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
324 "http delete filename: \"%s\"", path.data);
|
|
325
|
484
|
326 if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) {
|
362
|
327 err = ngx_errno;
|
|
328
|
|
329 rc = (err == NGX_ENOTDIR) ? NGX_HTTP_CONFLICT : NGX_HTTP_NOT_FOUND;
|
|
330
|
|
331 return ngx_http_dav_error(r->connection->log, err,
|
|
332 rc, ngx_file_info_n, path.data);
|
286
|
333 }
|
|
334
|
|
335 if (ngx_is_dir(&fi)) {
|
|
336
|
|
337 if (r->uri.data[r->uri.len - 1] != '/') {
|
362
|
338 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_EISDIR,
|
|
339 "DELETE \"%s\" failed", path.data);
|
|
340 return NGX_HTTP_CONFLICT;
|
286
|
341 }
|
|
342
|
|
343 depth = ngx_http_dav_depth(r, NGX_HTTP_DAV_INFINITY_DEPTH);
|
|
344
|
|
345 if (depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
|
362
|
346 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
347 "\"Depth\" header must be infinity");
|
286
|
348 return NGX_HTTP_BAD_REQUEST;
|
|
349 }
|
|
350
|
|
351 path.len -= 2; /* omit "/\0" */
|
|
352
|
|
353 dir = 1;
|
|
354
|
|
355 } else {
|
|
356
|
362
|
357 /*
|
|
358 * we do not need to test (r->uri.data[r->uri.len - 1] == '/')
|
|
359 * because ngx_file_info("/file/") returned NGX_ENOTDIR above
|
|
360 */
|
|
361
|
286
|
362 depth = ngx_http_dav_depth(r, 0);
|
|
363
|
|
364 if (depth != 0 && depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
|
362
|
365 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
366 "\"Depth\" header must be 0 or infinity");
|
286
|
367 return NGX_HTTP_BAD_REQUEST;
|
|
368 }
|
|
369
|
|
370 dir = 0;
|
|
371 }
|
|
372
|
|
373 rc = ngx_http_dav_delete_path(r, &path, dir);
|
|
374
|
|
375 if (rc == NGX_OK) {
|
|
376 return NGX_HTTP_NO_CONTENT;
|
|
377 }
|
|
378
|
|
379 return rc;
|
|
380 }
|
|
381
|
|
382
|
|
383 static ngx_int_t
|
362
|
384 ngx_http_dav_delete_path(ngx_http_request_t *r, ngx_str_t *path, ngx_uint_t dir)
|
286
|
385 {
|
362
|
386 char *failed;
|
|
387 ngx_tree_ctx_t tree;
|
|
388
|
|
389 if (dir) {
|
|
390
|
|
391 tree.init_handler = NULL;
|
|
392 tree.file_handler = ngx_http_dav_delete_file;
|
|
393 tree.pre_tree_handler = ngx_http_dav_noop;
|
|
394 tree.post_tree_handler = ngx_http_dav_delete_dir;
|
|
395 tree.spec_handler = ngx_http_dav_delete_file;
|
|
396 tree.data = NULL;
|
|
397 tree.alloc = 0;
|
|
398 tree.log = r->connection->log;
|
|
399
|
|
400 /* TODO: 207 */
|
|
401
|
|
402 if (ngx_walk_tree(&tree, path) != NGX_OK) {
|
|
403 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
404 }
|
|
405
|
|
406 if (ngx_delete_dir(path->data) != NGX_FILE_ERROR) {
|
|
407 return NGX_OK;
|
|
408 }
|
|
409
|
|
410 failed = ngx_delete_dir_n;
|
|
411
|
|
412 } else {
|
|
413
|
|
414 if (ngx_delete_file(path->data) != NGX_FILE_ERROR) {
|
|
415 return NGX_OK;
|
|
416 }
|
|
417
|
|
418 failed = ngx_delete_file_n;
|
|
419 }
|
|
420
|
|
421 return ngx_http_dav_error(r->connection->log, ngx_errno,
|
|
422 NGX_HTTP_NOT_FOUND, failed, path->data);
|
286
|
423 }
|
|
424
|
|
425
|
|
426 static ngx_int_t
|
|
427 ngx_http_dav_delete_dir(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
|
428 {
|
|
429 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
430 "http delete dir: \"%s\"", path->data);
|
|
431
|
|
432 if (ngx_delete_dir(path->data) == NGX_FILE_ERROR) {
|
|
433
|
|
434 /* TODO: add to 207 */
|
|
435
|
|
436 (void) ngx_http_dav_error(ctx->log, ngx_errno, 0, ngx_delete_dir_n,
|
|
437 path->data);
|
|
438 }
|
|
439
|
|
440 return NGX_OK;
|
|
441 }
|
|
442
|
|
443
|
|
444 static ngx_int_t
|
|
445 ngx_http_dav_delete_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
|
446 {
|
|
447 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
448 "http delete file: \"%s\"", path->data);
|
|
449
|
|
450 if (ngx_delete_file(path->data) == NGX_FILE_ERROR) {
|
|
451
|
|
452 /* TODO: add to 207 */
|
|
453
|
|
454 (void) ngx_http_dav_error(ctx->log, ngx_errno, 0, ngx_delete_file_n,
|
|
455 path->data);
|
|
456 }
|
|
457
|
|
458 return NGX_OK;
|
|
459 }
|
|
460
|
|
461
|
|
462 static ngx_int_t
|
362
|
463 ngx_http_dav_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
|
464 {
|
|
465 return NGX_OK;
|
|
466 }
|
|
467
|
|
468
|
|
469 static ngx_int_t
|
286
|
470 ngx_http_dav_mkcol_handler(ngx_http_request_t *r, ngx_http_dav_loc_conf_t *dlcf)
|
|
471 {
|
362
|
472 u_char *p;
|
286
|
473 size_t root;
|
|
474 ngx_str_t path;
|
|
475
|
|
476 if (r->headers_in.content_length_n > 0) {
|
362
|
477 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
478 "MKCOL with body is unsupported");
|
286
|
479 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
|
|
480 }
|
|
481
|
362
|
482 if (r->uri.data[r->uri.len - 1] != '/') {
|
|
483 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
484 "MKCOL can create a collection only");
|
|
485 return NGX_HTTP_CONFLICT;
|
286
|
486 }
|
|
487
|
362
|
488 p = ngx_http_map_uri_to_path(r, &path, &root, 0);
|
|
489
|
|
490 *(p - 1) = '\0';
|
286
|
491
|
|
492 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
493 "http mkcol path: \"%s\"", path.data);
|
|
494
|
|
495 if (ngx_create_dir(path.data, ngx_dir_access(dlcf->access))
|
|
496 != NGX_FILE_ERROR)
|
|
497 {
|
|
498 if (ngx_http_dav_location(r, path.data) != NGX_OK) {
|
|
499 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
500 }
|
|
501
|
|
502 return NGX_HTTP_CREATED;
|
|
503 }
|
|
504
|
|
505 return ngx_http_dav_error(r->connection->log, ngx_errno,
|
362
|
506 NGX_HTTP_CONFLICT, ngx_create_dir_n, path.data);
|
286
|
507 }
|
|
508
|
|
509
|
|
510 static ngx_int_t
|
|
511 ngx_http_dav_copy_move_handler(ngx_http_request_t *r)
|
|
512 {
|
376
|
513 u_char *p, *host, *last, ch;
|
362
|
514 size_t len, root;
|
286
|
515 ngx_err_t err;
|
|
516 ngx_int_t rc, depth;
|
362
|
517 ngx_uint_t overwrite, slash, dir;
|
286
|
518 ngx_str_t path, uri;
|
|
519 ngx_tree_ctx_t tree;
|
514
|
520 ngx_copy_file_t cf;
|
286
|
521 ngx_file_info_t fi;
|
376
|
522 ngx_table_elt_t *dest, *over;
|
430
|
523 ngx_ext_rename_file_t ext;
|
286
|
524 ngx_http_dav_copy_ctx_t copy;
|
362
|
525 ngx_http_dav_loc_conf_t *dlcf;
|
286
|
526
|
|
527 if (r->headers_in.content_length_n > 0) {
|
|
528 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
|
|
529 }
|
|
530
|
|
531 dest = r->headers_in.destination;
|
|
532
|
|
533 if (dest == NULL) {
|
|
534 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
535 "client sent no \"Destination\" header");
|
|
536 return NGX_HTTP_BAD_REQUEST;
|
|
537 }
|
|
538
|
376
|
539 len = r->headers_in.server.len;
|
362
|
540
|
376
|
541 if (len == 0) {
|
362
|
542 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
543 "client sent no \"Host\" header");
|
|
544 return NGX_HTTP_BAD_REQUEST;
|
286
|
545 }
|
|
546
|
|
547 #if (NGX_HTTP_SSL)
|
|
548
|
|
549 if (r->connection->ssl) {
|
|
550 if (ngx_strncmp(dest->value.data, "https://", sizeof("https://") - 1)
|
|
551 != 0)
|
|
552 {
|
|
553 goto invalid_destination;
|
|
554 }
|
|
555
|
376
|
556 host = dest->value.data + sizeof("https://") - 1;
|
286
|
557
|
|
558 } else
|
|
559 #endif
|
|
560 {
|
|
561 if (ngx_strncmp(dest->value.data, "http://", sizeof("http://") - 1)
|
|
562 != 0)
|
|
563 {
|
|
564 goto invalid_destination;
|
|
565 }
|
|
566
|
376
|
567 host = dest->value.data + sizeof("http://") - 1;
|
286
|
568 }
|
|
569
|
376
|
570 if (ngx_strncmp(host, r->headers_in.server.data, len) != 0) {
|
286
|
571 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
362
|
572 "\"Destination\" URI \"%V\" is handled by "
|
286
|
573 "different repository than the source URI",
|
|
574 &dest->value);
|
|
575 return NGX_HTTP_BAD_REQUEST;
|
|
576 }
|
|
577
|
|
578 last = dest->value.data + dest->value.len;
|
|
579
|
376
|
580 for (p = host + len; p < last; p++) {
|
286
|
581 if (*p == '/') {
|
|
582 goto destination_done;
|
|
583 }
|
|
584 }
|
|
585
|
|
586 invalid_destination:
|
|
587
|
|
588 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
589 "client sent invalid \"Destination\" header: \"%V\"",
|
|
590 &dest->value);
|
|
591 return NGX_HTTP_BAD_REQUEST;
|
|
592
|
|
593 destination_done:
|
|
594
|
362
|
595 if ((r->uri.data[r->uri.len - 1] == '/' && *(last - 1) != '/')
|
|
596 || (r->uri.data[r->uri.len - 1] != '/' && *(last - 1) == '/'))
|
|
597 {
|
|
598 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
599 "both URI \"%V\" and \"Destination\" URI \"%V\" "
|
|
600 "should be either collections or non-collections",
|
|
601 &r->uri, &dest->value);
|
|
602 return NGX_HTTP_CONFLICT;
|
|
603 }
|
|
604
|
|
605 depth = ngx_http_dav_depth(r, NGX_HTTP_DAV_INFINITY_DEPTH);
|
286
|
606
|
362
|
607 if (depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
|
|
608
|
|
609 if (r->method == NGX_HTTP_COPY) {
|
|
610 if (depth != 0) {
|
|
611 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
612 "\"Depth\" header must be 0 or infinity");
|
|
613 return NGX_HTTP_BAD_REQUEST;
|
|
614 }
|
|
615
|
|
616 } else {
|
|
617 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
618 "\"Depth\" header must be infinity");
|
|
619 return NGX_HTTP_BAD_REQUEST;
|
|
620 }
|
286
|
621 }
|
296
|
622
|
286
|
623 over = r->headers_in.overwrite;
|
|
624
|
|
625 if (over) {
|
|
626 if (over->value.len == 1) {
|
|
627 ch = over->value.data[0];
|
|
628
|
|
629 if (ch == 'T' || ch == 't') {
|
|
630 overwrite = 1;
|
|
631 goto overwrite_done;
|
|
632 }
|
|
633
|
|
634 if (ch == 'F' || ch == 'f') {
|
|
635 overwrite = 0;
|
|
636 goto overwrite_done;
|
|
637 }
|
|
638
|
|
639 }
|
|
640
|
|
641 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
642 "client sent invalid \"Overwrite\" header: \"%V\"",
|
|
643 &over->value);
|
|
644 return NGX_HTTP_BAD_REQUEST;
|
|
645 }
|
|
646
|
|
647 overwrite = 1;
|
|
648
|
|
649 overwrite_done:
|
|
650
|
|
651 ngx_http_map_uri_to_path(r, &path, &root, 0);
|
|
652
|
|
653 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
654 "http copy from: \"%s\"", path.data);
|
|
655
|
|
656 uri = r->uri;
|
|
657
|
|
658 r->uri.len = last - p;
|
|
659 r->uri.data = p;
|
|
660
|
|
661 ngx_http_map_uri_to_path(r, ©.path, &root, 0);
|
|
662
|
|
663 r->uri = uri;
|
|
664
|
|
665 copy.path.len--; /* omit "\0" */
|
|
666
|
|
667 if (copy.path.data[copy.path.len - 1] == '/') {
|
|
668 slash = 1;
|
|
669 copy.path.len--;
|
|
670 copy.path.data[copy.path.len] = '\0';
|
|
671
|
|
672 } else {
|
|
673 slash = 0;
|
|
674 }
|
|
675
|
|
676 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
677 "http copy to: \"%s\"", copy.path.data);
|
|
678
|
484
|
679 if (ngx_file_info(copy.path.data, &fi) == NGX_FILE_ERROR) {
|
286
|
680 err = ngx_errno;
|
|
681
|
|
682 if (err != NGX_ENOENT) {
|
|
683 return ngx_http_dav_error(r->connection->log, err,
|
|
684 NGX_HTTP_NOT_FOUND, ngx_file_info_n,
|
|
685 copy.path.data);
|
|
686 }
|
|
687
|
|
688 /* destination does not exist */
|
|
689
|
362
|
690 overwrite = 0;
|
|
691 dir = 0;
|
|
692
|
286
|
693 } else {
|
|
694
|
|
695 /* destination exists */
|
|
696
|
|
697 if (ngx_is_dir(&fi) && !slash) {
|
362
|
698 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
699 "\"%V\" could not be %Ved to collection \"%V\"",
|
|
700 &r->uri, &r->method_name, &dest->value);
|
286
|
701 return NGX_HTTP_CONFLICT;
|
|
702 }
|
|
703
|
|
704 if (!overwrite) {
|
362
|
705 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_EEXIST,
|
|
706 "\"%s\" could not be created", copy.path.data);
|
286
|
707 return NGX_HTTP_PRECONDITION_FAILED;
|
|
708 }
|
|
709
|
362
|
710 dir = ngx_is_dir(&fi);
|
286
|
711 }
|
|
712
|
484
|
713 if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) {
|
286
|
714 return ngx_http_dav_error(r->connection->log, ngx_errno,
|
|
715 NGX_HTTP_NOT_FOUND, ngx_file_info_n,
|
|
716 path.data);
|
|
717 }
|
|
718
|
|
719 if (ngx_is_dir(&fi)) {
|
|
720
|
|
721 if (r->uri.data[r->uri.len - 1] != '/') {
|
362
|
722 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
723 "\"%V\" is collection", &r->uri);
|
286
|
724 return NGX_HTTP_BAD_REQUEST;
|
|
725 }
|
|
726
|
362
|
727 if (overwrite) {
|
|
728 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
729 "http delete: \"%s\"", copy.path.data);
|
|
730
|
|
731 rc = ngx_http_dav_delete_path(r, ©.path, dir);
|
|
732
|
|
733 if (rc != NGX_OK) {
|
|
734 return rc;
|
|
735 }
|
|
736 }
|
|
737 }
|
|
738
|
|
739 if (ngx_is_dir(&fi)) {
|
|
740
|
286
|
741 path.len -= 2; /* omit "/\0" */
|
|
742
|
|
743 if (r->method == NGX_HTTP_MOVE) {
|
|
744 if (ngx_rename_file(path.data, copy.path.data) != NGX_FILE_ERROR) {
|
|
745 return NGX_HTTP_CREATED;
|
|
746 }
|
|
747 }
|
|
748
|
|
749 if (ngx_create_dir(copy.path.data, ngx_file_access(&fi))
|
|
750 == NGX_FILE_ERROR)
|
|
751 {
|
|
752 return ngx_http_dav_error(r->connection->log, ngx_errno,
|
|
753 NGX_HTTP_NOT_FOUND,
|
|
754 ngx_create_dir_n, copy.path.data);
|
|
755 }
|
|
756
|
|
757 copy.len = path.len;
|
|
758
|
358
|
759 tree.init_handler = NULL;
|
362
|
760 tree.file_handler = ngx_http_dav_copy_tree_file;
|
286
|
761 tree.pre_tree_handler = ngx_http_dav_copy_dir;
|
|
762 tree.post_tree_handler = ngx_http_dav_copy_dir_time;
|
|
763 tree.spec_handler = ngx_http_dav_noop;
|
|
764 tree.data = ©
|
|
765 tree.alloc = 0;
|
|
766 tree.log = r->connection->log;
|
|
767
|
|
768 if (ngx_walk_tree(&tree, &path) == NGX_OK) {
|
|
769
|
|
770 if (r->method == NGX_HTTP_MOVE) {
|
|
771 rc = ngx_http_dav_delete_path(r, &path, 1);
|
|
772
|
|
773 if (rc != NGX_OK) {
|
|
774 return rc;
|
|
775 }
|
|
776 }
|
|
777
|
|
778 return NGX_HTTP_CREATED;
|
|
779 }
|
|
780
|
|
781 } else {
|
|
782
|
|
783 if (r->method == NGX_HTTP_MOVE) {
|
430
|
784
|
|
785 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
|
786
|
|
787 ext.access = 0;
|
|
788 ext.path_access = dlcf->access;
|
|
789 ext.time = -1;
|
|
790 ext.create_path = 1;
|
|
791 ext.delete_file = 0;
|
|
792 ext.log = r->connection->log;
|
|
793
|
|
794 if (ngx_ext_rename_file(&path, ©.path, &ext) == NGX_OK) {
|
286
|
795 return NGX_HTTP_NO_CONTENT;
|
|
796 }
|
430
|
797
|
514
|
798 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
286
|
799 }
|
|
800
|
362
|
801 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
|
|
802
|
514
|
803 cf.size = ngx_file_size(&fi);
|
|
804 cf.buf_size = 0;
|
|
805 cf.access = dlcf->access;
|
|
806 cf.time = ngx_file_mtime(&fi);
|
|
807 cf.log = r->connection->log;
|
286
|
808
|
514
|
809 if (ngx_copy_file(path.data, copy.path.data, &cf) == NGX_OK) {
|
286
|
810 return NGX_HTTP_NO_CONTENT;
|
|
811 }
|
|
812 }
|
|
813
|
|
814 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
815 }
|
|
816
|
|
817
|
|
818 static ngx_int_t
|
|
819 ngx_http_dav_copy_dir(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
|
820 {
|
|
821 u_char *p, *dir;
|
|
822 size_t len;
|
|
823 ngx_http_dav_copy_ctx_t *copy;
|
|
824
|
|
825 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
826 "http copy dir: \"%s\"", path->data);
|
|
827
|
|
828 copy = ctx->data;
|
|
829
|
|
830 len = copy->path.len + path->len;
|
|
831
|
|
832 dir = ngx_alloc(len + 1, ctx->log);
|
|
833 if (dir == NULL) {
|
|
834 return NGX_ABORT;
|
|
835 }
|
|
836
|
|
837 p = ngx_cpymem(dir, copy->path.data, copy->path.len);
|
|
838 (void) ngx_cpystrn(p, path->data + copy->len, path->len - copy->len + 1);
|
|
839
|
|
840 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
841 "http copy dir to: \"%s\"", dir);
|
|
842
|
|
843 if (ngx_create_dir(dir, ngx_dir_access(ctx->access)) == NGX_FILE_ERROR) {
|
|
844 (void) ngx_http_dav_error(ctx->log, ngx_errno, 0, ngx_create_dir_n,
|
|
845 dir);
|
|
846 }
|
|
847
|
|
848 ngx_free(dir);
|
|
849
|
|
850 return NGX_OK;
|
|
851 }
|
|
852
|
|
853
|
|
854 static ngx_int_t
|
|
855 ngx_http_dav_copy_dir_time(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
|
856 {
|
|
857 u_char *p, *dir;
|
|
858 size_t len;
|
|
859 ngx_http_dav_copy_ctx_t *copy;
|
|
860
|
|
861 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
862 "http copy dir time: \"%s\"", path->data);
|
|
863
|
|
864 copy = ctx->data;
|
|
865
|
|
866 len = copy->path.len + path->len;
|
|
867
|
|
868 dir = ngx_alloc(len + 1, ctx->log);
|
|
869 if (dir == NULL) {
|
|
870 return NGX_ABORT;
|
|
871 }
|
|
872
|
|
873 p = ngx_cpymem(dir, copy->path.data, copy->path.len);
|
|
874 (void) ngx_cpystrn(p, path->data + copy->len, path->len - copy->len + 1);
|
|
875
|
|
876 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
877 "http copy dir time to: \"%s\"", dir);
|
|
878
|
362
|
879 #if (NGX_WIN32)
|
|
880 {
|
|
881 ngx_fd_t fd;
|
286
|
882
|
|
883 fd = ngx_open_file(dir, NGX_FILE_RDWR, NGX_FILE_OPEN, 0);
|
|
884
|
|
885 if (fd == NGX_INVALID_FILE) {
|
|
886 (void) ngx_http_dav_error(ctx->log, ngx_errno, 0, ngx_open_file_n, dir);
|
|
887 goto failed;
|
|
888 }
|
|
889
|
|
890 if (ngx_set_file_time(NULL, fd, ctx->mtime) != NGX_OK) {
|
|
891 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
|
|
892 ngx_set_file_time_n " \"%s\" failed", dir);
|
|
893 }
|
|
894
|
|
895 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
|
|
896 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
|
|
897 ngx_close_file_n " \"%s\" failed", dir);
|
|
898 }
|
362
|
899 }
|
286
|
900
|
|
901 failed:
|
|
902
|
|
903 #else
|
|
904
|
|
905 if (ngx_set_file_time(dir, 0, ctx->mtime) != NGX_OK) {
|
|
906 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
|
|
907 ngx_set_file_time_n " \"%s\" failed", dir);
|
|
908 }
|
|
909
|
|
910 #endif
|
|
911
|
|
912 ngx_free(dir);
|
|
913
|
|
914 return NGX_OK;
|
|
915 }
|
|
916
|
|
917
|
|
918 static ngx_int_t
|
362
|
919 ngx_http_dav_copy_tree_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
|
286
|
920 {
|
|
921 u_char *p, *file;
|
|
922 size_t len;
|
514
|
923 ngx_copy_file_t cf;
|
286
|
924 ngx_http_dav_copy_ctx_t *copy;
|
|
925
|
|
926 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
927 "http copy file: \"%s\"", path->data);
|
|
928
|
|
929 copy = ctx->data;
|
|
930
|
|
931 len = copy->path.len + path->len;
|
|
932
|
|
933 file = ngx_alloc(len + 1, ctx->log);
|
|
934 if (file == NULL) {
|
|
935 return NGX_ABORT;
|
|
936 }
|
|
937
|
|
938 p = ngx_cpymem(file, copy->path.data, copy->path.len);
|
|
939 (void) ngx_cpystrn(p, path->data + copy->len, path->len - copy->len + 1);
|
|
940
|
|
941 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
|
|
942 "http copy file to: \"%s\"", file);
|
|
943
|
514
|
944 cf.size = ctx->size;
|
|
945 cf.buf_size = 0;
|
|
946 cf.access = ctx->access;
|
|
947 cf.time = ctx->mtime;
|
|
948 cf.log = ctx->log;
|
|
949
|
|
950 (void) ngx_copy_file(path->data, file, &cf);
|
362
|
951
|
|
952 ngx_free(file);
|
|
953
|
|
954 return NGX_OK;
|
|
955 }
|
|
956
|
|
957
|
|
958 static ngx_int_t
|
286
|
959 ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt)
|
|
960 {
|
|
961 ngx_table_elt_t *depth;
|
296
|
962
|
286
|
963 depth = r->headers_in.depth;
|
|
964
|
|
965 if (depth == NULL) {
|
|
966 return dflt;
|
|
967 }
|
|
968
|
|
969 if (depth->value.len == 1) {
|
|
970
|
|
971 if (depth->value.data[0] == '0') {
|
|
972 return 0;
|
|
973 }
|
|
974
|
|
975 if (depth->value.data[0] == '1') {
|
|
976 return 1;
|
|
977 }
|
|
978
|
|
979 } else {
|
|
980
|
|
981 if (depth->value.len == sizeof("infinity") - 1
|
|
982 && ngx_strcmp(depth->value.data, "infinity") == 0)
|
|
983 {
|
|
984 return NGX_HTTP_DAV_INFINITY_DEPTH;
|
|
985 }
|
|
986 }
|
|
987
|
|
988 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
|
|
989 "client sent invalid \"Depth\" header: \"%V\"",
|
|
990 &depth->value);
|
|
991
|
|
992 return NGX_HTTP_DAV_INVALID_DEPTH;
|
|
993 }
|
|
994
|
|
995
|
|
996 static ngx_int_t
|
|
997 ngx_http_dav_error(ngx_log_t *log, ngx_err_t err, ngx_int_t not_found,
|
186
|
998 char *failed, u_char *path)
|
|
999 {
|
|
1000 ngx_int_t rc;
|
|
1001 ngx_uint_t level;
|
|
1002
|
|
1003 if (err == NGX_ENOENT || err == NGX_ENOTDIR || err == NGX_ENAMETOOLONG) {
|
|
1004 level = NGX_LOG_ERR;
|
|
1005 rc = not_found;
|
|
1006
|
|
1007 } else if (err == NGX_EACCES || err == NGX_EPERM) {
|
|
1008 level = NGX_LOG_ERR;
|
|
1009 rc = NGX_HTTP_FORBIDDEN;
|
|
1010
|
|
1011 } else if (err == NGX_EEXIST) {
|
|
1012 level = NGX_LOG_ERR;
|
|
1013 rc = NGX_HTTP_NOT_ALLOWED;
|
|
1014
|
|
1015 } else if (err == NGX_ENOSPC) {
|
|
1016 level = NGX_LOG_CRIT;
|
|
1017 rc = NGX_HTTP_INSUFFICIENT_STORAGE;
|
|
1018
|
|
1019 } else {
|
|
1020 level = NGX_LOG_CRIT;
|
|
1021 rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
1022 }
|
|
1023
|
286
|
1024 ngx_log_error(level, log, err, "%s \"%s\" failed", failed, path);
|
186
|
1025
|
|
1026 return rc;
|
|
1027 }
|
|
1028
|
|
1029
|
|
1030 static ngx_int_t
|
|
1031 ngx_http_dav_location(ngx_http_request_t *r, u_char *path)
|
|
1032 {
|
|
1033 u_char *location;
|
|
1034 ngx_http_core_loc_conf_t *clcf;
|
|
1035
|
|
1036 r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
|
|
1037 if (r->headers_out.location == NULL) {
|
|
1038 return NGX_ERROR;
|
|
1039 }
|
|
1040
|
|
1041 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
1042
|
|
1043 if (!clcf->alias && clcf->root_lengths == NULL) {
|
|
1044 location = path + clcf->root.len;
|
|
1045
|
|
1046 } else {
|
382
|
1047 location = ngx_pnalloc(r->pool, r->uri.len);
|
186
|
1048 if (location == NULL) {
|
|
1049 return NGX_ERROR;
|
|
1050 }
|
|
1051
|
|
1052 ngx_memcpy(location, r->uri.data, r->uri.len);
|
|
1053 }
|
|
1054
|
|
1055 /*
|
|
1056 * we do not need to set the r->headers_out.location->hash and
|
|
1057 * r->headers_out.location->key fields
|
|
1058 */
|
|
1059
|
|
1060 r->headers_out.location->value.len = r->uri.len;
|
|
1061 r->headers_out.location->value.data = location;
|
|
1062
|
|
1063 return NGX_OK;
|
|
1064 }
|
|
1065
|
|
1066
|
182
|
1067 static void *
|
|
1068 ngx_http_dav_create_loc_conf(ngx_conf_t *cf)
|
|
1069 {
|
|
1070 ngx_http_dav_loc_conf_t *conf;
|
|
1071
|
|
1072 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_dav_loc_conf_t));
|
|
1073 if (conf == NULL) {
|
496
|
1074 return NULL;
|
182
|
1075 }
|
|
1076
|
|
1077 /*
|
|
1078 * set by ngx_pcalloc():
|
|
1079 *
|
|
1080 * conf->methods = 0;
|
|
1081 */
|
|
1082
|
364
|
1083 conf->min_delete_depth = NGX_CONF_UNSET_UINT;
|
362
|
1084 conf->access = NGX_CONF_UNSET_UINT;
|
186
|
1085 conf->create_full_put_path = NGX_CONF_UNSET;
|
|
1086
|
182
|
1087 return conf;
|
|
1088 }
|
|
1089
|
|
1090
|
|
1091 static char *
|
|
1092 ngx_http_dav_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
1093 {
|
|
1094 ngx_http_dav_loc_conf_t *prev = parent;
|
|
1095 ngx_http_dav_loc_conf_t *conf = child;
|
|
1096
|
|
1097 ngx_conf_merge_bitmask_value(conf->methods, prev->methods,
|
186
|
1098 (NGX_CONF_BITMASK_SET|NGX_HTTP_DAV_OFF));
|
|
1099
|
362
|
1100 ngx_conf_merge_uint_value(conf->min_delete_depth,
|
|
1101 prev->min_delete_depth, 0);
|
182
|
1102
|
218
|
1103 ngx_conf_merge_uint_value(conf->access, prev->access, 0600);
|
|
1104
|
362
|
1105 ngx_conf_merge_value(conf->create_full_put_path,
|
|
1106 prev->create_full_put_path, 0);
|
|
1107
|
182
|
1108 return NGX_CONF_OK;
|
|
1109 }
|
|
1110
|
|
1111
|
|
1112 static ngx_int_t
|
230
|
1113 ngx_http_dav_init(ngx_conf_t *cf)
|
182
|
1114 {
|
|
1115 ngx_http_handler_pt *h;
|
|
1116 ngx_http_core_main_conf_t *cmcf;
|
|
1117
|
230
|
1118 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
182
|
1119
|
|
1120 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
|
|
1121 if (h == NULL) {
|
|
1122 return NGX_ERROR;
|
|
1123 }
|
|
1124
|
|
1125 *h = ngx_http_dav_handler;
|
|
1126
|
|
1127 return NGX_OK;
|
|
1128 }
|