2 * getdate.c : entry point for get_dated_revision for ra_serf
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
29 #include "svn_pools.h"
34 #include "private/svn_dav_protocol.h"
36 #include "svn_private_config.h"
38 #include "../libsvn_ra/ra_loader.h"
44 * This enum represents the current state of our XML parsing for a REPORT.
47 INITIAL = XML_STATE_INITIAL,
53 typedef struct date_context_t {
54 /* The time asked about. */
57 /* What was the youngest revision at that time? */
58 svn_revnum_t *revision;
63 #define S_ SVN_XML_NAMESPACE
64 static const svn_ra_serf__xml_transition_t date_ttable[] = {
65 { INITIAL, S_, "dated-rev-report", REPORT,
66 FALSE, { NULL }, FALSE },
68 { REPORT, D_, SVN_DAV__VERSION_NAME, VERSION_NAME,
69 TRUE, { NULL }, TRUE },
75 /* Conforms to svn_ra_serf__xml_closed_t */
77 date_closed(svn_ra_serf__xml_estate_t *xes,
80 const svn_string_t *cdata,
82 apr_pool_t *scratch_pool)
84 date_context_t *date_ctx = baton;
87 SVN_ERR_ASSERT(leaving_state == VERSION_NAME);
88 SVN_ERR_ASSERT(cdata != NULL);
90 SVN_ERR(svn_cstring_atoi64(&rev, cdata->data));
92 *date_ctx->revision = (svn_revnum_t)rev;
98 /* Implements svn_ra_serf__request_body_delegate_t */
100 create_getdate_body(serf_bucket_t **body_bkt,
102 serf_bucket_alloc_t *alloc,
103 apr_pool_t *pool /* request pool */,
104 apr_pool_t *scratch_pool)
106 serf_bucket_t *buckets;
107 date_context_t *date_ctx = baton;
109 buckets = serf_bucket_aggregate_create(alloc);
111 svn_ra_serf__add_open_tag_buckets(buckets, alloc, "S:dated-rev-report",
112 "xmlns:S", SVN_XML_NAMESPACE,
116 svn_ra_serf__add_tag_buckets(buckets,
117 "D:" SVN_DAV__CREATIONDATE,
118 svn_time_to_cstring(date_ctx->time, pool),
121 svn_ra_serf__add_close_tag_buckets(buckets, alloc, "S:dated-rev-report");
128 svn_ra_serf__get_dated_revision(svn_ra_session_t *ra_session,
129 svn_revnum_t *revision,
133 date_context_t *date_ctx;
134 svn_ra_serf__session_t *session = ra_session->priv;
135 svn_ra_serf__handler_t *handler;
136 svn_ra_serf__xml_context_t *xmlctx;
137 const char *report_target;
139 date_ctx = apr_palloc(pool, sizeof(*date_ctx));
141 date_ctx->revision = revision;
143 SVN_ERR(svn_ra_serf__report_resource(&report_target, session, pool));
145 xmlctx = svn_ra_serf__xml_context_create(date_ttable,
146 NULL, date_closed, NULL,
149 handler = svn_ra_serf__create_expat_handler(session, xmlctx, NULL, pool);
151 handler->method = "REPORT";
152 handler->path = report_target;
153 handler->body_type = "text/xml";
155 handler->body_delegate = create_getdate_body;
156 handler->body_delegate_baton = date_ctx;
158 *date_ctx->revision = SVN_INVALID_REVNUM;
160 SVN_ERR(svn_ra_serf__context_run_one(handler, pool));
162 if (handler->sline.code != 200)
163 return svn_error_trace(svn_ra_serf__unexpected_status(handler));
165 if (!SVN_IS_VALID_REVNUM(*revision))
166 return svn_error_create(SVN_ERR_RA_DAV_PROPS_NOT_FOUND, NULL,
167 _("The REPORT response did not include "
168 "the requested properties"));