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: 21572 $
00027  * $Author: csoutheren $
00028  * $Date: 2008-11-20 04:36:24 +0000 (Thu, 20 Nov 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 
00076     PURL(const PURL & other);
00077     PURL & operator=(const PURL & other);
00078 
00087     virtual Comparison Compare(
00088       const PObject & obj   
00089     ) const;
00090 
00102     virtual PINDEX HashFunction() const;
00103 
00106     virtual void PrintOn(
00107       ostream &strm   
00108     ) const;
00109 
00113     virtual void ReadFrom(
00114       istream &strm   
00115     );
00117  
00121     inline PBoolean Parse(
00122       const char * cstr,   
00123       const char * defaultScheme = NULL 
00124     ) { return InternalParse(cstr, defaultScheme); }
00126     inline PBoolean Parse(
00127       const PString & str, 
00128       const char * defaultScheme = NULL 
00129     ) { return InternalParse((const char *)str, defaultScheme); }
00130 
00132     enum UrlFormat {
00134       FullURL,      
00136       PathOnly,     
00138       URIOnly,      
00140       HostPortOnly  
00141     };
00142 
00149     PString AsString(
00150       UrlFormat fmt = FullURL   
00151     ) const;
00152 
00156     PFilePath AsFilePath() const;
00157 
00159     enum TranslationType {
00161       LoginTranslation,
00163       PathTranslation,
00165       QueryTranslation
00166     };
00167 
00175     static PString TranslateString(
00176       const PString & str,    
00177       TranslationType type    
00178     );
00179 
00187     static PString UntranslateString(
00188       const PString & str,    
00189       TranslationType type    
00190     );
00191 
00193     static void SplitVars(
00194       const PString & str,    
00195       PStringToString & vars, 
00196       char sep1,              
00197       char sep2               
00198     );
00199 
00201     static void SplitQueryVars(
00202       const PString & queryStr,   
00203       PStringToString & queryVars 
00204     ) { SplitVars(queryStr, queryVars, '&', '='); }
00205 
00206 
00207 
00209     const PCaselessString & GetScheme() const { return scheme; }
00210 
00212     void SetScheme(const PString & scheme);
00213 
00215     const PString & GetUserName() const { return username; }
00216 
00218     void SetUserName(const PString & username);
00219 
00221     const PString & GetPassword() const { return password; }
00222 
00224     void SetPassword(const PString & password);
00225 
00227     const PCaselessString & GetHostName() const { return hostname; }
00228 
00230     void SetHostName(const PString & hostname);
00231 
00233     WORD GetPort() const { return port; }
00234 
00236     void SetPort(WORD newPort);
00237     
00239     PBoolean GetPortSupplied() const { return portSupplied; }
00240 
00242     PBoolean GetRelativePath() const { return relativePath; }
00243 
00245     const PString & GetPathStr() const { return pathStr; }
00246 
00248     void SetPathStr(const PString & pathStr);
00249 
00251     const PStringArray & GetPath() const { return path; }
00252 
00254     void SetPath(const PStringArray & path);
00255 
00257     PString GetParameters() const;
00258 
00260     void SetParameters(const PString & parameters);
00261 
00263     const PStringToString & GetParamVars() const { return paramVars; }
00264 
00266     void SetParamVars(const PStringToString & paramVars);
00267 
00269     void SetParamVar(const PString & key, const PString & data);
00270 
00272     const PString & GetFragment() const { return fragment; }
00273 
00275     PString GetQuery() const;
00276 
00278     void SetQuery(const PString & query);
00279 
00281     const PStringToString & GetQueryVars() const { return queryVars; }
00282 
00284     void SetQueryVars(const PStringToString & queryVars);
00285 
00287     void SetQueryVar(const PString & key, const PString & data);
00288 
00290     PBoolean IsEmpty() const { return urlString.IsEmpty(); }
00291 
00292 
00299     static PBoolean OpenBrowser(
00300       const PString & url   
00301     );
00303 
00304     PBoolean LegacyParse(const PString & _url, const PURLLegacyScheme * schemeInfo);
00305     PString LegacyAsString(PURL::UrlFormat fmt, const PURLLegacyScheme * schemeInfo) const;
00306 
00307   protected:
00308     void CopyContents(const PURL & other);
00309     virtual PBoolean InternalParse(
00310       const char * cstr,         
00311       const char * defaultScheme 
00312     );
00313     void Recalculate();
00314     PString urlString;
00315 
00316     PCaselessString scheme;
00317     PString username;
00318     PString password;
00319     PCaselessString hostname;
00320     WORD port;
00321     PBoolean portSupplied;          
00322     PBoolean relativePath;
00323     PString pathStr;
00324     PStringArray path;
00325     PStringToString paramVars;
00326     PString fragment;
00327     PStringToString queryVars;
00328 };
00329 
00330 
00332 // PURLScheme
00333 
00334 class PURLScheme : public PObject
00335 {
00336   PCLASSINFO(PURLScheme, PObject);
00337   public:
00338     virtual PString GetName() const = 0;
00339     virtual PBoolean Parse(const PString & url, PURL & purl) const = 0;
00340     virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0;
00341 };
00342 
00344 // PURLLegacyScheme
00345 
00346 class PURLLegacyScheme : public PURLScheme
00347 {
00348   public:
00349     PURLLegacyScheme(const char * _scheme)
00350       : scheme(_scheme) { }
00351 
00352     PBoolean Parse(const PString & url, PURL & purl) const
00353     { return purl.LegacyParse(url, this); }
00354 
00355     PString AsString(PURL::UrlFormat fmt, const PURL & purl) const
00356     { return purl.LegacyAsString(fmt, this); }
00357 
00358     PString GetName() const     
00359     { return scheme; }
00360 
00361     PString scheme;
00362     PBoolean hasUsername;
00363     PBoolean hasPassword;
00364     PBoolean hasHostPort;
00365     PBoolean defaultToUserIfNoAt;
00366     PBoolean defaultHostToLocal;
00367     PBoolean hasQuery;
00368     PBoolean hasParameters;
00369     PBoolean hasFragments;
00370     PBoolean hasPath;
00371     PBoolean relativeImpliesScheme;
00372     WORD defaultPort;
00373 };
00374 
00375 #endif // P_URL
00376 
00377 #endif // _PURL_H
00378 
00379 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 01:57:54 2009 for PTLib by  doxygen 1.5.1