** - various utilities, repository-independent
*/
+#include "apr_strings.h"
+
+#define APR_WANT_STRFUNC
+#include "apr_want.h"
+
#include "mod_dav.h"
#include "http_request.h"
#include "http_log.h"
#include "http_protocol.h"
-#include "apr_strings.h"
-
DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status,
int error_id, const char *desc)
{
{
dav_lookup_result result = { 0 };
const char *scheme;
- unsigned short port = ntohs(r->connection->local_addr.sin_port);
+ apr_port_t port;
uri_components comp;
char *new_file;
const char *domain;
the port, must match our port.
the URI must not have a query (args) or a fragment
*/
+ apr_sockaddr_port_get(&port, r->connection->local_addr);
if (strcasecmp(comp.scheme, scheme) != 0 ||
comp.port != port) {
result.err.status = HTTP_BAD_GATEWAY;
* same HTTP method on the destination. This allows the destination
* to apply appropriate restrictions (e.g. readonly).
*/
- result.rnew = ap_sub_req_method_uri(r->method, new_file, r);
+ result.rnew = ap_sub_req_method_uri(r->method, new_file, r, NULL);
return result;
}
return NULL;
}
+/* gather up all the CDATA into a single string */
+const char *dav_xml_get_cdata(const ap_xml_elem *elem, apr_pool_t *pool,
+ int strip_white)
+{
+ apr_size_t len = 0;
+ ap_text *scan;
+ const ap_xml_elem *child;
+ char *cdata;
+ char *s;
+ apr_size_t tlen;
+
+ for (scan = elem->first_cdata.first; scan != NULL; scan = scan->next)
+ len += strlen(scan->text);
+
+ for (child = elem->first_child; child != NULL; child = child->next) {
+ for (scan = child->following_cdata.first;
+ scan != NULL;
+ scan = scan->next)
+ len += strlen(scan->text);
+ }
+
+ cdata = s = apr_palloc(pool, len + 1);
+
+ for (scan = elem->first_cdata.first; scan != NULL; scan = scan->next) {
+ tlen = strlen(scan->text);
+ memcpy(s, scan->text, tlen);
+ s += tlen;
+ }
+
+ for (child = elem->first_child; child != NULL; child = child->next) {
+ for (scan = child->following_cdata.first;
+ scan != NULL;
+ scan = scan->next) {
+ tlen = strlen(scan->text);
+ memcpy(s, scan->text, tlen);
+ s += tlen;
+ }
+ }
+
+ *s = '\0';
+
+ if (strip_white && len > 0) {
+ /* trim leading whitespace */
+ while (apr_isspace(*cdata)) /* assume: return false for '\0' */
+ ++cdata;
+
+ /* trim trailing whitespace */
+ while (len-- > 0 && apr_isspace(cdata[len]))
+ continue;
+ cdata[len + 1] = '\0';
+ }
+
+ return cdata;
+}
+
/* ---------------------------------------------------------------
**
** Timeout header processing
/* (2) Validate the parent resource if requested */
if (err == NULL && (flags & DAV_VALIDATE_PARENT)) {
- dav_resource *parent_resource = (*repos_hooks->get_parent_resource)(resource);
+ dav_resource *parent_resource;
+
+ err = (*repos_hooks->get_parent_resource)(resource, &parent_resource);
- if (parent_resource == NULL) {
+ if (err == NULL && parent_resource == NULL) {
err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0,
"Cannot access parent of repository root.");
}
- else {
+ else if (err == NULL) {
err = dav_validate_resource_state(r->pool, parent_resource, lockdb,
if_header,
flags | DAV_VALIDATE_IS_PARENT,
return NULL;
}
+#if 0 /* not needed right now... */
+
static const char *strip_white(const char *s, apr_pool_t *pool)
{
apr_size_t idx;
return s;
}
+#endif
-#define DAV_TARGET_SELECTOR_HDR "Target-Selector"
-
-/* see mod_dav.h for docco */
-int dav_get_target_selector(request_rec *r,
- const ap_xml_elem *version,
- const char **target,
- int *is_label)
-{
- /* Initialize results */
- *target = NULL;
- *is_label = 0;
-
- if (version != NULL) {
- /* Expect either <DAV:version><DAV:href>URI</DAV:href></DAV:version>
- * or <DAV:label-name>LABEL</DAV:label-name> */
- if (strcmp(version->name, "version") == 0) {
- if ((version = dav_find_child(version, "href")) == NULL) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
- "Missing DAV:href in DAV:version element");
- return HTTP_BAD_REQUEST;
- }
-
- /* return the contents of the DAV:href element */
- /* ### this presumes no child elements */
- *target = strip_white(version->first_cdata.first->text, r->pool);
- }
- else if (strcmp(version->name, "label-name") == 0) {
- /* return contents of the DAV:label-name element */
- *target = strip_white(version->first_cdata.first->text, r->pool);
- *is_label = 1;
- }
- else {
- ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r,
- "Unknown version specifier (not DAV:version or DAV:label-name)");
- return HTTP_BAD_REQUEST;
- }
- }
- else {
- /* no element. see if a Target-Selector header was provided
- * (which is always interpreted as a label) */
- *target = apr_table_get(r->headers_in, DAV_TARGET_SELECTOR_HDR);
- *is_label = 1;
- }
-
- return OK;
-}
+#define DAV_LABEL_HDR "Label"
/* dav_add_vary_header
*
{
const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(in_req);
+ /* ### this is probably all wrong... I think there is a function in
+ ### the Apache API to add things to the Vary header. need to check */
+
/* Only versioning headers require a Vary response header,
* so only do this check if there is a versioning provider */
if (vsn_hooks != NULL) {
- const char *target = apr_table_get(in_req->headers_in, DAV_TARGET_SELECTOR_HDR);
+ const char *target = apr_table_get(in_req->headers_in, DAV_LABEL_HDR);
const char *vary = apr_table_get(out_req->headers_out, "Vary");
/* If Target-Selector specified, add it to the Vary header */
if (target != NULL) {
if (vary == NULL)
- vary = DAV_TARGET_SELECTOR_HDR;
+ vary = DAV_LABEL_HDR;
else
- vary = apr_pstrcat(out_req->pool, vary, "," DAV_TARGET_SELECTOR_HDR, NULL);
+ vary = apr_pstrcat(out_req->pool, vary, "," DAV_LABEL_HDR,
+ NULL);
apr_table_setn(out_req->headers_out, "Vary", vary);
}
/* check parent resource if requested or if resource must be created */
if (!resource->exists || parent_only) {
- dav_resource *parent = (*resource->hooks->get_parent_resource)(resource);
+ dav_resource *parent;
+
+ if ((err = (*resource->hooks->get_parent_resource)(resource,
+ &parent)) != NULL)
+ return err;
+
if (parent == NULL || !parent->exists) {
body = apr_psprintf(r->pool,
"Missing one or more intermediate collections. "
* Note that auto-versioning can only be applied to a version selector,
* so no separate working resource will be created.
*/
- if ((err = (*vsn_hooks->checkout)(parent, NULL))
+ if ((err = (*vsn_hooks->checkout)(parent, 0, 0, 0, NULL, NULL))
!= NULL)
{
body = apr_psprintf(r->pool,
if (!parent_only && !resource->working) {
/* Auto-versioning can only be applied to version selectors, so
* no separate working resource will be created. */
- if ((err = (*vsn_hooks->checkout)(resource, NULL))
+ if ((err = (*vsn_hooks->checkout)(resource, 0, 0, 0, NULL, NULL))
!= NULL)
{
body = apr_psprintf(r->pool,