#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static svn_opt_revision_t revision_head; static svn_opt_revision_t revision_unspecified; char *svnwiki_user, *svnwiki_pass; apr_pool_t *chicken_svn_client_global_pool; apr_pool_t *chicken_svn_client_global_auth_pool = NULL; svn_client_ctx_t *svn_ctx; static apr_array_header_t *auth_providers; svn_error_t * svnwiki_simple_first_credentials (void **credentials, void **iter_baton, void *provider_baton, apr_hash_t *parameters, const char *realmstring, apr_pool_t *pool) { svn_auth_cred_simple_t *cred; if (svnwiki_user == NULL) { *credentials = NULL; return 0; } *credentials = cred = apr_pcalloc(pool, sizeof(svn_auth_cred_simple_t)); cred->username = apr_pstrdup (pool, svnwiki_user); cred->password = apr_pstrdup (pool, svnwiki_pass); cred->may_save = 0; return 0; } svn_error_t * svnwiki_username_first_credentials (void **credentials, void **iter_baton, void *provider_baton, apr_hash_t *parameters, const char *realmstring, apr_pool_t *pool) { svn_auth_cred_username_t *cred; if (svnwiki_user == NULL) { *credentials = NULL; return 0; } *credentials = cred = apr_pcalloc(pool, sizeof(svn_auth_cred_username_t)); cred->username = apr_pstrdup (pool, svnwiki_user); cred->may_save = 0; return 0; } svn_error_t * svnwiki_log_callback (const char **log_msg, const char **tmp_file, apr_array_header_t *commit_items, void *baton, apr_pool_t *pool) { *tmp_file = NULL; *log_msg = baton; return SVN_NO_ERROR; } /* Pick the highest revision created */ svn_error_t * svnclient_commit_set_revision(const svn_commit_info_t *commit_info, void *baton, apr_pool_t *pool) { C_word *rev = (C_word *)baton; if (!(*rev & C_FIXNUM_BIT) || C_unfix(*rev) < commit_info->revision) { *rev = C_fix(commit_info->revision); } return SVN_NO_ERROR; } svn_auth_provider_t svnwiki_auth_simple = { SVN_AUTH_CRED_SIMPLE, svnwiki_simple_first_credentials, NULL, NULL }; svn_auth_provider_object_t svnwiki_auth_simple_obj = { &svnwiki_auth_simple, NULL }; svn_auth_provider_t svnwiki_auth_username = { SVN_AUTH_CRED_USERNAME, svnwiki_username_first_credentials, NULL, NULL }; svn_auth_provider_object_t svnwiki_auth_username_obj = { &svnwiki_auth_username, NULL }; void set_creds_for_next_command(char *user, char *pass) { svn_auth_provider_object_t *provider; svnwiki_user = user; svnwiki_pass = pass; if (chicken_svn_client_global_auth_pool != NULL) svn_pool_destroy(chicken_svn_client_global_auth_pool); chicken_svn_client_global_auth_pool = svn_pool_create(chicken_svn_client_global_pool); auth_providers = apr_array_make(chicken_svn_client_global_auth_pool, 3, sizeof(svn_auth_provider_object_t *)); APR_ARRAY_PUSH(auth_providers, svn_auth_provider_object_t *) = &svnwiki_auth_simple_obj; APR_ARRAY_PUSH(auth_providers, svn_auth_provider_object_t *) = &svnwiki_auth_username_obj; /* Always allow default SSL server overrides from user's config */ svn_auth_get_ssl_server_trust_file_provider(&provider, chicken_svn_client_global_auth_pool); APR_ARRAY_PUSH(auth_providers, svn_auth_provider_object_t *) = provider; svn_auth_open(&svn_ctx->auth_baton, auth_providers, chicken_svn_client_global_auth_pool); } char *svnclient_canonicalize_path_or_url(const char *path_or_url) { char *result; const char *canonical; apr_pool_t *tmp_pool; int len; tmp_pool = svn_pool_create(NULL); if (svn_path_is_url(path_or_url)) { canonical = svn_uri_canonicalize(path_or_url, tmp_pool); } else { canonical = svn_dirent_canonicalize(path_or_url, tmp_pool); } len = strlen(canonical)+1; result = malloc(len); if (result == NULL) { svn_pool_destroy(tmp_pool); return NULL; } memcpy(result, canonical, len); svn_pool_destroy(tmp_pool); return result; } void chicken_svn_client_lib_initialize() { apr_status_t status; status = apr_initialize(); if (status != APR_SUCCESS) { exit(1); } chicken_svn_client_global_pool = svn_pool_create(NULL); if (chicken_svn_client_global_pool == NULL) { exit (2); } svn_utf_initialize2(FALSE, chicken_svn_client_global_pool); svn_config_ensure(NULL, chicken_svn_client_global_pool); svn_ra_initialize(chicken_svn_client_global_pool); svn_client_create_context2(&svn_ctx, NULL, chicken_svn_client_global_pool); svn_config_get_config(&svn_ctx->config, NULL, chicken_svn_client_global_pool); /* Initialize authentication */ svnwiki_user = NULL; svnwiki_pass = NULL; revision_head.kind = svn_opt_revision_head; revision_unspecified.kind = svn_opt_revision_unspecified; }