libzypp  17.35.15
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-core/url/UrlUtils.h>
17 
18 
20 namespace zypp
21 {
22 
24  namespace url
25  {
26 
27 
28  // ---------------------------------------------------------------
40  {
51  static const ViewOption WITH_SCHEME ZYPP_API;
58  static const ViewOption WITH_USERNAME ZYPP_API;
67  static const ViewOption WITH_PASSWORD ZYPP_API;
74  static const ViewOption WITH_HOST ZYPP_API;
81  static const ViewOption WITH_PORT ZYPP_API;
87  static const ViewOption WITH_PATH_NAME ZYPP_API;
95  static const ViewOption WITH_PATH_PARAMS ZYPP_API;
101  static const ViewOption WITH_QUERY_STR ZYPP_API;
107  static const ViewOption WITH_FRAGMENT ZYPP_API;
121  static const ViewOption EMPTY_AUTHORITY ZYPP_API;
133  static const ViewOption EMPTY_PATH_NAME ZYPP_API;
143  static const ViewOption EMPTY_PATH_PARAMS ZYPP_API;
154  static const ViewOption EMPTY_QUERY_STR ZYPP_API;
165  static const ViewOption EMPTY_FRAGMENT ZYPP_API;
177  static const ViewOption DEFAULTS ZYPP_API;
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 &
216  operator = (const ViewOption &o)
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  static const ViewOption hotfix1050625;
234  private:
235  ViewOption(int option);
236  int opt;
237  };
238 
239 
240  // ---------------------------------------------------------------
245 
246 
247  // ---------------------------------------------------------------
251  using UrlSchemes = std::vector<std::string>;
252 
253 
254  // ---------------------------------------------------------------
258  class UrlBaseData;
259 
260 
261  // ---------------------------------------------------------------
270  class UrlBase
271  {
272  public:
273 
274  virtual
275  ~UrlBase();
276 
277  UrlBase();
278 
283  UrlBase(const UrlBase &url);
284 
299  UrlBase(const std::string &scheme,
300  const std::string &authority,
301  const std::string &pathdata,
302  const std::string &querystr,
303  const std::string &fragment);
304 
305 
306  // -----------------
310  virtual void
311  clear();
312 
324  virtual UrlBase *
325  clone() const;
326 
340  virtual void
341  init(const std::string &scheme,
342  const std::string &authority,
343  const std::string &pathdata,
344  const std::string &querystr,
345  const std::string &fragment);
346 
347 
348  // -----------------
366  virtual UrlSchemes
367  getKnownSchemes() const;
368 
373  virtual bool
374  isKnownScheme(const std::string &scheme) const;
375 
376 
389  virtual bool
390  isValidScheme(const std::string &scheme) const;
391 
401  virtual bool
402  isValid() const;
403 
404 
405  // -----------------
413  virtual std::string
414  asString() const;
415 
428  virtual std::string
429  asString(const zypp::url::ViewOptions &opts) const;
430 
431 
432  // -----------------
437  virtual std::string
438  getScheme() const;
439 
440 
441  // -----------------
451  virtual std::string
452  getAuthority() const;
453 
461  virtual std::string
462  getUsername(EEncoding eflag) const;
463 
471  virtual std::string
472  getPassword(EEncoding eflag) const;
473 
486  virtual std::string
487  getHost(EEncoding eflag) const;
488 
493  virtual std::string
494  getPort() const;
495 
496 
497  // -----------------
507  virtual std::string
508  getPathData() const;
509 
518  virtual std::string
519  getPathName(EEncoding eflag) const;
520 
525  virtual std::string
526  getPathParams() const;
527 
540  virtual zypp::url::ParamVec
541  getPathParamsVec() const;
542 
562  virtual zypp::url::ParamMap
563  getPathParamsMap(EEncoding eflag) const;
564 
581  virtual std::string
582  getPathParam(const std::string &param, EEncoding eflag) const;
583 
584 
585  // -----------------
595  virtual std::string
596  getQueryString() const;
597 
599  virtual std::string
600  getQueryString( const ViewOptions & viewopts_r ) const;
601 
615  virtual zypp::url::ParamVec
616  getQueryStringVec() const;
617 
636  virtual zypp::url::ParamMap
637  getQueryStringMap(EEncoding eflag) const;
638 
655  virtual std::string
656  getQueryParam(const std::string &param, EEncoding eflag) const;
657 
658 
659  // -----------------
667  virtual std::string
668  getFragment(EEncoding eflag) const;
669 
670 
671  // -----------------
678  virtual void
679  setScheme(const std::string &scheme);
680 
681 
682  // -----------------
696  virtual void
697  setAuthority(const std::string &authority);
698 
708  virtual void
709  setUsername(const std::string &user,
710  EEncoding eflag);
711 
721  virtual void
722  setPassword(const std::string &pass,
723  EEncoding eflag);
724 
745  virtual void
746  setHost(const std::string &host);
747 
755  virtual void
756  setPort(const std::string &port);
757 
758 
759  // -----------------
770  virtual void
771  setPathData(const std::string &pathdata);
772 
780  virtual void
781  setPathName(const std::string &path,
782  EEncoding eflag);
783 
790  virtual void
791  setPathParams(const std::string &params);
792 
799  virtual void
801 
808  virtual void
810 
820  virtual void
821  setPathParam(const std::string &param, const std::string &value);
822 
823 
824  // -----------------
837  virtual void
838  setQueryString(const std::string &querystr);
839 
846  virtual void
848 
856  virtual void
857  setQueryStringMap(const zypp::url::ParamMap &qmap, EEncoding eflag);
858 
868  virtual void
869  setQueryParam(const std::string &param, const std::string &value);
870 
879  virtual void
880  delQueryParam(const std::string &param);
881 
882 
883  // -----------------
891  virtual void
892  setFragment(const std::string &fragment,
893  EEncoding eflag);
894 
895 
896  // -----------------
952  virtual void
953  configure();
954 
955 
966  std::string
967  config(const std::string &opt) const;
968 
978  void
979  config(const std::string &opt, const std::string &val);
980 
981 
991  getViewOptions() const;
992 
1001  void
1002  setViewOptions(const ViewOptions &vopts);
1003 
1004  std::string asString1050625() const;
1005  protected:
1032  virtual std::string
1033  cleanupPathName(const std::string &path, bool authority) const;
1034 
1045  virtual std::string
1046  cleanupPathName(const std::string &path) const;
1047 
1069  virtual bool
1070  isValidHost(const std::string &host) const;
1071 
1078  virtual bool
1079  isValidPort(const std::string &port) const;
1080 
1081  private:
1083  };
1084 
1085 
1086  // ---------------------------------------------------------------
1091 
1092 
1094  } // namespace url
1096 
1098 } // namespace zypp
1100 
1101 #endif /* ZYPP_URL_URLBASE_H */
1102 /*
1103 ** vim: set ts=2 sts=2 sw=2 ai et:
1104 */
static const ViewOption WITH_USERNAME ZYPP_API
Option to include username in the URL string.
Definition: UrlBase.h:58
virtual std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: UrlBase.cc:661
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: UrlBase.cc:698
static const ViewOption EMPTY_QUERY_STR ZYPP_API
Explicitely include the query string separator "?".
Definition: UrlBase.h:154
static const ViewOption WITH_PATH_NAME ZYPP_API
Option to include path name in the URL string.
Definition: UrlBase.h:87
Internal data used by UrlBase.
Definition: UrlBase.cc:179
static const ViewOption EMPTY_FRAGMENT ZYPP_API
Explicitely include the fragment string separator "#".
Definition: UrlBase.h:165
virtual void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: UrlBase.cc:1324
virtual zypp::url::ParamMap getQueryStringMap(EEncoding eflag) const
Returns a string map with query parameter and their values.
Definition: UrlBase.cc:858
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
Definition: UrlBase.cc:416
std::string asString1050625() const
Definition: UrlBase.cc:510
virtual ~UrlBase()
Definition: UrlBase.cc:258
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition: UrlUtils.h:47
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
Definition: UrlBase.cc:782
static const ViewOption EMPTY_PATH_PARAMS ZYPP_API
Explicitely include the path parameters separator ";".
Definition: UrlBase.h:143
virtual void setUsername(const std::string &user, EEncoding eflag)
Set the username in the URL authority.
Definition: UrlBase.cc:1013
virtual std::string getPathName(EEncoding eflag) const
Returns the path name from the URL.
Definition: UrlBase.cc:763
virtual void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: UrlBase.cc:944
static const ViewOption WITH_PATH_PARAMS ZYPP_API
Option to include path parameters in the URL string.
Definition: UrlBase.h:95
static const ViewOption WITH_QUERY_STR ZYPP_API
Option to include query string in the URL string.
Definition: UrlBase.h:101
static const ViewOption EMPTY_PATH_NAME ZYPP_API
Explicitely include the "/" path character.
Definition: UrlBase.h:133
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: UrlBase.cc:1134
static const ViewOption hotfix1050625
Definition: UrlBase.h:233
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
Url::asString() view options.
Definition: UrlBase.h:39
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: UrlBase.cc:388
virtual void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: UrlBase.cc:916
virtual void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: UrlBase.cc:1081
virtual void setPathParams(const std::string &params)
Set the path parameters.
Definition: UrlBase.cc:1226
UrlBaseData * m_data
Definition: UrlBase.h:1082
virtual std::string getPassword(EEncoding eflag) const
Returns the password from the URL authority.
Definition: UrlBase.cc:733
virtual void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: UrlBase.cc:1243
virtual std::string getQueryParam(const std::string &param, EEncoding eflag) const
Return the value for the specified query parameter.
Definition: UrlBase.cc:881
static const ViewOption DEFAULTS ZYPP_API
Default combination of view options.
Definition: UrlBase.h:177
virtual std::string getPathParam(const std::string &param, EEncoding eflag) const
Return the value for the specified path parameter.
Definition: UrlBase.cc:826
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
Definition: UrlBase.cc:986
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
Definition: UrlBase.cc:1047
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
Definition: UrlBase.cc:744
string operator+(const string &lhs, const std::string &rhs)
Definition: Utf8.h:176
virtual std::string getPathParams() const
Returns the encoded path parameters from the URL.
Definition: UrlBase.cc:774
virtual std::string getPort() const
Returns the port number from the URL authority.
Definition: UrlBase.cc:755
static const ViewOption WITH_PORT ZYPP_API
Option to include port number in the URL string.
Definition: UrlBase.h:81
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
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:295
static const ViewOption WITH_PASSWORD ZYPP_API
Option to include password in the URL string.
Definition: UrlBase.h:67
static const ViewOption EMPTY_AUTHORITY ZYPP_API
Explicitely include the URL authority separator "//".
Definition: UrlBase.h:121
virtual UrlBase * clone() const
Returns pointer to a copy of the current object.
Definition: UrlBase.cc:408
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: UrlBase.cc:380
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
Definition: UrlBase.cc:711
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: UrlBase.cc:892
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: UrlBase.cc:969
virtual bool isKnownScheme(const std::string &scheme) const
Returns if scheme name is known to this object.
Definition: UrlBase.cc:424
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:251
virtual std::string cleanupPathName(const std::string &path, bool authority) const
Utility method to cleanup an encoded path name.
Definition: UrlBase.cc:1371
bool has(const ViewOption &o) const
Check if specified option o is set in the current object.
Definition: UrlBase.h:228
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition: UrlBase.cc:368
virtual void clear()
Clears all data in the object.
Definition: UrlBase.cc:396
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition: UrlBase.cc:1166
static const ViewOption WITH_HOST ZYPP_API
Option to include hostname in the URL string.
Definition: UrlBase.h:74
virtual bool isValidPort(const std::string &port) const
Verifies specified port number.
Definition: UrlBase.cc:1452
virtual void configure()
Configures behaviour of the instance.
Definition: UrlBase.cc:315
Generic Url base class.
Definition: UrlBase.h:270
virtual void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: UrlBase.cc:1256
virtual zypp::url::ParamMap getPathParamsMap(EEncoding eflag) const
Returns a string map with path parameter keys and values.
Definition: UrlBase.cc:803
static const ViewOption WITH_FRAGMENT ZYPP_API
Option to include fragment string in the URL string.
Definition: UrlBase.h:107
virtual bool isValidHost(const std::string &host) const
Verifies specified host or IP.
Definition: UrlBase.cc:1423
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: UrlBase.cc:837
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition: UrlBase.cc:688
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
virtual void setQueryStringMap(const zypp::url::ParamMap &qmap, EEncoding eflag)
Set the query parameters.
Definition: UrlBase.cc:1302
virtual void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: UrlBase.cc:1279
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
Definition: UrlBase.cc:441
static const ViewOption WITH_SCHEME ZYPP_API
Option to include scheme name in the URL string.
Definition: UrlBase.h:51
virtual void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: UrlBase.cc:1289
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
virtual bool isValid() const
Verifies the Url.
Definition: UrlBase.cc:473
virtual std::string asString() const
Returns a default string representation of the Url object.
Definition: UrlBase.cc:505
virtual std::string getUsername(EEncoding eflag) const
Returns the username from the URL authority.
Definition: UrlBase.cc:722
virtual std::string getScheme() const
Returns the scheme name of the URL.
Definition: UrlBase.cc:653
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: UrlBase.cc:1348