libzypp: zypp-core/Url.cc Source File

libzypp 17.38.14

Url.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
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
24namespace 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
68 UrlSchemes
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
97 zypp::url::ParamMap
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(
169 zypp::url::join(
170 pmap,
171 config("psep_querystr"),
172 config("vsep_querystr"),
173 config("safe_querystr"),
174 url::E_ENCODED
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 // -----------------------------------------------------------------
300 Url::~Url()
301 {
302 }
303
304
305 // -----------------------------------------------------------------
306 Url::Url()
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 {
318 ZYPP_THROW(url::UrlException(
319 _("Unable to clone Url object")
320 ));
321 }
322 }
323
324
325 // -----------------------------------------------------------------
326 Url::Url(zypp::url::UrlRef url)
327 : m_impl(std::move( url))
328 {
329 if( !m_impl)
330 {
331 ZYPP_THROW(url::UrlException(
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 {
344 ZYPP_THROW(url::UrlParsingException(
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 {
358 ZYPP_THROW(url::UrlParsingException(
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 {
397 str::regex rex(RX_SPLIT_URL);
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
432 zypp::url::UrlSchemes
433 Url::getRegisteredSchemes()
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 // -----------------------------------------------------------------
449 zypp::url::UrlSchemes
450 Url::getKnownSchemes() const
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 }
512
513
514 // -----------------------------------------------------------------
515 bool
516 Url::isValid() const
517 {
518 return m_impl->isValid();
519 }
520
521
522 // -----------------------------------------------------------------
523 std::string
524 Url::asString() const
525 {
526 return m_impl->asString();
527 }
528
529
530 // -----------------------------------------------------------------
531 std::string
532 Url::asCompleteString() const
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
560 Url::getScheme() const
561 {
562 return m_impl->getScheme();
563 }
564
565
566 // -----------------------------------------------------------------
567 std::string
568 Url::getAuthority() const
569 {
570 return m_impl->getAuthority();
571 }
572
573 // -----------------------------------------------------------------
574 std::string
575 Url::getPathData() const
576 {
577 return m_impl->getPathData();
578 }
579
580
581 // -----------------------------------------------------------------
582 std::string
583 Url::getQueryString() const
584 {
585 return m_impl->getQueryString();
586 }
587
588
589 // -----------------------------------------------------------------
590 std::string
591 Url::getFragment(zypp::url::EEncoding eflag) const
592 {
593 return m_impl->getFragment(eflag);
594 }
595
596
597 // -----------------------------------------------------------------
598 std::string
599 Url::getUsername(EEncoding eflag) const
600 {
601 return m_impl->getUsername(eflag);
602 }
603
604
605 // -----------------------------------------------------------------
606 std::string
607 Url::getPassword(EEncoding eflag) const
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
631 Url::getPathName(EEncoding eflag) const
632 {
633 return m_impl->getPathName(eflag);
634 }
635
636
637 // -----------------------------------------------------------------
638 std::string
639 Url::getPathParams() const
640 {
641 return m_impl->getPathParams();
642 }
643
644
645 // -----------------------------------------------------------------
646 zypp::url::ParamVec
647 Url::getPathParamsVec() const
648 {
649 return m_impl->getPathParamsVec();
650 }
651
652
653 // -----------------------------------------------------------------
654 zypp::url::ParamMap
655 Url::getPathParamsMap(EEncoding eflag) const
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 // -----------------------------------------------------------------
670 zypp::url::ParamVec
671 Url::getQueryStringVec() const
672 {
673 return m_impl->getQueryStringVec();
674 }
675
676
677 // -----------------------------------------------------------------
678 zypp::url::ParamMap
679 Url::getQueryStringMap(EEncoding eflag) const
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(),
716 m_impl->getQueryString(),
717 m_impl->getFragment(zypp::url::E_ENCODED)
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
798 Url::setPathName(const Pathname &path,
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
864 Url::setPathParamsVec(const zypp::url::ParamVec &pvec)
865 {
866 m_impl->setPathParamsVec(pvec);
867 }
868
869
870 // -----------------------------------------------------------------
871 void
872 Url::setPathParamsMap(const zypp::url::ParamMap &pmap)
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
888 Url::setQueryStringVec(const zypp::url::ParamVec &pvec)
889 {
890 m_impl->setQueryStringVec(pvec);
891 }
892
893
894 // -----------------------------------------------------------------
895 void
896 Url::setQueryStringMap(const zypp::url::ParamMap &pmap)
897 {
898 m_impl->setQueryStringMap(pmap, url::E_DECODED);
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 // -----------------------------------------------------------------
922 ViewOptions
923 Url::getViewOptions() const
924 {
925 return m_impl->getViewOptions();
926 }
927
928 // -----------------------------------------------------------------
929 void
930 Url::setViewOptions(const ViewOptions &vopts)
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*/
arrayBegin
#define arrayBegin(A)
Simple C-array iterator.
Definition Easy.h:36
arrayEnd
#define arrayEnd(A)
Definition Easy.h:38
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
Gettext.h
_
#define _(MSG)
Definition Gettext.h:39
Pathname.h
Regex.h
String.h
RX_SPLIT_URL
#define RX_SPLIT_URL
Definition Url.cc:35
Url.h
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::Url::schemeIsPlugin
bool schemeIsPlugin() const
Definition Url.h:298
zypp::Url::delQueryParams
void delQueryParams(const std::set< std::string > &params)
remove multiple query parameters at once
Definition Url.cc:916
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:560
zypp::Url::asCompleteString
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:532
zypp::Url::setViewOptions
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition Url.cc:930
zypp::Url::setAuthority
void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition Url.cc:725
zypp::Url::getPathParamsMap
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
zypp::Url::getPathParamsVec
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition Url.cc:647
zypp::Url::ViewOptions
zypp::url::ViewOptions ViewOptions
View options.
Definition Url.h:103
zypp::Url::setQueryString
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition Url.cc:741
zypp::Url::schemeIsRemote
bool schemeIsRemote() const
Definition Url.h:279
zypp::Url::getPathParams
std::string getPathParams() const
Returns the path parameters from the URL.
Definition Url.cc:639
zypp::Url::asString
std::string asString() const
Returns a default string representation of the Url object.
Definition Url.cc:524
zypp::Url::getPathData
std::string getPathData() const
Returns the encoded path component of the URL.
Definition Url.cc:575
zypp::Url::getPathParam
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
zypp::Url::getAuthority
std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition Url.cc:568
zypp::Url::getUsername
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition Url.cc:599
zypp::Url::isRegisteredScheme
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
Definition Url.cc:442
zypp::Url::schemeIsHttpLike
static bool schemeIsHttpLike(const std::string &scheme_r)
Definition Url.cc:497
zypp::Url::setFragment
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
Definition Url.cc:749
zypp::Url::getPathName
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition Url.cc:631
zypp::Url::setQueryStringVec
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition Url.cc:888
zypp::Url::Url
Url()
Definition Url.cc:306
zypp::Url::getQueryParam
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
zypp::Url::setPathName
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition Url.cc:791
zypp::Url::setPathParamsMap
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition Url.cc:872
zypp::Url::getViewOptions
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition Url.cc:923
zypp::Url::schemeIsDownloading
bool schemeIsDownloading() const
Definition Url.h:291
zypp::Url::setPathData
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition Url.cc:733
zypp::Url::getHost
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition Url.cc:615
zypp::Url::schemeIsFtpLike
static bool schemeIsFtpLike(const std::string &scheme_r)
Definition Url.cc:502
zypp::Url::m_impl
url::UrlRef m_impl
Definition Url.h:860
zypp::Url::setHost
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition Url.cc:775
zypp::Url::setPort
void setPort(const std::string &port)
Set the port number in the URL authority.
Definition Url.cc:783
zypp::Url::~Url
~Url()
Definition Url.cc:300
zypp::Url::delQueryParam
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition Url.cc:910
zypp::Url::setPathParamsVec
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition Url.cc:864
zypp::Url::isValid
bool isValid() const
Verifies the Url.
Definition Url.cc:516
zypp::Url::getFragment
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition Url.cc:591
zypp::Url::parseUrl
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
Definition Url.cc:389
zypp::Url::setPathParam
void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition Url.cc:880
zypp::Url::schemeIsHttpLike
bool schemeIsHttpLike() const
Definition Url.h:292
zypp::Url::setPassword
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition Url.cc:766
zypp::Url::setPathParams
void setPathParams(const std::string &params)
Set the path parameters.
Definition Url.cc:856
zypp::Url::operator=
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
Definition Url.cc:353
zypp::Url::EEncoding
zypp::url::EEncoding EEncoding
Encoding flags.
Definition Url.h:98
zypp::Url::registerScheme
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
Definition Url.cc:379
zypp::Url::getQueryString
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition Url.cc:583
zypp::Url::isValidScheme
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition Url.cc:458
zypp::Url::setQueryParam
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition Url.cc:903
zypp::Url::getRegisteredSchemes
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
Definition Url.cc:433
zypp::Url::getQueryStringVec
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition Url.cc:671
zypp::Url::pathNameSetTrailingSlash
void pathNameSetTrailingSlash(bool apply_r=true)
Apply or remove a trailing '/' from pathName.
Definition Url.cc:838
zypp::Url::schemeIsLocal
bool schemeIsLocal() const
Definition Url.h:274
zypp::Url::setUsername
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
Definition Url.cc:757
zypp::Url::getKnownSchemes
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
Definition Url.cc:450
zypp::Url::appendPathName
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition Url.cc:813
zypp::Url::setScheme
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition Url.cc:695
zypp::Url::getPassword
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition Url.cc:607
zypp::Url::schemeIsVolatile
bool schemeIsVolatile() const
Definition Url.h:284
zypp::Url::schemeIsFtpLike
bool schemeIsFtpLike() const
Definition Url.h:293
zypp::Url::getQueryStringMap
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
zypp::Url::getPort
std::string getPort() const
Returns the port from the URL authority.
Definition Url.cc:623
zypp::Url::setQueryStringMap
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition Url.cc:896
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::emptyOrRoot
bool emptyOrRoot() const
Test for "" or "/".
Definition Pathname.h:127
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition Pathname.h:94
zypp::filesystem::Pathname::absolutename
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Definition Pathname.h:148
zypp::str::regex
Regular expression.
Definition Regex.h:95
zypp::str::smatch
Regular expression match result.
Definition Regex.h:168
zypp::str::smatch::size
unsigned size() const
Definition Regex.cc:106
zypp::url::UrlBase
Generic Url base class.
Definition UrlBase.h:272
zypp::url::UrlBase::setQueryString
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition UrlBase.cc:969
zypp::url::UrlBase::getQueryString
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition UrlBase.cc:698
zypp::url::UrlBase::getPort
virtual std::string getPort() const
Returns the port number from the URL authority.
Definition UrlBase.cc:755
zypp::url::UrlBase::setScheme
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition UrlBase.cc:892
zypp::url::UrlBase::setHost
virtual void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition UrlBase.cc:1081
zypp::url::UrlBase::getPathParamsMap
virtual zypp::url::ParamMap getPathParamsMap(EEncoding eflag) const
Returns a string map with path parameter keys and values.
Definition UrlBase.cc:803
zypp::url::UrlBase::getPathParamsVec
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
Definition UrlBase.cc:782
zypp::url::UrlBase::getUsername
virtual std::string getUsername(EEncoding eflag) const
Returns the username from the URL authority.
Definition UrlBase.cc:722
zypp::url::UrlBase::getKnownSchemes
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
Definition UrlBase.cc:416
zypp::url::UrlBase::getAuthority
virtual std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition UrlBase.cc:661
zypp::url::UrlBase::setQueryParam
virtual void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition UrlBase.cc:1324
zypp::url::UrlBase::config
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition UrlBase.cc:368
zypp::url::UrlBase::setPathParamsVec
virtual void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition UrlBase.cc:1243
zypp::url::UrlBase::getFragment
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
Definition UrlBase.cc:711
zypp::url::UrlBase::getPathParams
virtual std::string getPathParams() const
Returns the encoded path parameters from the URL.
Definition UrlBase.cc:774
zypp::url::UrlBase::getPassword
virtual std::string getPassword(EEncoding eflag) const
Returns the password from the URL authority.
Definition UrlBase.cc:733
zypp::url::UrlBase::getScheme
virtual std::string getScheme() const
Returns the scheme name of the URL.
Definition UrlBase.cc:653
zypp::url::UrlBase::getQueryStringMap
virtual zypp::url::ParamMap getQueryStringMap(EEncoding eflag) const
Returns a string map with query parameter and their values.
Definition UrlBase.cc:858
zypp::url::UrlBase::setUsername
virtual void setUsername(const std::string &user, EEncoding eflag)
Set the username in the URL authority.
Definition UrlBase.cc:1013
zypp::url::UrlBase::getPathParam
virtual std::string getPathParam(const std::string &param, EEncoding eflag) const
Return the value for the specified path parameter.
Definition UrlBase.cc:826
zypp::url::UrlBase::setQueryStringMap
virtual void setQueryStringMap(const zypp::url::ParamMap &qmap, EEncoding eflag)
Set the query parameters.
Definition UrlBase.cc:1302
zypp::url::UrlBase::setPathParamsMap
virtual void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition UrlBase.cc:1256
zypp::url::UrlBase::asString
virtual std::string asString() const
Returns a default string representation of the Url object.
Definition UrlBase.cc:505
zypp::url::UrlBase::delQueryParams
void delQueryParams(const std::set< std::string > &params)
Definition UrlBase.cc:1364
zypp::url::UrlBase::isKnownScheme
virtual bool isKnownScheme(const std::string &scheme) const
Returns if scheme name is known to this object.
Definition UrlBase.cc:424
zypp::url::UrlBase::getHost
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
Definition UrlBase.cc:744
zypp::url::UrlBase::setPathData
virtual void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition UrlBase.cc:944
zypp::url::UrlBase::setPathName
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
Definition UrlBase.cc:1166
zypp::url::UrlBase::setPort
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
Definition UrlBase.cc:1134
zypp::url::UrlBase::getPathData
virtual std::string getPathData() const
Returns the encoded path component of the URL.
Definition UrlBase.cc:688
zypp::url::UrlBase::isValid
virtual bool isValid() const
Verifies the Url.
Definition UrlBase.cc:473
zypp::url::UrlBase::getPathName
virtual std::string getPathName(EEncoding eflag) const
Returns the path name from the URL.
Definition UrlBase.cc:763
zypp::url::UrlBase::setFragment
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
Definition UrlBase.cc:986
zypp::url::UrlBase::clear
virtual void clear()
Clears all data in the object.
Definition UrlBase.cc:396
zypp::url::UrlBase::isValidScheme
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
Definition UrlBase.cc:441
zypp::url::UrlBase::getQueryStringVec
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition UrlBase.cc:837
zypp::url::UrlBase::UrlBase
UrlBase()
Definition UrlBase.cc:266
zypp::url::UrlBase::getQueryParam
virtual std::string getQueryParam(const std::string &param, EEncoding eflag) const
Return the value for the specified query parameter.
Definition UrlBase.cc:881
zypp::url::UrlBase::setViewOptions
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition UrlBase.cc:388
zypp::url::UrlBase::setQueryStringVec
virtual void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition UrlBase.cc:1289
zypp::url::UrlBase::delQueryParam
virtual void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition UrlBase.cc:1348
zypp::url::UrlBase::setPassword
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
Definition UrlBase.cc:1047
zypp::url::UrlBase::setPathParam
virtual void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition UrlBase.cc:1279
zypp::url::UrlBase::setPathParams
virtual void setPathParams(const std::string &params)
Set the path parameters.
Definition UrlBase.cc:1226
zypp::url::UrlBase::asString1050625
std::string asString1050625() const
Definition UrlBase.cc:510
zypp::url::UrlBase::setAuthority
virtual void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition UrlBase.cc:916
zypp::url::UrlBase::getViewOptions
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition UrlBase.cc:380
zypp::url::UrlException
Base class for all URL exceptions.
Definition UrlException.h:32
zypp::url::UrlNotSupportedException
Thrown if a feature e.g.
Definition UrlException.h:125
zypp::url::UrlParsingException
Thrown if the url or a component can't be parsed at all.
Definition UrlException.h:68
zypp::str::regex_match
bool regex_match(const char *s, smatch &matches, const regex &regex) ZYPP_API
Regular expression matching.
Definition Regex.cc:80
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zypp::hotfix1050625
Definition Url.cc:956
zypp::hotfix1050625::asString
std::string asString(const Url &url_r)
Definition Url.cc:957
zypp::str::toLower
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition String.cc:180
zypp::str::startsWith
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition String.h:1155
zypp::str::endsWith
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
Definition String.h:1162
zypp::str::form
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp::url::UrlRef
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition UrlBase.h:1093
zypp::url::encode
std::string encode(const std::string &str, const std::string &safe, EEncoding eflag)
Encodes a string using URL percent encoding.
Definition UrlUtils.cc:32
zypp::url::ParamVec
std::vector< std::string > ParamVec
A parameter vector container.
Definition UrlUtils.h:40
zypp::url::ViewOptions
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition UrlBase.h:245
zypp::url::join
std::string join(const ParamVec &pvec, const std::string &psep)
Join parameter vector to a string.
Definition UrlUtils.cc:252
zypp::url::ParamMap
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition UrlUtils.h:47
zypp::url::UrlSchemes
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition UrlBase.h:252
zypp::url::EEncoding
EEncoding
Encoding flags.
Definition UrlUtils.h:52
zypp::url::E_DECODED
@ E_DECODED
Flag to request decoded string(s).
Definition UrlUtils.h:54
zypp::url::E_ENCODED
@ E_ENCODED
Flag to request encoded string(s).
Definition UrlUtils.h:53
zypp::url::decode
std::string decode(const std::string &str, bool allowNUL)
Decodes a URL percent encoded string.
Definition UrlUtils.cc:87
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::operator<
bool operator<(const Capability &lhs, const Capability &rhs)
relates: Capability Arbitrary order.
Definition Capability.h:317
zypp::operator!=
bool operator!=(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:313
zypp::operator==
bool operator==(const Capability &lhs, const Capability &rhs)
relates: Capability
Definition Capability.h:309
zypp::operator<<
std::ostream & operator<<(std::ostream &str, const Capabilities &obj)
relates: Capabilities Stream output
Definition Capabilities.cc:65
zypp::RWCOW_pointer::reset
void reset()
Definition PtrTypes.h:498