2 * get_deleted_rev.c : ra_serf get_deleted_rev API implementation.
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 * ====================================================================
28 #include "svn_private_config.h"
30 #include "../libsvn_ra/ra_loader.h"
36 * This enum represents the current state of our XML parsing for a REPORT.
44 typedef struct drev_context_t {
46 svn_revnum_t peg_revision;
47 svn_revnum_t end_revision;
49 /* What revision was PATH@PEG_REVISION first deleted within
50 the range PEG_REVISION-END-END_REVISION? */
51 svn_revnum_t *revision_deleted;
56 #define S_ SVN_XML_NAMESPACE
57 static const svn_ra_serf__xml_transition_t getdrev_ttable[] = {
58 { INITIAL, S_, "get-deleted-rev-report", REPORT,
59 FALSE, { NULL }, FALSE },
61 { REPORT, D_, SVN_DAV__VERSION_NAME, VERSION_NAME,
62 TRUE, { NULL }, TRUE },
68 /* Conforms to svn_ra_serf__xml_closed_t */
70 getdrev_closed(svn_ra_serf__xml_estate_t *xes,
73 const svn_string_t *cdata,
75 apr_pool_t *scratch_pool)
77 drev_context_t *drev_ctx = baton;
79 SVN_ERR_ASSERT(leaving_state == VERSION_NAME);
80 SVN_ERR_ASSERT(cdata != NULL);
82 *drev_ctx->revision_deleted = SVN_STR_TO_REV(cdata->data);
88 /* Implements svn_ra_serf__request_body_delegate_t */
90 create_getdrev_body(serf_bucket_t **body_bkt,
92 serf_bucket_alloc_t *alloc,
95 serf_bucket_t *buckets;
96 drev_context_t *drev_ctx = baton;
98 buckets = serf_bucket_aggregate_create(alloc);
100 svn_ra_serf__add_open_tag_buckets(buckets, alloc,
101 "S:get-deleted-rev-report",
102 "xmlns:S", SVN_XML_NAMESPACE,
106 svn_ra_serf__add_tag_buckets(buckets,
107 "S:path", drev_ctx->path,
110 svn_ra_serf__add_tag_buckets(buckets,
112 apr_ltoa(pool, drev_ctx->peg_revision),
115 svn_ra_serf__add_tag_buckets(buckets,
117 apr_ltoa(pool, drev_ctx->end_revision),
120 svn_ra_serf__add_close_tag_buckets(buckets, alloc,
121 "S:get-deleted-rev-report");
128 svn_ra_serf__get_deleted_rev(svn_ra_session_t *session,
130 svn_revnum_t peg_revision,
131 svn_revnum_t end_revision,
132 svn_revnum_t *revision_deleted,
135 drev_context_t *drev_ctx;
136 svn_ra_serf__session_t *ras = session->priv;
137 svn_ra_serf__handler_t *handler;
138 svn_ra_serf__xml_context_t *xmlctx;
142 drev_ctx = apr_pcalloc(pool, sizeof(*drev_ctx));
143 drev_ctx->path = path;
144 drev_ctx->peg_revision = peg_revision;
145 drev_ctx->end_revision = end_revision;
146 drev_ctx->revision_deleted = revision_deleted;
148 SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
149 ras, NULL /* conn */,
150 NULL /* url */, peg_revision,
153 xmlctx = svn_ra_serf__xml_context_create(getdrev_ttable,
154 NULL, getdrev_closed, NULL,
157 handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
159 handler->method = "REPORT";
160 handler->path = req_url;
161 handler->body_type = "text/xml";
162 handler->body_delegate = create_getdrev_body;
163 handler->body_delegate_baton = drev_ctx;
164 handler->conn = ras->conns[0];
165 handler->session = ras;
167 err = svn_ra_serf__context_run_one(handler, pool);
169 /* Map status 501: Method Not Implemented to our not implemented error.
170 1.5.x servers and older don't support this report. */
171 if (handler->sline.code == 501)
172 return svn_error_createf(SVN_ERR_RA_NOT_IMPLEMENTED, err,
173 _("'%s' REPORT not implemented"),