libcamgm
UrlBase.hpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | _ _ _ _ __ _ |
4 | | | | | | \_/ | / \ | | |
5 | | | | | | |_| | / /\ \ | | |
6 | | |__ | | | | | | / ____ \ | |__ |
7 | |____||_| |_| |_|/ / \ \|____| |
8 | |
9 | core library |
10 | |
11 | (C) SUSE Linux Products GmbH |
12 \----------------------------------------------------------------------/
13 
14  File: UrlBase.hpp
15 
16  Author: Marius Tomaschewski
17  Maintainer: Marius Tomaschewski
18 
19 /-*/
24 #ifndef CA_MGM_URLBASE_HPP
25 #define CA_MGM_URLBASE_HPP
26 
27 #include <ca-mgm/config.h>
28 #include <ca-mgm/UrlUtils.hpp>
29 #include <ca-mgm/PtrTypes.hpp>
30 
31 
32 // -------------------------------------------------------------------
33 namespace CA_MGM_NAMESPACE
34 {
35 namespace url
36 {
37 
38 // ---------------------------------------------------------------
49 {
54  {
65  WITH_SCHEME = 1L << 0,
72  WITH_USERNAME = 1L << 1,
81  WITH_PASSWORD = 1L << 2,
88  WITH_HOST = 1L << 3,
95  WITH_PORT = 1L << 4,
101  WITH_PATH_NAME = 1L << 5,
109  WITH_PATH_PARAMS = 1L << 6,
115  WITH_QUERY_STR = 1L << 7,
121  WITH_FRAGMENT = 1L << 8,
135  EMPTY_AUTHORITY = 1L << 10,
147  EMPTY_PATH_NAME = 1L << 11,
157  EMPTY_PATH_PARAMS = 1L << 12,
168  EMPTY_QUERY_STR = 1L << 13,
179  EMPTY_FRAGMENT = 1L << 14,
181  };
182 
191  ViewOptions();
192 
198  friend inline ViewOptions
199  operator + (const ViewOptions &lv, const ViewOptions &rv)
200  {
201  return ViewOptions(lv.opt | rv.opt);
202  }
203  friend inline ViewOptions
205  {
206  return ViewOptions(v.opt | static_cast<int>(o));
207  }
208  friend inline ViewOptions
210  {
211  return ViewOptions(static_cast<int>(lo) | static_cast<int>(ro));
212  }
213 
219  friend inline ViewOptions
220  operator - (const ViewOptions &vl, const ViewOptions &vr)
221  {
222  return ViewOptions(vl.opt & ~vr.opt);
223  }
224  friend inline ViewOptions
225  operator - (const ViewOptions &v, EViewOption o)
226  {
227  return ViewOptions(v.opt & ~ static_cast<int>(o));
228  }
229 
236  inline ViewOptions &
237  operator = (const ViewOptions &v)
238  {
239  opt = v.opt;
240  return *this;
241  }
242 
243  inline ViewOptions &
244  operator += (const ViewOptions &v)
245  {
246  opt |= v.opt;
247  return *this;
248  }
249  inline ViewOptions &
250  operator += (EViewOption o)
251  {
252  opt |= static_cast<int>(o);
253  return *this;
254  }
255 
256  inline ViewOptions &
257  operator -= (const ViewOptions &v)
258  {
259  opt &= ~ v.opt;
260  return *this;
261  }
262  inline ViewOptions &
263  operator -= (EViewOption o)
264  {
265  opt &= ~ static_cast<int>(o);
266  return *this;
267  }
268 
275  inline bool
276  has(EViewOption o) const
277  {
278  return opt & static_cast<int>(o);
279  }
280 
287  inline bool
288  has(const ViewOptions &v) const
289  {
290  return opt & v.opt;
291  }
292 
293 private:
294  ViewOptions(int o);
295  int opt;
296 };
297 
298 
299 // ---------------------------------------------------------------
303 class UrlBaseData;
304 
305 
306 // ---------------------------------------------------------------
315 class UrlBase
316 {
317 public:
318 
322  virtual
323  ~UrlBase();
324 
328  UrlBase();
329 
334  UrlBase(const UrlBase &url);
335 
346  UrlBase(const UrlComponents &components);
347 
358  UrlBase(const std::string &urlString);
359 
360 
361  // -----------------
371  UrlBase&
372  operator = (const UrlBase &url);
373 
374 
390  UrlBase&
391  operator = (const std::string &urlString);
392 
393 
394  // -----------------
398  virtual void
399  clear();
400 
412  virtual UrlBase *
413  clone() const;
414 
424  virtual void
425  init(const UrlComponents &components);
426 
427 
428  // -----------------
446  virtual std::vector<std::string>
447  getKnownSchemes() const;
448 
453  virtual bool
454  isKnownScheme(const std::string &scheme) const;
455 
456 
469  virtual bool
470  isValidScheme(const std::string &scheme) const;
471 
481  virtual bool
482  isValid() const;
483 
484 
485  // -----------------
493  virtual std::string
494  toString() const;
495 
508  virtual std::string
509  toString(const ca_mgm::url::ViewOptions &opts) const;
510 
511 
512  // -----------------
517  virtual std::string
518  getScheme() const;
519 
520 
521  // -----------------
531  virtual std::string
532  getAuthority() const;
533 
541  virtual std::string
542  getUsername(EEncoding eflag) const;
543 
551  virtual std::string
552  getPassword(EEncoding eflag) const;
553 
566  virtual std::string
567  getHost(EEncoding eflag) const;
568 
573  virtual std::string
574  getPort() const;
575 
576 
577  // -----------------
587  virtual std::string
588  getPathData() const;
589 
598  virtual std::string
599  getPathName(EEncoding eflag) const;
600 
605  virtual std::string
606  getPathParams() const;
607 
620  virtual std::vector<std::string>
621  getPathParamsArray() const;
622 
642  virtual ca_mgm::url::ParamMap
643  getPathParamsMap(EEncoding eflag) const;
644 
661  virtual std::string
662  getPathParam(const std::string &param, EEncoding eflag) const;
663 
664 
665  // -----------------
675  virtual std::string
676  getQueryString() const;
677 
691  virtual std::vector<std::string>
692  getQueryStringArray() const;
693 
712  virtual ca_mgm::url::ParamMap
713  getQueryStringMap(EEncoding eflag) const;
714 
731  virtual std::string
732  getQueryParam(const std::string &param, EEncoding eflag) const;
733 
734 
735  // -----------------
743  virtual std::string
744  getFragment(EEncoding eflag) const;
745 
746 
747  // -----------------
754  virtual void
755  setScheme(const std::string &scheme);
756 
757 
758  // -----------------
772  virtual void
773  setAuthority(const std::string &authority);
774 
784  virtual void
785  setUsername(const std::string &user,
786  EEncoding eflag);
787 
797  virtual void
798  setPassword(const std::string &pass,
799  EEncoding eflag);
800 
821  virtual void
822  setHost(const std::string &host,
823  EEncoding eflag);
824 
832  virtual void
833  setPort(const std::string &port);
834 
835 
836  // -----------------
847  virtual void
848  setPathData(const std::string &pathdata);
849 
857  virtual void
858  setPathName(const std::string &path,
859  EEncoding eflag);
860 
867  virtual void
868  setPathParams(const std::string &params);
869 
876  virtual void
877  setPathParamsArray(const std::vector<std::string> &parray);
878 
885  virtual void
886  setPathParamsMap(const ca_mgm::url::ParamMap &pmap);
887 
897  virtual void
898  setPathParam(const std::string &param, const std::string &value);
899 
900 
901  // -----------------
914  virtual void
915  setQueryString(const std::string &querystr);
916 
923  virtual void
924  setQueryStringArray(const std::vector<std::string> &qarray);
925 
932  virtual void
933  setQueryStringMap(const ca_mgm::url::ParamMap &qmap);
934 
944  virtual void
945  setQueryParam(const std::string &param, const std::string &value);
946 
947 
948  // -----------------
956  virtual void
957  setFragment(const std::string &fragment,
958  EEncoding eflag);
959 
960 
961  // -----------------
1017  virtual void
1018  configure();
1019 
1020 
1031  std::string
1032  config(const std::string &opt) const;
1033 
1043  void
1044  config(const std::string &opt, const std::string &val);
1045 
1046 
1055  ViewOptions
1056  getViewOptions() const;
1057 
1066  void
1067  setViewOptions(const ViewOptions &vopts);
1068 
1069 
1070 protected:
1097  virtual std::string
1098  cleanupPathName(const std::string &path, bool authority) const;
1099 
1110  virtual std::string
1111  cleanupPathName(const std::string &path) const;
1112 
1113  virtual void
1114  checkValidScheme(const std::string &scheme, EEncoding eflag) const;
1115 
1116  virtual void
1117  checkValidUser(const std::string &user, EEncoding eflag) const;
1118 
1119  virtual void
1120  checkValidPass(const std::string &pass, EEncoding eflag) const;
1121 
1145  virtual void
1146  checkValidHost(const std::string &host, EEncoding eflag) const;
1147 
1154  virtual void
1155  checkValidPort(const std::string &port, EEncoding eflag) const;
1156 
1157  virtual void
1158  checkValidPathName(const std::string &path, EEncoding eflag) const;
1159 
1160  virtual void
1161  checkValidPathParams(const std::string &params, EEncoding eflag) const;
1162 
1163  virtual void
1164  checkValidQueryStr(const std::string &querystr, EEncoding eflag) const;
1165 
1166  virtual void
1167  checkValidFragment(const std::string &fragment, EEncoding eflag) const;
1168 
1169 private:
1171 };
1172 
1173 
1174 // -------------------------------------------------------------------
1179 
1180 
1181 // -------------------------------------------------------------------
1182 } // End url namespace
1183 } // End of CA_MGM_NAMESPACE
1184 #endif // CA_MGM_URLBASE_HPP
1185 // vim: set ts=8 sts=8 sw=8 ai noet:
PathName operator+(const PathName &lname, const PathName &rname)
Definition: PathName.hpp:451
bool has(EViewOption o) const
Definition: UrlBase.hpp:276
Definition: UrlBase.hpp:48
std::string toString(bool b)
Definition: String.hpp:125
EViewOption
Definition: UrlBase.hpp:53
RWCOW_pointer< UrlBaseData > m_data
Definition: UrlBase.hpp:1170
LiMaL url utilities.
bool has(const ViewOptions &v) const
Definition: UrlBase.hpp:288
Definition: UrlUtils.hpp:102
Generic Url base class.
Definition: UrlBase.hpp:315
std::map< std::string, std::string > ParamMap
Definition: UrlUtils.hpp:95
int opt
Definition: UrlBase.hpp:295
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition: UrlBase.hpp:1178
EEncoding
Definition: UrlUtils.hpp:135