libzypp  17.36.3
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 <set>
16 #include <zypp-core/url/UrlUtils.h>
18 
19 
21 namespace zypp
22 {
23 
25  namespace url
26  {
27 
28 
29  // ---------------------------------------------------------------
41  {
52  static const ViewOption WITH_SCHEME ZYPP_API;
59  static const ViewOption WITH_USERNAME ZYPP_API;
68  static const ViewOption WITH_PASSWORD ZYPP_API;
75  static const ViewOption WITH_HOST ZYPP_API;
82  static const ViewOption WITH_PORT ZYPP_API;
88  static const ViewOption WITH_PATH_NAME ZYPP_API;
96  static const ViewOption WITH_PATH_PARAMS ZYPP_API;
102  static const ViewOption WITH_QUERY_STR ZYPP_API;
108  static const ViewOption WITH_FRAGMENT ZYPP_API;
122  static const ViewOption EMPTY_AUTHORITY ZYPP_API;
134  static const ViewOption EMPTY_PATH_NAME ZYPP_API;
144  static const ViewOption EMPTY_PATH_PARAMS ZYPP_API;
155  static const ViewOption EMPTY_QUERY_STR ZYPP_API;
166  static const ViewOption EMPTY_FRAGMENT ZYPP_API;
178  static const ViewOption DEFAULTS ZYPP_API;
185  ViewOption();
186 
187 
193  friend inline ViewOption
194  operator + (const ViewOption &l, const ViewOption &r)
195  {
196  return ViewOption(l.opt | r.opt);
197  }
198 
204  friend inline ViewOption
205  operator - (const ViewOption &l, const ViewOption &r)
206  {
207  return ViewOption(l.opt & ~r.opt);
208  }
209 
216  inline ViewOption &
217  operator = (const ViewOption &o)
218  {
219  opt = o.opt; return *this;
220  }
221 
228  inline bool
229  has(const ViewOption &o) const
230  {
231  return o.opt & opt;
232  }
233 
234  static const ViewOption hotfix1050625;
235  private:
236  ViewOption(int option);
237  int opt;
238  };
239 
240 
241  // ---------------------------------------------------------------
246 
247 
248  // ---------------------------------------------------------------
252  using UrlSchemes = std::vector<std::string>;
253 
254 
255  // ---------------------------------------------------------------
259  class UrlBaseData;
260 
261 
262  // ---------------------------------------------------------------
271  class UrlBase
272  {
273  public:
274 
275  virtual
276  ~UrlBase();
277 
278  UrlBase();
279 
284  UrlBase(const UrlBase &url);
285 
300  UrlBase(const std::string &scheme,
301  const std::string &authority,
302  const std::string &pathdata,
303  const std::string &querystr,
304  const std::string &fragment);
305 
306 
307  // -----------------
311  virtual void
312  clear();
313 
325  virtual UrlBase *
326  clone() const;
327 
341  virtual void
342  init(const std::string &scheme,
343  const std::string &authority,
344  const std::string &pathdata,
345  const std::string &querystr,
346  const std::string &fragment);
347 
348 
349  // -----------------
367  virtual UrlSchemes
368  getKnownSchemes() const;
369 
374  virtual bool
375  isKnownScheme(const std::string &scheme) const;
376 
377 
390  virtual bool
391  isValidScheme(const std::string &scheme) const;
392 
402  virtual bool
403  isValid() const;
404 
405 
406  // -----------------
414  virtual std::string
415  asString() const;
416 
429  virtual std::string
430  asString(const zypp::url::ViewOptions &opts) const;
431 
432 
433  // -----------------
438  virtual std::string
439  getScheme() const;
440 
441 
442  // -----------------
452  virtual std::string
453  getAuthority() const;
454 
462  virtual std::string
463  getUsername(EEncoding eflag) const;
464 
472  virtual std::string
473  getPassword(EEncoding eflag) const;
474 
487  virtual std::string
488  getHost(EEncoding eflag) const;
489 
494  virtual std::string
495  getPort() const;
496 
497 
498  // -----------------
508  virtual std::string
509  getPathData() const;
510 
519  virtual std::string
520  getPathName(EEncoding eflag) const;
521 
526  virtual std::string
527  getPathParams() const;
528 
541  virtual zypp::url::ParamVec
542  getPathParamsVec() const;
543 
563  virtual zypp::url::ParamMap
564  getPathParamsMap(EEncoding eflag) const;
565 
582  virtual std::string
583  getPathParam(const std::string &param, EEncoding eflag) const;
584 
585 
586  // -----------------
596  virtual std::string
597  getQueryString() const;
598 
600  virtual std::string
601  getQueryString( const ViewOptions & viewopts_r ) const;
602 
616  virtual zypp::url::ParamVec
617  getQueryStringVec() const;
618 
637  virtual zypp::url::ParamMap
638  getQueryStringMap(EEncoding eflag) const;
639 
656  virtual std::string
657  getQueryParam(const std::string &param, EEncoding eflag) const;
658 
659 
660  // -----------------
668  virtual std::string
669  getFragment(EEncoding eflag) const;
670 
671 
672  // -----------------
679  virtual void
680  setScheme(const std::string &scheme);
681 
682 
683  // -----------------
697  virtual void
698  setAuthority(const std::string &authority);
699 
709  virtual void
710  setUsername(const std::string &user,
711  EEncoding eflag);
712 
722  virtual void
723  setPassword(const std::string &pass,
724  EEncoding eflag);
725 
746  virtual void
747  setHost(const std::string &host);
748 
756  virtual void
757  setPort(const std::string &port);
758 
759 
760  // -----------------
771  virtual void
772  setPathData(const std::string &pathdata);
773 
781  virtual void
782  setPathName(const std::string &path,
783  EEncoding eflag);
784 
791  virtual void
792  setPathParams(const std::string &params);
793 
800  virtual void
802 
809  virtual void
811 
821  virtual void
822  setPathParam(const std::string &param, const std::string &value);
823 
824 
825  // -----------------
838  virtual void
839  setQueryString(const std::string &querystr);
840 
847  virtual void
849 
857  virtual void
858  setQueryStringMap(const zypp::url::ParamMap &qmap, EEncoding eflag);
859 
869  virtual void
870  setQueryParam(const std::string &param, const std::string &value);
871 
880  virtual void
881  delQueryParam(const std::string &param);
882 
883  void
884  delQueryParams(const std::set<std::string> &params);
885 
886  // -----------------
894  virtual void
895  setFragment(const std::string &fragment,
896  EEncoding eflag);
897 
898 
899  // -----------------
955  virtual void
956  configure();
957 
958 
969  std::string
970  config(const std::string &opt) const;
971 
981  void
982  config(const std::string &opt, const std::string &val);
983 
984 
994  getViewOptions() const;
995 
1004  void
1005  setViewOptions(const ViewOptions &vopts);
1006 
1007  std::string asString1050625() const;
1008  protected:
1035  virtual std::string
1036  cleanupPathName(const std::string &path, bool authority) const;
1037 
1048  virtual std::string
1049  cleanupPathName(const std::string &path) const;
1050 
1072  virtual bool
1073  isValidHost(const std::string &host) const;
1074 
1081  virtual bool
1082  isValidPort(const std::string &port) const;
1083 
1084  private:
1086  };
1087 
1088 
1089  // ---------------------------------------------------------------
1094 
1095 
1097  } // namespace url
1099 
1101 } // namespace zypp
1103 
1104 #endif /* ZYPP_URL_URLBASE_H */
1105 /*
1106 ** vim: set ts=2 sts=2 sw=2 ai et:
1107 */
static const ViewOption WITH_USERNAME ZYPP_API
Option to include username in the URL string.
Definition: UrlBase.h:59
void delQueryParams(const std::set< std::string > &params)
Definition: UrlBase.cc:1364
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:155
static const ViewOption WITH_PATH_NAME ZYPP_API
Option to include path name in the URL string.
Definition: UrlBase.h:88
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:166
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:144
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:96
static const ViewOption WITH_QUERY_STR ZYPP_API
Option to include query string in the URL string.
Definition: UrlBase.h:102
static const ViewOption EMPTY_PATH_NAME ZYPP_API
Explicitely include the "/" path character.
Definition: UrlBase.h:134
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:234
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
Url::asString() view options.
Definition: UrlBase.h:40
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:1085
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:178
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:82
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:68
static const ViewOption EMPTY_AUTHORITY ZYPP_API
Explicitely include the URL authority separator "//".
Definition: UrlBase.h:122
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:252
virtual std::string cleanupPathName(const std::string &path, bool authority) const
Utility method to cleanup an encoded path name.
Definition: UrlBase.cc:1389
bool has(const ViewOption &o) const
Check if specified option o is set in the current object.
Definition: UrlBase.h:229
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:75
virtual bool isValidPort(const std::string &port) const
Verifies specified port number.
Definition: UrlBase.cc:1470
virtual void configure()
Configures behaviour of the instance.
Definition: UrlBase.cc:315
Generic Url base class.
Definition: UrlBase.h:271
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:108
virtual bool isValidHost(const std::string &host) const
Verifies specified host or IP.
Definition: UrlBase.cc:1441
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:52
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