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