// Token: 0x0600159A RID: 5530 RVA: 0x0007FF68 File Offset: 0x0007E168 internal static int CopyStream(Stream source, Stream target, Encoding encoding, int charCount, bool needCrc, out uint crc) { crc = 0U; byte[] array = null; StreamHelper.CharArrayBuffer charArrayBuffer = null; int num = 0; if (charCount == 0) { return(0); } if (charCount < 0) { charCount = int.MaxValue; } int result; try { array = StreamHelper.bytesBufferPool.Acquire(); charArrayBuffer = StreamHelper.charsBufferPool.Acquire(); if (array == null) { throw new InvalidOperationException("bytesBuffer should never be null."); } if (charArrayBuffer == null) { throw new InvalidOperationException("charsBuffer should never be null."); } StreamReader streamReader = new StreamReader(source, encoding); do { int num2 = (6144 > charCount - num - 1) ? (charCount - num - 1) : 6144; if (num2 == 0) { num2 = 1; } int num3 = streamReader.ReadBlock(charArrayBuffer.Buffer, 0, num2); if (num3 == 0) { break; } if (StreamHelper.NeedToHandleSurrogate(charArrayBuffer.Buffer, num2, num3)) { int num4 = streamReader.Read(); if (num4 != -1) { charArrayBuffer.Buffer[num3] = (char)num4; char c = charArrayBuffer.Buffer[num3]; char c2 = charArrayBuffer.Buffer[num3 - 1]; if (!char.IsSurrogatePair(c2, c)) { string message = string.Format(CultureInfo.InvariantCulture, "Invalid surrogate chars: first={0}, second={1}", new object[] { c2, c }); AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, null, message); } num3++; } } num += num3; int bytes = encoding.GetBytes(charArrayBuffer.Buffer, 0, num3, array, 0); target.Write(array, 0, bytes); if (needCrc) { crc = StreamHelper.UpdateCrc32(crc, array, 0, bytes); } }while (num < charCount); result = num; } finally { if (array != null) { StreamHelper.bytesBufferPool.Release(array); } if (charArrayBuffer != null) { charArrayBuffer.Clear(); StreamHelper.charsBufferPool.Release(charArrayBuffer); } } return(result); }
// Token: 0x0600074D RID: 1869 RVA: 0x00027EFC File Offset: 0x000260FC public void Execute() { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrary Fetch command received. Processing request..."); Uri uri = null; try { uri = new Uri(this.linkId); } catch (UriFormatException innerException) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Bad document Uri {0} was specified!", new object[] { this.linkId })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException, false); } AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Processing Fetch command with Uri {0}.", uri.AbsoluteUri); if (!DocumentLibraryUtility.IsTrustedProtocol(uri.Scheme)) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: untrusted protocol: {0}!", new object[] { uri.Scheme })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadProtocolInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } if (!DocumentLibraryUtility.IsInternalUri(uri)) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Uri must be internal: {0}!", new object[] { uri.Host })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ExternalProtocolInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } AuthenticationContext authenticationContext = new AuthenticationContext(); try { IPrincipal principal; if (this.userPassword == null) { principal = this.user.WindowsPrincipal; if (principal == null) { if (GlobalSettings.EnableCredentialRequest && this.user.Context.Request.Version >= 121) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedPromptForCredsToProxy2"); throw new AirSyncPermanentException(StatusCode.ItemOperations_CredentialsRequired, false); } this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedCredsToProxy2"); throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false); } } else { SecurityStatus securityStatus = authenticationContext.LogonUser(this.userName, this.userPassword); this.userPassword.Dispose(); this.userPassword = null; if (securityStatus != SecurityStatus.OK) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Authentication failed with status {0}.", new object[] { securityStatus })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, string.Format(CultureInfo.InvariantCulture, "AuthenticationErrorStatus{0}", new object[] { securityStatus })); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false); } principal = new WindowsPrincipal(authenticationContext.Identity); } ClassifyResult classifyResult = LinkClassifier.ClassifyLinks(principal, new Uri[] { uri })[0]; if (classifyResult.Error != ClassificationError.None) { AirSyncDiagnostics.TraceDebug <string, ClassificationError>(ExTraceGlobals.RequestsTracer, this, "The LinkClassifier failed to classify the link {0}, returned {1}", this.linkId, classifyResult.Error); switch (classifyResult.Error) { case ClassificationError.ConnectionFailed: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassConnFailedInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_Conflict, null, false); case ClassificationError.AccessDenied: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassDeniedInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false); case ClassificationError.ObjectNotFound: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassNotFoundInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ClientServerConversion, null, false); case ClassificationError.UriTypeNotSupported: case ClassificationError.InvalidUri: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassBadUriInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ProtocolError, null, false); } this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassFailureInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false); } IDocument document = null; UncSession uncSession = null; SharepointSession sharepointSession = null; if ((classifyResult.UriFlags & UriFlags.UncDocument) == UriFlags.UncDocument) { if (!DocumentLibraryUtility.IsUncAccessEnabled(this.user)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } if (DocumentLibraryUtility.IsBlockedHostName(uri.Host)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } uncSession = UncSession.Open(classifyResult.ObjectId, principal); } else { if ((classifyResult.UriFlags & UriFlags.SharepointDocument) != UriFlags.SharepointDocument) { AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Fetch", this.linkId, classifyResult.UriFlags); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false); } if (!DocumentLibraryUtility.IsWssAccessEnabled(this.user)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "WssDeniedInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } if (DocumentLibraryUtility.IsBlockedHostName(uri.Host)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.SharePointDocs); sharepointSession = SharepointSession.Open(classifyResult.ObjectId, principal); } try { if (uncSession != null) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Reading UNC document..."); document = UncDocument.Read(uncSession, classifyResult.ObjectId); } else { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Reading Sharepoint document..."); AirSyncDiagnostics.Assert(sharepointSession != null); document = SharepointDocument.Read(sharepointSession, classifyResult.ObjectId); } } catch (ObjectNotFoundException innerException2) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException2, false); } catch (AccessDeniedException innerException3) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException3, false); } this.documentSize = (int)document.Size; if (this.documentSize == 0) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "The file {0} was found to be empty!", this.linkId); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "EmptyDocInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_NotificationGUID, null, false); } object obj = document.TryGetProperty(DocumentLibraryItemSchema.LastModifiedDate); if (obj is PropertyError) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "GeneralErrorInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false); } ExDateTime exDateTime; if (obj is DateTime) { exDateTime = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)obj); } else { exDateTime = (ExDateTime)obj; } this.version = exDateTime.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", CultureInfo.InvariantCulture); if (this.rangeSpecified && this.minRange >= this.documentSize) { AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, this, "The minimum range specified {0} is greater than the document size {1}", this.minRange, this.documentSize); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadMinSizeInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ObjectNotFound, null, false); } using (Stream document2 = document.GetDocument()) { int num; if (this.rangeSpecified) { num = this.maxRange - this.minRange + 1; } else { num = this.documentSize; } if (uncSession != null) { this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.UNCFiles); this.user.Context.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.UNCBytes, num); } if (sharepointSession != null) { this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.SharePointDocs); this.user.Context.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.SharePointBytes, num); } this.outStream = new MemoryStream(num); if (num > GlobalSettings.MaxDocumentDataSize) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DocTooBigInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_NotificationsNotProvisioned, false); } try { StreamHelper.CopyStream(document2, this.outStream, this.minRange, num); } catch (IOException innerException4) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException4, false); } } } catch (UnknownErrorException innerException5) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException5, false); } catch (DocumentModifiedException innerException6) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch3"); throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException6, false); } catch (DocumentStreamAccessDeniedException innerException7) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch3"); throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException7, false); } catch (ObjectMovedOrDeletedException innerException8) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException8, false); } catch (DocumentLibraryException innerException9) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "GeneralErrorInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, innerException9, false); } finally { if (authenticationContext != null) { authenticationContext.Dispose(); authenticationContext = null; } } }
// Token: 0x0600159E RID: 5534 RVA: 0x00080150 File Offset: 0x0007E350 internal static int CopyStream(Stream source, Stream target, int offset, int count) { uint num; return(StreamHelper.CopyStream(source, target, offset, count, false, out num)); }
// Token: 0x0600159D RID: 5533 RVA: 0x00080141 File Offset: 0x0007E341 internal static int CopyStream(Stream source, Stream target, int byteCount, out uint crc) { return(StreamHelper.CopyStream(source, target, 0, byteCount, true, out crc)); }
// Token: 0x0600159C RID: 5532 RVA: 0x00080128 File Offset: 0x0007E328 internal static int CopyStream(Stream source, Stream target, int byteCount) { uint num; return(StreamHelper.CopyStream(source, target, 0, byteCount, false, out num)); }
// Token: 0x0600159B RID: 5531 RVA: 0x00080118 File Offset: 0x0007E318 internal static int CopyStream(Stream source, Stream target) { return(StreamHelper.CopyStream(source, target, int.MaxValue)); }
private static string GetAttachmentItself(Attachment attachment, Stream outStream, int offset, int count, out int total) { string text = string.Empty; total = 0; StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase; if (streamAttachmentBase != null) { OleAttachment oleAttachment = streamAttachmentBase as OleAttachment; Stream stream = null; try { if (oleAttachment != null) { stream = oleAttachment.TryConvertToImage(ImageFormat.Jpeg); if (stream != null) { text = "image/jpeg"; } } if (stream == null) { stream = streamAttachmentBase.GetContentStream(); } if (string.IsNullOrEmpty(text)) { text = attachment.ContentType; } if (string.IsNullOrEmpty(text)) { text = attachment.CalculatedContentType; } if (stream.Length > 0L) { if ((long)offset >= stream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num = (count == -1) ? ((int)stream.Length) : count; if (num > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(stream, outStream, offset, num); total = (int)stream.Length; } } finally { if (stream != null) { stream.Dispose(); stream = null; } } return(text); } ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { text = "message/rfc822"; OutboundConversionOptions outboundConversionOptions = AirSyncUtility.GetOutboundConversionOptions(); using (AirSyncStream airSyncStream = new AirSyncStream()) { try { ItemConversion.ConvertItemToMime(item, airSyncStream, outboundConversionOptions); } catch (ConversionFailedException innerException) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "MIME conversion failed for Attachment {0}!", new object[] { attachment }), innerException); } if (airSyncStream.Length > 0L) { if ((long)offset >= airSyncStream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num2 = (count == -1) ? ((int)airSyncStream.Length) : count; if (num2 > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(airSyncStream, outStream, offset, num2); total = (int)airSyncStream.Length; } } } return(text); } throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Attachment {0} is of invalid format!", new object[] { attachment })); }