There was an error somewhere in the code when it was extracted from arut/dav-ext-module, perhaps due to the formatter.

This commit is contained in:
2024-04-16 12:34:32 +03:00
parent 74d7fa4143
commit 8b075a6abd

View File

@@ -310,8 +310,8 @@ static ngx_int_t ngx_http_dav_ext_content_handler(ngx_http_request_t *r) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http dav_ext propfind"); "http dav_ext propfind");
rc = rc = ngx_http_read_client_request_body(r,
ngx_http_read_client_request_body(r, ngx_http_dav_ext_propfind_handler); ngx_http_dav_ext_propfind_handler);
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc; return rc;
} }
@@ -458,8 +458,9 @@ static ngx_int_t ngx_http_dav_ext_content_handler(ngx_http_request_t *r) {
return NGX_DECLINED; return NGX_DECLINED;
} }
static void
static void ngx_http_dav_ext_propfind_handler(ngx_http_request_t *r) { ngx_http_dav_ext_propfind_handler(ngx_http_request_t *r)
{
off_t len; off_t len;
ngx_buf_t *b; ngx_buf_t *b;
ngx_chain_t *cl; ngx_chain_t *cl;
@@ -505,8 +506,9 @@ static void ngx_http_dav_ext_propfind_handler(ngx_http_request_t *r) {
len += b->last - b->pos; len += b->last - b->pos;
if (xmlParseChunk(pctx, (const char *)b->pos, b->last - b->pos, if (xmlParseChunk(pctx, (const char *) b->pos, b->last - b->pos,
b->last_buf)) { b->last_buf))
{
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"xmlParseChunk() failed"); "xmlParseChunk() failed");
xmlFreeParserCtxt(pctx); xmlFreeParserCtxt(pctx);
@@ -530,10 +532,12 @@ static void ngx_http_dav_ext_propfind_handler(ngx_http_request_t *r) {
ngx_http_finalize_request(r, ngx_http_dav_ext_propfind(r, xctx.props)); ngx_http_finalize_request(r, ngx_http_dav_ext_propfind(r, xctx.props));
} }
static void ngx_http_dav_ext_propfind_xml_start( static void
void *data, const xmlChar *localname, const xmlChar *prefix, ngx_http_dav_ext_propfind_xml_start(void *data, const xmlChar *localname,
const xmlChar *uri, int nb_namespaces, const xmlChar **namespaces, const xmlChar *prefix, const xmlChar *uri, int nb_namespaces,
int nb_attributes, int nb_defaulted, const xmlChar **attributes) { const xmlChar **namespaces, int nb_attributes, int nb_defaulted,
const xmlChar **attributes)
{
ngx_http_dav_ext_xml_ctx_t *xctx = data; ngx_http_dav_ext_xml_ctx_t *xctx = data;
if (ngx_strcmp(localname, "propfind") == 0) { if (ngx_strcmp(localname, "propfind") == 0) {
@@ -553,10 +557,11 @@ static void ngx_http_dav_ext_propfind_xml_start(
} }
} }
static void ngx_http_dav_ext_propfind_xml_end(void *data,
const xmlChar *localname, static void
const xmlChar *prefix, ngx_http_dav_ext_propfind_xml_end(void *data, const xmlChar *localname,
const xmlChar *uri) { const xmlChar *prefix, const xmlChar *uri)
{
ngx_http_dav_ext_xml_ctx_t *xctx = data; ngx_http_dav_ext_xml_ctx_t *xctx = data;
if (xctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROPFIND) { if (xctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROPFIND) {
@@ -596,12 +601,14 @@ static void ngx_http_dav_ext_propfind_xml_end(void *data,
} }
} }
ngx_http_dav_ext_propfind_xml_start(data, localname, prefix, uri, 0, NULL, 0, ngx_http_dav_ext_propfind_xml_start(data, localname, prefix, uri,
0, NULL); 0, NULL, 0, 0, NULL);
} }
static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
ngx_uint_t props) { static ngx_int_t
ngx_http_dav_ext_propfind(ngx_http_request_t *r, ngx_uint_t props)
{
size_t root, allocated; size_t root, allocated;
u_char *p, *last, *filename; u_char *p, *last, *filename;
ngx_int_t rc; ngx_int_t rc;
@@ -613,8 +620,9 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
ngx_file_info_t fi; ngx_file_info_t fi;
ngx_http_dav_ext_entry_t *entry; ngx_http_dav_ext_entry_t *entry;
if (ngx_array_init(&entries, r->pool, 40, sizeof(ngx_http_dav_ext_entry_t)) != if (ngx_array_init(&entries, r->pool, 40, sizeof(ngx_http_dav_ext_entry_t))
NGX_OK) { != NGX_OK)
{
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
@@ -639,8 +647,8 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
depth = rc; depth = rc;
last = last = ngx_http_map_uri_to_path(r, &path, &root,
ngx_http_map_uri_to_path(r, &path, &root, NGX_HTTP_DAV_EXT_PREALLOCATE); NGX_HTTP_DAV_EXT_PREALLOCATE);
if (last == NULL) { if (last == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
@@ -700,8 +708,8 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
} }
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http dav_ext propfind name:\"%V\", uri:\"%V\"", &entry->name, "http dav_ext propfind name:\"%V\", uri:\"%V\"",
&entry->uri); &entry->name, &entry->uri);
if (depth == 0 || !entry->dir) { if (depth == 0 || !entry->dir) {
return ngx_http_dav_ext_propfind_response(r, &entries, props); return ngx_http_dav_ext_propfind_response(r, &entries, props);
@@ -718,7 +726,7 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
filename = path.data; filename = path.data;
filename[path.len] = '/'; filename[path.len] = '/';
for (;;) { for ( ;; ) {
ngx_set_errno(0); ngx_set_errno(0);
if (ngx_read_dir(&dir) == NGX_ERROR) { if (ngx_read_dir(&dir) == NGX_ERROR) {
@@ -736,8 +744,7 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
name.len = ngx_de_namelen(&dir); name.len = ngx_de_namelen(&dir);
name.data = ngx_de_name(&dir); name.data = ngx_de_name(&dir);
if ((name.len == 1 && name.data[0] == '.') || if (name.data[0] == '.') {
(name.len == 2 && name.data[0] == '.' && name.data[1] == '.')) {
continue; continue;
} }
@@ -755,7 +762,8 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
if (!dir.valid_info) { if (!dir.valid_info) {
if (path.len + 1 + name.len + 1 > allocated) { if (path.len + 1 + name.len + 1 > allocated) {
allocated = path.len + 1 + name.len + 1 + NGX_HTTP_DAV_EXT_PREALLOCATE; allocated = path.len + 1 + name.len + 1
+ NGX_HTTP_DAV_EXT_PREALLOCATE;
filename = ngx_pnalloc(r->pool, allocated); filename = ngx_pnalloc(r->pool, allocated);
if (filename == NULL) { if (filename == NULL) {
@@ -770,9 +778,10 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
ngx_cpystrn(last, name.data, name.len + 1); ngx_cpystrn(last, name.data, name.len + 1);
if (ngx_de_info(filename, &dir) == NGX_FILE_ERROR) { if (ngx_de_info(filename, &dir) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
ngx_de_info_n " \"%s\" failed", filename); ngx_de_info_n " \"%s\" failed", filename);
continue; rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
break;
} }
} }
@@ -831,10 +840,10 @@ static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
return ngx_http_dav_ext_propfind_response(r, &entries, props); return ngx_http_dav_ext_propfind_response(r, &entries, props);
} }
static ngx_int_t
static ngx_int_t ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries,
ngx_array_t *entries, ngx_uint_t props)
ngx_uint_t props) { {
size_t len; size_t len;
u_char *p; u_char *p;
uintptr_t escape; uintptr_t escape;
@@ -844,16 +853,18 @@ static ngx_int_t ngx_http_dav_ext_propfind_response(ngx_http_request_t *r,
ngx_chain_t cl; ngx_chain_t cl;
ngx_http_dav_ext_entry_t *entry; ngx_http_dav_ext_entry_t *entry;
static u_char head[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" static u_char head[] =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"
"<D:multistatus xmlns:D=\"DAV:\">\n"; "<D:multistatus xmlns:D=\"DAV:\">\n";
static u_char tail[] = "</D:multistatus>\n"; static u_char tail[] =
"</D:multistatus>\n";
entry = entries->elts; entry = entries->elts;
for (n = 0; n < entries->nelts; n++) { for (n = 0; n < entries->nelts; n++) {
escape = 2 * ngx_escape_uri(NULL, entry[n].uri.data, entry[n].uri.len, escape = 2 * ngx_escape_uri(NULL, entry[n].uri.data, entry[n].uri.len,
NGX_ESCAPE_URI_COMPONENT); NGX_ESCAPE_URI);
if (escape == 0) { if (escape == 0) {
continue; continue;
} }
@@ -863,10 +874,10 @@ static ngx_int_t ngx_http_dav_ext_propfind_response(ngx_http_request_t *r,
return NGX_HTTP_INTERNAL_SERVER_ERROR; return NGX_HTTP_INTERNAL_SERVER_ERROR;
} }
entry[n].uri.len = entry[n].uri.len = (u_char *) ngx_escape_uri(p, entry[n].uri.data,
(u_char *)ngx_escape_uri(p, entry[n].uri.data, entry[n].uri.len, entry[n].uri.len,
NGX_ESCAPE_URI_COMPONENT) - NGX_ESCAPE_URI)
p; - p;
entry[n].uri.data = p; entry[n].uri.data = p;
} }
@@ -884,8 +895,8 @@ static ngx_int_t ngx_http_dav_ext_propfind_response(ngx_http_request_t *r,
b->last = ngx_cpymem(b->last, head, sizeof(head) - 1); b->last = ngx_cpymem(b->last, head, sizeof(head) - 1);
for (n = 0; n < entries->nelts; n++) { for (n = 0; n < entries->nelts; n++) {
b->last = (u_char *)ngx_http_dav_ext_format_propfind(r, b->last, &entry[n], b->last = (u_char *) ngx_http_dav_ext_format_propfind(r, b->last,
props); &entry[n], props);
} }
b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1); b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);
@@ -1255,46 +1266,52 @@ static uint32_t ngx_http_dav_ext_lock_token(ngx_http_request_t *r) {
return 0; return 0;
} }
static uintptr_t static uintptr_t
ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst, ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
ngx_http_dav_ext_entry_t *entry, ngx_http_dav_ext_entry_t *entry, ngx_uint_t props)
ngx_uint_t props) { {
size_t len; size_t len;
static u_char head[] = "<D:response>\n" static u_char head[] =
"<D:response>\n"
"<D:href>"; "<D:href>";
/* uri */ /* uri */
static u_char prop[] = "</D:href>\n" static u_char prop[] =
"</D:href>\n"
"<D:propstat>\n" "<D:propstat>\n"
"<D:prop>\n"; "<D:prop>\n";
/* properties */ /* properties */
static u_char tail[] = "</D:prop>\n" static u_char tail[] =
"</D:prop>\n"
"<D:status>HTTP/1.1 200 OK</D:status>\n" "<D:status>HTTP/1.1 200 OK</D:status>\n"
"</D:propstat>\n" "</D:propstat>\n"
"</D:response>\n"; "</D:response>\n";
static u_char names[] = "<D:displayname/>\n" static u_char names[] =
"<D:displayname/>\n"
"<D:getcontentlength/>\n" "<D:getcontentlength/>\n"
"<D:getlastmodified/>\n" "<D:getlastmodified/>\n"
"<D:resourcetype/>\n" "<D:resourcetype/>\n"
"<D:lockdiscovery/>\n" "<D:lockdiscovery/>\n"
"<D:supportedlock/>\n"; "<D:supportedlock/>\n";
static u_char supportedlock[] = "<D:lockentry>\n" static u_char supportedlock[] =
"<D:lockentry>\n"
"<D:lockscope><D:exclusive/></D:lockscope>\n" "<D:lockscope><D:exclusive/></D:lockscope>\n"
"<D:locktype><D:write/></D:locktype>\n" "<D:locktype><D:write/></D:locktype>\n"
"</D:lockentry>\n"; "</D:lockentry>\n";
if (dst == NULL) { if (dst == NULL) {
len = sizeof(head) - 1 + sizeof(prop) - 1 + sizeof(tail) - 1; len = sizeof(head) - 1
+ sizeof(prop) - 1
+ sizeof(tail) - 1;
len += len += entry->uri.len + ngx_escape_html(NULL, entry->uri.data,
entry->uri.len + ngx_escape_html(NULL, entry->uri.data, entry->uri.len); entry->uri.len);
if (props & NGX_HTTP_DAV_EXT_PROP_NAMES) { if (props & NGX_HTTP_DAV_EXT_PROP_NAMES) {
len += sizeof(names) - 1; len += sizeof(names) - 1;
@@ -1315,12 +1332,11 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
"</D:resourcetype>\n" "</D:resourcetype>\n"
"<D:supportedlock>\n" "<D:supportedlock>\n"
"</D:supportedlock>\n") - "</D:supportedlock>\n") - 1;
1;
/* displayname */ /* displayname */
len += entry->name.len + len += entry->name.len
ngx_escape_html(NULL, entry->name.data, entry->name.len); + ngx_escape_html(NULL, entry->name.data, entry->name.len);
/* getcontentlength */ /* getcontentlength */
len += NGX_OFF_T_LEN; len += NGX_OFF_T_LEN;
@@ -1338,7 +1354,7 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
} }
dst = ngx_cpymem(dst, head, sizeof(head) - 1); dst = ngx_cpymem(dst, head, sizeof(head) - 1);
dst = (u_char *)ngx_escape_html(dst, entry->uri.data, entry->uri.len); dst = (u_char *) ngx_escape_html(dst, entry->uri.data, entry->uri.len);
dst = ngx_cpymem(dst, prop, sizeof(prop) - 1); dst = ngx_cpymem(dst, prop, sizeof(prop) - 1);
if (props & NGX_HTTP_DAV_EXT_PROP_NAMES) { if (props & NGX_HTTP_DAV_EXT_PROP_NAMES) {
@@ -1346,18 +1362,18 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
} else { } else {
if (props & NGX_HTTP_DAV_EXT_PROP_DISPLAYNAME) { if (props & NGX_HTTP_DAV_EXT_PROP_DISPLAYNAME) {
dst = ngx_cpymem(dst, "<D:displayname>", sizeof("<D:displayname>") - 1); dst = ngx_cpymem(dst, "<D:displayname>",
dst = (u_char *)ngx_escape_html(dst, entry->name.data, entry->name.len); sizeof("<D:displayname>") - 1);
dst = (u_char *) ngx_escape_html(dst, entry->name.data,
entry->name.len);
dst = ngx_cpymem(dst, "</D:displayname>\n", dst = ngx_cpymem(dst, "</D:displayname>\n",
sizeof("</D:displayname>\n") - 1); sizeof("</D:displayname>\n") - 1);
} }
if (props & NGX_HTTP_DAV_EXT_PROP_GETCONTENTLENGTH) { if (props & NGX_HTTP_DAV_EXT_PROP_GETCONTENTLENGTH) {
if (!entry->dir) { if (!entry->dir) {
dst = ngx_sprintf(dst, dst = ngx_sprintf(dst, "<D:getcontentlength>%O"
"<D:getcontentlength>%O" "</D:getcontentlength>\n", entry->size);
"</D:getcontentlength>\n",
entry->size);
} }
} }
@@ -1370,10 +1386,12 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
} }
if (props & NGX_HTTP_DAV_EXT_PROP_RESOURCETYPE) { if (props & NGX_HTTP_DAV_EXT_PROP_RESOURCETYPE) {
dst = ngx_cpymem(dst, "<D:resourcetype>", sizeof("<D:resourcetype>") - 1); dst = ngx_cpymem(dst, "<D:resourcetype>",
sizeof("<D:resourcetype>") - 1);
if (entry->dir) { if (entry->dir) {
dst = ngx_cpymem(dst, "<D:collection/>", sizeof("<D:collection/>") - 1); dst = ngx_cpymem(dst, "<D:collection/>",
sizeof("<D:collection/>") - 1);
} }
dst = ngx_cpymem(dst, "</D:resourcetype>\n", dst = ngx_cpymem(dst, "</D:resourcetype>\n",
@@ -1381,7 +1399,8 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
} }
if (props & NGX_HTTP_DAV_EXT_PROP_LOCKDISCOVERY) { if (props & NGX_HTTP_DAV_EXT_PROP_LOCKDISCOVERY) {
dst = (u_char *)ngx_http_dav_ext_format_lockdiscovery(r, dst, entry); dst = (u_char *) ngx_http_dav_ext_format_lockdiscovery(r, dst,
entry);
} }
if (props & NGX_HTTP_DAV_EXT_PROP_SUPPORTEDLOCK) { if (props & NGX_HTTP_DAV_EXT_PROP_SUPPORTEDLOCK) {
@@ -1399,10 +1418,9 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
dst = ngx_cpymem(dst, tail, sizeof(tail) - 1); dst = ngx_cpymem(dst, tail, sizeof(tail) - 1);
return (uintptr_t)dst; return (uintptr_t) dst;
} }
static ngx_int_t ngx_http_dav_ext_init_zone(ngx_shm_zone_t *shm_zone, static ngx_int_t ngx_http_dav_ext_init_zone(ngx_shm_zone_t *shm_zone,
void *data) { void *data) {
ngx_http_dav_ext_lock_t *olock = data; ngx_http_dav_ext_lock_t *olock = data;