1 #ifndef FILEZILLA_ENGINE_PROXY_HEADER 2 #define FILEZILLA_ENGINE_PROXY_HEADER 3 4 #include <libfilezilla/buffer.hpp> 5 #include <libfilezilla/socket.hpp> 6 7 enum class ProxyType { 8 NONE, 9 HTTP, 10 SOCKS5, 11 SOCKS4, 12 13 count 14 }; 15 16 class CControlSocket; 17 class CProxySocket final : protected fz::event_handler, public fz::socket_layer 18 { 19 public: 20 CProxySocket(fz::event_handler* pEvtHandler, fz::socket_interface & next_layer, CControlSocket* pOwner, 21 ProxyType t, fz::native_string const& proxy_host, unsigned int proxy_port, std::wstring const& user, std::wstring const& pass); 22 virtual ~CProxySocket(); 23 24 static std::wstring Name(ProxyType t); 25 26 virtual int connect(fz::native_string const& host, unsigned int port, fz::address_type family = fz::address_type::unknown) override; 27 get_state()28 fz::socket_state get_state() const override { return state_; } 29 30 virtual int read(void *buffer, unsigned int size, int& error) override; 31 virtual int write(void const* buffer, unsigned int size, int& error) override; 32 GetProxyType()33 ProxyType GetProxyType() const { return type_; } 34 std::wstring GetUser() const; 35 std::wstring GetPass() const; 36 37 virtual fz::native_string peer_host() const override; 38 virtual int peer_port(int& error) const override; 39 40 virtual int shutdown() override; 41 42 protected: 43 CControlSocket* m_pOwner; 44 45 ProxyType type_{}; 46 fz::native_string proxy_host_; 47 unsigned int proxy_port_{}; 48 std::string user_; 49 std::string pass_; 50 51 fz::native_string host_; 52 unsigned int port_{}; 53 fz::address_type family_{}; 54 55 fz::socket_state state_{}; 56 57 int m_handshakeState{}; 58 59 fz::buffer sendBuffer_; 60 fz::buffer receiveBuffer_; 61 62 virtual void operator()(fz::event_base const& ev) override; 63 void OnSocketEvent(socket_event_source* source, fz::socket_event_flag t, int error); 64 65 void OnReceive(); 66 void OnSend(); 67 68 bool m_can_write{}; 69 bool m_can_read{}; 70 }; 71 72 #endif 73