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: 20385 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00029  */
00030 
00031 #ifndef _PURL_H
00032 #define _PURL_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #ifndef _PTLIB_H
00039 #include <ptlib.h>
00040 #endif
00041 
00042 #if P_URL
00043 
00044 
00046 // PURL
00047 
00048 class PURLLegacyScheme;
00049 
00055 class PURL : public PObject
00056 {
00057   PCLASSINFO(PURL, PObject)
00058   public:
00060     PURL();
00062     PURL(
00063       const char * cstr,    
00064       const char * defaultScheme = NULL 
00065     );
00067     PURL(
00068       const PString & str,  
00069       const char * defaultScheme = NULL 
00070     );
00072     PURL(
00073       const PFilePath & path   
00074     );
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 SplitQueryVars(
00191       const PString & queryStr,   
00192       PStringToString & queryVars 
00193     );
00194 
00195 
00197     const PCaselessString & GetScheme() const { return scheme; }
00198 
00200     void SetScheme(const PString & scheme);
00201 
00203     const PString & GetUserName() const { return username; }
00204 
00206     void SetUserName(const PString & username);
00207 
00209     const PString & GetPassword() const { return password; }
00210 
00212     void SetPassword(const PString & password);
00213 
00215     const PCaselessString & GetHostName() const { return hostname; }
00216 
00218     void SetHostName(const PString & hostname);
00219 
00221     WORD GetPort() const { return port; }
00222 
00224     void SetPort(WORD newPort);
00225     
00227     PBoolean GetPortSupplied() const { return portSupplied; }
00228 
00230     PBoolean GetRelativePath() const { return relativePath; }
00231 
00233     const PString & GetPathStr() const { return pathStr; }
00234 
00236     void SetPathStr(const PString & pathStr);
00237 
00239     const PStringArray & GetPath() const { return path; }
00240 
00242     void SetPath(const PStringArray & path);
00243 
00245     PString GetParameters() const;
00246 
00248     void SetParameters(const PString & parameters);
00249 
00251     const PStringToString & GetParamVars() const { return paramVars; }
00252 
00254     void SetParamVars(const PStringToString & paramVars);
00255 
00257     void SetParamVar(const PString & key, const PString & data);
00258 
00260     const PString & GetFragment() const { return fragment; }
00261 
00263     PString GetQuery() const;
00264 
00266     void SetQuery(const PString & query);
00267 
00269     const PStringToString & GetQueryVars() const { return queryVars; }
00270 
00272     void SetQueryVars(const PStringToString & queryVars);
00273 
00275     void SetQueryVar(const PString & key, const PString & data);
00276 
00278     PBoolean IsEmpty() const { return urlString.IsEmpty(); }
00279 
00280 
00287     static PBoolean OpenBrowser(
00288       const PString & url   
00289     );
00291 
00292     PBoolean LegacyParse(const PString & _url, const PURLLegacyScheme * schemeInfo);
00293     PString LegacyAsString(PURL::UrlFormat fmt, const PURLLegacyScheme * schemeInfo) const;
00294 
00295   protected:
00296     virtual PBoolean InternalParse(
00297       const char * cstr,         
00298       const char * defaultScheme 
00299     );
00300     void Recalculate();
00301     PString urlString;
00302 
00303     PCaselessString scheme;
00304     PString username;
00305     PString password;
00306     PCaselessString hostname;
00307     WORD port;
00308     PBoolean portSupplied;          
00309     PBoolean relativePath;
00310     PString pathStr;
00311     PStringArray path;
00312     PStringToString paramVars;
00313     PString fragment;
00314     PStringToString queryVars;
00315 };
00316 
00317 
00319 // PURLScheme
00320 
00321 class PURLScheme : public PObject
00322 {
00323   PCLASSINFO(PURLScheme, PObject);
00324   public:
00325     virtual PString GetName() const = 0;
00326     virtual PBoolean Parse(const PString & url, PURL & purl) const = 0;
00327     virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0;
00328 };
00329 
00331 // PURLLegacyScheme
00332 
00333 class PURLLegacyScheme : public PURLScheme
00334 {
00335   public:
00336     PURLLegacyScheme(const char * _scheme)
00337       : scheme(_scheme) { }
00338 
00339     PBoolean Parse(const PString & url, PURL & purl) const
00340     { return purl.LegacyParse(url, this); }
00341 
00342     PString AsString(PURL::UrlFormat fmt, const PURL & purl) const
00343     { return purl.LegacyAsString(fmt, this); }
00344 
00345     PString GetName() const     
00346     { return scheme; }
00347 
00348     PString scheme;
00349     PBoolean hasUsername;
00350     PBoolean hasPassword;
00351     PBoolean hasHostPort;
00352     PBoolean defaultToUserIfNoAt;
00353     PBoolean defaultHostToLocal;
00354     PBoolean hasQuery;
00355     PBoolean hasParameters;
00356     PBoolean hasFragments;
00357     PBoolean hasPath;
00358     PBoolean relativeImpliesScheme;
00359     WORD defaultPort;
00360 };
00361 
00362 #endif // P_URL
00363 
00364 #endif // _PURL_H
00365 
00366 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1