00001 // Filename: urlSpec.I 00002 // Created by: drose (24Sep02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: URLSpec::Constructor 00022 // Access: Published 00023 // Description: 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE URLSpec:: 00026 URLSpec(const string &url, bool server_name_expected) { 00027 set_url(url, server_name_expected); 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: URLSpec::Copy Constructor 00032 // Access: Published 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE URLSpec:: 00036 URLSpec(const URLSpec ©) { 00037 (*this) = copy; 00038 } 00039 00040 //////////////////////////////////////////////////////////////////// 00041 // Function: URLSpec::Assignment Operator 00042 // Access: Published 00043 // Description: 00044 //////////////////////////////////////////////////////////////////// 00045 INLINE void URLSpec:: 00046 operator = (const string &url) { 00047 set_url(url); 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: URLSpec::Operator == 00052 // Access: Published 00053 // Description: 00054 //////////////////////////////////////////////////////////////////// 00055 INLINE bool URLSpec:: 00056 operator == (const URLSpec &other) const { 00057 return _url == other._url; 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: URLSpec::Operator != 00062 // Access: Published 00063 // Description: 00064 //////////////////////////////////////////////////////////////////// 00065 INLINE bool URLSpec:: 00066 operator != (const URLSpec &other) const { 00067 return !operator == (other); 00068 } 00069 00070 //////////////////////////////////////////////////////////////////// 00071 // Function: URLSpec::Operator < 00072 // Access: Published 00073 // Description: 00074 //////////////////////////////////////////////////////////////////// 00075 INLINE bool URLSpec:: 00076 operator < (const URLSpec &other) const { 00077 return _url < other._url; 00078 } 00079 00080 //////////////////////////////////////////////////////////////////// 00081 // Function: URLSpec::compare_to 00082 // Access: Published 00083 // Description: Returns a number less than zero if this URLSpec 00084 // sorts before the other one, greater than zero if it 00085 // sorts after, or zero if they are equivalent. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE int URLSpec:: 00088 compare_to(const URLSpec &other) const { 00089 return strcmp(_url.c_str(), other._url.c_str()); 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: URLSpec::has_scheme 00094 // Access: Published 00095 // Description: Returns true if the URL specifies a scheme 00096 // (e.g. "http:"), false otherwise. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE bool URLSpec:: 00099 has_scheme() const { 00100 return (_flags & F_has_scheme) != 0; 00101 } 00102 00103 //////////////////////////////////////////////////////////////////// 00104 // Function: URLSpec::has_authority 00105 // Access: Published 00106 // Description: Returns true if the URL specifies an authority 00107 // (this includes username, server, and/or port), false 00108 // otherwise. 00109 //////////////////////////////////////////////////////////////////// 00110 INLINE bool URLSpec:: 00111 has_authority() const { 00112 return (_flags & F_has_authority) != 0; 00113 } 00114 00115 //////////////////////////////////////////////////////////////////// 00116 // Function: URLSpec::has_username 00117 // Access: Published 00118 // Description: Returns true if the URL specifies a username 00119 // (and/or password), false otherwise. 00120 //////////////////////////////////////////////////////////////////// 00121 INLINE bool URLSpec:: 00122 has_username() const { 00123 return (_flags & F_has_username) != 0; 00124 } 00125 00126 //////////////////////////////////////////////////////////////////// 00127 // Function: URLSpec::has_server 00128 // Access: Published 00129 // Description: Returns true if the URL specifies a server name, 00130 // false otherwise. 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE bool URLSpec:: 00133 has_server() const { 00134 return (_flags & F_has_server) != 0; 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: URLSpec::has_port 00139 // Access: Published 00140 // Description: Returns true if the URL specifies a port number, 00141 // false otherwise. 00142 //////////////////////////////////////////////////////////////////// 00143 INLINE bool URLSpec:: 00144 has_port() const { 00145 return (_flags & F_has_port) != 0; 00146 } 00147 00148 //////////////////////////////////////////////////////////////////// 00149 // Function: URLSpec::has_path 00150 // Access: Published 00151 // Description: Returns true if the URL includes a path specification 00152 // (that is, the particular filename on the server to 00153 // retrieve), false otherwise. 00154 //////////////////////////////////////////////////////////////////// 00155 INLINE bool URLSpec:: 00156 has_path() const { 00157 return (_flags & F_has_path) != 0; 00158 } 00159 00160 //////////////////////////////////////////////////////////////////// 00161 // Function: URLSpec::has_query 00162 // Access: Published 00163 // Description: Returns true if the URL includes a query 00164 // specification, false otherwise. 00165 //////////////////////////////////////////////////////////////////// 00166 INLINE bool URLSpec:: 00167 has_query() const { 00168 return (_flags & F_has_query) != 0; 00169 } 00170 00171 //////////////////////////////////////////////////////////////////// 00172 // Function: URLSpec::get_authority 00173 // Access: Published 00174 // Description: Returns the authority specified by the URL (this 00175 // includes username, server, and/or port), or empty 00176 // string if no authority is specified. 00177 //////////////////////////////////////////////////////////////////// 00178 INLINE string URLSpec:: 00179 get_authority() const { 00180 return _url.substr(_username_start, _port_end - _username_start); 00181 } 00182 00183 //////////////////////////////////////////////////////////////////// 00184 // Function: URLSpec::get_username 00185 // Access: Published 00186 // Description: Returns the username specified by the URL, if any. 00187 // This might also include a password, 00188 // e.g. "username:password", although putting a password 00189 // on the URL is probably a bad idea. 00190 //////////////////////////////////////////////////////////////////// 00191 INLINE string URLSpec:: 00192 get_username() const { 00193 return _url.substr(_username_start, _username_end - _username_start); 00194 } 00195 00196 //////////////////////////////////////////////////////////////////// 00197 // Function: URLSpec::get_server 00198 // Access: Published 00199 // Description: Returns the server name specified by the URL, if any. 00200 //////////////////////////////////////////////////////////////////// 00201 INLINE string URLSpec:: 00202 get_server() const { 00203 return _url.substr(_server_start, _server_end - _server_start); 00204 } 00205 00206 //////////////////////////////////////////////////////////////////// 00207 // Function: URLSpec::get_port_str 00208 // Access: Published 00209 // Description: Returns the port specified by the URL as a string, or 00210 // the empty string if no port is specified. Compare 00211 // this with get_port(), which returns a default port 00212 // number if no port is specified. 00213 //////////////////////////////////////////////////////////////////// 00214 INLINE string URLSpec:: 00215 get_port_str() const { 00216 return _url.substr(_port_start, _port_end - _port_start); 00217 } 00218 00219 //////////////////////////////////////////////////////////////////// 00220 // Function: URLSpec::get_query 00221 // Access: Published 00222 // Description: Returns the query specified by the URL, or empty 00223 // string if no query is specified. 00224 //////////////////////////////////////////////////////////////////// 00225 INLINE string URLSpec:: 00226 get_query() const { 00227 return _url.substr(_query_start); 00228 } 00229 00230 //////////////////////////////////////////////////////////////////// 00231 // Function: URLSpec::get_url 00232 // Access: Published 00233 // Description: Returns the complete URL specification. 00234 //////////////////////////////////////////////////////////////////// 00235 INLINE const string &URLSpec:: 00236 get_url() const { 00237 return _url; 00238 } 00239 00240 //////////////////////////////////////////////////////////////////// 00241 // Function: URLSpec::string typecast operator 00242 // Access: Public 00243 // Description: 00244 //////////////////////////////////////////////////////////////////// 00245 INLINE URLSpec:: 00246 operator const string & () const { 00247 return _url; 00248 } 00249 00250 //////////////////////////////////////////////////////////////////// 00251 // Function: URLSpec::c_str 00252 // Access: Public 00253 // Description: 00254 //////////////////////////////////////////////////////////////////// 00255 INLINE const char *URLSpec:: 00256 c_str() const { 00257 return _url.c_str(); 00258 } 00259 00260 //////////////////////////////////////////////////////////////////// 00261 // Function: URLSpec::empty 00262 // Access: Public 00263 // Description: 00264 //////////////////////////////////////////////////////////////////// 00265 INLINE bool URLSpec:: 00266 empty() const { 00267 return _url.empty(); 00268 } 00269 00270 //////////////////////////////////////////////////////////////////// 00271 // Function: URLSpec::length 00272 // Access: Public 00273 // Description: 00274 //////////////////////////////////////////////////////////////////// 00275 INLINE size_t URLSpec:: 00276 length() const { 00277 return _url.length(); 00278 } 00279 00280 //////////////////////////////////////////////////////////////////// 00281 // Function: URLSpec::Indexing operator 00282 // Access: Public 00283 // Description: 00284 //////////////////////////////////////////////////////////////////// 00285 INLINE char URLSpec:: 00286 operator [] (int n) const { 00287 nassertr(n >= 0 && n < (int)_url.length(), '\0'); 00288 return _url[n]; 00289 } 00290 00291 INLINE istream & 00292 operator >> (istream &in, URLSpec &url) { 00293 if (!url.input(in)) { 00294 in.clear(ios::failbit | in.rdstate()); 00295 } 00296 return in; 00297 } 00298 00299 INLINE ostream & 00300 operator << (ostream &out, const URLSpec &url) { 00301 url.output(out); 00302 return out; 00303 } 00304 00305