Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef ACE_FTP_CLIENT_REQUEST_HANDLER_H
00010 #define ACE_FTP_CLIENT_REQUEST_HANDLER_H
00011
00012 #include "ace/pre.h"
00013
00014 #include "ace/config-all.h"
00015
00016 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00017 # pragma once
00018 #endif
00019
00020 #include "ace/Synch_Traits.h"
00021 #include "ace/Thread_Mutex.h"
00022 #include "ace/INet/INet_Export.h"
00023 #include "ace/INet/IOS_util.h"
00024 #include "ace/INet/StreamInterceptor.h"
00025 #include "ace/INet/ClientRequestHandler.h"
00026 #include "ace/INet/FTP_Request.h"
00027 #include "ace/INet/FTP_Response.h"
00028 #include "ace/INet/FTP_Session.h"
00029 #include "ace/INet/FTP_URL.h"
00030 #include "ace/INet/FTP_IOStream.h"
00031 #include "ace/INet/Sock_IOStream.h"
00032
00033 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00034
00035 namespace ACE
00036 {
00037 namespace FTP
00038 {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 class ACE_INET_Export ClientRequestHandler
00049 : public ACE::INet::ClientINetRequestHandler,
00050 public ACE::IOS::StreamInterceptor
00051 {
00052 public:
00053 ClientRequestHandler (bool passive_mode = true);
00054 virtual ~ClientRequestHandler ();
00055
00056 bool uses_passive_mode () const;
00057
00058 void use_passive_mode ();
00059
00060 void use_active_mode (u_short port = 0);
00061
00062 u_short uses_active_port () const;
00063
00064 virtual Request& request ();
00065
00066 virtual const Request& request () const;
00067
00068 virtual Response& response ();
00069
00070 virtual const Response& response () const;
00071
00072 std::ostream& request_stream ();
00073
00074 virtual std::istream& response_stream ();
00075
00076 virtual bool is_response_ok () const;
00077
00078 virtual std::istream& handle_open_request (const ACE::INet::URL_Base& url);
00079
00080 virtual std::istream& handle_get_request (const URL& url, bool binary=true);
00081
00082
00083
00084
00085
00086 void quit_connection ();
00087
00088 static const ACE_CString anonymous_user_;
00089
00090 protected:
00091 static const ACE_CString empty_;
00092
00093 typedef Session_T<ACE_SYNCH>::connection_type connection_type;
00094 typedef ACE::IOS::Sock_IOStreamBase<ACE_SYNCH> stream_type;
00095
00096 virtual void on_eof ();
00097
00098 class Authentication
00099 : public ACE::INet::AuthenticationBase
00100 {
00101 public:
00102 Authentication (const ACE_CString& realm,
00103 ACE_CString& user,
00104 ACE_CString& pw);
00105
00106 virtual ~Authentication ();
00107
00108 virtual const ACE_CString& scheme () const;
00109
00110 virtual const ACE_CString& realm () const;
00111
00112 virtual const ACE_CString& user () const;
00113
00114 virtual void user (const ACE_CString& usr);
00115
00116 virtual const ACE_CString& password () const;
00117
00118 virtual void password (const ACE_CString& pw);
00119
00120 private:
00121 const ACE_CString& realm_;
00122 ACE_CString& user_;
00123 ACE_CString& password_;
00124 };
00125
00126 class SessionHolder
00127 : public ACE::INet::ConnectionHolder
00128 {
00129 public:
00130 typedef Session_T<ACE_SYNCH> session_type;
00131
00132 SessionHolder ();
00133 virtual ~SessionHolder();
00134
00135 session_type& operator *();
00136 session_type* operator ->();
00137
00138 private:
00139 session_type session_;
00140 };
00141
00142 class SessionFactory
00143 : public ACE::INet::ConnectionFactory
00144 {
00145 public:
00146 SessionFactory ();
00147 virtual ~SessionFactory ();
00148
00149 virtual ACE::INet::ConnectionHolder* create_connection (
00150 const ACE::INet::ConnectionKey& key) const;
00151 };
00152
00153 SessionHolder& session ();
00154
00155 void session (SessionHolder* session);
00156
00157 virtual bool initialize_connection (const ACE_CString& host,
00158 u_short port);
00159
00160 virtual bool handle_credentials (const URL& url,
00161 ACE_CString& user,
00162 ACE_CString& password);
00163
00164 virtual void handle_request_error (const URL& url);
00165
00166 virtual void handle_connection_error (const URL& url);
00167
00168 void release_connection ();
00169
00170 void close_connection ();
00171
00172
00173
00174
00175
00176 bool login (const ACE_CString& user, const ACE_CString& password);
00177
00178 bool logout ();
00179
00180 bool is_valid_path (const ACE_CString& path);
00181
00182 bool is_file (const ACE_CString& path);
00183
00184 bool is_dir (const ACE_CString& path);
00185
00186 bool set_filetype (bool binary);
00187
00188 stream_type* start_download (const ACE_CString& path, bool binary);
00189
00190 stream_type* start_upload (const ACE_CString& path, bool binary);
00191
00192 bool finish_transfer ();
00193
00194 bool abort_transfer ();
00195
00196 Response::StatusType process_command (const ACE_CString& cmd,
00197 const ACE_CString& arg = empty_);
00198
00199 stream_type* open_data_connection (const ACE_CString& cmd,
00200 const ACE_CString& arg);
00201
00202 bool get_passive_address (ACE_INET_Addr& addr);
00203
00204 bool parse_address (const ACE_CString& str, ACE_INET_Addr& addr);
00205
00206 bool parse_ext_address (const ACE_CString& str, ACE_INET_Addr& addr);
00207
00208 bool send_active_address (const ACE_INET_Addr& addr);
00209
00210 private:
00211 Request request_;
00212 Response response_;
00213 SessionHolder* session_;
00214 bool use_passive_mode_;
00215 u_short active_port_;
00216
00217 OStream out_data_stream_;
00218 IStream in_data_stream_;
00219 bool transfer_active_;
00220
00221 ACE_CString current_user_;
00222 };
00223
00224 }
00225 }
00226
00227 ACE_END_VERSIONED_NAMESPACE_DECL
00228
00229 #if defined (__ACE_INLINE__)
00230 #include "ace/INet/FTP_ClientRequestHandler.inl"
00231 #endif
00232
00233 #include "ace/post.h"
00234 #endif