2 * list.c : entry point for the list RA function in 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 * ====================================================================
31 #include "svn_pools.h"
34 #include "svn_base64.h"
36 #include "svn_config.h"
38 #include "svn_props.h"
41 #include "private/svn_dav_protocol.h"
42 #include "private/svn_string_private.h"
43 #include "private/svn_subr_private.h"
44 #include "svn_private_config.h"
47 #include "../libsvn_ra/ra_loader.h"
52 * This enum represents the current state of our XML parsing for a REPORT.
55 INITIAL = XML_STATE_INITIAL,
61 typedef struct list_context_t {
64 /* parameters set by our caller */
66 svn_revnum_t revision;
67 const apr_array_header_t *patterns;
69 apr_uint32_t dirent_fields;
70 apr_array_header_t *props;
72 /* Buffer the author info for the current item.
73 * We use the AUTHOR pointer to differentiate between 0-length author
74 * strings and missing / NULL authors. */
76 svn_stringbuf_t *author_buf;
78 /* log receiver function and baton */
79 svn_ra_dirent_receiver_t receiver;
84 #define S_ SVN_XML_NAMESPACE
85 static const svn_ra_serf__xml_transition_t log_ttable[] = {
86 { INITIAL, S_, "list-report", REPORT,
87 FALSE, { NULL }, FALSE },
89 { REPORT, S_, "item", ITEM,
90 TRUE, { "node-kind", "?size", "?has-props", "?created-rev",
91 "?date", NULL }, TRUE },
93 { ITEM, D_, "creator-displayname", AUTHOR,
94 TRUE, { "?encoding", NULL }, TRUE },
99 /* Conforms to svn_ra_serf__xml_closed_t */
101 item_closed(svn_ra_serf__xml_estate_t *xes,
104 const svn_string_t *cdata,
106 apr_pool_t *scratch_pool)
108 list_context_t *list_ctx = baton;
110 if (leaving_state == AUTHOR)
112 /* For compatibility with liveprops, current servers will not use
113 * base64-encoding for "binary" user names bu simply drop the
114 * offending control chars.
116 * We might want to switch to revprop-style encoding, though,
117 * and this is the code to do that. */
118 const char *encoding = svn_hash_gets(attrs, "encoding");
121 /* Check for a known encoding type. This is easy -- there's
123 if (strcmp(encoding, "base64") != 0)
125 return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
126 _("Unsupported encoding '%s'"),
130 cdata = svn_base64_decode_string(cdata, scratch_pool);
133 /* Remember until the next ITEM closing tag. */
134 svn_stringbuf_set(list_ctx->author_buf, cdata->data);
135 list_ctx->author = list_ctx->author_buf->data;
137 else if (leaving_state == ITEM)
139 const char *dirent_path = cdata->data;
140 const char *kind_word, *date, *crev, *size;
141 svn_dirent_t dirent = { 0 };
143 kind_word = svn_hash_gets(attrs, "node-kind");
144 size = svn_hash_gets(attrs, "size");
146 dirent.has_props = svn_hash__get_bool(attrs, "has-props", FALSE);
147 crev = svn_hash_gets(attrs, "created-rev");
148 date = svn_hash_gets(attrs, "date");
151 dirent.kind = svn_node_kind_from_word(kind_word);
154 SVN_ERR(svn_cstring_atoi64(&dirent.size, size));
156 dirent.size = SVN_INVALID_FILESIZE;
159 SVN_ERR(svn_revnum_parse(&dirent.created_rev, crev, NULL));
161 dirent.created_rev = SVN_INVALID_REVNUM;
164 SVN_ERR(svn_time_from_cstring(&dirent.time, date, scratch_pool));
166 if (list_ctx->author)
167 dirent.last_author = list_ctx->author;
169 /* Invoke RECEIVER */
170 SVN_ERR(list_ctx->receiver(dirent_path, &dirent,
171 list_ctx->receiver_baton, scratch_pool));
173 /* Reset buffered info. */
174 list_ctx->author = NULL;
180 /* Implements svn_ra_serf__request_body_delegate_t */
182 create_list_body(serf_bucket_t **body_bkt,
184 serf_bucket_alloc_t *alloc,
185 apr_pool_t *pool /* request pool */,
186 apr_pool_t *scratch_pool)
188 serf_bucket_t *buckets;
189 list_context_t *list_ctx = baton;
192 buckets = serf_bucket_aggregate_create(alloc);
194 svn_ra_serf__add_open_tag_buckets(buckets, alloc,
196 "xmlns:S", SVN_XML_NAMESPACE,
199 svn_ra_serf__add_tag_buckets(buckets,
200 "S:path", list_ctx->path,
202 svn_ra_serf__add_tag_buckets(buckets,
204 apr_ltoa(pool, list_ctx->revision),
206 svn_ra_serf__add_tag_buckets(buckets,
207 "S:depth", svn_depth_to_word(list_ctx->depth),
210 if (list_ctx->patterns)
212 for (i = 0; i < list_ctx->patterns->nelts; i++)
214 char *name = APR_ARRAY_IDX(list_ctx->patterns, i, char *);
215 svn_ra_serf__add_tag_buckets(buckets,
219 if (list_ctx->patterns->nelts == 0)
221 svn_ra_serf__add_empty_tag_buckets(buckets, alloc,
222 "S:no-patterns", SVN_VA_NULL);
226 for (i = 0; i < list_ctx->props->nelts; i++)
228 const svn_ra_serf__dav_props_t *prop
229 = &APR_ARRAY_IDX(list_ctx->props, i, const svn_ra_serf__dav_props_t);
231 = apr_pstrcat(pool, prop->xmlns, prop->name, SVN_VA_NULL);
233 svn_ra_serf__add_tag_buckets(buckets, "S:prop", name, alloc);
236 svn_ra_serf__add_close_tag_buckets(buckets, alloc,
245 svn_ra_serf__list(svn_ra_session_t *ra_session,
247 svn_revnum_t revision,
248 const apr_array_header_t *patterns,
250 apr_uint32_t dirent_fields,
251 svn_ra_dirent_receiver_t receiver,
252 void *receiver_baton,
253 apr_pool_t *scratch_pool)
255 list_context_t *list_ctx;
256 svn_ra_serf__session_t *session = ra_session->priv;
257 svn_ra_serf__handler_t *handler;
258 svn_ra_serf__xml_context_t *xmlctx;
261 list_ctx = apr_pcalloc(scratch_pool, sizeof(*list_ctx));
262 list_ctx->pool = scratch_pool;
263 list_ctx->receiver = receiver;
264 list_ctx->receiver_baton = receiver_baton;
265 list_ctx->path = path;
266 list_ctx->revision = revision;
267 list_ctx->patterns = patterns;
268 list_ctx->depth = depth;
269 list_ctx->dirent_fields = dirent_fields;
270 list_ctx->props = svn_ra_serf__get_dirent_props(dirent_fields, session,
272 list_ctx->author_buf = svn_stringbuf_create_empty(scratch_pool);
274 /* At this point, we may have a deleted file. So, we'll match ra_neon's
275 * behavior and use the larger of start or end as our 'peg' rev.
277 SVN_ERR(svn_ra_serf__get_stable_url(&req_url, NULL /* latest_revnum */,
279 NULL /* url */, revision,
280 scratch_pool, scratch_pool));
282 xmlctx = svn_ra_serf__xml_context_create(log_ttable,
283 NULL, item_closed, NULL,
286 handler = svn_ra_serf__create_expat_handler(session, xmlctx, NULL,
289 handler->method = "REPORT";
290 handler->path = req_url;
291 handler->body_delegate = create_list_body;
292 handler->body_delegate_baton = list_ctx;
293 handler->body_type = "text/xml";
295 SVN_ERR(svn_ra_serf__context_run_one(handler, scratch_pool));
297 if (handler->sline.code != 200)
298 SVN_ERR(svn_ra_serf__unexpected_status(handler));