libzypp 17.37.17
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>
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
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 };
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 {
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 {
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
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 // -----------------------------------------------------------------
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&
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 }
503
504
505 // -----------------------------------------------------------------
506 bool
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...
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
607 {
608 return m_impl->getHost(eflag);
609 }
610
611
612 // -----------------------------------------------------------------
613 std::string
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(),
707 m_impl->getQueryString(),
708 m_impl->getFragment(zypp::url::E_ENCODED)
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 {
806 if ( ! path_r.emptyOrRoot() ) {
807 // Check on string level to restore leading double slashes "//" (E_DECODED)
808 // Most important for ftp: where "/%2f" (E_ENCODED) denotes an absolute path.
809 std::string upath { getPathName( url::E_DECODED ) };
810 if ( upath.empty() ) {
811 setPathName( path_r.absolutename(), eflag_r );
812 } else {
813 bool doubleslhash = str::startsWith( upath, "//" );
814 Pathname npath { upath }; // now let Pathname handle the correct concatenation
815 if ( eflag_r == url::E_DECODED ) {
816 npath /= path_r;
817 } else {
818 npath /= url::decode( path_r.asString() );
819 }
820 if ( doubleslhash ) {
821 setPathName( "/" + npath.asString(), url::E_DECODED );
822 } else {
824 }
825 }
826 }
827 }
828
829 void Url::pathNameSetTrailingSlash( bool apply_r )
830 {
831 std::string upath { getPathName( url::E_DECODED ) };
832 if ( upath.empty() || upath == "/" || upath == "//" )
833 return;
834 if ( str::endsWith( upath, "/" ) == apply_r )
835 return;
836
837 if ( apply_r ) {
838 setPathName( upath+"/", url::E_DECODED );
839 } else {
840 do { upath.pop_back(); } while ( str::endsWith( upath, "/" ) );
841 setPathName( upath, url::E_DECODED );
842 }
843 }
844
845 // -----------------------------------------------------------------
846 void
847 Url::setPathParams(const std::string &params)
848 {
849 m_impl->setPathParams(params);
850 }
851
852
853 // -----------------------------------------------------------------
854 void
856 {
857 m_impl->setPathParamsVec(pvec);
858 }
859
860
861 // -----------------------------------------------------------------
862 void
864 {
865 m_impl->setPathParamsMap(pmap);
866 }
867
868
869 // -----------------------------------------------------------------
870 void
871 Url::setPathParam(const std::string &param, const std::string &value)
872 {
873 m_impl->setPathParam(param, value);
874 }
875
876
877 // -----------------------------------------------------------------
878 void
880 {
881 m_impl->setQueryStringVec(pvec);
882 }
883
884
885 // -----------------------------------------------------------------
886 void
888 {
889 m_impl->setQueryStringMap(pmap, url::E_DECODED);
890 }
891
892 // -----------------------------------------------------------------
893 void
894 Url::setQueryParam(const std::string &param, const std::string &value)
895 {
896 m_impl->setQueryParam(param, value);
897 }
898
899 // -----------------------------------------------------------------
900 void
901 Url::delQueryParam(const std::string &param)
902 {
903 m_impl->delQueryParam(param);
904 }
905
906 void
907 Url::delQueryParams(const std::set<std::string> &params)
908 {
909 m_impl->delQueryParams(params);
910 }
911
912 // -----------------------------------------------------------------
915 {
916 return m_impl->getViewOptions();
917 }
918
919 // -----------------------------------------------------------------
920 void
922 {
923 m_impl->setViewOptions(vopts);
924 }
925
926 // -----------------------------------------------------------------
927 std::ostream & operator<<( std::ostream & str, const Url & url )
928 {
929 return str << url.asString();
930 }
931
932 bool operator<( const Url &lhs, const Url &rhs )
933 {
934 return (lhs.asCompleteString() < rhs.asCompleteString());
935 }
936
937 bool operator==( const Url &lhs, const Url &rhs )
938 {
939 return (lhs.asCompleteString() == rhs.asCompleteString());
940 }
941
942 bool operator!=( const Url &lhs, const Url &rhs )
943 {
944 return (lhs.asCompleteString() != rhs.asCompleteString());
945 }
946
947 namespace hotfix1050625 {
948 std::string asString( const Url & url_r )
949 { return url_r.m_impl->asString1050625(); }
950 }
951
953} // namespace zypp
955/*
956** vim: set ts=2 sts=2 sw=2 ai et:
957*/
#define RX_SPLIT_URL
Definition Url.cc:35
Url manipulation class.
Definition Url.h:93
bool schemeIsPlugin() const
Definition Url.h:294
void delQueryParams(const std::set< std::string > &params)
remove multiple query parameters at once
Definition Url.cc:907
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:551
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:523
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition Url.cc:921
void setAuthority(const std::string &authority)
Set the authority component in the URL.
Definition Url.cc:716
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
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
Definition Url.cc:638
zypp::url::ViewOptions ViewOptions
View options.
Definition Url.h:103
void setQueryString(const std::string &querystr)
Set the query string in the URL.
Definition Url.cc:732
bool schemeIsRemote() const
Definition Url.h:279
std::string getPathParams() const
Returns the path parameters from the URL.
Definition Url.cc:630
std::string asString() const
Returns a default string representation of the Url object.
Definition Url.cc:515
std::string getPathData() const
Returns the encoded path component of the URL.
Definition Url.cc:566
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
std::string getAuthority() const
Returns the encoded authority component of the URL.
Definition Url.cc:559
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
Definition Url.cc:590
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
Definition Url.cc:442
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
Definition Url.cc:740
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition Url.cc:622
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
Definition Url.cc:879
Url()
Definition Url.cc:306
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 setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Definition Url.cc:782
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
Definition Url.cc:863
ViewOptions getViewOptions() const
Return the view options of the current object.
Definition Url.cc:914
bool schemeIsDownloading() const
Definition Url.h:289
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
Definition Url.cc:724
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
Definition Url.cc:606
url::UrlRef m_impl
Definition Url.h:856
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
Definition Url.cc:766
void setPort(const std::string &port)
Set the port number in the URL authority.
Definition Url.cc:774
~Url()
Definition Url.cc:300
void delQueryParam(const std::string &param)
remove the specified query parameter.
Definition Url.cc:901
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
Definition Url.cc:855
bool isValid() const
Verifies the Url.
Definition Url.cc:507
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
Definition Url.cc:582
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
Definition Url.cc:389
void setPathParam(const std::string &param, const std::string &value)
Set or add value for the specified path parameter.
Definition Url.cc:871
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
Definition Url.cc:757
void setPathParams(const std::string &params)
Set the path parameters.
Definition Url.cc:847
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
Definition Url.cc:353
zypp::url::EEncoding EEncoding
Encoding flags.
Definition Url.h:98
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
Definition Url.cc:379
std::string getQueryString() const
Returns the encoded query string component of the URL.
Definition Url.cc:574
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
Definition Url.cc:458
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition Url.cc:894
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
Definition Url.cc:433
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
Definition Url.cc:662
void pathNameSetTrailingSlash(bool apply_r=true)
Apply or remove a trailing '/' from pathName.
Definition Url.cc:829
bool schemeIsLocal() const
Definition Url.h:274
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
Definition Url.cc:748
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
Definition Url.cc:450
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition Url.cc:804
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
Definition Url.cc:686
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
Definition Url.cc:598
bool schemeIsVolatile() const
Definition Url.h:284
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
std::string getPort() const
Returns the port from the URL authority.
Definition Url.cc:614
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
Definition Url.cc:887
bool emptyOrRoot() const
Test for "" or "/".
Definition Pathname.h:123
const std::string & asString() const
String representation.
Definition Pathname.h:93
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Definition Pathname.h:141
Regular expression.
Definition Regex.h:95
Regular expression match result.
Definition Regex.h:168
unsigned size() const
Definition Regex.cc:106
Generic Url base class.
Definition UrlBase.h:272
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
Definition UrlBase.cc:368
virtual void clear()
Clears all data in the object.
Definition UrlBase.cc:396
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
Definition UrlBase.cc:441
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
Definition UrlBase.cc:388
std::string asString1050625() const
Definition UrlBase.cc:510
Base class for all URL exceptions.
Thrown if the url or a component can't be parsed at all.
Definition Arch.h:364
String related utilities and Regular expression matching.
std::string asString(const Url &url_r)
Definition Url.cc:948
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition String.cc:180
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition String.h:1155
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
Definition String.h:1162
bool regex_match(const std::string &s, smatch &matches, const regex &regex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
Definition Regex.h:70
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition String.cc:39
Url details namespace.
Definition UrlBase.cc:58
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
Definition UrlBase.h:1093
std::string encode(const std::string &str, const std::string &safe, EEncoding eflag)
Encodes a string using URL percent encoding.
Definition UrlUtils.cc:32
std::vector< std::string > ParamVec
A parameter vector container.
Definition UrlUtils.h:40
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
Definition UrlBase.h:245
std::string join(const ParamVec &pvec, const std::string &psep)
Join parameter vector to a string.
Definition UrlUtils.cc:252
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition UrlUtils.h:47
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Definition UrlBase.h:252
EEncoding
Encoding flags.
Definition UrlUtils.h:52
@ E_DECODED
Flag to request decoded string(s).
Definition UrlUtils.h:54
@ E_ENCODED
Flag to request encoded string(s).
Definition UrlUtils.h:53
std::string decode(const std::string &str, bool allowNUL)
Decodes a URL percent encoded string.
Definition UrlUtils.cc:87
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
#define arrayBegin(A)
Simple C-array iterator.
Definition Easy.h:36
#define arrayEnd(A)
Definition Easy.h:38
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
#define _(MSG)
Definition Gettext.h:39