2 * version.c: mod_dav_svn versioning provider functions for Subversion
4 * ====================================================================
5 * Copyright (c) 2000-2006 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 #include <apr_tables.h>
28 #include "svn_repos.h"
31 #include "svn_pools.h"
32 #include "svn_props.h"
34 #include "svn_base64.h"
36 #include "private/svn_dav_protocol.h"
38 #include "../dav_svn.h"
41 /* Respond to a S:dated-rev-report request. The request contains a
42 * DAV:creationdate element giving the requested date; the response
43 * contains a DAV:version-name element giving the most recent revision
46 dav_svn__dated_rev_report(const dav_resource
*resource
,
47 const apr_xml_doc
*doc
,
52 apr_time_t tm
= (apr_time_t
) -1;
54 apr_bucket_brigade
*bb
;
57 dav_error
*derr
= NULL
;
59 /* Find the DAV:creationdate element and get the requested time from it. */
60 ns
= dav_svn__find_ns(doc
->namespaces
, "DAV:");
63 for (child
= doc
->root
->first_child
; child
!= NULL
; child
= child
->next
)
65 if (child
->ns
!= ns
||
66 strcmp(child
->name
, SVN_DAV__CREATIONDATE
) != 0)
68 /* If this fails, we'll notice below, so ignore any error for now. */
70 (svn_time_from_cstring(&tm
, dav_xml_get_cdata(child
,
76 if (tm
== (apr_time_t
) -1)
78 return dav_new_error(resource
->pool
, HTTP_BAD_REQUEST
, 0,
79 "The request does not contain a valid "
80 "'DAV:" SVN_DAV__CREATIONDATE
"' element.");
83 /* Do the actual work of finding the revision by date. */
84 if ((err
= svn_repos_dated_revision(&rev
, resource
->info
->repos
->repos
, tm
,
85 resource
->pool
)) != SVN_NO_ERROR
)
88 return dav_new_error(resource
->pool
, HTTP_INTERNAL_SERVER_ERROR
, 0,
89 "Could not access revision times.");
92 bb
= apr_brigade_create(resource
->pool
, output
->c
->bucket_alloc
);
93 apr_err
= ap_fprintf(output
, bb
,
94 DAV_XML_HEADER DEBUG_CR
95 "<S:dated-rev-report xmlns:S=\"" SVN_XML_NAMESPACE
"\" "
96 "xmlns:D=\"DAV:\">" DEBUG_CR
97 "<D:" SVN_DAV__VERSION_NAME
">%ld</D:"
98 SVN_DAV__VERSION_NAME
">""</S:dated-rev-report>", rev
);
100 derr
= dav_svn__convert_err(svn_error_create(apr_err
, 0, NULL
),
101 HTTP_INTERNAL_SERVER_ERROR
,
102 "Error writing REPORT response.",
105 /* Flush the contents of the brigade (returning an error only if we
106 don't already have one). */
107 if (((apr_err
= ap_fflush(output
, bb
))) && (! derr
))
108 derr
= dav_svn__convert_err(svn_error_create(apr_err
, 0, NULL
),
109 HTTP_INTERNAL_SERVER_ERROR
,
110 "Error flushing brigade.",