Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / protocols / ace / INet / FTP_ClientRequestHandler.h
blob64019d9c178d8de0aca881220163ef46f29188b7
1 /**
2 * @file FTP_ClientRequestHandler.h
4 * @author Martin Corino <mcorino@remedy.nl>
5 */
7 #ifndef ACE_FTP_CLIENT_REQUEST_HANDLER_H
8 #define ACE_FTP_CLIENT_REQUEST_HANDLER_H
10 #include /**/ "ace/pre.h"
12 #include /**/ "ace/config-all.h"
14 #if !defined (ACE_LACKS_PRAGMA_ONCE)
15 # pragma once
16 #endif /* ACE_LACKS_PRAGMA_ONCE */
18 #include "ace/Synch_Traits.h"
19 #include "ace/Thread_Mutex.h"
20 #include "ace/INet/INet_Export.h"
21 #include "ace/INet/IOS_util.h"
22 #include "ace/INet/StreamInterceptor.h"
23 #include "ace/INet/ClientRequestHandler.h"
24 #include "ace/INet/FTP_Request.h"
25 #include "ace/INet/FTP_Response.h"
26 #include "ace/INet/FTP_Session.h"
27 #include "ace/INet/FTP_URL.h"
28 #include "ace/INet/FTP_IOStream.h"
29 #include "ace/INet/Sock_IOStream.h"
31 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
33 namespace ACE
35 namespace FTP
37 /**
38 * @class ACE_FTP_ClientRequestHandler
40 * @brief This class implements clientside request handling
41 * for FTP URLs.
43 * The class supports the FTP protocol as specified in RFCs 959
44 * and 2428.
46 class ACE_INET_Export ClientRequestHandler
47 : public ACE::INet::ClientINetRequestHandler,
48 public ACE::IOS::StreamInterceptor
50 public:
51 ClientRequestHandler (bool passive_mode = true);
52 virtual ~ClientRequestHandler ();
54 bool uses_passive_mode () const;
56 void use_passive_mode ();
58 void use_active_mode (u_short port = 0);
60 u_short uses_active_port () const;
62 virtual Request& request ();
64 virtual const Request& request () const;
66 virtual Response& response ();
68 virtual const Response& response () const;
70 std::ostream& request_stream ();
72 virtual std::istream& response_stream ();
74 virtual bool is_response_ok () const;
76 virtual std::istream& handle_open_request (const ACE::INet::URL_Base& url);
78 virtual std::istream& handle_get_request (const URL& url, bool binary=true);
80 virtual std::ostream& start_put_request (const URL& url, bool binary=true);
82 virtual bool finish_put_request ();
84 void quit_connection ();
86 static const ACE_CString anonymous_user_;
88 protected:
89 static const ACE_CString empty_;
91 typedef Session_T<ACE_SYNCH>::connection_type connection_type;
92 typedef ACE::IOS::Sock_IOStreamBase<ACE_SYNCH> stream_type;
94 virtual void on_eof ();
96 class Authentication
97 : public ACE::INet::AuthenticationBase
99 public:
100 Authentication (const ACE_CString& realm,
101 ACE_CString& user,
102 ACE_CString& pw);
104 virtual ~Authentication ();
106 virtual const ACE_CString& scheme () const;
108 virtual const ACE_CString& realm () const;
110 virtual const ACE_CString& user () const;
112 virtual void user (const ACE_CString& usr);
114 virtual const ACE_CString& password () const;
116 virtual void password (const ACE_CString& pw);
118 private:
119 const ACE_CString& realm_;
120 ACE_CString& user_;
121 ACE_CString& password_;
124 class SessionHolder
125 : public ACE::INet::ConnectionHolder
127 public:
128 typedef Session_T<ACE_SYNCH> session_type;
130 SessionHolder ();
131 virtual ~SessionHolder();
133 session_type& operator *();
134 session_type* operator ->();
136 private:
137 session_type session_;
140 class SessionFactory
141 : public ACE::INet::ConnectionFactory
143 public:
144 SessionFactory ();
145 virtual ~SessionFactory ();
147 virtual ACE::INet::ConnectionHolder* create_connection (
148 const ACE::INet::ConnectionKey& key) const;
151 SessionHolder& session ();
153 void session (SessionHolder* session);
155 virtual bool initialize_connection (const ACE_CString& host,
156 u_short port);
158 virtual bool handle_credentials (const URL& url,
159 ACE_CString& user,
160 ACE_CString& password);
162 virtual void handle_request_error (const URL& url);
164 virtual void handle_connection_error (const URL& url);
166 void release_connection ();
168 void close_connection ();
171 * FTP protocol helpers
174 bool login (const ACE_CString& user, const ACE_CString& password);
176 bool logout ();
178 bool is_valid_path (const ACE_CString& path);
180 bool is_file (const ACE_CString& path);
182 bool is_dir (const ACE_CString& path);
184 bool set_filetype (bool binary);
186 stream_type* start_download (const ACE_CString& path, bool binary);
188 stream_type* start_upload (const ACE_CString& path, bool binary);
190 bool finish_transfer ();
192 bool abort_transfer ();
194 Response::StatusType process_command (const ACE_CString& cmd,
195 const ACE_CString& arg = empty_);
197 stream_type* open_data_connection (const ACE_CString& cmd,
198 const ACE_CString& arg);
200 bool get_passive_address (ACE_INET_Addr& addr);
202 bool parse_address (const ACE_CString& str, ACE_INET_Addr& addr);
204 bool parse_ext_address (const ACE_CString& str, ACE_INET_Addr& addr);
206 bool send_active_address (const ACE_INET_Addr& addr);
208 private:
209 Request request_;
210 Response response_;
211 SessionHolder* session_;
212 bool use_passive_mode_;
213 u_short active_port_;
215 OStream out_data_stream_;
216 IStream in_data_stream_;
217 bool transfer_active_;
219 ACE_CString current_user_;
224 ACE_END_VERSIONED_NAMESPACE_DECL
226 #if defined (__ACE_INLINE__)
227 #include "ace/INet/FTP_ClientRequestHandler.inl"
228 #endif
230 #include /**/ "ace/post.h"
231 #endif /* ACE_INET_CLIENT_REQUEST_HANDLER_H */