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