Skip to content

Commit a360425

Browse files
committed
Eliminated request context.
1 parent 920f4fb commit a360425

File tree

1 file changed

+50
-58
lines changed

1 file changed

+50
-58
lines changed

ngx_http_dav_ext_module.c

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct {
5050
typedef struct {
5151
ngx_uint_t nodes;
5252
ngx_uint_t props;
53-
} ngx_http_dav_ext_ctx_t;
53+
} ngx_http_dav_ext_xml_ctx_t;
5454

5555

5656
typedef struct {
@@ -98,11 +98,12 @@ static void ngx_http_dav_ext_propfind_xml_start(void *data,
9898
int nb_defaulted, const xmlChar **attributes);
9999
static void ngx_http_dav_ext_propfind_xml_end(void *data,
100100
const xmlChar *localname, const xmlChar *prefix, const xmlChar *uri);
101-
static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r);
101+
static ngx_int_t ngx_http_dav_ext_propfind(ngx_http_request_t *r,
102+
ngx_uint_t props);
102103
static ngx_int_t ngx_http_dav_ext_set_locks(ngx_http_request_t *r,
103104
ngx_http_dav_ext_entry_t *entry);
104105
static ngx_int_t ngx_http_dav_ext_propfind_response(ngx_http_request_t *r,
105-
ngx_array_t *entries);
106+
ngx_array_t *entries, ngx_uint_t props);
106107
static ngx_int_t ngx_http_dav_ext_lock_handler(ngx_http_request_t *r);
107108
static ngx_int_t ngx_http_dav_ext_lock_response(ngx_http_request_t *r,
108109
ngx_uint_t status, time_t timeout, ngx_uint_t depth, uint32_t token);
@@ -113,7 +114,7 @@ static ngx_int_t ngx_http_dav_ext_depth(ngx_http_request_t *r,
113114
static uint32_t ngx_http_dav_ext_lock_token(ngx_http_request_t *r);
114115
static uint32_t ngx_http_dav_ext_if(ngx_http_request_t *r, ngx_str_t *uri);
115116
static uintptr_t ngx_http_dav_ext_format_propfind(ngx_http_request_t *r,
116-
u_char *dst, ngx_http_dav_ext_entry_t *entry);
117+
u_char *dst, ngx_http_dav_ext_entry_t *entry, ngx_uint_t props);
117118
static uintptr_t ngx_http_dav_ext_format_lockdiscovery(ngx_http_request_t *r,
118119
u_char *dst, ngx_http_dav_ext_entry_t *entry);
119120
static uintptr_t ngx_http_dav_ext_format_token(u_char *dst, uint32_t token,
@@ -581,31 +582,24 @@ ngx_http_dav_ext_content_handler(ngx_http_request_t *r)
581582
static void
582583
ngx_http_dav_ext_propfind_handler(ngx_http_request_t *r)
583584
{
584-
off_t len;
585-
ngx_buf_t *b;
586-
ngx_chain_t *cl;
587-
xmlSAXHandler sax;
588-
xmlParserCtxtPtr pctx;
589-
ngx_http_dav_ext_ctx_t *ctx;
585+
off_t len;
586+
ngx_buf_t *b;
587+
ngx_chain_t *cl;
588+
xmlSAXHandler sax;
589+
xmlParserCtxtPtr pctx;
590+
ngx_http_dav_ext_xml_ctx_t xctx;
590591

591592
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
592593
"http dav_ext propfind handler");
593594

594-
ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_dav_ext_ctx_t));
595-
if (ctx == NULL) {
596-
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
597-
return;
598-
}
599-
600-
ngx_http_set_ctx(r, ctx, ngx_http_dav_ext_module);
601-
595+
ngx_memzero(&xctx, sizeof(ngx_http_dav_ext_xml_ctx_t));
602596
ngx_memzero(&sax, sizeof(xmlSAXHandler));
603597

604598
sax.initialized = XML_SAX2_MAGIC;
605599
sax.startElementNs = ngx_http_dav_ext_propfind_xml_start;
606600
sax.endElementNs = ngx_http_dav_ext_propfind_xml_end;
607601

608-
pctx = xmlCreatePushParserCtxt(&sax, ctx, NULL, 0, NULL);
602+
pctx = xmlCreatePushParserCtxt(&sax, &xctx, NULL, 0, NULL);
609603
if (pctx == NULL) {
610604
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
611605
"xmlCreatePushParserCtxt() failed");
@@ -656,10 +650,10 @@ ngx_http_dav_ext_propfind_handler(ngx_http_request_t *r)
656650
* as if they expect all properties.
657651
*/
658652

659-
ctx->props = NGX_HTTP_DAV_EXT_PROP_ALL;
653+
xctx.props = NGX_HTTP_DAV_EXT_PROP_ALL;
660654
}
661655

662-
ngx_http_finalize_request(r, ngx_http_dav_ext_propfind(r));
656+
ngx_http_finalize_request(r, ngx_http_dav_ext_propfind(r, xctx.props));
663657
}
664658

665659

@@ -669,22 +663,22 @@ ngx_http_dav_ext_propfind_xml_start(void *data, const xmlChar *localname,
669663
const xmlChar **namespaces, int nb_attributes, int nb_defaulted,
670664
const xmlChar **attributes)
671665
{
672-
ngx_http_dav_ext_ctx_t *ctx = data;
666+
ngx_http_dav_ext_xml_ctx_t *xctx = data;
673667

674668
if (ngx_strcmp(localname, "propfind") == 0) {
675-
ctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_PROPFIND;
669+
xctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_PROPFIND;
676670
}
677671

678672
if (ngx_strcmp(localname, "prop") == 0) {
679-
ctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_PROP;
673+
xctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_PROP;
680674
}
681675

682676
if (ngx_strcmp(localname, "propname") == 0) {
683-
ctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_PROPNAME;
677+
xctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_PROPNAME;
684678
}
685679

686680
if (ngx_strcmp(localname, "allprop") == 0) {
687-
ctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_ALLPROP;
681+
xctx->nodes ^= NGX_HTTP_DAV_EXT_NODE_ALLPROP;
688682
}
689683
}
690684

@@ -693,42 +687,42 @@ static void
693687
ngx_http_dav_ext_propfind_xml_end(void *data, const xmlChar *localname,
694688
const xmlChar *prefix, const xmlChar *uri)
695689
{
696-
ngx_http_dav_ext_ctx_t *ctx = data;
690+
ngx_http_dav_ext_xml_ctx_t *xctx = data;
697691

698-
if (ctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROPFIND) {
692+
if (xctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROPFIND) {
699693

700-
if (ctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROP) {
694+
if (xctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROP) {
701695
if (ngx_strcmp(localname, "displayname") == 0) {
702-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_DISPLAYNAME;
696+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_DISPLAYNAME;
703697
}
704698

705699
if (ngx_strcmp(localname, "getcontentlength") == 0) {
706-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_GETCONTENTLENGTH;
700+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_GETCONTENTLENGTH;
707701
}
708702

709703
if (ngx_strcmp(localname, "getlastmodified") == 0) {
710-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_GETLASTMODIFIED;
704+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_GETLASTMODIFIED;
711705
}
712706

713707
if (ngx_strcmp(localname, "resourcetype") == 0) {
714-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_RESOURCETYPE;
708+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_RESOURCETYPE;
715709
}
716710

717711
if (ngx_strcmp(localname, "lockdiscovery") == 0) {
718-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_LOCKDISCOVERY;
712+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_LOCKDISCOVERY;
719713
}
720714

721715
if (ngx_strcmp(localname, "supportedlock") == 0) {
722-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_SUPPORTEDLOCK;
716+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_SUPPORTEDLOCK;
723717
}
724718
}
725719

726-
if (ctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROPNAME) {
727-
ctx->props |= NGX_HTTP_DAV_EXT_PROP_NAMES;
720+
if (xctx->nodes & NGX_HTTP_DAV_EXT_NODE_PROPNAME) {
721+
xctx->props |= NGX_HTTP_DAV_EXT_PROP_NAMES;
728722
}
729723

730-
if (ctx->nodes & NGX_HTTP_DAV_EXT_NODE_ALLPROP) {
731-
ctx->props = NGX_HTTP_DAV_EXT_PROP_ALL;
724+
if (xctx->nodes & NGX_HTTP_DAV_EXT_NODE_ALLPROP) {
725+
xctx->props = NGX_HTTP_DAV_EXT_PROP_ALL;
732726
}
733727
}
734728

@@ -738,7 +732,7 @@ ngx_http_dav_ext_propfind_xml_end(void *data, const xmlChar *localname,
738732

739733

740734
static ngx_int_t
741-
ngx_http_dav_ext_propfind(ngx_http_request_t *r)
735+
ngx_http_dav_ext_propfind(ngx_http_request_t *r, ngx_uint_t props)
742736
{
743737
size_t root, allocated;
744738
u_char *p, *last, *filename;
@@ -843,7 +837,7 @@ ngx_http_dav_ext_propfind(ngx_http_request_t *r)
843837
&entry->name, &entry->uri);
844838

845839
if (depth == 0 || !entry->dir) {
846-
return ngx_http_dav_ext_propfind_response(r, &entries);
840+
return ngx_http_dav_ext_propfind_response(r, &entries, props);
847841
}
848842

849843
if (ngx_open_dir(&path, &dir) == NGX_ERROR) {
@@ -967,7 +961,7 @@ ngx_http_dav_ext_propfind(ngx_http_request_t *r)
967961
return rc;
968962
}
969963

970-
return ngx_http_dav_ext_propfind_response(r, &entries);
964+
return ngx_http_dav_ext_propfind_response(r, &entries, props);
971965
}
972966

973967

@@ -1019,7 +1013,8 @@ ngx_http_dav_ext_set_locks(ngx_http_request_t *r,
10191013

10201014

10211015
static ngx_int_t
1022-
ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries)
1016+
ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries,
1017+
ngx_uint_t props)
10231018
{
10241019
size_t len;
10251020
u_char *p;
@@ -1061,7 +1056,7 @@ ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries)
10611056
len = sizeof(head) - 1 + sizeof(tail) - 1;
10621057

10631058
for (n = 0; n < entries->nelts; n++) {
1064-
len += ngx_http_dav_ext_format_propfind(r, NULL, &entry[n]);
1059+
len += ngx_http_dav_ext_format_propfind(r, NULL, &entry[n], props);
10651060
}
10661061

10671062
b = ngx_create_temp_buf(r->pool, len);
@@ -1073,7 +1068,7 @@ ngx_http_dav_ext_propfind_response(ngx_http_request_t *r, ngx_array_t *entries)
10731068

10741069
for (n = 0; n < entries->nelts; n++) {
10751070
b->last = (u_char *) ngx_http_dav_ext_format_propfind(r, b->last,
1076-
&entry[n]);
1071+
&entry[n], props);
10771072
}
10781073

10791074
b->last = ngx_cpymem(b->last, tail, sizeof(tail) - 1);
@@ -1674,10 +1669,9 @@ ngx_http_dav_ext_if(ngx_http_request_t *r, ngx_str_t *uri)
16741669

16751670
static uintptr_t
16761671
ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
1677-
ngx_http_dav_ext_entry_t *entry)
1672+
ngx_http_dav_ext_entry_t *entry, ngx_uint_t props)
16781673
{
1679-
size_t len;
1680-
ngx_http_dav_ext_ctx_t *ctx;
1674+
size_t len;
16811675

16821676
static u_char head[] =
16831677
"<D:response>\n"
@@ -1712,8 +1706,6 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
17121706
"<D:locktype><D:write/></D:locktype>\n"
17131707
"</D:lockentry>\n";
17141708

1715-
ctx = ngx_http_get_module_ctx(r, ngx_http_dav_ext_module);
1716-
17171709
if (dst == NULL) {
17181710
len = sizeof(head) - 1
17191711
+ sizeof(prop) - 1
@@ -1722,7 +1714,7 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
17221714
len += entry->uri.len + ngx_escape_html(NULL, entry->uri.data,
17231715
entry->uri.len);
17241716

1725-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_NAMES) {
1717+
if (props & NGX_HTTP_DAV_EXT_PROP_NAMES) {
17261718
len += sizeof(names) - 1;
17271719

17281720
} else {
@@ -1766,11 +1758,11 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
17661758
dst = (u_char *) ngx_escape_html(dst, entry->uri.data, entry->uri.len);
17671759
dst = ngx_cpymem(dst, prop, sizeof(prop) - 1);
17681760

1769-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_NAMES) {
1761+
if (props & NGX_HTTP_DAV_EXT_PROP_NAMES) {
17701762
dst = ngx_cpymem(dst, names, sizeof(names) - 1);
17711763

17721764
} else {
1773-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_DISPLAYNAME) {
1765+
if (props & NGX_HTTP_DAV_EXT_PROP_DISPLAYNAME) {
17741766
dst = ngx_cpymem(dst, "<D:displayname>",
17751767
sizeof("<D:displayname>") - 1);
17761768
dst = (u_char *) ngx_escape_html(dst, entry->name.data,
@@ -1779,22 +1771,22 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
17791771
sizeof("</D:displayname>\n") - 1);
17801772
}
17811773

1782-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_GETCONTENTLENGTH) {
1774+
if (props & NGX_HTTP_DAV_EXT_PROP_GETCONTENTLENGTH) {
17831775
if (!entry->dir) {
17841776
dst = ngx_sprintf(dst, "<D:getcontentlength>%O"
17851777
"</D:getcontentlength>\n", entry->size);
17861778
}
17871779
}
17881780

1789-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_GETLASTMODIFIED) {
1781+
if (props & NGX_HTTP_DAV_EXT_PROP_GETLASTMODIFIED) {
17901782
dst = ngx_cpymem(dst, "<D:getlastmodified>",
17911783
sizeof("<D:getlastmodified>") - 1);
17921784
dst = ngx_http_time(dst, entry->mtime);
17931785
dst = ngx_cpymem(dst, "</D:getlastmodified>\n",
17941786
sizeof("</D:getlastmodified>\n") - 1);
17951787
}
17961788

1797-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_RESOURCETYPE) {
1789+
if (props & NGX_HTTP_DAV_EXT_PROP_RESOURCETYPE) {
17981790
dst = ngx_cpymem(dst, "<D:resourcetype>",
17991791
sizeof("<D:resourcetype>") - 1);
18001792

@@ -1807,12 +1799,12 @@ ngx_http_dav_ext_format_propfind(ngx_http_request_t *r, u_char *dst,
18071799
sizeof("</D:resourcetype>\n") - 1);
18081800
}
18091801

1810-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_LOCKDISCOVERY) {
1802+
if (props & NGX_HTTP_DAV_EXT_PROP_LOCKDISCOVERY) {
18111803
dst = (u_char *) ngx_http_dav_ext_format_lockdiscovery(r, dst,
18121804
entry);
18131805
}
18141806

1815-
if (ctx->props & NGX_HTTP_DAV_EXT_PROP_SUPPORTEDLOCK) {
1807+
if (props & NGX_HTTP_DAV_EXT_PROP_SUPPORTEDLOCK) {
18161808
dst = ngx_cpymem(dst, "<D:supportedlock>\n",
18171809
sizeof("<D:supportedlock>\n") - 1);
18181810

0 commit comments

Comments
 (0)