Use a variable on the stack to not have a temporary in the call
[ACE_TAO.git] / ACE / protocols / ace / INet / URLBase.h
blobe6efb596a92c0d7968b988f7aebbc97ce70e8e83
1 /**
2 * @file URLBase.h
4 * @author Martin Corino <mcorino@remedy.nl>
5 */
7 #ifndef ACE_INET_URL_BASE_H
8 #define ACE_INET_URL_BASE_H
10 #include /**/ "ace/pre.h"
12 #include "ace/SString.h"
13 #include "ace/Map_Manager.h"
14 #include "ace/Singleton.h"
15 #include "ace/Null_Mutex.h"
16 #include "ace/Recursive_Thread_Mutex.h"
17 #include "ace/Refcounted_Auto_Ptr.h"
18 #include "ace/INet/INet_Export.h"
19 #include "ace/INet/AuthenticationBase.h"
20 #include "ace/INet/ClientRequestHandler.h"
21 #include <iosfwd>
23 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
25 namespace ACE
27 namespace INet
29 /**
30 * @class ACE_INet_URLStream
32 * @brief Provides abstracted wrapper class for the resulting
33 * stream of an URL <open> operation.
35 * Provides proper life cycle management for either factory provided
36 * or user provided request handlers.
38 class ACE_INET_Export URLStream
40 public:
41 URLStream (const URLStream& url_stream);
42 ~URLStream ();
44 bool operator ! ();
46 operator bool ();
48 std::istream& operator * ();
50 std::istream* operator -> ();
52 private:
53 friend class URL_Base;
55 URLStream (ClientRequestHandler& rh);
56 URLStream (ClientRequestHandler* rh);
58 typedef ACE_Refcounted_Auto_Ptr<ClientRequestHandler,
59 ACE_Null_Mutex> TRequestHandlerRef;
61 TRequestHandlerRef request_handler_ref_;
62 ClientRequestHandler* request_handler_;
65 /**
66 * @class ACE_INet_URL_Base
68 * @brief Base class for URL/URI addresses conforming to RFC3986.
71 class ACE_INET_Export URL_Base
73 public:
74 URL_Base ();
75 virtual ~URL_Base ();
77 virtual bool parse (const ACE_CString& url_string);
79 void set_path (const ACE_CString& path);
81 virtual void set_query (const ACE_CString& query);
83 virtual void set_fragment (const ACE_CString& fragment);
85 virtual const ACE_CString& get_scheme () const = 0;
87 const ACE_CString& get_protocol () const;
89 virtual ACE_CString get_authority () const;
91 const ACE_CString& get_path () const;
93 virtual const ACE_CString& get_query () const;
95 virtual const ACE_CString& get_fragment () const;
97 virtual URLStream open () const;
99 virtual URLStream open (ClientRequestHandler& rh) const;
101 virtual ACE_CString to_string () const = 0;
103 static URL_Base* create_from_string (const ACE_CString& url_string);
105 #if defined (ACE_HAS_WCHAR)
106 virtual bool parse (const ACE_WString& url_string);
108 virtual ACE_WString to_wstring () const;
110 static URL_Base* create_from_wstring (const ACE_WString& url_string);
111 #endif
113 virtual bool validate ();
115 protected:
116 static const ACE_CString empty_;
118 bool strip_scheme (ACE_CString& url_string);
120 virtual int parse_authority (std::istream& is);
122 virtual bool has_authority ();
124 virtual ClientRequestHandler* create_default_request_handler () const = 0;
126 private:
127 ACE_CString path_;
129 public:
130 class ACE_INET_Export Factory
132 public:
133 Factory ();
134 virtual ~Factory ();
135 virtual const ACE_CString& protocol () = 0;
136 virtual URL_Base* create_from_string (const ACE_CString& url_string) = 0;
139 static void register_factory (Factory* url_factory);
140 static void deregister_factory (Factory* url_factory);
142 private:
143 typedef ACE_Map_Manager<ACE_CString,
144 Factory*,
145 ACE_SYNCH::MUTEX> TURLFactoryMap;
146 typedef ACE_Singleton<TURLFactoryMap,
147 ACE_SYNCH::NULL_MUTEX> TURLFactorySingleton;
148 static TURLFactoryMap* factories_;
152 * @class ACE_INet_URL_INetBase
154 * @brief Base class for internet protocol based URL/URI
155 * addresses supporting host(name) and port specification.
158 class ACE_INET_Export URL_INetBase
159 : public URL_Base
161 public:
162 URL_INetBase(u_short port);
163 virtual ~URL_INetBase ();
165 void set_host (const ACE_CString& host);
167 void set_port (u_short port);
169 const ACE_CString& get_host () const;
171 u_short get_port () const;
173 virtual u_short default_port () const = 0;
175 virtual ACE_CString get_authority () const;
177 virtual bool validate ();
179 protected:
180 virtual int parse_authority (std::istream& is);
182 virtual bool has_authority ();
184 int parse_authority_i (std::istream& is,
185 std::ostream& os,
186 int lastch);
188 private:
189 ACE_CString host_;
190 u_short port_;
195 * @class ACE_INet_URL_INetAuthBase
197 * @brief Base class for internet protocol based URL/URI
198 * addresses supporting authentication information.
200 * This implementation does *not* support the specification
201 * of passwords in user_info field of the URL (deprecated as
202 * of RFC3986).
204 class ACE_INET_Export URL_INetAuthBase
205 : public URL_INetBase
207 public:
208 URL_INetAuthBase(u_short port);
209 virtual ~URL_INetAuthBase ();
211 const ACE_CString& get_user_info () const;
213 void set_user_info (const ACE_CString& userinfo);
215 virtual ACE_CString get_authority () const;
217 protected:
218 virtual int parse_authority (std::istream& is);
220 private:
221 ACE_CString userinfo_;
223 public:
224 static bool add_authenticator (const ACE_CString& auth_id, AuthenticatorBase* authenticator);
226 static bool has_authenticator (const ACE_CString& auth_id);
228 static AuthenticatorBase* remove_authenticator (const ACE_CString& auth_id);
230 static bool authenticate (AuthenticationBase& authentication);
232 private:
233 typedef ACE_Refcounted_Auto_Ptr<AuthenticatorBase,
234 ACE_SYNCH::NULL_MUTEX> authenticator_ptr;
235 typedef ACE_Map_Manager<ACE_CString,
236 authenticator_ptr,
237 ACE_SYNCH::RECURSIVE_MUTEX> authenticator_map;
239 static authenticator_map authenticators_;
244 ACE_END_VERSIONED_NAMESPACE_DECL
246 #if defined (__ACE_INLINE__)
247 #include "ace/INet/URLBase.inl"
248 #endif
250 #include /**/ "ace/post.h"
251 #endif /* ACE_INET_URL_BASE_H */