public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { UserFlags flags = requestStream.ReadEnum<UserFlags>(); int? userId = null; //if (flags != UserFlags.ThisUser) { userId = requestStream.ReadInt32(); // } UserBitmap bitmap = requestStream.ReadEnum<UserBitmap>(); responseStream.WriteEnum(bitmap); foreach (UserBitmap value in bitmap.EnumerateFlags()) { switch (value) { case UserBitmap.UserId: responseStream.WriteInt32(0); break; case UserBitmap.Uuid: responseStream.WriteBytes(new byte[16]); break; case UserBitmap.PrimaryGroupId: responseStream.WriteInt32(0); break; } } return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad short forkId = requestStream.ReadInt16(); long offset = requestStream.ReadInt64(); long readBytes = requestStream.ReadInt64(); //byte newLineMask = requestStream.ReadUInt8(); //byte newLineChar = requestStream.ReadUInt8(); IAfpFork fork = session.GetFork(forkId); if (fork == null) { return(AfpResultCode.FPObjectNotFound); } byte[] buffer = new byte[readBytes]; int bytesRead = fork.DataProvider.Read(offset, buffer, 0, (int)readBytes); responseStream.WriteBytes(buffer); if (bytesRead < readBytes) { return(AfpResultCode.FPEOFErr); } return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad short forkId = requestStream.ReadInt16(); long offset = requestStream.ReadInt64(); long readBytes = requestStream.ReadInt64(); //byte newLineMask = requestStream.ReadUInt8(); //byte newLineChar = requestStream.ReadUInt8(); IAfpFork fork = session.GetFork(forkId); if (fork == null) { return AfpResultCode.FPObjectNotFound; } byte[] buffer = new byte[readBytes]; int bytesRead = fork.DataProvider.Read(offset, buffer, 0, (int)readBytes); responseStream.WriteBytes(buffer); if (bytesRead < readBytes) { return AfpResultCode.FPEOFErr; } return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { UserFlags flags = requestStream.ReadEnum <UserFlags>(); int? userId = null; //if (flags != UserFlags.ThisUser) { userId = requestStream.ReadInt32(); // } UserBitmap bitmap = requestStream.ReadEnum <UserBitmap>(); responseStream.WriteEnum(bitmap); foreach (UserBitmap value in bitmap.EnumerateFlags()) { switch (value) { case UserBitmap.UserId: responseStream.WriteInt32(0); break; case UserBitmap.Uuid: responseStream.WriteBytes(new byte[16]); break; case UserBitmap.PrimaryGroupId: responseStream.WriteInt32(0); break; } } return(AfpResultCode.FPNoErr); }
public DsiHeader WriteReply(AfpResultCode resultCode, byte[] resultPayload, AfpStream writeToStream) { DsiHeader replyHeader = this.CreateReply(resultCode, (uint)resultPayload.Length); replyHeader.Write(writeToStream); writeToStream.WriteBytes(resultPayload); return replyHeader; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad AfpSessionTokenTypes type = requestStream.ReadEnum<AfpSessionTokenTypes>(); int idLength = requestStream.ReadInt32(); int? timestamp = null; if (type == AfpSessionTokenTypes.kLoginWithTimeAndID || type == AfpSessionTokenTypes.kReconnWithTimeAndID) { timestamp = requestStream.ReadInt32(); } Guid clientToken = new Guid(requestStream.ReadBytes((uint)idLength)); switch (type) { case AfpSessionTokenTypes.kLoginWithID: { // Find existing session and disconnect it. IAfpSession existingSession = session.Server.FindSession(clientToken, AfpSessionSearchType.ClientIssued); if (existingSession != null) { existingSession.Close(); } break; } case AfpSessionTokenTypes.kLoginWithTimeAndID: { if (!timestamp.HasValue) { return AfpResultCode.FPParamErr; } // Find an existing session. IAfpSession existingSession = session.Server.FindSession(clientToken, AfpSessionSearchType.ClientIssued); if (existingSession != null && existingSession != session) { // Existing session found, transfer resources if timestamp matches. if (!existingSession.Timestamp.HasValue || existingSession.Timestamp.Value != timestamp.Value) { // Timestamp is different, close old session. existingSession.Close(); } } break; } } session.Timestamp = timestamp; session.ClientToken = clientToken; session.ServerToken = Guid.NewGuid(); byte[] token = session.ServerToken.Value.ToByteArray(); responseStream.WriteInt32(token.Length); responseStream.WriteBytes(token); return AfpResultCode.FPNoErr; }
public void SendRequest(DsiCommand command, byte[] payload, AfpTransportReplyHandler replyHandler = null) { DsiHeader header = new DsiHeader() { command = command, flags = DsiFlags.Request, requestId = this.NextRequestId(), errorCodeOrWriteOffset = 0, totalDataLength = (uint)payload.Length }; AfpStream stream = new AfpStream(); header.Write(stream); stream.WriteBytes(payload); if (replyHandler != null) { _replyHandlers[header.requestId] = replyHandler; } byte[] result = stream.ToByteArray(); this.SendBuffer(result); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>(); AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>(); short reqCount = requestStream.ReadInt16(); int startIndex = requestStream.ReadInt32(); int maxReplySize = requestStream.ReadInt32(); AfpPathType pathType = requestStream.ReadEnum<AfpPathType>(); string path = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: path = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: path = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return AfpResultCode.FPObjectNotFound; } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { return AfpResultCode.FPObjectNotFound; } IStorageContainer lookAtContainer = null; if (string.IsNullOrEmpty(path)) { lookAtContainer = container; } else { lookAtContainer = (container.Content(path) as IStorageContainer); } if (lookAtContainer == null) { return AfpResultCode.FPObjectNotFound; } var useContents = lookAtContainer.Contents(); if (fileBitmap == 0) { useContents = useContents.OfType<IStorageContainer>(); } else if (directoryBitmap == 0) { useContents = useContents.OfType<IStorageFile>(); } useContents = useContents .Skip(startIndex-1) .Take(reqCount); var contents = useContents.ToList(); if (contents.Count == 0) { return AfpResultCode.FPObjectNotFound; } responseStream.WriteEnum<AfpFileDirectoryBitmap>(fileBitmap); responseStream.WriteEnum<AfpFileDirectoryBitmap>(directoryBitmap); responseStream.WriteInt16((short)contents.Count); foreach (IStorageItem item in contents) { AfpStream resultRecord = new AfpStream(); resultRecord.WriteUInt16(0); // Length if (item is IStorageContainer) { resultRecord.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap); } else { resultRecord.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap); } resultRecord.WritePadding(); resultRecord.Stream.Position = 0; resultRecord.WriteUInt16((byte)resultRecord.Stream.Length); byte[] recordData = resultRecord.ToByteArray(); responseStream.WriteBytes(recordData); } return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad AfpSessionTokenTypes type = requestStream.ReadEnum <AfpSessionTokenTypes>(); int idLength = requestStream.ReadInt32(); int?timestamp = null; if (type == AfpSessionTokenTypes.kLoginWithTimeAndID || type == AfpSessionTokenTypes.kReconnWithTimeAndID) { timestamp = requestStream.ReadInt32(); } Guid clientToken = new Guid(requestStream.ReadBytes((uint)idLength)); switch (type) { case AfpSessionTokenTypes.kLoginWithID: { // Find existing session and disconnect it. IAfpSession existingSession = session.Server.FindSession(clientToken, AfpSessionSearchType.ClientIssued); if (existingSession != null) { existingSession.Close(); } break; } case AfpSessionTokenTypes.kLoginWithTimeAndID: { if (!timestamp.HasValue) { return(AfpResultCode.FPParamErr); } // Find an existing session. IAfpSession existingSession = session.Server.FindSession(clientToken, AfpSessionSearchType.ClientIssued); if (existingSession != null && existingSession != session) { // Existing session found, transfer resources if timestamp matches. if (!existingSession.Timestamp.HasValue || existingSession.Timestamp.Value != timestamp.Value) { // Timestamp is different, close old session. existingSession.Close(); } } break; } } session.Timestamp = timestamp; session.ClientToken = clientToken; session.ServerToken = Guid.NewGuid(); byte[] token = session.ServerToken.Value.ToByteArray(); responseStream.WriteInt32(token.Length); responseStream.WriteBytes(token); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); short reqCount = requestStream.ReadInt16(); int startIndex = requestStream.ReadInt32(); int maxReplySize = requestStream.ReadInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string path = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: path = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: path = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer lookAtContainer = null; if (string.IsNullOrEmpty(path)) { lookAtContainer = container; } else { lookAtContainer = (container.Content(path) as IStorageContainer); } if (lookAtContainer == null) { return(AfpResultCode.FPObjectNotFound); } var useContents = lookAtContainer.Contents(); if (fileBitmap == 0) { useContents = useContents.OfType <IStorageContainer>(); } else if (directoryBitmap == 0) { useContents = useContents.OfType <IStorageFile>(); } useContents = useContents .Skip(startIndex - 1) .Take(reqCount); var contents = useContents.ToList(); if (contents.Count == 0) { return(AfpResultCode.FPObjectNotFound); } responseStream.WriteEnum <AfpFileDirectoryBitmap>(fileBitmap); responseStream.WriteEnum <AfpFileDirectoryBitmap>(directoryBitmap); responseStream.WriteInt16((short)contents.Count); foreach (IStorageItem item in contents) { AfpStream resultRecord = new AfpStream(); resultRecord.WriteUInt16(0); // Length if (item is IStorageContainer) { resultRecord.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap); } else { resultRecord.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap); } resultRecord.WritePadding(); resultRecord.Stream.Position = 0; resultRecord.WriteUInt16((byte)resultRecord.Stream.Length); byte[] recordData = resultRecord.ToByteArray(); responseStream.WriteBytes(recordData); } return(AfpResultCode.FPNoErr); }