Reorganize the output to "svnserve --help".
[svn.git] / subversion / mod_dav_svn / reports / dated-rev.c
blobacdeeb6753f268f7c80837954b55aebaa81d53f2
1 /*
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>
20 #include <apr_uuid.h>
22 #include <httpd.h>
23 #include <http_log.h>
24 #include <mod_dav.h>
26 #include "svn_fs.h"
27 #include "svn_xml.h"
28 #include "svn_repos.h"
29 #include "svn_dav.h"
30 #include "svn_time.h"
31 #include "svn_pools.h"
32 #include "svn_props.h"
33 #include "svn_dav.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
44 * as of that date. */
45 dav_error *
46 dav_svn__dated_rev_report(const dav_resource *resource,
47 const apr_xml_doc *doc,
48 ap_filter_t *output)
50 apr_xml_elem *child;
51 int ns;
52 apr_time_t tm = (apr_time_t) -1;
53 svn_revnum_t rev;
54 apr_bucket_brigade *bb;
55 svn_error_t *err;
56 apr_status_t apr_err;
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:");
61 if (ns != -1)
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)
67 continue;
68 /* If this fails, we'll notice below, so ignore any error for now. */
69 svn_error_clear
70 (svn_time_from_cstring(&tm, dav_xml_get_cdata(child,
71 resource->pool, 1),
72 resource->pool));
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)
87 svn_error_clear(err);
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);
99 if (apr_err)
100 derr = dav_svn__convert_err(svn_error_create(apr_err, 0, NULL),
101 HTTP_INTERNAL_SERVER_ERROR,
102 "Error writing REPORT response.",
103 resource->pool);
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.",
111 resource->pool);
113 return derr;