public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum<AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } AfpPathType newNameType = requestStream.ReadEnum<AfpPathType>(); string newName = null; switch (newNameType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: newName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: newName = 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; } IStorageItem renameItem = container.Content(pathName); if (renameItem == null) { return AfpResultCode.FPObjectNotFound; } renameItem.Rename(newName); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad ushort volumeId = requestStream.ReadUInt16(); uint fileId = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageFile item = volume.GetNode(fileId) as IStorageFile; if (item == null) { return(AfpResultCode.FPObjectNotFound); } responseStream.WriteEnum(fileBitmap); responseStream.WriteStorageFileInfo(volume, item, fileBitmap, false); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding requestStream.ReadUInt16(); // Read unused flags string version = requestStream.ReadPascalString(); string uam = requestStream.ReadPascalString(); requestStream.ReadUInt8(); // User type always 3 string userName = requestStream.ReadUTF8String(); requestStream.ReadUInt8(); string pathname = requestStream.ReadUTF8String(); requestStream.ReadPadding(); IAfpUserAuthenticationMethod method = session.Server.GetAuthenticationMethod(uam); if (method == null) { return(AfpResultCode.FPBadUAM); } session.AuthenticationMethod = method; AfpUserAuthenticationResult result = method.Authenticate(session, version, pathname, userName, requestStream); return(result.Execute(session, responseStream)); }
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 ushort volumeId = requestStream.ReadUInt16(); uint fileId = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>(); IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return AfpResultCode.FPObjectNotFound; } IStorageFile item = volume.GetNode(fileId) as IStorageFile; if (item == null) { return AfpResultCode.FPObjectNotFound; } responseStream.WriteEnum(fileBitmap); responseStream.WriteStorageFileInfo(volume, item, fileBitmap, false); 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 AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad AfpVolumeBitmap volumeBitmap = requestStream.ReadEnum <AfpVolumeBitmap>(); string volumeName = requestStream.ReadPascalString(); IStorageProvider provider = session.Server.Shares .Where(s => s.Name == volumeName) .FirstOrDefault(); if (provider == null) { return(AfpResultCode.FPObjectNotFound); } IAfpVolume volume = session.OpenVolume(provider); if (volume == null) { return(AfpResultCode.FPAccessDenied); } responseStream.WriteEnum(volumeBitmap); responseStream.WriteVolumeInfo(volume, volumeBitmap); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { byte flag = requestStream.ReadUInt8(); short forkId = requestStream.ReadInt16(); long offset = requestStream.ReadInt64(); long reqCount = requestStream.ReadInt64(); IAfpFork fork = session.GetFork(forkId); if (fork == null) { return AfpResultCode.FPObjectNotFound; } byte[] writeData = requestStream.ReadBytes((uint)reqCount); long position = 0; if (flag == 1) { // End of the fork position = (fork.DataProvider.Length - offset); } else { position = offset; } fork.DataProvider.Write(position, writeData, 0, writeData.Length); responseStream.WriteUInt64((ulong)(position + writeData.LongLength)); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { byte flag = requestStream.ReadUInt8(); short forkId = requestStream.ReadInt16(); long offset = requestStream.ReadInt64(); long reqCount = requestStream.ReadInt64(); IAfpFork fork = session.GetFork(forkId); if (fork == null) { return(AfpResultCode.FPObjectNotFound); } byte[] writeData = requestStream.ReadBytes((uint)reqCount); long position = 0; if (flag == 1) { // End of the fork position = (fork.DataProvider.Length - offset); } else { position = offset; } fork.DataProvider.Write(position, writeData, 0, writeData.Length); responseStream.WriteUInt64((ulong)(position + writeData.LongLength)); 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 AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding requestStream.ReadUInt16(); // Read unused flags string version = requestStream.ReadPascalString(); string uam = requestStream.ReadPascalString(); requestStream.ReadUInt8(); // User type always 3 string userName = requestStream.ReadUTF8String(); requestStream.ReadUInt8(); string pathname = requestStream.ReadUTF8String(); requestStream.ReadPadding(); IAfpUserAuthenticationMethod method = session.Server.GetAuthenticationMethod(uam); if (method == null) { return AfpResultCode.FPBadUAM; } session.AuthenticationMethod = method; AfpUserAuthenticationResult result = method.Authenticate(session, version, pathname, userName, requestStream); return result.Execute(session, responseStream); }
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 AfpVolumeBitmap volumeBitmap = requestStream.ReadEnum<AfpVolumeBitmap>(); string volumeName = requestStream.ReadPascalString(); IStorageProvider provider = session.Server.Shares .Where(s => s.Name == volumeName) .FirstOrDefault(); if (provider == null) { return AfpResultCode.FPObjectNotFound; } IAfpVolume volume = session.OpenVolume(provider); if (volume == null) { return AfpResultCode.FPAccessDenied; } responseStream.WriteEnum(volumeBitmap); responseStream.WriteVolumeInfo(volume, volumeBitmap); 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) { byte hardCreate = requestStream.ReadUInt8(); ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { throw new StorageItemNotFoundException(); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { throw new StorageItemNotFoundException(); } IStorageFile existingFile = container.Content(pathName) as IStorageFile; if (existingFile != null && hardCreate == 0) { return(AfpResultCode.FPObjectExists); } IStorageFile newFile = container.CreateFile(pathName); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { responseStream.WriteMacintoshDate(DateTime.Now); responseStream.WriteUInt8((byte)session.Server.Shares.Count); // Documentation says int16_t ? foreach (IStorageProvider share in session.Server.Shares) { responseStream.WriteUInt8(0); // Flags responseStream.WritePascalString(share.Name); } 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(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = 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 newContainer = container.CreateContainer(pathName); uint newContainerId = volume.GetNode(newContainer); responseStream.WriteUInt32(newContainerId); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { responseStream.WriteMacintoshDate(DateTime.Now); responseStream.WriteUInt8((byte)session.Server.Shares.Count); // Documentation says int16_t ? foreach (IStorageProvider share in session.Server.Shares) { responseStream.WriteUInt8(0); // Flags responseStream.WritePascalString(share.Name); } return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return AfpResultCode.FPObjectNotFound; } volume.Close(); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { string version = requestStream.ReadPascalString(); string uam = requestStream.ReadPascalString(); IAfpUserAuthenticationMethod method = session.Server.GetAuthenticationMethod(uam); if (method == null) { return AfpResultCode.FPBadUAM; } AfpUserAuthenticationResult result = method.Authenticate(session, version, null, null, requestStream); return result.Execute(session, responseStream); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); short forkId = requestStream.ReadInt16(); IAfpFork fork = session.GetFork(forkId); if (fork == null) { return AfpResultCode.FPObjectNotFound; } fork.Close(); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { string version = requestStream.ReadPascalString(); string uam = requestStream.ReadPascalString(); IAfpUserAuthenticationMethod method = session.Server.GetAuthenticationMethod(uam); if (method == null) { return(AfpResultCode.FPBadUAM); } AfpUserAuthenticationResult result = method.Authenticate(session, version, null, null, requestStream); return(result.Execute(session, responseStream)); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } volume.Close(); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); short forkId = requestStream.ReadInt16(); IAfpFork fork = session.GetFork(forkId); if (fork == null) { return(AfpResultCode.FPObjectNotFound); } fork.Close(); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { byte hardCreate = requestStream.ReadUInt8(); ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum<AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { throw new StorageItemNotFoundException(); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { throw new StorageItemNotFoundException(); } IStorageFile existingFile = container.Content(pathName) as IStorageFile; if (existingFile != null && hardCreate == 0) { return AfpResultCode.FPObjectExists; } IStorageFile newFile = container.CreateFile(pathName); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad ushort volumeId = requestStream.ReadUInt16(); AfpVolumeBitmap bitmap = requestStream.ReadEnum<AfpVolumeBitmap>(); IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return AfpResultCode.FPObjectNotFound; } responseStream.WriteEnum(bitmap); responseStream.WriteVolumeInfo(volume, bitmap); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad ushort volumeId = requestStream.ReadUInt16(); AfpVolumeBitmap bitmap = requestStream.ReadEnum <AfpVolumeBitmap>(); IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } responseStream.WriteEnum(bitmap); responseStream.WriteVolumeInfo(volume, bitmap); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding requestStream.ReadInt16(); // Type (always zero) int tokenLength = requestStream.ReadInt32(); byte[] tokenData = requestStream.ReadBytes((uint)tokenLength); Guid token = new Guid(tokenData); IAfpSession otherSession = session.Server.FindSession(token, AfpSessionSearchType.ServerIssued); if (otherSession == null) { return AfpResultCode.FPMiscErr; } otherSession.Recover(session); return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding requestStream.ReadInt16(); // Type (always zero) int tokenLength = requestStream.ReadInt32(); byte[] tokenData = requestStream.ReadBytes((uint)tokenLength); Guid token = new Guid(tokenData); IAfpSession otherSession = session.Server.FindSession(token, AfpSessionSearchType.ServerIssued); if (otherSession == null) { return(AfpResultCode.FPMiscErr); } otherSession.Recover(session); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { byte flag = requestStream.ReadUInt8(); ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); bool resourceFork = (flag == 0x80); if (resourceFork) { Log.Add(this, EntryType.Error, "Session '{0}' attempted to open resource fork, failing...", session); return(AfpResultCode.FPMiscErr); } AfpFileDirectoryBitmap bitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); AfpAccessModes accessMode = requestStream.ReadEnum <AfpAccessModes>(); 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) { throw new StorageItemNotFoundException(); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { throw new StorageItemNotFoundException(); } IStorageFile file = (container.Content(path) as IStorageFile); if (file == null) { throw new StorageItemNotFoundException(); } IAfpFork info = session.OpenFork(file, accessMode); if (info == null) { throw new StorageItemNotFoundException(); } responseStream.WriteEnum <AfpFileDirectoryBitmap>(bitmap); responseStream.WriteInt16(info.Identifier); responseStream.WriteStorageFileInfo(volume, file, bitmap); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint sourceDirId = requestStream.ReadUInt32(); uint destDirId = requestStream.ReadUInt32(); AfpPathType sourcePathType = requestStream.ReadEnum <AfpPathType>(); string sourcePathName = null; switch (sourcePathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: sourcePathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: sourcePathName = requestStream.ReadUTF8StringWithHint(); break; } AfpPathType destPathType = requestStream.ReadEnum <AfpPathType>(); string destPathName = null; switch (destPathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: destPathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: destPathName = requestStream.ReadUTF8StringWithHint(); break; } AfpPathType newPathType = requestStream.ReadEnum <AfpPathType>(); string newPathName = null; switch (newPathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: newPathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: newPathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); IStorageContainer sourceContainer = sourceDirId == 2 ? volume.StorageProvider : (IStorageContainer)volume.GetNode(sourceDirId); IStorageContainer destinationContainer = destDirId == 2 ? volume.StorageProvider : (IStorageContainer)volume.GetNode(destDirId); if (sourceContainer == null || destinationContainer == null) { return(AfpResultCode.FPObjectNotFound); } IStorageItem sourceItem = null; if (!string.IsNullOrEmpty(destPathName)) { destinationContainer = destinationContainer.Content(destPathName) as IStorageContainer; if (destinationContainer == null) { return(AfpResultCode.FPObjectNotFound); } } if (!string.IsNullOrEmpty(sourcePathName)) { sourceItem = sourceContainer.Content(sourcePathName); } else { sourceItem = sourceContainer; } if (sourceItem == null) { return(AfpResultCode.FPObjectNotFound); } if (string.IsNullOrEmpty(newPathName)) { newPathName = sourceItem.Name; } if (destinationContainer.Content(newPathName) != null) { return(AfpResultCode.FPObjectExists); } sourceItem.Move(destinationContainer); sourceItem.Rename(newPathName); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { byte flag = requestStream.ReadUInt8(); ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); bool resourceFork = (flag == 0x80); if (resourceFork) { Log.Add(this, EntryType.Error, "Session '{0}' attempted to open resource fork, failing...", session); return AfpResultCode.FPMiscErr; } AfpFileDirectoryBitmap bitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>(); AfpAccessModes accessMode = requestStream.ReadEnum<AfpAccessModes>(); 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) { throw new StorageItemNotFoundException(); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { throw new StorageItemNotFoundException(); } IStorageFile file = (container.Content(path) as IStorageFile); if (file == null) { throw new StorageItemNotFoundException(); } IAfpFork info = session.OpenFork(file, accessMode); if (info == null) { throw new StorageItemNotFoundException(); } responseStream.WriteEnum<AfpFileDirectoryBitmap>(bitmap); responseStream.WriteInt16(info.Identifier); responseStream.WriteStorageFileInfo(volume, file, bitmap); 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(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = 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); } IStorageItem deleteItem = null; if (!string.IsNullOrEmpty(pathName)) { deleteItem = container.Content(pathName); } if (deleteItem == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer deleteContainer = (deleteItem as IStorageContainer); if (deleteContainer != null && deleteContainer.Contents().Count() > 0) { return(AfpResultCode.FPDirNotEmpty); } deleteItem.Delete(); return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { session.Logout(); 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; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint sourceDirId = requestStream.ReadUInt32(); uint destDirId = requestStream.ReadUInt32(); AfpPathType sourcePathType = requestStream.ReadEnum<AfpPathType>(); string sourcePathName = null; switch (sourcePathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: sourcePathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: sourcePathName = requestStream.ReadUTF8StringWithHint(); break; } AfpPathType destPathType = requestStream.ReadEnum<AfpPathType>(); string destPathName = null; switch (destPathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: destPathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: destPathName = requestStream.ReadUTF8StringWithHint(); break; } AfpPathType newPathType = requestStream.ReadEnum<AfpPathType>(); string newPathName = null; switch (newPathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: newPathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: newPathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); IStorageContainer sourceContainer = sourceDirId == 2 ? volume.StorageProvider : (IStorageContainer)volume.GetNode(sourceDirId); IStorageContainer destinationContainer = destDirId == 2 ? volume.StorageProvider : (IStorageContainer)volume.GetNode(destDirId); if (sourceContainer == null || destinationContainer == null) { return AfpResultCode.FPObjectNotFound; } IStorageItem sourceItem = null; if (!string.IsNullOrEmpty(destPathName)) { destinationContainer = destinationContainer.Content(destPathName) as IStorageContainer; if (destinationContainer == null) { return AfpResultCode.FPObjectNotFound; } } if (!string.IsNullOrEmpty(sourcePathName)) { sourceItem = sourceContainer.Content(sourcePathName); } else { sourceItem = sourceContainer; } if (sourceItem == null) { return AfpResultCode.FPObjectNotFound; } if (string.IsNullOrEmpty(newPathName)) { newPathName = sourceItem.Name; } if (destinationContainer.Content(newPathName) != null) { return AfpResultCode.FPObjectExists; } sourceItem.Move(destinationContainer); sourceItem.Rename(newPathName); 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); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad ushort volumeId = requestStream.ReadUInt16(); uint directoryID = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>(); AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum<AfpFileDirectoryBitmap>(); AfpPathType pathType = requestStream.ReadEnum<AfpPathType>(); string pathname = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathname = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathname = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return AfpResultCode.FPObjectNotFound; } IStorageContainer container = null; if (directoryID == 2) { container = volume.StorageProvider; } else if (directoryID == 1) { if (pathname == volume.StorageProvider.Name) { container = volume.StorageProvider; } } else { container = volume.GetNode(directoryID) as IStorageContainer; } if (container == null) { return AfpResultCode.FPObjectNotFound; } IStorageItem item = null; if (directoryID == 1) { item = container; } else { if (string.IsNullOrEmpty(pathname)) { item = container; } else { item = container.Content(pathname); } } if (item == null) { return AfpResultCode.FPObjectNotFound; } responseStream.WriteEnum(fileBitmap); responseStream.WriteEnum(directoryBitmap); if (item is IStorageContainer) { responseStream.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap); } else { responseStream.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap); } return AfpResultCode.FPNoErr; }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Pad ushort volumeId = requestStream.ReadUInt16(); uint directoryID = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathname = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathname = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathname = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer container = null; if (directoryID == 2) { container = volume.StorageProvider; } else if (directoryID == 1) { if (pathname == volume.StorageProvider.Name) { container = volume.StorageProvider; } } else { container = volume.GetNode(directoryID) as IStorageContainer; } if (container == null) { return(AfpResultCode.FPObjectNotFound); } IStorageItem item = null; if (directoryID == 1) { item = container; } else { if (string.IsNullOrEmpty(pathname)) { item = container; } else { item = container.Content(pathname); } } if (item == null) { return(AfpResultCode.FPObjectNotFound); } responseStream.WriteEnum(fileBitmap); responseStream.WriteEnum(directoryBitmap); if (item is IStorageContainer) { responseStream.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap); } else { responseStream.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap); } return(AfpResultCode.FPNoErr); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { 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); }