Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

url.h

Go to the documentation of this file.
00001 /* 00002 * url.h 00003 * 00004 * Universal Resource Locator (for HTTP/HTML) class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-2002 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Log: url.h,v $ 00027 * Revision 1.29 2004/07/07 07:18:43 csoutheren 00028 * Removed warnings on Linux from Windows static global hacks 00029 * 00030 * Revision 1.28 2004/07/06 10:12:51 csoutheren 00031 * Added static integer o factory template to assist in ensuring factories are instantiated 00032 * 00033 * Revision 1.27 2004/06/01 07:32:45 csoutheren 00034 * Removed warning on Linux 00035 * 00036 * Revision 1.26 2004/06/01 07:28:44 csoutheren 00037 * Changed URL parsing to use abstract factory code 00038 * 00039 * Revision 1.25 2004/03/13 06:30:52 rjongbloed 00040 * Virtualised parse function. 00041 * 00042 * Revision 1.24 2003/04/04 05:18:08 robertj 00043 * Added "callto", "tel" and fixed "h323" URL types. 00044 * 00045 * Revision 1.23 2002/12/10 04:40:34 robertj 00046 * Added test function for URL being empty. 00047 * 00048 * Revision 1.22 2002/11/20 00:50:09 robertj 00049 * Fixed correct interpretation of url re double slashes as per latest RFC, 00050 * including file: mapping and relative paths. Probably still more to do. 00051 * 00052 * Revision 1.21 2002/11/19 10:36:08 robertj 00053 * Added functions to set anf get "file:" URL. as PFilePath and do the right 00054 * things with platform dependent directory components. 00055 * 00056 * Revision 1.20 2002/11/06 22:47:24 robertj 00057 * Fixed header comment (copyright etc) 00058 * 00059 * Revision 1.19 2002/09/16 01:08:59 robertj 00060 * Added #define so can select if #pragma interface/implementation is used on 00061 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00062 * 00063 * Revision 1.18 2002/03/18 05:01:54 robertj 00064 * Added functions to set component parts of URL. 00065 * 00066 * Revision 1.17 2001/11/08 00:32:49 robertj 00067 * Added parsing of ';' based parameter fields into string dictionary if there are multiple parameters, with '=' values. 00068 * 00069 * Revision 1.16 2001/09/28 00:32:24 robertj 00070 * Broke out internal static function for unstranslating URL strings. 00071 * 00072 * Revision 1.15 1999/03/09 08:01:47 robertj 00073 * Changed comments for doc++ support (more to come). 00074 * 00075 * Revision 1.14 1999/02/16 08:07:10 robertj 00076 * MSVC 6.0 compatibility changes. 00077 * 00078 * Revision 1.13 1998/09/23 06:20:11 robertj 00079 * Added open source copyright license. 00080 * 00081 * Revision 1.12 1998/02/16 00:12:53 robertj 00082 * Added function to open a URL in a browser. 00083 * 00084 * Revision 1.11 1998/02/03 10:02:35 robertj 00085 * Added ability to get scheme, host and port from URL as a string. 00086 * 00087 * Revision 1.10 1998/02/03 06:18:49 robertj 00088 * Fixed URL encoding to be closer to RFC 00089 * 00090 * Revision 1.9 1997/01/12 04:22:54 robertj 00091 * Added has function so URL can be dictionary key. 00092 * 00093 * Revision 1.8 1996/08/19 13:37:28 robertj 00094 * Fixed URL parsing and definition (cannot have relative paths). 00095 * 00096 * Revision 1.7 1996/06/10 09:55:44 robertj 00097 * Added global function for query parameters parsing. 00098 * 00099 * Revision 1.6 1996/03/31 08:53:13 robertj 00100 * Added string representation for URI part only. 00101 * 00102 * Revision 1.5 1996/03/16 04:46:02 robertj 00103 * Added translation type to TranslateString() to accommodate query variables. 00104 * 00105 * Revision 1.4 1996/03/02 03:12:13 robertj 00106 * Added function to translate a string to a form suitable for inclusion in a URL. 00107 * 00108 * Revision 1.3 1996/02/03 11:06:27 robertj 00109 * Added splitting of query field into variables dictionary. 00110 * 00111 * Revision 1.2 1996/01/26 02:24:32 robertj 00112 * Further implemetation. 00113 * 00114 * Revision 1.1 1996/01/23 13:04:20 robertj 00115 * Initial revision 00116 * 00117 */ 00118 00119 #ifndef _PURL 00120 #define _PURL 00121 00122 #ifdef P_USE_PRAGMA 00123 #pragma interface 00124 #endif 00125 00127 // PURL 00128 00129 class PURLLegacyScheme; 00130 00136 class PURL : public PObject 00137 { 00138 PCLASSINFO(PURL, PObject) 00139 public: 00141 PURL(); 00143 PURL( 00144 const char * cstr, 00145 const char * defaultScheme = NULL 00146 ); 00148 PURL( 00149 const PString & str, 00150 const char * defaultScheme = NULL 00151 ); 00153 PURL( 00154 const PFilePath & path 00155 ); 00156 00165 virtual Comparison Compare( 00166 const PObject & obj 00167 ) const; 00168 00180 virtual PINDEX HashFunction() const; 00181 00184 virtual void PrintOn( 00185 ostream &strm 00186 ) const; 00187 00191 virtual void ReadFrom( 00192 istream &strm 00193 ); 00195 00199 inline BOOL Parse( 00200 const char * cstr, 00201 const char * defaultScheme = NULL 00202 ) { return InternalParse(cstr, defaultScheme); } 00204 inline BOOL Parse( 00205 const PString & str, 00206 const char * defaultScheme = NULL 00207 ) { return InternalParse((const char *)str, defaultScheme); } 00208 00210 enum UrlFormat { 00212 FullURL, 00214 PathOnly, 00216 URIOnly, 00218 HostPortOnly 00219 }; 00220 00227 PString AsString( 00228 UrlFormat fmt = FullURL 00229 ) const; 00230 00234 PFilePath AsFilePath() const; 00235 00237 enum TranslationType { 00239 LoginTranslation, 00241 PathTranslation, 00243 QueryTranslation 00244 }; 00245 00253 static PString TranslateString( 00254 const PString & str, 00255 TranslationType type 00256 ); 00257 00265 static PString UntranslateString( 00266 const PString & str, 00267 TranslationType type 00268 ); 00269 00271 static void SplitQueryVars( 00272 const PString & queryStr, 00273 PStringToString & queryVars 00274 ); 00275 00276 00278 const PCaselessString & GetScheme() const { return scheme; } 00279 00281 void SetScheme(const PString & scheme); 00282 00284 const PString & GetUserName() const { return username; } 00285 00287 void SetUserName(const PString & username); 00288 00290 const PString & GetPassword() const { return password; } 00291 00293 void SetPassword(const PString & password); 00294 00296 const PCaselessString & GetHostName() const { return hostname; } 00297 00299 void SetHostName(const PString & hostname); 00300 00302 WORD GetPort() const { return port; } 00303 00305 void SetPort(WORD newPort); 00306 00308 BOOL GetRelativePath() const { return relativePath; } 00309 00311 const PString & GetPathStr() const { return pathStr; } 00312 00314 void SetPathStr(const PString & pathStr); 00315 00317 const PStringArray & GetPath() const { return path; } 00318 00320 void SetPath(const PStringArray & path); 00321 00323 PString GetParameters() const; 00324 00326 void SetParameters(const PString & parameters); 00327 00329 const PStringToString & GetParamVars() const { return paramVars; } 00330 00332 void SetParamVars(const PStringToString & paramVars); 00333 00335 void SetParamVar(const PString & key, const PString & data); 00336 00338 const PString & GetFragment() const { return fragment; } 00339 00341 PString GetQuery() const; 00342 00344 void SetQuery(const PString & query); 00345 00347 const PStringToString & GetQueryVars() const { return queryVars; } 00348 00350 void SetQueryVars(const PStringToString & queryVars); 00351 00353 void SetQueryVar(const PString & key, const PString & data); 00354 00356 BOOL IsEmpty() const { return urlString.IsEmpty(); } 00357 00358 00365 static BOOL OpenBrowser( 00366 const PString & url 00367 ); 00369 00370 BOOL LegacyParse(const PString & _url, const PURLLegacyScheme * schemeInfo); 00371 PString LegacyAsString(PURL::UrlFormat fmt, const PURLLegacyScheme * schemeInfo) const; 00372 00373 protected: 00374 virtual BOOL InternalParse( 00375 const char * cstr, 00376 const char * defaultScheme 00377 ); 00378 void Recalculate(); 00379 PString urlString; 00380 00381 PCaselessString scheme; 00382 PString username; 00383 PString password; 00384 PCaselessString hostname; 00385 WORD port; 00386 BOOL relativePath; 00387 PString pathStr; 00388 PStringArray path; 00389 PStringToString paramVars; 00390 PString fragment; 00391 PStringToString queryVars; 00392 }; 00393 00394 00395 class PURLScheme : public PObject 00396 { 00397 PCLASSINFO(PURLScheme, PObject); 00398 public: 00399 virtual PString GetName() const = 0; 00400 virtual BOOL Parse(const PString & url, PURL & purl) const = 0; 00401 virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0; 00402 }; 00403 00404 #ifdef _WIN32 00405 # ifndef P_DISABLE_FACTORY_INSTANCES 00406 # ifndef P_FACTORY_INSTANCE_PURLScheme 00407 # define P_FACTORY_INSTANCE_PURLScheme 1 00408 # pragma message("Including PURLScheme factory loader") 00409 PLOAD_FACTORY(PURLScheme, PString) 00410 # endif 00411 # endif 00412 #endif 00413 00414 #endif 00415 00416 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:57 2004 for PWLib by doxygen 1.3.7