In the command-line client, forbid
[svn.git] / subversion / libsvn_ra_serf / update.c
blob0cad063753d6349d85b5b957105a45f0fcf8b1b8
1 /*
2 * update.c : entry point for update RA functions for ra_serf
4 * ====================================================================
5 * Copyright (c) 2006 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
21 #define APR_WANT_STRFUNC
22 #include <apr_want.h>
24 #include <apr_uri.h>
26 #include <expat.h>
28 #include <serf.h>
30 #include "svn_pools.h"
31 #include "svn_ra.h"
32 #include "svn_dav.h"
33 #include "svn_xml.h"
34 #include "../libsvn_ra/ra_loader.h"
35 #include "svn_config.h"
36 #include "svn_delta.h"
37 #include "svn_version.h"
38 #include "svn_path.h"
39 #include "svn_base64.h"
40 #include "svn_private_config.h"
42 #include "ra_serf.h"
46 * This enum represents the current state of our XML parsing for a REPORT.
48 * A little explanation of how the parsing works. Every time we see
49 * an open-directory tag, we enter the OPEN_DIR state. Likewise, for
50 * add-directory, open-file, etc. When we see the closing variant of the
51 * open-directory tag, we'll 'pop' out of that state.
53 * Each state has a pool associated with it that can have temporary
54 * allocations that will live as long as the tag is opened. Once
55 * the tag is 'closed', the pool will be reused.
57 typedef enum {
58 NONE = 0,
59 OPEN_DIR,
60 ADD_DIR,
61 OPEN_FILE,
62 ADD_FILE,
63 PROP,
64 IGNORE_PROP_NAME,
65 NEED_PROP_NAME,
66 } report_state_e;
68 /* Forward-declare our report context. */
69 typedef struct report_context_t report_context_t;
72 * This structure represents the information for a directory.
74 typedef struct report_dir_t
76 /* Our parent directory.
78 * This value is NULL when we are the root.
80 struct report_dir_t *parent_dir;
82 apr_pool_t *pool;
84 /* Pointer back to our original report context. */
85 report_context_t *report_context;
87 /* Our name sans any parents. */
88 const char *base_name;
90 /* the expanded directory name (including all parent names) */
91 const char *name;
93 /* temporary path buffer for this directory. */
94 svn_stringbuf_t *name_buf;
96 /* the canonical url for this directory. */
97 const char *url;
99 /* Our base revision - SVN_INVALID_REVNUM if we're adding this dir. */
100 svn_revnum_t base_rev;
102 /* The target revision we're retrieving. */
103 svn_revnum_t target_rev;
105 /* controlling dir baton - this is only created in open_dir() */
106 void *dir_baton;
107 apr_pool_t *dir_baton_pool;
109 /* Our master update editor and baton. */
110 const svn_delta_editor_t *update_editor;
111 void *update_baton;
113 /* How many references to this directory do we still have open? */
114 apr_size_t ref_count;
116 /* Namespace list allocated out of this ->pool. */
117 svn_ra_serf__ns_t *ns_list;
119 /* hashtable for all of the properties (shared within a dir) */
120 apr_hash_t *props;
122 /* hashtable for all to-be-removed properties (shared within a dir) */
123 apr_hash_t *removed_props;
125 /* The propfind request for our current directory */
126 svn_ra_serf__propfind_context_t *propfind;
128 /* Has the server told us to fetch the dir props? */
129 svn_boolean_t fetch_props;
131 /* Have we closed the directory tag (meaning no more additions)? */
132 svn_boolean_t tag_closed;
134 /* The children of this directory */
135 struct report_dir_t *children;
137 /* The next sibling of this directory */
138 struct report_dir_t *sibling;
139 } report_dir_t;
142 * This structure represents the information for a file.
144 * A directory may have a report_info_t associated with it as well.
146 * This structure is created as we parse the REPORT response and
147 * once the element is completed, we create a report_fetch_t structure
148 * to give to serf to retrieve this file.
150 typedef struct report_info_t
152 apr_pool_t *pool;
154 /* The enclosing directory.
156 * If this structure refers to a directory, the dir it points to will be
157 * itself.
159 report_dir_t *dir;
161 /* Our name sans any directory info. */
162 const char *base_name;
164 /* the expanded file name (including all parent directory names) */
165 const char *name;
167 /* file name buffer */
168 svn_stringbuf_t *name_buf;
170 /* the canonical url for this file. */
171 const char *url;
173 /* lock token, if we had one to start off with. */
174 const char *lock_token;
176 /* Our base revision - SVN_INVALID_REVNUM if we're adding this file. */
177 svn_revnum_t base_rev;
179 /* The target revision we're retrieving. */
180 svn_revnum_t target_rev;
182 /* our delta base, if present (NULL if we're adding the file) */
183 const svn_string_t *delta_base;
185 /* Path of original item if add with history */
186 const char *copyfrom_path;
188 /* Revision of original item if add with history */
189 svn_revnum_t copyfrom_rev;
191 /* The propfind request for our current file (if present) */
192 svn_ra_serf__propfind_context_t *propfind;
194 /* Has the server told us to fetch the file props? */
195 svn_boolean_t fetch_props;
197 /* Has the server told us to go fetch - only valid if we had it already */
198 svn_boolean_t fetch_file;
200 /* The properties for this file */
201 apr_hash_t *props;
203 /* pool passed to update->add_file, etc. */
204 apr_pool_t *editor_pool;
206 /* controlling file_baton and textdelta handler */
207 void *file_baton;
208 svn_txdelta_window_handler_t textdelta;
209 void *textdelta_baton;
211 /* temporary property for this file which is currently being parsed
212 * It will eventually be stored in our parent directory's property hash.
214 const char *prop_ns;
215 const char *prop_name;
216 const char *prop_val;
217 apr_size_t prop_val_len;
218 const char *prop_encoding;
219 } report_info_t;
222 * This structure represents a single request to GET (fetch) a file with
223 * its associated Serf session/connection.
225 typedef struct report_fetch_t {
226 /* Our pool. */
227 apr_pool_t *pool;
229 /* Non-NULL if we received an error during processing. */
230 svn_error_t *err;
232 /* The session we should use to fetch the file. */
233 svn_ra_serf__session_t *sess;
235 /* The connection we should use to fetch file. */
236 svn_ra_serf__connection_t *conn;
238 /* Stores the information for the file we want to fetch. */
239 report_info_t *info;
241 /* Have we read our response headers yet? */
242 svn_boolean_t read_headers;
244 /* This flag is set when our response is aborted before we reach the
245 * end and we decide to requeue this request.
247 svn_boolean_t aborted_read;
248 apr_off_t aborted_read_size;
250 /* This is the amount of data that we have read so far. */
251 apr_off_t read_size;
253 /* If we're receiving an svndiff, this will be non-NULL. */
254 svn_stream_t *delta_stream;
256 /* If we're writing this file to a stream, this will be non-NULL. */
257 svn_stream_t *target_stream;
259 /* Are we done fetching this file? */
260 svn_boolean_t done;
261 svn_ra_serf__list_t **done_list;
262 svn_ra_serf__list_t done_item;
264 } report_fetch_t;
267 * The master structure for a REPORT request and response.
269 struct report_context_t {
270 apr_pool_t *pool;
272 svn_ra_serf__session_t *sess;
273 svn_ra_serf__connection_t *conn;
275 /* Source path and destination path */
276 const char *source;
277 const char *destination;
279 /* Our update target. */
280 const char *update_target;
282 /* What is the target revision that we want for this REPORT? */
283 svn_revnum_t target_rev;
285 /* Have we been asked to ignore ancestry or textdeltas? */
286 svn_boolean_t ignore_ancestry;
287 svn_boolean_t text_deltas;
289 /* Do we want the server to send copyfrom args or not? */
290 svn_boolean_t send_copyfrom_args;
292 /* Path -> lock token mapping. */
293 apr_hash_t *lock_path_tokens;
295 /* Our master update editor and baton. */
296 const svn_delta_editor_t *update_editor;
297 void *update_baton;
299 /* The request body for the REPORT. */
300 serf_bucket_t *buckets;
302 /* root directory object */
303 report_dir_t *root_dir;
305 /* number of pending GET requests */
306 unsigned int active_fetches;
308 /* completed fetches (contains report_fetch_t) */
309 svn_ra_serf__list_t *done_fetches;
311 /* number of pending PROPFIND requests */
312 unsigned int active_propfinds;
314 /* completed PROPFIND requests (contains propfind_context_t) */
315 svn_ra_serf__list_t *done_propfinds;
317 /* list of files that only have prop changes (contains report_info_t) */
318 svn_ra_serf__list_t *file_propchanges_only;
320 /* The path to the REPORT request */
321 const char *path;
323 /* Are we done parsing the REPORT response? */
324 svn_boolean_t done;
329 /** Report state management helper **/
331 static report_info_t *
332 push_state(svn_ra_serf__xml_parser_t *parser,
333 report_context_t *ctx,
334 report_state_e state)
336 report_info_t *info;
337 apr_pool_t *info_parent_pool;
339 svn_ra_serf__xml_push_state(parser, state);
341 info = parser->state->private;
343 /* Our private pool needs to be disjoint from the state pool. */
344 if (!info)
346 info_parent_pool = ctx->pool;
348 else
350 info_parent_pool = info->pool;
353 if (state == OPEN_DIR || state == ADD_DIR)
355 report_info_t *new_info;
357 new_info = apr_palloc(info_parent_pool, sizeof(*new_info));
358 apr_pool_create(&new_info->pool, info_parent_pool);
359 new_info->lock_token = NULL;
361 new_info->dir = apr_pcalloc(new_info->pool, sizeof(*new_info->dir));
362 new_info->dir->pool = new_info->pool;
364 /* Create the root property tree. */
365 new_info->dir->props = apr_hash_make(new_info->pool);
366 new_info->props = new_info->dir->props;
367 new_info->dir->removed_props = apr_hash_make(new_info->pool);
369 /* Point to the update_editor */
370 new_info->dir->update_editor = ctx->update_editor;
371 new_info->dir->update_baton = ctx->update_baton;
372 new_info->dir->report_context = ctx;
374 if (info)
376 info->dir->ref_count++;
378 new_info->dir->parent_dir = info->dir;
380 /* Point our ns_list at our parents to try to reuse it. */
381 new_info->dir->ns_list = info->dir->ns_list;
383 /* Add ourselves to our parent's list */
384 new_info->dir->sibling = info->dir->children;
385 info->dir->children = new_info->dir;
387 else
389 /* Allow us to be found later. */
390 ctx->root_dir = new_info->dir;
393 parser->state->private = new_info;
395 else if (state == OPEN_FILE || state == ADD_FILE)
397 report_info_t *new_info;
399 new_info = apr_palloc(info_parent_pool, sizeof(*new_info));
400 apr_pool_create(&new_info->pool, info_parent_pool);
401 new_info->file_baton = NULL;
402 new_info->lock_token = NULL;
403 new_info->fetch_file = FALSE;
405 /* Point at our parent's directory state. */
406 new_info->dir = info->dir;
407 info->dir->ref_count++;
409 new_info->props = apr_hash_make(new_info->pool);
411 parser->state->private = new_info;
414 return parser->state->private;
418 /** Wrappers around our various property walkers **/
420 static svn_error_t *
421 set_file_props(void *baton,
422 const char *ns, apr_ssize_t ns_len,
423 const char *name, apr_ssize_t name_len,
424 const svn_string_t *val,
425 apr_pool_t *pool)
427 report_info_t *info = baton;
428 const svn_delta_editor_t *editor = info->dir->update_editor;
430 return svn_ra_serf__set_baton_props(editor->change_file_prop,
431 info->file_baton,
432 ns, ns_len, name, name_len, val, pool);
435 static svn_error_t *
436 set_dir_props(void *baton,
437 const char *ns, apr_ssize_t ns_len,
438 const char *name, apr_ssize_t name_len,
439 const svn_string_t *val,
440 apr_pool_t *pool)
442 report_dir_t *dir = baton;
443 return svn_ra_serf__set_baton_props(dir->update_editor->change_dir_prop,
444 dir->dir_baton,
445 ns, ns_len, name, name_len, val, pool);
448 static svn_error_t *
449 remove_file_props(void *baton,
450 const char *ns, apr_ssize_t ns_len,
451 const char *name, apr_ssize_t name_len,
452 const svn_string_t *val,
453 apr_pool_t *pool)
455 report_info_t *info = baton;
456 const svn_delta_editor_t *editor = info->dir->update_editor;
458 return svn_ra_serf__set_baton_props(editor->change_file_prop,
459 info->file_baton,
460 ns, ns_len, name, name_len, NULL, pool);
463 static svn_error_t *
464 remove_dir_props(void *baton,
465 const char *ns, apr_ssize_t ns_len,
466 const char *name, apr_ssize_t name_len,
467 const svn_string_t *val,
468 apr_pool_t *pool)
470 report_dir_t *dir = baton;
471 return svn_ra_serf__set_baton_props(dir->update_editor->change_dir_prop,
472 dir->dir_baton,
473 ns, ns_len, name, name_len, NULL, pool);
477 /** Helpers to open and close directories */
479 static svn_error_t*
480 open_dir(report_dir_t *dir)
482 /* if we're already open, return now */
483 if (dir->dir_baton)
485 return SVN_NO_ERROR;
488 if (dir->base_name[0] == '\0')
490 apr_pool_create(&dir->dir_baton_pool, dir->pool);
492 if (dir->report_context->destination &&
493 dir->report_context->sess->wc_callbacks->invalidate_wc_props)
495 SVN_ERR(dir->report_context->sess->wc_callbacks->invalidate_wc_props(
496 dir->report_context->sess->wc_callback_baton,
497 dir->report_context->update_target,
498 SVN_RA_SERF__WC_CHECKED_IN_URL, dir->pool));
501 SVN_ERR(dir->update_editor->open_root(dir->update_baton, dir->base_rev,
502 dir->dir_baton_pool,
503 &dir->dir_baton));
505 else
507 SVN_ERR(open_dir(dir->parent_dir));
509 apr_pool_create(&dir->dir_baton_pool, dir->parent_dir->dir_baton_pool);
511 if (SVN_IS_VALID_REVNUM(dir->base_rev))
513 SVN_ERR(dir->update_editor->open_directory(dir->name,
514 dir->parent_dir->dir_baton,
515 dir->base_rev,
516 dir->dir_baton_pool,
517 &dir->dir_baton));
519 else
521 SVN_ERR(dir->update_editor->add_directory(dir->name,
522 dir->parent_dir->dir_baton,
523 NULL, SVN_INVALID_REVNUM,
524 dir->dir_baton_pool,
525 &dir->dir_baton));
529 return SVN_NO_ERROR;
532 static svn_error_t *
533 close_dir(report_dir_t *dir)
535 report_dir_t *prev, *sibling;
537 if (dir->ref_count)
539 abort();
542 svn_ra_serf__walk_all_props(dir->props, dir->base_name, dir->base_rev,
543 set_dir_props, dir, dir->dir_baton_pool);
545 svn_ra_serf__walk_all_props(dir->removed_props, dir->base_name,
546 dir->base_rev, remove_dir_props, dir,
547 dir->dir_baton_pool);
549 if (dir->fetch_props)
551 svn_ra_serf__walk_all_props(dir->props, dir->url, dir->target_rev,
552 set_dir_props, dir, dir->dir_baton_pool);
555 SVN_ERR(dir->update_editor->close_directory(dir->dir_baton,
556 dir->dir_baton_pool));
558 /* remove us from our parent's children list */
559 if (dir->parent_dir)
561 prev = NULL;
562 sibling = dir->parent_dir->children;
564 while (sibling != dir)
566 prev = sibling;
567 sibling = sibling->sibling;
568 if (!sibling)
569 abort();
572 if (!prev)
574 dir->parent_dir->children = dir->sibling;
576 else
578 prev->sibling = dir->sibling;
582 svn_pool_destroy(dir->dir_baton_pool);
583 svn_pool_destroy(dir->pool);
585 return SVN_NO_ERROR;
588 static svn_error_t *close_all_dirs(report_dir_t *dir)
590 while (dir->children)
592 SVN_ERR(close_all_dirs(dir->children));
593 dir->ref_count--;
596 if (dir->ref_count)
598 abort();
601 SVN_ERR(open_dir(dir));
603 return close_dir(dir);
607 /** Routines called when we are fetching a file */
609 /* This function works around a bug in mod_dav_svn in that it will not
610 * send remove-prop in the update report when a lock property disappears
611 * when send-all is false.
613 * Therefore, we'll try to look at our properties and see if there's
614 * an active lock. If not, then we'll assume there isn't a lock
615 * anymore.
617 static void
618 check_lock(report_info_t *info)
620 const char *lock_val;
622 lock_val = svn_ra_serf__get_ver_prop(info->props, info->url,
623 info->target_rev,
624 "DAV:", "lockdiscovery");
626 if (lock_val)
628 char *new_lock;
629 new_lock = apr_pstrdup(info->editor_pool, lock_val);
630 apr_collapse_spaces(new_lock, new_lock);
631 lock_val = new_lock;
634 if (!lock_val || lock_val[0] == '\0')
636 svn_string_t *str;
638 str = svn_string_ncreate("", 1, info->editor_pool);
640 svn_ra_serf__set_ver_prop(info->dir->removed_props, info->base_name,
641 info->base_rev, "DAV:", "lock-token",
642 str, info->dir->pool);
646 static apr_status_t
647 headers_fetch(serf_bucket_t *headers,
648 void *baton,
649 apr_pool_t *pool)
651 report_fetch_t *fetch_ctx = baton;
653 /* note that we have old VC URL */
654 if (SVN_IS_VALID_REVNUM(fetch_ctx->info->base_rev) &&
655 fetch_ctx->info->delta_base)
657 serf_bucket_headers_setn(headers, SVN_DAV_DELTA_BASE_HEADER,
658 fetch_ctx->info->delta_base->data);
659 serf_bucket_headers_setn(headers, "Accept-Encoding",
660 "svndiff1;q=0.9,svndiff;q=0.8");
662 else if (fetch_ctx->conn->using_compression == TRUE)
664 serf_bucket_headers_setn(headers, "Accept-Encoding", "gzip");
667 return APR_SUCCESS;
670 static apr_status_t
671 cancel_fetch(serf_request_t *request,
672 serf_bucket_t *response,
673 int status_code,
674 void *baton)
676 report_fetch_t *fetch_ctx = baton;
678 /* Uh-oh. Our connection died on us.
680 * The core ra_serf layer will requeue our request - we just need to note
681 * that we got cut off in the middle of our song.
683 if (!response)
685 /* If we already started the fetch and opened the file handle, we need
686 * to hold subsequent read() ops until we get back to where we were
687 * before the close and we can then resume the textdelta() calls.
689 if (fetch_ctx->read_headers == TRUE)
691 if (fetch_ctx->aborted_read == FALSE && fetch_ctx->read_size)
693 fetch_ctx->aborted_read = TRUE;
694 fetch_ctx->aborted_read_size = fetch_ctx->read_size;
696 fetch_ctx->read_size = 0;
699 return APR_SUCCESS;
702 /* We have no idea what went wrong. */
703 abort();
706 static apr_status_t
707 error_fetch(serf_request_t *request,
708 report_fetch_t *fetch_ctx,
709 svn_error_t *err)
711 fetch_ctx->err = err;
713 fetch_ctx->done = TRUE;
715 fetch_ctx->done_item.data = fetch_ctx;
716 fetch_ctx->done_item.next = *fetch_ctx->done_list;
717 *fetch_ctx->done_list = &fetch_ctx->done_item;
719 serf_request_set_handler(request, svn_ra_serf__handle_discard_body, NULL);
721 return APR_SUCCESS;
724 static apr_status_t
725 handle_fetch(serf_request_t *request,
726 serf_bucket_t *response,
727 void *handler_baton,
728 apr_pool_t *pool)
730 const char *data;
731 apr_size_t len;
732 apr_status_t status;
733 report_fetch_t *fetch_ctx = handler_baton;
734 svn_error_t *err;
736 if (fetch_ctx->read_headers == FALSE)
738 serf_bucket_t *hdrs;
739 const char *val;
740 report_info_t *info;
742 hdrs = serf_bucket_response_get_headers(response);
743 val = serf_bucket_headers_get(hdrs, "Content-Type");
744 info = fetch_ctx->info;
746 err = open_dir(info->dir);
747 if (err)
749 return error_fetch(request, fetch_ctx, err);
752 apr_pool_create(&info->editor_pool, info->dir->dir_baton_pool);
754 /* Expand our full name now if we haven't done so yet. */
755 if (!info->name)
757 info->name_buf = svn_stringbuf_dup(info->dir->name_buf,
758 info->editor_pool);
759 svn_path_add_component(info->name_buf, info->base_name);
760 info->name = info->name_buf->data;
763 if (SVN_IS_VALID_REVNUM(info->base_rev))
765 err = info->dir->update_editor->open_file(info->name,
766 info->dir->dir_baton,
767 info->base_rev,
768 info->editor_pool,
769 &info->file_baton);
771 else
773 err = info->dir->update_editor->add_file(info->name,
774 info->dir->dir_baton,
775 info->copyfrom_path,
776 info->copyfrom_rev,
777 info->editor_pool,
778 &info->file_baton);
781 if (err)
783 return error_fetch(request, fetch_ctx, err);
786 err = info->dir->update_editor->apply_textdelta(info->file_baton,
787 NULL,
788 info->editor_pool,
789 &info->textdelta,
790 &info->textdelta_baton);
792 if (err)
794 return error_fetch(request, fetch_ctx, err);
797 if (val && strcasecmp(val, "application/vnd.svn-svndiff") == 0)
799 fetch_ctx->delta_stream =
800 svn_txdelta_parse_svndiff(info->textdelta,
801 info->textdelta_baton,
802 TRUE, info->editor_pool);
804 else
806 fetch_ctx->delta_stream = NULL;
809 fetch_ctx->read_headers = TRUE;
812 while (1)
814 svn_txdelta_window_t delta_window = { 0 };
815 svn_txdelta_op_t delta_op;
816 svn_string_t window_data;
818 status = serf_bucket_read(response, 8000, &data, &len);
819 if (SERF_BUCKET_READ_ERROR(status))
821 return status;
824 fetch_ctx->read_size += len;
826 if (fetch_ctx->aborted_read == TRUE)
828 /* We haven't caught up to where we were before. */
829 if (fetch_ctx->read_size < fetch_ctx->aborted_read_size)
831 /* Eek. What did the file shrink or something? */
832 if (APR_STATUS_IS_EOF(status))
834 abort();
837 /* Skip on to the next iteration of this loop. */
838 if (APR_STATUS_IS_EAGAIN(status))
840 return status;
842 continue;
845 /* Woo-hoo. We're back. */
846 fetch_ctx->aborted_read = FALSE;
848 /* Increment data and len by the difference. */
849 data += fetch_ctx->read_size - fetch_ctx->aborted_read_size;
850 len = fetch_ctx->read_size - fetch_ctx->aborted_read_size;
853 if (fetch_ctx->delta_stream)
855 err = svn_stream_write(fetch_ctx->delta_stream, data, &len);
856 if (err)
858 return error_fetch(request, fetch_ctx, err);
861 /* otherwise, manually construct the text delta window. */
862 else if (len)
864 window_data.data = data;
865 window_data.len = len;
867 delta_op.action_code = svn_txdelta_new;
868 delta_op.offset = 0;
869 delta_op.length = len;
871 delta_window.tview_len = len;
872 delta_window.num_ops = 1;
873 delta_window.ops = &delta_op;
874 delta_window.new_data = &window_data;
876 /* write to the file located in the info. */
877 err = fetch_ctx->info->textdelta(&delta_window,
878 fetch_ctx->info->textdelta_baton);
879 if (err)
881 return error_fetch(request, fetch_ctx, err);
885 if (APR_STATUS_IS_EOF(status))
887 report_info_t *info = fetch_ctx->info;
889 err = info->textdelta(NULL, info->textdelta_baton);
890 if (err)
892 return error_fetch(request, fetch_ctx, err);
895 if (info->lock_token)
896 check_lock(info);
898 /* set all of the properties we received */
899 svn_ra_serf__walk_all_props(info->props,
900 info->base_name,
901 info->base_rev,
902 set_file_props,
903 info, info->editor_pool);
904 svn_ra_serf__walk_all_props(info->dir->removed_props,
905 info->base_name,
906 info->base_rev,
907 remove_file_props,
908 info, info->editor_pool);
909 if (info->fetch_props)
911 svn_ra_serf__walk_all_props(info->props,
912 info->url,
913 info->target_rev,
914 set_file_props,
915 info, info->editor_pool);
918 err = info->dir->update_editor->close_file(info->file_baton, NULL,
919 info->editor_pool);
921 if (err)
923 return error_fetch(request, fetch_ctx, err);
926 fetch_ctx->done = TRUE;
928 fetch_ctx->done_item.data = fetch_ctx;
929 fetch_ctx->done_item.next = *fetch_ctx->done_list;
930 *fetch_ctx->done_list = &fetch_ctx->done_item;
932 /* We're done with our pools. */
933 svn_pool_destroy(info->editor_pool);
934 svn_pool_destroy(info->pool);
936 return status;
938 if (APR_STATUS_IS_EAGAIN(status))
940 return status;
943 /* not reached */
946 static apr_status_t
947 handle_stream(serf_request_t *request,
948 serf_bucket_t *response,
949 void *handler_baton,
950 apr_pool_t *pool)
952 report_fetch_t *fetch_ctx = handler_baton;
953 serf_status_line sl;
955 serf_bucket_response_status(response, &sl);
957 /* Woo-hoo. Nothing here to see. */
958 if (sl.code == 404)
960 fetch_ctx->done = TRUE;
961 fetch_ctx->err = svn_error_createf(SVN_ERR_RA_DAV_PATH_NOT_FOUND, NULL,
962 "'%s' path not found",
963 fetch_ctx->info->name);
964 return svn_ra_serf__handle_discard_body(request, response, NULL, pool);
967 while (1)
969 const char *data;
970 apr_size_t len;
971 apr_status_t status;
973 status = serf_bucket_read(response, 8000, &data, &len);
974 if (SERF_BUCKET_READ_ERROR(status))
976 return status;
979 fetch_ctx->read_size += len;
981 if (fetch_ctx->aborted_read == TRUE)
983 /* We haven't caught up to where we were before. */
984 if (fetch_ctx->read_size < fetch_ctx->aborted_read_size)
986 /* Eek. What did the file shrink or something? */
987 if (APR_STATUS_IS_EOF(status))
989 abort();
992 /* Skip on to the next iteration of this loop. */
993 if (APR_STATUS_IS_EAGAIN(status))
995 return status;
997 continue;
1000 /* Woo-hoo. We're back. */
1001 fetch_ctx->aborted_read = FALSE;
1003 /* Increment data and len by the difference. */
1004 data += fetch_ctx->read_size - fetch_ctx->aborted_read_size;
1005 len += fetch_ctx->read_size - fetch_ctx->aborted_read_size;
1008 if (len)
1010 apr_size_t written_len;
1012 written_len = len;
1014 svn_stream_write(fetch_ctx->target_stream, data, &written_len);
1017 if (APR_STATUS_IS_EOF(status))
1019 fetch_ctx->done = TRUE;
1022 if (status)
1024 return status;
1027 /* not reached */
1030 static svn_error_t *
1031 handle_propchange_only(report_info_t *info)
1033 /* Ensure our parent is open. */
1034 SVN_ERR(open_dir(info->dir));
1036 apr_pool_create(&info->editor_pool, info->dir->dir_baton_pool);
1038 /* Expand our full name now if we haven't done so yet. */
1039 if (!info->name)
1041 info->name_buf = svn_stringbuf_dup(info->dir->name_buf,
1042 info->editor_pool);
1043 svn_path_add_component(info->name_buf, info->base_name);
1044 info->name = info->name_buf->data;
1047 if (SVN_IS_VALID_REVNUM(info->base_rev))
1049 SVN_ERR(info->dir->update_editor->open_file(info->name,
1050 info->dir->dir_baton,
1051 info->base_rev,
1052 info->editor_pool,
1053 &info->file_baton));
1055 else
1057 SVN_ERR(info->dir->update_editor->add_file(info->name,
1058 info->dir->dir_baton,
1059 info->copyfrom_path,
1060 info->copyfrom_rev,
1061 info->editor_pool,
1062 &info->file_baton));
1065 if (info->fetch_file)
1067 SVN_ERR(info->dir->update_editor->apply_textdelta(info->file_baton,
1068 NULL,
1069 info->editor_pool,
1070 &info->textdelta,
1071 &info->textdelta_baton));
1074 if (info->lock_token)
1075 check_lock(info);
1077 /* set all of the properties we received */
1078 svn_ra_serf__walk_all_props(info->props,
1079 info->base_name, info->base_rev,
1080 set_file_props, info, info->editor_pool);
1081 svn_ra_serf__walk_all_props(info->dir->removed_props,
1082 info->base_name, info->base_rev,
1083 remove_file_props, info, info->editor_pool);
1084 if (info->fetch_props)
1086 svn_ra_serf__walk_all_props(info->props, info->url, info->target_rev,
1087 set_file_props, info, info->editor_pool);
1090 SVN_ERR(info->dir->update_editor->close_file(info->file_baton, NULL,
1091 info->editor_pool));
1093 /* We're done with our pools. */
1094 svn_pool_destroy(info->editor_pool);
1095 svn_pool_destroy(info->pool);
1097 info->dir->ref_count--;
1099 return SVN_NO_ERROR;
1102 static svn_error_t *
1103 fetch_file(report_context_t *ctx, report_info_t *info)
1105 svn_ra_serf__connection_t *conn;
1106 svn_ra_serf__handler_t *handler;
1108 /* What connection should we go on? */
1109 conn = ctx->sess->conns[ctx->sess->cur_conn];
1111 /* go fetch info->name from DAV:checked-in */
1112 info->url =
1113 svn_ra_serf__get_ver_prop(info->props, info->base_name,
1114 info->base_rev, "DAV:", "checked-in");
1116 if (!info->url)
1118 return svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED, NULL,
1119 _("The OPTIONS response did not include the "
1120 "requested checked-in value"));
1123 /* If needed, create the PROPFIND to retrieve the file's properties. */
1124 info->propfind = NULL;
1125 if (info->fetch_props)
1127 svn_ra_serf__deliver_props(&info->propfind, info->props,
1128 ctx->sess, conn,
1129 info->url, info->target_rev, "0", all_props,
1130 FALSE, &ctx->done_propfinds, info->dir->pool);
1131 if (!info->propfind)
1133 abort();
1136 ctx->active_propfinds++;
1139 /* If we've been asked to fetch the file or its an add, do so.
1140 * Otherwise, handle the case where only the properties changed.
1142 if (info->fetch_file && ctx->text_deltas == TRUE)
1144 report_fetch_t *fetch_ctx;
1146 fetch_ctx = apr_pcalloc(info->dir->pool, sizeof(*fetch_ctx));
1147 fetch_ctx->pool = info->pool;
1148 fetch_ctx->info = info;
1149 fetch_ctx->done_list = &ctx->done_fetches;
1150 fetch_ctx->sess = ctx->sess;
1151 fetch_ctx->conn = conn;
1153 handler = apr_pcalloc(info->pool, sizeof(*handler));
1155 handler->method = "GET";
1156 handler->path = fetch_ctx->info->url;
1158 handler->conn = conn;
1159 handler->session = ctx->sess;
1161 handler->header_delegate = headers_fetch;
1162 handler->header_delegate_baton = fetch_ctx;
1164 handler->response_handler = handle_fetch;
1165 handler->response_baton = fetch_ctx;
1167 handler->response_error = cancel_fetch;
1168 handler->response_error_baton = fetch_ctx;
1170 svn_ra_serf__request_create(handler);
1172 ctx->active_fetches++;
1174 else if (info->propfind)
1176 svn_ra_serf__list_t *list_item;
1178 list_item = apr_pcalloc(info->dir->pool, sizeof(*list_item));
1179 list_item->data = info;
1180 list_item->next = ctx->file_propchanges_only;
1181 ctx->file_propchanges_only = list_item;
1183 else
1185 /* No propfind or GET request. Just handle the prop changes now. */
1186 SVN_ERR(handle_propchange_only(info));
1189 return SVN_NO_ERROR;
1193 /** XML callbacks for our update-report response parsing */
1195 static svn_error_t *
1196 start_report(svn_ra_serf__xml_parser_t *parser,
1197 void *userData,
1198 svn_ra_serf__dav_props_t name,
1199 const char **attrs)
1201 report_context_t *ctx = userData;
1202 report_state_e state;
1204 state = parser->state->current_state;
1206 if (state == NONE && strcmp(name.name, "target-revision") == 0)
1208 const char *rev;
1210 rev = svn_xml_get_attr_value("rev", attrs);
1212 if (!rev)
1214 return svn_error_create
1215 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1216 _("Missing revision attr in target-revision element"));
1219 ctx->update_editor->set_target_revision(ctx->update_baton,
1220 SVN_STR_TO_REV(rev),
1221 ctx->sess->pool);
1223 else if (state == NONE && strcmp(name.name, "open-directory") == 0)
1225 const char *rev;
1226 report_info_t *info;
1228 rev = svn_xml_get_attr_value("rev", attrs);
1230 if (!rev)
1232 return svn_error_create
1233 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1234 _("Missing revision attr in open-directory element"));
1237 info = push_state(parser, ctx, OPEN_DIR);
1239 info->base_rev = apr_atoi64(rev);
1240 info->dir->base_rev = info->base_rev;
1241 info->dir->target_rev = ctx->target_rev;
1242 info->fetch_props = TRUE;
1244 info->dir->base_name = "";
1245 info->dir->name_buf = svn_stringbuf_create("", info->pool);
1246 info->dir->name = info->dir->name_buf->data;
1248 info->base_name = info->dir->base_name;
1249 info->name = info->dir->name;
1250 info->name_buf = info->dir->name_buf;
1252 else if (state == NONE)
1254 /* do nothing as we haven't seen our valid start tag yet. */
1256 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1257 strcmp(name.name, "open-directory") == 0)
1259 const char *rev, *dirname;
1260 report_dir_t *dir;
1261 report_info_t *info;
1263 rev = svn_xml_get_attr_value("rev", attrs);
1265 if (!rev)
1267 return svn_error_create
1268 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1269 _("Missing revision attr in open-directory element"));
1272 dirname = svn_xml_get_attr_value("name", attrs);
1274 if (!dirname)
1276 return svn_error_create
1277 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1278 _("Missing name attr in open-directory element"));
1281 info = push_state(parser, ctx, OPEN_DIR);
1283 dir = info->dir;
1285 info->base_rev = apr_atoi64(rev);
1286 dir->base_rev = info->base_rev;
1287 dir->target_rev = ctx->target_rev;
1289 info->fetch_props = FALSE;
1291 dir->base_name = apr_pstrdup(dir->pool, dirname);
1292 info->base_name = dir->base_name;
1294 /* Expand our name. */
1295 dir->name_buf = svn_stringbuf_dup(dir->parent_dir->name_buf, dir->pool);
1296 svn_path_add_component(dir->name_buf, dir->base_name);
1298 dir->name = dir->name_buf->data;
1299 info->name = dir->name;
1301 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1302 strcmp(name.name, "add-directory") == 0)
1304 const char *dir_name, *cf, *cr;
1305 report_dir_t *dir;
1306 report_info_t *info;
1308 dir_name = svn_xml_get_attr_value("name", attrs);
1309 if (!dir_name)
1311 return svn_error_create
1312 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1313 _("Missing name attr in add-directory element"));
1315 cf = svn_xml_get_attr_value("copyfrom-path", attrs);
1316 cr = svn_xml_get_attr_value("copyfrom-rev", attrs);
1318 info = push_state(parser, ctx, ADD_DIR);
1320 dir = info->dir;
1322 dir->base_name = apr_pstrdup(dir->pool, dir_name);
1323 info->base_name = dir->base_name;
1325 /* Expand our name. */
1326 dir->name_buf = svn_stringbuf_dup(dir->parent_dir->name_buf, dir->pool);
1327 svn_path_add_component(dir->name_buf, dir->base_name);
1329 dir->name = dir->name_buf->data;
1330 info->name = dir->name;
1332 info->copyfrom_path = cf ? apr_pstrdup(info->pool, cf) : NULL;
1333 info->copyfrom_rev = cr ? apr_atoi64(cr) : SVN_INVALID_REVNUM;
1335 /* Mark that we don't have a base. */
1336 info->base_rev = SVN_INVALID_REVNUM;
1337 dir->base_rev = info->base_rev;
1338 dir->target_rev = ctx->target_rev;
1339 dir->fetch_props = TRUE;
1341 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1342 strcmp(name.name, "open-file") == 0)
1344 const char *file_name, *rev;
1345 report_info_t *info;
1347 file_name = svn_xml_get_attr_value("name", attrs);
1349 if (!file_name)
1351 return svn_error_create
1352 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1353 _("Missing name attr in open-file element"));
1356 rev = svn_xml_get_attr_value("rev", attrs);
1358 if (!rev)
1360 return svn_error_create
1361 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1362 _("Missing revision attr in open-file element"));
1365 info = push_state(parser, ctx, OPEN_FILE);
1367 info->base_rev = apr_atoi64(rev);
1368 info->target_rev = ctx->target_rev;
1369 info->fetch_props = FALSE;
1371 info->base_name = apr_pstrdup(info->pool, file_name);
1372 info->name = NULL;
1374 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1375 strcmp(name.name, "add-file") == 0)
1377 const char *file_name, *cf, *cr;
1378 report_info_t *info;
1380 file_name = svn_xml_get_attr_value("name", attrs);
1381 cf = svn_xml_get_attr_value("copyfrom-path", attrs);
1382 cr = svn_xml_get_attr_value("copyfrom-rev", attrs);
1384 if (!file_name)
1386 return svn_error_create
1387 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1388 _("Missing name attr in add-file element"));
1391 info = push_state(parser, ctx, ADD_FILE);
1393 info->base_rev = SVN_INVALID_REVNUM;
1394 info->target_rev = ctx->target_rev;
1395 info->fetch_props = TRUE;
1396 info->fetch_file = TRUE;
1398 info->base_name = apr_pstrdup(info->pool, file_name);
1399 info->name = NULL;
1401 info->copyfrom_path = cf ? apr_pstrdup(info->pool, cf) : NULL;
1402 info->copyfrom_rev = cr ? apr_atoi64(cr) : SVN_INVALID_REVNUM;
1404 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1405 strcmp(name.name, "delete-entry") == 0)
1407 const char *file_name;
1408 svn_stringbuf_t *name_buf;
1409 report_info_t *info;
1410 apr_pool_t *tmppool;
1412 file_name = svn_xml_get_attr_value("name", attrs);
1414 if (!file_name)
1416 return svn_error_create
1417 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1418 _("Missing name attr in delete-entry element"));
1421 info = parser->state->private;
1423 SVN_ERR(open_dir(info->dir));
1425 apr_pool_create(&tmppool, info->dir->dir_baton_pool);
1427 name_buf = svn_stringbuf_dup(info->dir->name_buf, tmppool);
1428 svn_path_add_component(name_buf, file_name);
1430 SVN_ERR(info->dir->update_editor->delete_entry(name_buf->data,
1431 SVN_INVALID_REVNUM,
1432 info->dir->dir_baton,
1433 tmppool));
1435 svn_pool_destroy(tmppool);
1437 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1438 strcmp(name.name, "absent-directory") == 0)
1440 const char *file_name;
1441 report_info_t *info;
1443 file_name = svn_xml_get_attr_value("name", attrs);
1445 if (!file_name)
1447 return svn_error_create
1448 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1449 _("Missing name attr in absent-directory element"));
1452 info = parser->state->private;
1454 SVN_ERR(open_dir(info->dir));
1456 ctx->update_editor->absent_directory(file_name,
1457 info->dir->dir_baton,
1458 info->dir->pool);
1460 else if ((state == OPEN_DIR || state == ADD_DIR) &&
1461 strcmp(name.name, "absent-file") == 0)
1463 const char *file_name;
1464 report_info_t *info;
1466 file_name = svn_xml_get_attr_value("name", attrs);
1468 if (!file_name)
1470 return svn_error_create
1471 (SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1472 _("Missing name attr in absent-file element"));
1475 info = parser->state->private;
1477 SVN_ERR(open_dir(info->dir));
1479 ctx->update_editor->absent_file(file_name,
1480 info->dir->dir_baton,
1481 info->dir->pool);
1483 else if (state == OPEN_DIR || state == ADD_DIR)
1485 report_info_t *info;
1487 if (strcmp(name.name, "checked-in") == 0)
1489 info = push_state(parser, ctx, IGNORE_PROP_NAME);
1490 info->prop_ns = name.namespace;
1491 info->prop_name = apr_pstrdup(parser->state->pool, name.name);
1492 info->prop_encoding = NULL;
1493 info->prop_val = NULL;
1494 info->prop_val_len = 0;
1496 else if (strcmp(name.name, "set-prop") == 0 ||
1497 strcmp(name.name, "remove-prop") == 0)
1499 const char *full_prop_name;
1500 const char *colon;
1502 info = push_state(parser, ctx, PROP);
1504 full_prop_name = svn_xml_get_attr_value("name", attrs);
1505 if (!full_prop_name)
1507 return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1508 _("Missing name attr in %s element"),
1509 name.name);
1512 colon = strchr(full_prop_name, ':');
1514 if (colon)
1515 colon++;
1516 else
1517 colon = full_prop_name;
1519 info->prop_ns = apr_pstrmemdup(info->dir->pool, full_prop_name,
1520 colon - full_prop_name);
1521 info->prop_name = apr_pstrdup(parser->state->pool, colon);
1522 info->prop_encoding = svn_xml_get_attr_value("encoding", attrs);
1523 info->prop_val = NULL;
1524 info->prop_val_len = 0;
1526 else if (strcmp(name.name, "prop") == 0)
1528 /* need to fetch it. */
1529 push_state(parser, ctx, NEED_PROP_NAME);
1531 else if (strcmp(name.name, "fetch-props") == 0)
1533 info = parser->state->private;
1535 info->dir->fetch_props = TRUE;
1537 else
1539 abort();
1543 else if (state == OPEN_FILE || state == ADD_FILE)
1545 report_info_t *info;
1547 if (strcmp(name.name, "checked-in") == 0)
1549 info = push_state(parser, ctx, IGNORE_PROP_NAME);
1550 info->prop_ns = name.namespace;
1551 info->prop_name = apr_pstrdup(parser->state->pool, name.name);
1552 info->prop_encoding = NULL;
1553 info->prop_val = NULL;
1554 info->prop_val_len = 0;
1556 else if (strcmp(name.name, "prop") == 0)
1558 /* need to fetch it. */
1559 push_state(parser, ctx, NEED_PROP_NAME);
1561 else if (strcmp(name.name, "fetch-props") == 0)
1563 info = parser->state->private;
1565 info->fetch_props = TRUE;
1567 else if (strcmp(name.name, "fetch-file") == 0)
1569 info = parser->state->private;
1571 info->fetch_file = TRUE;
1573 else if (strcmp(name.name, "set-prop") == 0 ||
1574 strcmp(name.name, "remove-prop") == 0)
1576 const char *full_prop_name;
1577 const char *colon;
1579 info = push_state(parser, ctx, PROP);
1581 full_prop_name = svn_xml_get_attr_value("name", attrs);
1582 if (!full_prop_name)
1584 return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
1585 _("Missing name attr in %s element"),
1586 name.name);
1588 colon = strchr(full_prop_name, ':');
1590 if (colon)
1591 colon++;
1592 else
1593 colon = full_prop_name;
1595 info->prop_ns = apr_pstrmemdup(info->dir->pool, full_prop_name,
1596 colon - full_prop_name);
1597 info->prop_name = apr_pstrdup(parser->state->pool, colon);
1598 info->prop_encoding = svn_xml_get_attr_value("encoding", attrs);
1599 info->prop_val = NULL;
1600 info->prop_val_len = 0;
1602 else
1604 abort();
1607 else if (state == IGNORE_PROP_NAME)
1609 push_state(parser, ctx, PROP);
1611 else if (state == NEED_PROP_NAME)
1613 report_info_t *info;
1615 info = push_state(parser, ctx, PROP);
1617 info->prop_ns = name.namespace;
1618 info->prop_name = apr_pstrdup(parser->state->pool, name.name);
1619 info->prop_val = NULL;
1620 info->prop_val_len = 0;
1623 return SVN_NO_ERROR;
1626 static svn_error_t *
1627 end_report(svn_ra_serf__xml_parser_t *parser,
1628 void *userData,
1629 svn_ra_serf__dav_props_t name)
1631 report_context_t *ctx = userData;
1632 report_state_e state;
1634 state = parser->state->current_state;
1636 if (state == NONE)
1638 /* nothing to close yet. */
1639 return SVN_NO_ERROR;
1642 if (((state == OPEN_DIR && (strcmp(name.name, "open-directory") == 0)) ||
1643 (state == ADD_DIR && (strcmp(name.name, "add-directory") == 0))))
1645 const char *checked_in_url;
1646 report_info_t *info = parser->state->private;
1648 /* We've now closed this directory; note it. */
1649 info->dir->tag_closed = TRUE;
1651 /* go fetch info->file_name from DAV:checked-in */
1652 checked_in_url =
1653 svn_ra_serf__get_ver_prop(info->dir->props, info->base_name,
1654 info->base_rev, "DAV:", "checked-in");
1656 /* If we were expecting to have the properties and we aren't able to
1657 * get it, bail.
1659 if (!checked_in_url &&
1660 (!SVN_IS_VALID_REVNUM(info->dir->base_rev) || info->dir->fetch_props))
1662 return svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED, NULL,
1663 _("The OPTIONS response did not include the "
1664 "requested checked-in value"));
1667 info->dir->url = checked_in_url;
1669 /* At this point, we should have the checked-in href.
1670 * If needed, create the PROPFIND to retrieve the dir's properties.
1672 if (!SVN_IS_VALID_REVNUM(info->dir->base_rev) || info->dir->fetch_props)
1674 /* Unconditionally set fetch_props now. */
1675 info->dir->fetch_props = TRUE;
1677 svn_ra_serf__deliver_props(&info->dir->propfind, info->dir->props,
1678 ctx->sess,
1679 ctx->sess->conns[ctx->sess->cur_conn],
1680 info->dir->url, info->dir->target_rev,
1681 "0", all_props, FALSE,
1682 &ctx->done_propfinds, info->dir->pool);
1684 if (!info->dir->propfind)
1686 abort();
1689 ctx->active_propfinds++;
1691 else
1693 info->dir->propfind = NULL;
1696 svn_ra_serf__xml_pop_state(parser);
1698 else if (state == OPEN_FILE && strcmp(name.name, "open-file") == 0)
1700 report_info_t *info = parser->state->private;
1702 /* Expand our full name now if we haven't done so yet. */
1703 if (!info->name)
1705 info->name_buf = svn_stringbuf_dup(info->dir->name_buf, info->pool);
1706 svn_path_add_component(info->name_buf, info->base_name);
1707 info->name = info->name_buf->data;
1710 info->lock_token = apr_hash_get(ctx->lock_path_tokens, info->name,
1711 APR_HASH_KEY_STRING);
1713 if (info->lock_token && info->fetch_props == FALSE)
1714 info->fetch_props = TRUE;
1716 /* If we have a WC, we can dive all the way into the WC to get the
1717 * previous URL so we can do an differential GET with the base URL.
1719 * If we don't have a WC (as is the case for URL<->URL diff), we can
1720 * manually reconstruct the base URL. This avoids us having to grab
1721 * two full-text for URL<->URL diffs. Instead, we can just grab one
1722 * full-text and a diff from the server against that other file.
1724 if (ctx->sess->wc_callbacks->get_wc_prop)
1726 ctx->sess->wc_callbacks->get_wc_prop(ctx->sess->wc_callback_baton,
1727 info->name,
1728 SVN_RA_SERF__WC_CHECKED_IN_URL,
1729 &info->delta_base,
1730 info->pool);
1732 else
1734 const char *c;
1735 apr_size_t comp_count;
1736 svn_stringbuf_t *path;
1737 svn_boolean_t fix_root = FALSE;
1739 c = svn_ra_serf__get_ver_prop(info->props, info->base_name,
1740 info->base_rev, "DAV:", "checked-in");
1742 path = svn_stringbuf_create(c, info->pool);
1744 comp_count = svn_path_component_count(info->name_buf->data);
1746 svn_path_remove_components(path, comp_count);
1748 /* Our paths may be relative to a file from the actual root, so
1749 * we would need to strip out the difference from our fixed point
1750 * to the root and then add it back in after we replace the
1751 * version number.
1753 if (strcmp(ctx->source, ctx->sess->repos_root.path) != 0)
1755 apr_size_t root_count, src_count;
1757 src_count = svn_path_component_count(ctx->source);
1758 root_count = svn_path_component_count(ctx->sess->repos_root.path);
1760 svn_path_remove_components(path, src_count - root_count);
1762 fix_root = TRUE;
1765 /* At this point, we should just have the version number
1766 * remaining. We know our target revision, so we'll replace it
1767 * and recreate what we just chopped off.
1769 svn_path_remove_component(path);
1771 svn_path_add_component(path, apr_ltoa(info->pool, info->base_rev));
1773 if (fix_root == TRUE)
1775 apr_size_t root_len;
1777 root_len = strlen(ctx->sess->repos_root.path) + 1;
1779 svn_path_add_component(path, &ctx->source[root_len]);
1782 svn_path_add_component(path, info->name);
1784 info->delta_base = svn_string_create_from_buf(path, info->pool);
1787 SVN_ERR(fetch_file(ctx, info));
1788 svn_ra_serf__xml_pop_state(parser);
1790 else if (state == ADD_FILE && strcmp(name.name, "add-file") == 0)
1792 /* We should have everything we need to fetch the file. */
1793 SVN_ERR(fetch_file(ctx, parser->state->private));
1794 svn_ra_serf__xml_pop_state(parser);
1796 else if (state == PROP)
1798 /* We need to move the prop_ns, prop_name, and prop_val into the
1799 * same lifetime as the dir->pool.
1801 svn_ra_serf__ns_t *ns, *ns_name_match;
1802 int found = 0;
1803 report_info_t *info;
1804 report_dir_t *dir;
1805 apr_hash_t *props;
1806 const char *set_val;
1807 svn_string_t *set_val_str;
1808 apr_pool_t *pool;
1810 info = parser->state->private;
1811 dir = info->dir;
1813 /* We're going to be slightly tricky. We don't care what the ->url
1814 * field is here at this point. So, we're going to stick a single
1815 * copy of the property name inside of the ->url field.
1817 ns_name_match = NULL;
1818 for (ns = dir->ns_list; ns; ns = ns->next)
1820 if (strcmp(ns->namespace, info->prop_ns) == 0)
1822 ns_name_match = ns;
1823 if (strcmp(ns->url, info->prop_name) == 0)
1825 found = 1;
1826 break;
1831 if (!found)
1833 ns = apr_palloc(dir->pool, sizeof(*ns));
1834 if (!ns_name_match)
1836 ns->namespace = apr_pstrdup(dir->pool, info->prop_ns);
1838 else
1840 ns->namespace = ns_name_match->namespace;
1842 ns->url = apr_pstrdup(dir->pool, info->prop_name);
1844 ns->next = dir->ns_list;
1845 dir->ns_list = ns;
1848 if (strcmp(name.name, "remove-prop") != 0)
1850 props = info->props;
1851 pool = info->pool;
1853 else
1855 props = dir->removed_props;
1856 pool = dir->pool;
1857 info->prop_val = "";
1858 info->prop_val_len = 1;
1861 if (info->prop_encoding)
1863 if (strcmp(info->prop_encoding, "base64") == 0)
1865 svn_string_t encoded;
1866 const svn_string_t *decoded;
1868 encoded.data = info->prop_val;
1869 encoded.len = info->prop_val_len;
1871 decoded = svn_base64_decode_string(&encoded, parser->state->pool);
1873 info->prop_val = decoded->data;
1874 info->prop_val_len = decoded->len;
1876 else
1878 return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA,
1879 NULL,
1880 _("Got unrecognized encoding '%s'"),
1881 info->prop_encoding);
1886 set_val = apr_pmemdup(pool, info->prop_val, info->prop_val_len);
1887 set_val_str = svn_string_ncreate(set_val, info->prop_val_len, pool);
1889 svn_ra_serf__set_ver_prop(props, info->base_name, info->base_rev,
1890 ns->namespace, ns->url, set_val_str, pool);
1891 svn_ra_serf__xml_pop_state(parser);
1893 else if (state == IGNORE_PROP_NAME || state == NEED_PROP_NAME)
1895 svn_ra_serf__xml_pop_state(parser);
1898 return SVN_NO_ERROR;
1901 static svn_error_t *
1902 cdata_report(svn_ra_serf__xml_parser_t *parser,
1903 void *userData,
1904 const char *data,
1905 apr_size_t len)
1907 report_context_t *ctx = userData;
1909 UNUSED_CTX(ctx);
1911 if (parser->state->current_state == PROP)
1913 report_info_t *info = parser->state->private;
1915 svn_ra_serf__expand_string(&info->prop_val, &info->prop_val_len,
1916 data, len, parser->state->pool);
1919 return SVN_NO_ERROR;
1923 /** Editor callbacks given to callers to create request body */
1925 static svn_error_t *
1926 set_path(void *report_baton,
1927 const char *path,
1928 svn_revnum_t revision,
1929 svn_depth_t depth,
1930 svn_boolean_t start_empty,
1931 const char *lock_token,
1932 apr_pool_t *pool)
1934 report_context_t *report = report_baton;
1935 serf_bucket_t *tmp;
1936 svn_stringbuf_t *path_buf;
1938 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("<S:entry rev=\"",
1939 sizeof("<S:entry rev=\"")-1,
1940 report->sess->bkt_alloc);
1941 serf_bucket_aggregate_append(report->buckets, tmp);
1943 tmp = SERF_BUCKET_SIMPLE_STRING(apr_ltoa(report->pool, revision),
1944 report->sess->bkt_alloc);
1945 serf_bucket_aggregate_append(report->buckets, tmp);
1947 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
1948 report->sess->bkt_alloc);
1949 serf_bucket_aggregate_append(report->buckets, tmp);
1951 if (lock_token)
1953 apr_hash_set(report->lock_path_tokens,
1954 apr_pstrdup(report->pool, path),
1955 APR_HASH_KEY_STRING,
1956 apr_pstrdup(report->pool, lock_token));
1958 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" lock-token=\"",
1959 sizeof(" lock-token=\"")-1,
1960 report->sess->bkt_alloc);
1961 serf_bucket_aggregate_append(report->buckets, tmp);
1963 tmp = SERF_BUCKET_SIMPLE_STRING(lock_token,
1964 report->sess->bkt_alloc);
1965 serf_bucket_aggregate_append(report->buckets, tmp);
1967 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
1968 report->sess->bkt_alloc);
1969 serf_bucket_aggregate_append(report->buckets, tmp);
1972 /* Depth. */
1973 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" depth=\"",
1974 sizeof(" depth=\"")-1,
1975 report->sess->bkt_alloc);
1976 serf_bucket_aggregate_append(report->buckets, tmp);
1978 tmp = SERF_BUCKET_SIMPLE_STRING(svn_depth_to_word(depth),
1979 report->sess->bkt_alloc);
1980 serf_bucket_aggregate_append(report->buckets, tmp);
1982 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
1983 report->sess->bkt_alloc);
1984 serf_bucket_aggregate_append(report->buckets, tmp);
1986 if (start_empty)
1988 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" start-empty=\"true\"",
1989 sizeof(" start-empty=\"true\"")-1,
1990 report->sess->bkt_alloc);
1991 serf_bucket_aggregate_append(report->buckets, tmp);
1994 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(">", sizeof(">")-1,
1995 report->sess->bkt_alloc);
1996 serf_bucket_aggregate_append(report->buckets, tmp);
1998 path_buf = NULL;
1999 svn_xml_escape_cdata_cstring(&path_buf, path, report->pool);
2001 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(path_buf->data, path_buf->len,
2002 report->sess->bkt_alloc);
2003 serf_bucket_aggregate_append(report->buckets, tmp);
2005 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("</S:entry>",
2006 sizeof("</S:entry>")-1,
2007 report->sess->bkt_alloc);
2009 serf_bucket_aggregate_append(report->buckets, tmp);
2010 return APR_SUCCESS;
2013 static svn_error_t *
2014 delete_path(void *report_baton,
2015 const char *path,
2016 apr_pool_t *pool)
2018 report_context_t *report = report_baton;
2019 serf_bucket_t *tmp;
2021 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("<S:missing>",
2022 sizeof("<S:missing>")-1,
2023 report->sess->bkt_alloc);
2024 serf_bucket_aggregate_append(report->buckets, tmp);
2026 tmp = SERF_BUCKET_SIMPLE_STRING(apr_pstrdup(report->pool, path),
2027 report->sess->bkt_alloc);
2028 serf_bucket_aggregate_append(report->buckets, tmp);
2030 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("</S:missing>",
2031 sizeof("</S:missing>")-1,
2032 report->sess->bkt_alloc);
2034 serf_bucket_aggregate_append(report->buckets, tmp);
2035 return APR_SUCCESS;
2038 static svn_error_t *
2039 link_path(void *report_baton,
2040 const char *path,
2041 const char *url,
2042 svn_revnum_t revision,
2043 svn_depth_t depth,
2044 svn_boolean_t start_empty,
2045 const char *lock_token,
2046 apr_pool_t *pool)
2048 report_context_t *report = report_baton;
2049 serf_bucket_t *tmp;
2050 const char *link, *vcc_url;
2051 apr_uri_t uri;
2052 apr_status_t status;
2054 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("<S:entry rev=\"",
2055 sizeof("<S:entry rev=\"")-1,
2056 report->sess->bkt_alloc);
2057 serf_bucket_aggregate_append(report->buckets, tmp);
2059 tmp = SERF_BUCKET_SIMPLE_STRING(apr_ltoa(report->pool, revision),
2060 report->sess->bkt_alloc);
2061 serf_bucket_aggregate_append(report->buckets, tmp);
2063 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
2064 report->sess->bkt_alloc);
2065 serf_bucket_aggregate_append(report->buckets, tmp);
2067 if (lock_token)
2069 apr_hash_set(report->lock_path_tokens,
2070 apr_pstrdup(report->pool, path),
2071 APR_HASH_KEY_STRING,
2072 apr_pstrdup(report->pool, lock_token));
2074 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" lock-token=\"",
2075 sizeof(" lock-token=\"")-1,
2076 report->sess->bkt_alloc);
2077 serf_bucket_aggregate_append(report->buckets, tmp);
2079 tmp = SERF_BUCKET_SIMPLE_STRING(lock_token,
2080 report->sess->bkt_alloc);
2081 serf_bucket_aggregate_append(report->buckets, tmp);
2083 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
2084 report->sess->bkt_alloc);
2085 serf_bucket_aggregate_append(report->buckets, tmp);
2088 /* Depth. */
2089 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" depth=\"",
2090 sizeof(" depth=\"")-1,
2091 report->sess->bkt_alloc);
2092 serf_bucket_aggregate_append(report->buckets, tmp);
2094 tmp = SERF_BUCKET_SIMPLE_STRING(svn_depth_to_word(depth),
2095 report->sess->bkt_alloc);
2096 serf_bucket_aggregate_append(report->buckets, tmp);
2098 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
2099 report->sess->bkt_alloc);
2100 serf_bucket_aggregate_append(report->buckets, tmp);
2102 if (start_empty)
2104 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" start-empty=\"true\"",
2105 sizeof(" start-empty=\"true\"")-1,
2106 report->sess->bkt_alloc);
2107 serf_bucket_aggregate_append(report->buckets, tmp);
2110 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(" linkpath=\"/",
2111 sizeof(" linkpath=\"/")-1,
2112 report->sess->bkt_alloc);
2113 serf_bucket_aggregate_append(report->buckets, tmp);
2115 /* We need to pass in the baseline relative path.
2117 * TODO Confirm that it's on the same server?
2119 status = apr_uri_parse(pool, url, &uri);
2120 if (status)
2122 return svn_error_createf(SVN_ERR_RA_DAV_MALFORMED_DATA, NULL,
2123 _("Unable to parse URL '%s'"), url);
2126 SVN_ERR(svn_ra_serf__discover_root(&vcc_url, &link, report->sess,
2127 report->sess->conns[0], uri.path, pool));
2129 tmp = SERF_BUCKET_SIMPLE_STRING(apr_pstrdup(report->pool, link),
2130 report->sess->bkt_alloc);
2131 serf_bucket_aggregate_append(report->buckets, tmp);
2133 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\"", sizeof("\"")-1,
2134 report->sess->bkt_alloc);
2135 serf_bucket_aggregate_append(report->buckets, tmp);
2137 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(">", sizeof(">")-1,
2138 report->sess->bkt_alloc);
2139 serf_bucket_aggregate_append(report->buckets, tmp);
2141 tmp = SERF_BUCKET_SIMPLE_STRING(apr_pstrdup(report->pool, path),
2142 report->sess->bkt_alloc);
2143 serf_bucket_aggregate_append(report->buckets, tmp);
2145 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("</S:entry>",
2146 sizeof("</S:entry>")-1,
2147 report->sess->bkt_alloc);
2149 serf_bucket_aggregate_append(report->buckets, tmp);
2150 return APR_SUCCESS;
2153 static svn_error_t *
2154 finish_report(void *report_baton,
2155 apr_pool_t *pool)
2157 report_context_t *report = report_baton;
2158 svn_ra_serf__session_t *sess = report->sess;
2159 svn_ra_serf__handler_t *handler;
2160 svn_ra_serf__xml_parser_t *parser_ctx;
2161 svn_ra_serf__list_t *done_list;
2162 serf_bucket_t *tmp;
2163 const char *vcc_url;
2164 apr_hash_t *props;
2165 apr_status_t status;
2166 svn_boolean_t closed_root;
2167 int i;
2169 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("</S:update-report>",
2170 sizeof("</S:update-report>")-1,
2171 report->sess->bkt_alloc);
2172 serf_bucket_aggregate_append(report->buckets, tmp);
2174 props = apr_hash_make(pool);
2176 SVN_ERR(svn_ra_serf__discover_root(&vcc_url, NULL, sess, sess->conns[0],
2177 sess->repos_url.path, pool));
2179 if (!vcc_url)
2181 return svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED, NULL,
2182 _("The OPTIONS response did not include the "
2183 "requested version-controlled-configuration "
2184 "value"));
2187 /* create and deliver request */
2188 report->path = vcc_url;
2190 handler = apr_pcalloc(pool, sizeof(*handler));
2192 handler->method = "REPORT";
2193 handler->path = report->path;
2194 handler->body_buckets = report->buckets;
2195 handler->body_type = "text/xml";
2196 handler->conn = sess->conns[0];
2197 handler->session = sess;
2199 parser_ctx = apr_pcalloc(pool, sizeof(*parser_ctx));
2201 parser_ctx->pool = pool;
2202 parser_ctx->user_data = report;
2203 parser_ctx->start = start_report;
2204 parser_ctx->end = end_report;
2205 parser_ctx->cdata = cdata_report;
2206 parser_ctx->done = &report->done;
2208 handler->response_handler = svn_ra_serf__handle_xml_parser;
2209 handler->response_baton = parser_ctx;
2211 svn_ra_serf__request_create(handler);
2213 for (i = sess->num_conns; i < 4; i++)
2215 sess->conns[i] = apr_palloc(sess->pool, sizeof(*sess->conns[i]));
2216 sess->conns[i]->bkt_alloc = serf_bucket_allocator_create(sess->pool,
2217 NULL, NULL);
2218 sess->conns[i]->address = sess->conns[0]->address;
2219 sess->conns[i]->hostinfo = sess->conns[0]->hostinfo;
2220 sess->conns[i]->using_ssl = sess->conns[0]->using_ssl;
2221 sess->conns[i]->using_compression = sess->conns[0]->using_compression;
2222 sess->conns[i]->last_status_code = -1;
2223 sess->conns[i]->ssl_context = NULL;
2224 sess->conns[i]->session = sess;
2225 sess->conns[i]->conn = serf_connection_create(sess->context,
2226 sess->conns[i]->address,
2227 svn_ra_serf__conn_setup,
2228 sess->conns[i],
2229 svn_ra_serf__conn_closed,
2230 sess->conns[i],
2231 sess->pool);
2232 sess->num_conns++;
2234 /* Authentication protocol specific initalization. */
2235 if (sess->auth_protocol)
2236 sess->auth_protocol->init_conn_func(sess, sess->conns[i], pool);
2239 sess->cur_conn = 1;
2240 closed_root = FALSE;
2242 while (!report->done || report->active_fetches || report->active_propfinds)
2244 status = serf_context_run(sess->context, SERF_DURATION_FOREVER, pool);
2245 if (APR_STATUS_IS_TIMEUP(status))
2247 continue;
2249 if (status)
2251 SVN_ERR(sess->pending_error);
2253 return svn_error_wrap_apr(status, _("Error retrieving REPORT (%d)"),
2254 status);
2257 /* Switch our connection. */
2258 if (!report->done)
2259 if (++sess->cur_conn == sess->num_conns)
2260 sess->cur_conn = 1;
2262 /* prune our propfind list if they are done. */
2263 done_list = report->done_propfinds;
2264 while (done_list)
2266 report->active_propfinds--;
2268 /* If we have some files that we won't be fetching the content
2269 * for, ensure that we update the file with any altered props.
2271 if (report->file_propchanges_only)
2273 svn_ra_serf__list_t *cur, *prev;
2275 prev = NULL;
2276 cur = report->file_propchanges_only;
2278 while (cur)
2280 report_info_t *item = cur->data;
2282 if (item->propfind == done_list->data)
2284 break;
2287 prev = cur;
2288 cur = cur->next;
2291 /* If we found a match, set the new props and remove this
2292 * propchange from our list.
2294 if (cur)
2296 SVN_ERR(handle_propchange_only(cur->data));
2298 if (!prev)
2300 report->file_propchanges_only = cur->next;
2302 else
2304 prev->next = cur->next;
2309 done_list = done_list->next;
2311 report->done_propfinds = NULL;
2313 /* prune our fetches list if they are done. */
2314 done_list = report->done_fetches;
2315 while (done_list)
2317 report_fetch_t *done_fetch = done_list->data;
2318 report_dir_t *cur_dir;
2320 if (done_fetch->err)
2322 svn_error_t *err = done_fetch->err;
2323 /* Error found. There might be more, clear those first. */
2324 done_list = done_list->next;
2325 while (done_list)
2327 done_fetch = done_list->data;
2328 if (done_fetch->err)
2329 svn_error_clear(done_fetch->err);
2330 done_list = done_list->next;
2332 return err;
2335 /* decrease our parent's directory refcount. */
2336 cur_dir = done_fetch->info->dir;
2337 cur_dir->ref_count--;
2339 /* Decrement our active fetch count. */
2340 report->active_fetches--;
2342 done_list = done_list->next;
2344 /* If we have a valid directory and
2345 * we have no open items in this dir and
2346 * we've closed the directory tag (no more children can be added)
2347 * and either:
2348 * we know we won't be fetching props or
2349 * we've already completed the propfind
2350 * then, we know it's time for us to close this directory.
2352 while (cur_dir && !cur_dir->ref_count && cur_dir->tag_closed &&
2353 (!cur_dir->fetch_props ||
2354 svn_ra_serf__propfind_is_done(cur_dir->propfind)))
2356 report_dir_t *parent = cur_dir->parent_dir;
2358 SVN_ERR(close_dir(cur_dir));
2359 if (parent)
2361 parent->ref_count--;
2363 else
2365 closed_root = TRUE;
2367 cur_dir = parent;
2370 report->done_fetches = NULL;
2372 /* Debugging purposes only! */
2373 serf_debug__closed_conn(sess->bkt_alloc);
2374 for (i = 0; i < sess->num_conns; i++)
2376 serf_debug__closed_conn(sess->conns[i]->bkt_alloc);
2380 /* Ensure that we opened and closed our root dir and that we closed
2381 * all of our children. */
2382 if (closed_root == FALSE)
2384 SVN_ERR(close_all_dirs(report->root_dir));
2387 /* FIXME subpool */
2388 SVN_ERR(report->update_editor->close_edit(report->update_baton, sess->pool));
2390 return SVN_NO_ERROR;
2393 static svn_error_t *
2394 abort_report(void *report_baton,
2395 apr_pool_t *pool)
2397 #if 0
2398 report_context_t *report = report_baton;
2399 #endif
2400 abort();
2403 static const svn_ra_reporter3_t ra_serf_reporter = {
2404 set_path,
2405 delete_path,
2406 link_path,
2407 finish_report,
2408 abort_report
2412 /** RA function implementations and body */
2414 static svn_error_t *
2415 make_update_reporter(svn_ra_session_t *ra_session,
2416 const svn_ra_reporter3_t **reporter,
2417 void **report_baton,
2418 svn_revnum_t revision,
2419 const char *src_path,
2420 const char *dest_path,
2421 const char *update_target,
2422 svn_depth_t depth,
2423 svn_boolean_t ignore_ancestry,
2424 svn_boolean_t text_deltas,
2425 svn_boolean_t send_copyfrom_args,
2426 const svn_delta_editor_t *update_editor,
2427 void *update_baton,
2428 apr_pool_t *pool)
2430 report_context_t *report;
2431 serf_bucket_t *tmp;
2432 svn_stringbuf_t *path_buf;
2433 const svn_delta_editor_t *filter_editor;
2434 void *filter_baton;
2435 svn_boolean_t has_target = *update_target ? TRUE : FALSE;
2436 svn_boolean_t server_supports_depth;
2437 svn_ra_serf__session_t *sess = ra_session->priv;
2439 SVN_ERR(svn_ra_serf__has_capability(ra_session, &server_supports_depth,
2440 SVN_RA_CAPABILITY_DEPTH, pool));
2441 /* We can skip the depth filtering when the user requested
2442 depth_files or depth_infinity because the server will
2443 transmit the right stuff anyway. */
2444 if ((depth != svn_depth_files)
2445 && (depth != svn_depth_infinity)
2446 && ! server_supports_depth)
2448 SVN_ERR(svn_delta_depth_filter_editor(&filter_editor,
2449 &filter_baton,
2450 update_editor,
2451 update_baton,
2452 depth, has_target,
2453 sess->pool));
2454 update_editor = filter_editor;
2455 update_baton = filter_baton;
2458 report = apr_pcalloc(pool, sizeof(*report));
2459 report->pool = pool;
2460 report->sess = sess;
2461 report->conn = report->sess->conns[0];
2462 report->target_rev = revision;
2463 report->ignore_ancestry = ignore_ancestry;
2464 report->send_copyfrom_args = send_copyfrom_args;
2465 report->text_deltas = text_deltas;
2466 report->lock_path_tokens = apr_hash_make(pool);
2468 if (src_path)
2470 path_buf = NULL;
2471 svn_xml_escape_cdata_cstring(&path_buf, src_path, report->pool);
2472 report->source = path_buf->data;
2475 if (dest_path)
2477 path_buf = NULL;
2478 svn_xml_escape_cdata_cstring(&path_buf, dest_path, report->pool);
2479 report->destination = path_buf->data;
2482 if (update_target)
2484 path_buf = NULL;
2485 svn_xml_escape_cdata_cstring(&path_buf, update_target, report->pool);
2486 report->update_target = path_buf->data;
2489 report->update_editor = update_editor;
2490 report->update_baton = update_baton;
2491 report->done = FALSE;
2493 *reporter = &ra_serf_reporter;
2494 *report_baton = report;
2496 report->buckets = serf_bucket_aggregate_create(report->sess->bkt_alloc);
2498 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("<S:update-report xmlns:S=\"",
2499 sizeof("<S:update-report xmlns:S=\"")-1,
2500 report->sess->bkt_alloc);
2501 serf_bucket_aggregate_append(report->buckets, tmp);
2503 tmp = SERF_BUCKET_SIMPLE_STRING_LEN(SVN_XML_NAMESPACE,
2504 sizeof(SVN_XML_NAMESPACE)-1,
2505 report->sess->bkt_alloc);
2506 serf_bucket_aggregate_append(report->buckets, tmp);
2508 tmp = SERF_BUCKET_SIMPLE_STRING_LEN("\">",
2509 sizeof("\">")-1,
2510 report->sess->bkt_alloc);
2511 serf_bucket_aggregate_append(report->buckets, tmp);
2513 svn_ra_serf__add_tag_buckets(report->buckets,
2514 "S:src-path", report->source,
2515 report->sess->bkt_alloc);
2517 if (SVN_IS_VALID_REVNUM(report->target_rev))
2519 svn_ra_serf__add_tag_buckets(report->buckets,
2520 "S:target-revision",
2521 apr_ltoa(pool, report->target_rev),
2522 report->sess->bkt_alloc);
2525 if (report->destination && *report->destination)
2527 svn_ra_serf__add_tag_buckets(report->buckets,
2528 "S:dst-path",
2529 report->destination,
2530 report->sess->bkt_alloc);
2533 if (report->update_target && *report->update_target)
2535 svn_ra_serf__add_tag_buckets(report->buckets,
2536 "S:update-target", report->update_target,
2537 report->sess->bkt_alloc);
2540 if (report->ignore_ancestry)
2542 svn_ra_serf__add_tag_buckets(report->buckets,
2543 "S:ignore-ancestry", "yes",
2544 report->sess->bkt_alloc);
2547 if (report->send_copyfrom_args)
2549 svn_ra_serf__add_tag_buckets(report->buckets,
2550 "S:send-copyfrom-args", "yes",
2551 report->sess->bkt_alloc);
2554 /* Old servers know "recursive" but not "depth"; help them DTRT. */
2555 if (depth == svn_depth_files || depth == svn_depth_empty)
2557 svn_ra_serf__add_tag_buckets(report->buckets,
2558 "S:recursive", "no",
2559 report->sess->bkt_alloc);
2562 svn_ra_serf__add_tag_buckets(report->buckets,
2563 "S:depth", svn_depth_to_word(depth),
2564 report->sess->bkt_alloc);
2566 return SVN_NO_ERROR;
2569 svn_error_t *
2570 svn_ra_serf__do_update(svn_ra_session_t *ra_session,
2571 const svn_ra_reporter3_t **reporter,
2572 void **report_baton,
2573 svn_revnum_t revision_to_update_to,
2574 const char *update_target,
2575 svn_depth_t depth,
2576 svn_boolean_t send_copyfrom_args,
2577 const svn_delta_editor_t *update_editor,
2578 void *update_baton,
2579 apr_pool_t *pool)
2581 svn_ra_serf__session_t *session = ra_session->priv;
2583 return make_update_reporter(ra_session, reporter, report_baton,
2584 revision_to_update_to,
2585 session->repos_url.path, NULL, update_target,
2586 depth, FALSE, TRUE, send_copyfrom_args,
2587 update_editor, update_baton, pool);
2590 svn_error_t *
2591 svn_ra_serf__do_diff(svn_ra_session_t *ra_session,
2592 const svn_ra_reporter3_t **reporter,
2593 void **report_baton,
2594 svn_revnum_t revision,
2595 const char *diff_target,
2596 svn_depth_t depth,
2597 svn_boolean_t ignore_ancestry,
2598 svn_boolean_t text_deltas,
2599 const char *versus_url,
2600 const svn_delta_editor_t *diff_editor,
2601 void *diff_baton,
2602 apr_pool_t *pool)
2604 svn_ra_serf__session_t *session = ra_session->priv;
2606 return make_update_reporter(ra_session, reporter, report_baton,
2607 revision,
2608 session->repos_url.path, versus_url, diff_target,
2609 depth, ignore_ancestry, text_deltas, FALSE,
2610 diff_editor, diff_baton, pool);
2613 svn_error_t *
2614 svn_ra_serf__do_status(svn_ra_session_t *ra_session,
2615 const svn_ra_reporter3_t **reporter,
2616 void **report_baton,
2617 const char *status_target,
2618 svn_revnum_t revision,
2619 svn_depth_t depth,
2620 const svn_delta_editor_t *status_editor,
2621 void *status_baton,
2622 apr_pool_t *pool)
2624 svn_ra_serf__session_t *session = ra_session->priv;
2626 return make_update_reporter(ra_session, reporter, report_baton,
2627 revision,
2628 session->repos_url.path, NULL, status_target,
2629 depth, FALSE, FALSE, FALSE,
2630 status_editor, status_baton, pool);
2633 svn_error_t *
2634 svn_ra_serf__do_switch(svn_ra_session_t *ra_session,
2635 const svn_ra_reporter3_t **reporter,
2636 void **report_baton,
2637 svn_revnum_t revision_to_switch_to,
2638 const char *switch_target,
2639 svn_depth_t depth,
2640 const char *switch_url,
2641 const svn_delta_editor_t *switch_editor,
2642 void *switch_baton,
2643 apr_pool_t *pool)
2645 svn_ra_serf__session_t *session = ra_session->priv;
2647 return make_update_reporter(ra_session, reporter, report_baton,
2648 revision_to_switch_to,
2649 session->repos_url.path,
2650 switch_url, switch_target,
2651 depth, TRUE, TRUE, FALSE /* TODO(sussman) */,
2652 switch_editor, switch_baton, pool);
2655 svn_error_t *
2656 svn_ra_serf__get_file(svn_ra_session_t *ra_session,
2657 const char *path,
2658 svn_revnum_t revision,
2659 svn_stream_t *stream,
2660 svn_revnum_t *fetched_rev,
2661 apr_hash_t **props,
2662 apr_pool_t *pool)
2664 svn_ra_serf__session_t *session = ra_session->priv;
2665 svn_ra_serf__connection_t *conn;
2666 svn_ra_serf__handler_t *handler;
2667 const char *fetch_url;
2668 apr_hash_t *fetch_props;
2670 /* What connection should we go on? */
2671 conn = session->conns[session->cur_conn];
2673 /* Fetch properties. */
2674 fetch_props = apr_hash_make(pool);
2676 fetch_url = svn_path_url_add_component(session->repos_url.path, path, pool);
2678 /* The simple case is if we want HEAD - then a GET on the fetch_url is fine.
2680 * Otherwise, we need to get the baseline version for this particular
2681 * revision and then fetch that file.
2683 if (SVN_IS_VALID_REVNUM(revision))
2685 const char *vcc_url, *rel_path, *baseline_url;
2687 SVN_ERR(svn_ra_serf__discover_root(&vcc_url, &rel_path,
2688 session, conn, fetch_url, pool));
2690 SVN_ERR(svn_ra_serf__retrieve_props(fetch_props, session, conn, vcc_url,
2691 revision, "0", baseline_props, pool));
2693 baseline_url = svn_ra_serf__get_ver_prop(fetch_props, vcc_url, revision,
2694 "DAV:", "baseline-collection");
2696 fetch_url = svn_path_url_add_component(baseline_url, rel_path, pool);
2697 revision = SVN_INVALID_REVNUM;
2700 /* TODO Filter out all of our props into a usable format. */
2701 if (props)
2703 *props = apr_hash_make(pool);
2705 SVN_ERR(svn_ra_serf__retrieve_props(fetch_props, session, conn, fetch_url,
2706 revision, "0", all_props, pool));
2708 svn_ra_serf__walk_all_props(fetch_props, fetch_url, revision,
2709 svn_ra_serf__set_flat_props, *props, pool);
2712 if (stream)
2714 report_fetch_t *stream_ctx;
2716 /* Create the fetch context. */
2717 stream_ctx = apr_pcalloc(pool, sizeof(*stream_ctx));
2718 stream_ctx->pool = pool;
2719 stream_ctx->target_stream = stream;
2720 stream_ctx->sess = session;
2721 stream_ctx->conn = conn;
2722 stream_ctx->info = apr_pcalloc(pool, sizeof(*stream_ctx->info));
2723 stream_ctx->info->name = fetch_url;
2725 handler = apr_pcalloc(pool, sizeof(*handler));
2726 handler->method = "GET";
2727 handler->path = fetch_url;
2728 handler->conn = conn;
2729 handler->session = session;
2731 handler->response_handler = handle_stream;
2732 handler->response_baton = stream_ctx;
2734 handler->response_error = cancel_fetch;
2735 handler->response_error_baton = stream_ctx;
2737 svn_ra_serf__request_create(handler);
2739 SVN_ERR(svn_ra_serf__context_run_wait(&stream_ctx->done, session, pool));
2740 SVN_ERR(stream_ctx->err);
2743 return SVN_NO_ERROR;