Commit 16f160c4 authored by Greg Stein's avatar Greg Stein
Browse files

*) add activity handling: OPTIONS and MKACTIVITY

*) fix HTTP status code in MKWORKSPACE handling
*) add can_be_activity and make_activity hooks to dav_hooks_vsn


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87980 13f79535-47bb-0310-9956-ffa450edef68
parent f486b708
Loading
Loading
Loading
Loading
+56 −3
Original line number Diff line number Diff line
@@ -1672,6 +1672,10 @@ static int dav_method_options(request_rec *r)
            if (vsn_hooks->can_be_workspace != NULL
                && (*vsn_hooks->can_be_workspace)(resource))
                apr_table_addn(methods, "MKWORKSPACE", "");

            if (vsn_hooks->can_be_activity != NULL
                && (*vsn_hooks->can_be_activity)(resource))
                apr_table_addn(methods, "MKACTIVITY", "");
        }
        else if (!resource->versioned) {
            if ((*vsn_hooks->versionable)(resource))
@@ -3930,7 +3934,7 @@ static int dav_method_make_workspace(request_rec *r)

    /* attempt to create the workspace */
    if ((err = (*vsn_hooks->make_workspace)(resource, doc)) != NULL) {
	err = dav_push_error(r->pool, HTTP_CONFLICT, 0,
	err = dav_push_error(r->pool, err->status, 0,
			     apr_psprintf(r->pool,
					 "Could not create workspace %s.",
					 ap_escape_html(r->pool, r->uri)),
@@ -3947,8 +3951,57 @@ static int dav_method_make_workspace(request_rec *r)

static int dav_method_make_activity(request_rec *r)
{
    /* ### */
    return HTTP_METHOD_NOT_ALLOWED;
    dav_resource *resource;
    const dav_hooks_vsn *vsn_hooks = DAV_GET_HOOKS_VSN(r);
    dav_error *err;
    int result;

    /* if no versioning provider, or the provider does not support activities,
     * decline the request
     */
    if (vsn_hooks == NULL || vsn_hooks->make_activity == NULL)
        return DECLINED;

    /* ask repository module to resolve the resource */
    err = dav_get_resource(r, 0 /*target_allowed*/, NULL, &resource);
    if (err != NULL)
        return dav_handle_err(r, err, NULL);

    /* MKACTIVITY does not have a defined request body. */
    if ((result = ap_discard_request_body(r)) != OK) {
	return result;
    }

    /* Check request preconditions */

    /* ### need a general mechanism for reporting precondition violations
     * ### (should be returning XML document for 403/409 responses)
     */

    /* resource must not already exist */
    if (resource->exists) {
        err = dav_new_error(r->pool, HTTP_CONFLICT, 0,
                            "<DAV:resource-must-be-null/>");
	return dav_handle_err(r, err, NULL);
    }

    /* ### what about locking? */

    /* attempt to create the activity */
    if ((err = (*vsn_hooks->make_activity)(resource)) != NULL) {
	err = dav_push_error(r->pool, err->status, 0,
			     apr_psprintf(r->pool,
					 "Could not create activity %s.",
					 ap_escape_html(r->pool, r->uri)),
			     err);
        return dav_handle_err(r, err, NULL);
    }

    /* set the Cache-Control header, per the spec */
    apr_table_setn(r->headers_out, "Cache-Control", "no-cache");

    /* return an appropriate response (HTTP_CREATED) */
    return dav_created(r, resource->uri, "Activity", 0 /*replaced*/);
}

static int dav_method_baseline_control(request_rec *r)
+22 −0
Original line number Diff line number Diff line
@@ -2063,6 +2063,28 @@ struct dav_hooks_vsn
    */
    dav_error * (*make_workspace)(dav_resource *resource,
                                  ap_xml_doc *doc);

    /*
    ** Determine whether a null resource can be created as an activity.
    ** The provider may restrict activities to certain locations.
    ** Returns 0 if the resource cannot be an activity.
    **
    ** This hook is optional; if the provider does not support activities,
    ** it should be set to NULL.
    */
    int (*can_be_activity)(const dav_resource *resource);

    /*
    ** Create an activity resource. The resource must not already
    ** exist.
    **
    ** If activity creation is succesful, the state of the resource
    ** object is updated appropriately.
    **
    ** This hook is optional; if the provider does not support activities,
    ** it should be set to NULL.
    */
    dav_error * (*make_activity)(dav_resource *resource);
};