2 * ra_loader.c: logic for loading different RA library implementations
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 /* ==================================================================== */
27 #define APR_WANT_STRFUNC
31 #include <apr_strings.h>
32 #include <apr_pools.h>
37 #include "svn_version.h"
39 #include "svn_types.h"
40 #include "svn_error.h"
41 #include "svn_error_codes.h"
42 #include "svn_pools.h"
43 #include "svn_delta.h"
48 #include "svn_props.h"
49 #include "svn_sorts.h"
51 #include "svn_config.h"
52 #include "ra_loader.h"
53 #include "deprecated.h"
55 #include "private/svn_auth_private.h"
56 #include "private/svn_ra_private.h"
57 #include "svn_private_config.h"
62 /* These are the URI schemes that the respective libraries *may* support.
63 * The schemes actually supported may be a subset of the schemes listed below.
64 * This can't be determine until the library is loaded.
65 * (Currently, this applies to the https scheme, which is only
66 * available if SSL is supported.) */
67 static const char * const dav_schemes[] = { "http", "https", NULL };
68 static const char * const svn_schemes[] = { "svn", NULL };
69 static const char * const local_schemes[] = { "file", NULL };
71 static const struct ra_lib_defn {
72 /* the name of this RA library (e.g. "neon" or "local") */
75 const char * const *schemes;
76 /* the initialization function if linked in; otherwise, NULL */
77 svn_ra__init_func_t initfunc;
78 svn_ra_init_func_t compat_initfunc;
83 #ifdef SVN_LIBSVN_CLIENT_LINKS_RA_SVN
85 svn_ra_svn__deprecated_init
92 #ifdef SVN_LIBSVN_CLIENT_LINKS_RA_LOCAL
94 svn_ra_local__deprecated_init
101 #ifdef SVN_LIBSVN_CLIENT_LINKS_RA_SERF
103 svn_ra_serf__deprecated_init
107 /* ADD NEW RA IMPLEMENTATIONS HERE (as they're written) */
113 /* Ensure that the RA library NAME is loaded.
115 * If FUNC is non-NULL, set *FUNC to the address of the svn_ra_NAME__init
116 * function of the library.
118 * If COMPAT_FUNC is non-NULL, set *COMPAT_FUNC to the address of the
119 * svn_ra_NAME_init compatibility init function of the library.
121 * ### todo: Any RA libraries implemented from this point forward
122 * ### don't really need an svn_ra_NAME_init compatibility function.
123 * ### Currently, load_ra_module() will error if no such function is
124 * ### found, but it might be more friendly to simply set *COMPAT_FUNC
125 * ### to null (assuming COMPAT_FUNC itself is non-null).
128 load_ra_module(svn_ra__init_func_t *func,
129 svn_ra_init_func_t *compat_func,
130 const char *ra_name, apr_pool_t *pool)
137 #if defined(SVN_USE_DSO) && APR_HAS_DSO
139 apr_dso_handle_t *dso;
140 apr_dso_handle_sym_t symbol;
142 const char *funcname;
143 const char *compat_funcname;
146 libname = apr_psprintf(pool, "libsvn_ra_%s-%d.so.%d",
147 ra_name, SVN_VER_MAJOR, SVN_SOVERSION);
148 funcname = apr_psprintf(pool, "svn_ra_%s__init", ra_name);
149 compat_funcname = apr_psprintf(pool, "svn_ra_%s_init", ra_name);
151 /* find/load the specified library */
152 SVN_ERR(svn_dso_load(&dso, libname));
156 /* find the initialization routines */
159 status = apr_dso_sym(&symbol, dso, funcname);
162 return svn_error_wrap_apr(status,
163 _("'%s' does not define '%s()'"),
167 *func = (svn_ra__init_func_t) symbol;
172 status = apr_dso_sym(&symbol, dso, compat_funcname);
175 return svn_error_wrap_apr(status,
176 _("'%s' does not define '%s()'"),
177 libname, compat_funcname);
180 *compat_func = (svn_ra_init_func_t) symbol;
183 #endif /* APR_HAS_DSO */
188 /* If SCHEMES contains URL, return the scheme. Else, return NULL. */
190 has_scheme_of(const char * const *schemes, const char *url)
194 for ( ; *schemes != NULL; ++schemes)
196 const char *scheme = *schemes;
197 len = strlen(scheme);
198 /* Case-insensitive comparison, per RFC 2396 section 3.1. Allow
199 URL to contain a trailing "+foo" section in the scheme, since
200 that's how we specify tunnel schemes in ra_svn. */
201 if (strncasecmp(scheme, url, len) == 0 &&
202 (url[len] == ':' || url[len] == '+'))
209 /* Return an error if RA_VERSION doesn't match the version of this library.
210 Use SCHEME in the error message to describe the library that was loaded. */
212 check_ra_version(const svn_version_t *ra_version, const char *scheme)
214 const svn_version_t *my_version = svn_ra_version();
215 if (!svn_ver_equal(my_version, ra_version))
216 return svn_error_createf(SVN_ERR_VERSION_MISMATCH, NULL,
217 _("Mismatched RA version for '%s':"
219 " expected %d.%d.%d%s"),
221 my_version->major, my_version->minor,
222 my_version->patch, my_version->tag,
223 ra_version->major, ra_version->minor,
224 ra_version->patch, ra_version->tag);
229 /* -------------------------------------------------------------- */
231 /*** Public Interfaces ***/
233 svn_error_t *svn_ra_initialize(apr_pool_t *pool)
235 #if defined(SVN_USE_DSO) && APR_HAS_DSO
236 /* Ensure that DSO subsystem is initialized early as possible if
237 we're going to use it. */
238 SVN_ERR(svn_dso_initialize2());
243 /* Please note: the implementation of svn_ra_create_callbacks is
244 * duplicated in libsvn_ra/wrapper_template.h:compat_open() . This
245 * duplication is intentional, is there to avoid a circular
246 * dependancy, and is justified in great length in the code of
247 * compat_open() in libsvn_ra/wrapper_template.h. If you modify the
248 * implementation of svn_ra_create_callbacks(), be sure to keep the
249 * code in wrapper_template.h:compat_open() in sync with your
252 svn_ra_create_callbacks(svn_ra_callbacks2_t **callbacks,
255 *callbacks = apr_pcalloc(pool, sizeof(**callbacks));
259 svn_error_t *svn_ra_open4(svn_ra_session_t **session_p,
260 const char **corrected_url_p,
261 const char *repos_URL,
263 const svn_ra_callbacks2_t *callbacks,
264 void *callback_baton,
268 apr_pool_t *sesspool = svn_pool_create(pool);
269 apr_pool_t *scratch_pool = svn_pool_create(sesspool);
270 svn_ra_session_t *session;
271 const struct ra_lib_defn *defn;
272 const svn_ra__vtable_t *vtable = NULL;
274 apr_status_t apr_err;
276 #ifdef CHOOSABLE_DAV_MODULE
277 const char *http_library = DEFAULT_HTTP_LIBRARY;
279 svn_auth_baton_t *auth_baton;
281 /* Initialize the return variable. */
284 apr_err = apr_uri_parse(sesspool, repos_URL, &repos_URI);
285 /* ### Should apr_uri_parse leave hostname NULL? It doesn't
286 * for "file:///" URLs, only for bogus URLs like "bogus".
287 * If this is the right behavior for apr_uri_parse, maybe we
288 * should have a svn_uri_parse wrapper. */
289 if (apr_err != APR_SUCCESS || repos_URI.hostname == NULL)
290 return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
291 _("Illegal repository URL '%s'"),
294 if (callbacks->auth_baton)
295 SVN_ERR(svn_auth__make_session_auth(&auth_baton,
296 callbacks->auth_baton, config,
298 sesspool, scratch_pool));
302 #ifdef CHOOSABLE_DAV_MODULE
305 svn_config_t *servers = NULL;
306 const char *server_group = NULL;
308 /* Grab the 'servers' config. */
309 servers = svn_hash_gets(config, SVN_CONFIG_CATEGORY_SERVERS);
312 /* First, look in the global section. */
314 /* Find out where we're about to connect to, and
315 * try to pick a server group based on the destination. */
316 server_group = svn_config_find_group(servers, repos_URI.hostname,
317 SVN_CONFIG_SECTION_GROUPS,
320 /* Now, which DAV-based RA method do we want to use today? */
322 = svn_config_get_server_setting(servers,
323 server_group, /* NULL is OK */
324 SVN_CONFIG_OPTION_HTTP_LIBRARY,
325 DEFAULT_HTTP_LIBRARY);
327 if (strcmp(http_library, "serf") != 0)
328 return svn_error_createf(SVN_ERR_BAD_CONFIG_VALUE, NULL,
329 _("Invalid config: unknown HTTP library "
336 /* Find the library. */
337 for (defn = ra_libraries; defn->ra_name != NULL; ++defn)
341 if ((scheme = has_scheme_of(defn->schemes, repos_URL)))
343 svn_ra__init_func_t initfunc = defn->initfunc;
345 #ifdef CHOOSABLE_DAV_MODULE
346 if (defn->schemes == dav_schemes
347 && strcmp(defn->ra_name, http_library) != 0)
352 SVN_ERR(load_ra_module(&initfunc, NULL, defn->ra_name,
355 /* Library not found. */
358 SVN_ERR(initfunc(svn_ra_version(), &vtable, scratch_pool));
360 SVN_ERR(check_ra_version(vtable->get_version(), scheme));
362 if (! has_scheme_of(vtable->get_schemes(scratch_pool), repos_URL))
363 /* Library doesn't support the scheme at runtime. */
372 return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
373 _("Unrecognized URL scheme for '%s'"),
376 /* Create the session object. */
377 session = apr_pcalloc(sesspool, sizeof(*session));
378 session->cancel_func = callbacks->cancel_func;
379 session->cancel_baton = callback_baton;
380 session->vtable = vtable;
381 session->pool = sesspool;
383 /* Ask the library to open the session. */
384 err = vtable->open_session(session, corrected_url_p,
386 callbacks, callback_baton, auth_baton,
387 config, sesspool, scratch_pool);
391 svn_pool_destroy(sesspool); /* Includes scratch_pool */
392 if (err->apr_err == SVN_ERR_RA_SESSION_URL_MISMATCH)
393 return svn_error_trace(err);
395 return svn_error_createf(
396 SVN_ERR_RA_CANNOT_CREATE_SESSION, err,
397 _("Unable to connect to a repository at URL '%s'"),
401 /* If the session open stuff detected a server-provided URL
402 correction (a 301 or 302 redirect response during the initial
403 OPTIONS request), then kill the session so the caller can decide
405 if (corrected_url_p && *corrected_url_p)
407 /* *session_p = NULL; */
408 *corrected_url_p = apr_pstrdup(pool, *corrected_url_p);
409 svn_pool_destroy(sesspool); /* Includes scratch_pool */
413 /* Check the UUID. */
416 const char *repository_uuid;
418 SVN_ERR(vtable->get_uuid(session, &repository_uuid, pool));
419 if (strcmp(uuid, repository_uuid) != 0)
421 /* Duplicate the uuid as it is allocated in sesspool */
422 repository_uuid = apr_pstrdup(pool, repository_uuid);
423 svn_pool_destroy(sesspool); /* includes scratch_pool */
424 return svn_error_createf(SVN_ERR_RA_UUID_MISMATCH, NULL,
425 _("Repository UUID '%s' doesn't match "
426 "expected UUID '%s'"),
427 repository_uuid, uuid);
431 svn_pool_destroy(scratch_pool);
432 *session_p = session;
437 svn_ra__dup_session(svn_ra_session_t **new_session,
438 svn_ra_session_t *old_session,
439 const char *session_url,
440 apr_pool_t *result_pool,
441 apr_pool_t *scratch_pool)
443 svn_ra_session_t *session;
449 /* This verifies in new_session_url is in the repository */
450 SVN_ERR(svn_ra_get_path_relative_to_root(old_session,
456 SVN_ERR(svn_ra_get_session_url(old_session, &session_url, scratch_pool));
458 /* Create the session object. */
459 session = apr_pcalloc(result_pool, sizeof(*session));
460 session->cancel_func = old_session->cancel_func;
461 session->cancel_baton = old_session->cancel_baton;
462 session->vtable = old_session->vtable;
463 session->pool = result_pool;
465 SVN_ERR(old_session->vtable->dup_session(session,
471 *new_session = session;
475 svn_error_t *svn_ra_reparent(svn_ra_session_t *session,
479 const char *repos_root;
481 /* Make sure the new URL is in the same repository, so that the
482 implementations don't have to do it. */
483 SVN_ERR(svn_ra_get_repos_root2(session, &repos_root, pool));
484 if (! svn_uri__is_ancestor(repos_root, url))
485 return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
486 _("'%s' isn't in the same repository as '%s'"),
489 return session->vtable->reparent(session, url, pool);
492 svn_error_t *svn_ra_get_session_url(svn_ra_session_t *session,
496 return session->vtable->get_session_url(session, url, pool);
499 svn_error_t *svn_ra_get_path_relative_to_session(svn_ra_session_t *session,
500 const char **rel_path,
504 const char *sess_url;
506 SVN_ERR(session->vtable->get_session_url(session, &sess_url, pool));
507 *rel_path = svn_uri_skip_ancestor(sess_url, url, pool);
509 return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
510 _("'%s' isn't a child of session URL '%s'"),
515 svn_error_t *svn_ra_get_path_relative_to_root(svn_ra_session_t *session,
516 const char **rel_path,
520 const char *root_url;
522 SVN_ERR(session->vtable->get_repos_root(session, &root_url, pool));
523 *rel_path = svn_uri_skip_ancestor(root_url, url, pool);
525 return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
526 _("'%s' isn't a child of repository root "
532 svn_error_t *svn_ra_get_latest_revnum(svn_ra_session_t *session,
533 svn_revnum_t *latest_revnum,
536 return session->vtable->get_latest_revnum(session, latest_revnum, pool);
539 svn_error_t *svn_ra_get_dated_revision(svn_ra_session_t *session,
540 svn_revnum_t *revision,
544 return session->vtable->get_dated_revision(session, revision, tm, pool);
547 svn_error_t *svn_ra_change_rev_prop2(svn_ra_session_t *session,
550 const svn_string_t *const *old_value_p,
551 const svn_string_t *value,
554 SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(rev));
556 /* If an old value was specified, make sure the server supports
560 svn_boolean_t has_atomic_revprops;
562 SVN_ERR(svn_ra_has_capability(session, &has_atomic_revprops,
563 SVN_RA_CAPABILITY_ATOMIC_REVPROPS,
566 if (!has_atomic_revprops)
567 /* API violation. (Should be an ASSERT, but gstein talked me
569 return svn_error_createf(SVN_ERR_UNSUPPORTED_FEATURE, NULL,
570 _("Specifying 'old_value_p' is not allowed when "
571 "the '%s' capability is not advertised, and "
572 "could indicate a bug in your client"),
573 SVN_RA_CAPABILITY_ATOMIC_REVPROPS);
576 return session->vtable->change_rev_prop(session, rev, name,
577 old_value_p, value, pool);
580 svn_error_t *svn_ra_rev_proplist(svn_ra_session_t *session,
585 SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(rev));
586 return session->vtable->rev_proplist(session, rev, props, pool);
589 svn_error_t *svn_ra_rev_prop(svn_ra_session_t *session,
592 svn_string_t **value,
595 SVN_ERR_ASSERT(SVN_IS_VALID_REVNUM(rev));
596 return session->vtable->rev_prop(session, rev, name, value, pool);
599 svn_error_t *svn_ra_get_commit_editor3(svn_ra_session_t *session,
600 const svn_delta_editor_t **editor,
602 apr_hash_t *revprop_table,
603 svn_commit_callback2_t commit_callback,
605 apr_hash_t *lock_tokens,
606 svn_boolean_t keep_locks,
609 return session->vtable->get_commit_editor(session, editor, edit_baton,
611 commit_callback, commit_baton,
612 lock_tokens, keep_locks, pool);
615 svn_error_t *svn_ra_get_file(svn_ra_session_t *session,
617 svn_revnum_t revision,
618 svn_stream_t *stream,
619 svn_revnum_t *fetched_rev,
623 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
624 return session->vtable->get_file(session, path, revision, stream,
625 fetched_rev, props, pool);
628 svn_error_t *svn_ra_get_dir2(svn_ra_session_t *session,
629 apr_hash_t **dirents,
630 svn_revnum_t *fetched_rev,
633 svn_revnum_t revision,
634 apr_uint32_t dirent_fields,
637 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
638 return session->vtable->get_dir(session, dirents, fetched_rev, props,
639 path, revision, dirent_fields, pool);
642 svn_error_t *svn_ra_get_mergeinfo(svn_ra_session_t *session,
643 svn_mergeinfo_catalog_t *catalog,
644 const apr_array_header_t *paths,
645 svn_revnum_t revision,
646 svn_mergeinfo_inheritance_t inherit,
647 svn_boolean_t include_descendants,
653 /* Validate path format. */
654 for (i = 0; i < paths->nelts; i++)
656 const char *path = APR_ARRAY_IDX(paths, i, const char *);
657 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
660 /* Check server Merge Tracking capability. */
661 err = svn_ra__assert_mergeinfo_capable_server(session, NULL, pool);
668 return session->vtable->get_mergeinfo(session, catalog, paths,
670 include_descendants, pool);
674 svn_ra_do_update3(svn_ra_session_t *session,
675 const svn_ra_reporter3_t **reporter,
677 svn_revnum_t revision_to_update_to,
678 const char *update_target,
680 svn_boolean_t send_copyfrom_args,
681 svn_boolean_t ignore_ancestry,
682 const svn_delta_editor_t *update_editor,
684 apr_pool_t *result_pool,
685 apr_pool_t *scratch_pool)
687 SVN_ERR_ASSERT(svn_path_is_empty(update_target)
688 || svn_path_is_single_path_component(update_target));
689 return session->vtable->do_update(session,
690 reporter, report_baton,
691 revision_to_update_to, update_target,
692 depth, send_copyfrom_args,
694 update_editor, update_baton,
695 result_pool, scratch_pool);
699 svn_ra_do_switch3(svn_ra_session_t *session,
700 const svn_ra_reporter3_t **reporter,
702 svn_revnum_t revision_to_switch_to,
703 const char *switch_target,
705 const char *switch_url,
706 svn_boolean_t send_copyfrom_args,
707 svn_boolean_t ignore_ancestry,
708 const svn_delta_editor_t *switch_editor,
710 apr_pool_t *result_pool,
711 apr_pool_t *scratch_pool)
713 SVN_ERR_ASSERT(svn_path_is_empty(switch_target)
714 || svn_path_is_single_path_component(switch_target));
715 return session->vtable->do_switch(session,
716 reporter, report_baton,
717 revision_to_switch_to, switch_target,
723 result_pool, scratch_pool);
726 svn_error_t *svn_ra_do_status2(svn_ra_session_t *session,
727 const svn_ra_reporter3_t **reporter,
729 const char *status_target,
730 svn_revnum_t revision,
732 const svn_delta_editor_t *status_editor,
736 SVN_ERR_ASSERT(svn_path_is_empty(status_target)
737 || svn_path_is_single_path_component(status_target));
738 return session->vtable->do_status(session,
739 reporter, report_baton,
740 status_target, revision, depth,
741 status_editor, status_baton, pool);
744 svn_error_t *svn_ra_do_diff3(svn_ra_session_t *session,
745 const svn_ra_reporter3_t **reporter,
747 svn_revnum_t revision,
748 const char *diff_target,
750 svn_boolean_t ignore_ancestry,
751 svn_boolean_t text_deltas,
752 const char *versus_url,
753 const svn_delta_editor_t *diff_editor,
757 SVN_ERR_ASSERT(svn_path_is_empty(diff_target)
758 || svn_path_is_single_path_component(diff_target));
759 return session->vtable->do_diff(session,
760 reporter, report_baton,
761 revision, diff_target,
762 depth, ignore_ancestry,
763 text_deltas, versus_url, diff_editor,
767 svn_error_t *svn_ra_get_log2(svn_ra_session_t *session,
768 const apr_array_header_t *paths,
772 svn_boolean_t discover_changed_paths,
773 svn_boolean_t strict_node_history,
774 svn_boolean_t include_merged_revisions,
775 const apr_array_header_t *revprops,
776 svn_log_entry_receiver_t receiver,
777 void *receiver_baton,
783 for (i = 0; i < paths->nelts; i++)
785 const char *path = APR_ARRAY_IDX(paths, i, const char *);
786 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
790 if (include_merged_revisions)
791 SVN_ERR(svn_ra__assert_mergeinfo_capable_server(session, NULL, pool));
793 return session->vtable->get_log(session, paths, start, end, limit,
794 discover_changed_paths, strict_node_history,
795 include_merged_revisions, revprops,
796 receiver, receiver_baton, pool);
799 svn_error_t *svn_ra_check_path(svn_ra_session_t *session,
801 svn_revnum_t revision,
802 svn_node_kind_t *kind,
805 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
806 return session->vtable->check_path(session, path, revision, kind, pool);
809 svn_error_t *svn_ra_stat(svn_ra_session_t *session,
811 svn_revnum_t revision,
812 svn_dirent_t **dirent,
816 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
817 err = session->vtable->stat(session, path, revision, dirent, pool);
819 /* svnserve before 1.2 doesn't support the above, so fall back on
820 a far less efficient, but still correct method. */
821 if (err && err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED)
823 /* ### TODO: Find out if we can somehow move this code in libsvn_ra_svn.
825 apr_pool_t *scratch_pool = svn_pool_create(pool);
826 svn_node_kind_t kind;
828 svn_error_clear(err);
830 SVN_ERR(svn_ra_check_path(session, path, revision, &kind, scratch_pool));
832 if (kind != svn_node_none)
834 const char *repos_root_url;
835 const char *session_url;
837 SVN_ERR(svn_ra_get_repos_root2(session, &repos_root_url,
839 SVN_ERR(svn_ra_get_session_url(session, &session_url,
842 if (!svn_path_is_empty(path))
843 session_url = svn_path_url_add_component2(session_url, path,
846 if (strcmp(session_url, repos_root_url) != 0)
848 svn_ra_session_t *parent_session;
849 apr_hash_t *parent_ents;
850 const char *parent_url, *base_name;
852 /* Open another session to the path's parent. This server
853 doesn't support svn_ra_reparent anyway, so don't try it. */
854 svn_uri_split(&parent_url, &base_name, session_url,
857 SVN_ERR(svn_ra__dup_session(&parent_session, session, parent_url,
858 scratch_pool, scratch_pool));
860 /* Get all parent's entries, no props. */
861 SVN_ERR(svn_ra_get_dir2(parent_session, &parent_ents, NULL,
862 NULL, "", revision, SVN_DIRENT_ALL,
865 /* Get the relevant entry. */
866 *dirent = svn_hash_gets(parent_ents, base_name);
869 *dirent = svn_dirent_dup(*dirent, pool);
874 const svn_string_t *val;
876 /* We can't get the directory entry for the repository root,
877 but we can still get the information we want.
878 The created-rev of the repository root must, by definition,
880 *dirent = apr_pcalloc(pool, sizeof(**dirent));
881 (*dirent)->kind = kind;
882 (*dirent)->size = SVN_INVALID_FILESIZE;
884 SVN_ERR(svn_ra_get_dir2(session, NULL, NULL, &props,
885 "", revision, 0 /* no dirent fields */,
887 (*dirent)->has_props = (apr_hash_count(props) != 0);
889 (*dirent)->created_rev = revision;
891 SVN_ERR(svn_ra_rev_proplist(session, revision, &props,
894 val = svn_hash_gets(props, SVN_PROP_REVISION_DATE);
896 SVN_ERR(svn_time_from_cstring(&(*dirent)->time, val->data,
899 val = svn_hash_gets(props, SVN_PROP_REVISION_AUTHOR);
900 (*dirent)->last_author = val ? apr_pstrdup(pool, val->data)
907 svn_pool_clear(scratch_pool);
915 svn_error_t *svn_ra_get_uuid2(svn_ra_session_t *session,
919 SVN_ERR(session->vtable->get_uuid(session, uuid, pool));
920 *uuid = *uuid ? apr_pstrdup(pool, *uuid) : NULL;
924 svn_error_t *svn_ra_get_uuid(svn_ra_session_t *session,
928 return session->vtable->get_uuid(session, uuid, pool);
931 svn_error_t *svn_ra_get_repos_root2(svn_ra_session_t *session,
935 SVN_ERR(session->vtable->get_repos_root(session, url, pool));
936 *url = *url ? apr_pstrdup(pool, *url) : NULL;
940 svn_error_t *svn_ra_get_repos_root(svn_ra_session_t *session,
944 return session->vtable->get_repos_root(session, url, pool);
947 svn_error_t *svn_ra_get_locations(svn_ra_session_t *session,
948 apr_hash_t **locations,
950 svn_revnum_t peg_revision,
951 const apr_array_header_t *location_revisions,
956 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
957 err = session->vtable->get_locations(session, locations, path,
958 peg_revision, location_revisions, pool);
959 if (err && (err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED))
961 svn_error_clear(err);
963 /* Do it the slow way, using get-logs, for older servers. */
964 err = svn_ra__locations_from_log(session, locations, path,
965 peg_revision, location_revisions,
972 svn_ra_get_location_segments(svn_ra_session_t *session,
974 svn_revnum_t peg_revision,
975 svn_revnum_t start_rev,
976 svn_revnum_t end_rev,
977 svn_location_segment_receiver_t receiver,
978 void *receiver_baton,
983 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
984 err = session->vtable->get_location_segments(session, path, peg_revision,
986 receiver, receiver_baton, pool);
987 if (err && (err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED))
989 svn_error_clear(err);
991 /* Do it the slow way, using get-logs, for older servers. */
992 err = svn_ra__location_segments_from_log(session, path,
993 peg_revision, start_rev,
995 receiver_baton, pool);
1000 svn_error_t *svn_ra_get_file_revs2(svn_ra_session_t *session,
1004 svn_boolean_t include_merged_revisions,
1005 svn_file_rev_handler_t handler,
1006 void *handler_baton,
1011 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1013 if (include_merged_revisions)
1014 SVN_ERR(svn_ra__assert_mergeinfo_capable_server(session, NULL, pool));
1016 if (start > end || !SVN_IS_VALID_REVNUM(start))
1018 svn_ra__assert_capable_server(session,
1019 SVN_RA_CAPABILITY_GET_FILE_REVS_REVERSE,
1023 err = session->vtable->get_file_revs(session, path, start, end,
1024 include_merged_revisions,
1025 handler, handler_baton, pool);
1026 if (err && (err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED)
1027 && !include_merged_revisions)
1029 svn_error_clear(err);
1031 /* Do it the slow way, using get-logs, for older servers. */
1032 err = svn_ra__file_revs_from_log(session, path, start, end,
1033 handler, handler_baton, pool);
1035 return svn_error_trace(err);
1038 svn_error_t *svn_ra_lock(svn_ra_session_t *session,
1039 apr_hash_t *path_revs,
1040 const char *comment,
1041 svn_boolean_t steal_lock,
1042 svn_ra_lock_callback_t lock_func,
1046 apr_hash_index_t *hi;
1048 for (hi = apr_hash_first(pool, path_revs); hi; hi = apr_hash_next(hi))
1050 const char *path = apr_hash_this_key(hi);
1052 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1055 if (comment && ! svn_xml_is_xml_safe(comment, strlen(comment)))
1056 return svn_error_create
1057 (SVN_ERR_XML_UNESCAPABLE_DATA, NULL,
1058 _("Lock comment contains illegal characters"));
1060 return session->vtable->lock(session, path_revs, comment, steal_lock,
1061 lock_func, lock_baton, pool);
1064 svn_error_t *svn_ra_unlock(svn_ra_session_t *session,
1065 apr_hash_t *path_tokens,
1066 svn_boolean_t break_lock,
1067 svn_ra_lock_callback_t lock_func,
1071 apr_hash_index_t *hi;
1073 for (hi = apr_hash_first(pool, path_tokens); hi; hi = apr_hash_next(hi))
1075 const char *path = apr_hash_this_key(hi);
1077 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1080 return session->vtable->unlock(session, path_tokens, break_lock,
1081 lock_func, lock_baton, pool);
1084 svn_error_t *svn_ra_get_lock(svn_ra_session_t *session,
1089 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1090 return session->vtable->get_lock(session, lock, path, pool);
1093 svn_error_t *svn_ra_get_locks2(svn_ra_session_t *session,
1099 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1100 SVN_ERR_ASSERT((depth == svn_depth_empty) ||
1101 (depth == svn_depth_files) ||
1102 (depth == svn_depth_immediates) ||
1103 (depth == svn_depth_infinity));
1104 return session->vtable->get_locks(session, locks, path, depth, pool);
1107 svn_error_t *svn_ra_get_locks(svn_ra_session_t *session,
1112 return svn_ra_get_locks2(session, locks, path, svn_depth_infinity, pool);
1115 svn_error_t *svn_ra_replay(svn_ra_session_t *session,
1116 svn_revnum_t revision,
1117 svn_revnum_t low_water_mark,
1118 svn_boolean_t text_deltas,
1119 const svn_delta_editor_t *editor,
1123 return session->vtable->replay(session, revision, low_water_mark,
1124 text_deltas, editor, edit_baton, pool);
1128 svn_ra__replay_ev2(svn_ra_session_t *session,
1129 svn_revnum_t revision,
1130 svn_revnum_t low_water_mark,
1131 svn_boolean_t send_deltas,
1132 svn_editor_t *editor,
1133 apr_pool_t *scratch_pool)
1135 SVN__NOT_IMPLEMENTED();
1138 static svn_error_t *
1139 replay_range_from_replays(svn_ra_session_t *session,
1140 svn_revnum_t start_revision,
1141 svn_revnum_t end_revision,
1142 svn_revnum_t low_water_mark,
1143 svn_boolean_t text_deltas,
1144 svn_ra_replay_revstart_callback_t revstart_func,
1145 svn_ra_replay_revfinish_callback_t revfinish_func,
1147 apr_pool_t *scratch_pool)
1149 apr_pool_t *iterpool = svn_pool_create(scratch_pool);
1152 for (rev = start_revision ; rev <= end_revision ; rev++)
1154 const svn_delta_editor_t *editor;
1156 apr_hash_t *rev_props;
1158 svn_pool_clear(iterpool);
1160 SVN_ERR(svn_ra_rev_proplist(session, rev, &rev_props, iterpool));
1162 SVN_ERR(revstart_func(rev, replay_baton,
1163 &editor, &edit_baton,
1166 SVN_ERR(svn_ra_replay(session, rev, low_water_mark,
1167 text_deltas, editor, edit_baton,
1169 SVN_ERR(revfinish_func(rev, replay_baton,
1174 svn_pool_destroy(iterpool);
1176 return SVN_NO_ERROR;
1180 svn_ra_replay_range(svn_ra_session_t *session,
1181 svn_revnum_t start_revision,
1182 svn_revnum_t end_revision,
1183 svn_revnum_t low_water_mark,
1184 svn_boolean_t text_deltas,
1185 svn_ra_replay_revstart_callback_t revstart_func,
1186 svn_ra_replay_revfinish_callback_t revfinish_func,
1191 session->vtable->replay_range(session, start_revision, end_revision,
1192 low_water_mark, text_deltas,
1193 revstart_func, revfinish_func,
1194 replay_baton, pool);
1196 if (!err || (err && (err->apr_err != SVN_ERR_RA_NOT_IMPLEMENTED)))
1197 return svn_error_trace(err);
1199 svn_error_clear(err);
1200 return svn_error_trace(replay_range_from_replays(session, start_revision,
1206 replay_baton, pool));
1210 svn_ra__replay_range_ev2(svn_ra_session_t *session,
1211 svn_revnum_t start_revision,
1212 svn_revnum_t end_revision,
1213 svn_revnum_t low_water_mark,
1214 svn_boolean_t send_deltas,
1215 svn_ra__replay_revstart_ev2_callback_t revstart_func,
1216 svn_ra__replay_revfinish_ev2_callback_t revfinish_func,
1218 svn_ra__provide_base_cb_t provide_base_cb,
1219 svn_ra__provide_props_cb_t provide_props_cb,
1220 svn_ra__get_copysrc_kind_cb_t get_copysrc_kind_cb,
1222 apr_pool_t *scratch_pool)
1224 if (session->vtable->replay_range_ev2 == NULL)
1226 /* The specific RA layer does not have an implementation. Use our
1227 default shim over the normal replay editor. */
1229 /* This will call the Ev1 replay range handler with modified
1231 return svn_error_trace(svn_ra__use_replay_range_shim(
1246 return svn_error_trace(session->vtable->replay_range_ev2(
1247 session, start_revision, end_revision,
1248 low_water_mark, send_deltas, revstart_func,
1249 revfinish_func, replay_baton, scratch_pool));
1252 svn_error_t *svn_ra_has_capability(svn_ra_session_t *session,
1254 const char *capability,
1257 return session->vtable->has_capability(session, has, capability, pool);
1261 svn_ra_get_deleted_rev(svn_ra_session_t *session,
1263 svn_revnum_t peg_revision,
1264 svn_revnum_t end_revision,
1265 svn_revnum_t *revision_deleted,
1270 /* Path must be relative. */
1271 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1273 if (!SVN_IS_VALID_REVNUM(peg_revision))
1274 return svn_error_createf(SVN_ERR_CLIENT_BAD_REVISION, NULL,
1275 _("Invalid peg revision %ld"), peg_revision);
1276 if (!SVN_IS_VALID_REVNUM(end_revision))
1277 return svn_error_createf(SVN_ERR_CLIENT_BAD_REVISION, NULL,
1278 _("Invalid end revision %ld"), end_revision);
1279 if (end_revision <= peg_revision)
1280 return svn_error_create(SVN_ERR_CLIENT_BAD_REVISION, NULL,
1281 _("Peg revision must precede end revision"));
1282 err = session->vtable->get_deleted_rev(session, path,
1287 if (err && (err->apr_err == SVN_ERR_UNSUPPORTED_FEATURE))
1289 svn_error_clear(err);
1291 /* Do it the slow way, using get-logs, for older servers. */
1292 err = svn_ra__get_deleted_rev_from_log(session, path, peg_revision,
1293 end_revision, revision_deleted,
1300 svn_ra_get_inherited_props(svn_ra_session_t *session,
1301 apr_array_header_t **iprops,
1303 svn_revnum_t revision,
1304 apr_pool_t *result_pool,
1305 apr_pool_t *scratch_pool)
1308 /* Path must be relative. */
1309 SVN_ERR_ASSERT(svn_relpath_is_canonical(path));
1311 err = session->vtable->get_inherited_props(session, iprops, path,
1312 revision, result_pool,
1315 if (err && err->apr_err == SVN_ERR_RA_NOT_IMPLEMENTED)
1317 svn_error_clear(err);
1319 /* Fallback for legacy servers. */
1320 SVN_ERR(svn_ra__get_inherited_props_walk(session, path, revision, iprops,
1321 result_pool, scratch_pool));
1326 return SVN_NO_ERROR;
1330 svn_ra__get_commit_ev2(svn_editor_t **editor,
1331 svn_ra_session_t *session,
1332 apr_hash_t *revprop_table,
1333 svn_commit_callback2_t commit_callback,
1335 apr_hash_t *lock_tokens,
1336 svn_boolean_t keep_locks,
1337 svn_ra__provide_base_cb_t provide_base_cb,
1338 svn_ra__provide_props_cb_t provide_props_cb,
1339 svn_ra__get_copysrc_kind_cb_t get_copysrc_kind_cb,
1341 apr_pool_t *result_pool,
1342 apr_pool_t *scratch_pool)
1344 if (session->vtable->get_commit_ev2 == NULL)
1346 /* The specific RA layer does not have an implementation. Use our
1347 default shim over the normal commit editor. */
1349 return svn_error_trace(svn_ra__use_commit_shim(
1353 commit_callback, commit_baton,
1358 get_copysrc_kind_cb,
1360 session->cancel_func, session->cancel_baton,
1361 result_pool, scratch_pool));
1364 /* Note: no need to remap the callback for Ev2. RA layers providing this
1365 vtable entry should completely fill in commit_info. */
1367 return svn_error_trace(session->vtable->get_commit_ev2(
1371 commit_callback, commit_baton,
1376 get_copysrc_kind_cb,
1378 session->cancel_func, session->cancel_baton,
1379 result_pool, scratch_pool));
1384 svn_ra_print_modules(svn_stringbuf_t *output,
1387 const struct ra_lib_defn *defn;
1388 const char * const *schemes;
1389 svn_ra__init_func_t initfunc;
1390 const svn_ra__vtable_t *vtable;
1391 apr_pool_t *iterpool = svn_pool_create(pool);
1393 for (defn = ra_libraries; defn->ra_name != NULL; ++defn)
1397 svn_pool_clear(iterpool);
1399 initfunc = defn->initfunc;
1401 SVN_ERR(load_ra_module(&initfunc, NULL, defn->ra_name,
1406 SVN_ERR(initfunc(svn_ra_version(), &vtable, iterpool));
1408 SVN_ERR(check_ra_version(vtable->get_version(), defn->ra_name));
1410 /* Note: if you change the formatting of the description,
1411 bear in mind that ra_svn's description has multiple lines when
1413 line = apr_psprintf(iterpool, "* ra_%s : %s\n",
1415 vtable->get_description(iterpool));
1416 svn_stringbuf_appendcstr(output, line);
1418 for (schemes = vtable->get_schemes(iterpool); *schemes != NULL;
1421 line = apr_psprintf(iterpool, _(" - handles '%s' scheme\n"),
1423 svn_stringbuf_appendcstr(output, line);
1428 svn_pool_destroy(iterpool);
1430 return SVN_NO_ERROR;
1435 svn_ra_print_ra_libraries(svn_stringbuf_t **descriptions,
1439 *descriptions = svn_stringbuf_create_empty(pool);
1440 return svn_ra_print_modules(*descriptions, pool);
1445 svn_ra__register_editor_shim_callbacks(svn_ra_session_t *session,
1446 svn_delta_shim_callbacks_t *callbacks)
1448 SVN_ERR(session->vtable->register_editor_shim_callbacks(session, callbacks));
1449 return SVN_NO_ERROR;
1453 /* Return the library version number. */
1454 const svn_version_t *
1455 svn_ra_version(void)
1461 /*** Compatibility Interfaces **/
1463 svn_ra_init_ra_libs(void **ra_baton,
1467 return SVN_NO_ERROR;
1471 svn_ra_get_ra_library(svn_ra_plugin_t **library,
1476 const struct ra_lib_defn *defn;
1477 apr_pool_t *load_pool = ra_baton;
1478 apr_hash_t *ht = apr_hash_make(pool);
1480 /* Figure out which RA library key matches URL. */
1481 for (defn = ra_libraries; defn->ra_name != NULL; ++defn)
1484 if ((scheme = has_scheme_of(defn->schemes, url)))
1486 svn_ra_init_func_t compat_initfunc = defn->compat_initfunc;
1488 if (! compat_initfunc)
1490 SVN_ERR(load_ra_module
1491 (NULL, &compat_initfunc, defn->ra_name, load_pool));
1493 if (! compat_initfunc)
1498 SVN_ERR(compat_initfunc(SVN_RA_ABI_VERSION, load_pool, ht));
1500 *library = svn_hash_gets(ht, scheme);
1502 /* The library may support just a subset of the schemes listed,
1503 so we have to check here too. */
1507 return check_ra_version((*library)->get_version(), scheme);
1511 /* Couldn't find a match... */
1513 return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL,
1514 _("Unrecognized URL scheme '%s'"), url);
1517 /* For each libsvn_ra_foo library that is not linked in, provide a default
1518 implementation for svn_ra_foo_init which returns a "not implemented"
1521 #ifndef SVN_LIBSVN_CLIENT_LINKS_RA_NEON
1523 svn_ra_dav_init(int abi_version,
1527 return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, NULL, NULL);
1529 #endif /* ! SVN_LIBSVN_CLIENT_LINKS_RA_NEON */
1531 #ifndef SVN_LIBSVN_CLIENT_LINKS_RA_SVN
1533 svn_ra_svn_init(int abi_version,
1537 return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, NULL, NULL);
1539 #endif /* ! SVN_LIBSVN_CLIENT_LINKS_RA_SVN */
1541 #ifndef SVN_LIBSVN_CLIENT_LINKS_RA_LOCAL
1543 svn_ra_local_init(int abi_version,
1547 return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, NULL, NULL);
1549 #endif /* ! SVN_LIBSVN_CLIENT_LINKS_RA_LOCAL */
1551 #ifndef SVN_LIBSVN_CLIENT_LINKS_RA_SERF
1553 svn_ra_serf_init(int abi_version,
1557 return svn_error_create(SVN_ERR_RA_NOT_IMPLEMENTED, NULL, NULL);
1559 #endif /* ! SVN_LIBSVN_CLIENT_LINKS_RA_SERF */