libzypp  17.35.16
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  static const char * val[] = { "http", "https", "ftp", "sftp", "tftp" };
496  return isInList( arrayBegin(val), arrayEnd(val), scheme_r );
497  }
498 
499  bool Url::schemeIsPlugin( const std::string & scheme_r )
500  {
501  return scheme_r == "plugin";
502  }
504 
505  // -----------------------------------------------------------------
506  bool
507  Url::isValid() const
508  {
509  return m_impl->isValid();
510  }
511 
512 
513  // -----------------------------------------------------------------
514  std::string
516  {
517  return m_impl->asString();
518  }
519 
520 
521  // -----------------------------------------------------------------
522  std::string
524  {
525  // make sure, all url components are included;
526  // regardless of the current configuration...
527  ViewOptions opts(getViewOptions() +
528  ViewOption::WITH_SCHEME +
529  ViewOption::WITH_USERNAME +
530  ViewOption::WITH_PASSWORD +
531  ViewOption::WITH_HOST +
532  ViewOption::WITH_PORT +
533  ViewOption::WITH_PATH_NAME +
534  ViewOption::WITH_PATH_PARAMS +
535  ViewOption::WITH_QUERY_STR +
536  ViewOption::WITH_FRAGMENT);
537  return m_impl->asString(opts);
538  }
539 
540 
541  // -----------------------------------------------------------------
542  std::string
543  Url::asString(const ViewOptions &opts) const
544  {
545  return m_impl->asString(opts);
546  }
547 
548 
549  // -----------------------------------------------------------------
550  std::string
552  {
553  return m_impl->getScheme();
554  }
555 
556 
557  // -----------------------------------------------------------------
558  std::string
560  {
561  return m_impl->getAuthority();
562  }
563 
564  // -----------------------------------------------------------------
565  std::string
567  {
568  return m_impl->getPathData();
569  }
570 
571 
572  // -----------------------------------------------------------------
573  std::string
575  {
576  return m_impl->getQueryString();
577  }
578 
579 
580  // -----------------------------------------------------------------
581  std::string
583  {
584  return m_impl->getFragment(eflag);
585  }
586 
587 
588  // -----------------------------------------------------------------
589  std::string
591  {
592  return m_impl->getUsername(eflag);
593  }
594 
595 
596  // -----------------------------------------------------------------
597  std::string
599  {
600  return m_impl->getPassword(eflag);
601  }
602 
603 
604  // -----------------------------------------------------------------
605  std::string
606  Url::getHost(EEncoding eflag) const
607  {
608  return m_impl->getHost(eflag);
609  }
610 
611 
612  // -----------------------------------------------------------------
613  std::string
614  Url::getPort() const
615  {
616  return m_impl->getPort();
617  }
618 
619 
620  // -----------------------------------------------------------------
621  std::string
623  {
624  return m_impl->getPathName(eflag);
625  }
626 
627 
628  // -----------------------------------------------------------------
629  std::string
631  {
632  return m_impl->getPathParams();
633  }
634 
635 
636  // -----------------------------------------------------------------
639  {
640  return m_impl->getPathParamsVec();
641  }
642 
643 
644  // -----------------------------------------------------------------
647  {
648  return m_impl->getPathParamsMap(eflag);
649  }
650 
651 
652  // -----------------------------------------------------------------
653  std::string
654  Url::getPathParam(const std::string &param, EEncoding eflag) const
655  {
656  return m_impl->getPathParam(param, eflag);
657  }
658 
659 
660  // -----------------------------------------------------------------
663  {
664  return m_impl->getQueryStringVec();
665  }
666 
667 
668  // -----------------------------------------------------------------
671  {
672  return m_impl->getQueryStringMap(eflag);
673  }
674 
675 
676  // -----------------------------------------------------------------
677  std::string
678  Url::getQueryParam(const std::string &param, EEncoding eflag) const
679  {
680  return m_impl->getQueryParam(param, eflag);
681  }
682 
683 
684  // -----------------------------------------------------------------
685  void
686  Url::setScheme(const std::string &scheme)
687  {
688  if(scheme == m_impl->getScheme())
689  {
690  return;
691  }
692  if( m_impl->isKnownScheme(scheme))
693  {
694  m_impl->setScheme(scheme);
695  return;
696  }
697 
698  UrlRef url = g_urlSchemeRepository().getUrlByScheme(scheme);
699  if( !url)
700  {
701  url.reset( new UrlBase());
702  }
703  url->init(
704  scheme,
705  m_impl->getAuthority(),
706  m_impl->getPathData(),
709  );
710  m_impl = url;
711  }
712 
713 
714  // -----------------------------------------------------------------
715  void
716  Url::setAuthority(const std::string &authority)
717  {
718  m_impl->setAuthority(authority);
719  }
720 
721 
722  // -----------------------------------------------------------------
723  void
724  Url::setPathData(const std::string &pathdata)
725  {
726  m_impl->setPathData(pathdata);
727  }
728 
729 
730  // -----------------------------------------------------------------
731  void
732  Url::setQueryString(const std::string &querystr)
733  {
734  m_impl->setQueryString(querystr);
735  }
736 
737 
738  // -----------------------------------------------------------------
739  void
740  Url::setFragment(const std::string &fragment, EEncoding eflag)
741  {
742  m_impl->setFragment(fragment, eflag);
743  }
744 
745 
746  // -----------------------------------------------------------------
747  void
748  Url::setUsername(const std::string &user,
749  EEncoding eflag)
750  {
751  m_impl->setUsername(user, eflag);
752  }
753 
754 
755  // -----------------------------------------------------------------
756  void
757  Url::setPassword(const std::string &pass,
758  EEncoding eflag)
759  {
760  m_impl->setPassword(pass, eflag);
761  }
762 
763 
764  // -----------------------------------------------------------------
765  void
766  Url::setHost(const std::string &host)
767  {
768  m_impl->setHost(host);
769  }
770 
771 
772  // -----------------------------------------------------------------
773  void
774  Url::setPort(const std::string &port)
775  {
776  m_impl->setPort(port);
777  }
778 
779 
780  // -----------------------------------------------------------------
781  void
782  Url::setPathName(const std::string &path,
783  EEncoding eflag)
784  {
785  m_impl->setPathName(path, eflag);
786  }
787 
788  void
790  EEncoding eflag)
791  {
792  m_impl->setPathName(path.asString(), eflag);
793  }
794 
795  void
796  Url::setPathName(const char *path,
797  EEncoding eflag)
798  {
799  m_impl->setPathName(path, eflag);
800  }
801 
802  // -----------------------------------------------------------------
803 
804  void Url::appendPathName( const Pathname & path_r, EEncoding eflag_r )
805  { if ( ! path_r.emptyOrRoot() ) setPathName( Pathname(getPathName( eflag_r )) / path_r, eflag_r ); }
806 
807  // -----------------------------------------------------------------
808  void
809  Url::setPathParams(const std::string &params)
810  {
811  m_impl->setPathParams(params);
812  }
813 
814 
815  // -----------------------------------------------------------------
816  void
818  {
819  m_impl->setPathParamsVec(pvec);
820  }
821 
822 
823  // -----------------------------------------------------------------
824  void
826  {
827  m_impl->setPathParamsMap(pmap);
828  }
829 
830 
831  // -----------------------------------------------------------------
832  void
833  Url::setPathParam(const std::string &param, const std::string &value)
834  {
835  m_impl->setPathParam(param, value);
836  }
837 
838 
839  // -----------------------------------------------------------------
840  void
842  {
843  m_impl->setQueryStringVec(pvec);
844  }
845 
846 
847  // -----------------------------------------------------------------
848  void
850  {
852  }
853 
854  // -----------------------------------------------------------------
855  void
856  Url::setQueryParam(const std::string &param, const std::string &value)
857  {
858  m_impl->setQueryParam(param, value);
859  }
860 
861  // -----------------------------------------------------------------
862  void
863  Url::delQueryParam(const std::string &param)
864  {
865  m_impl->delQueryParam(param);
866  }
867 
868  void
869  Url::delQueryParams(const std::set<std::string> &params)
870  {
871  m_impl->delQueryParams(params);
872  }
873 
874  // -----------------------------------------------------------------
877  {
878  return m_impl->getViewOptions();
879  }
880 
881  // -----------------------------------------------------------------
882  void
884  {
885  m_impl->setViewOptions(vopts);
886  }
887 
888  // -----------------------------------------------------------------
889  std::ostream & operator<<( std::ostream & str, const Url & url )
890  {
891  return str << url.asString();
892  }
893 
894  bool operator<( const Url &lhs, const Url &rhs )
895  {
896  return (lhs.asCompleteString() < rhs.asCompleteString());
897  }
898 
899  bool operator==( const Url &lhs, const Url &rhs )
900  {
901  return (lhs.asCompleteString() == rhs.asCompleteString());
902  }
903 
904  bool operator!=( const Url &lhs, const Url &rhs )
905  {
906  return (lhs.asCompleteString() != rhs.asCompleteString());
907  }
908 
909  namespace hotfix1050625 {
910  std::string asString( const Url & url_r )
911  { return url_r.m_impl->asString1050625(); }
912  }
913 
915 } // namespace zypp
917 /*
918 ** vim: set ts=2 sts=2 sw=2 ai et:
919 */
std::string getScheme() const
Returns the scheme name of the URL.
Definition: Url.cc:551
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition: Url.cc:757
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:178
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:662
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
void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition: Url.cc:833
#define _(MSG)
Definition: Gettext.h:39
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:856
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:424
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:883
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:804
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition: Url.cc:582
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:809
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:774
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
Definition: SerialNumber.cc:52
Definition: Arch.h:363
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition: Url.cc:638
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
Definition: Url.cc:748
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition: Url.cc:766
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
Definition: Url.cc:670
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
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:37
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:841
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:740
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:716
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:876
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:123
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:782
std::string getPathData() const
Returns the encoded path component of the URL.
Definition: Url.cc:566
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:515
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:630
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:294
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:678
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition: Url.cc:686
const std::string & asString() const
String representation.
Definition: Pathname.h:93
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:523
bool schemeIsVolatile() const
Definition: Url.h:284
std::string getPort() const
Returns the port from the URL authority.
Definition: Url.cc:614
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:724
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:910
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:646
std::string join(const ParamVec &pvec, const std::string &psep)
Join parameter vector to a string.
Definition: UrlUtils.cc:252
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:507
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:559
std::string decode(const std::string &str, bool allowNUL)
Decodes a URL percent encoded string.
Definition: UrlUtils.cc:87
#define arrayEnd(A)
Definition: Easy.h:43
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition: UrlBase.cc:368
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition: UrlBase.cc:1166
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:289
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition: Url.cc:732
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition: Url.cc:458
~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:622
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition: Url.cc:606
void delQueryParams(const std::set< std::string > &params)
remove multiple query parameters at once
Definition: Url.cc:869
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 std::string &s, smatch &matches, const regex &regex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
Definition: Regex.h:70
url::UrlRef m_impl
Definition: Url.h:851
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:654
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition: UrlBase.cc:688
EEncoding
Encoding flags.
Definition: UrlUtils.h:52
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
Definition: StrMatcher.cc:340
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:817
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition: Url.cc:825
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition: Url.cc:849
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: Application.cc:19
SolvableIdType size_type
Definition: PoolMember.h:126
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:598
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:574
Url manipulation class.
Definition: Url.h:92
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: UrlBase.cc:1348
#define arrayBegin(A)
Simple C-array iterator.
Definition: Easy.h:41
#define RX_SPLIT_URL
Definition: Url.cc:35
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition: Url.cc:863
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition: Url.cc:590
Flag to request decoded string(s).
Definition: UrlUtils.h:54
bool schemeIsLocal() const
Definition: Url.h:274