]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_ra_serf/get_deleted_rev.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / libsvn_ra_serf / get_deleted_rev.c
1 /*
2  * get_deleted_rev.c :  ra_serf get_deleted_rev API implementation.
3  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24 \f
25 #include "svn_ra.h"
26 #include "svn_xml.h"
27 #include "svn_path.h"
28 #include "svn_private_config.h"
29
30 #include "../libsvn_ra/ra_loader.h"
31
32 #include "ra_serf.h"
33 \f
34
35 /*
36  * This enum represents the current state of our XML parsing for a REPORT.
37  */
38 enum drev_state_e {
39   INITIAL = 0,
40   REPORT,
41   VERSION_NAME
42 };
43
44 typedef struct drev_context_t {
45   const char *path;
46   svn_revnum_t peg_revision;
47   svn_revnum_t end_revision;
48
49   /* What revision was PATH@PEG_REVISION first deleted within
50      the range PEG_REVISION-END-END_REVISION? */
51   svn_revnum_t *revision_deleted;
52
53 } drev_context_t;
54
55 #define D_ "DAV:"
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 },
60
61   { REPORT, D_, SVN_DAV__VERSION_NAME, VERSION_NAME,
62     TRUE, { NULL }, TRUE },
63
64   { 0 }
65 };
66
67 \f
68 /* Conforms to svn_ra_serf__xml_closed_t  */
69 static svn_error_t *
70 getdrev_closed(svn_ra_serf__xml_estate_t *xes,
71                void *baton,
72                int leaving_state,
73                const svn_string_t *cdata,
74                apr_hash_t *attrs,
75                apr_pool_t *scratch_pool)
76 {
77   drev_context_t *drev_ctx = baton;
78
79   SVN_ERR_ASSERT(leaving_state == VERSION_NAME);
80   SVN_ERR_ASSERT(cdata != NULL);
81
82   *drev_ctx->revision_deleted = SVN_STR_TO_REV(cdata->data);
83
84   return SVN_NO_ERROR;
85 }
86
87
88 /* Implements svn_ra_serf__request_body_delegate_t */
89 static svn_error_t *
90 create_getdrev_body(serf_bucket_t **body_bkt,
91                     void *baton,
92                     serf_bucket_alloc_t *alloc,
93                     apr_pool_t *pool)
94 {
95   serf_bucket_t *buckets;
96   drev_context_t *drev_ctx = baton;
97
98   buckets = serf_bucket_aggregate_create(alloc);
99
100   svn_ra_serf__add_open_tag_buckets(buckets, alloc,
101                                     "S:get-deleted-rev-report",
102                                     "xmlns:S", SVN_XML_NAMESPACE,
103                                     "xmlns:D", "DAV:",
104                                     NULL, NULL);
105
106   svn_ra_serf__add_tag_buckets(buckets,
107                                "S:path", drev_ctx->path,
108                                alloc);
109
110   svn_ra_serf__add_tag_buckets(buckets,
111                                "S:peg-revision",
112                                apr_ltoa(pool, drev_ctx->peg_revision),
113                                alloc);
114
115   svn_ra_serf__add_tag_buckets(buckets,
116                                "S:end-revision",
117                                apr_ltoa(pool, drev_ctx->end_revision),
118                                alloc);
119
120   svn_ra_serf__add_close_tag_buckets(buckets, alloc,
121                                      "S:get-deleted-rev-report");
122
123   *body_bkt = buckets;
124   return SVN_NO_ERROR;
125 }
126
127 svn_error_t *
128 svn_ra_serf__get_deleted_rev(svn_ra_session_t *session,
129                              const char *path,
130                              svn_revnum_t peg_revision,
131                              svn_revnum_t end_revision,
132                              svn_revnum_t *revision_deleted,
133                              apr_pool_t *pool)
134 {
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;
139   const char *req_url;
140   svn_error_t *err;
141
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;
147
148   SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
149                                       ras, NULL /* conn */,
150                                       NULL /* url */, peg_revision,
151                                       pool, pool));
152
153   xmlctx = svn_ra_serf__xml_context_create(getdrev_ttable,
154                                            NULL, getdrev_closed, NULL,
155                                            drev_ctx,
156                                            pool);
157   handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
158
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;
166
167   err = svn_ra_serf__context_run_one(handler, pool);
168
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"),
174                              "get-deleted-rev");
175   SVN_ERR(err);
176
177   return SVN_NO_ERROR;
178 }