Add FTP protocol debugging facilities.
[dftpd.git] / Session.hpp
blob1df9fca14a73ab2b91800bf634fe8ada3503890c
1 #ifndef __DFTPD__SESSION_HPP__
2 #define __DFTPD__SESSION_HPP__
4 #include <list>
5 #include <string>
6 #include "Auth.hpp"
7 #include "Data.hpp"
8 #include "Filesystem.hpp"
9 #include "ServerPtr.hpp"
10 #include "SessionControllerPtr.hpp"
11 #include "SessionPtr.hpp"
12 #include "String.hpp"
13 #include "Telnet.hpp"
14 #include "TelnetPtr.hpp"
16 class Session
18 enum State
20 S_GREETING,
21 S_LOGIN,
22 S_PASSWORD,
23 S_READY
26 enum PassState
28 PS_NONE,
29 PS_LOGGEDIN,
30 PS_BADPASS
33 public:
34 static SessionPtr Create( int controlSock, const SessionControllerPtr& sessionController, const AuthPtr& auth, const std::string& ip, const ServerWPtr& server );
35 ~Session();
37 void Tick();
39 void DataConnectionFinished();
40 void DataConnectionError();
41 void OutOfSpace();
43 std::list<int> GetFds() const;
45 private:
46 Session( int controlSock, const SessionControllerPtr& sessionController, const AuthPtr& auth, const std::string& ip, const ServerWPtr& server );
48 void Remove();
50 void SendGreeting();
51 void SendSyntaxError();
52 void SendNotLoggedIn();
53 void SendDataConnectionBusy();
54 void SendSyst();
56 bool AwaitLogin();
57 PassState AwaitPassword();
58 void AwaitReady();
60 void HandleMode( const Command& cmd );
61 void HandleType( const Command& cmd );
62 void HandleStru( const Command& cmd );
63 void HandlePort( const Command& cmd );
64 void HandleRetr( const Command& cmd );
65 void HandleStor( const Command& cmd );
66 void HandleAbor();
67 void HandleList( const Command& cmd );
68 void HandlePasv( const Command& cmd );
69 void HandleDele( const Command& cmd );
70 void HandleMkd( const Command& cmd );
71 void HandleRmd( const Command& cmd );
73 void PrintDirectory();
74 void ChangeDirectory( const Command& cmd );
75 void ChangeDirectory( const std::string& cmd );
77 void Upload( const Command& cmd );
78 void Download( const Command& cmd );
80 bool OpenDataConnection();
82 Command GetCommand() { return ParseCommand( m_control->GetBuf() ); }
85 TelnetPtr m_control;
86 int m_controlSock;
87 int m_listenSock;
89 int m_dataPort;
90 std::string m_dataAddress;
91 DataPtr m_data;
93 int m_id;
94 static int m_counter;
96 State m_state;
98 SessionControllerWPtr m_sessionController;
99 SessionWPtr m_this;
100 AuthPtr m_auth;
101 FilesystemPtr m_filesystem;
102 ServerWPtr m_server;
104 std::string m_user;
105 std::string m_ip;
108 #endif