00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef FALCON_URI_H
00017 #define FALCON_URI_H
00018
00019 #include <falcon/setup.h>
00020 #include <falcon/string.h>
00021 #include <falcon/path.h>
00022 #include <falcon/genericmap.h>
00023
00024 namespace Falcon
00025 {
00026
00031 class FALCON_DYN_CLASS URI: public BaseAlloc
00032 {
00034 String m_original;
00035
00037 mutable String m_encoded;
00038
00040 bool m_bValid;
00041
00043 String m_scheme;
00044
00045
00047 String m_userInfo;
00048
00050 String m_host;
00051
00053 String m_port;
00054
00065 Path m_path;
00066
00068 mutable String m_query;
00069
00080 Map *m_queryMap;
00081
00083 MapIterator m_queryIter;
00084
00086 String m_fragment;
00087
00089 void encode( const String &u );
00090
00092 bool internal_parseQuery( const String &str, uint32 pos, bool parseQuery , bool bDecode );
00093
00095 bool internal_parseFragment( uint32 pos );
00096
00097 bool internal_parse( const String &newUri, bool parseQuery, bool decode = true );
00098
00099 friend class Path;
00100
00101 public:
00102
00106 URI();
00107
00113 URI( const String &suri );
00114
00118 URI( const URI &other );
00119
00120 virtual ~URI();
00121
00142 bool parse( const String &newUri, bool parseQuery = false, bool decode = true );
00143
00160 bool parseQuery( bool decode = true );
00161
00169 bool parseQuery( const String &q, bool decode = true )
00170 {
00171 query( q );
00172 return parseQuery( decode );
00173 }
00174
00186 void query( const String &q, bool encode = false );
00187
00195 const String &query() const { return m_query; }
00196
00207 const String &makeQuery() const;
00208
00219 const String &get( bool synthQuery = true ) const;
00220
00221
00223 static bool isResDelim( uint32 chr );
00224
00226 static bool isMainDelim( uint32 chr );
00227
00229 static bool isGenDelim( uint32 chr );
00230
00232 static bool isSubDelim( uint32 chr );
00233
00253
00254
00256 const String &scheme() const { return m_scheme; }
00257
00261 void scheme( const String &s );
00262
00264 const String &userInfo() const { return m_userInfo; }
00265
00269 void userInfo( const String &s );
00270
00272 const String &host() const { return m_host; }
00273
00277 void host( const String &h );
00278
00280 const String &port() const { return m_port; }
00281
00285 void port( const String &h );
00286
00288 const String &path() const { return m_path.get(); }
00289
00291 const Path &pathElement() const { return m_path; }
00292
00294 Path &pathElement() { return m_path; }
00295
00299 void path( const String &p );
00300
00304 void path( const Path &p );
00305
00307 bool hasField( const String &f ) const ;
00308
00310 bool getField( const String &key, String &value ) const;
00311
00319 void setField( const String &key, const String &value );
00320
00322 bool removeField( const String &key );
00323
00334 bool firstField( String &key, String &value );
00335
00345 bool nextField( String &key, String &value );
00346
00356 uint32 fieldCount();
00357
00359 const String &fragment() const { return m_fragment; }
00360
00362 void fragment( const String &s );
00363
00365 void clear();
00366
00368 bool isValid() const { return m_bValid; }
00369
00370 static void URLEncode( const String &source, String &target );
00371 static String URLEncode( const String &source )
00372 {
00373 String t;
00374 URLEncode( source, t );
00375 return t;
00376 }
00377
00384 static bool URLDecode( const String &source, String &target );
00385 static String URLDecode( const String &source )
00386 {
00387 String t;
00388 URLDecode( source, t );
00389 return t;
00390 }
00391
00392 static unsigned char CharToHex( unsigned char ch )
00393 {
00394 return ch <= 9 ? '0' + ch : 'A' + (ch - 10);
00395 }
00396
00397 static unsigned char HexToChar( unsigned char ch )
00398 {
00399 if ( ch >= '0' && ch <= '9' )
00400 return ch - '0';
00401 else if ( ch >= 'A' && ch <= 'F' )
00402 return ch - 'A'+ 10;
00403 else if ( ch >= 'a' && ch <= 'f' )
00404 return ch - 'a'+ 10;
00405 else
00406 return 0xFF;
00407 }
00408 };
00409
00410
00411
00412
00413
00414 inline bool URI::isResDelim( uint32 chr )
00415 {
00416 return isGenDelim( chr ) | isSubDelim( chr );
00417 }
00418
00419 inline bool URI::isMainDelim( uint32 chr )
00420 {
00421 return (chr == ':') | (chr == '?') | (chr == '#') | (chr == '@');
00422 }
00423
00424 inline bool URI::isGenDelim( uint32 chr )
00425 {
00426 return (chr == ':') | (chr == '/') | (chr == '?') |
00427 (chr == '#') | (chr == '[') | (chr == ']') |
00428 (chr == '@');
00429 }
00430
00431 inline bool URI::isSubDelim( uint32 chr )
00432 {
00433 return (chr == '!') | (chr == '$') | (chr == '&') |
00434 (chr == '\'') | (chr == '(') | (chr == ')') |
00435 (chr == '*') | (chr == '+') | (chr == ',') |
00436 (chr == ';') | (chr == '=');
00437 }
00438
00439 }
00440
00441 #endif