Skip to content

Commit 4f3a133

Browse files
committed
PROPFIND child items lockdiscovery.
1 parent 1f51d6b commit 4f3a133

File tree

1 file changed

+51
-67
lines changed

1 file changed

+51
-67
lines changed

ngx_http_dav_ext_module.c

Lines changed: 51 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void ngx_http_dav_ext_propfind_xml_end(void *data,
100100
const xmlChar *localname, const xmlChar *prefix, const xmlChar *uri);
101101
static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r);
102102
static ngx_int_t ngx_http_dav_ext_set_locks(ngx_http_request_t *r,
103-
ngx_str_t *uri, ngx_http_dav_ext_entry_t *entry);
103+
ngx_http_dav_ext_entry_t *entry);
104104
static ngx_int_t ngx_http_dav_ext_propfind_response(ngx_http_request_t *r,
105105
ngx_array_t *entries);
106106
static ngx_int_t ngx_http_dav_ext_lock_handler(ngx_http_request_t *r);
@@ -738,10 +738,9 @@ ngx_http_dav_ext_propfind(ngx_http_request_t *r)
738738
{
739739
size_t root, allocated;
740740
u_char *p, *last, *filename;
741-
uintptr_t escape;
742741
ngx_int_t rc;
743742
ngx_err_t err;
744-
ngx_str_t path, name, uri;
743+
ngx_str_t path, name;
745744
ngx_dir_t dir;
746745
ngx_uint_t depth;
747746
ngx_array_t entries;
@@ -821,48 +820,27 @@ ngx_http_dav_ext_propfind(ngx_http_request_t *r)
821820
}
822821
}
823822

824-
if (r->valid_unparsed_uri) {
825-
uri = r->unparsed_uri;
826-
827-
} else {
828-
escape = 2 * ngx_escape_uri(NULL, r->uri.data, r->uri.len,
829-
NGX_ESCAPE_URI);
830-
if (escape == 0) {
831-
uri = r->uri;
832-
833-
} else {
834-
uri.data = ngx_pnalloc(r->pool, r->uri.len + escape);
835-
if (uri.data == NULL) {
836-
return NGX_HTTP_INTERNAL_SERVER_ERROR;
837-
}
838-
839-
p = (u_char *) ngx_escape_uri(uri.data, r->uri.data, r->uri.len,
840-
NGX_ESCAPE_URI);
841-
uri.len = p - uri.data;
842-
}
843-
}
844-
845-
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
846-
"http dav_ext propfind name:\"%V\", uri:\"%V\"",
847-
&name, &uri);
848-
849823
entry = ngx_array_push(&entries);
850824
if (entry == NULL) {
851825
return NGX_HTTP_INTERNAL_SERVER_ERROR;
852826
}
853827

854828
ngx_memzero(entry, sizeof(ngx_http_dav_ext_entry_t));
855829

856-
entry->uri = uri;
830+
entry->uri = r->uri;
857831
entry->name = name;
858832
entry->dir = ngx_is_dir(&fi);
859833
entry->mtime = ngx_file_mtime(&fi);
860834
entry->size = ngx_file_size(&fi);
861835

862-
if (ngx_http_dav_ext_set_locks(r, &r->uri, entry) != NGX_OK) {
836+
if (ngx_http_dav_ext_set_locks(r, entry) != NGX_OK) {
863837
return NGX_HTTP_INTERNAL_SERVER_ERROR;
864838
}
865839

840+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
841+
"http dav_ext propfind name:\"%V\", uri:\"%V\"",
842+
&entry->name, &entry->uri);
843+
866844
if (depth == 0 || !entry->dir) {
867845
return ngx_http_dav_ext_propfind_response(r, &entries);
868846
}
@@ -936,62 +914,47 @@ ngx_http_dav_ext_propfind(ngx_http_request_t *r)
936914
}
937915
}
938916

939-
escape = 2 * ngx_escape_uri(NULL, name.data, name.len,
940-
NGX_ESCAPE_URI_COMPONENT);
917+
p = ngx_pnalloc(r->pool, name.len);
918+
if (p == NULL) {
919+
rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
920+
break;
921+
}
922+
923+
ngx_memcpy(p, name.data, name.len);
924+
entry->name.data = p;
925+
entry->name.len = name.len;
941926

942-
p = ngx_pnalloc(r->pool, uri.len + 1 + name.len + escape + 1);
927+
p = ngx_pnalloc(r->pool, r->uri.len + 1 + name.len + 1);
943928
if (p == NULL) {
944929
rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
945930
break;
946931
}
947932

948933
entry->uri.data = p;
934+
p = ngx_cpymem(p, r->uri.data, r->uri.len);
949935

950-
p = ngx_cpymem(p, uri.data, uri.len);
951-
952-
if (uri.len && uri.data[uri.len - 1] != '/') {
936+
if (r->uri.len && r->uri.data[r->uri.len - 1] != '/') {
953937
*p++ = '/';
954938
}
955939

956-
p = (u_char *) ngx_escape_uri(p, name.data, name.len,
957-
NGX_ESCAPE_URI_COMPONENT);
958-
940+
p = ngx_cpymem(p, name.data, name.len);
959941
if (ngx_de_is_dir(&dir)) {
960942
*p++ = '/';
961943
}
962944

963945
entry->uri.len = p - entry->uri.data;
964946

965-
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
966-
"http dav_ext propfind child name:\"%V\", uri:\"%V\"",
967-
&name, &entry->uri);
968-
969-
p = ngx_pnalloc(r->pool, name.len);
970-
if (p == NULL) {
971-
rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
972-
break;
973-
}
974-
975-
ngx_memcpy(p, name.data, name.len);
976-
977-
entry->name.data = p;
978-
entry->name.len = name.len;
979-
980947
entry->dir = ngx_de_is_dir(&dir);
981948
entry->mtime = ngx_de_mtime(&dir);
982949
entry->size = ngx_de_size(&dir);
983950

984-
/*
985-
* XXX
986-
* - this may be slow, check flags?
987-
* - we only have urlencoded uri, but need unencoded
988-
*/
989-
990-
/*
991-
if (ngx_http_dav_ext_set_locks(r, uri?, entry) != NGX_OK) {
951+
if (ngx_http_dav_ext_set_locks(r, entry) != NGX_OK) {
992952
return NGX_HTTP_INTERNAL_SERVER_ERROR;
993953
}
994-
*/
954+
955+
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
956+
"http dav_ext propfind child name:\"%V\", uri:\"%V\"",
957+
&entry->name, &entry->uri);
995958
}
996959

997960
if (ngx_close_dir(&dir) == NGX_ERROR) {
@@ -1008,7 +971,7 @@ ngx_http_dav_ext_propfind(ngx_http_request_t *r)
1008971

1009972

1010973
static ngx_int_t
1011-
ngx_http_dav_ext_set_locks(ngx_http_request_t *r, ngx_str_t *uri,
974+
ngx_http_dav_ext_set_locks(ngx_http_request_t *r,
1012975
ngx_http_dav_ext_entry_t *entry)
1013976
{
1014977
ngx_http_dav_ext_node_t *node;
@@ -1028,7 +991,7 @@ ngx_http_dav_ext_set_locks(ngx_http_request_t *r, ngx_str_t *uri,
1028991

1029992
ngx_shmtx_lock(&lock->shpool->mutex);
1030993

1031-
node = ngx_http_dav_ext_lock_lookup(r, lock, uri, -1);
994+
node = ngx_http_dav_ext_lock_lookup(r, lock, &entry->uri, -1);
1032995

1033996
if (node == NULL) {
1034997
ngx_shmtx_unlock(&lock->shpool->mutex);
@@ -1058,6 +1021,8 @@ static ngx_int_t
10581021
ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries)
10591022
{
10601023
size_t len;
1024+
u_char *p;
1025+
uintptr_t escape;
10611026
ngx_buf_t *b;
10621027
ngx_int_t rc;
10631028
ngx_uint_t n;
@@ -1071,10 +1036,29 @@ ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries)
10711036
static u_char tail[] =
10721037
"</D:multistatus>\n";
10731038

1074-
len = sizeof(head) - 1 + sizeof(tail) - 1;
1075-
10761039
entry = entries->elts;
10771040

1041+
for (n = 0; n < entries->nelts; n++) {
1042+
escape = 2 * ngx_escape_uri(NULL, entry[n].uri.data, entry[n].uri.len,
1043+
NGX_ESCAPE_URI);
1044+
if (escape == 0) {
1045+
continue;
1046+
}
1047+
1048+
p = ngx_pnalloc(r->pool, entry[n].uri.len + escape);
1049+
if (p == NULL) {
1050+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
1051+
}
1052+
1053+
entry[n].uri.len = (u_char *) ngx_escape_uri(p, entry[n].uri.data,
1054+
entry[n].uri.len,
1055+
NGX_ESCAPE_URI)
1056+
- p;
1057+
entry[n].uri.data = p;
1058+
}
1059+
1060+
len = sizeof(head) - 1 + sizeof(tail) - 1;
1061+
10781062
for (n = 0; n < entries->nelts; n++) {
10791063
len += ngx_http_dav_ext_format_propfind(r, NULL, &entry[n]);
10801064
}

0 commit comments

Comments
 (0)