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.
39 INITIAL = XML_STATE_INITIAL,
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;
80 SVN_ERR_ASSERT(leaving_state == VERSION_NAME);
81 SVN_ERR_ASSERT(cdata != NULL);
83 SVN_ERR(svn_cstring_atoi64(&rev, cdata->data));
84 *drev_ctx->revision_deleted = (svn_revnum_t)rev;
90 /* Implements svn_ra_serf__request_body_delegate_t */
92 create_getdrev_body(serf_bucket_t **body_bkt,
94 serf_bucket_alloc_t *alloc,
95 apr_pool_t *pool /* request pool */,
96 apr_pool_t *scratch_pool)
98 serf_bucket_t *buckets;
99 drev_context_t *drev_ctx = baton;
101 buckets = serf_bucket_aggregate_create(alloc);
103 svn_ra_serf__add_open_tag_buckets(buckets, alloc,
104 "S:get-deleted-rev-report",
105 "xmlns:S", SVN_XML_NAMESPACE,
109 svn_ra_serf__add_tag_buckets(buckets,
110 "S:path", drev_ctx->path,
113 svn_ra_serf__add_tag_buckets(buckets,
115 apr_ltoa(pool, drev_ctx->peg_revision),
118 svn_ra_serf__add_tag_buckets(buckets,
120 apr_ltoa(pool, drev_ctx->end_revision),
123 svn_ra_serf__add_close_tag_buckets(buckets, alloc,
124 "S:get-deleted-rev-report");
131 svn_ra_serf__get_deleted_rev(svn_ra_session_t *session,
133 svn_revnum_t peg_revision,
134 svn_revnum_t end_revision,
135 svn_revnum_t *revision_deleted,
138 drev_context_t *drev_ctx;
139 svn_ra_serf__session_t *ras = session->priv;
140 svn_ra_serf__handler_t *handler;
141 svn_ra_serf__xml_context_t *xmlctx;
145 drev_ctx = apr_pcalloc(pool, sizeof(*drev_ctx));
146 drev_ctx->path = path;
147 drev_ctx->peg_revision = peg_revision;
148 drev_ctx->end_revision = end_revision;
149 drev_ctx->revision_deleted = revision_deleted;
151 SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
152 ras, NULL /* url */, peg_revision,
155 xmlctx = svn_ra_serf__xml_context_create(getdrev_ttable,
156 NULL, getdrev_closed, NULL,
159 handler = svn_ra_serf__create_expat_handler(ras, xmlctx, NULL, pool);
161 handler->method = "REPORT";
162 handler->path = req_url;
163 handler->body_type = "text/xml";
164 handler->body_delegate = create_getdrev_body;
165 handler->body_delegate_baton = drev_ctx;
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"),