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  * $Revision: 21788 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00029  */
00030 
00031 #ifndef PTLIB_PURL_H
00032 #define PTLIB_PURL_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 
00039 #if P_URL
00040 
00041 
00043 // PURL
00044 
00045 class PURLLegacyScheme;
00046 
00052 class PURL : public PObject
00053 {
00054   PCLASSINFO(PURL, PObject)
00055   public:
00057     PURL();
00059     PURL(
00060       const char * cstr,    
00061       const char * defaultScheme = NULL 
00062     );
00064     PURL(
00065       const PString & str,  
00066       const char * defaultScheme = NULL 
00067     );
00069     PURL(
00070       const PFilePath & path   
00071     );
00072 
00073     PURL(const PURL & other);
00074     PURL & operator=(const PURL & other);
00075 
00084     virtual Comparison Compare(
00085       const PObject & obj   
00086     ) const;
00087 
00099     virtual PINDEX HashFunction() const;
00100 
00103     virtual void PrintOn(
00104       ostream &strm   
00105     ) const;
00106 
00110     virtual void ReadFrom(
00111       istream &strm   
00112     );
00114  
00118     inline PBoolean Parse(
00119       const char * cstr,   
00120       const char * defaultScheme = NULL 
00121     ) { return InternalParse(cstr, defaultScheme); }
00123     inline PBoolean Parse(
00124       const PString & str, 
00125       const char * defaultScheme = NULL 
00126     ) { return InternalParse((const char *)str, defaultScheme); }
00127 
00129     enum UrlFormat {
00131       FullURL,      
00133       PathOnly,     
00135       URIOnly,      
00137       HostPortOnly  
00138     };
00139 
00146     PString AsString(
00147       UrlFormat fmt = FullURL   
00148     ) const;
00149 
00153     PFilePath AsFilePath() const;
00154 
00156     enum TranslationType {
00158       LoginTranslation,
00160       PathTranslation,
00162       QueryTranslation
00163     };
00164 
00172     static PString TranslateString(
00173       const PString & str,    
00174       TranslationType type    
00175     );
00176 
00184     static PString UntranslateString(
00185       const PString & str,    
00186       TranslationType type    
00187     );
00188 
00190     static void SplitVars(
00191       const PString & str,    
00192       PStringToString & vars, 
00193       char sep1,              
00194       char sep2               
00195     );
00196 
00198     static void SplitQueryVars(
00199       const PString & queryStr,   
00200       PStringToString & queryVars 
00201     ) { SplitVars(queryStr, queryVars, '&', '='); }
00202 
00203 
00204 
00206     const PCaselessString & GetScheme() const { return scheme; }
00207 
00209     void SetScheme(const PString & scheme);
00210 
00212     const PString & GetUserName() const { return username; }
00213 
00215     void SetUserName(const PString & username);
00216 
00218     const PString & GetPassword() const { return password; }
00219 
00221     void SetPassword(const PString & password);
00222 
00224     const PCaselessString & GetHostName() const { return hostname; }
00225 
00227     void SetHostName(const PString & hostname);
00228 
00230     WORD GetPort() const { return port; }
00231 
00233     void SetPort(WORD newPort);
00234     
00236     PBoolean GetPortSupplied() const { return portSupplied; }
00237 
00239     PBoolean GetRelativePath() const { return relativePath; }
00240 
00242     const PString & GetPathStr() const { return pathStr; }
00243 
00245     void SetPathStr(const PString & pathStr);
00246 
00248     const PStringArray & GetPath() const { return path; }
00249 
00251     void SetPath(const PStringArray & path);
00252 
00254     PString GetParameters() const;
00255 
00257     void SetParameters(const PString & parameters);
00258 
00260     const PStringToString & GetParamVars() const { return paramVars; }
00261 
00263     void SetParamVars(const PStringToString & paramVars);
00264 
00266     void SetParamVar(const PString & key, const PString & data);
00267 
00269     const PString & GetFragment() const { return fragment; }
00270 
00272     PString GetQuery() const;
00273 
00275     void SetQuery(const PString & query);
00276 
00278     const PStringToString & GetQueryVars() const { return queryVars; }
00279 
00281     void SetQueryVars(const PStringToString & queryVars);
00282 
00284     void SetQueryVar(const PString & key, const PString & data);
00285 
00287     PBoolean IsEmpty() const { return urlString.IsEmpty(); }
00288 
00289 
00296     static PBoolean OpenBrowser(
00297       const PString & url   
00298     );
00300 
00301     PBoolean LegacyParse(const PString & url, const PURLLegacyScheme * schemeInfo);
00302     PString LegacyAsString(PURL::UrlFormat fmt, const PURLLegacyScheme * schemeInfo) const;
00303 
00304   protected:
00305     void CopyContents(const PURL & other);
00306     virtual PBoolean InternalParse(
00307       const char * cstr,         
00308       const char * defaultScheme 
00309     );
00310     void Recalculate();
00311     PString urlString;
00312 
00313     PCaselessString scheme;
00314     PString username;
00315     PString password;
00316     PCaselessString hostname;
00317     WORD port;
00318     PBoolean portSupplied;          
00319     PBoolean relativePath;
00320     PString pathStr;
00321     PStringArray path;
00322     PStringToString paramVars;
00323     PString fragment;
00324     PStringToString queryVars;
00325 };
00326 
00327 
00329 // PURLScheme
00330 
00331 class PURLScheme : public PObject
00332 {
00333   PCLASSINFO(PURLScheme, PObject);
00334   public:
00335     virtual PString GetName() const = 0;
00336     virtual PBoolean Parse(const PString & url, PURL & purl) const = 0;
00337     virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0;
00338 };
00339 
00341 // PURLLegacyScheme
00342 
00343 class PURLLegacyScheme : public PURLScheme
00344 {
00345   public:
00346     PURLLegacyScheme(const char * s)
00347       : scheme(s) { }
00348 
00349     PBoolean Parse(const PString & url, PURL & purl) const
00350     { return purl.LegacyParse(url, this); }
00351 
00352     PString AsString(PURL::UrlFormat fmt, const PURL & purl) const
00353     { return purl.LegacyAsString(fmt, this); }
00354 
00355     PString GetName() const     
00356     { return scheme; }
00357 
00358     PString scheme;
00359     PBoolean hasUsername;
00360     PBoolean hasPassword;
00361     PBoolean hasHostPort;
00362     PBoolean defaultToUserIfNoAt;
00363     PBoolean defaultHostToLocal;
00364     PBoolean hasQuery;
00365     PBoolean hasParameters;
00366     PBoolean hasFragments;
00367     PBoolean hasPath;
00368     PBoolean relativeImpliesScheme;
00369     WORD defaultPort;
00370 };
00371 
00372 #endif // P_URL
00373 
00374 #endif // PTLIB_PURL_H
00375 
00376 
00377 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:48 2010 for PTLib by  doxygen 1.4.7