libzypp  17.32.4
Url.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_URL_H
13 #define ZYPP_URL_H
14 
15 #include <zypp-core/url/UrlBase.h>
16 #include <zypp-core/url/UrlUtils.h>
17 
18 
20 namespace zypp
21 {
22 
23  class Url;
24  namespace hotfix1050625 {
25  std::string asString( const Url & url_r );
26  }
27  namespace filesystem {
28  class Pathname;
29  }
30  using filesystem::Pathname;
31 
91  class Url
92  {
93  public:
98 
103 
104 
105  ~Url();
106  Url();
107 
118  Url(const Url &url);
119 
120 
131  Url(zypp::url::UrlRef url);
132 
133 
147  Url(const std::string &encodedUrl);
148 
149 
153  Url(Url &&other) = default;
154 
155 
156  // -----------------
173  static url::UrlRef
174  parseUrl(const std::string &encodedUrl);
175 
176 
177  // -----------------
192  Url&
193  operator = (const std::string &encodedUrl);
194 
195 
206  Url&
207  operator = (const Url &url);
208 
209 
213  Url &operator=(Url &&other) = default;
214 
215 
216  // -----------------
224  static bool
225  registerScheme(const std::string &scheme,
226  url::UrlRef urlImpl);
227 
232  static zypp::url::UrlSchemes
234 
239  static bool
240  isRegisteredScheme(const std::string &scheme);
241 
242 
243  // -----------------
249  getKnownSchemes() const;
250 
251 
266  bool
267  isValidScheme(const std::string &scheme) const;
268 
269 
271  static bool schemeIsLocal( const std::string & scheme_r );
273  bool schemeIsLocal() const { return schemeIsLocal( getScheme() ); }
274 
276  static bool schemeIsRemote( const std::string & scheme_r );
278  bool schemeIsRemote() const { return schemeIsRemote( getScheme() ); }
279 
281  static bool schemeIsVolatile( const std::string & scheme_r );
283  bool schemeIsVolatile() const { return schemeIsVolatile( getScheme() ); }
284 
286  static bool schemeIsDownloading( const std::string & scheme_r );
288  bool schemeIsDownloading() const { return schemeIsDownloading( getScheme() ); }
289 
291  static bool schemeIsPlugin( const std::string & scheme_r );
293  bool schemeIsPlugin() const { return schemeIsPlugin( getScheme() ); }
294 
304  bool
305  isValid() const;
306 
307 
308  // -----------------
316  std::string
317  asString() const;
318 
331  std::string
332  asString(const ViewOptions &opts) const;
333 
343  std::string
344  asCompleteString() const;
345 
346 
347  // -----------------
352  std::string
353  getScheme() const;
354 
355 
356  // -----------------
366  std::string
367  getAuthority() const;
368 
376  std::string
378 
386  std::string
388 
393  { return ! ( getUsername().empty() || getPassword().empty() ); }
394 
407  std::string
408  getHost(EEncoding eflag = zypp::url::E_DECODED) const;
409 
414  std::string
415  getPort() const;
416 
417 
418  // -----------------
428  std::string
429  getPathData() const;
430 
439  std::string
441 
446  std::string
447  getPathParams() const;
448 
462  getPathParamsVec() const;
463 
485 
502  std::string
503  getPathParam(const std::string &param,
504  EEncoding eflag = zypp::url::E_DECODED) const;
505 
506 
507  // -----------------
517  std::string
518  getQueryString() const;
519 
534  getQueryStringVec() const;
535 
556 
573  std::string
574  getQueryParam(const std::string &param,
575  EEncoding eflag = zypp::url::E_DECODED) const;
576 
577 
578  // -----------------
586  std::string
588 
589 
590  // -----------------
597  void
598  setScheme(const std::string &scheme);
599 
600 
601  // -----------------
615  void
616  setAuthority(const std::string &authority);
617 
627  void
628  setUsername(const std::string &user,
630 
640  void
641  setPassword(const std::string &pass,
643 
664  void
665  setHost(const std::string &host);
666 
674  void
675  setPort(const std::string &port);
676 
677 
678  // -----------------
689  void
690  setPathData(const std::string &pathdata);
691 
699  void
700  setPathName(const std::string &path,
703  void
704  setPathName(const Pathname &path,
707  void
708  setPathName(const char *path,
710 
714  void appendPathName( const Pathname & path_r, EEncoding eflag_r = zypp::url::E_DECODED );
715 
722  void
723  setPathParams(const std::string &params);
724 
731  void
733 
740  void
742 
752  void
753  setPathParam(const std::string &param, const std::string &value);
754 
755 
756  // -----------------
763  void
764  setQueryString(const std::string &querystr);
765 
772  void
774 
781  void
783 
793  void
794  setQueryParam(const std::string &param, const std::string &value);
795 
804  void
805  delQueryParam(const std::string &param);
806 
807 
808  // -----------------
816  void
817  setFragment(const std::string &fragment,
819 
820 
821  // -----------------
831  getViewOptions() const;
832 
841  void
842  setViewOptions(const ViewOptions &vopts);
843 
844  private:
845  friend std::string hotfix1050625::asString( const Url & url_r );
847  };
848 
849  std::ostream & operator<<( std::ostream & str, const Url & url );
850 
854  bool operator<( const Url &lhs, const Url &rhs );
855 
859  bool operator==( const Url &lhs, const Url &rhs );
860 
861 
862  bool operator!=( const Url &lhs, const Url &rhs );
863 
865 } // namespace zypp
867 
868 #endif /* ZYPP_URL_H */
869 /*
870 ** vim: set ts=2 sts=2 sw=2 ai et:
871 */
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:537
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition: Url.cc:743
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: Url.cc:648
constexpr std::string_view Url("url")
void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: Url.cc:819
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:842
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition: UrlUtils.h:47
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: Url.cc:863
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
Definition: Url.cc:419
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition: Url.cc:790
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition: Url.cc:568
String related utilities and Regular expression matching.
void setPathParams(const std::string &params)
Set the path parameters.
Definition: Url.cc:795
bool hasCredentialsInAuthority() const
Returns true if username and password are encoded in the authority component.
Definition: Url.h:392
void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: Url.cc:760
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition: Url.cc:624
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
Definition: Url.cc:734
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: Url.cc:752
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
Definition: Url.cc:656
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
Definition: Url.cc:365
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: Url.cc:827
Url::asString() view options.
Definition: UrlBase.h:39
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
Definition: Url.cc:726
void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: Url.cc:702
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: Url.cc:856
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition: UrlBase.h:244
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:768
std::string getPathData() const
Returns the encoded path component of the URL.
Definition: Url.cc:552
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
Definition: Url.cc:436
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:501
std::string getPathParams() const
Returns the path parameters from the URL.
Definition: Url.cc:616
bool schemeIsPlugin() const
Definition: Url.h:293
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
Definition: Url.cc:428
std::string getQueryParam(const std::string &param, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
Definition: Url.cc:664
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: Url.cc:672
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
Definition: Url.cc:375
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:509
bool schemeIsVolatile() const
Definition: Url.h:283
std::string getPort() const
Returns the port from the URL authority.
Definition: Url.cc:600
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: Url.cc:710
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
Definition: Url.cc:339
std::string asString(const Url &url_r)
Definition: Url.cc:890
Url()
Definition: Url.cc:292
zypp::url::ParamMap getPathParamsMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with path parameter keys and values.
Definition: Url.cc:632
bool isValid() const
Verifies the Url.
Definition: Url.cc:493
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:251
std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: Url.cc:545
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
bool schemeIsRemote() const
Definition: Url.h:278
bool schemeIsDownloading() const
Definition: Url.h:288
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: Url.cc:718
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition: Url.cc:444
~Url()
Definition: Url.cc:286
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:608
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:592
url::UrlRef m_impl
Definition: Url.h:846
std::string getPathParam(const std::string &param, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified path parameter.
Definition: Url.cc:640
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:340
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: Url.cc:803
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: Url.cc:811
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: Url.cc:835
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition: Url.cc:584
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: Url.cc:560
Url manipulation class.
Definition: Url.h:91
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: Url.cc:849
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:576
Flag to request decoded string(s).
Definition: UrlUtils.h:54
bool schemeIsLocal() const
Definition: Url.h:273