2 * getlocationsegments.c : entry point for get_location_segments
3 * RA functions for ra_serf
5 * ====================================================================
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
22 * ====================================================================
31 #include "svn_pools.h"
35 #include "svn_private_config.h"
36 #include "../libsvn_ra/ra_loader.h"
42 typedef struct gls_context_t {
43 /* parameters set by our caller */
44 svn_revnum_t peg_revision;
45 svn_revnum_t start_rev;
49 /* location segment callback function/baton */
50 svn_location_segment_receiver_t receiver;
62 #define S_ SVN_XML_NAMESPACE
63 static const svn_ra_serf__xml_transition_t gls_ttable[] = {
64 { INITIAL, S_, "get-location-segments-report", REPORT,
65 FALSE, { NULL }, FALSE },
67 { REPORT, S_, "location-segment", SEGMENT,
68 FALSE, { "?path", "range-start", "range-end", NULL }, TRUE },
74 /* Conforms to svn_ra_serf__xml_closed_t */
76 gls_closed(svn_ra_serf__xml_estate_t *xes,
79 const svn_string_t *cdata,
81 apr_pool_t *scratch_pool)
83 gls_context_t *gls_ctx = baton;
85 const char *start_str;
87 svn_location_segment_t segment;
89 SVN_ERR_ASSERT(leaving_state == SEGMENT);
91 path = svn_hash_gets(attrs, "path");
92 start_str = svn_hash_gets(attrs, "range-start");
93 end_str = svn_hash_gets(attrs, "range-end");
95 /* The transition table said these must exist. */
96 SVN_ERR_ASSERT(start_str && end_str);
98 segment.path = path; /* may be NULL */
99 segment.range_start = SVN_STR_TO_REV(start_str);
100 segment.range_end = SVN_STR_TO_REV(end_str);
101 SVN_ERR(gls_ctx->receiver(&segment, gls_ctx->receiver_baton, scratch_pool));
107 /* Implements svn_ra_serf__request_body_delegate_t */
109 create_gls_body(serf_bucket_t **body_bkt,
111 serf_bucket_alloc_t *alloc,
114 serf_bucket_t *buckets;
115 gls_context_t *gls_ctx = baton;
117 buckets = serf_bucket_aggregate_create(alloc);
119 svn_ra_serf__add_open_tag_buckets(buckets, alloc,
120 "S:get-location-segments",
121 "xmlns:S", SVN_XML_NAMESPACE,
124 svn_ra_serf__add_tag_buckets(buckets,
125 "S:path", gls_ctx->path,
128 svn_ra_serf__add_tag_buckets(buckets,
130 apr_ltoa(pool, gls_ctx->peg_revision),
133 svn_ra_serf__add_tag_buckets(buckets,
135 apr_ltoa(pool, gls_ctx->start_rev),
138 svn_ra_serf__add_tag_buckets(buckets,
140 apr_ltoa(pool, gls_ctx->end_rev),
143 svn_ra_serf__add_close_tag_buckets(buckets, alloc,
144 "S:get-location-segments");
151 svn_ra_serf__get_location_segments(svn_ra_session_t *ra_session,
153 svn_revnum_t peg_revision,
154 svn_revnum_t start_rev,
155 svn_revnum_t end_rev,
156 svn_location_segment_receiver_t receiver,
157 void *receiver_baton,
160 gls_context_t *gls_ctx;
161 svn_ra_serf__session_t *session = ra_session->priv;
162 svn_ra_serf__handler_t *handler;
163 svn_ra_serf__xml_context_t *xmlctx;
167 gls_ctx = apr_pcalloc(pool, sizeof(*gls_ctx));
168 gls_ctx->path = path;
169 gls_ctx->peg_revision = peg_revision;
170 gls_ctx->start_rev = start_rev;
171 gls_ctx->end_rev = end_rev;
172 gls_ctx->receiver = receiver;
173 gls_ctx->receiver_baton = receiver_baton;
175 SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
176 session, NULL /* conn */,
177 NULL /* url */, peg_revision,
180 xmlctx = svn_ra_serf__xml_context_create(gls_ttable,
181 NULL, gls_closed, NULL,
184 handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
186 handler->method = "REPORT";
187 handler->path = req_url;
188 handler->body_delegate = create_gls_body;
189 handler->body_delegate_baton = gls_ctx;
190 handler->body_type = "text/xml";
191 handler->conn = session->conns[0];
192 handler->session = session;
194 err = svn_ra_serf__context_run_one(handler, pool);
196 err = svn_error_compose_create(
197 svn_ra_serf__error_on_status(handler->sline,
202 if (err && (err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))
203 return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, err, NULL);
205 return svn_error_trace(err);