comparison src/http/modules/ngx_http_dav_module.c @ 665:0b460e61bdcd default tip

Merge with nginx 1.0.0.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:22:17 +0400
parents bc110f60c0de
children
comparison
equal deleted inserted replaced
572:06419a2298a9 665:0b460e61bdcd
144 ngx_http_dav_handler(ngx_http_request_t *r) 144 ngx_http_dav_handler(ngx_http_request_t *r)
145 { 145 {
146 ngx_int_t rc; 146 ngx_int_t rc;
147 ngx_http_dav_loc_conf_t *dlcf; 147 ngx_http_dav_loc_conf_t *dlcf;
148 148
149 if (r->zero_in_uri) {
150 return NGX_DECLINED;
151 }
152
153 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module); 149 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
154 150
155 if (!(r->method & dlcf->methods)) { 151 if (!(r->method & dlcf->methods)) {
156 return NGX_DECLINED; 152 return NGX_DECLINED;
157 } 153 }
323 ngx_http_map_uri_to_path(r, &path, &root, 0); 319 ngx_http_map_uri_to_path(r, &path, &root, 0);
324 320
325 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 321 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
326 "http delete filename: \"%s\"", path.data); 322 "http delete filename: \"%s\"", path.data);
327 323
328 if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) { 324 if (ngx_link_info(path.data, &fi) == NGX_FILE_ERROR) {
329 err = ngx_errno; 325 err = ngx_errno;
330 326
331 rc = (err == NGX_ENOTDIR) ? NGX_HTTP_CONFLICT : NGX_HTTP_NOT_FOUND; 327 rc = (err == NGX_ENOTDIR) ? NGX_HTTP_CONFLICT : NGX_HTTP_NOT_FOUND;
332 328
333 return ngx_http_dav_error(r->connection->log, err, 329 return ngx_http_dav_error(r->connection->log, err,
334 rc, ngx_file_info_n, path.data); 330 rc, ngx_link_info_n, path.data);
335 } 331 }
336 332
337 if (ngx_is_dir(&fi)) { 333 if (ngx_is_dir(&fi)) {
338 334
339 if (r->uri.data[r->uri.len - 1] != '/') { 335 if (r->uri.data[r->uri.len - 1] != '/') {
356 352
357 } else { 353 } else {
358 354
359 /* 355 /*
360 * we do not need to test (r->uri.data[r->uri.len - 1] == '/') 356 * we do not need to test (r->uri.data[r->uri.len - 1] == '/')
361 * because ngx_file_info("/file/") returned NGX_ENOTDIR above 357 * because ngx_link_info("/file/") returned NGX_ENOTDIR above
362 */ 358 */
363 359
364 depth = ngx_http_dav_depth(r, 0); 360 depth = ngx_http_dav_depth(r, 0);
365 361
366 if (depth != 0 && depth != NGX_HTTP_DAV_INFINITY_DEPTH) { 362 if (depth != 0 && depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
488 } 484 }
489 485
490 p = ngx_http_map_uri_to_path(r, &path, &root, 0); 486 p = ngx_http_map_uri_to_path(r, &path, &root, 0);
491 487
492 *(p - 1) = '\0'; 488 *(p - 1) = '\0';
489 r->uri.len--;
493 490
494 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 491 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
495 "http mkcol path: \"%s\"", path.data); 492 "http mkcol path: \"%s\"", path.data);
496 493
497 if (ngx_create_dir(path.data, ngx_dir_access(dlcf->access)) 494 if (ngx_create_dir(path.data, ngx_dir_access(dlcf->access))
514 { 511 {
515 u_char *p, *host, *last, ch; 512 u_char *p, *host, *last, ch;
516 size_t len, root; 513 size_t len, root;
517 ngx_err_t err; 514 ngx_err_t err;
518 ngx_int_t rc, depth; 515 ngx_int_t rc, depth;
519 ngx_uint_t overwrite, slash, dir; 516 ngx_uint_t overwrite, slash, dir, flags;
520 ngx_str_t path, uri; 517 ngx_str_t path, uri, duri, args;
521 ngx_tree_ctx_t tree; 518 ngx_tree_ctx_t tree;
522 ngx_copy_file_t cf; 519 ngx_copy_file_t cf;
523 ngx_file_info_t fi; 520 ngx_file_info_t fi;
524 ngx_table_elt_t *dest, *over; 521 ngx_table_elt_t *dest, *over;
525 ngx_ext_rename_file_t ext; 522 ngx_ext_rename_file_t ext;
536 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 533 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
537 "client sent no \"Destination\" header"); 534 "client sent no \"Destination\" header");
538 return NGX_HTTP_BAD_REQUEST; 535 return NGX_HTTP_BAD_REQUEST;
539 } 536 }
540 537
538 p = dest->value.data;
539 /* there is always '\0' even after empty header value */
540 if (p[0] == '/') {
541 last = p + dest->value.len;
542 goto destination_done;
543 }
544
541 len = r->headers_in.server.len; 545 len = r->headers_in.server.len;
542 546
543 if (len == 0) { 547 if (len == 0) {
544 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 548 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
545 "client sent no \"Host\" header"); 549 "client sent no \"Host\" header");
591 "client sent invalid \"Destination\" header: \"%V\"", 595 "client sent invalid \"Destination\" header: \"%V\"",
592 &dest->value); 596 &dest->value);
593 return NGX_HTTP_BAD_REQUEST; 597 return NGX_HTTP_BAD_REQUEST;
594 598
595 destination_done: 599 destination_done:
600
601 duri.len = last - p;
602 duri.data = p;
603 flags = 0;
604
605 if (ngx_http_parse_unsafe_uri(r, &duri, &args, &flags) != NGX_OK) {
606 goto invalid_destination;
607 }
596 608
597 if ((r->uri.data[r->uri.len - 1] == '/' && *(last - 1) != '/') 609 if ((r->uri.data[r->uri.len - 1] == '/' && *(last - 1) != '/')
598 || (r->uri.data[r->uri.len - 1] != '/' && *(last - 1) == '/')) 610 || (r->uri.data[r->uri.len - 1] != '/' && *(last - 1) == '/'))
599 { 611 {
600 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 612 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
654 666
655 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 667 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
656 "http copy from: \"%s\"", path.data); 668 "http copy from: \"%s\"", path.data);
657 669
658 uri = r->uri; 670 uri = r->uri;
659 671 r->uri = duri;
660 r->uri.len = last - p;
661 r->uri.data = p;
662 672
663 ngx_http_map_uri_to_path(r, &copy.path, &root, 0); 673 ngx_http_map_uri_to_path(r, &copy.path, &root, 0);
664 674
665 r->uri = uri; 675 r->uri = uri;
666 676
676 } 686 }
677 687
678 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 688 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
679 "http copy to: \"%s\"", copy.path.data); 689 "http copy to: \"%s\"", copy.path.data);
680 690
681 if (ngx_file_info(copy.path.data, &fi) == NGX_FILE_ERROR) { 691 if (ngx_link_info(copy.path.data, &fi) == NGX_FILE_ERROR) {
682 err = ngx_errno; 692 err = ngx_errno;
683 693
684 if (err != NGX_ENOENT) { 694 if (err != NGX_ENOENT) {
685 return ngx_http_dav_error(r->connection->log, err, 695 return ngx_http_dav_error(r->connection->log, err,
686 NGX_HTTP_NOT_FOUND, ngx_file_info_n, 696 NGX_HTTP_NOT_FOUND, ngx_link_info_n,
687 copy.path.data); 697 copy.path.data);
688 } 698 }
689 699
690 /* destination does not exist */ 700 /* destination does not exist */
691 701
710 } 720 }
711 721
712 dir = ngx_is_dir(&fi); 722 dir = ngx_is_dir(&fi);
713 } 723 }
714 724
715 if (ngx_file_info(path.data, &fi) == NGX_FILE_ERROR) { 725 if (ngx_link_info(path.data, &fi) == NGX_FILE_ERROR) {
716 return ngx_http_dav_error(r->connection->log, ngx_errno, 726 return ngx_http_dav_error(r->connection->log, ngx_errno,
717 NGX_HTTP_NOT_FOUND, ngx_file_info_n, 727 NGX_HTTP_NOT_FOUND, ngx_link_info_n,
718 path.data); 728 path.data);
719 } 729 }
720 730
721 if (ngx_is_dir(&fi)) { 731 if (ngx_is_dir(&fi)) {
722 732