Skip to content

Commit cec536c

Browse files
committed
Add DASL(SEARCH) support to mod_dav.
Submitted by: Sung Kim <hunkim@cse.ucsc.edu> git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@94486 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2b6596f commit cec536c

3 files changed

Lines changed: 126 additions & 3 deletions

File tree

modules/dav/fs/repos.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,8 @@ static const dav_provider dav_fs_provider =
20972097
&dav_hooks_db_dbm,
20982098
&dav_hooks_locks_fs,
20992099
NULL, /* vsn */
2100-
NULL /* binding */
2100+
NULL, /* binding */
2101+
NULL /* search */
21012102
};
21022103

21032104
void dav_fs_gather_propsets(apr_array_header_t *uris)

modules/dav/main/mod_dav.c

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ extern module DAV_DECLARE_DATA dav_module;
133133
/* DAV methods */
134134
enum {
135135
DAV_M_BIND = 0,
136+
DAV_M_SEARCH,
136137
DAV_M_LAST
137138
};
138139
static int dav_methods[DAV_M_LAST];
@@ -145,6 +146,7 @@ static int dav_init_handler(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,
145146

146147
/* Register DAV methods */
147148
dav_methods[DAV_M_BIND] = ap_method_register(p, "BIND");
149+
dav_methods[DAV_M_SEARCH] = ap_method_register(p, "SEARCH");
148150

149151
ap_add_version_component(p, "DAV/2");
150152

@@ -265,6 +267,11 @@ const dav_hooks_binding *dav_get_binding_hooks(request_rec *r)
265267
return dav_get_provider(r)->binding;
266268
}
267269

270+
const dav_hooks_search *dav_get_search_hooks(request_rec *r)
271+
{
272+
return dav_get_provider(r)->search;
273+
}
274+
268275
/*
269276
* Command handler for the DAV directive, which is TAKE1.
270277
*/
@@ -1427,12 +1434,69 @@ static dav_error *dav_gen_supported_reports(request_rec *r,
14271434
return NULL;
14281435
}
14291436

1437+
1438+
/* handle the SEARCH method */
1439+
static int dav_method_search(request_rec *r)
1440+
{
1441+
const dav_hooks_search *search_hooks = DAV_GET_HOOKS_SEARCH(r);
1442+
dav_resource *resource;
1443+
dav_error *err;
1444+
dav_response *multi_status;
1445+
1446+
/* If no search provider, decline the request */
1447+
if (search_hooks == NULL)
1448+
return DECLINED;
1449+
1450+
/* This method should only be called when the resource is not
1451+
* visible to Apache. We will fetch the resource from the repository,
1452+
* then create a subrequest for Apache to handle.
1453+
*/
1454+
err = dav_get_resource(r, 1 /* label_allowed */, 0 /* use_checked_in */,
1455+
&resource);
1456+
if (err != NULL)
1457+
return dav_handle_err(r, err, NULL);
1458+
1459+
if (!resource->exists) {
1460+
/* Apache will supply a default error for this. */
1461+
return HTTP_NOT_FOUND;
1462+
}
1463+
1464+
/* set up the HTTP headers for the response */
1465+
if ((err = (*resource->hooks->set_headers)(r, resource)) != NULL) {
1466+
err = dav_push_error(r->pool, err->status, 0,
1467+
"Unable to set up HTTP headers.",
1468+
err);
1469+
return dav_handle_err(r, err, NULL);
1470+
}
1471+
1472+
if (r->header_only) {
1473+
return DONE;
1474+
}
1475+
1476+
/* okay... time to search the content */
1477+
/* Let's validate XML and process walk function
1478+
* in the hook function
1479+
*/
1480+
if ((err = (*search_hooks->search_resource)(r, &multi_status)) != NULL) {
1481+
/* ### add a higher-level description? */
1482+
return dav_handle_err(r, err, NULL);
1483+
}
1484+
1485+
/* We have results in multi_status */
1486+
/* Should I pass namespace?? */
1487+
dav_send_multistatus(r, HTTP_MULTI_STATUS, multi_status, NULL);
1488+
1489+
return DONE;
1490+
}
1491+
1492+
14301493
/* handle the OPTIONS method */
14311494
static int dav_method_options(request_rec *r)
14321495
{
14331496
const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r);
14341497
const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
14351498
const dav_hooks_binding *binding_hooks = DAV_GET_HOOKS_BINDING(r);
1499+
const dav_hooks_search *search_hooks = DAV_GET_HOOKS_SEARCH(r);
14361500
dav_resource *resource;
14371501
const char *dav_level;
14381502
char *allow;
@@ -1617,6 +1681,11 @@ static int dav_method_options(request_rec *r)
16171681
apr_table_addn(methods, "BIND", "");
16181682
}
16191683

1684+
/* If there is a search provider, set SEARCH in option */
1685+
if (search_hooks != NULL) {
1686+
apr_table_addn(methods, "SEARCH", "");
1687+
}
1688+
16201689
/* Generate the Allow header */
16211690
arr = apr_table_elts(methods);
16221691
elts = (const apr_table_entry_t *)arr->elts;
@@ -1646,6 +1715,19 @@ static int dav_method_options(request_rec *r)
16461715

16471716
apr_table_setn(r->headers_out, "Allow", allow);
16481717

1718+
1719+
/* If there is search set_option_head function, set head */
1720+
/* DASL: <DAV:basicsearch>
1721+
* DASL: <http://foo.bar.com/syntax1>
1722+
* DASL: <http://akuma.com/syntax2>
1723+
*/
1724+
if (search_hooks != NULL
1725+
&& *search_hooks->set_option_head != NULL) {
1726+
if ((err = (*search_hooks->set_option_head)(r)) != NULL) {
1727+
return dav_handle_err(r, err, NULL);
1728+
}
1729+
}
1730+
16491731
/* if there was no request body, then there is no response body */
16501732
if (doc == NULL) {
16511733
ap_set_content_length(r, 0);
@@ -4513,7 +4595,12 @@ static int dav_handler(request_rec *r)
45134595
return dav_method_bind(r);
45144596
}
45154597

4516-
/* ### add'l methods for Advanced Collections, ACLs, DASL */
4598+
/* DASL method */
4599+
if (r->method_number == dav_methods[DAV_M_SEARCH]) {
4600+
return dav_method_search(r);
4601+
}
4602+
4603+
/* ### add'l methods for Advanced Collections, ACLs */
45174604

45184605
return DECLINED;
45194606
}

modules/dav/main/mod_dav.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ typedef struct dav_hooks_vsn dav_hooks_vsn;
268268
typedef struct dav_hooks_repository dav_hooks_repository;
269269
typedef struct dav_hooks_liveprop dav_hooks_liveprop;
270270
typedef struct dav_hooks_binding dav_hooks_binding;
271+
typedef struct dav_hooks_search dav_hooks_search;
271272

272273
/* ### deprecated name */
273274
typedef dav_hooks_propdb dav_hooks_db;
@@ -612,7 +613,7 @@ typedef struct {
612613
const dav_hooks_locks *locks;
613614
const dav_hooks_vsn *vsn;
614615
const dav_hooks_binding *binding;
615-
616+
const dav_hooks_search *search;
616617
} dav_provider;
617618

618619
/*
@@ -666,6 +667,7 @@ const dav_hooks_locks *dav_get_lock_hooks(request_rec *r);
666667
const dav_hooks_propdb *dav_get_propdb_hooks(request_rec *r);
667668
const dav_hooks_vsn *dav_get_vsn_hooks(request_rec *r);
668669
const dav_hooks_binding *dav_get_binding_hooks(request_rec *r);
670+
const dav_hooks_search *dav_get_search(request_rec *r);
669671

670672
DAV_DECLARE(void) dav_register_provider(apr_pool_t *p, const char *name,
671673
const dav_provider *hooks);
@@ -677,6 +679,7 @@ const dav_provider * dav_lookup_provider(const char *name);
677679
#define DAV_GET_HOOKS_LOCKS(r) dav_get_lock_hooks(r)
678680
#define DAV_GET_HOOKS_VSN(r) dav_get_vsn_hooks(r)
679681
#define DAV_GET_HOOKS_BINDING(r) dav_get_binding_hooks(r)
682+
#define DAV_GET_HOOKS_SEARCH(r) dav_get_search_hooks(r)
680683

681684

682685
/* --------------------------------------------------------------------
@@ -2334,6 +2337,38 @@ struct dav_hooks_binding {
23342337
};
23352338

23362339

2340+
/* --------------------------------------------------------------------
2341+
**
2342+
** SEARCH(DASL) FUNCTIONS
2343+
*/
2344+
2345+
/* search provider hooks */
2346+
struct dav_hooks_search {
2347+
/* Set header for a OPTION method
2348+
* An error may be returned.
2349+
* To set a hadder, this function might call
2350+
* apr_table_setn(r->headers_out, "DASL", dasl_optin1);
2351+
*
2352+
* Examples:
2353+
* DASL: <DAV:basicsearch>
2354+
* DASL: <http://foo.bar.com/syntax1>
2355+
* DASL: <http://akuma.com/syntax2>
2356+
*/
2357+
dav_error * (*set_option_head)(request_rec *r);
2358+
2359+
/* Search resources
2360+
* An error may be returned. *response will contain multistatus
2361+
* responses (if any) suitable for the body of the error. It is also
2362+
* possible to return NULL, yet still have multistatus responses.
2363+
* In this case, typically the caller should return a 207 (Multistatus)
2364+
* and the responses (in the body) as the HTTP response.
2365+
*/
2366+
dav_error * (*search_resource)(request_rec *r,
2367+
dav_response **response);
2368+
2369+
};
2370+
2371+
23372372
/* --------------------------------------------------------------------
23382373
**
23392374
** MISCELLANEOUS STUFF

0 commit comments

Comments
 (0)