00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
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 = "http"
00062 );
00064 PURL(
00065 const PString & str,
00066 const char * defaultScheme = "http"
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 operator PString() const { return AsString(); }
00150
00154 PFilePath AsFilePath() const;
00155
00157 enum TranslationType {
00159 LoginTranslation,
00161 PathTranslation,
00163 QueryTranslation
00164 };
00165
00173 static PString TranslateString(
00174 const PString & str,
00175 TranslationType type
00176 );
00177
00185 static PString UntranslateString(
00186 const PString & str,
00187 TranslationType type
00188 );
00189
00191 static void SplitVars(
00192 const PString & str,
00193 PStringToString & vars,
00194 char sep1,
00195 char sep2
00196 );
00197
00199 static void SplitQueryVars(
00200 const PString & queryStr,
00201 PStringToString & queryVars
00202 ) { SplitVars(queryStr, queryVars, '&', '='); }
00203
00204
00205
00207 const PCaselessString & GetScheme() const { return scheme; }
00208
00210 void SetScheme(const PString & scheme);
00211
00213 const PString & GetUserName() const { return username; }
00214
00216 void SetUserName(const PString & username);
00217
00219 const PString & GetPassword() const { return password; }
00220
00222 void SetPassword(const PString & password);
00223
00225 const PCaselessString & GetHostName() const { return hostname; }
00226
00228 void SetHostName(const PString & hostname);
00229
00231 WORD GetPort() const { return port; }
00232
00234 void SetPort(WORD newPort);
00235
00237 PBoolean GetPortSupplied() const { return portSupplied; }
00238
00240 PBoolean GetRelativePath() const { return relativePath; }
00241
00243 PString GetPathStr() const;
00244
00246 void SetPathStr(const PString & pathStr);
00247
00249 const PStringArray & GetPath() const { return path; }
00250
00252 void SetPath(const PStringArray & path);
00253
00255 void AppendPath(const PString & segment);
00256
00258 PString GetParameters() const;
00259
00261 void SetParameters(const PString & parameters);
00262
00265 const PStringToString & GetParamVars() const { return paramVars; }
00266
00269 void SetParamVars(const PStringToString & paramVars);
00270
00273 void SetParamVar(
00274 const PString & key,
00275 const PString & data,
00276 bool emptyDataDeletes = true
00277 );
00278
00280 const PString & GetFragment() const { return fragment; }
00281
00283 PString GetQuery() const;
00284
00287 void SetQuery(const PString & query);
00288
00291 const PStringToString & GetQueryVars() const { return queryVars; }
00292
00295 void SetQueryVars(const PStringToString & queryVars);
00296
00299 void SetQueryVar(const PString & key, const PString & data);
00300
00302 const PString & GetContents() const { return m_contents; }
00303
00305 void SetContents(const PString & str);
00306
00308 PBoolean IsEmpty() const { return urlString.IsEmpty(); }
00309
00310
00317 static PBoolean OpenBrowser(
00318 const PString & url
00319 );
00321
00322 PBoolean LegacyParse(const PString & url, const PURLLegacyScheme * schemeInfo);
00323 PString LegacyAsString(PURL::UrlFormat fmt, const PURLLegacyScheme * schemeInfo) const;
00324
00325 protected:
00326 void CopyContents(const PURL & other);
00327 virtual PBoolean InternalParse(
00328 const char * cstr,
00329 const char * defaultScheme
00330 );
00331 void Recalculate();
00332 PString urlString;
00333
00334 PCaselessString scheme;
00335 PString username;
00336 PString password;
00337 PCaselessString hostname;
00338 WORD port;
00339 PBoolean portSupplied;
00340 PBoolean relativePath;
00341 PStringArray path;
00342 PStringToString paramVars;
00343 PString fragment;
00344 PStringToString queryVars;
00345 PString m_contents;
00346 };
00347
00348
00350
00351
00352 class PURLScheme : public PObject
00353 {
00354 PCLASSINFO(PURLScheme, PObject);
00355 public:
00356 virtual PString GetName() const = 0;
00357 virtual PBoolean Parse(const PString & url, PURL & purl) const = 0;
00358 virtual PString AsString(PURL::UrlFormat fmt, const PURL & purl) const = 0;
00359 };
00360
00362
00363
00364 class PURLLegacyScheme : public PURLScheme
00365 {
00366 public:
00367 PURLLegacyScheme(
00368 const char * s,
00369 bool user = false,
00370 bool pass = false,
00371 bool host = false,
00372 bool def = false,
00373 bool defhost = false,
00374 bool query = false,
00375 bool params = false,
00376 bool frags = false,
00377 bool path = false,
00378 bool rel = false,
00379 WORD port = 0
00380 )
00381 : scheme(s)
00382 , hasUsername (user)
00383 , hasPassword (pass)
00384 , hasHostPort (host)
00385 , defaultToUserIfNoAt (def)
00386 , defaultHostToLocal (defhost)
00387 , hasQuery (query)
00388 , hasParameters (params)
00389 , hasFragments (frags)
00390 , hasPath (path)
00391 , relativeImpliesScheme (rel)
00392 , defaultPort (port)
00393 { }
00394
00395 PBoolean Parse(const PString & url, PURL & purl) const
00396 { return purl.LegacyParse(url, this); }
00397
00398 PString AsString(PURL::UrlFormat fmt, const PURL & purl) const
00399 { return purl.LegacyAsString(fmt, this); }
00400
00401 PString GetName() const
00402 { return scheme; }
00403
00404 PString scheme;
00405 bool hasUsername;
00406 bool hasPassword;
00407 bool hasHostPort;
00408 bool defaultToUserIfNoAt;
00409 bool defaultHostToLocal;
00410 bool hasQuery;
00411 bool hasParameters;
00412 bool hasFragments;
00413 bool hasPath;
00414 bool relativeImpliesScheme;
00415 WORD defaultPort;
00416 };
00417
00418 #endif // P_URL
00419
00420 #endif // PTLIB_PURL_H
00421
00422
00423