2 * mergeinfo.c : entry point for mergeinfo RA functions 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 * ====================================================================
24 #include <apr_tables.h>
28 #include "svn_mergeinfo.h"
31 #include "svn_string.h"
34 #include "private/svn_dav_protocol.h"
35 #include "../libsvn_ra/ra_loader.h"
36 #include "svn_private_config.h"
42 /* The current state of our XML parsing. */
43 typedef enum mergeinfo_state_e {
51 /* Baton for accumulating mergeinfo. RESULT_CATALOG stores the final
52 mergeinfo catalog result we are going to hand back to the caller of
54 typedef struct mergeinfo_context_t {
56 svn_mergeinfo_t result_catalog;
57 const apr_array_header_t *paths;
58 svn_revnum_t revision;
59 svn_mergeinfo_inheritance_t inherit;
60 svn_boolean_t include_descendants;
61 } mergeinfo_context_t;
65 #define S_ SVN_XML_NAMESPACE
66 static const svn_ra_serf__xml_transition_t mergeinfo_ttable[] = {
67 { INITIAL, S_, SVN_DAV__MERGEINFO_REPORT, MERGEINFO_REPORT,
68 FALSE, { NULL }, FALSE },
70 { MERGEINFO_REPORT, S_, SVN_DAV__MERGEINFO_ITEM, MERGEINFO_ITEM,
71 FALSE, { NULL }, TRUE },
73 { MERGEINFO_ITEM, S_, SVN_DAV__MERGEINFO_PATH, MERGEINFO_PATH,
74 TRUE, { NULL }, TRUE },
76 { MERGEINFO_ITEM, S_, SVN_DAV__MERGEINFO_INFO, MERGEINFO_INFO,
77 TRUE, { NULL }, TRUE },
83 /* Conforms to svn_ra_serf__xml_closed_t */
85 mergeinfo_closed(svn_ra_serf__xml_estate_t *xes,
88 const svn_string_t *cdata,
90 apr_pool_t *scratch_pool)
92 mergeinfo_context_t *mergeinfo_ctx = baton;
94 if (leaving_state == MERGEINFO_ITEM)
96 /* Placed here from the child elements. */
97 const char *path = svn_hash_gets(attrs, "path");
98 const char *info = svn_hash_gets(attrs, "info");
100 if (path != NULL && info != NULL)
102 svn_mergeinfo_t path_mergeinfo;
104 /* Correct for naughty servers that send "relative" paths
105 with leading slashes! */
109 SVN_ERR(svn_mergeinfo_parse(&path_mergeinfo, info,
110 mergeinfo_ctx->pool));
112 svn_hash_sets(mergeinfo_ctx->result_catalog,
113 apr_pstrdup(mergeinfo_ctx->pool, path),
119 SVN_ERR_ASSERT(leaving_state == MERGEINFO_PATH
120 || leaving_state == MERGEINFO_INFO);
122 /* Stash the value onto the parent MERGEINFO_ITEM. */
123 svn_ra_serf__xml_note(xes, MERGEINFO_ITEM,
124 leaving_state == MERGEINFO_PATH
135 create_mergeinfo_body(serf_bucket_t **bkt,
137 serf_bucket_alloc_t *alloc,
140 mergeinfo_context_t *mergeinfo_ctx = baton;
141 serf_bucket_t *body_bkt;
143 body_bkt = serf_bucket_aggregate_create(alloc);
145 svn_ra_serf__add_open_tag_buckets(body_bkt, alloc,
146 "S:" SVN_DAV__MERGEINFO_REPORT,
147 "xmlns:S", SVN_XML_NAMESPACE,
150 svn_ra_serf__add_tag_buckets(body_bkt,
151 "S:" SVN_DAV__REVISION,
152 apr_ltoa(pool, mergeinfo_ctx->revision),
154 svn_ra_serf__add_tag_buckets(body_bkt, "S:" SVN_DAV__INHERIT,
155 svn_inheritance_to_word(mergeinfo_ctx->inherit),
157 if (mergeinfo_ctx->include_descendants)
159 svn_ra_serf__add_tag_buckets(body_bkt, "S:"
160 SVN_DAV__INCLUDE_DESCENDANTS,
164 if (mergeinfo_ctx->paths)
168 for (i = 0; i < mergeinfo_ctx->paths->nelts; i++)
170 const char *this_path = APR_ARRAY_IDX(mergeinfo_ctx->paths,
173 svn_ra_serf__add_tag_buckets(body_bkt, "S:" SVN_DAV__PATH,
178 svn_ra_serf__add_close_tag_buckets(body_bkt, alloc,
179 "S:" SVN_DAV__MERGEINFO_REPORT);
186 svn_ra_serf__get_mergeinfo(svn_ra_session_t *ra_session,
187 svn_mergeinfo_catalog_t *catalog,
188 const apr_array_header_t *paths,
189 svn_revnum_t revision,
190 svn_mergeinfo_inheritance_t inherit,
191 svn_boolean_t include_descendants,
195 mergeinfo_context_t *mergeinfo_ctx;
196 svn_ra_serf__session_t *session = ra_session->priv;
197 svn_ra_serf__handler_t *handler;
198 svn_ra_serf__xml_context_t *xmlctx;
203 SVN_ERR(svn_ra_serf__get_stable_url(&path, NULL /* latest_revnum */,
204 session, NULL /* conn */,
205 NULL /* url */, revision,
208 mergeinfo_ctx = apr_pcalloc(pool, sizeof(*mergeinfo_ctx));
209 mergeinfo_ctx->pool = pool;
210 mergeinfo_ctx->result_catalog = apr_hash_make(pool);
211 mergeinfo_ctx->paths = paths;
212 mergeinfo_ctx->revision = revision;
213 mergeinfo_ctx->inherit = inherit;
214 mergeinfo_ctx->include_descendants = include_descendants;
216 xmlctx = svn_ra_serf__xml_context_create(mergeinfo_ttable,
217 NULL, mergeinfo_closed, NULL,
220 handler = svn_ra_serf__create_expat_handler(xmlctx, pool);
222 handler->method = "REPORT";
223 handler->path = path;
224 handler->conn = session->conns[0];
225 handler->session = session;
226 handler->body_delegate = create_mergeinfo_body;
227 handler->body_delegate_baton = mergeinfo_ctx;
228 handler->body_type = "text/xml";
230 err = svn_ra_serf__context_run_one(handler, pool);
232 SVN_ERR(svn_error_compose_create(
233 svn_ra_serf__error_on_status(handler->sline, handler->path,
237 if (handler->done && apr_hash_count(mergeinfo_ctx->result_catalog))
238 *catalog = mergeinfo_ctx->result_catalog;