ACE+TAO-7_0_10
[ACE_TAO.git] / ACE / websvcs / lib / URL_Addr.h
blob2cf9fe638ffb7e9c4f6d33b3cd8a0d8652c5372f
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file URL_Addr.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
12 #ifndef ACE_URL_ADDR_H
13 #define ACE_URL_ADDR_H
15 #include "ace/INET_Addr.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #include "websvcs_export.h"
22 #include "ace/ACE.h"
24 class ACE_URL_Addr_Visitor;
26 /**
27 * @class ACE_URL_Addr
29 * @brief Defines the interface for an URL
31 * All URLs derive from this class
33 class ACE_WEBSVCS_Export ACE_URL_Addr : public ACE_Addr
35 public:
36 /// Constructor.
37 ACE_URL_Addr ();
39 /// The copy constructor.
40 ACE_URL_Addr (const ACE_URL_Addr& address);
42 /// The assignment operator
43 ACE_URL_Addr& operator= (const ACE_URL_Addr& address);
45 /// destructor
46 virtual ~ACE_URL_Addr ();
48 /// Get the original URL
49 const ACE_TCHAR *get_url () const;
51 /// Essentially the copy constructor.
52 int set (const ACE_URL_Addr& address);
54 /**
55 * Initializes from the scheme specific address, for instance: if
56 * the address is an http URL it will initialize the address from
57 * an string such as "www.dre.vanderbilt.edu/~schmidt/"
59 virtual int string_to_addr (const ACE_TCHAR *address);
61 /**
62 * Write the address in the scheme specific representation.
63 * <flags> provides control over scheme specific features (such as
64 * using numeric vs. fully qualified host names).
66 virtual int addr_to_string (ACE_TCHAR *s,
67 size_t size,
68 int flags = 0) const;
70 /// The accept method in the Visitor Pattern. Should return 0 on
71 /// success and not 0 on failure.
72 virtual int accept (ACE_URL_Addr_Visitor* visitor);
74 /// Create an address from a complete URL, such as "http://www/foo"
75 /// or "ftp://ftp.here/get_this".
76 static ACE_URL_Addr* create_address (const ACE_TCHAR *url);
78 /// Returns 1 if the URL scheme is recognized, 0 otherwise.
79 static int known_scheme (const ACE_TCHAR *url);
81 /// Hash function
82 u_long hash () const;
84 protected:
85 /// Allows the derived classes to store the compact representation of
86 /// the URL
87 void set_url (ACE_TCHAR *url);
89 private:
90 ACE_TCHAR *url_;
93 /**
94 * @class ACE_Mailto_Addr;
95 @@ TODO add more URL schemes as needed.
96 * class ACE_File_Addr;
97 * class ACE_AFS_Addr;
98 * class ACE_News_Addr;
99 * class ACE_NNTP_Addr;
100 * class ACE_CID_Addr;
101 * class ACE_MID_Addr;
102 * class ACE_WAIS_Addr;
103 * class ACE_Prospero_Addr;
104 * class ACE_Telnet_Addr;
105 * class ACE_Rlogin_Addr;
106 * class ACE_TN3270_Addr;
107 * class ACE_Gopher_Addr;
109 class ACE_HTTP_Addr;
110 class ACE_FTP_Addr;
111 class ACE_Mailto_Addr;
114 * @class ACE_URL_Addr_Visitor
116 * @brief Implements a Visitor object for the ACE_URL hierarchy.
118 * The manipulation of URL objects is much simpler if we use the
119 * Visitor pattern to solve the double dispatch problem between
120 * the "what to do on a URL" vs. "what to do on each kind of
121 * URL".
123 class ACE_WEBSVCS_Export ACE_URL_Addr_Visitor
125 public:
126 /// Destructor
127 virtual ~ACE_URL_Addr_Visitor ();
130 * The visit methods for all the hierarchy.
131 * The default implementation is a nop (instead of a pure virtual
132 * function) to facilitate the addition of new members in the
133 * hierarchy.
134 * virtual int visit (ACE_AFS_Addr*);
135 * virtual int visit (ACE_News_Addr*);
136 * virtual int visit (ACE_NNTP_Addr*);
138 virtual int visit (ACE_URL_Addr*);
139 virtual int visit (ACE_HTTP_Addr*);
140 virtual int visit (ACE_FTP_Addr*);
141 virtual int visit (ACE_Mailto_Addr*);
144 // ****************************************************************
147 * @class ACE_HTTP_Addr
149 * @brief Defines the HTTP scheme addresses
151 * Encapsulates an HTTP URL; the most general form is:
152 * http://host:port/path?query
153 * but these are also accepted:
154 * http://host/path?query
155 * http://host:port/path
156 * http://host/path
158 class ACE_WEBSVCS_Export ACE_HTTP_Addr : public ACE_URL_Addr
160 public:
161 /// Constructor
162 ACE_HTTP_Addr ();
164 /// Construct an HTTP URL from the host, path, query and port.
165 ACE_HTTP_Addr (const ACE_TCHAR *host_name,
166 const ACE_TCHAR *path,
167 const ACE_TCHAR *query = 0,
168 u_short port = ACE_DEFAULT_HTTP_PORT);
170 /// Essentially the constructor above.
171 int set (const ACE_TCHAR *host_name,
172 const ACE_TCHAR *path,
173 const ACE_TCHAR *query = 0,
174 u_short port = ACE_DEFAULT_HTTP_PORT);
176 /// Copy constructor.
177 ACE_HTTP_Addr (const ACE_HTTP_Addr &addr);
179 /// Assignment operator.
180 ACE_HTTP_Addr& operator= (const ACE_HTTP_Addr &addr);
182 /// Essentially the copy constructor.
183 int set (const ACE_HTTP_Addr &addr);
185 /// Destructor
186 virtual ~ACE_HTTP_Addr ();
189 * Build the INET_Address implicit in the URL, notice that we
190 * maintain the hostname in its string representation, because the
191 * URL can be can be refering to an hostname that cannot be
192 * validated at this point.
194 ACE_INET_Addr get_inet_address () const;
196 /// Get the name of the host.
197 const ACE_TCHAR *get_hostname () const;
199 /// Get the port number.
200 u_short get_port_number () const;
202 /// Get the path component in the URL
203 const ACE_TCHAR *get_path () const;
205 /// Get the query component in the URL
206 const ACE_TCHAR *get_query () const;
209 * Create an address from a (possibly) relative URL, such as
210 * "../foo.html", or "/icons/bar.gif"
211 * If the URL is absolute (like "http://www/foo" or "ftp:host/bar")
212 * it simply returns the correct ACE_URL_Addr object; but if the URL
213 * is not absolute then it is interpreted as relative from the
214 * current address. In that case url is just a path, if it is a
215 * relative path the new address simply concatenates the path and
216 * uses the same host:port; if it is an absolute path only the host
217 * and port are used.
219 ACE_URL_Addr* create_relative_address (const ACE_TCHAR *url) const;
221 // = The ACE_URL methods, see the documentation above.
222 virtual int string_to_addr (const ACE_TCHAR *address);
223 virtual int addr_to_string (ACE_TCHAR *s,
224 size_t size,
225 int flags = 0) const;
226 virtual int accept (ACE_URL_Addr_Visitor* visitor);
228 private:
229 /// Compute the size required to store the URL in a string
230 /// representation.
231 size_t url_size (int flags = 0) const;
233 /// Helper method to cleanup resources
234 void clear ();
236 private:
237 /// The host:port component in the URL
238 ACE_TCHAR *hostname_;
239 u_short port_number_;
241 /// The path component in the URL
242 ACE_TCHAR *path_;
244 /// The query component in the URL
245 ACE_TCHAR *query_;
248 // ****************************************************************
251 * @class ACE_FTP_Addr
253 * @brief Defines the FTP scheme addresses
255 * Encapsulates an FTP URL; usually an FTP URL is of the form:
256 * ftp://hostname/path
257 * but the most general form is:
258 * ftp://user:password@hostname/path
259 * the [:password] part can be omitted too.
261 class ACE_WEBSVCS_Export ACE_FTP_Addr : public ACE_URL_Addr
263 public:
264 /// Constructor
265 ACE_FTP_Addr ();
267 /// Construct an FTP URL from the host_name, the path, the username
268 /// and the password.
269 ACE_FTP_Addr (const ACE_TCHAR *host_name,
270 const ACE_TCHAR *path,
271 const ACE_TCHAR *user = 0,
272 const ACE_TCHAR *password = 0);
274 /// Essentially the constructor above.
275 int set (const ACE_TCHAR *host_name,
276 const ACE_TCHAR *path,
277 const ACE_TCHAR *user = 0,
278 const ACE_TCHAR *password = 0);
280 /// Copy constructor.
281 ACE_FTP_Addr (const ACE_FTP_Addr &addr);
283 /// Assignment operator
284 ACE_FTP_Addr& operator= (const ACE_FTP_Addr &addr);
286 /// Essentially the copy constructor.
287 int set (const ACE_FTP_Addr &addr);
289 /// Destructor
290 virtual ~ACE_FTP_Addr ();
292 /// Get the host name component in the URL
293 const ACE_TCHAR *get_hostname () const;
295 /// Get the username component in the URL
296 const ACE_TCHAR *get_user () const;
298 /// Get the password component in the URL
299 const ACE_TCHAR *get_passwd () const;
301 /// Get the path component in the URL
302 const ACE_TCHAR *get_path () const;
304 /// Obtain the INET_Address implicit in the URL, can be used to
305 /// obtain the host and the port.
306 ACE_INET_Addr get_inet_address () const;
308 // = The ACE_Addr methods, see the documentation above.
309 virtual int string_to_addr (const ACE_TCHAR *address);
310 virtual int addr_to_string (ACE_TCHAR *s,
311 size_t size,
312 int flags = 0) const;
313 virtual int accept (ACE_URL_Addr_Visitor* visitor);
315 private:
316 /// Compute the size required to store the URL in a string
317 /// representation.
318 size_t url_size (int flags = 0) const;
320 /// Helper method to release the internal resources
321 void clear ();
323 private:
324 /// The login name
325 ACE_TCHAR *user_;
326 ACE_TCHAR *password_;
328 /// The hostname part.
329 ACE_TCHAR *hostname_;
331 /// The other components.
332 ACE_TCHAR *path_;
335 // ****************************************************************
338 * @class ACE_Mailto_Addr
340 * @brief Defines the mailto scheme addresses
342 * Encapsulates an URL that refers to an email address.
344 class ACE_WEBSVCS_Export ACE_Mailto_Addr : public ACE_URL_Addr
346 public:
347 /// Constructor
348 ACE_Mailto_Addr ();
350 /// Construct an FTP URL from the host, path and headers.
351 ACE_Mailto_Addr (const ACE_TCHAR *user,
352 const ACE_TCHAR *hostname,
353 const ACE_TCHAR *headers = 0);
355 /// Essentially the constructor above.
356 int set (const ACE_TCHAR *user,
357 const ACE_TCHAR *hostname,
358 const ACE_TCHAR *headers = 0);
360 /// Copy constructor.
361 ACE_Mailto_Addr (const ACE_Mailto_Addr &addr);
363 /// Assignment operator
364 ACE_Mailto_Addr& operator= (const ACE_Mailto_Addr &addr);
366 /// Essentially the copy constructor.
367 int set (const ACE_Mailto_Addr &addr);
369 /// Destructor
370 virtual ~ACE_Mailto_Addr ();
372 /// Get the username component in the URL
373 const ACE_TCHAR *get_user () const;
375 /// Get the hostname component in the URL
376 const ACE_TCHAR *get_hostname () const;
378 /// Get the headers as a single string
379 const ACE_TCHAR *get_headers () const;
381 // @@ TODO A mailto: URL can contain multiple headers, an iterator
382 // over them would be a good idea. Similarly a method to *add*
383 // headers would be nice also.
385 // = The ACE_URL methods, see the documentation above.
386 virtual int string_to_addr (const ACE_TCHAR *address);
387 virtual int addr_to_string (ACE_TCHAR *s,
388 size_t size,
389 int flags = 0) const;
390 virtual int accept (ACE_URL_Addr_Visitor* visitor);
392 private:
393 /// Compute the size required to store the URL in a string
394 /// representation.
395 size_t url_size (int flags = 0) const;
397 /// Helper method to cleanup resources
398 void clear ();
400 private:
401 ACE_TCHAR *user_;
402 ACE_TCHAR *hostname_;
403 ACE_TCHAR *headers_;
406 #if defined (__ACE_INLINE__)
407 #include "URL_Addr.inl"
408 #endif /* __ACE_INLINE__ */
410 #endif /* ACE_URL_ADDR_H */