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: 20764 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-08-29 02:15:19 +0000 (Fri, 29 Aug 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 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     virtual PBoolean InternalParse(
00306       const char * cstr,         
00307       const char * defaultScheme 
00308     );
00309     void Recalculate();
00310     PString urlString;
00311 
00312     PCaselessString scheme;
00313     PString username;
00314     PString password;
00315     PCaselessString hostname;
00316     WORD port;
00317     PBoolean portSupplied;          
00318     PBoolean relativePath;
00319     PString pathStr;
00320     PStringArray path;
00321     PStringToString paramVars;
00322     PString fragment;
00323     PStringToString queryVars;
00324 };
00325 
00326 
00328 // PURLScheme
00329 
00330 class PURLScheme : public PObject
00331 {
00332   PCLASSINFO(PURLScheme, PObject);
00333   public:
00334     virtual PString GetName() const = 0;
00335     virtual PBoolean Parse(const PString & url, PURL & purl) const = 0;
00336     virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0;
00337 };
00338 
00340 // PURLLegacyScheme
00341 
00342 class PURLLegacyScheme : public PURLScheme
00343 {
00344   public:
00345     PURLLegacyScheme(const char * _scheme)
00346       : scheme(_scheme) { }
00347 
00348     PBoolean Parse(const PString & url, PURL & purl) const
00349     { return purl.LegacyParse(url, this); }
00350 
00351     PString AsString(PURL::UrlFormat fmt, const PURL & purl) const
00352     { return purl.LegacyAsString(fmt, this); }
00353 
00354     PString GetName() const     
00355     { return scheme; }
00356 
00357     PString scheme;
00358     PBoolean hasUsername;
00359     PBoolean hasPassword;
00360     PBoolean hasHostPort;
00361     PBoolean defaultToUserIfNoAt;
00362     PBoolean defaultHostToLocal;
00363     PBoolean hasQuery;
00364     PBoolean hasParameters;
00365     PBoolean hasFragments;
00366     PBoolean hasPath;
00367     PBoolean relativeImpliesScheme;
00368     WORD defaultPort;
00369 };
00370 
00371 #endif // P_URL
00372 
00373 #endif // _PURL_H
00374 
00375 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 08:27:59 2008 for PTLib by  doxygen 1.5.1