00001 /* -*- C++ -*- */ 00002 00003 /** @file URL_Addr.h 00004 * 00005 * URL_Addr.h,v 1.10 2004/04/23 03:45:34 ossama Exp 00006 * 00007 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00008 * @author Krishnakumar B <kitty@cs.wustl.edu> 00009 * 00010 */ 00011 00012 #ifndef _ACEXML_URL_ADDR_H 00013 #define _ACEXML_URL_ADDR_H 00014 00015 #include /**/ "ace/pre.h" 00016 #include "ACEXML/common/ACEXML_Export.h" 00017 00018 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00019 #pragma once 00020 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00021 00022 #include "ace/Default_Constants.h" 00023 #include "ace/INET_Addr.h" 00024 #include "ACEXML/common/XML_Types.h" 00025 #include "ACEXML/common/ACEXML_Export.h" 00026 00027 /** 00028 * @class ACEXML_URL_Addr URL_Addr.h "ACEXML/common/URL_Addr.h" 00029 * 00030 * Defines a URL address family address format. 00031 */ 00032 class ACEXML_Export ACEXML_URL_Addr : public ACE_INET_Addr 00033 { 00034 public: 00035 /// Initialization and termination methods. 00036 ACEXML_URL_Addr (void); 00037 00038 /// Constructor. 00039 ACEXML_URL_Addr (const ACEXML_Char *host_name, 00040 const ACEXML_Char *path_name, 00041 unsigned short port = ACE_DEFAULT_HTTP_PORT); 00042 00043 /// Copy constructor. 00044 ACEXML_URL_Addr (const ACEXML_URL_Addr &addr); 00045 00046 /// Essentially the copy constructor. 00047 int set (const ACEXML_URL_Addr &addr); 00048 00049 /** 00050 * Initializes an <ACEXML_URL_Addr> from the <address>, which can be 00051 * "ip-number:port-number/path-name" (e.g., 00052 * "www.cs.wustl.edu:1234/~schmidt/" "ip-number:port-number/path-name" 00053 * (e.g., "128.252.166.57:1234/~schmidt"). If there is no ':' in the 00054 * <address> it is assumed to be an ip-number or ip-address number, with 00055 * the port number <ACE_DEFAULT_HTTP_PORT>. 00056 */ 00057 virtual int string_to_addr (const ACEXML_Char* address); 00058 00059 // Function to shut up Borland C++ 00060 #if defined (ACE_USES_WCHAR) 00061 virtual int string_to_addr (const char* address); 00062 #endif 00063 00064 /** 00065 * Transform the current <ACE_INET_Addr> address into string format. If 00066 * <ipaddr_format> is non-0 this produces 00067 * "ip-number:port-number/path-name" (e.g., 00068 * "128.252.166.57:80/~schmidt/"), whereas if <ipaddr_format> is 0 this 00069 * produces "ip-name:port-number" (e.g., 00070 * "www.cs.wustl.edu:80/~schmidt/"). Returns -1 if the <size> of the 00071 * <buffer> is too small, else 0. 00072 */ 00073 virtual int addr_to_string (ACEXML_Char *s, 00074 size_t size, 00075 int ipaddr_format = 1) const; 00076 00077 /** 00078 * Transform the current <ACE_INET_Addr> address into string format. If 00079 * <ipaddr_format> is non-0 this produces 00080 * "ip-number:port-number/path-name" (e.g., 00081 * "128.252.166.57:80/~schmidt/"), whereas if <ipaddr_format> is 0 this 00082 * produces "ip-name:port-number" (e.g., 00083 * "www.cs.wustl.edu:80/~schmidt/"). Uses dynamic memory, which is 00084 * allocated on demand and deallocated when the object is destroyed. 00085 * Returns -1 if dynamic memory fails, else 0. 00086 */ 00087 virtual const ACEXML_Char *addr_to_string (int ipaddr_format = 1); 00088 00089 /// Assignment operator. 00090 void operator= (const ACEXML_URL_Addr &addr); 00091 00092 /// Destructor. 00093 ~ACEXML_URL_Addr (void); 00094 00095 /** 00096 * Compare two addresses for equality. The addresses are considered 00097 * equal if they contain the same IP address, port number, and path name. 00098 */ 00099 bool operator == (const ACEXML_URL_Addr &SAP) const; 00100 00101 /// Compare two addresses for inequality. 00102 bool operator != (const ACEXML_URL_Addr &SAP) const; 00103 00104 /// Computes and returns hash value. 00105 virtual u_long hash (void) const; 00106 00107 /// Return the path name. 00108 const ACEXML_Char *get_path_name (void) const; 00109 00110 /// Commit suicide. 00111 int destroy (void); 00112 00113 private: 00114 00115 /// Calculate the maximum length of the address string 00116 size_t calculate_length (int ipaddr_format) const; 00117 00118 /// Our path name. 00119 ACEXML_Char *path_name_; 00120 00121 /// The dynamically created address string that's used for the 00122 /// <addr_to_string> method. 00123 ACEXML_Char *addr_string_; 00124 00125 /// Current length of the <addr_string_> 00126 size_t addr_string_len_; 00127 }; 00128 00129 #if defined (__ACEXML_INLINE__) 00130 # include "ACEXML/common/URL_Addr.inl" 00131 #endif /* __ACEXML_INLINE__ */ 00132 00133 #include /**/ "ace/post.h" 00134 00135 #endif /* _ACEXML_URL_ADDR_H */