libzypp  17.38.7
Url.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <zypp-core/Url.h>
14 #include <zypp-core/Pathname.h>
15 #include <zypp-core/base/Gettext.h>
16 #include <zypp-core/base/String.h>
17 #include <zypp-core/base/Regex.h>
18 #include <stdexcept>
19 #include <iostream>
20 #include <utility>
21 
22 
24 namespace zypp
25 {
26 
27 
28  using namespace zypp::url;
29 
30 
31  // -----------------------------------------------------------------
32  /*
33  * url = [scheme:] [//authority] /path [?query] [#fragment]
34  */
35  #define RX_SPLIT_URL "^([^:/?#]+:|)" \
36  "(//[^/?#]*|)" \
37  "([^?#]*)" \
38  "([?][^#]*|)" \
39  "(#.*|)"
40 
41 
43  namespace
44  {
45 
46 
47  // ---------------------------------------------------------------
48  class LDAPUrl: public UrlBase
49  {
50  public:
51  LDAPUrl(): UrlBase()
52  {
53  configure();
54  }
55 
56  LDAPUrl(LDAPUrl &&) = default;
57  LDAPUrl &operator=(const LDAPUrl &) = default;
58  LDAPUrl &operator=(LDAPUrl &&) = default;
59  LDAPUrl(const LDAPUrl &url) : UrlBase(url) {}
60  ~LDAPUrl() override = default;
61 
62  UrlBase *
63  clone() const override
64  {
65  return new LDAPUrl(*this);
66  }
67 
69  getKnownSchemes() const override
70  {
71  UrlSchemes schemes(2);
72  schemes[0] = "ldap";
73  schemes[1] = "ldaps";
74  return schemes;
75  }
76 
77  void
78  configure() override
79  {
80  config("sep_pathparams", "");
81 
82  config("psep_querystr", "?");
83  config("vsep_querystr", "");
84 
85  // host is required (isValid=>false)
86  // but not mandatory (see RFC 2255),
87  // that is, accept empty host.
88  config("require_host", "y");
89 
90  // not allowed here
91  config("rx_username", "");
92  config("rx_password", "");
93  config("rx_fragment", "");
94  config("rx_pathparams", "");
95  }
96 
98  getQueryStringMap(zypp::url::EEncoding eflag) const override
99  {
100  static const char * const keys[] = {
101  "attrs", "scope", "filter", "exts", NULL
102  };
103  zypp::url::ParamMap pmap;
104  zypp::url::ParamVec pvec( getQueryStringVec());
105  if( pvec.size() <= 4)
106  {
107  for(size_t i=0; i<pvec.size(); i++)
108  {
109  if(eflag == zypp::url::E_ENCODED)
110  pmap[keys[i]] = pvec[i];
111  else
112  pmap[keys[i]] = zypp::url::decode( pvec[i]);
113  }
114  }
115  else
116  {
117  ZYPP_THROW(url::UrlNotSupportedException(
118  _("Invalid LDAP URL query string")
119  ));
120  }
121  return pmap;
122  }
123 
124  void
125  setQueryStringMap(const zypp::url::ParamMap &pmap, EEncoding eflag ) override
126  {
127  static const char * const keys[] = {
128  "attrs", "scope", "filter", "exts", NULL
129  };
130 
131  if ( eflag == url::E_DECODED )
132  {
133  // remove psep ("?") from safe chars
134  std::string join_safe;
135  std::string safe(config("safe_querystr"));
136  std::string psep(config("psep_querystr"));
137  for(std::string::size_type i=0; i<safe.size(); i++)
138  {
139  if( psep.find(safe[i]) == std::string::npos)
140  join_safe.append(1, safe[i]);
141  }
142 
143  zypp::url::ParamVec pvec(4);
144  zypp::url::ParamMap::const_iterator p;
145  for(p=pmap.begin(); p!=pmap.end(); ++p)
146  {
147  bool found=false;
148  for(size_t i=0; i<4; i++)
149  {
150  if(p->first == keys[i])
151  {
152  found=true;
153  pvec[i] = zypp::url::encode(p->second, join_safe);
154  }
155  }
156  if( !found)
157  {
158  ZYPP_THROW(url::UrlNotSupportedException(
159  str::form(_("Invalid LDAP URL query parameter '%s'"),
160  p->first.c_str())
161  ));
162  }
163  }
164  setQueryStringVec(pvec);
165  }
166  else
167  {
168  setQueryString(
170  pmap,
171  config("psep_querystr"),
172  config("vsep_querystr"),
173  config("safe_querystr"),
175  )
176  );
177  }
178  }
179  };
180 
181  // ---------------------------------------------------------------
182  // FIXME: hmm..
183  class UrlByScheme
184  {
185  private:
186  using UrlBySchemeMap = std::map<std::string, UrlRef>;
187  UrlBySchemeMap urlByScheme;
188 
189  public:
190  UrlByScheme()
191  {
192  UrlRef ref;
193 
194  // =====================================
195  ref.reset( new LDAPUrl());
196  addUrlByScheme("ldap", ref);
197  addUrlByScheme("ldaps", ref);
198 
199 
200  // =====================================
201  ref.reset( new UrlBase());
202  // don't show empty authority
203  ref->setViewOptions( zypp::url::ViewOption::DEFAULTS -
204  zypp::url::ViewOption::EMPTY_AUTHORITY);
205 
206  ref->config("with_authority", "n"); // disallow host,...
207  ref->config("require_pathname", "m"); // path is mandatory
208  addUrlByScheme("hd", ref);
209  addUrlByScheme("cd", ref);
210  addUrlByScheme("dvd", ref);
211  addUrlByScheme("dir", ref);
212  addUrlByScheme("iso", ref);
213 
214  addUrlByScheme("mailto", ref);
215  addUrlByScheme("urn", ref);
216  addUrlByScheme("plugin", ref); // zypp plugable media handler:
217 
218  // RFC1738, 3.10: may contain a host
219  ref->config("with_authority", "y"); // allow host,
220  ref->config("with_port", "n"); // but no port,
221  ref->config("rx_username", ""); // username or
222  ref->config("rx_password", ""); // password ...
223  addUrlByScheme("file", ref);
224 
225  // =====================================
226  ref.reset( new UrlBase());
227  ref->config("require_host", "m"); // host is mandatory
228  addUrlByScheme("nfs", ref);
229  addUrlByScheme("nfs4", ref);
230  addUrlByScheme("smb", ref);
231  addUrlByScheme("cifs", ref);
232  addUrlByScheme("http", ref);
233  addUrlByScheme("https", ref);
234  ref->config("path_encode_slash2", "y"); // always encode 2. slash
235  addUrlByScheme("ftp", ref);
236  addUrlByScheme("sftp", ref);
237  addUrlByScheme("tftp", ref);
238  }
239 
240  bool
241  addUrlByScheme(const std::string &scheme,
242  UrlRef urlImpl)
243  {
244  if( urlImpl && urlImpl->isValidScheme(scheme))
245  {
246  UrlRef ref(urlImpl);
247  ref->clear();
248  urlByScheme[str::toLower(scheme)] = ref;
249  return true;
250  }
251  return false;
252  }
253 
254  UrlRef
255  getUrlByScheme(const std::string &scheme) const
256  {
257  UrlBySchemeMap::const_iterator i(urlByScheme.find(str::toLower(scheme)));
258  if( i != urlByScheme.end())
259  {
260  return i->second;
261  }
262  return UrlRef();
263  }
264 
265  bool
266  isRegisteredScheme(const std::string &scheme) const
267  {
268  return urlByScheme.find(str::toLower(scheme)) != urlByScheme.end();
269  }
270 
271  UrlSchemes
272  getRegisteredSchemes() const
273  {
274  UrlBySchemeMap::const_iterator i(urlByScheme.begin());
275  UrlSchemes schemes;
276 
277  schemes.reserve(urlByScheme.size());
278  for( ; i != urlByScheme.end(); ++i)
279  {
280  schemes.push_back(i->first);
281  }
282  return schemes;
283  }
284  };
285 
286 
287  // ---------------------------------------------------------------
288  UrlByScheme & g_urlSchemeRepository()
289  {
290  static UrlByScheme _v;
291  return _v;
292  }
293 
295  } // anonymous namespace
297 
298 
299  // -----------------------------------------------------------------
301  {
302  }
303 
304 
305  // -----------------------------------------------------------------
307  : m_impl( new UrlBase())
308  {
309  }
310 
311 
312  // -----------------------------------------------------------------
313  Url::Url(const Url &url)
314  : m_impl( url.m_impl)
315  {
316  if( !m_impl)
317  {
319  _("Unable to clone Url object")
320  ));
321  }
322  }
323 
324 
325  // -----------------------------------------------------------------
327  : m_impl(std::move( url))
328  {
329  if( !m_impl)
330  {
332  _("Invalid empty Url object reference")
333  ));
334  }
335  }
336 
337 
338  // -----------------------------------------------------------------
339  Url::Url(const std::string &encodedUrl)
340  : m_impl( parseUrl(encodedUrl))
341  {
342  if( !m_impl)
343  {
345  _("Unable to parse Url components")
346  ));
347  }
348  }
349 
350 
351  // -----------------------------------------------------------------
352  Url&
353  Url::operator = (const std::string &encodedUrl)
354  {
355  UrlRef url( parseUrl(encodedUrl));
356  if( !url)
357  {
359  _("Unable to parse Url components")
360  ));
361  }
362  m_impl = url;
363  return *this;
364  }
365 
366 
367  // -----------------------------------------------------------------
368  Url&
369  Url::operator = (const Url &url)
370  {
371  m_impl = url.m_impl;
372  return *this;
373  }
374 
375 
376  // -----------------------------------------------------------------
377  // static
378  bool
379  Url::registerScheme(const std::string &scheme,
380  UrlRef urlImpl)
381  {
382  return g_urlSchemeRepository().addUrlByScheme(scheme, std::move(urlImpl));
383  }
384 
385 
386  // -----------------------------------------------------------------
387  // static
388  UrlRef
389  Url::parseUrl(const std::string &encodedUrl)
390  {
391  UrlRef url;
392  str::smatch out;
393  bool ret = false;
394 
395  try
396  {
398  ret = str::regex_match(encodedUrl, out, rex);
399  }
400  catch( ... )
401  {}
402 
403  if(ret && out.size() == 6)
404  {
405  std::string scheme = out[1];
406  if (scheme.size() > 1)
407  scheme.pop_back();
408  std::string authority = out[2];
409  if (authority.size() >= 2)
410  authority = authority.substr(2);
411  std::string query = out[4];
412  if (query.size() > 1)
413  query = query.substr(1);
414  std::string fragment = out[5];
415  if (fragment.size() > 1)
416  fragment = fragment.substr(1);
417 
418  url = g_urlSchemeRepository().getUrlByScheme(scheme);
419  if( !url)
420  {
421  url.reset( new UrlBase());
422  }
423  url->init(scheme, authority, out[3],
424  query, fragment);
425  }
426  return url;
427  }
428 
429 
430  // -----------------------------------------------------------------
431  // static
434  {
435  return g_urlSchemeRepository().getRegisteredSchemes();
436  }
437 
438 
439  // -----------------------------------------------------------------
440  // static
441  bool
442  Url::isRegisteredScheme(const std::string &scheme)
443  {
444  return g_urlSchemeRepository().isRegisteredScheme(scheme);
445  }
446 
447 
448  // -----------------------------------------------------------------
451  {
452  return m_impl->getKnownSchemes();
453  }
454 
455 
456  // -----------------------------------------------------------------
457  bool
458  Url::isValidScheme(const std::string &scheme) const
459  {
460  return m_impl->isValidScheme(scheme);
461  }
462 
463 
465  namespace
466  {
467  inline bool isInList( const char ** begin_r, const char ** end_r, const std::string & scheme_r )
468  {
469  for ( ; begin_r != end_r; ++begin_r )
470  if ( scheme_r == *begin_r )
471  return true;
472  return false;
473  }
474  }
475  bool Url::schemeIsLocal( const std::string & scheme_r )
476  {
477  static const char * val[] = { "cd", "dvd", "dir", "hd", "iso", "file" };
478  return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
479  }
480 
481  bool Url::schemeIsRemote( const std::string & scheme_r )
482  {
483  static const char * val[] = { "http", "https", "nfs", "nfs4", "smb", "cifs", "ftp", "sftp", "tftp" };
484  return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
485  }
486 
487  bool Url::schemeIsVolatile( const std::string & scheme_r )
488  {
489  static const char * val[] = { "cd", "dvd" };
490  return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
491  }
492 
493  bool Url::schemeIsDownloading( const std::string & scheme_r )
494  {
495  return schemeIsHttpLike( scheme_r ) | schemeIsFtpLike( scheme_r );
496  }
497  bool Url::schemeIsHttpLike( const std::string & scheme_r )
498  {
499  static const char * val[] = { "https", "http", };
500  return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
501  }
502  bool Url::schemeIsFtpLike( const std::string & scheme_r )
503  {
504  static const char * val[] = { "ftp", "sftp", "tftp" };
505  return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
506  }
507 
508  bool Url::schemeIsPlugin( const std::string & scheme_r )
509  {
510  return scheme_r == "plugin";
511  }
513 
514  // -----------------------------------------------------------------
515  bool
516  Url::isValid() const
517  {
518  return m_impl->isValid();
519  }
520 
521 
522  // -----------------------------------------------------------------
523  std::string
525  {
526  return m_impl->asString();
527  }
528 
529 
530  // -----------------------------------------------------------------
531  std::string
533  {
534  // make sure, all url components are included;
535  // regardless of the current configuration...
536  ViewOptions opts(getViewOptions() +
537  ViewOption::WITH_SCHEME +
538  ViewOption::WITH_USERNAME +
539  ViewOption::WITH_PASSWORD +
540  ViewOption::WITH_HOST +
541  ViewOption::WITH_PORT +
542  ViewOption::WITH_PATH_NAME +
543  ViewOption::WITH_PATH_PARAMS +
544  ViewOption::WITH_QUERY_STR +
545  ViewOption::WITH_FRAGMENT);
546  return m_impl->asString(opts);
547  }
548 
549 
550  // -----------------------------------------------------------------
551  std::string
552  Url::asString(const ViewOptions &opts) const
553  {
554  return m_impl->asString(opts);
555  }
556 
557 
558  // -----------------------------------------------------------------
559  std::string
561  {
562  return m_impl->getScheme();
563  }
564 
565 
566  // -----------------------------------------------------------------
567  std::string
569  {
570  return m_impl->getAuthority();
571  }
572 
573  // -----------------------------------------------------------------
574  std::string
576  {
577  return m_impl->getPathData();
578  }
579 
580 
581  // -----------------------------------------------------------------
582  std::string
584  {
585  return m_impl->getQueryString();
586  }
587 
588 
589  // -----------------------------------------------------------------
590  std::string
592  {
593  return m_impl->getFragment(eflag);
594  }
595 
596 
597  // -----------------------------------------------------------------
598  std::string
600  {
601  return m_impl->getUsername(eflag);
602  }
603 
604 
605  // -----------------------------------------------------------------
606  std::string
608  {
609  return m_impl->getPassword(eflag);
610  }
611 
612 
613  // -----------------------------------------------------------------
614  std::string
615  Url::getHost(EEncoding eflag) const
616  {
617  return m_impl->getHost(eflag);
618  }
619 
620 
621  // -----------------------------------------------------------------
622  std::string
623  Url::getPort() const
624  {
625  return m_impl->getPort();
626  }
627 
628 
629  // -----------------------------------------------------------------
630  std::string
632  {
633  return m_impl->getPathName(eflag);
634  }
635 
636 
637  // -----------------------------------------------------------------
638  std::string
640  {
641  return m_impl->getPathParams();
642  }
643 
644 
645  // -----------------------------------------------------------------
648  {
649  return m_impl->getPathParamsVec();
650  }
651 
652 
653  // -----------------------------------------------------------------
656  {
657  return m_impl->getPathParamsMap(eflag);
658  }
659 
660 
661  // -----------------------------------------------------------------
662  std::string
663  Url::getPathParam(const std::string &param, EEncoding eflag) const
664  {
665  return m_impl->getPathParam(param, eflag);
666  }
667 
668 
669  // -----------------------------------------------------------------
672  {
673  return m_impl->getQueryStringVec();
674  }
675 
676 
677  // -----------------------------------------------------------------
680  {
681  return m_impl->getQueryStringMap(eflag);
682  }
683 
684 
685  // -----------------------------------------------------------------
686  std::string
687  Url::getQueryParam(const std::string &param, EEncoding eflag) const
688  {
689  return m_impl->getQueryParam(param, eflag);
690  }
691 
692 
693  // -----------------------------------------------------------------
694  void
695  Url::setScheme(const std::string &scheme)
696  {
697  if(scheme == m_impl->getScheme())
698  {
699  return;
700  }
701  if( m_impl->isKnownScheme(scheme))
702  {
703  m_impl->setScheme(scheme);
704  return;
705  }
706 
707  UrlRef url = g_urlSchemeRepository().getUrlByScheme(scheme);
708  if( !url)
709  {
710  url.reset( new UrlBase());
711  }
712  url->init(
713  scheme,
714  m_impl->getAuthority(),
715  m_impl->getPathData(),
718  );
719  m_impl = url;
720  }
721 
722 
723  // -----------------------------------------------------------------
724  void
725  Url::setAuthority(const std::string &authority)
726  {
727  m_impl->setAuthority(authority);
728  }
729 
730 
731  // -----------------------------------------------------------------
732  void
733  Url::setPathData(const std::string &pathdata)
734  {
735  m_impl->setPathData(pathdata);
736  }
737 
738 
739  // -----------------------------------------------------------------
740  void
741  Url::setQueryString(const std::string &querystr)
742  {
743  m_impl->setQueryString(querystr);
744  }
745 
746 
747  // -----------------------------------------------------------------
748  void
749  Url::setFragment(const std::string &fragment, EEncoding eflag)
750  {
751  m_impl->setFragment(fragment, eflag);
752  }
753 
754 
755  // -----------------------------------------------------------------
756  void
757  Url::setUsername(const std::string &user,
758  EEncoding eflag)
759  {
760  m_impl->setUsername(user, eflag);
761  }
762 
763 
764  // -----------------------------------------------------------------
765  void
766  Url::setPassword(const std::string &pass,
767  EEncoding eflag)
768  {
769  m_impl->setPassword(pass, eflag);
770  }
771 
772 
773  // -----------------------------------------------------------------
774  void
775  Url::setHost(const std::string &host)
776  {
777  m_impl->setHost(host);
778  }
779 
780 
781  // -----------------------------------------------------------------
782  void
783  Url::setPort(const std::string &port)
784  {
785  m_impl->setPort(port);
786  }
787 
788 
789  // -----------------------------------------------------------------
790  void
791  Url::setPathName(const std::string &path,
792  EEncoding eflag)
793  {
794  m_impl->setPathName(path, eflag);
795  }
796 
797  void
799  EEncoding eflag)
800  {
801  m_impl->setPathName(path.asString(), eflag);
802  }
803 
804  void
805  Url::setPathName(const char *path,
806  EEncoding eflag)
807  {
808  m_impl->setPathName(path, eflag);
809  }
810 
811  // -----------------------------------------------------------------
812 
813  void Url::appendPathName( const Pathname & path_r, EEncoding eflag_r )
814  {
815  if ( ! path_r.emptyOrRoot() ) {
816  // Check on string level to restore leading double slashes "//" (E_DECODED)
817  // Most important for ftp: where "/%2f" (E_ENCODED) denotes an absolute path.
818  std::string upath { getPathName( url::E_DECODED ) };
819  if ( upath.empty() ) {
820  setPathName( path_r.absolutename(), eflag_r );
821  } else {
822  bool doubleslhash = str::startsWith( upath, "//" );
823  Pathname npath { upath }; // now let Pathname handle the correct concatenation
824  if ( eflag_r == url::E_DECODED ) {
825  npath /= path_r;
826  } else {
827  npath /= url::decode( path_r.asString() );
828  }
829  if ( doubleslhash ) {
830  setPathName( "/" + npath.asString(), url::E_DECODED );
831  } else {
832  setPathName( npath.asString(), url::E_DECODED );
833  }
834  }
835  }
836  }
837 
838  void Url::pathNameSetTrailingSlash( bool apply_r )
839  {
840  std::string upath { getPathName( url::E_DECODED ) };
841  if ( upath.empty() || upath == "/" || upath == "//" )
842  return;
843  if ( str::endsWith( upath, "/" ) == apply_r )
844  return;
845 
846  if ( apply_r ) {
847  setPathName( upath+"/", url::E_DECODED );
848  } else {
849  do { upath.pop_back(); } while ( str::endsWith( upath, "/" ) );
850  setPathName( upath, url::E_DECODED );
851  }
852  }
853 
854  // -----------------------------------------------------------------
855  void
856  Url::setPathParams(const std::string &params)
857  {
858  m_impl->setPathParams(params);
859  }
860 
861 
862  // -----------------------------------------------------------------
863  void
865  {
866  m_impl->setPathParamsVec(pvec);
867  }
868 
869 
870  // -----------------------------------------------------------------
871  void
873  {
874  m_impl->setPathParamsMap(pmap);
875  }
876 
877 
878  // -----------------------------------------------------------------
879  void
880  Url::setPathParam(const std::string &param, const std::string &value)
881  {
882  m_impl->setPathParam(param, value);
883  }
884 
885 
886  // -----------------------------------------------------------------
887  void
889  {
890  m_impl->setQueryStringVec(pvec);
891  }
892 
893 
894  // -----------------------------------------------------------------
895  void
897  {
899  }
900 
901  // -----------------------------------------------------------------
902  void
903  Url::setQueryParam(const std::string &param, const std::string &value)
904  {
905  m_impl->setQueryParam(param, value);
906  }
907 
908  // -----------------------------------------------------------------
909  void
910  Url::delQueryParam(const std::string &param)
911  {
912  m_impl->delQueryParam(param);
913  }
914 
915  void
916  Url::delQueryParams(const std::set<std::string> &params)
917  {
918  m_impl->delQueryParams(params);
919  }
920 
921  // -----------------------------------------------------------------
924  {
925  return m_impl->getViewOptions();
926  }
927 
928  // -----------------------------------------------------------------
929  void
931  {
932  m_impl->setViewOptions(vopts);
933  }
934 
935  // -----------------------------------------------------------------
936  std::ostream & operator<<( std::ostream & str, const Url & url )
937  {
938  return str << url.asString();
939  }
940 
941  bool operator<( const Url &lhs, const Url &rhs )
942  {
943  return (lhs.asCompleteString() < rhs.asCompleteString());
944  }
945 
946  bool operator==( const Url &lhs, const Url &rhs )
947  {
948  return (lhs.asCompleteString() == rhs.asCompleteString());
949  }
950 
951  bool operator!=( const Url &lhs, const Url &rhs )
952  {
953  return (lhs.asCompleteString() != rhs.asCompleteString());
954  }
955 
956  namespace hotfix1050625 {
957  std::string asString( const Url & url_r )
958  { return url_r.m_impl->asString1050625(); }
959  }
960 
962 } // namespace zypp
964 /*
965 ** vim: set ts=2 sts=2 sw=2 ai et:
966 */
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:560
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition: Url.cc:766
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:180
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
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: Url.cc:671
unsigned size() const
Definition: Regex.cc:106
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: UrlBase.cc:698
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: Capability.h:309
void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: Url.cc:880
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:903
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
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:459
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
Definition: UrlBase.cc:416
Regular expression.
Definition: Regex.h:94
std::string asString1050625() const
Definition: UrlBase.cc:510
Flag to request encoded string(s).
Definition: UrlUtils.h:53
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:930
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
Definition: Url.cc:433
Url details namespace.
Definition: UrlBase.cc:57
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition: Url.cc:813
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition: Url.cc:591
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
Definition: UrlBase.cc:782
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition: UrlBase.h:1093
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
String related utilities and Regular expression matching.
void setPathParams(const std::string &params)
Set the path parameters.
Definition: Url.cc:856
Base class for all URL exceptions.
Definition: UrlException.h:31
void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: Url.cc:783
Definition: ansi.h:854
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition: Url.cc:647
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
Definition: Url.cc:757
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: Url.cc:775
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
Definition: Url.cc:679
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
Definition: Url.cc:379
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
Definition: UrlBase.cc:1134
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:39
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:888
Url::asString() view options.
Definition: UrlBase.h:40
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
Definition: Url.cc:749
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
void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition: Url.cc:725
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
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: Url.cc:923
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
UrlBySchemeMap urlByScheme
Definition: Url.cc:187
virtual std::string getQueryParam(const std::string &param, EEncoding eflag) const
Return the value for the specified query parameter.
Definition: UrlBase.cc:881
bool emptyOrRoot() const
Test for "" or "/".
Definition: Pathname.h:127
Thrown if the url or a component can&#39;t be parsed at all.
Definition: UrlException.h:67
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition: Url.cc:791
std::string getPathData() const
Returns the encoded path component of the URL.
Definition: Url.cc:575
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
Definition: Url.cc:450
std::string asString() const
Returns a default string representation of the Url object.
Definition: Url.cc:524
virtual std::string getPathParam(const std::string &param, EEncoding eflag) const
Return the value for the specified path parameter.
Definition: UrlBase.cc:826
std::string getPathParams() const
Returns the path parameters from the URL.
Definition: Url.cc:639
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
Definition: UrlBase.cc:986
bool schemeIsPlugin() const
Definition: Url.h:298
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
Definition: UrlBase.cc:1047
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
Definition: Url.cc:442
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
Definition: UrlBase.cc:744
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:687
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: Url.cc:695
const std::string & asString() const
String representation.
Definition: Pathname.h:94
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
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 url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
Definition: Url.cc:389
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:532
bool schemeIsVolatile() const
Definition: Url.h:284
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:1156
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition: Capability.h:313
std::string getPort() const
Returns the port from the URL authority.
Definition: Url.cc:623
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition: UrlBase.cc:380
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition: Url.cc:733
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
Definition: UrlBase.cc:711
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
Definition: Url.cc:353
std::string asString(const Url &url_r)
Definition: Url.cc:957
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: UrlBase.cc:892
Url()
Definition: Url.cc:306
zypp::url::ParamMap getPathParamsMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with path parameter keys and values.
Definition: Url.cc:655
std::string join(const ParamVec &pvec, const std::string &psep)
Join parameter vector to a string.
Definition: UrlUtils.cc:252
#define _(MSG)
Definition: Gettext.h:39
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: UrlBase.cc:969
bool isValid() const
Verifies the Url.
Definition: Url.cc:516
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
std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition: Url.cc:568
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
Definition: String.h:1163
SolvableIdType size_type
Definition: poolconstants.h:59
std::string decode(const std::string &str, bool allowNUL)
Decodes a URL percent encoded string.
Definition: UrlUtils.cc:87
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition: UrlBase.cc:368
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition: UrlBase.cc:1166
#define arrayEnd(A)
Definition: Easy.h:38
#define arrayBegin(A)
Simple C-array iterator.
Definition: Easy.h:36
Regular expression match result.
Definition: Regex.h:167
bool schemeIsRemote() const
Definition: Url.h:279
std::string encode(const std::string &str, const std::string &safe, EEncoding eflag)
Encodes a string using URL percent encoding.
Definition: UrlUtils.cc:32
bool schemeIsDownloading() const
Definition: Url.h:291
Pathname absolutename() const
Return this path, adding a leading &#39;/&#39; if relative.
Definition: Pathname.h:148
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: Url.cc:741
bool schemeIsHttpLike() const
Definition: Url.h:292
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition: Url.cc:458
void pathNameSetTrailingSlash(bool apply_r=true)
Apply or remove a trailing &#39;/&#39; from pathName.
Definition: Url.cc:838
~Url()
Definition: Url.cc:300
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:631
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:615
void delQueryParams(const std::set< std::string > &params)
remove multiple query parameters at once
Definition: Url.cc:916
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition: Capability.h:317
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
bool regex_match(const char *s, smatch &matches, const regex &regex) ZYPP_API
Regular expression matching.
Definition: Regex.cc:80
url::UrlRef m_impl
Definition: Url.h:860
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition: UrlBase.cc:837
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:663
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition: UrlBase.cc:688
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition: Capabilities.cc:65
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
bool schemeIsFtpLike() const
Definition: Url.h:293
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
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition: Url.cc:864
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: Url.cc:872
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: Url.cc:896
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: CodePitfalls.doc:1
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
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition: Url.cc:607
virtual std::string getScheme() const
Returns the scheme name of the URL.
Definition: UrlBase.cc:653
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition: Url.cc:583
Url manipulation class.
Definition: Url.h:92
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: UrlBase.cc:1348
#define RX_SPLIT_URL
Definition: Url.cc:35
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: Url.cc:910
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:599
Flag to request decoded string(s).
Definition: UrlUtils.h:54
bool schemeIsLocal() const
Definition: Url.h:274