/// <summary>Retrieves an authorization baton allocated in the specified pool; containing the current authorization settings</summary> internal unsafe svn_auth_baton_t GetAuthorizationBaton(ref int cookie) { if (_currentBaton != null && _cookie == cookie) { return(_currentBaton); } using var tmpPool = new AprPool(_parentPool); apr_hash_t creds = null; if (_currentBaton != null) { creds = clone_credentials(get_cache(_currentBaton), null, tmpPool); } _authPool.Clear(); var authArray = new AprArray <ISvnAuthWrapper, SvnAuthProviderMarshaller>(_handlers, _authPool); svn_auth_baton_t.__Internal *rsltPtr = null; svn_auth.svn_auth_open((void **)&rsltPtr, authArray.Handle, _authPool.Handle); var rslt = svn_auth_baton_t.__CreateInstance(new IntPtr(rsltPtr)); if (creds != null) { clone_credentials(creds, get_cache(rslt), _authPool); } if (_clientContext._configPath != null) { svn_auth.svn_auth_set_parameter( rslt, tmpPool.AllocString(Constants.SVN_AUTH_PARAM_CONFIG_DIR), new IntPtr(_authPool.AllocDirent(_clientContext._configPath))); } if (_forcedUser != null) { svn_auth.svn_auth_set_parameter( rslt, tmpPool.AllocString(Constants.SVN_AUTH_PARAM_DEFAULT_USERNAME), new IntPtr(_authPool.AllocString(_forcedUser))); } if (_forcedPassword != null) { svn_auth.svn_auth_set_parameter( rslt, tmpPool.AllocString(Constants.SVN_AUTH_PARAM_DEFAULT_PASSWORD), new IntPtr(_authPool.AllocString(_forcedPassword))); } _currentBaton = rslt; cookie = _cookie; return(rslt); }
internal static unsafe bool TryParse(string targetString, bool allowOperationalRevision, out SvnUriTarget target, AprPool pool) { if (string.IsNullOrEmpty(targetString)) { throw new ArgumentNullException(nameof(targetString)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } if (allowOperationalRevision) { svn_error_t r; sbyte * truePath; var path = pool.AllocString(targetString); if ((r = svn_opt.svn_opt_parse_path(out svn_opt_revision_t rev, &truePath, path, pool.Handle)) == null) { if (Uri.TryCreate(Utf8_PtrToString(truePath), UriKind.Absolute, out var uri)) { var pegRev = SvnRevision.Load(rev); target = new SvnUriTarget(uri, pegRev); return(true); } } else { svn_error.svn_error_clear(r); } }
static unsafe /*svn_error_t*/ IntPtr _svn_auth_simple_prompt_func( /*out svn_auth_cred_simple_t*/ void **credPtr, IntPtr baton, sbyte *realm, sbyte *username, int maySave, /*apr_pool_t*/ IntPtr pool) { var wrapper = AprBaton <SvnAuthWrapper <SvnUserNamePasswordEventArgs> > .Get(baton); var args = new SvnUserNamePasswordEventArgs(SvnBase.Utf8_PtrToString(username), SvnBase.Utf8_PtrToString(realm), maySave != 0); var cred = (svn_auth_cred_simple_t.__Internal * *)credPtr; using (var tmpPool = new AprPool(pool, false)) { *cred = null; try { wrapper.Raise(args); } catch (Exception e) { return(SvnException.CreateExceptionSvnError("Authorization handler", e).__Instance); } if (args.Cancel) { return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Authorization canceled operation").__Instance); } if (args.Break) { return(IntPtr.Zero); } *cred = (svn_auth_cred_simple_t.__Internal *)tmpPool.AllocCleared(sizeof(svn_auth_cred_simple_t.__Internal)); (*cred)->username = new IntPtr(tmpPool.AllocString(args.UserName)); (*cred)->password = new IntPtr(tmpPool.AllocString(args.Password)); (*cred)->may_save = args.Save ? 1 : 0; } return(IntPtr.Zero); }
/// <summary>Exports the specified target to the specified path</summary> /// <remarks>Subversion optimizes this call if you specify a workingcopy file instead of an url</remarks> public unsafe bool Export(SvnTarget from, string toPath, SvnExportArgs args, out SvnUpdateResult result) { if (from == null) { throw new ArgumentNullException(nameof(from)); } if (toPath == null) { throw new ArgumentNullException(nameof(toPath)); } if (args == null) { throw new ArgumentNullException(nameof(args)); } EnsureState(SvnContextState.AuthorizationInitialized); using var pool = new AprPool(_pool); using var store = new ArgsStore(this, args, pool); result = null; int resultRev = 0; svn_opt_revision_t pegRev = from.Revision.AllocSvnRevision(pool); svn_opt_revision_t rev = args.Revision.Or(from.GetSvnRevision(SvnRevision.Working, SvnRevision.Head)).AllocSvnRevision(pool); svn_error_t r = svn_client.svn_client_export5( ref resultRev, from.AllocAsString(pool), pool.AllocDirent(toPath), pegRev, rev, args.Overwrite, args.IgnoreExternals, args.IgnoreKeywords, (svn_depth_t)args.Depth, pool.AllocString(GetEolPtr(args.LineStyle)), CtxHandle, pool.Handle); if (args.HandleResult(this, r, from)) { result = SvnUpdateResult.Create(this, args, resultRev); return(true); } return(false); }
public unsafe void Write(ISvnAuthWrapper value, IntPtr ptr, AprPool pool) { var ppProvider = (svn_auth_provider_object_t.__Internal * *)ptr; *ppProvider = (svn_auth_provider_object_t.__Internal *)value.GetProviderPtr(pool).__Instance; if (*ppProvider == null) { var stub_provider = (svn_auth_provider_t.__Internal *)pool.AllocCleared( sizeof(svn_auth_provider_t.__Internal)); stub_provider->cred_kind = new IntPtr(pool.AllocString("LibSvnSharp-FakeType")); var pProvider = (svn_auth_provider_object_t.__Internal *)pool.AllocCleared( sizeof(svn_auth_provider_object_t.__Internal)); pProvider->vtable = new IntPtr(stub_provider); *ppProvider = pProvider; } }
internal unsafe SvnClientContext(AprPool pool) { if (pool is null) { throw new ArgumentNullException(nameof(pool)); } _ctxBaton = new AprBaton <SvnClientContext>(this); _callbacks = new SvnClientCallbacks(); _pool = pool; svn_client_ctx_t.__Internal *ctxInternal = null; // We manage the config hash ourselves var error = svn_client.svn_client_create_context2((void **)&ctxInternal, null, pool.Handle); if (error != null) { throw SvnException.Create(error); } var ctx = svn_client_ctx_t.__CreateInstance(new IntPtr(ctxInternal)); ctx.cancel_func = _callbacks.libsvnsharp_cancel_func.Get(); ctx.cancel_baton = _ctxBaton.Handle; ctx.progress_func = _callbacks.libsvnsharp_progress_func.Get(); ctx.progress_baton = _ctxBaton.Handle; ctx.log_msg_func3 = _callbacks.libsvnsharp_commit_log_func.Get(); ctx.log_msg_baton3 = _ctxBaton.Handle; //TODO: //ctx.check_tunnel_func = libsvnsharp_check_tunnel_func; //ctx.open_tunnel_func = libsvnsharp_open_tunnel_func; //ctx.tunnel_baton = _ctxBaton.Handle; ctx.client_name = pool.AllocString(SvnBase._clientName); _ctx = ctx; _authentication = new SvnAuthentication(this, pool); }
unsafe bool InternalSetProperty(string target, string propertyName, svn_string_t value, SvnSetPropertyArgs args, AprPool pool) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException(nameof(propertyName)); } if (string.IsNullOrEmpty(propertyName)) { throw new ArgumentNullException(nameof(propertyName)); } EnsureState(SvnContextState.ConfigLoaded); // We might need repository access using var store = new ArgsStore(this, args, pool); sbyte *pcPropertyName = pool.AllocString(propertyName); if (!svn_props.svn_prop_name_is_valid(pcPropertyName)) { throw new ArgumentException(SharpSvnStrings.PropertyNameIsNotValid, nameof(propertyName)); } svn_error_t r = svn_client.svn_client_propset_local( pcPropertyName, value, AllocDirentArray(NewSingleItemCollection(SvnTools.GetNormalizedFullPath(target)), pool), (svn_depth_t)args.Depth, args.SkipChecks, CreateChangeListsList(args.ChangeLists, pool), // Intersect ChangeLists CtxHandle, pool.Handle); return(args.HandleResult(this, r, target)); }
/// <summary>Sets the specified property on the specfied path to value</summary> /// <remarks>Use <see cref="DeleteProperty(string, string, SvnSetPropertyArgs)" /> to remove an existing property</remarks> public unsafe bool GetProperty(SvnTarget target, string propertyName, SvnGetPropertyArgs args, out SvnTargetPropertyCollection properties) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (propertyName == null) { throw new ArgumentNullException(nameof(propertyName)); } properties = null; EnsureState(SvnContextState.AuthorizationInitialized); using var pool = new AprPool(_pool); using var store = new ArgsStore(this, args, pool); var pegRev = target.Revision.AllocSvnRevision(pool); var rev = args.Revision.Or(target.Revision).AllocSvnRevision(pool); int actualRev = 0; apr_hash_t.__Internal *pHash = null; sbyte *pName = pool.AllocString(propertyName); sbyte *prefix = null; sbyte *targetName = target.AllocAsString(pool); if (!svn_path.svn_path_is_url(targetName)) { prefix = targetName; targetName = target.AllocAsString(pool, true); } svn_error_t r = svn_client.svn_client_propget5( (void **)&pHash, null, pName, targetName, pegRev, rev, ref actualRev, (svn_depth_t)args.Depth, CreateChangeListsList(args.ChangeLists, pool), // Intersect ChangeLists CtxHandle, pool.Handle, pool.Handle); if (pHash != null) { var rd = new SvnTargetPropertyCollection(); apr_hash_t hash = apr_hash_t.__CreateInstance(new IntPtr(pHash)); for (apr_hash_index_t hi = apr_hash.apr_hash_first(pool.Handle, hash); hi != null; hi = apr_hash.apr_hash_next(hi)) { sbyte *pKey; long keyLen = 0; svn_string_t.__Internal *propVal; apr_hash.apr_hash_this(hi, (void **)&pKey, ref keyLen, (void **)&propVal); SvnTarget itemTarget; if (prefix != null && !svn_path.svn_path_is_url(pKey)) { string path = Utf8_PathPtrToString( svn_dirent_uri.svn_dirent_join( prefix, svn_dirent_uri.svn_dirent_skip_ancestor(targetName, pKey), pool.Handle), pool); if (!string.IsNullOrEmpty(path)) { itemTarget = path; } else { itemTarget = "."; } } else { itemTarget = Utf8_PtrToUri(pKey, SvnNodeKind.Unknown); } var propValStr = svn_string_t.__CreateInstance(new IntPtr(propVal)); rd.Add(SvnPropertyValue.Create(pName, propValStr, itemTarget, propertyName)); } properties = rd; } return(args.HandleResult(this, r, target)); }