// Decompiled with JetBrains decompiler // Type: Rei.Fs.Webdav.WebdavFs // Assembly: Rei.Fs.Webdav, Version=1.13.2.18288, Culture=neutral, PublicKeyToken=null // MVID: D30DD1E3-8520-48B5-AAE5-C87970350A82 // Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\Rei.Fs.Webdav.dll using Microsoft.VisualBasic.CompilerServices; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Globalization; using System.IO; using System.IO.Compression; using System.Net; using System.Net.Security; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Xml; namespace Rei.Fs.Webdav { public class WebdavFs : FsBase { public const string NameSpace_DAV = "DAV:"; public const string NameSpace_urnmicrosoft = "urn:schemas-microsoft-com:"; public const string DAV_CreationDate = "DAV:creationdate"; public const string DAV_DisplayName = "DAV:displayname"; public const string DAV_GetContentLanguage = "DAV:getcontentlanguage"; public const string DAV_GetContentLength = "DAV:getcontentlength"; public const string DAV_GetContentType = "DAV:getcontenttype"; public const string DAV_GetETag = "DAV:getetag"; public const string DAV_GetLastModified = "DAV:getlastmodified"; public const string DAV_ResourceType = "DAV:resourcetype"; public const string Microsoft_Win32CreationTime = "urn:schemas-microsoft-com:Win32CreationTime"; public const string Microsoft_Win32LastModifiedTime = "urn:schemas-microsoft-com:Win32LastModifiedTime"; public const string Microsoft_Win32LastAccessTime = "urn:schemas-microsoft-com:Win32LastAccessTime"; public const string Microsoft_Win32FileAttribute = "urn:schemas-microsoft-com:Win32FileAttributes"; private static string pDefClientName; private static FieldInfo WebHeader_InnerCollectionInfo; private static FieldInfo s_ModuleBindingInfo; private static FieldInfo m_StoreInfo; private static FieldInfo challengeCacheinfo; private static WebdavFs.WebDAVCredentialManager pCredentialPolicy; public bool UseDefaultCredential; public bool UsePreAuthentication_Basic; public bool UsePreAuthentication_WSSE; private string[] pAuthModules; public X509Certificate2Collection ClientCertificates; private bool UsePassportAuthentication; public SslProtocols DisableTlsVersions; public Encoding URIRequestEncoding; public Encoding URIResponseEncoding; public Encoding CredentialEncoding; public bool DontRequestGzip; public bool DontRequestDeflate; public bool RequestTranslatef; public bool DontExpect100; public bool SendEmptyPUT; public bool DontUpdateProperty; public bool UseFullUriInDestinationHeader; public string UploadCompression; public int MaxRedirection; public bool DontVerifyContentRange; public bool RedirectionCollectionOnly; public bool RemoveLastSlashOnMKCOL; public bool DisableUploadResume; public IWebProxy Proxy; public int ReadWriteTimeout; public int ConnectTimeout; private PassportAuthHelper pPassportAuthHelper; private string pLastAuthType; private List pServicePointList; private Uri pLastUri; static WebdavFs() { UriParserFixer.Register(); AuthenticationManager.Register((IAuthenticationModule) new WsseClient()); WebdavFs.pCredentialPolicy = new WebdavFs.WebDAVCredentialManager(); AuthenticationManager.CredentialPolicy = (ICredentialPolicy) WebdavFs.pCredentialPolicy; WebdavFs.WebHeader_InnerCollectionInfo = typeof (WebHeaderCollection).GetField("m_InnerCollection", BindingFlags.Instance | BindingFlags.NonPublic); try { object obj = (object) null; IEnumerator registeredModules = AuthenticationManager.RegisteredModules; while (registeredModules.MoveNext()) { if (Operators.CompareString(((IAuthenticationModule) registeredModules.Current).AuthenticationType, "Digest", false) == 0) { obj = (object) (IAuthenticationModule) registeredModules.Current; break; } } if (obj == null) throw new Exception("No digest authentication module"); WebdavFs.s_ModuleBindingInfo = typeof (AuthenticationManager).GetField("s_ModuleBinding", BindingFlags.Static | BindingFlags.NonPublic); WebdavFs.m_StoreInfo = WebdavFs.s_ModuleBindingInfo.FieldType.GetField("m_Store", BindingFlags.Instance | BindingFlags.NonPublic); WebdavFs.challengeCacheinfo = obj.GetType().GetField("challengeCache", BindingFlags.Static | BindingFlags.NonPublic); } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } Assembly executingAssembly = Assembly.GetExecutingAssembly(); WebdavFs.pDefClientName = ((AssemblyProductAttribute) executingAssembly.GetCustomAttributes(typeof (AssemblyProductAttribute), false)[0]).Product + "/" + executingAssembly.GetName().Version.ToString(3); } internal static bool ShouldSendCredential(Uri challengeUri, WebRequest request, NetworkCredential credential, IAuthenticationModule authenticationModule) { string lower = authenticationModule.AuthenticationType.ToLower(); ConnectionSetting connectionSetting = WebRequestCertificateValidationManager.GetConnectionSetting(request) as ConnectionSetting; if (connectionSetting == null) return false; string[] authModules = connectionSetting.AuthModules; if (authModules == null || authModules.Length == 0) return true; string[] strArray = authModules; int index = 0; while (index < strArray.Length) { if (Operators.CompareString(strArray[index].ToLower(), lower, false) == 0) return true; checked { ++index; } } return false; } public WebdavFs(ConnectionSetting setting) : base((ConnectionSettingBase) setting) { this.ClientName = WebdavFs.pDefClientName; this.ReadWriteTimeout = 10000; this.ConnectTimeout = 10000; this.URIRequestEncoding = Encoding.GetEncoding("utf-8"); this.URIResponseEncoding = Encoding.GetEncoding("utf-8"); this.CredentialEncoding = Encoding.GetEncoding("utf-8"); this.AuthModules = new string[0]; this.ClientCertificates = new X509Certificate2Collection(); this.UploadCompression = "None"; this.MaxRedirection = 2; this.pServicePointList = new List(); } public string[] AuthModules { get { return this.pAuthModules; } set { if (value == null) value = new string[0]; this.pAuthModules = value; int num1 = 0; int num2 = checked (this.pAuthModules.Length - 1); int index = num1; while (index <= num2) { if (Operators.CompareString(this.pAuthModules[index].ToUpper(), "Passport".ToUpper(), false) == 0) { this.UsePassportAuthentication = true; return; } checked { ++index; } } if (this.pAuthModules.Length == 0) this.UsePassportAuthentication = true; else this.UsePassportAuthentication = false; } } public PassportAuthHelper PassportAuth { get { if (this.pPassportAuthHelper == null) { this.pPassportAuthHelper = new PassportAuthHelper(); this.pPassportAuthHelper.UserAgent = this.ClientName; this.pPassportAuthHelper.Proxy = this.Proxy; this.pPassportAuthHelper.ReadWriteTimeout = this.ReadWriteTimeout; this.pPassportAuthHelper.ConnectTimeout = this.ConnectTimeout; this.pPassportAuthHelper.CookieContainer = this.ConnectionSetting.CookieContainer; this.pPassportAuthHelper.GroupName = this.GroupName; } return this.pPassportAuthHelper; } } public string LastAuthType { get { return this.pLastAuthType; } } public override SecureType LastSecureType { get { if ((object) this.pLastUri != null && Operators.CompareString(this.pLastUri.Scheme, Uri.UriSchemeHttps, false) == 0) return this.ConnectionSetting.LastCertError == SslPolicyErrors.None ? SecureType.Secure : SecureType.Warning; return Operators.CompareString(this.LastAuthType.ToLowerInvariant(), "basic", false) == 0 ? SecureType.Warning : SecureType.None; } } public override FsAbility Ability { get { return this.DisableUploadResume ? FsAbility.AdvancedFs | FsAbility.Times | FsAbility.Lock | FsAbility.MoveOver | FsAbility.CopyOver | FsAbility.PartialRead | FsAbility.Property : FsAbility.All; } } public override void ResetConnection() { bool flag1 = true; List.Enumerator enumerator = this.pServicePointList.GetEnumerator(); ; try { while (enumerator.MoveNext()) { ServicePoint current = enumerator.Current; try { flag1 &= current.CloseConnectionGroup(this.GroupName); } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } } } finally { enumerator.Dispose(); } this.pServicePointList.Clear(); try { if (this.pPassportAuthHelper != null) { bool flag2 = flag1 & this.pPassportAuthHelper.ResetConnection(); } } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } base.ResetConnection(); } public Uri HeadResource(Uri target) { int num = 0; string str = (string) null; WebdavFs.CheckUri(target); Uri uri = UriUtil.UriEncodeConvert(target, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri); request.Method = "HEAD"; request.ContentLength = 0L; if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri = new Uri(uri, response.Headers[HttpResponseHeader.Location]); } else { if (!WebdavFs.CheckStatus(response)) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); return UriUtil.UriEncodeConvert(response.ResponseUri, this.URIResponseEncoding, (Encoding) null); } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(target, (Exception) simpleWebException); throw; } } } } public DavResourceOptions GetResourceOptions(Uri target) { int num = 0; string str = (string) null; WebdavFs.CheckUri(target); Uri uri = UriUtil.UriEncodeConvert(target, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri); request.Method = "OPTIONS"; if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri = new Uri(uri, response.Headers[HttpResponseHeader.Location]); } else { if (!WebdavFs.CheckStatus(response)) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); return new DavResourceOptions(UriUtil.UriEncodeConvert(response.ResponseUri, this.URIResponseEncoding, (Encoding) null), response); } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(target, (Exception) simpleWebException); throw; } } } } public override ResourceInfo GetInfo(Uri targeturi) { WebdavFs.CheckUri(targeturi); return this.InnerGetInfo(targeturi, WebdavFs.DepthType.Depth_0)[0]; } public override ResourceInfo GetInfo(ResourceId id) { return this.InnerGetInfo(id.Uri, WebdavFs.DepthType.Depth_0)[0]; } public override ResourceInfo GetInfo(ResourceId parentid, string name) { return this.InnerGetInfo(UriUtil.CombineName(parentid.Uri, name), WebdavFs.DepthType.Depth_0)[0]; } public override ResourceInfo[] GetEntries(ResourceId id) { List info = this.InnerGetInfo(id.Uri, WebdavFs.DepthType.Depth_1); if (info.Count >= 1) info.RemoveAt(0); return info.ToArray(); } public override ResourceInfo[] GetInfoAndEntries(ResourceId id) { return this.InnerGetInfo(id.Uri, WebdavFs.DepthType.Depth_1).ToArray(); } public override ResourceInfo[] GetInfoAndEntries(Uri targeturi) { WebdavFs.CheckUri(targeturi); return this.InnerGetInfo(targeturi, WebdavFs.DepthType.Depth_1).ToArray(); } public override ResourceInfo[] GetParentInfoAndEntries(ResourceId childid) { return this.InnerGetInfo(UriUtil.GetParent(childid.Uri), WebdavFs.DepthType.Depth_1).ToArray(); } private List InnerGetInfo(Uri target, WebdavFs.DepthType depth) { int num = 0; string str1 = (string) null; Uri uri = UriUtil.UriEncodeConvert(target, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri); request.Method = "PROPFIND"; string str2 = string.Empty; if (!this.DontRequestDeflate) str2 = "deflate"; if (!this.DontRequestGzip) { if (str2.Length > 0) str2 += ", "; str2 += "gzip"; } if (str2.Length > 0) request.Headers.Add(HttpRequestHeader.AcceptEncoding, str2); switch (depth) { case WebdavFs.DepthType.Depth_infinity: request.Headers.Add("Depth", "infinity"); break; case WebdavFs.DepthType.Depth_0: request.Headers.Add("Depth", "0"); break; case WebdavFs.DepthType.Depth_1: request.Headers.Add("Depth", "1"); break; } request.ContentLength = 0L; if (str1 != null) request.Headers.Add(HttpRequestHeader.Authorization, str1); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str1 = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri = new Uri(uri, response.Headers[HttpResponseHeader.Location]); } else { if (response.StatusCode != (HttpStatusCode) 207) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); List propfindResponse = this.ParsePROPFINDResponse(this.GetResponseBody(response), response.ResponseUri); if (this.RedirectionCollectionOnly && !propfindResponse[0].IsCollection) propfindResponse[0].Id = new ResourceId(target, (FsBase) this); return propfindResponse; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(target, (Exception) simpleWebException); throw; } } } } public override ReturnedInfo CreateCollection(ResourceId parendid, string name) { Uri uri1 = UriUtil.AddLastSlash(UriUtil.CombineName(parendid.Uri, name)); int num = 0; string str = (string) null; Uri uri2 = !this.RemoveLastSlashOnMKCOL ? UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding) : UriUtil.UriEncodeConvert(UriUtil.RemoveLastSlash(uri1), (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri2); request.Method = "MKCOL"; request.ContentLength = 0L; if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri2 = new Uri(uri2, response.Headers[HttpResponseHeader.Location]); } else { if (!WebdavFs.CheckStatus(response)) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); break; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri2.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri2 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); throw; } } } return (ReturnedInfo) new ResourceId(uri1, (FsBase) this); } public override void Delete(ResourceId id) { Uri uri1 = id.Uri; int num = 0; string str = (string) null; WebdavFs.CheckUri(uri1); Uri uri2 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri2); request.Method = "DELETE"; if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri2 = new Uri(uri2, response.Headers[HttpResponseHeader.Location]); } else { if (WebdavFs.CheckStatus(response)) break; throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri2.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri2 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); throw; } } } } public override ReturnedInfo Move(ResourceId id, ResourceId newparentid, string newname, bool overwrite) { if (newname == null) newname = UriUtil.GetLastName(id.Uri); Uri baseuri = (object) newparentid != null ? newparentid.Uri : UriUtil.GetParent(id.Uri); Uri uri1 = id.Uri; Uri target1 = UriUtil.CombineName(baseuri, newname); Uri uri2 = !UriUtil.EndWithSlash(uri1) ? UriUtil.RemoveLastSlash(target1) : UriUtil.AddLastSlash(target1); int num = 0; string str = (string) null; if (UriUtil.UriEquals(uri1, uri2, this.IsCaseSensitiveFs)) throw new DestinationAlreadyExistsException(uri2); Uri uri3 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); Uri target2 = UriUtil.UriEncodeConvert(uri2, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri3); request.Method = "MOVE"; if (this.UseFullUriInDestinationHeader) request.Headers.Add("Destination", target2.AbsoluteUri); else if (Operators.CompareString(UriUtil.GetAuthority(uri3), UriUtil.GetAuthority(target2), false) != 0) request.Headers.Add("Destination", target2.AbsoluteUri); else request.Headers.Add("Destination", target2.AbsolutePath); if (overwrite) request.Headers.Add("Overwrite", "T"); else request.Headers.Add("Overwrite", "F"); if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri3 = new Uri(uri3, response.Headers[HttpResponseHeader.Location]); } else { if (!WebdavFs.CheckStatus(response)) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); break; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri3.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri3 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); if (simpleWebException.StatusCode == 412) throw new DestinationAlreadyExistsException(uri2, (Exception) simpleWebException); throw; } } } return (ReturnedInfo) new ResourceId(uri2, (FsBase) this); } public override ReturnedInfo Copy(ResourceId id, ResourceId newparentid, string newname, bool overwrite) { if (newname == null) newname = UriUtil.GetLastName(id.Uri); Uri baseuri = (object) newparentid != null ? newparentid.Uri : UriUtil.GetParent(id.Uri); Uri uri1 = id.Uri; Uri target1 = UriUtil.CombineName(baseuri, newname); Uri uri2 = !UriUtil.EndWithSlash(uri1) ? UriUtil.RemoveLastSlash(target1) : UriUtil.AddLastSlash(target1); int num = 0; string str = (string) null; WebdavFs.CheckUri(uri1); WebdavFs.CheckUri(uri2); if (UriUtil.UriEquals(uri1, uri2, this.IsCaseSensitiveFs)) throw new DestinationAlreadyExistsException(uri2); Uri uri3 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); Uri target2 = UriUtil.UriEncodeConvert(uri2, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri3); request.Method = "COPY"; if (this.UseFullUriInDestinationHeader) request.Headers.Add("Destination", target2.AbsoluteUri); else if (Operators.CompareString(UriUtil.GetAuthority(uri3), UriUtil.GetAuthority(target2), false) != 0) request.Headers.Add("Destination", target2.AbsoluteUri); else request.Headers.Add("Destination", target2.AbsolutePath); if (overwrite) request.Headers.Add("Overwrite", "T"); else request.Headers.Add("Overwrite", "F"); request.Headers.Add("Depth", "infinity"); if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri3 = new Uri(uri3, response.Headers[HttpResponseHeader.Location]); } else { if (!WebdavFs.CheckStatus(response)) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); break; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri3.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri3 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); if (simpleWebException.StatusCode == 412) throw new DestinationAlreadyExistsException(uri2, (Exception) simpleWebException); throw; } } } return (ReturnedInfo) new ResourceId(uri2, (FsBase) this); } public override ReturnedInfo SetResourceInfo(ResourceInfo info, ResourceInfo original) { if (this.DontUpdateProperty) return (ReturnedInfo) info; int num = 0; string str = (string) null; Uri uri1 = info.Id.Uri; WebdavFs.CheckUri(uri1); Uri uri2 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); string proppatchRequest = WebdavFs.CreatePROPPATCHRequest(info, original); if (proppatchRequest == null) return (ReturnedInfo) info; byte[] bytes = Encoding.UTF8.GetBytes(proppatchRequest); while (true) { HttpWebRequest request = this.CreateRequest(uri2); request.Method = "PROPPATCH"; request.ContentType = "text/xml; charset=\"utf-8\""; request.ContentLength = (long) bytes.Length; if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (Stream requestStream = this.GetRequestStream(request)) requestStream.Write(bytes, 0, bytes.Length); using (HttpWebResponse response = this.GetResponse(request, false)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri2 = new Uri(uri2, response.Headers[HttpResponseHeader.Location]); } else { if (response.StatusCode != (HttpStatusCode) 207) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (!WebdavFs.CheckPROPPATCHResponse(this.GetResponseBody(response))) throw new SimpleWebException("Cannot PROPPATCH", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); break; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri2.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri2 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); throw; } } } return (ReturnedInfo) info; } public override ReturnedInfo SetTimes(ResourceId id, DateTime lastmodifiedtime, DateTime creationtime, DateTime lastaccesstime) { if (DateTime.Compare(lastmodifiedtime, DateTime.MinValue) == 0 && DateTime.Compare(creationtime, DateTime.MinValue) == 0 && DateTime.Compare(lastaccesstime, DateTime.MinValue) == 0) throw new InvalidOperationException(); Uri uri1 = id.Uri; if (this.DontUpdateProperty) return (ReturnedInfo) id; int num = 0; string str = (string) null; WebdavFs.CheckUri(uri1); Uri uri2 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(""); stringBuilder.Append(""); stringBuilder.Append(""); if (DateTime.Compare(creationtime, DateTime.MinValue) != 0) { stringBuilder.Append(""); stringBuilder.Append(creationtime.ToUniversalTime().ToString("r")); stringBuilder.Append(""); } if (DateTime.Compare(lastaccesstime, DateTime.MinValue) != 0) { stringBuilder.Append(""); stringBuilder.Append(lastaccesstime.ToUniversalTime().ToString("r")); stringBuilder.Append(""); } if (DateTime.Compare(lastmodifiedtime, DateTime.MinValue) != 0) { stringBuilder.Append(""); stringBuilder.Append(lastmodifiedtime.ToUniversalTime().ToString("r")); stringBuilder.Append(""); } stringBuilder.Append(""); stringBuilder.Append(""); byte[] bytes = Encoding.UTF8.GetBytes(stringBuilder.ToString()); while (true) { HttpWebRequest request = this.CreateRequest(uri2); request.Method = "PROPPATCH"; request.ContentType = "text/xml; charset=\"utf-8\""; request.ContentLength = (long) bytes.Length; if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (Stream requestStream = this.GetRequestStream(request)) requestStream.Write(bytes, 0, bytes.Length); using (HttpWebResponse response = this.GetResponse(request, false)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); else if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri2 = new Uri(uri2, response.Headers[HttpResponseHeader.Location]); } else { if (response.StatusCode != (HttpStatusCode) 207) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (!WebdavFs.CheckPROPPATCHResponse(this.GetResponseBody(response))) throw new SimpleWebException("Cannot PROPPATCH", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); break; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri2.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri2 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); throw; } } } return (ReturnedInfo) id; } public override Stream OpenRead(Uri targeturi) { Uri target = targeturi; long start = 0; long length = -1; return this.InnerOpenRead(target, ref start, ref length); } public override Stream OpenRead(ResourceId id, ref long start, ref long length) { if (start < 0L) throw new ArgumentOutOfRangeException(nameof (start)); WebdavFs.CheckUri(id.Uri); return this.InnerOpenRead(id.Uri, ref start, ref length); } private Stream InnerOpenRead(Uri target, ref long start, ref long length) { WebdavFs.CheckUri(target); HttpWebResponse httpWebResponse = (HttpWebResponse) null; int num = 0; string str1 = (string) null; if (start < 0L && length < 0L) throw new ArgumentOutOfRangeException(nameof (start)); if (length == 0L) throw new ArgumentOutOfRangeException(nameof (length)); Uri uri = UriUtil.UriEncodeConvert(target, (Encoding) null, this.URIRequestEncoding); WebdavFs.ExtWebHeaderCollection headerCollection; while (true) { HttpWebRequest request = this.CreateRequest(uri); request.Method = "GET"; request.Accept = "*/*"; if (this.RequestTranslatef) request.Headers.Add("Translate", "f"); headerCollection = new WebdavFs.ExtWebHeaderCollection(); if (start == 0L) { if (length >= 0L) headerCollection.Add("Range", "bytes=0-" + checked (start + length - 1L).ToString()); } else if (start < 0L) headerCollection.Add("Range", "bytes=-" + length.ToString()); else if (length < 0L) headerCollection.Add("Range", "bytes=" + start.ToString() + "-"); else headerCollection.Add("Range", "bytes=" + start.ToString() + "-" + checked (start + length - 1L).ToString()); if (headerCollection.Count > 0) { NameValueCollection nameValueCollection = (NameValueCollection) WebdavFs.WebHeader_InnerCollectionInfo.GetValue((object) request.Headers); try { foreach (object obj in (WebHeaderCollection) headerCollection) { string name = Conversions.ToString(obj); nameValueCollection.Add(name, headerCollection[name]); } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } } else { string str2 = string.Empty; if (!this.DontRequestDeflate) str2 = "deflate"; if (!this.DontRequestGzip) { if (str2.Length > 0) str2 += ", "; str2 += "gzip"; } if (str2.Length > 0) request.Headers.Add(HttpRequestHeader.AcceptEncoding, str2); } if (str1 != null) request.Headers.Add(HttpRequestHeader.Authorization, str1); try { httpWebResponse = this.GetResponse(request, true); checked { ++num; } if (num > this.MaxRedirection) { httpWebResponse.Close(); throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) httpWebResponse); } if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(httpWebResponse)) str1 = this.PassportAuth.GetPassportToken(httpWebResponse, this.UserName, this.Password); else if (httpWebResponse.StatusCode >= HttpStatusCode.MultipleChoices) { if (httpWebResponse.StatusCode < HttpStatusCode.BadRequest) { httpWebResponse.Close(); uri = new Uri(uri, httpWebResponse.Headers[HttpResponseHeader.Location]); } else break; } else break; } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (httpWebResponse != null) httpWebResponse.Close(); if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(target, (Exception) simpleWebException); if (simpleWebException.StatusCode == 416) throw new InvalidRangeException((Exception) simpleWebException); throw; } } } if (!WebdavFs.CheckStatus(httpWebResponse)) { SimpleWebException simpleWebException = new SimpleWebException("Unassumed " + httpWebResponse.Method + " response\r\nStatus: " + Conversions.ToString((int) httpWebResponse.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) httpWebResponse); httpWebResponse.Close(); throw simpleWebException; } try { if (this.DontVerifyContentRange) { if (httpWebResponse.StatusCode != HttpStatusCode.PartialContent) { start = 0L; length = httpWebResponse.ContentLength; } } else if (httpWebResponse.Headers[HttpResponseHeader.ContentRange] == null) { if (httpWebResponse.StatusCode == HttpStatusCode.PartialContent) throw new InvalidServerResponseException("\"206 Partial Content\" MUST contain Content-Range Header."); start = 0L; length = httpWebResponse.ContentLength; } else { if (headerCollection.Count == 0) throw new InvalidServerResponseException("Unexpected Content-Range Header"); FsBase.ParseContentRange(httpWebResponse.Headers[HttpResponseHeader.ContentRange], ref start, ref length, true); } } catch (InvalidServerResponseException ex) { ProjectData.SetProjectError((Exception) ex); InvalidServerResponseException responseException = ex; httpWebResponse.Close(); throw new InvalidRangeException((Exception) responseException); } catch (Exception ex) { ProjectData.SetProjectError(ex); httpWebResponse.Close(); throw; } Stream stream = (Stream) null; try { stream = httpWebResponse.GetResponseStream(); if (httpWebResponse.Headers[HttpResponseHeader.ContentEncoding] != null) { string lower = httpWebResponse.Headers[HttpResponseHeader.ContentEncoding].ToLower(); if (Operators.CompareString(lower, "gzip", false) == 0 || Operators.CompareString(lower, "x-gzip", false) == 0) { stream = (Stream) new GZipStream(stream, CompressionMode.Decompress); length = -1L; } else { if (Operators.CompareString(lower, "deflate", false) != 0) throw new InvalidServerResponseException("invalid content encoding"); stream = (Stream) new ZlibStream(stream, CompressionMode.Decompress, false, true); length = -1L; } } return (Stream) new PartialStream(stream, length); } catch (Exception ex) { ProjectData.SetProjectError(ex); if (stream != null) stream.Close(); throw; } } public override Stream OpenWrite(ResourceId parentid, string name, long length) { return this.InnerOpenWrite(UriUtil.CombineName(parentid.Uri, name), (string) null, length); } public override Stream OpenWriteOver(ResourceId id, long length) { return this.InnerOpenWrite(id.Uri, (string) null, length); } public override Stream OpenWriteResume(ResourceId id, ref long start, ref long length) { Uri uri = id.Uri; if (start < 0L) throw new ArgumentOutOfRangeException(nameof (start)); if (length < 0L) throw new ArgumentOutOfRangeException(nameof (length)); string contentrange; if (length < 0L) contentrange = "bytes " + start.ToString() + "-/*"; else contentrange = "bytes " + start.ToString() + "-" + checked (start + length - 1L).ToString() + "/*"; return this.InnerOpenWrite(uri, contentrange, length); } private Stream InnerOpenWrite(Uri target, string contentrange, long length) { int num = 0; string str = (string) null; WebdavFs.CheckUri(target); Uri uri = UriUtil.UriEncodeConvert(target, (Encoding) null, this.URIRequestEncoding); HttpWebRequest request1; Stream stream; while (true) { try { string lowerInvariant = this.LastAuthType.ToLowerInvariant(); if (Operators.CompareString(lowerInvariant, "negotiate", false) == 0 || Operators.CompareString(lowerInvariant, "ntlm", false) == 0 || Operators.CompareString(lowerInvariant, "kerberos", false) == 0) { HttpWebRequest request2 = this.CreateRequest(uri); request2.Method = "PUT"; request2.Headers.Add(HttpRequestHeader.Allow, "PUT"); request2.ContentLength = 0L; request2.AllowWriteStreamBuffering = true; request2.PreAuthenticate = false; if (str != null) request2.Headers.Add(HttpRequestHeader.Authorization, str); using (HttpWebResponse response = this.GetResponse(request2, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (response.StatusCode >= HttpStatusCode.MultipleChoices) { if (response.StatusCode < HttpStatusCode.BadRequest) { uri = new Uri(uri, response.Headers[HttpResponseHeader.Location]); continue; } } } this.SendEmptyPUT = true; request1 = this.CreateRequest(uri); request1.PreAuthenticate = false; request1.UnsafeAuthenticatedConnectionSharing = true; request1.Credentials = (ICredentials) null; } else if (this.SendEmptyPUT) { HttpWebRequest request2 = this.CreateRequest(uri); request2.Method = "PUT"; request2.Headers.Add(HttpRequestHeader.Allow, "PUT"); request2.ContentLength = 0L; request2.AllowWriteStreamBuffering = true; request2.PreAuthenticate = true; if (str != null) request2.Headers.Add(HttpRequestHeader.Authorization, str); using (HttpWebResponse response = this.GetResponse(request2, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (this.UsePassportAuthentication && PassportAuthHelper.CheckPassportAuth(response)) { str = this.PassportAuth.GetPassportToken(response, this.UserName, this.Password); continue; } if (response.StatusCode >= HttpStatusCode.MultipleChoices) { if (response.StatusCode < HttpStatusCode.BadRequest) { uri = new Uri(uri, response.Headers[HttpResponseHeader.Location]); continue; } } } this.SendEmptyPUT = true; request1 = this.CreateRequest(uri); request1.PreAuthenticate = true; } else { request1 = this.CreateRequest(uri); request1.PreAuthenticate = true; } request1.Method = "PUT"; request1.AllowWriteStreamBuffering = false; if (Operators.CompareString(this.UploadCompression.ToLower(), "gzip", false) == 0) { request1.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip"); request1.SendChunked = true; } else if (Operators.CompareString(this.UploadCompression.ToLower(), "deflate", false) == 0) { request1.Headers.Add(HttpRequestHeader.ContentEncoding, "deflate"); request1.SendChunked = true; } else if (length >= 0L) request1.ContentLength = length; else request1.SendChunked = true; request1.ContentType = "application/octet-stream"; if (contentrange != null) request1.Headers.Add(HttpRequestHeader.ContentRange, contentrange); stream = this.GetRequestStream(request1); break; } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(target, (Exception) simpleWebException); if (simpleWebException.StatusCode == 416) throw new InvalidRangeException((Exception) simpleWebException); throw; } } } if (Operators.CompareString(this.UploadCompression.ToLower(), "gzip", false) == 0) stream = (Stream) new GZipStream(stream, CompressionMode.Compress, false); else if (Operators.CompareString(this.UploadCompression.ToLower(), "deflate", false) == 0) stream = (Stream) new ZlibStream(stream, CompressionMode.Compress); CloseNotifyStream closeNotifyStream; try { closeNotifyStream = new CloseNotifyStream(stream); closeNotifyStream.ClosingEvent += new EventHandler(this.WriteStream_Closing); closeNotifyStream.ClosedEvent += new EventHandler(this.WriteStream_Closed); } catch (Exception ex) { ProjectData.SetProjectError(ex); if (stream != null) stream.Close(); throw; } closeNotifyStream.Tag = (object) new object[3] { (object) request1, (object) target, (object) new ResourceId(target, (FsBase) this) }; return (Stream) closeNotifyStream; } public override ReturnedInfo CloseWrite(Stream st) { st.Close(); return (ReturnedInfo) ((object[]) ((CloseNotifyStream) st).Tag)[2]; } public override string GetLock(ResourceId id, string owner, int timeoutseconds, FsBase.LockScope scope) { Uri uri1 = id.Uri; int num = 0; string str = (string) null; WebdavFs.CheckUri(uri1); Uri uri2 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); StringBuilder sb = new StringBuilder(200); StringWriter stringWriter = new StringWriter(sb); stringWriter.Write(""); stringWriter.Write(""); stringWriter.Write(""); if (scope == FsBase.LockScope.Exclusive) stringWriter.Write(""); else if (scope == FsBase.LockScope.Shared) stringWriter.Write(""); stringWriter.Write(""); stringWriter.Write(""); stringWriter.Write(""); stringWriter.Write(""); stringWriter.Write(""); stringWriter.Write(owner); stringWriter.Write(""); stringWriter.Write(""); stringWriter.Close(); byte[] bytes = Encoding.UTF8.GetBytes(sb.ToString()); while (true) { HttpWebRequest request = this.CreateRequest(uri2); request.Method = "LOCK"; request.ContentType = "text/xml; charset=\"utf-8\""; request.ContentLength = (long) bytes.Length; if (timeoutseconds > 0) request.Headers.Add("Timeout", "Second-" + timeoutseconds.ToString()); if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (Stream requestStream = this.GetRequestStream(request)) requestStream.Write(bytes, 0, bytes.Length); using (HttpWebResponse response = this.GetResponse(request, false)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri2 = new Uri(uri2, response.Headers[HttpResponseHeader.Location]); } else { if (!WebdavFs.CheckStatus(response)) throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); string header = response.Headers["Lock-Token"]; if (header != null || header.Length == 0) throw new SimpleWebException("Invalid Lock Token", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); return header; } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri2.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri2 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); throw; } } } } public override void ReleaseLock(ResourceId id, string locktoken) { Uri uri1 = id.Uri; int num = 0; string str = (string) null; WebdavFs.CheckUri(uri1); Uri uri2 = UriUtil.UriEncodeConvert(uri1, (Encoding) null, this.URIRequestEncoding); while (true) { HttpWebRequest request = this.CreateRequest(uri2); request.Method = "UNLOCK"; request.Headers.Add("Lock-Token", locktoken); if (str != null) request.Headers.Add(HttpRequestHeader.Authorization, str); try { using (HttpWebResponse response = this.GetResponse(request, true)) { checked { ++num; } if (num > this.MaxRedirection) throw new SimpleWebException("Too many redirection", (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); if (response.StatusCode >= HttpStatusCode.MultipleChoices && response.StatusCode < HttpStatusCode.BadRequest) { uri2 = new Uri(uri2, response.Headers[HttpResponseHeader.Location]); } else { if (WebdavFs.CheckStatus(response)) break; throw new SimpleWebException("Unassumed " + response.Method + " response\r\nStatus: " + Conversions.ToString((int) response.StatusCode), (Exception) null, WebExceptionStatus.ProtocolError, (WebResponse) response); } } } catch (SimpleWebException ex) { ProjectData.SetProjectError((Exception) ex); SimpleWebException simpleWebException = ex; if (simpleWebException.Status == WebExceptionStatus.KeepAliveFailure) ProjectData.ClearProjectError(); else if (simpleWebException.Status == WebExceptionStatus.TrustFailure) { if (this.ConnectionSetting.LastCertError != SslPolicyErrors.None) throw new RemoteCertificateErrorException((Exception) simpleWebException, this.ConnectionSetting.LastCertError); throw; } else if (simpleWebException.StatusCode == 401) { if (Operators.CompareString(simpleWebException.ResponseUri.AbsolutePath, uri2.AbsolutePath, false) == 0) throw new UnauthorizedException((Exception) simpleWebException, !this.UseDefaultCredential); uri2 = simpleWebException.ResponseUri; ProjectData.ClearProjectError(); } else { if (simpleWebException.StatusCode == 404) throw new RemoteResourceNotFoundException(uri1, (Exception) simpleWebException); throw; } } } } private HttpWebRequest CreateRequest(Uri target) { ServicePointManager.SecurityProtocol = (SecurityProtocolType) (~this.DisableTlsVersions & FsBase.AvailableTlss()); ServicePoint servicePoint = ServicePointManager.FindServicePoint(target, this.Proxy); if (!this.pServicePointList.Contains(servicePoint)) { this.pServicePointList.Add(servicePoint); servicePoint.ConnectionLimit = 1; servicePoint.Expect100Continue = !this.DontExpect100; } HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(target); if (this.UseDefaultCredential) { httpWebRequest.UseDefaultCredentials = true; } else { httpWebRequest.UseDefaultCredentials = false; string userName = string.Empty; string password = string.Empty; string domain = string.Empty; if (this.UserName.Length > 0) { userName = this.UserName; password = this.Password; int length = userName.IndexOf('\\'); if (length > 0) { domain = userName.Substring(0, length); userName = userName.Substring(checked (length + 1)); } } if (this.UsePreAuthentication_Basic) { string s = userName + ":" + password; if (this.CredentialEncoding == null) httpWebRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(s))); else httpWebRequest.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(this.CredentialEncoding.GetBytes(s))); } else if (this.UsePreAuthentication_WSSE) { httpWebRequest.Headers.Add("Authorization", "WSSE profile=\"UsernameToken\""); httpWebRequest.Headers.Add("X-WSSE", WsseClient.GetAuthString(new NetworkCredential(userName, password), this.CredentialEncoding)); } else httpWebRequest.Credentials = domain.Length <= 0 ? (ICredentials) new NetworkCredential(userName, password) : (ICredentials) new NetworkCredential(userName, password, domain); } httpWebRequest.ConnectionGroupName = this.GroupName; httpWebRequest.UserAgent = this.ClientName; httpWebRequest.KeepAlive = true; httpWebRequest.PreAuthenticate = true; httpWebRequest.UnsafeAuthenticatedConnectionSharing = true; if (this.ClientCertificates.Count > 0) httpWebRequest.ClientCertificates = (X509CertificateCollection) this.ClientCertificates; httpWebRequest.Proxy = this.Proxy; httpWebRequest.ReadWriteTimeout = this.ReadWriteTimeout; httpWebRequest.Timeout = this.ConnectTimeout; httpWebRequest.CookieContainer = this.ConnectionSetting.CookieContainer; httpWebRequest.AllowAutoRedirect = false; this.pLastUri = httpWebRequest.RequestUri; this.ConnectionSetting.LastCertError = SslPolicyErrors.None; WebRequestCertificateValidationManager.Register((WebRequest) httpWebRequest, this.ConnectionSetting); return httpWebRequest; } private HttpWebResponse GetResponse(HttpWebRequest request, bool notreqstream) { string str = ""; if (notreqstream) { string message = str + "\r\n> " + request.Method + " " + request.RequestUri.PathAndQuery + " HTTP/" + request.ProtocolVersion.ToString(); try { foreach (object key in request.Headers.Keys) { string index = Conversions.ToString(key); if (Operators.CompareString(index.ToLower(), "authorization", false) == 0 && request.Headers[index].ToLower().StartsWith("basic")) message = message + "\r\n> " + index + ": Basic *****"; else message = message + "\r\n> " + index + ": " + request.Headers[index]; } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } this.OnLogMessage(message); } HttpWebResponse httpWebResponse1 = (HttpWebResponse) null; try { IAsyncResult response = request.BeginGetResponse((AsyncCallback) null, (object) null); if (!response.AsyncWaitHandle.WaitOne(this.ConnectTimeout, false)) { try { request.Abort(); httpWebResponse1 = (HttpWebResponse) request.EndGetResponse(response); } catch (WebException ex) { ProjectData.SetProjectError((Exception) ex); throw new WebException("Timeout", (Exception) null, WebExceptionStatus.Timeout, ex.Response); } throw new WebException("Timeout", (Exception) null, WebExceptionStatus.Timeout, (WebResponse) httpWebResponse1); } httpWebResponse1 = (HttpWebResponse) request.EndGetResponse(response); WebdavFs.FixDigestAuthDomain(request); } catch (WebException ex1) { ProjectData.SetProjectError((Exception) ex1); WebException ex2 = ex1; using (WebResponse response = ex2.Response) { this.CheckAuthType(request); string message = "AuthorizationMethod = " + this.LastAuthType + "\r\n" + ex2.ToString() + "\r\n"; HttpWebResponse httpWebResponse2 = response as HttpWebResponse; if (httpWebResponse2 != null) { WebdavFs.FixDigestAuthDomain(request); message = message + " " + request.Method + " " + request.RequestUri.PathAndQuery + " HTTP/" + request.ProtocolVersion.ToString(); try { foreach (object key in request.Headers.Keys) { string index = Conversions.ToString(key); if (Operators.CompareString(index.ToLower(), "authorization", false) == 0 && request.Headers[index].ToLower().StartsWith("basic")) message1 = message1 + "\r\n> " + index + ": Basic *****"; else message1 = message1 + "\r\n> " + index + ": " + request.Headers[index]; } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } // this.OnLogMessage(message1); Stream requestStream1; try { IAsyncResult requestStream2 = request.BeginGetRequestStream((AsyncCallback) null, (object) null); if (!requestStream2.AsyncWaitHandle.WaitOne(this.ConnectTimeout, false)) { try { request.Abort(); request.EndGetRequestStream(requestStream2); } catch (WebException ex) { ProjectData.SetProjectError((Exception) ex); throw new WebException("Timeout", (Exception) null, WebExceptionStatus.Timeout, ex.Response); } throw new WebException("Timeout", (Exception) null, WebExceptionStatus.Timeout, (WebResponse) null); } requestStream1 = request.EndGetRequestStream(requestStream2); WebdavFs.FixDigestAuthDomain(request); } catch (WebException ex1) { ProjectData.SetProjectError((Exception) ex1); WebException ex2 = ex1; using (WebResponse response = ex2.Response) { this.CheckAuthType(request); string message2 = "AuthorizationMethod = " + this.LastAuthType + "\r\n"; HttpWebResponse httpWebResponse = response as HttpWebResponse; if (httpWebResponse != null) { WebdavFs.FixDigestAuthDomain(request); message2 = message2 + "= 0 && checked (num1 + 7) < target.Length) { string str4 = target.Substring(checked (num1 + 7)).Trim(); if (Operators.CompareString(Conversions.ToString(str4[0]), "=", false) == 0) { string str5 = str4.Substring(1).Trim(); if (Operators.CompareString(Conversions.ToString(str5[0]), "\"", false) == 0) { int num2 = str5.IndexOf("\"", 1); if (num2 < 0) num2 = str5.Length; str3 = str5.Substring(1, checked (num2 - 1)); } else str3 = str5; } } Encoding encoding; if (Operators.CompareString(str3, "", false) != 0) { try { encoding = Encoding.GetEncoding(str3); goto label_19; } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } } string name = "ISO-8859-1"; if (Operators.CompareString(Left, "xml", false) == 0) name = "UTF-8"; encoding = Encoding.GetEncoding(name); label_19: return this.GetResponseBody(res, encoding); } private string GetResponseBody(HttpWebResponse res, Encoding encoding) { byte[] responseBodyInBytes = this.GetResponseBodyInBytes(res); encoding.GetString(responseBodyInBytes); string str = encoding.CodePage != 65001 || responseBodyInBytes.Length <= 3 || ((int) responseBodyInBytes[0] != 239 || (int) responseBodyInBytes[1] != 187) || (int) responseBodyInBytes[2] != 191 ? encoding.GetString(responseBodyInBytes) : encoding.GetString(responseBodyInBytes, 3, checked (responseBodyInBytes.Length - 3)); this.OnLogMessage("< [MESSAGEBODY LENGTH:" + str.Length.ToString() + "]"); return str; } private byte[] GetResponseBodyInBytes(HttpWebResponse res) { Stream stream = res.GetResponseStream(); List numArrayList = new List(); List intList = new List(); int num1=0; try { if (res.Headers[HttpResponseHeader.ContentEncoding] != null) { string lower = res.Headers[HttpResponseHeader.ContentEncoding].ToLower(); if (Operators.CompareString(lower, "gzip", false) == 0 || Operators.CompareString(lower, "x-gzip", false) == 0) stream = (Stream) new GZipStream(stream, CompressionMode.Decompress); else if (Operators.CompareString(lower, "deflate", false) == 0) stream = (Stream) new ZlibStream(stream, CompressionMode.Decompress, false, true); } while (true) { byte[] buffer = new byte[4096]; int num2 = stream.Read(buffer, 0, buffer.Length); if (num2 != 0) { intList.Add(num2); numArrayList.Add(buffer); checked { num1 += num2; } } else break; } } finally { stream.Close(); res.Close(); } byte[] numArray = new byte[checked (num1 - 1 + 1)]; int destinationIndex = 0; int num3 = 0; int num4 = checked (numArrayList.Count - 1); int index = num3; while (index <= num4) { Array.Copy((Array) numArrayList[index], 0, (Array) numArray, destinationIndex, intList[index]); checked { destinationIndex += intList[index]; } checked { ++index; } } return numArray; } private static void CheckUri(Uri target) { if (!target.IsAbsoluteUri) throw new CannotProcessRequest(target, "Target URI is not absolute."); if (target.Fragment.Length > 0) throw new CannotProcessRequest(target, "Target URI cannot contain fragment."); if (target.UserInfo.Length > 0) throw new CannotProcessRequest(target, "Target URI cannot contain userinfo."); if (Operators.CompareString(target.Scheme, Uri.UriSchemeHttp, false) != 0 && Operators.CompareString(target.Scheme, Uri.UriSchemeHttps, false) != 0) throw new CannotProcessRequest(target, "Scheme of target Uri is not supported."); } private static bool CheckStatus(HttpWebResponse response) { return response.StatusCode >= HttpStatusCode.OK && response.StatusCode < HttpStatusCode.MultipleChoices && response.StatusCode != (HttpStatusCode) 207; } private static bool IsStatusOK(int statuscode) { return statuscode >= 200 && statuscode < 300; } private void CheckAuthType(HttpWebRequest req) { if (req.Headers[HttpRequestHeader.Authorization] == null) { this.pLastAuthType = ""; } else { string header = req.Headers[HttpRequestHeader.Authorization]; int length = header.IndexOf(' '); if (length < 0) this.pLastAuthType = ""; else this.pLastAuthType = header.Substring(0, length); } } private List ParsePROPFINDResponse(string message, Uri responseuri) { List resourceInfoList = new List(); XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.LoadXml(message); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception innerException = ex; throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. Xml Error.", message, innerException); } XmlElement xmlElement = xmlDocument["multistatus", "DAV:"]; if (xmlElement == null) throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. No multistatus element.", message); try { foreach (XmlNode childNode in xmlElement.ChildNodes) { if (Operators.CompareString(childNode.LocalName, "response", false) == 0 && Operators.CompareString(childNode.NamespaceURI, "DAV:", false) == 0) { Uri result1 = (Uri) null; XmlNode xmlNode1 = (XmlNode) childNode["location", "DAV:"]; if (xmlNode1 != null) { string innerText = xmlNode1["href", "DAV:"].InnerText; if (!Uri.TryCreate(innerText, UriKind.Absolute, out result1) && !Uri.TryCreate(responseuri, innerText, out result1)) ; } if (childNode["propstat", "DAV:"] != null) { ResourceInfo resourceInfo = new ResourceInfo(); try { foreach (XmlNode xmlNode2 in childNode) { if (Operators.CompareString(xmlNode2.NamespaceURI, "DAV:", false) == 0) { if (Operators.CompareString(xmlNode2.LocalName, "href", false) == 0) { Uri result2 = (Uri) null; if (!Uri.TryCreate(xmlNode2.InnerText, UriKind.Absolute, out result2) && !Uri.TryCreate(responseuri, xmlNode2.InnerText, out result2)) throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. Cannot create URI from href element.", message); result2 = UriUtil.UriEncodeConvert(result2, this.URIResponseEncoding, (Encoding) null); if (Operators.CompareString(result2.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped), responseuri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped), false) != 0) result2 = new UriBuilder(result2) { Scheme = responseuri.Scheme, Host = responseuri.Host, Port = responseuri.Port }.Uri; resourceInfo.Id = new ResourceId(result2, (FsBase) this); } else if (Operators.CompareString(xmlNode2.LocalName, "propstat", false) == 0) { bool haserror; string statedescription; string str; if (xmlNode2["status", "DAV:"] == null) { haserror = true; statedescription = "No Status-Line"; str = "No Status-Line"; XmlNode xmlNode3 = (XmlNode) xmlNode2["error", "DAV:"]; if (xmlNode3 != null) statedescription = statedescription + "\r\n" + xmlNode3.InnerText; XmlNode xmlNode4 = (XmlNode) xmlNode2["responsedescription", "DAV:"]; if (xmlNode4 != null) statedescription = statedescription + "\r\n" + xmlNode4.InnerText; } else { WebdavFs.Statusline statusline = new WebdavFs.Statusline(xmlNode2["status", "DAV:"].InnerText); haserror = !statusline.IsStatusOK; statedescription = statusline.StatusCode.ToString() + " " + statusline.StatusDescription; str = statusline.ToString(); XmlNode xmlNode3 = (XmlNode) xmlNode2["error", "DAV:"]; if (xmlNode3 != null) statedescription = statedescription + "\r\n" + xmlNode3.InnerText; XmlNode xmlNode4 = (XmlNode) xmlNode2["responsedescription", "DAV:"]; if (xmlNode4 != null) statedescription = statedescription + "\r\n" + xmlNode4.InnerText; } resourceInfo.HasError = resourceInfo.HasError || haserror; resourceInfo.StatusDescription = resourceInfo.StatusDescription != null ? WebdavFs.Statusline.StatusHTTP11MultiStatus.ToString() : str; try { foreach (XmlNode xmlNode3 in xmlNode2) { if (Operators.CompareString(xmlNode3.LocalName, "prop", false) == 0) { if (Operators.CompareString(xmlNode3.NamespaceURI, "DAV:", false) == 0) { try { foreach (XmlNode xmlNode4 in xmlNode3) { string name = xmlNode4.LocalName; if (xmlNode4.NamespaceURI != null) name = xmlNode4.NamespaceURI + name; resourceInfo.Properties.Add(name, xmlNode4.InnerXml, statedescription, haserror); } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } } } } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } } } } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } if ((object) resourceInfo.Id != null) { resourceInfo.IsCollection = resourceInfo.Id.IsCollection; resourceInfoList.Add(resourceInfo); } } else { bool flag; string str1; string str2; if (childNode["status", "DAV:"] == null) { flag = true; string str3 = "No Status-Line"; str1 = "No Status-Line"; XmlNode xmlNode2 = (XmlNode) childNode["error", "DAV:"]; if (xmlNode2 != null) str3 = str3 + "\r\n" + xmlNode2.InnerText; XmlNode xmlNode3 = (XmlNode) childNode["responsedescription", "DAV:"]; if (xmlNode3 != null) str2 = str3 + "\r\n" + xmlNode3.InnerText; } else { WebdavFs.Statusline statusline = new WebdavFs.Statusline(childNode["status", "DAV:"].InnerText); flag = !statusline.IsStatusOK; string str3 = statusline.StatusCode.ToString() + " " + statusline.StatusDescription; str1 = statusline.ToString(); XmlNode xmlNode2 = (XmlNode) childNode["error", "DAV:"]; if (xmlNode2 != null) str3 = str3 + "\r\n" + xmlNode2.InnerText; XmlNode xmlNode3 = (XmlNode) childNode["responsedescription", "DAV:"]; if (xmlNode3 != null) str2 = str3 + "\r\n" + xmlNode3.InnerText; } try { foreach (XmlNode xmlNode2 in childNode) { if (Operators.CompareString(xmlNode2.LocalName, "href", false) == 0 && Operators.CompareString(xmlNode2.NamespaceURI, "DAV:", false) == 0) { ResourceInfo resourceInfo = new ResourceInfo(); Uri result2 = (Uri) null; if (!Uri.TryCreate(xmlNode2.InnerText, UriKind.Absolute, out result2) && !Uri.TryCreate(responseuri, xmlNode2.InnerText, out result2)) throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. Cannot create URI from href element.", message); result2 = UriUtil.UriEncodeConvert(result2, this.URIResponseEncoding, (Encoding) null); if (Operators.CompareString(result2.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped), responseuri.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped), false) != 0) result2 = new UriBuilder(result2) { Scheme = responseuri.Scheme, Host = responseuri.Host, Port = responseuri.Port }.Uri; resourceInfo.Id = new ResourceId(result2, (FsBase) this); resourceInfo.HasError = resourceInfo.HasError || flag; resourceInfo.StatusDescription = str1; resourceInfoList.Add(resourceInfo); } } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } } } } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } if (resourceInfoList.Count == 0) throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. No response element.", message); int num1 = 1; int num2 = checked (resourceInfoList.Count - 1); int index1 = num1; while (index1 <= num2) { if (resourceInfoList[index1].Id.Uri.Segments.Length < resourceInfoList[0].Id.Uri.Segments.Length) { ResourceInfo resourceInfo = resourceInfoList[0]; resourceInfoList[0] = resourceInfoList[index1]; resourceInfoList[index1] = resourceInfo; } checked { ++index1; } } List.Enumerator enumerator1 = resourceInfoList.GetEnumerator(); try { while (enumerator1.MoveNext()) { ResourceInfo current = enumerator1.Current; int index2 = current.Properties.IndexOf("DAV:getcontentlength"); long result1; current.Size = index2 < 0 || current.Properties[index2].HasError || !long.TryParse(current.Properties[index2].Value, out result1) ? -1L : result1; int index3 = current.Properties.IndexOf("urn:schemas-microsoft-com:Win32LastModifiedTime"); DateTime result2; if (index3 >= 0 && !current.Properties[index3].HasError && DateTime.TryParse(current.Properties[index3].Value, out result2)) { current.LastModifiedTime = result2; } else { int index4 = current.Properties.IndexOf("DAV:getlastmodified"); if (index4 >= 0 && !current.Properties[index4].HasError && DateTime.TryParse(current.Properties[index4].Value, out result2)) current.LastModifiedTime = result2; } int index5 = current.Properties.IndexOf("urn:schemas-microsoft-com:Win32CreationTime"); if (index5 >= 0 && !current.Properties[index5].HasError && DateTime.TryParse(current.Properties[index5].Value, out result2)) { current.CreationTime = result2; } else { int index4 = current.Properties.IndexOf("DAV:creationdate"); if (index4 >= 0 && !current.Properties[index4].HasError && DateTime.TryParse(current.Properties[index4].Value, out result2)) current.CreationTime = result2; } int index6 = current.Properties.IndexOf("urn:schemas-microsoft-com:Win32LastAccessTime"); if (index6 >= 0 && !current.Properties[index6].HasError && DateTime.TryParse(current.Properties[index6].Value, out result2)) current.LastAccessTime = result2; XmlReaderSettings settings = new XmlReaderSettings(); XmlParserContext inputContext = (XmlParserContext) null; settings.ConformanceLevel = ConformanceLevel.Fragment; int index7 = current.Properties.IndexOf("DAV:resourcetype"); if (index7 >= 0 && !current.Properties[index7].HasError) { if (current.Properties[index7].Value.Length > 0) { try { bool flag = false; using (XmlReader xmlReader = XmlReader.Create((TextReader) new StringReader(current.Properties[index7].Value), settings, inputContext)) { while (xmlReader.Read()) { if (xmlReader.NodeType == XmlNodeType.Element && Operators.CompareString(xmlReader.LocalName, "collection", false) == 0 && Operators.CompareString(xmlReader.NamespaceURI, "DAV:", false) == 0) flag = true; } } current.IsCollection = flag; } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } current.Types.Sort(); } } if (current.IsCollection) { if (!UriUtil.EndWithSlash(current.Id.Uri)) current.Id = new ResourceId(UriUtil.AddLastSlash(current.Id.Uri), (FsBase) this); } else if (UriUtil.EndWithSlash(current.Id.Uri)) current.Id = new ResourceId(UriUtil.RemoveLastSlash(current.Id.Uri), (FsBase) this); current.CanCopy = true; current.CanDelete = true; current.CanMove = true; current.CanRename = true; current.CanSetInfo = true; } } finally { enumerator1.Dispose(); } return resourceInfoList; } private static bool CheckPROPPATCHResponse(string message) { XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.LoadXml(message); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception innerException = ex; throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. Xml Error.", message, innerException); } XmlElement xmlElement = xmlDocument["multistatus", "DAV:"]; if (xmlElement == null) throw new InvalidServerResponseException("Cannot Parse PROPFIND Response. No multistatus element.", message); try { foreach (XmlNode childNode in xmlElement.ChildNodes) { if (Operators.CompareString(childNode.LocalName, "response", false) == 0 && Operators.CompareString(childNode.NamespaceURI, "DAV:", false) == 0) { if (childNode["propstat", "DAV:"] != null) { try { foreach (XmlNode xmlNode in childNode) { if (Operators.CompareString(xmlNode.LocalName, "propstat", false) == 0 && Operators.CompareString(xmlNode.NamespaceURI, "DAV:", false) == 0 && xmlNode["status", "DAV:"] != null) { string innerText = xmlNode["status", "DAV:"].InnerText; int result; if (innerText.Length < 12 || !int.TryParse(innerText.Substring(9, 3), out result) || result < 200 | result >= 300) return false; } } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } } else if (childNode["status", "DAV:"] != null) { string str = ""; string innerText = childNode["status", "DAV:"].InnerText; int result; if (innerText.Length < 12 || !int.TryParse(innerText.Substring(9, 3), out result) || result < 200 | result >= 300) return false; str = childNode["status", "DAV:"].InnerText; } } } } finally { //IEnumerator enumerator; //if (enumerator is IDisposable) // (enumerator as IDisposable).Dispose(); } return true; } private static string CreatePROPPATCHRequest(ResourceInfo newinfo, ResourceInfo originalinfo) { StringBuilder stringBuilder = new StringBuilder(); bool flag = false; stringBuilder.Append(""); stringBuilder.Append("\r\n"); List.Enumerator enumerator1 = newinfo.Properties.GetEnumerator(); try { while (enumerator1.MoveNext()) { ResourceInfo.ResourceProperty current = enumerator1.Current; int index = originalinfo.Properties.IndexOf(current.Name); if (index < 0 || Operators.CompareString(originalinfo.Properties[index].Value, current.Value, false) != 0) { int num = current.Name.LastIndexOf(":"); string str1; string str2; if (num < 0) { str1 = current.Name; str2 = ""; } else { str1 = "P:" + current.Name.Substring(checked (num + 1)); str2 = " xmlns:P=\"" + current.Name.Substring(0, checked (num + 1)) + "\""; } stringBuilder.Append("\r\n"); stringBuilder.Append("<" + str1 + str2 + ">"); stringBuilder.Append(current.Value); stringBuilder.Append(""); stringBuilder.Append("\r\n"); flag = true; } } } finally { enumerator1.Dispose(); } List.Enumerator enumerator2 = originalinfo.Properties.GetEnumerator(); try { while (enumerator2.MoveNext()) { ResourceInfo.ResourceProperty current = enumerator2.Current; if (newinfo.Properties.IndexOf(current.Name) < 0) { int num = current.Name.LastIndexOf(":"); string str1; string str2; if (num < 0) { str1 = current.Name; str2 = ""; } else { str1 = "P:" + current.Name.Substring(checked (num + 1)); str2 = " xmlns:P=\"" + current.Name.Substring(0, checked (num + 1)) + "\""; } stringBuilder.Append("\r\n"); stringBuilder.Append("<" + str1 + str2 + ">"); stringBuilder.Append(current.Value); stringBuilder.Append(""); stringBuilder.Append("\r\n"); flag = true; } } } finally { enumerator2.Dispose(); } stringBuilder.Append(""); if (!flag) return (string) null; return stringBuilder.ToString(); } private static int IndexOfWithQuote(string target, string value, StringComparison comparisontype) { int startIndex = 0; int length = target.Length; do { int num1 = target.IndexOf("\""); if (num1 < 0) num1 = length; int num2 = target.Substring(startIndex, checked (num1 - startIndex)).IndexOf(value, comparisontype); if (num2 >= 0) return num2; if (checked (num1 + 1) >= length) return -1; startIndex = target.IndexOf("\"", checked (num1 + 1)); } while (startIndex >= 0 && checked (startIndex + 1) < length); return -1; } private static void FixDigestAuthDomain(HttpWebRequest request) { string[] challenges = WebRequestCertificateValidationManager.GetChallenges((WebRequest) request); List strArrayList = new List(); string[] strArray1 = challenges; int index1 = 0; while (index1 < strArray1.Length) { string[] values = new WebHeaderCollection() { { HttpResponseHeader.WwwAuthenticate, strArray1[index1] } }.GetValues(0); int index2 = 0; while (index2 < values.Length) { string str1 = values[index2]; if (str1.Length > 7 && Operators.CompareString(str1.Substring(0, 7).ToLowerInvariant(), "digest ", false) == 0) { int startIndex1 = 7; while (startIndex1 < str1.Length) { while (startIndex1 < str1.Length && (int) str1[startIndex1] == 32) checked { ++startIndex1; } int index3 = checked (startIndex1 + 1); while (index3 < str1.Length && (int) str1[index3] != 61) checked { ++index3; } string Left = str1.Substring(startIndex1, checked (index3 - startIndex1)).Trim(); int startIndex2 = checked (index3 + 1); while (startIndex2 < str1.Length && (int) str1[startIndex2] == 32) checked { ++startIndex2; } string str2; if ((int) str1[startIndex2] == 34) { int startIndex3 = checked (startIndex2 + 1); int num = str1.IndexOf('"', startIndex3); if (num < 0) num = str1.Length; str2 = str1.Substring(startIndex3, checked (num - startIndex3)); startIndex1 = checked (num + 1); } else { int index4 = checked (startIndex2 + 1); while (index4 < str1.Length && (int) str1[index4] != 32) checked { ++index4; } str2 = str1.Substring(startIndex2, checked (index4 - startIndex2)); startIndex1 = checked (index4 + 1); } if (Operators.CompareString(Left, "domain", false) == 0) { string[] strArray2 = str2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); int num1 = 0; int num2 = checked (strArray2.Length - 1); int index4 = num1; while (index4 <= num2) { Uri result = (Uri) null; if (Uri.TryCreate(request.RequestUri, strArray2[index4], out result)) strArrayList.Add(new string[2] { result.AbsoluteUri, strArray2[index4] }); checked { ++index4; } } break; } } } checked { ++index2; } } checked { ++index1; } } if (strArrayList.Count <= 0) return; object objectValue1 = RuntimeHelpers.GetObjectValue(WebdavFs.s_ModuleBindingInfo.GetValue((object) null)); object objectValue2 = RuntimeHelpers.GetObjectValue(WebdavFs.challengeCacheinfo.GetValue((object) null)); Hashtable hashtable1 = (Hashtable) WebdavFs.m_StoreInfo.GetValue(RuntimeHelpers.GetObjectValue(objectValue1)); Hashtable hashtable2 = (Hashtable) WebdavFs.m_StoreInfo.GetValue(RuntimeHelpers.GetObjectValue(objectValue2)); int num3 = 0; int num4 = checked (strArrayList.Count - 1); int index5 = num3; while (index5 <= num4) { object Expression = objectValue1; ObjectFlowControl.CheckForSyncLockOnValueType(Expression); Monitor.Enter(Expression); try { lock (hashtable1) { hashtable1[(object) strArrayList[index5][0]] = RuntimeHelpers.GetObjectValue(hashtable1[(object) strArrayList[index5][1]]); hashtable1.Remove((object) strArrayList[index5][1]); } } finally { Monitor.Exit(Expression); } lock (hashtable2) { hashtable2[(object) strArrayList[index5][0]] = RuntimeHelpers.GetObjectValue(hashtable2[(object) strArrayList[index5][1]]); hashtable2.Remove((object) strArrayList[index5][1]); } checked { ++index5; } } } internal class WebDAVCredentialManager : ICredentialPolicy { public bool ShouldSendCredential(Uri challengeUri, WebRequest request, NetworkCredential credential, IAuthenticationModule authenticationModule) { return WebdavFs.ShouldSendCredential(challengeUri, request, credential, authenticationModule); } } private class ExtWebHeaderCollection : WebHeaderCollection { public override void Add(string name, string value) { this.AddWithoutValidate(name, value); } public override void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext) { serializationInfo.AddValue("Count", this.Count); int num1 = 0; int num2 = checked (this.Count - 1); int index = num1; while (index <= num2) { serializationInfo.AddValue(index.ToString((IFormatProvider) NumberFormatInfo.InvariantInfo), (object) this.GetKey(index)); serializationInfo.AddValue(checked (index + this.Count).ToString((IFormatProvider) NumberFormatInfo.InvariantInfo), (object) this.Get(index)); checked { ++index; } } } } private class Statusline { public static WebdavFs.Statusline StatusHTTP11OK = new WebdavFs.Statusline("HTTP/1.1 200 OK"); public static WebdavFs.Statusline StatusHTTP11MultiStatus = new WebdavFs.Statusline("HTTP/1.1 207 Multi-Status"); private const string HTTPStatuslineHeader = "HTTP/"; private int _statuscode; private Version _version; private string _description; public Statusline(string line) { line = line.Trim(); if (Operators.CompareString(line.Substring(0, 5), "HTTP/", false) != 0) throw new ArgumentException(); this._version = new Version(line.Substring(5, 3)); this._statuscode = int.Parse(line.Substring(9, 3)); if (line.Length < 14) this._description = ""; else this._description = line.Substring(13).Trim(); } public Statusline(HttpWebResponse response) { this._version = (Version) response.ProtocolVersion.Clone(); this._statuscode = (int) response.StatusCode; this._description = response.StatusDescription; } public Version ProtocolVersion { get { return this._version; } } public int StatusCode { get { return this._statuscode; } } public string StatusDescription { get { return this._description; } } public bool IsStatusOK { get { return this._statuscode >= 200 && this._statuscode < 300; } } public override string ToString() { return string.Join(" ", new string[3] { "HTTP/" + this._version.ToString(), this._statuscode.ToString(), this._description }); } } private enum DepthType { Depth_infinity = -1, Depth_0 = 0, Depth_1 = 1, } } }