internal static unsafe SvnPropertyCollection CreatePropertyDictionary(apr_hash_t propHash, AprPool pool) { if (propHash == null) { throw new ArgumentNullException(nameof(propHash)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } var _properties = new SvnPropertyCollection(); for (var hi = apr_hash.apr_hash_first(pool.Handle, propHash); hi != null; hi = apr_hash.apr_hash_next(hi)) { sbyte *pKey; long keyLen = 0; svn_string_t.__Internal *propValPtr; apr_hash.apr_hash_this(hi, (void **)&pKey, ref keyLen, (void **)&propValPtr); var propVal = svn_string_t.__CreateInstance(new IntPtr(propValPtr)); _properties.Add(SvnPropertyValue.Create(pKey, propVal, null)); } return(_properties); }
/// <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 apr_hash_t CreateRevPropList(SvnRevisionPropertyCollection revProps, AprPool pool) { if (pool == null) { throw new ArgumentNullException(nameof(pool)); } if (revProps != null && revProps.Count != 0) { apr_hash_t items = apr_hash.apr_hash_make(pool.Handle); foreach (SvnPropertyValue value in revProps) { sbyte *key = pool.AllocString(value.Key); var val = pool.AllocSvnString((byte[])value.RawValue); apr_hash.apr_hash_set(items, new IntPtr(key), Constants.APR_HASH_KEY_STRING, val.__Instance); } return(items); } return(null); }
/// <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)); }
static unsafe apr_hash_t clone_credentials(apr_hash_t from, apr_hash_t to, AprPool pool) { if (from == null) { throw new ArgumentNullException(nameof(from)); } if (pool == null) { throw new ArgumentNullException(nameof(pool)); } // to can be null apr_hash_t hash_to = to ?? apr_hash.apr_hash_make(pool.Handle); sbyte * pKey; long len = default; void * pValue; void * pNewValue; using (var tmpPool = new AprPool(pool)) { for (var hi = apr_hash.apr_hash_first(tmpPool.Handle, from); hi != null; hi = apr_hash.apr_hash_next(hi)) { apr_hash.apr_hash_this(hi, (void **)&pKey, ref len, &pValue); pNewValue = null; if (pValue == null) { continue; } #if IMPLEMENTED if (MatchPrefix(pKey, Constants.SVN_AUTH_CRED_SIMPLE)) { pNewValue = clone_cred_usernamepassword((const svn_auth_cred_simple_t *)pValue, pool); } else if (MatchPrefix(pKey, Constants.SVN_AUTH_CRED_USERNAME)) { pNewValue = clone_cred_username((const svn_auth_cred_username_t *)pValue, pool); } else if (MatchPrefix(pKey, Constants.SVN_AUTH_CRED_SSL_CLIENT_CERT)) { pNewValue = clone_cred_ssl_clientcert((const svn_auth_cred_ssl_client_cert_t *)pValue, pool); } else if (MatchPrefix(pKey, Constants.SVN_AUTH_CRED_SSL_CLIENT_CERT_PW)) { pNewValue = clone_cred_ssl_clientcertpw((const svn_auth_cred_ssl_client_cert_pw_t *)pValue, pool); } else if (MatchPrefix(pKey, Constants.SVN_AUTH_CRED_SSL_SERVER_TRUST)) { pNewValue = clone_cred_ssl_servercert((const svn_auth_cred_ssl_server_trust_t *)pValue, pool); } /* else: Unknown -> Don't copy */ if (pNewValue != null) { // Create a 0 terminated copy of key char *pNewKey = (char *)apr_pcalloc(pool->Handle, len + 1); memcpy(pNewKey, pKey, len); apr_hash_set(hash_to, pNewKey, len, pNewValue); } #endif // IMPLEMENTED throw new NotImplementedException(); } } return(hash_to); }