libzypp  17.14.0
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/url/UrlBase.h"
16 #include "zypp/url/UrlUtils.h"
17 
18 
20 namespace zypp
21 {
22 
23  namespace filesystem {
24  class Pathname;
25  }
26  using filesystem::Pathname;
27 
87  class Url
88  {
89  public:
94 
99 
100 
101  ~Url();
102  Url();
103 
114  Url(const Url &url);
115 
116 
127  Url(const zypp::url::UrlRef &url);
128 
129 
143  Url(const std::string &encodedUrl);
144 
145 
146  // -----------------
163  static url::UrlRef
164  parseUrl(const std::string &encodedUrl);
165 
166 
167  // -----------------
182  Url&
183  operator = (const std::string &encodedUrl);
184 
185 
196  Url&
197  operator = (const Url &url);
198 
199 
200  // -----------------
208  static bool
209  registerScheme(const std::string &scheme,
210  url::UrlRef urlImpl);
211 
216  static zypp::url::UrlSchemes
218 
223  static bool
224  isRegisteredScheme(const std::string &scheme);
225 
226 
227  // -----------------
233  getKnownSchemes() const;
234 
235 
250  bool
251  isValidScheme(const std::string &scheme) const;
252 
253 
255  static bool schemeIsLocal( const std::string & scheme_r );
257  bool schemeIsLocal() const { return schemeIsLocal( getScheme() ); }
258 
260  static bool schemeIsRemote( const std::string & scheme_r );
262  bool schemeIsRemote() const { return schemeIsRemote( getScheme() ); }
263 
265  static bool schemeIsVolatile( const std::string & scheme_r );
267  bool schemeIsVolatile() const { return schemeIsVolatile( getScheme() ); }
268 
270  static bool schemeIsDownloading( const std::string & scheme_r );
272  bool schemeIsDownloading() const { return schemeIsDownloading( getScheme() ); }
273 
283  bool
284  isValid() const;
285 
286 
287  // -----------------
295  std::string
296  asString() const;
297 
310  std::string
311  asString(const ViewOptions &opts) const;
312 
322  std::string
323  asCompleteString() const;
324 
325 
326  // -----------------
331  std::string
332  getScheme() const;
333 
334 
335  // -----------------
345  std::string
346  getAuthority() const;
347 
355  std::string
357 
365  std::string
367 
372  { return ! ( getUsername().empty() || getPassword().empty() ); }
373 
386  std::string
387  getHost(EEncoding eflag = zypp::url::E_DECODED) const;
388 
393  std::string
394  getPort() const;
395 
396 
397  // -----------------
407  std::string
408  getPathData() const;
409 
418  std::string
420 
425  std::string
426  getPathParams() const;
427 
441  getPathParamsVec() const;
442 
464 
481  std::string
482  getPathParam(const std::string &param,
483  EEncoding eflag = zypp::url::E_DECODED) const;
484 
485 
486  // -----------------
496  std::string
497  getQueryString() const;
498 
513  getQueryStringVec() const;
514 
535 
552  std::string
553  getQueryParam(const std::string &param,
554  EEncoding eflag = zypp::url::E_DECODED) const;
555 
556 
557  // -----------------
565  std::string
567 
568 
569  // -----------------
576  void
577  setScheme(const std::string &scheme);
578 
579 
580  // -----------------
594  void
595  setAuthority(const std::string &authority);
596 
606  void
607  setUsername(const std::string &user,
609 
619  void
620  setPassword(const std::string &pass,
622 
643  void
644  setHost(const std::string &host);
645 
653  void
654  setPort(const std::string &port);
655 
656 
657  // -----------------
668  void
669  setPathData(const std::string &pathdata);
670 
678  void
679  setPathName(const std::string &path,
682  void
683  setPathName(const Pathname &path,
686  void
687  setPathName(const char *path,
689 
693  void appendPathName( const Pathname & path_r, EEncoding eflag_r = zypp::url::E_DECODED );
694 
701  void
702  setPathParams(const std::string &params);
703 
710  void
712 
719  void
721 
731  void
732  setPathParam(const std::string &param, const std::string &value);
733 
734 
735  // -----------------
742  void
743  setQueryString(const std::string &querystr);
744 
751  void
753 
760  void
762 
772  void
773  setQueryParam(const std::string &param, const std::string &value);
774 
783  void
784  delQueryParam(const std::string &param);
785 
786 
787  // -----------------
795  void
796  setFragment(const std::string &fragment,
798 
799 
800  // -----------------
810  getViewOptions() const;
811 
820  void
821  setViewOptions(const ViewOptions &vopts);
822 
823  private:
825  };
826 
827  std::ostream & operator<<( std::ostream & str, const Url & url );
828 
832  bool operator<( const Url &lhs, const Url &rhs );
833 
837  bool operator==( const Url &lhs, const Url &rhs );
838 
839 
840  bool operator!=( const Url &lhs, const Url &rhs );
841 
843 } // namespace zypp
845 
846 #endif /* ZYPP_URL_H */
847 /*
848 ** vim: set ts=2 sts=2 sw=2 ai et:
849 */
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:528
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition: Url.cc:734
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: Url.cc:639
std::vector< std::string > ParamVec
A parameter vector container.
Definition: UrlUtils.h:40
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition: UrlUtils.h:47
void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: Url.cc:810
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:833
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:250
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: Url.cc:854
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
Definition: Url.cc:415
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition: Url.cc:781
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition: Url.cc:559
String related utilities and Regular expression matching.
void setPathParams(const std::string &params)
Set the path parameters.
Definition: Url.cc:786
bool hasCredentialsInAuthority() const
Returns true if username and password are encoded in the authority component.
Definition: Url.h:371
void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: Url.cc:751
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition: Url.cc:615
Url url
Definition: MediaCurl.cc:180
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
Definition: Url.cc:725
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: Url.cc:743
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
Definition: Url.cc:647
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
Definition: Url.cc:361
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: Url.cc:818
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:717
void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: Url.cc:693
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: Url.cc:847
zypp::url::EEncoding EEncoding
Encoding flags.
Definition: Url.h:93
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:759
std::string getPathData() const
Returns the encoded path component of the URL.
Definition: Url.cc:543
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
Definition: Url.cc:432
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:492
std::string getPathParams() const
Returns the path parameters from the URL.
Definition: Url.cc:607
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
Definition: Url.cc:424
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:655
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: Url.cc:663
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
Definition: Url.cc:371
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:500
bool schemeIsVolatile() const
Definition: Url.h:267
std::string getPort() const
Returns the port from the URL authority.
Definition: Url.cc:591
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: Url.cc:701
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
Definition: Url.cc:335
Url()
Definition: Url.cc:288
zypp::url::ParamMap getPathParamsMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with path parameter keys and values.
Definition: Url.cc:623
bool isValid() const
Verifies the Url.
Definition: Url.cc:484
std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: Url.cc:536
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
zypp::url::ViewOptions ViewOptions
View options.
Definition: Url.h:98
bool schemeIsRemote() const
Definition: Url.h:262
bool schemeIsDownloading() const
Definition: Url.h:272
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: Url.cc:709
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition: Url.cc:440
~Url()
Definition: Url.cc:282
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:599
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:583
url::UrlRef m_impl
Definition: Url.h:824
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:631
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:335
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: Url.cc:794
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: Url.cc:802
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: Url.cc:826
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition: Url.cc:575
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: Url.cc:551
Url manipulation class.
Definition: Url.h:87
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: Url.cc:840
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:567
Flag to request decoded string(s).
Definition: UrlUtils.h:54
bool schemeIsLocal() const
Definition: Url.h:257