34 #define RX_SPLIT_URL "^([^:/?#]+:|)" \
61 return new LDAPUrl(*
this);
65 getKnownSchemes()
const
76 config(
"sep_pathparams",
"");
78 config(
"psep_querystr",
"?");
79 config(
"vsep_querystr",
"");
84 config(
"require_host",
"y");
87 config(
"rx_username",
"");
88 config(
"rx_password",
"");
89 config(
"rx_fragment",
"");
90 config(
"rx_pathparams",
"");
96 static const char *
const keys[] = {
97 "attrs",
"scope",
"filter",
"exts", NULL
101 if( pvec.size() <= 4)
103 for(
size_t i=0; i<pvec.size(); i++)
106 pmap[keys[i]] = pvec[i];
114 _(
"Invalid LDAP URL query string")
123 static const char *
const keys[] = {
124 "attrs",
"scope",
"filter",
"exts", NULL
128 std::string join_safe;
129 std::string safe(config(
"safe_querystr"));
130 std::string psep(config(
"psep_querystr"));
133 if( psep.find(safe[i]) == std::string::npos)
134 join_safe.append(1, safe[i]);
138 zypp::url::ParamMap::const_iterator p;
139 for(p=pmap.begin(); p!=pmap.end(); ++p)
142 for(
size_t i=0; i<4; i++)
144 if(p->first == keys[i])
153 str::form(
_(
"Invalid LDAP URL query parameter '%s'"),
158 setQueryStringVec(pvec);
168 typedef std::map<std::string,UrlRef> UrlBySchemeMap;
177 ref.
reset(
new LDAPUrl());
178 addUrlByScheme(
"ldap", ref);
179 addUrlByScheme(
"ldaps", ref);
184 ref->
config(
"with_authority",
"n");
185 ref->
config(
"require_pathname",
"m");
186 addUrlByScheme(
"hd", ref);
187 addUrlByScheme(
"cd", ref);
188 addUrlByScheme(
"dvd", ref);
189 addUrlByScheme(
"dir", ref);
190 addUrlByScheme(
"iso", ref);
195 addUrlByScheme(
"mailto", ref);
196 addUrlByScheme(
"urn", ref);
197 addUrlByScheme(
"plugin", ref);
200 ref->
config(
"with_authority",
"y");
201 ref->
config(
"with_port",
"n");
202 ref->
config(
"rx_username",
"");
203 ref->
config(
"rx_password",
"");
204 addUrlByScheme(
"file", ref);
208 ref->
config(
"require_host",
"m");
209 addUrlByScheme(
"nfs", ref);
210 addUrlByScheme(
"nfs4", ref);
211 addUrlByScheme(
"smb", ref);
212 addUrlByScheme(
"cifs", ref);
213 addUrlByScheme(
"http", ref);
214 addUrlByScheme(
"https", ref);
215 ref->
config(
"path_encode_slash2",
"y");
216 addUrlByScheme(
"ftp", ref);
217 addUrlByScheme(
"sftp", ref);
218 addUrlByScheme(
"tftp", ref);
222 addUrlByScheme(
const std::string &scheme,
236 getUrlByScheme(
const std::string &scheme)
const
247 isRegisteredScheme(
const std::string &scheme)
const
253 getRegisteredSchemes()
const
255 UrlBySchemeMap::const_iterator i(
urlByScheme.begin());
261 schemes.push_back(i->first);
269 UrlByScheme & g_urlSchemeRepository()
271 static UrlByScheme _v;
295 : m_impl( url.m_impl)
300 _(
"Unable to clone Url object")
313 _(
"Invalid empty Url object reference")
321 : m_impl( parseUrl(encodedUrl))
326 _(
"Unable to parse Url components")
340 _(
"Unable to parse Url components")
363 return g_urlSchemeRepository().addUrlByScheme(scheme, urlImpl);
384 if(ret && out.
size() == 6)
386 std::string scheme = out[1];
387 if (scheme.size() > 1)
388 scheme = scheme.substr(0, scheme.size()-1);
389 std::string authority = out[2];
390 if (authority.size() >= 2)
391 authority = authority.substr(2);
392 std::string query = out[4];
393 if (query.size() > 1)
394 query = query.substr(1);
395 std::string fragment = out[5];
396 if (fragment.size() > 1)
397 fragment = fragment.substr(1);
399 url = g_urlSchemeRepository().getUrlByScheme(scheme);
404 url->
init(scheme, authority, out[3],
416 return g_urlSchemeRepository().getRegisteredSchemes();
425 return g_urlSchemeRepository().isRegisteredScheme(scheme);
448 inline bool isInList(
const char ** begin_r,
const char ** end_r,
const std::string & scheme_r )
450 for ( ; begin_r != end_r; ++begin_r )
451 if ( scheme_r == *begin_r )
458 static const char * val[] = {
"cd",
"dvd",
"dir",
"hd",
"iso",
"file" };
464 static const char * val[] = {
"http",
"https",
"nfs",
"nfs4",
"smb",
"cifs",
"ftp",
"sftp",
"tftp" };
470 static const char * val[] = {
"cd",
"dvd" };
476 static const char * val[] = {
"http",
"https",
"ftp",
"sftp",
"tftp" };
674 UrlRef url = g_urlSchemeRepository().getUrlByScheme(scheme);
void setPassword(const std::string &pass, EEncoding eflag=zypp::url::E_DECODED)
Set the password in the URL authority.
virtual std::string getQueryParam(const std::string ¶m, EEncoding eflag) const
Return the value for the specified query parameter.
static const ViewOption WITH_USERNAME
Option to include username in the URL string.
virtual std::string getQueryString() const
Returns the encoded query string component of the URL.
std::vector< std::string > ParamVec
A parameter vector container.
static const ViewOption WITH_FRAGMENT
Option to include fragment string in the URL string.
std::map< std::string, std::string > ParamMap
A parameter map container.
virtual std::string getPathParam(const std::string ¶m, EEncoding eflag) const
Return the value for the specified path parameter.
void setPathParam(const std::string ¶m, const std::string &value)
Set or add value for the specified path parameter.
ViewOptions getViewOptions() const
Return the view options of the current object.
void setQueryParam(const std::string ¶m, const std::string &value)
Set or add value for the specified query parameter.
virtual void setQueryParam(const std::string ¶m, const std::string &value)
Set or add value for the specified query parameter.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
std::string getPathData() const
Returns the encoded path component of the URL.
bool operator!=(const CountryCode &lhs, const CountryCode &rhs)
bool schemeIsDownloading() const
std::vector< std::string > UrlSchemes
Vector of URL scheme names.
Flag to request encoded string(s).
ViewOptions getViewOptions() const
Return the view options of the current object.
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
static zypp::url::UrlSchemes getRegisteredSchemes()
Returns all registered scheme names.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
std::string getHost(EEncoding eflag=zypp::url::E_DECODED) const
Returns the hostname or IP from the URL authority.
bool schemeIsVolatile() const
virtual void setUsername(const std::string &user, EEncoding eflag)
Set the username in the URL authority.
bool schemeIsRemote() const
static const ViewOption WITH_SCHEME
Option to include scheme name in the URL string.
static const ViewOption WITH_HOST
Option to include hostname in the URL string.
virtual void setPathData(const std::string &pathdata)
Set the path data component in the URL.
virtual std::string getPathData() const
Returns the encoded path component of the URL.
void setPathParams(const std::string ¶ms)
Set the path parameters.
std::string encode(const std::string &str, const std::string &safe, EEncoding eflag)
Encodes a string using URL percent encoding.
Base class for all URL exceptions.
void setPort(const std::string &port)
Set the port number in the URL authority.
virtual std::string asString() const
Returns a default string representation of the Url object.
virtual std::string getUsername(EEncoding eflag) const
Returns the username from the URL authority.
std::string getUsername(EEncoding eflag=zypp::url::E_DECODED) const
Returns the username from the URL authority.
void setUsername(const std::string &user, EEncoding eflag=zypp::url::E_DECODED)
Set the username in the URL authority.
void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
static bool registerScheme(const std::string &scheme, url::UrlRef urlImpl)
Register a scheme-specific implementation.
virtual void setPort(const std::string &port)
Set the port number in the URL authority.
bool isValid() const
Verifies the Url.
void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
static const ViewOption WITH_PATH_NAME
Option to include path name in the URL string.
Url::asString() view options.
void setFragment(const std::string &fragment, EEncoding eflag=zypp::url::E_DECODED)
Set the fragment string in the URL.
void setViewOptions(const ViewOptions &vopts)
Change the view options of the current object.
virtual void setAuthority(const std::string &authority)
Set the authority component in the URL.
virtual std::string getScheme() const
Returns the scheme name of the URL.
void setAuthority(const std::string &authority)
Set the authority component in the URL.
virtual void setHost(const std::string &host)
Set the hostname or IP in the URL authority.
virtual void setPathParams(const std::string ¶ms)
Set the path parameters.
std::string getPathParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified path parameter.
std::string asString() const
Returns a default string representation of the Url object.
virtual void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
UrlBySchemeMap urlByScheme
Thrown if the url or a component can't be parsed at all.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
zypp::url::UrlSchemes getKnownSchemes() const
Returns scheme names known to this object.
virtual void setFragment(const std::string &fragment, EEncoding eflag)
Set the fragment string in the URL.
zypp::url::ParamMap getQueryStringMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with query parameter and their values.
virtual void setPassword(const std::string &pass, EEncoding eflag)
Set the password in the URL authority.
static bool isRegisteredScheme(const std::string &scheme)
Returns if scheme name is registered.
virtual zypp::url::ParamMap getQueryStringMap(EEncoding eflag) const
Returns a string map with query parameter and their values.
std::string asCompleteString() const
Returns a complete string representation of the Url object.
std::ostream & operator<<(std::ostream &str, const Exception &obj)
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
virtual void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
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.
static url::UrlRef parseUrl(const std::string &encodedUrl)
Parse a percent-encoded URL string.
bool schemeIsLocal() const
std::string getPathParams() const
Returns the path parameters from the URL.
static const ViewOption EMPTY_AUTHORITY
Explicitely include the URL authority separator "//".
virtual zypp::url::ParamVec getPathParamsVec() const
Returns a vector with encoded path parameter substrings.
void setPathData(const std::string &pathdata)
Set the path data component in the URL.
static const ViewOption WITH_PATH_PARAMS
Option to include path parameters in the URL string.
Url & operator=(const std::string &encodedUrl)
Assigns parsed percent-encoded URL string to the object.
virtual void setScheme(const std::string &scheme)
Set the scheme name in the URL.
virtual bool isValid() const
Verifies the Url.
std::string getQueryString() const
Returns the encoded query string component of the URL.
#define _(MSG)
Return translated text.
virtual void setQueryString(const std::string &querystr)
Set the query string in the URL.
virtual std::string getPathParams() const
Returns the encoded path parameters from the URL.
std::string getQueryParam(const std::string ¶m, EEncoding eflag=zypp::url::E_DECODED) const
Return the value for the specified query parameter.
zypp::url::ParamMap getPathParamsMap(EEncoding eflag=zypp::url::E_DECODED) const
Returns a string map with path parameter keys and values.
std::string getFragment(EEncoding eflag=zypp::url::E_DECODED) const
Returns the encoded fragment component of the URL.
std::string toLower(const std::string &s)
Return lowercase version of s.
virtual zypp::url::ParamVec getQueryStringVec() const
Returns a vector with query string parameter substrings.
bool operator==(const StrMatcher &lhs, const StrMatcher &rhs)
virtual void setPathName(const std::string &path, EEncoding eflag)
Set the path name.
#define arrayBegin(A)
Simple C-array iterator.
std::string form(const char *format,...)
Printf style construction of std::string.
static const ViewOption WITH_QUERY_STR
Option to include query string in the URL string.
Regular expression match result.
virtual std::string getPort() const
Returns the port number from the URL authority.
void setQueryString(const std::string &querystr)
Set the query string in the URL.
static const ViewOption WITH_PASSWORD
Option to include password in the URL string.
std::string getPort() const
Returns the port from the URL authority.
virtual std::string getAuthority() const
Returns the encoded authority component of the URL.
virtual zypp::url::ParamMap getPathParamsMap(EEncoding eflag) const
Returns a string map with path parameter keys and values.
virtual std::string getHost(EEncoding eflag) const
Returns the hostname or IP from the URL authority.
virtual bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
virtual std::string getFragment(EEncoding eflag) const
Returns the encoded fragment component of the URL.
zypp::url::ParamVec getPathParamsVec() const
Returns a vector with path parameter substrings.
virtual std::string getPassword(EEncoding eflag) const
Returns the password from the URL authority.
virtual void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
regex ZYPP_STR_REGEX regex ZYPP_STR_REGEX
std::string getAuthority() const
Returns the encoded authority component of the URL.
static const ViewOption DEFAULTS
Default combination of view options.
virtual std::string getPathName(EEncoding eflag) const
Returns the path name from the URL.
virtual UrlSchemes getKnownSchemes() const
Returns scheme names known by this object.
std::string getScheme() const
Returns the scheme name of the URL.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
static const ViewOption WITH_PORT
Option to include port number in the URL string.
bool isValidScheme(const std::string &scheme) const
Verifies specified scheme name.
virtual void setPathParam(const std::string ¶m, const std::string &value)
Set or add value for the specified path parameter.
void setPathParamsVec(const zypp::url::ParamVec &pvec)
Set the path parameters.
void setPathParamsMap(const zypp::url::ParamMap &pmap)
Set the path parameters.
void setQueryStringMap(const zypp::url::ParamMap &qmap)
Set the query parameters.
virtual void setQueryStringVec(const zypp::url::ParamVec &qvec)
Set the query parameters.
virtual bool isKnownScheme(const std::string &scheme) const
Returns if scheme name is known to this object.
RWCOW_pointer< UrlBase > UrlRef
Copy-On-Write Url reference.
std::string config(const std::string &opt) const
Get the value of a UrlBase configuration variable.
virtual void delQueryParam(const std::string ¶m)
remove the specified query parameter.
std::string decode(const std::string &str, bool allowNUL)
Decodes a URL percent encoded string.
std::string getPassword(EEncoding eflag=zypp::url::E_DECODED) const
Returns the password from the URL authority.
void delQueryParam(const std::string ¶m)
remove the specified query parameter.