Example #1
0
        static unsafe /*svn_error_t*/ IntPtr _svn_auth_ssl_server_trust_prompt_func(
            /*out svn_auth_cred_ssl_server_trust_t*/ void **ppCred, IntPtr baton, sbyte *realm, uint failures, /*svn_auth_ssl_server_cert_info_t*/ IntPtr certInfo, int maySave, /*apr_pool_t*/ IntPtr pool)
        {
            var wrapper = AprBaton <SvnAuthWrapper <SvnSslServerTrustEventArgs> > .Get(baton);

            var certInfoT = svn_auth_ssl_server_cert_info_t.__CreateInstance(certInfo);

            var args = new SvnSslServerTrustEventArgs(
                (SvnCertificateTrustFailures)failures,
                SvnBase.Utf8_PtrToString(certInfoT.hostname),
                SvnBase.Utf8_PtrToString(certInfoT.fingerprint),
                SvnBase.Utf8_PtrToString(certInfoT.valid_from),
                SvnBase.Utf8_PtrToString(certInfoT.valid_until),
                SvnBase.Utf8_PtrToString(certInfoT.issuer_dname),
                SvnBase.Utf8_PtrToString(certInfoT.ascii_cert),
                SvnBase.Utf8_PtrToString(realm), maySave != 0);

            var cred = (svn_auth_cred_ssl_server_trust_t.__Internal * *)ppCred;

            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);
                }

                if (args.AcceptedFailures != SvnCertificateTrustFailures.None)
                {
                    *cred = (svn_auth_cred_ssl_server_trust_t.__Internal *)tmpPool.AllocCleared(
                        sizeof(svn_auth_cred_ssl_server_trust_t.__Internal));

                    (*cred)->accepted_failures = (uint)args.AcceptedFailures;
                    (*cred)->may_save          = args.Save ? 1 : 0;
                }
            }

            return(IntPtr.Zero);
        }
        static int cleanup_handler(IntPtr data)
        {
            var ptr = AprBaton <SvnExceptionContainer> .Get(data);

            System.Diagnostics.Debug.Assert(ptr._id == _idValue);

            if (ptr._id == _idValue)
            {
                ptr.Dispose();
            }

            return(0);
        }
Example #3
0
        static IntPtr svnclient_log_handler(IntPtr baton, IntPtr logEntryPtr, IntPtr pool)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            if (!(client.CurrentCommandArgs is SvnLogArgs args))
            {
                return(IntPtr.Zero);
            }

            var logEntry = svn_log_entry_t.__CreateInstance(logEntryPtr);

            if (logEntry.revision == -1)
            {
                // This marks the end of logs at this level,
                args._mergeLogLevel--;
                return(IntPtr.Zero);
            }

            using AprPool aprPool = new AprPool(pool, false);

            var e = new SvnLogEventArgs(logEntry, args._mergeLogLevel, args._searchRoot, aprPool);

            if (logEntry.has_children)
            {
                args._mergeLogLevel++;
            }

            try
            {
                args.OnLog(e);

                if (e.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CEASE_INVOCATION, null, "Log receiver canceled operation").__Instance);
                }
                else
                {
                    return(IntPtr.Zero);
                }
            }
            catch (Exception ex)
            {
                return(SvnException.CreateExceptionSvnError("Log receiver", ex).__Instance);
            }
            finally
            {
                e.Detach(false);
            }
        }
Example #4
0
        internal SvnClientContext(AprPool pool, SvnClientContext client)
        {
            if (client is null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _ctxBaton = new AprBaton <SvnClientContext>(this);

            _pool   = pool;
            _parent = client;

            _ctx            = client.CtxHandle;
            _authentication = client.Authentication;
        }
        public SvnExceptionContainer(Exception ex, apr_pool_t pool)
        {
            _id        = _idValue;
            _exception = ex;

            _baton = new AprBaton <SvnExceptionContainer>(this);

            apr_pools.apr_pool_cleanup_register(
                pool,
                _baton.Handle,
                _cleanupHandle.Get(),
                _cleanupNullHandle.Get());

            _exception = ex;
        }
Example #6
0
        static unsafe IntPtr svnclient_list_handler(
            IntPtr baton,
            sbyte *path,
            IntPtr dirent,
            IntPtr @lock,
            sbyte *absPath,
            sbyte *externalParentUrl,
            sbyte *externalTarget,
            IntPtr pool)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            if (!(client.CurrentCommandArgs is SvnListArgs args))
            {
                return(IntPtr.Zero);
            }

            var e = new SvnListEventArgs(
                path,
                svn_dirent_t.__CreateInstance(dirent),
                svn_lock_t.__CreateInstance(@lock),
                absPath,
                args.CalculateRepositoryRoot(absPath),
                externalParentUrl,
                externalTarget);

            try
            {
                args.OnList(e);

                if (e.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CEASE_INVOCATION, null, "List receiver canceled operation").__Instance);
                }
                else
                {
                    return(IntPtr.Zero);
                }
            }
            catch (Exception ex)
            {
                return(SvnException.CreateExceptionSvnError("List receiver", ex).__Instance);
            }
            finally
            {
                e.Detach(false);
            }
        }
Example #7
0
        protected SvnAuthWrapper(EventHandler <T> handler, SvnAuthentication authentication)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            if (authentication == null)
            {
                throw new ArgumentNullException(nameof(authentication));
            }

            _handler        = handler;
            _baton          = new AprBaton <SvnAuthWrapper <T> >(this);
            _authentication = authentication;
            _callbacks      = new AuthPromptWrappers();
            _retryLimit     = 128;
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        static unsafe IntPtr svnclient_status_handler(IntPtr baton, sbyte *path, IntPtr status_ptr, IntPtr scratch_pool)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            using var aprPool = new AprPool(scratch_pool, false);

            if (!(client.CurrentCommandArgs is SvnStatusArgs args))
            {
                return(IntPtr.Zero);
            }

            var status = svn_client_status_t.__CreateInstance(status_ptr);
            var e      = new SvnStatusEventArgs(path, status, client, aprPool);

            try
            {
                args.OnStatus(e);

                if (e.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CEASE_INVOCATION, null, "Status receiver canceled operation").__Instance);
                }
                else
                {
                    return(IntPtr.Zero);
                }
            }
            catch (Exception ex)
            {
                return(SvnException.CreateExceptionSvnError("Status receiver", ex).__Instance);
            }
            finally
            {
                e.Detach(false);
            }
        }
Example #11
0
        static unsafe IntPtr svn_info_receiver(IntPtr baton, sbyte *path, IntPtr info_ptr, IntPtr pool)
        {
            var client = AprBaton <SvnClient> .Get(baton);

            using var thePool = new AprPool(pool, false);

            if (!(client.CurrentCommandArgs is SvnInfoArgs args))
            {
                return(IntPtr.Zero);
            }

            var info = svn_client_info2_t.__CreateInstance(info_ptr);
            var e    = new SvnInfoEventArgs(SvnBase.Utf8_PathPtrToString(path, thePool), info, thePool);

            try
            {
                args.OnInfo(e);

                if (e.Cancel)
                {
                    return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CEASE_INVOCATION, null, "Info receiver canceled operation").__Instance);
                }
                else
                {
                    return(IntPtr.Zero);
                }
            }
            catch (Exception ex)
            {
                return(SvnException.CreateExceptionSvnError("Info receiver", ex).__Instance);
            }
            finally
            {
                e.Detach(false);
            }
        }
Example #12
0
 ///<summary>Initializes a new <see cref="SvnClient" /> instance with default properties</summary>
 public SvnClient() : base(new AprPool())
 {
     _clientBaton = new AprBaton <SvnClient>(this);
     Initialize();
 }
 public static SvnExceptionContainer Get(IntPtr handle)
 {
     return(AprBaton <SvnExceptionContainer> .Get(handle));
 }