Minor code refactoring

This commit is contained in:
Tal Aloni 2017-07-26 14:22:00 +03:00
parent 09419f145f
commit 7e3df3f694
4 changed files with 35 additions and 21 deletions

View file

@ -203,6 +203,8 @@
<Compile Include="Server\Shares\NamedPipeShare.cs" /> <Compile Include="Server\Shares\NamedPipeShare.cs" />
<Compile Include="Server\Shares\SMBShareCollection.cs" /> <Compile Include="Server\Shares\SMBShareCollection.cs" />
<Compile Include="Server\SMB1\CancelHelper.cs" /> <Compile Include="Server\SMB1\CancelHelper.cs" />
<Compile Include="Server\SMB1\CloseHelper.cs" />
<Compile Include="Server\SMB1\EchoHelper.cs" />
<Compile Include="Server\SMB1\FileStoreResponseHelper.cs" /> <Compile Include="Server\SMB1\FileStoreResponseHelper.cs" />
<Compile Include="Server\SMB1\NegotiateHelper.cs" /> <Compile Include="Server\SMB1\NegotiateHelper.cs" />
<Compile Include="Server\SMB1\NotifyChangeHelper.cs" /> <Compile Include="Server\SMB1\NotifyChangeHelper.cs" />
@ -210,7 +212,6 @@
<Compile Include="Server\SMB1\NTTransactHelper.cs" /> <Compile Include="Server\SMB1\NTTransactHelper.cs" />
<Compile Include="Server\SMB1\OpenAndXHelper.cs" /> <Compile Include="Server\SMB1\OpenAndXHelper.cs" />
<Compile Include="Server\SMB1\ReadWriteResponseHelper.cs" /> <Compile Include="Server\SMB1\ReadWriteResponseHelper.cs" />
<Compile Include="Server\SMB1\ServerResponseHelper.cs" />
<Compile Include="Server\SMB1\SessionSetupHelper.cs" /> <Compile Include="Server\SMB1\SessionSetupHelper.cs" />
<Compile Include="Server\SMB1\SMB1FileStoreHelper.cs" /> <Compile Include="Server\SMB1\SMB1FileStoreHelper.cs" />
<Compile Include="Server\SMB1\SMB1FileStoreHelper.Query.cs" /> <Compile Include="Server\SMB1\SMB1FileStoreHelper.Query.cs" />

View file

@ -6,14 +6,12 @@
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text;
using SMBLibrary.SMB1; using SMBLibrary.SMB1;
using Utilities; using Utilities;
namespace SMBLibrary.Server.SMB1 namespace SMBLibrary.Server.SMB1
{ {
internal partial class ServerResponseHelper internal class CloseHelper
{ {
internal static SMB1Command GetCloseResponse(SMB1Header header, CloseRequest request, ISMBShare share, SMB1ConnectionState state) internal static SMB1Command GetCloseResponse(SMB1Header header, CloseRequest request, ISMBShare share, SMB1ConnectionState state)
{ {
@ -37,24 +35,11 @@ namespace SMBLibrary.Server.SMB1
return new CloseResponse(); return new CloseResponse();
} }
internal static SMB1Command GetFindClose2Request(SMB1Header header, FindClose2Request request, SMB1ConnectionState state) internal static SMB1Command GetFindClose2Response(SMB1Header header, FindClose2Request request, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
session.RemoveOpenSearch(request.SearchHandle); session.RemoveOpenSearch(request.SearchHandle);
return new FindClose2Response(); return new FindClose2Response();
} }
internal static List<SMB1Command> GetEchoResponse(EchoRequest request)
{
List<SMB1Command> response = new List<SMB1Command>();
for (int index = 0; index < request.EchoCount; index++)
{
EchoResponse echo = new EchoResponse();
echo.SequenceNumber = (ushort)index;
echo.SMBData = request.SMBData;
response.Add(echo);
}
return response;
}
} }
} }

View file

@ -0,0 +1,28 @@
/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
*
* You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*/
using System;
using System.Collections.Generic;
using SMBLibrary.SMB1;
namespace SMBLibrary.Server.SMB1
{
internal class EchoHelper
{
internal static List<SMB1Command> GetEchoResponse(EchoRequest request)
{
List<SMB1Command> response = new List<SMB1Command>();
for (int index = 0; index < request.EchoCount; index++)
{
EchoResponse echo = new EchoResponse();
echo.SequenceNumber = (ushort)index;
echo.SMBData = request.SMBData;
response.Add(echo);
}
return response;
}
}
}

View file

@ -127,7 +127,7 @@ namespace SMBLibrary.Server
} }
else if (command is EchoRequest) else if (command is EchoRequest)
{ {
return ServerResponseHelper.GetEchoResponse((EchoRequest)command); return EchoHelper.GetEchoResponse((EchoRequest)command);
} }
else else
{ {
@ -172,7 +172,7 @@ namespace SMBLibrary.Server
else if (command is CloseRequest) else if (command is CloseRequest)
{ {
CloseRequest request = (CloseRequest)command; CloseRequest request = (CloseRequest)command;
return ServerResponseHelper.GetCloseResponse(header, request, share, state); return CloseHelper.GetCloseResponse(header, request, share, state);
} }
else if (command is FlushRequest) else if (command is FlushRequest)
{ {
@ -249,7 +249,7 @@ namespace SMBLibrary.Server
} }
else if (command is FindClose2Request) else if (command is FindClose2Request)
{ {
return ServerResponseHelper.GetFindClose2Request(header, (FindClose2Request)command, state); return CloseHelper.GetFindClose2Response(header, (FindClose2Request)command, state);
} }
else if (command is TreeDisconnectRequest) else if (command is TreeDisconnectRequest)
{ {