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