28 using namespace zypp::url;
35 #define RX_SPLIT_URL "^([^:/?#]+:|)" \
56 LDAPUrl(LDAPUrl &&) =
default;
57 LDAPUrl &operator=(
const LDAPUrl &) =
default;
58 LDAPUrl &operator=(LDAPUrl &&) =
default;
60 ~LDAPUrl()
override =
default;
63 clone()
const override
65 return new LDAPUrl(*
this);
69 getKnownSchemes()
const override
80 config(
"sep_pathparams",
"");
82 config(
"psep_querystr",
"?");
83 config(
"vsep_querystr",
"");
88 config(
"require_host",
"y");
91 config(
"rx_username",
"");
92 config(
"rx_password",
"");
93 config(
"rx_fragment",
"");
94 config(
"rx_pathparams",
"");
100 static const char *
const keys[] = {
101 "attrs",
"scope",
"filter",
"exts", NULL
105 if( pvec.size() <= 4)
107 for(
size_t i=0; i<pvec.size(); i++)
110 pmap[keys[i]] = pvec[i];
118 _(
"Invalid LDAP URL query string")
127 static const char *
const keys[] = {
128 "attrs",
"scope",
"filter",
"exts", NULL
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++)
139 if( psep.find(safe[i]) == std::string::npos)
140 join_safe.append(1, safe[i]);
144 zypp::url::ParamMap::const_iterator p;
145 for(p=pmap.begin(); p!=pmap.end(); ++p)
148 for(
size_t i=0; i<4; i++)
150 if(p->first == keys[i])
159 str::form(
_(
"Invalid LDAP URL query parameter '%s'"),
164 setQueryStringVec(pvec);
171 config(
"psep_querystr"),
172 config(
"vsep_querystr"),
173 config(
"safe_querystr"),
186 using UrlBySchemeMap = std::map<std::string, UrlRef>;
187 UrlBySchemeMap urlByScheme;
195 ref.
reset(
new LDAPUrl());
196 addUrlByScheme(
"ldap", ref);
197 addUrlByScheme(
"ldaps", ref);
204 zypp::url::ViewOption::EMPTY_AUTHORITY);
206 ref->
config(
"with_authority",
"n");
207 ref->
config(
"require_pathname",
"m");
208 addUrlByScheme(
"hd", ref);
209 addUrlByScheme(
"cd", ref);
210 addUrlByScheme(
"dvd", ref);
211 addUrlByScheme(
"dir", ref);
212 addUrlByScheme(
"iso", ref);
214 addUrlByScheme(
"mailto", ref);
215 addUrlByScheme(
"urn", ref);
216 addUrlByScheme(
"plugin", ref);
219 ref->
config(
"with_authority",
"y");
220 ref->
config(
"with_port",
"n");
221 ref->
config(
"rx_username",
"");
222 ref->
config(
"rx_password",
"");
223 addUrlByScheme(
"file", ref);
227 ref->
config(
"require_host",
"m");
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");
235 addUrlByScheme(
"ftp", ref);
236 addUrlByScheme(
"sftp", ref);
237 addUrlByScheme(
"tftp", ref);
241 addUrlByScheme(
const std::string &scheme,
255 getUrlByScheme(
const std::string &scheme)
const
257 UrlBySchemeMap::const_iterator i(urlByScheme.find(
str::toLower(scheme)));
258 if( i != urlByScheme.end())
266 isRegisteredScheme(
const std::string &scheme)
const
268 return urlByScheme.find(
str::toLower(scheme)) != urlByScheme.end();
272 getRegisteredSchemes()
const
274 UrlBySchemeMap::const_iterator i(urlByScheme.begin());
277 schemes.reserve(urlByScheme.size());
278 for( ; i != urlByScheme.end(); ++i)
280 schemes.push_back(i->first);
288 UrlByScheme & g_urlSchemeRepository()
290 static UrlByScheme _v;
319 _(
"Unable to clone Url object")
332 _(
"Invalid empty Url object reference")
345 _(
"Unable to parse Url components")
359 _(
"Unable to parse Url components")
382 return g_urlSchemeRepository().addUrlByScheme(scheme, std::move(urlImpl));
403 if(ret && out.
size() == 6)
405 std::string scheme = out[1];
406 if (scheme.size() > 1)
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);
418 url = g_urlSchemeRepository().getUrlByScheme(scheme);
423 url->init(scheme, authority, out[3],
435 return g_urlSchemeRepository().getRegisteredSchemes();
444 return g_urlSchemeRepository().isRegisteredScheme(scheme);
452 return m_impl->getKnownSchemes();
460 return m_impl->isValidScheme(scheme);
467 inline bool isInList(
const char ** begin_r,
const char ** end_r,
const std::string & scheme_r )
469 for ( ; begin_r != end_r; ++begin_r )
470 if ( scheme_r == *begin_r )
477 static const char * val[] = {
"cd",
"dvd",
"dir",
"hd",
"iso",
"file" };
483 static const char * val[] = {
"http",
"https",
"nfs",
"nfs4",
"smb",
"cifs",
"ftp",
"sftp",
"tftp" };
489 static const char * val[] = {
"cd",
"dvd" };
495 static const char * val[] = {
"http",
"https",
"ftp",
"sftp",
"tftp" };
501 return scheme_r ==
"plugin";
517 return m_impl->asString();
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);
545 return m_impl->asString(opts);
553 return m_impl->getScheme();
561 return m_impl->getAuthority();
568 return m_impl->getPathData();
576 return m_impl->getQueryString();
584 return m_impl->getFragment(eflag);
592 return m_impl->getUsername(eflag);
600 return m_impl->getPassword(eflag);
608 return m_impl->getHost(eflag);
624 return m_impl->getPathName(eflag);
632 return m_impl->getPathParams();
640 return m_impl->getPathParamsVec();
648 return m_impl->getPathParamsMap(eflag);
656 return m_impl->getPathParam(param, eflag);
664 return m_impl->getQueryStringVec();
672 return m_impl->getQueryStringMap(eflag);
680 return m_impl->getQueryParam(param, eflag);
688 if(scheme ==
m_impl->getScheme())
692 if(
m_impl->isKnownScheme(scheme))
694 m_impl->setScheme(scheme);
698 UrlRef url = g_urlSchemeRepository().getUrlByScheme(scheme);
718 m_impl->setAuthority(authority);
726 m_impl->setPathData(pathdata);
734 m_impl->setQueryString(querystr);
742 m_impl->setFragment(fragment, eflag);
751 m_impl->setUsername(user, eflag);
760 m_impl->setPassword(pass, eflag);
785 m_impl->setPathName(path, eflag);
799 m_impl->setPathName(path, eflag);
810 if ( upath.empty() ) {
820 if ( doubleslhash ) {
832 if ( upath.empty() || upath ==
"/" || upath ==
"//" )
840 do { upath.pop_back(); }
while (
str::endsWith( upath,
"/" ) );
849 m_impl->setPathParams(params);
857 m_impl->setPathParamsVec(pvec);
865 m_impl->setPathParamsMap(pmap);
873 m_impl->setPathParam(param, value);
881 m_impl->setQueryStringVec(pvec);
896 m_impl->setQueryParam(param, value);
903 m_impl->delQueryParam(param);
909 m_impl->delQueryParams(params);
916 return m_impl->getViewOptions();
923 m_impl->setViewOptions(vopts);
929 return str <<
url.asString();
bool schemeIsPlugin() const
void delQueryParams(const std::set< std::string > ¶ms)
remove multiple query parameters at once
std::string getScheme() const
Returns the scheme name of the URL.
std::string asCompleteString() const
Returns a complete string representation of the Url object.
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
void setAuthority(const std::string &authority)
Set the authority component in the URL.
zypp::url::ParamMap getPathParamsMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with path parameter keys and values.
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
zypp::url::ViewOptions ViewOptions
View options.
void setQueryString(const std::string &querystr)
Set the query string in the URL.
bool schemeIsRemote() const
std::string getPathParams() const
Returns the path parameters from the URL.
std::string asString() const
Returns a default string representation of the Url object.
std::string getPathData() const
Returns the encoded path component of the URL.
std::string getPathParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified path parameter.
std::string getAuthority() const
Returns the encoded authority component of the URL.
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
ViewOptions getViewOptions() const
Return the view options of the current object.
bool schemeIsDownloading() const
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
void setPort(const std::string &port)
Set the port number in the URL authority.
void delQueryParam(const std::string ¶m)
remove the specified query parameter.
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
bool isValid() const
Verifies the Url.
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
void setPathParam(const std::string ¶m, const std::string &value)
Set or add value for the specified path parameter.
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
void setPathParams(const std::string ¶ms)
Set the path parameters.
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
zypp::url::EEncoding EEncoding
Encoding flags.
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
std::string getQueryString() const
Returns the encoded query string component of the URL.
bool isValidScheme(const std::string &scheme) const
Verifies the specified scheme name.
void setQueryParam(const std::string ¶m, const std::string &value)
Set or add value for the specified query parameter.
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
void pathNameSetTrailingSlash(bool apply_r=true)
Apply or remove a trailing '/' from pathName.
bool schemeIsLocal() const
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
bool schemeIsVolatile() const
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
std::string getPort() const
Returns the port from the URL authority.
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
bool emptyOrRoot() const
Test for "" or "/".
const std::string & asString() const
String representation.
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Regular expression match result.
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
virtual void clear()
Clears all data in the object.
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
std::string asString1050625() const
Base class for all URL exceptions.
Thrown if the url or a component can't be parsed at all.
String related utilities and Regular expression matching.
std::string asString(const Url &url_r)
std::string toLower(const std::string &s)
Return lowercase version of s.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
std::string encode(const std::string &str, const std::string &safe, EEncoding eflag)
Encodes a string using URL percent encoding.
std::vector< std::string > ParamVec
A parameter vector container.
ViewOption ViewOptions
ViewOptions is just an alias for ViewOption.
std::string join(const ParamVec &pvec, const std::string &psep)
Join parameter vector to a string.
std::map< std::string, std::string > ParamMap
A parameter map container.
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
@ E_DECODED
Flag to request decoded string(s).
@ E_ENCODED
Flag to request encoded string(s).
std::string decode(const std::string &str, bool allowNUL)
Decodes a URL percent encoded string.
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.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.