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