libzypp  17.25.8
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  static const ViewOption hotfix1050625;
234  private:
235  ViewOption(int option);
236  int opt;
237  };
238 
239 
240  // ---------------------------------------------------------------
245 
246 
247  // ---------------------------------------------------------------
251  typedef std::vector<std::string> UrlSchemes;
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 
855  virtual void
857 
867  virtual void
868  setQueryParam(const std::string &param, const std::string &value);
869 
878  virtual void
879  delQueryParam(const std::string &param);
880 
881 
882  // -----------------
890  virtual void
891  setFragment(const std::string &fragment,
892  EEncoding eflag);
893 
894 
895  // -----------------
951  virtual void
952  configure();
953 
954 
965  std::string
966  config(const std::string &opt) const;
967 
977  void
978  config(const std::string &opt, const std::string &val);
979 
980 
990  getViewOptions() const;
991 
1000  void
1001  setViewOptions(const ViewOptions &vopts);
1002 
1003  std::string asString1050625() const;
1004  protected:
1031  virtual std::string
1032  cleanupPathName(const std::string &path, bool authority) const;
1033 
1044  virtual std::string
1045  cleanupPathName(const std::string &path) const;
1046 
1068  virtual bool
1069  isValidHost(const std::string &host) const;
1070 
1077  virtual bool
1078  isValidPort(const std::string &port) const;
1079 
1080  private:
1082  };
1083 
1084 
1085  // ---------------------------------------------------------------
1090 
1091 
1093  } // namespace url
1095 
1097 } // namespace zypp
1099 
1100 #endif /* ZYPP_URL_URLBASE_H */
1101 /*
1102 ** vim: set ts=2 sts=2 sw=2 ai et:
1103 */
zypp::url::UrlBase::getPassword
virtual std::string getPassword(EEncoding eflag) const
Returns the password from the URL authority.
Definition: UrlBase.cc:732
zypp::url::UrlBase::config
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition: UrlBase.cc:367
zypp::url::UrlBase::setQueryString
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: UrlBase.cc:970
zypp::url::UrlBase::setPathName
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition: UrlBase.cc:1167
zypp::url::UrlBase::setPathParam
virtual void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: UrlBase.cc:1279
zypp::url::UrlBase::clone
virtual UrlBase * clone() const
Returns pointer to a copy of the current object.
Definition: UrlBase.cc:407
zypp::url::UrlBase::isValid
virtual bool isValid() const
Verifies the Url.
Definition: UrlBase.cc:472
zypp::url::UrlBase::getPathParam
virtual std::string getPathParam(const std::string &param, EEncoding eflag) const
Return the value for the specified path parameter.
Definition: UrlBase.cc:825
zypp::url::ViewOption::hotfix1050625
static const ViewOption hotfix1050625
Definition: UrlBase.h:233
zypp::url::UrlBase::getQueryParam
virtual std::string getQueryParam(const std::string &param, EEncoding eflag) const
Return the value for the specified query parameter.
Definition: UrlBase.cc:880
zypp::url::UrlBase::setPathParamsVec
virtual void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: UrlBase.cc:1244
zypp::url::UrlBase::getPathParams
virtual std::string getPathParams() const
Returns the encoded path parameters from the URL.
Definition: UrlBase.cc:773
zypp::url::UrlBase::setQueryStringMap
virtual void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: UrlBase.cc:1302
UrlUtils.h
zypp::url::UrlBaseData
Internal data used by UrlBase.
Definition: UrlBase.cc:179
zypp::url::ViewOption::operator=
ViewOption & operator=(const ViewOption &o)
Assign specified option combination o to the current object.
Definition: UrlBase.h:216
zypp::url::UrlSchemes
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:251
zypp::url::UrlBase::setAuthority
virtual void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: UrlBase.cc:915
zypp::url::ViewOption::EMPTY_PATH_NAME
static const ViewOption EMPTY_PATH_NAME
Explicitely include the "/" path character.
Definition: UrlBase.h:133
zypp::url::UrlBase::getPort
virtual std::string getPort() const
Returns the port number from the URL authority.
Definition: UrlBase.cc:754
zypp::url::UrlBase::clear
virtual void clear()
Clears all data in the object.
Definition: UrlBase.cc:395
zypp::url::ViewOptions
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition: UrlBase.h:244
zypp::url::ViewOption::WITH_USERNAME
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
Definition: UrlBase.h:58
zypp::url::UrlBase::getKnownSchemes
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
Definition: UrlBase.cc:415
zypp::url::UrlBase::asString1050625
std::string asString1050625() const
Definition: UrlBase.cc:509
zypp::url::ViewOption::WITH_FRAGMENT
static const ViewOption WITH_FRAGMENT
Option to include fragment string in the URL string.
Definition: UrlBase.h:107
PtrTypes.h
zypp::url::UrlBase::getPathData
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition: UrlBase.cc:687
zypp::url::ViewOption::WITH_PATH_NAME
static const ViewOption WITH_PATH_NAME
Option to include path name in the URL string.
Definition: UrlBase.h:87
zypp::url::UrlBase::isKnownScheme
virtual bool isKnownScheme(const std::string &scheme) const
Returns if scheme name is known to this object.
Definition: UrlBase.cc:423
zypp::url::ViewOption::EMPTY_PATH_PARAMS
static const ViewOption EMPTY_PATH_PARAMS
Explicitely include the path parameters separator ";".
Definition: UrlBase.h:143
zypp::url::ViewOption::ViewOption
ViewOption()
Create instance with default combination of view options.
Definition: UrlBase.cc:95
zypp::url::EEncoding
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
zypp::url::UrlBase::asString
virtual std::string asString() const
Returns a default string representation of the Url object.
Definition: UrlBase.cc:504
zypp::url::UrlBase::~UrlBase
virtual ~UrlBase()
Definition: UrlBase.cc:257
zypp::url::ViewOption::EMPTY_QUERY_STR
static const ViewOption EMPTY_QUERY_STR
Explicitely include the query string separator "?".
Definition: UrlBase.h:154
zypp::url::ViewOption::EMPTY_FRAGMENT
static const ViewOption EMPTY_FRAGMENT
Explicitely include the fragment string separator "#".
Definition: UrlBase.h:165
zypp::url::ViewOption::WITH_PASSWORD
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
Definition: UrlBase.h:67
zypp::url::UrlBase::getQueryStringMap
virtual zypp::url::ParamMap getQueryStringMap(EEncoding eflag) const
Returns a string map with query parameter and their values.
Definition: UrlBase.cc:857
zypp::url::UrlBase::getPathName
virtual std::string getPathName(EEncoding eflag) const
Returns the path name from the URL.
Definition: UrlBase.cc:762
zypp::url::UrlBase::configure
virtual void configure()
Configures behaviour of the instance.
Definition: UrlBase.cc:314
zypp::url::ViewOption::DEFAULTS
static const ViewOption DEFAULTS
Default combination of view options.
Definition: UrlBase.h:177
zypp::url::ViewOption::has
bool has(const ViewOption &o) const
Check if specified option o is set in the current object.
Definition: UrlBase.h:228
zypp::url::ViewOption::EMPTY_AUTHORITY
static const ViewOption EMPTY_AUTHORITY
Explicitely include the URL authority separator "//".
Definition: UrlBase.h:121
zypp::url::UrlBase::setUsername
virtual void setUsername(const std::string &user, EEncoding eflag)
Set the username in the URL authority.
Definition: UrlBase.cc:1014
zypp::url::UrlBase::setPathParamsMap
virtual void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: UrlBase.cc:1257
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::url::UrlRef
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition: UrlBase.h:1089
zypp::url::UrlBase::getAuthority
virtual std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: UrlBase.cc:660
zypp::url::UrlBase::setPathData
virtual void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: UrlBase.cc:945
zypp::url::UrlBase::isValidHost
virtual bool isValidHost(const std::string &host) const
Verifies specified host or IP.
Definition: UrlBase.cc:1402
zypp::url::ParamMap
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition: UrlUtils.h:47
zypp::url::UrlBase::UrlBase
UrlBase()
Definition: UrlBase.cc:265
zypp::url::UrlBase::getHost
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
Definition: UrlBase.cc:743
zypp::url::UrlBase::getQueryStringVec
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: UrlBase.cc:836
zypp::url::ViewOption::WITH_QUERY_STR
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
Definition: UrlBase.h:101
zypp::url::UrlBase::init
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:294
zypp::url::UrlBase::setQueryStringVec
virtual void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: UrlBase.cc:1289
zypp::url::UrlBase::isValidScheme
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
Definition: UrlBase.cc:440
zypp::url::ViewOption::operator-
friend ViewOption operator-(const ViewOption &l, const ViewOption &r)
Substract r from l to a new option combination.
Definition: UrlBase.h:204
zypp::url::UrlBase::getPathParamsMap
virtual zypp::url::ParamMap getPathParamsMap(EEncoding eflag) const
Returns a string map with path parameter keys and values.
Definition: UrlBase.cc:802
zypp::url::UrlBase::getScheme
virtual std::string getScheme() const
Returns the scheme name of the URL.
Definition: UrlBase.cc:652
zypp::url::ParamVec
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
zypp::url::UrlBase::setHost
virtual void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: UrlBase.cc:1082
zypp::url::UrlBase::setFragment
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
Definition: UrlBase.cc:987
zypp::url::UrlBase::delQueryParam
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: UrlBase.cc:1332
zypp::url::UrlBase::getPathParamsVec
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
Definition: UrlBase.cc:781
zypp::url::UrlBase::setScheme
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: UrlBase.cc:891
zypp::url::ViewOption::opt
int opt
Definition: UrlBase.h:236
zypp::url::UrlBase
Generic Url base class.
Definition: UrlBase.h:271
zypp::url::UrlBase::getUsername
virtual std::string getUsername(EEncoding eflag) const
Returns the username from the URL authority.
Definition: UrlBase.cc:721
zypp::url::UrlBase::setPathParams
virtual void setPathParams(const std::string &params)
Set the path parameters.
Definition: UrlBase.cc:1227
zypp::url::UrlBase::m_data
UrlBaseData * m_data
Definition: UrlBase.h:1081
zypp::url::UrlBase::setQueryParam
virtual void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: UrlBase.cc:1323
zypp::url::UrlBase::setPort
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: UrlBase.cc:1135
zypp::RWCOW_pointer< UrlBase >
zypp::url::UrlBase::cleanupPathName
virtual std::string cleanupPathName(const std::string &path, bool authority) const
Utility method to cleanup an encoded path name.
Definition: UrlBase.cc:1350
zypp::url::UrlBase::isValidPort
virtual bool isValidPort(const std::string &port) const
Verifies specified port number.
Definition: UrlBase.cc:1431
zypp::url::UrlBase::getQueryString
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: UrlBase.cc:697
zypp::url::ViewOption
Url::asString() view options.
Definition: UrlBase.h:40
zypp::url::UrlBase::getFragment
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
Definition: UrlBase.cc:710
zypp::url::ViewOption::operator+
friend ViewOption operator+(const ViewOption &l, const ViewOption &r)
Adds l and r to a new option combination.
Definition: UrlBase.h:193
url
Url url
Definition: MediaCurl.cc:66
zypp::url::ViewOption::WITH_SCHEME
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
Definition: UrlBase.h:51
zypp::url::ViewOption::WITH_HOST
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
Definition: UrlBase.h:74
zypp::url::UrlBase::setViewOptions
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: UrlBase.cc:387
zypp::url::UrlBase::getViewOptions
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: UrlBase.cc:379
zypp::url::UrlBase::setPassword
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
Definition: UrlBase.cc:1048
zypp::url::ViewOption::WITH_PORT
static const ViewOption WITH_PORT
Option to include port number in the URL string.
Definition: UrlBase.h:81
zypp::url::ViewOption::WITH_PATH_PARAMS
static const ViewOption WITH_PATH_PARAMS
Option to include path parameters in the URL string.
Definition: UrlBase.h:95