|
limal
|
00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | _ _ _ _ __ _ | 00004 | | | | | | \_/ | / \ | | | 00005 | | | | | | |_| | / /\ \ | | | 00006 | | |__ | | | | | | / ____ \ | |__ | 00007 | |____||_| |_| |_|/ / \ \|____| | 00008 | | 00009 | core library | 00010 | | 00011 | (C) SUSE Linux Products GmbH | 00012 \----------------------------------------------------------------------/ 00013 00014 File: UrlBase.hpp 00015 00016 Author: Marius Tomaschewski 00017 Maintainer: Marius Tomaschewski 00018 00019 /-*/ 00024 #ifndef LIMAL_URLBASE_HPP 00025 #define LIMAL_URLBASE_HPP 00026 00027 #include <limal/config.h> 00028 #include <limal/UrlUtils.hpp> 00029 #include <blocxx/COWReference.hpp> 00030 00031 00032 // ------------------------------------------------------------------- 00033 namespace LIMAL_NAMESPACE 00034 { 00035 namespace url 00036 { 00037 00038 // --------------------------------------------------------------- 00048 struct ViewOptions 00049 { 00053 enum EViewOption 00054 { 00065 WITH_SCHEME = 1L << 0, 00072 WITH_USERNAME = 1L << 1, 00081 WITH_PASSWORD = 1L << 2, 00088 WITH_HOST = 1L << 3, 00095 WITH_PORT = 1L << 4, 00101 WITH_PATH_NAME = 1L << 5, 00109 WITH_PATH_PARAMS = 1L << 6, 00115 WITH_QUERY_STR = 1L << 7, 00121 WITH_FRAGMENT = 1L << 8, 00135 EMPTY_AUTHORITY = 1L << 10, 00147 EMPTY_PATH_NAME = 1L << 11, 00157 EMPTY_PATH_PARAMS = 1L << 12, 00168 EMPTY_QUERY_STR = 1L << 13, 00179 EMPTY_FRAGMENT = 1L << 14, 00181 }; 00182 00191 ViewOptions(); 00192 00198 friend inline ViewOptions 00199 operator + (const ViewOptions &lv, const ViewOptions &rv) 00200 { 00201 return ViewOptions(lv.opt | rv.opt); 00202 } 00203 friend inline ViewOptions 00204 operator + (const ViewOptions &v, EViewOption o) 00205 { 00206 return ViewOptions(v.opt | static_cast<int>(o)); 00207 } 00208 friend inline ViewOptions 00209 operator + (const EViewOption lo, EViewOption ro) 00210 { 00211 return ViewOptions(static_cast<int>(lo) | static_cast<int>(ro)); 00212 } 00213 00219 friend inline ViewOptions 00220 operator - (const ViewOptions &vl, const ViewOptions &vr) 00221 { 00222 return ViewOptions(vl.opt & ~vr.opt); 00223 } 00224 friend inline ViewOptions 00225 operator - (const ViewOptions &v, EViewOption o) 00226 { 00227 return ViewOptions(v.opt & ~ static_cast<int>(o)); 00228 } 00229 00236 inline ViewOptions & 00237 operator = (const ViewOptions &v) 00238 { 00239 opt = v.opt; 00240 return *this; 00241 } 00242 00243 inline ViewOptions & 00244 operator += (const ViewOptions &v) 00245 { 00246 opt |= v.opt; 00247 return *this; 00248 } 00249 inline ViewOptions & 00250 operator += (EViewOption o) 00251 { 00252 opt |= static_cast<int>(o); 00253 return *this; 00254 } 00255 00256 inline ViewOptions & 00257 operator -= (const ViewOptions &v) 00258 { 00259 opt &= ~ v.opt; 00260 return *this; 00261 } 00262 inline ViewOptions & 00263 operator -= (EViewOption o) 00264 { 00265 opt &= ~ static_cast<int>(o); 00266 return *this; 00267 } 00268 00275 inline bool 00276 has(EViewOption o) const 00277 { 00278 return opt & static_cast<int>(o); 00279 } 00280 00287 inline bool 00288 has(const ViewOptions &v) const 00289 { 00290 return opt & v.opt; 00291 } 00292 00293 private: 00294 ViewOptions(int o); 00295 int opt; 00296 }; 00297 00298 00299 // --------------------------------------------------------------- 00303 class UrlBaseData; 00304 00305 00306 // --------------------------------------------------------------- 00315 class UrlBase 00316 { 00317 public: 00318 00322 virtual 00323 ~UrlBase(); 00324 00328 UrlBase(); 00329 00334 UrlBase(const UrlBase &url); 00335 00346 UrlBase(const UrlComponents &components); 00347 00358 UrlBase(const blocxx::String &urlString); 00359 00360 00361 // ----------------- 00371 UrlBase& 00372 operator = (const UrlBase &url); 00373 00374 00390 UrlBase& 00391 operator = (const blocxx::String &urlString); 00392 00393 00394 // ----------------- 00398 virtual void 00399 clear(); 00400 00412 virtual UrlBase * 00413 clone() const; 00414 00424 virtual void 00425 init(const UrlComponents &components); 00426 00427 00428 // ----------------- 00446 virtual blocxx::StringArray 00447 getKnownSchemes() const; 00448 00453 virtual bool 00454 isKnownScheme(const blocxx::String &scheme) const; 00455 00456 00469 virtual bool 00470 isValidScheme(const blocxx::String &scheme) const; 00471 00481 virtual bool 00482 isValid() const; 00483 00484 00485 // ----------------- 00493 virtual blocxx::String 00494 toString() const; 00495 00508 virtual blocxx::String 00509 toString(const limal::url::ViewOptions &opts) const; 00510 00511 00512 // ----------------- 00517 virtual blocxx::String 00518 getScheme() const; 00519 00520 00521 // ----------------- 00531 virtual blocxx::String 00532 getAuthority() const; 00533 00541 virtual blocxx::String 00542 getUsername(EEncoding eflag) const; 00543 00551 virtual blocxx::String 00552 getPassword(EEncoding eflag) const; 00553 00566 virtual blocxx::String 00567 getHost(EEncoding eflag) const; 00568 00573 virtual blocxx::String 00574 getPort() const; 00575 00576 00577 // ----------------- 00587 virtual blocxx::String 00588 getPathData() const; 00589 00598 virtual blocxx::String 00599 getPathName(EEncoding eflag) const; 00600 00605 virtual blocxx::String 00606 getPathParams() const; 00607 00620 virtual blocxx::StringArray 00621 getPathParamsArray() const; 00622 00642 virtual limal::url::ParamMap 00643 getPathParamsMap(EEncoding eflag) const; 00644 00661 virtual blocxx::String 00662 getPathParam(const blocxx::String ¶m, EEncoding eflag) const; 00663 00664 00665 // ----------------- 00675 virtual blocxx::String 00676 getQueryString() const; 00677 00691 virtual blocxx::StringArray 00692 getQueryStringArray() const; 00693 00712 virtual limal::url::ParamMap 00713 getQueryStringMap(EEncoding eflag) const; 00714 00731 virtual blocxx::String 00732 getQueryParam(const blocxx::String ¶m, EEncoding eflag) const; 00733 00734 00735 // ----------------- 00743 virtual blocxx::String 00744 getFragment(EEncoding eflag) const; 00745 00746 00747 // ----------------- 00754 virtual void 00755 setScheme(const blocxx::String &scheme); 00756 00757 00758 // ----------------- 00772 virtual void 00773 setAuthority(const blocxx::String &authority); 00774 00784 virtual void 00785 setUsername(const blocxx::String &user, 00786 EEncoding eflag); 00787 00797 virtual void 00798 setPassword(const blocxx::String &pass, 00799 EEncoding eflag); 00800 00821 virtual void 00822 setHost(const blocxx::String &host, 00823 EEncoding eflag); 00824 00832 virtual void 00833 setPort(const blocxx::String &port); 00834 00835 00836 // ----------------- 00847 virtual void 00848 setPathData(const blocxx::String &pathdata); 00849 00857 virtual void 00858 setPathName(const blocxx::String &path, 00859 EEncoding eflag); 00860 00867 virtual void 00868 setPathParams(const blocxx::String ¶ms); 00869 00876 virtual void 00877 setPathParamsArray(const blocxx::StringArray &parray); 00878 00885 virtual void 00886 setPathParamsMap(const limal::url::ParamMap &pmap); 00887 00897 virtual void 00898 setPathParam(const blocxx::String ¶m, const blocxx::String &value); 00899 00900 00901 // ----------------- 00914 virtual void 00915 setQueryString(const blocxx::String &querystr); 00916 00923 virtual void 00924 setQueryStringArray(const blocxx::StringArray &qarray); 00925 00932 virtual void 00933 setQueryStringMap(const limal::url::ParamMap &qmap); 00934 00944 virtual void 00945 setQueryParam(const blocxx::String ¶m, const blocxx::String &value); 00946 00947 00948 // ----------------- 00956 virtual void 00957 setFragment(const blocxx::String &fragment, 00958 EEncoding eflag); 00959 00960 00961 // ----------------- 01017 virtual void 01018 configure(); 01019 01020 01031 blocxx::String 01032 config(const blocxx::String &opt) const; 01033 01043 void 01044 config(const blocxx::String &opt, const blocxx::String &val); 01045 01046 01055 ViewOptions 01056 getViewOptions() const; 01057 01066 void 01067 setViewOptions(const ViewOptions &vopts); 01068 01069 01070 protected: 01097 virtual blocxx::String 01098 cleanupPathName(const blocxx::String &path, bool authority) const; 01099 01110 virtual blocxx::String 01111 cleanupPathName(const blocxx::String &path) const; 01112 01113 virtual void 01114 checkValidScheme(const blocxx::String &scheme, EEncoding eflag) const; 01115 01116 virtual void 01117 checkValidUser(const blocxx::String &user, EEncoding eflag) const; 01118 01119 virtual void 01120 checkValidPass(const blocxx::String &pass, EEncoding eflag) const; 01121 01145 virtual void 01146 checkValidHost(const blocxx::String &host, EEncoding eflag) const; 01147 01154 virtual void 01155 checkValidPort(const blocxx::String &port, EEncoding eflag) const; 01156 01157 virtual void 01158 checkValidPathName(const blocxx::String &path, EEncoding eflag) const; 01159 01160 virtual void 01161 checkValidPathParams(const blocxx::String ¶ms, EEncoding eflag) const; 01162 01163 virtual void 01164 checkValidQueryStr(const blocxx::String &querystr, EEncoding eflag) const; 01165 01166 virtual void 01167 checkValidFragment(const blocxx::String &fragment, EEncoding eflag) const; 01168 01169 private: 01170 blocxx::COWReference<UrlBaseData> m_data; 01171 }; 01172 01173 01174 // ------------------------------------------------------------------- 01178 typedef blocxx::COWReference<UrlBase> UrlRef; 01179 01180 01181 // ------------------------------------------------------------------- 01182 } // End url namespace 01183 } // End of LIMAL_NAMESPACE 01184 #endif // LIMAL_URLBASE_HPP 01185 // vim: set ts=8 sts=8 sw=8 ai noet:
1.7.5.1