libzypp  13.10.6
UrlBase.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_URL_URLBASE_H
13 #define ZYPP_URL_URLBASE_H
14 
15 #include "zypp/url/UrlUtils.h"
16 #include "zypp/base/PtrTypes.h"
17 
18 
20 namespace zypp
21 {
22 
24  namespace url
25  {
26 
27 
28  // ---------------------------------------------------------------
39  struct ViewOption
40  {
51  static const ViewOption WITH_SCHEME;
58  static const ViewOption WITH_USERNAME;
67  static const ViewOption WITH_PASSWORD;
74  static const ViewOption WITH_HOST;
81  static const ViewOption WITH_PORT;
87  static const ViewOption WITH_PATH_NAME;
107  static const ViewOption WITH_FRAGMENT;
177  static const ViewOption DEFAULTS;
184  ViewOption();
185 
186 
192  friend inline ViewOption
193  operator + (const ViewOption &l, const ViewOption &r)
194  {
195  return ViewOption(l.opt | r.opt);
196  }
197 
203  friend inline ViewOption
204  operator - (const ViewOption &l, const ViewOption &r)
205  {
206  return ViewOption(l.opt & ~r.opt);
207  }
208 
215  inline ViewOption &
217  {
218  opt = o.opt; return *this;
219  }
220 
227  inline bool
228  has(const ViewOption &o) const
229  {
230  return o.opt & opt;
231  }
232 
233  private:
234  ViewOption(int option);
235  int opt;
236  };
237 
238 
239  // ---------------------------------------------------------------
244 
245 
246  // ---------------------------------------------------------------
250  typedef std::vector<std::string> UrlSchemes;
251 
252 
253  // ---------------------------------------------------------------
257  class UrlBaseData;
258 
259 
260  // ---------------------------------------------------------------
269  class UrlBase
270  {
271  public:
272 
273  virtual
274  ~UrlBase();
275 
276  UrlBase();
277 
282  UrlBase(const UrlBase &url);
283 
298  UrlBase(const std::string &scheme,
299  const std::string &authority,
300  const std::string &pathdata,
301  const std::string &querystr,
302  const std::string &fragment);
303 
304 
305  // -----------------
309  virtual void
310  clear();
311 
323  virtual UrlBase *
324  clone() const;
325 
339  virtual void
340  init(const std::string &scheme,
341  const std::string &authority,
342  const std::string &pathdata,
343  const std::string &querystr,
344  const std::string &fragment);
345 
346 
347  // -----------------
365  virtual UrlSchemes
366  getKnownSchemes() const;
367 
372  virtual bool
373  isKnownScheme(const std::string &scheme) const;
374 
375 
388  virtual bool
389  isValidScheme(const std::string &scheme) const;
390 
400  virtual bool
401  isValid() const;
402 
403 
404  // -----------------
412  virtual std::string
413  asString() const;
414 
427  virtual std::string
428  asString(const zypp::url::ViewOptions &opts) const;
429 
430 
431  // -----------------
436  virtual std::string
437  getScheme() const;
438 
439 
440  // -----------------
450  virtual std::string
451  getAuthority() const;
452 
460  virtual std::string
461  getUsername(EEncoding eflag) const;
462 
470  virtual std::string
471  getPassword(EEncoding eflag) const;
472 
485  virtual std::string
486  getHost(EEncoding eflag) const;
487 
492  virtual std::string
493  getPort() const;
494 
495 
496  // -----------------
506  virtual std::string
507  getPathData() const;
508 
517  virtual std::string
518  getPathName(EEncoding eflag) const;
519 
524  virtual std::string
525  getPathParams() const;
526 
539  virtual zypp::url::ParamVec
540  getPathParamsVec() const;
541 
561  virtual zypp::url::ParamMap
562  getPathParamsMap(EEncoding eflag) const;
563 
580  virtual std::string
581  getPathParam(const std::string &param, EEncoding eflag) const;
582 
583 
584  // -----------------
594  virtual std::string
595  getQueryString() const;
596 
610  virtual zypp::url::ParamVec
611  getQueryStringVec() const;
612 
631  virtual zypp::url::ParamMap
632  getQueryStringMap(EEncoding eflag) const;
633 
650  virtual std::string
651  getQueryParam(const std::string &param, EEncoding eflag) const;
652 
653 
654  // -----------------
662  virtual std::string
663  getFragment(EEncoding eflag) const;
664 
665 
666  // -----------------
673  virtual void
674  setScheme(const std::string &scheme);
675 
676 
677  // -----------------
691  virtual void
692  setAuthority(const std::string &authority);
693 
703  virtual void
704  setUsername(const std::string &user,
705  EEncoding eflag);
706 
716  virtual void
717  setPassword(const std::string &pass,
718  EEncoding eflag);
719 
740  virtual void
741  setHost(const std::string &host);
742 
750  virtual void
751  setPort(const std::string &port);
752 
753 
754  // -----------------
765  virtual void
766  setPathData(const std::string &pathdata);
767 
775  virtual void
776  setPathName(const std::string &path,
777  EEncoding eflag);
778 
785  virtual void
786  setPathParams(const std::string &params);
787 
794  virtual void
796 
803  virtual void
805 
815  virtual void
816  setPathParam(const std::string &param, const std::string &value);
817 
818 
819  // -----------------
832  virtual void
833  setQueryString(const std::string &querystr);
834 
841  virtual void
843 
850  virtual void
852 
862  virtual void
863  setQueryParam(const std::string &param, const std::string &value);
864 
873  virtual void
874  delQueryParam(const std::string &param);
875 
876 
877  // -----------------
885  virtual void
886  setFragment(const std::string &fragment,
887  EEncoding eflag);
888 
889 
890  // -----------------
946  virtual void
947  configure();
948 
949 
960  std::string
961  config(const std::string &opt) const;
962 
972  void
973  config(const std::string &opt, const std::string &val);
974 
975 
985  getViewOptions() const;
986 
995  void
996  setViewOptions(const ViewOptions &vopts);
997 
998 
999  protected:
1026  virtual std::string
1027  cleanupPathName(const std::string &path, bool authority) const;
1028 
1039  virtual std::string
1040  cleanupPathName(const std::string &path) const;
1041 
1063  virtual bool
1064  isValidHost(const std::string &host) const;
1065 
1072  virtual bool
1073  isValidPort(const std::string &port) const;
1074 
1075  private:
1077  };
1078 
1079 
1080  // ---------------------------------------------------------------
1085 
1086 
1088  } // namespace url
1090 
1092 } // namespace zypp
1094 
1095 #endif /* ZYPP_URL_URLBASE_H */
1096 /*
1097 ** vim: set ts=2 sts=2 sw=2 ai et:
1098 */
bool has(const ViewOption &o) const
Check if specified option o is set in the current object.
Definition: UrlBase.h:228
virtual std::string getQueryParam(const std::string &param, EEncoding eflag) const
Return the value for the specified query parameter.
Definition: UrlBase.cc:799
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
Definition: UrlBase.h:58
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: UrlBase.cc:621
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
static const ViewOption WITH_FRAGMENT
Option to include fragment string in the URL string.
Definition: UrlBase.h:107
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition: UrlUtils.h:47
Internal data used by UrlBase.
Definition: UrlBase.cc:112
virtual std::string getPathParam(const std::string &param, EEncoding eflag) const
Return the value for the specified path parameter.
Definition: UrlBase.cc:744
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: UrlBase.cc:309
virtual void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: UrlBase.cc:1242
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:250
virtual ~UrlBase()
Definition: UrlBase.cc:191
ViewOption()
Create instance with default combination of view options.
Definition: UrlBase.cc:91
friend ViewOption operator+(const ViewOption &l, const ViewOption &r)
Adds l and r to a new option combination.
Definition: UrlBase.h:193
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition: UrlBase.h:243
virtual void setUsername(const std::string &user, EEncoding eflag)
Set the username in the URL authority.
Definition: UrlBase.cc:933
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
Definition: UrlBase.h:51
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
Definition: UrlBase.h:74
virtual void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: UrlBase.cc:864
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition: UrlBase.cc:611
virtual std::string asString() const
Returns a default string representation of the Url object.
Definition: UrlBase.cc:434
virtual std::string getUsername(EEncoding eflag) const
Returns the username from the URL authority.
Definition: UrlBase.cc:640
static const ViewOption EMPTY_FRAGMENT
Explicitely include the fragment string separator &quot;#&quot;.
Definition: UrlBase.h:165
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: UrlBase.cc:1054
ViewOption & operator=(const ViewOption &o)
Assign specified option combination o to the current object.
Definition: UrlBase.h:216
static const ViewOption WITH_PATH_NAME
Option to include path name in the URL string.
Definition: UrlBase.h:87
Url::asString() view options.
Definition: UrlBase.h:39
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: UrlBase.cc:317
virtual void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: UrlBase.cc:834
virtual std::string getScheme() const
Returns the scheme name of the URL.
Definition: UrlBase.cc:576
virtual void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: UrlBase.cc:1001
virtual void setPathParams(const std::string &params)
Set the path parameters.
Definition: UrlBase.cc:1146
UrlBaseData * m_data
Definition: UrlBase.h:1076
virtual void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: UrlBase.cc:1163
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
Definition: UrlBase.cc:906
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
Definition: UrlBase.cc:967
virtual zypp::url::ParamMap getQueryStringMap(EEncoding eflag) const
Returns a string map with query parameter and their values.
Definition: UrlBase.cc:776
virtual void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: UrlBase.cc:1221
virtual void init(const std::string &scheme, const std::string &authority, const std::string &pathdata, const std::string &querystr, const std::string &fragment)
Initializes current object with new URL components.
Definition: UrlBase.cc:228
static const ViewOption EMPTY_QUERY_STR
Explicitely include the query string separator &quot;?&quot;.
Definition: UrlBase.h:154
static const ViewOption EMPTY_AUTHORITY
Explicitely include the URL authority separator &quot;//&quot;.
Definition: UrlBase.h:121
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
Definition: UrlBase.cc:700
static const ViewOption WITH_PATH_PARAMS
Option to include path parameters in the URL string.
Definition: UrlBase.h:95
zypp::Url url
Definition: MediaCurl.cc:193
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: UrlBase.cc:810
virtual bool isValid() const
Verifies the Url.
Definition: UrlBase.cc:402
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: UrlBase.cc:889
virtual std::string getPathParams() const
Returns the encoded path parameters from the URL.
Definition: UrlBase.cc:692
static const ViewOption EMPTY_PATH_PARAMS
Explicitely include the path parameters separator &quot;;&quot;.
Definition: UrlBase.h:143
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: UrlBase.cc:755
virtual void clear()
Clears all data in the object.
Definition: UrlBase.cc:325
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition: UrlBase.cc:1086
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
Definition: UrlBase.h:101
virtual std::string getPort() const
Returns the port number from the URL authority.
Definition: UrlBase.cc:673
static const ViewOption EMPTY_PATH_NAME
Explicitely include the &quot;/&quot; path character.
Definition: UrlBase.h:133
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
Definition: UrlBase.h:67
virtual std::string cleanupPathName(const std::string &path, bool authority) const
Utility method to cleanup an encoded path name.
Definition: UrlBase.cc:1269
friend ViewOption operator-(const ViewOption &l, const ViewOption &r)
Substract r from l to a new option combination.
Definition: UrlBase.h:204
virtual std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: UrlBase.cc:584
virtual zypp::url::ParamMap getPathParamsMap(EEncoding eflag) const
Returns a string map with path parameter keys and values.
Definition: UrlBase.cc:721
virtual void configure()
Configures behaviour of the instance.
Definition: UrlBase.cc:244
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
Definition: UrlBase.cc:662
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
Definition: UrlBase.cc:370
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
Definition: UrlBase.cc:629
virtual std::string getPassword(EEncoding eflag) const
Returns the password from the URL authority.
Definition: UrlBase.cc:651
Generic Url base class.
Definition: UrlBase.h:269
virtual void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: UrlBase.cc:1176
virtual bool isValidHost(const std::string &host) const
Verifies specified host or IP.
Definition: UrlBase.cc:1321
static const ViewOption DEFAULTS
Default combination of view options.
Definition: UrlBase.h:177
virtual std::string getPathName(EEncoding eflag) const
Returns the path name from the URL.
Definition: UrlBase.cc:681
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
Definition: UrlBase.cc:345
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
virtual bool isValidPort(const std::string &port) const
Verifies specified port number.
Definition: UrlBase.cc:1350
static const ViewOption WITH_PORT
Option to include port number in the URL string.
Definition: UrlBase.h:81
virtual void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: UrlBase.cc:1198
virtual void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: UrlBase.cc:1208
virtual bool isKnownScheme(const std::string &scheme) const
Returns if scheme name is known to this object.
Definition: UrlBase.cc:353
virtual UrlBase * clone() const
Returns pointer to a copy of the current object.
Definition: UrlBase.cc:337
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition: UrlBase.h:1084
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition: UrlBase.cc:297
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: UrlBase.cc:1251