00001 // $Id: FTP_Session.h 90891 2010-06-28 09:55:39Z mcorino $ 00002 00003 /** 00004 * @file FTP_Session.h 00005 * 00006 * @author Martin Corino <mcorino@remedy.nl> 00007 */ 00008 00009 #ifndef ACE_FTP_SESSION_H 00010 #define ACE_FTP_SESSION_H 00011 00012 #include /**/ "ace/pre.h" 00013 00014 #include "ace/SString.h" 00015 #include "ace/Countdown_Time.h" 00016 #include "ace/SOCK_Connector.h" 00017 #include "ace/INET_Addr.h" 00018 #include "ace/INet/INet_Export.h" 00019 #include "ace/INet/FTP_Request.h" 00020 #include "ace/INet/FTP_Response.h" 00021 #include "ace/INet/StreamHandler.h" 00022 #include "ace/INet/Sock_IOStream.h" 00023 00024 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00025 00026 namespace ACE 00027 { 00028 namespace FTP 00029 { 00030 /** 00031 * @class ACE_FTP_Session 00032 * 00033 * @brief Encapsulates FTP session. 00034 * 00035 */ 00036 template <ACE_SYNCH_DECL> 00037 class Session_T 00038 { 00039 public: 00040 typedef ACE::IOS::StreamHandler<ACE_SOCK_STREAM, ACE_SYNCH_USE> connection_type; 00041 00042 enum 00043 { 00044 FTP_PORT = 21 00045 }; 00046 00047 Session_T (); 00048 00049 Session_T (const ACE_Time_Value& timeout); 00050 00051 virtual ~Session_T (); 00052 00053 bool is_connected () const; 00054 00055 bool is_new_connection () const; 00056 00057 void set_host (const ACE_CString& host, u_short port); 00058 00059 void set_host (const ACE_CString& host); 00060 00061 void set_port (u_short port); 00062 00063 const ACE_CString& get_host () const; 00064 00065 u_short get_port () const; 00066 00067 bool connect (bool use_reactor = false); 00068 00069 bool connect (connection_type* connection); 00070 00071 bool send_request (Request& request); 00072 00073 bool receive_response (Response& response); 00074 00075 bool send_interrupt (); 00076 00077 void close (); 00078 00079 bool supports_ftp_extensions () const; 00080 00081 void set_ftp_extension_support (bool f); 00082 00083 bool is_reactive () const; 00084 00085 const ACE_Time_Value& timeout () const; 00086 00087 void get_local_addr (ACE_INET_Addr& loc_addr) const; 00088 00089 private: 00090 enum 00091 { 00092 DEFAULT_TIMEOUT = 30, // sec 00093 00094 INTERRUPT = 244 // Telnet IP signal 00095 }; 00096 00097 ACE_CString host_; 00098 u_short port_; 00099 00100 typedef ACE::IOS::Sock_IOStreamBase<ACE_SYNCH_USE> sock_stream_type; 00101 00102 bool reactive_; 00103 connection_type* connection_; 00104 sock_stream_type* sock_stream_; 00105 ACE_Time_Value ftp_timeout_; 00106 bool cannot_reconnect_; 00107 bool has_ftp_ext_; // RFC 2428 - IPv6 and NAT 00108 bool new_connect_; 00109 }; 00110 00111 typedef Session_T<ACE_NULL_SYNCH> Session; 00112 } 00113 } 00114 00115 ACE_END_VERSIONED_NAMESPACE_DECL 00116 00117 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00118 #include "ace/INet/FTP_Session.cpp" 00119 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00120 00121 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00122 #pragma implementation ("FTP_Session.cpp") 00123 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00124 00125 #include /**/ "ace/post.h" 00126 #endif /* ACE_FTP_SESSION_H */