libzypp  15.28.6
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 
696  void
697  setPathParams(const std::string &params);
698 
705  void
707 
714  void
716 
726  void
727  setPathParam(const std::string &param, const std::string &value);
728 
729 
730  // -----------------
737  void
738  setQueryString(const std::string &querystr);
739 
746  void
748 
755  void
757 
767  void
768  setQueryParam(const std::string &param, const std::string &value);
769 
778  void
779  delQueryParam(const std::string &param);
780 
781 
782  // -----------------
790  void
791  setFragment(const std::string &fragment,
793 
794 
795  // -----------------
805  getViewOptions() const;
806 
815  void
816  setViewOptions(const ViewOptions &vopts);
817 
818  private:
820  };
821 
822  std::ostream & operator<<( std::ostream & str, const Url & url );
823 
827  bool operator<( const Url &lhs, const Url &rhs );
828 
832  bool operator==( const Url &lhs, const Url &rhs );
833 
834 
835  bool operator!=( const Url &lhs, const Url &rhs );
836 
838 } // namespace zypp
840 
841 #endif /* ZYPP_URL_H */
842 /*
843 ** vim: set ts=2 sts=2 sw=2 ai et:
844 */
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition: Url.cc:733
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:804
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:827
std::string getPathData() const
Returns the encoded path component of the URL.
Definition: Url.cc:542
bool schemeIsDownloading() const
Definition: Url.h:272
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition: UrlBase.h:250
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: Url.cc:841
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition: Url.cc:848
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
Definition: Url.cc:414
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:598
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:582
bool schemeIsVolatile() const
Definition: Url.h:267
bool schemeIsRemote() const
Definition: Url.h:262
void setPathParams(const std::string &params)
Set the path parameters.
Definition: Url.cc:780
void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: Url.cc:750
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:566
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:724
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: Url.cc:742
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
Definition: Url.cc:360
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
bool isValid() const
Verifies the Url.
Definition: Url.cc:483
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition: Url.cc:812
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:716
void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: Url.cc:692
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:630
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:491
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:758
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
Definition: Url.cc:431
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
Definition: Url.cc:646
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
Definition: Url.cc:423
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:499
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:120
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: Url.cc:662
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: Url.cc:638
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
Definition: Url.cc:370
bool schemeIsLocal() const
Definition: Url.h:257
std::string getPathParams() const
Returns the path parameters from the URL.
Definition: Url.cc:606
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: Url.cc:700
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
Definition: Url.cc:334
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: Url.cc:550
Url()
Definition: Url.cc:287
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:654
zypp::url::ParamMap getPathParamsMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with path parameter keys and values.
Definition: Url.cc:622
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition: Url.cc:558
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
zypp::url::ViewOptions ViewOptions
View options.
Definition: Url.h:98
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: Url.cc:708
std::string getPort() const
Returns the port from the URL authority.
Definition: Url.cc:590
~Url()
Definition: Url.cc:281
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition: Url.cc:614
std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: Url.cc:535
url::UrlRef m_impl
Definition: Url.h:819
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:527
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:316
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition: Url.cc:439
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: Url.cc:788
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: Url.cc:796
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: Url.cc:820
Url manipulation class.
Definition: Url.h:87
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition: Url.cc:574
bool hasCredentialsInAuthority() const
Returns true if username and password are encoded in the authority component.
Definition: Url.h:371
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: Url.cc:834
Flag to request decoded string(s).
Definition: UrlUtils.h:54