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: 19008 $
00027  * $Author: rjongbloed $
00028  * $Date: 2007-11-29 09:17:41 +0000 (Thu, 29 Nov 2007) $
00029  */
00030 
00031 #ifndef _PURL
00032 #define _PURL
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #ifndef _PTLIB_H
00039 #include <ptlib.h>
00040 #endif
00041 
00042 
00044 // PURL
00045 
00046 class PURLLegacyScheme;
00047 
00053 class PURL : public PObject
00054 {
00055   PCLASSINFO(PURL, PObject)
00056   public:
00058     PURL();
00060     PURL(
00061       const char * cstr,    
00062       const char * defaultScheme = NULL 
00063     );
00065     PURL(
00066       const PString & str,  
00067       const char * defaultScheme = NULL 
00068     );
00070     PURL(
00071       const PFilePath & path   
00072     );
00073 
00082     virtual Comparison Compare(
00083       const PObject & obj   
00084     ) const;
00085 
00097     virtual PINDEX HashFunction() const;
00098 
00101     virtual void PrintOn(
00102       ostream &strm   
00103     ) const;
00104 
00108     virtual void ReadFrom(
00109       istream &strm   
00110     );
00112  
00116     inline PBoolean Parse(
00117       const char * cstr,   
00118       const char * defaultScheme = NULL 
00119     ) { return InternalParse(cstr, defaultScheme); }
00121     inline PBoolean Parse(
00122       const PString & str, 
00123       const char * defaultScheme = NULL 
00124     ) { return InternalParse((const char *)str, defaultScheme); }
00125 
00127     enum UrlFormat {
00129       FullURL,      
00131       PathOnly,     
00133       URIOnly,      
00135       HostPortOnly  
00136     };
00137 
00144     PString AsString(
00145       UrlFormat fmt = FullURL   
00146     ) const;
00147 
00151     PFilePath AsFilePath() const;
00152 
00154     enum TranslationType {
00156       LoginTranslation,
00158       PathTranslation,
00160       QueryTranslation
00161     };
00162 
00170     static PString TranslateString(
00171       const PString & str,    
00172       TranslationType type    
00173     );
00174 
00182     static PString UntranslateString(
00183       const PString & str,    
00184       TranslationType type    
00185     );
00186 
00188     static void SplitQueryVars(
00189       const PString & queryStr,   
00190       PStringToString & queryVars 
00191     );
00192 
00193 
00195     const PCaselessString & GetScheme() const { return scheme; }
00196 
00198     void SetScheme(const PString & scheme);
00199 
00201     const PString & GetUserName() const { return username; }
00202 
00204     void SetUserName(const PString & username);
00205 
00207     const PString & GetPassword() const { return password; }
00208 
00210     void SetPassword(const PString & password);
00211 
00213     const PCaselessString & GetHostName() const { return hostname; }
00214 
00216     void SetHostName(const PString & hostname);
00217 
00219     WORD GetPort() const { return port; }
00220 
00222     void SetPort(WORD newPort);
00223     
00225     PBoolean GetPortSupplied() const { return portSupplied; }
00226 
00228     PBoolean GetRelativePath() const { return relativePath; }
00229 
00231     const PString & GetPathStr() const { return pathStr; }
00232 
00234     void SetPathStr(const PString & pathStr);
00235 
00237     const PStringArray & GetPath() const { return path; }
00238 
00240     void SetPath(const PStringArray & path);
00241 
00243     PString GetParameters() const;
00244 
00246     void SetParameters(const PString & parameters);
00247 
00249     const PStringToString & GetParamVars() const { return paramVars; }
00250 
00252     void SetParamVars(const PStringToString & paramVars);
00253 
00255     void SetParamVar(const PString & key, const PString & data);
00256 
00258     const PString & GetFragment() const { return fragment; }
00259 
00261     PString GetQuery() const;
00262 
00264     void SetQuery(const PString & query);
00265 
00267     const PStringToString & GetQueryVars() const { return queryVars; }
00268 
00270     void SetQueryVars(const PStringToString & queryVars);
00271 
00273     void SetQueryVar(const PString & key, const PString & data);
00274 
00276     PBoolean IsEmpty() const { return urlString.IsEmpty(); }
00277 
00278 
00285     static PBoolean OpenBrowser(
00286       const PString & url   
00287     );
00289 
00290     PBoolean LegacyParse(const PString & _url, const PURLLegacyScheme * schemeInfo);
00291     PString LegacyAsString(PURL::UrlFormat fmt, const PURLLegacyScheme * schemeInfo) const;
00292 
00293   protected:
00294     virtual PBoolean InternalParse(
00295       const char * cstr,         
00296       const char * defaultScheme 
00297     );
00298     void Recalculate();
00299     PString urlString;
00300 
00301     PCaselessString scheme;
00302     PString username;
00303     PString password;
00304     PCaselessString hostname;
00305     WORD port;
00306     PBoolean portSupplied;          
00307     PBoolean relativePath;
00308     PString pathStr;
00309     PStringArray path;
00310     PStringToString paramVars;
00311     PString fragment;
00312     PStringToString queryVars;
00313 };
00314 
00315 
00317 // PURLScheme
00318 
00319 class PURLScheme : public PObject
00320 {
00321   PCLASSINFO(PURLScheme, PObject);
00322   public:
00323     virtual PString GetName() const = 0;
00324     virtual PBoolean Parse(const PString & url, PURL & purl) const = 0;
00325     virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0;
00326 };
00327 
00329 // PURLLegacyScheme
00330 
00331 class PURLLegacyScheme : public PURLScheme
00332 {
00333   public:
00334     PURLLegacyScheme(const char * _scheme)
00335       : scheme(_scheme) { }
00336 
00337     PBoolean Parse(const PString & url, PURL & purl) const
00338     { return purl.LegacyParse(url, this); }
00339 
00340     PString AsString(PURL::UrlFormat fmt, const PURL & purl) const
00341     { return purl.LegacyAsString(fmt, this); }
00342 
00343     PString GetName() const     
00344     { return scheme; }
00345 
00346     PString scheme;
00347     PBoolean hasUsername;
00348     PBoolean hasPassword;
00349     PBoolean hasHostPort;
00350     PBoolean defaultToUserIfNoAt;
00351     PBoolean defaultHostToLocal;
00352     PBoolean hasQuery;
00353     PBoolean hasParameters;
00354     PBoolean hasFragments;
00355     PBoolean hasPath;
00356     PBoolean relativeImpliesScheme;
00357     WORD defaultPort;
00358 };
00359 
00360 #endif
00361 
00362 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Dec 10 11:18:57 2007 for PTLib by  doxygen 1.5.1