* \file zypp/Url.cc
*/
#include <zypp/Url.h>
+#include <zypp/base/Gettext.h>
#include <zypp/base/String.h>
+#include <zypp/base/Regex.h>
#include <stdexcept>
+#include <iostream>
//////////////////////////////////////////////////////////////////////
/*
* url = [scheme:] [//authority] /path [?query] [#fragment]
*/
- #define RX_SPLIT_URL "^(([^:/?#]+):)?" \
- "(//([^/?#]*))?" \
+ #define RX_SPLIT_URL "^([^:/?#]+:|)" \
+ "(//[^/?#]*|)" \
"([^?#]*)" \
- "([?]([^#]*))?" \
- "(#(.*))?"
+ "([?][^#]*|)" \
+ "(#.*|)"
////////////////////////////////////////////////////////////////////
config("psep_querystr", "?");
config("vsep_querystr", "");
+ // host is required (isValid=>false)
+ // but not mandatory (see RFC 2255),
+ // that is, accept empty host.
+ config("require_host", "y");
+
// not allowed here
config("rx_username", "");
config("rx_password", "");
else
{
ZYPP_THROW(url::UrlNotSupportedException(
- "Invalid LDAP URL query string"
+ _("Invalid LDAP URL query string")
));
}
return pmap;
if( !found)
{
ZYPP_THROW(url::UrlNotSupportedException(
- "Invalid LDAP URL query parameter '" + p->first + "'"
+ str::form(_("Invalid LDAP URL query parameter '%s'"),
+ p->first.c_str())
));
}
}
{
UrlRef ref;
+ // =====================================
ref.reset( new LDAPUrl());
addUrlByScheme("ldap", ref);
addUrlByScheme("ldaps", ref);
+
+ // =====================================
ref.reset( new UrlBase());
+ ref->config("with_authority", "n"); // disallow host,...
+ ref->config("require_pathname", "m"); // path is mandatory
+ addUrlByScheme("hd", ref);
+ addUrlByScheme("cd", ref);
+ addUrlByScheme("dvd", ref);
+ addUrlByScheme("dir", ref);
+ addUrlByScheme("iso", ref);
+
// don't show empty authority
ref->setViewOptions( zypp::url::ViewOption::DEFAULTS -
zypp::url::ViewOption::EMPTY_AUTHORITY);
- ref->config("rx_username", ""); // disallow username
- ref->config("rx_password", ""); // disallow password
- // FIXME: hmm... also host+port?
- addUrlByScheme("nfs", ref);
-
- ref->config("with_authority" "n"); // disallow host & port
addUrlByScheme("mailto", ref);
+ addUrlByScheme("urn", ref);
+
+ // RFC1738, 3.10: may contain a host
+ ref->config("with_authority", "y"); // allow host,
+ ref->config("with_port", "n"); // but no port,
+ ref->config("rx_username", ""); // username or
+ ref->config("rx_password", ""); // password ...
+ addUrlByScheme("file", ref);
+
+ // =====================================
+ ref.reset( new UrlBase());
+ ref->config("require_host", "m"); // host is mandatory
+ addUrlByScheme("nfs", ref);
+ addUrlByScheme("smb", ref);
+ addUrlByScheme("cifs", ref);
+ addUrlByScheme("http", ref);
+ addUrlByScheme("https", ref);
+ ref->config("path_encode_slash2", "y"); // always encode 2. slash
+ addUrlByScheme("ftp", ref);
+ addUrlByScheme("sftp", ref);
}
bool
UrlSchemes schemes;
schemes.reserve(urlByScheme.size());
- for( ; i != urlByScheme.begin(); ++i)
+ for( ; i != urlByScheme.end(); ++i)
{
schemes.push_back(i->first);
}
// ---------------------------------------------------------------
- UrlByScheme g_urlSchemeRepository;
-
+ UrlByScheme & g_urlSchemeRepository()
+ {
+ static UrlByScheme _v;
+ return _v;
+ }
//////////////////////////////////////////////////////////////////
} // anonymous namespace
if( !m_impl)
{
ZYPP_THROW(url::UrlException(
- "Unable to clone Url object"
+ _("Unable to clone Url object")
));
}
}
if( !m_impl)
{
ZYPP_THROW(url::UrlException(
- "Invalid empty Url reference"
+ _("Invalid empty Url object reference")
));
}
}
if( !m_impl)
{
ZYPP_THROW(url::UrlParsingException(
- "Unable to parse Url components"
+ _("Unable to parse Url components")
));
}
}
Url&
Url::operator = (const std::string &encodedUrl)
{
- UrlRef url( parseUrl(encodedUrl));
+ UrlRef url( parseUrl(encodedUrl));
if( !url)
{
ZYPP_THROW(url::UrlParsingException(
- "Unable to parse Url components"
+ _("Unable to parse Url components")
));
}
m_impl = url;
Url::registerScheme(const std::string &scheme,
UrlRef urlImpl)
{
- return g_urlSchemeRepository.addUrlByScheme(scheme, urlImpl);
+ return g_urlSchemeRepository().addUrlByScheme(scheme, urlImpl);
}
catch( ... )
{}
- if(ret && out.size() == 10)
+ if(ret && out.size() == 5)
{
- url = g_urlSchemeRepository.getUrlByScheme(out[2].str());
+ std::string scheme = out[1];
+ if (scheme.size() > 1)
+ scheme = scheme.substr(0, scheme.size()-1);
+ std::string authority = out[2];
+ if (authority.size() >= 2)
+ authority = authority.substr(2);
+ std::string query = out[4];
+ if (query.size() > 1)
+ query = query.substr(1);
+ std::string fragment = out[5];
+ if (fragment.size() > 1)
+ fragment = fragment.substr(1);
+
+ std::cout << "scheme: " << scheme << " authority: " << authority
+ << " query " << query << " fragment " << fragment << std::endl;
+
+ std::cout << "out[3] " << out[3] << std::endl;
+
+ url = g_urlSchemeRepository().getUrlByScheme(scheme);
if( !url)
{
url.reset( new UrlBase());
}
- url->init(out[2].str(),
- out[4].str(),
- out[5].str(),
- out[7].str(),
- out[9].str());
+ url->init(scheme, authority, out[3],
+ query, fragment);
}
return url;
}
zypp::url::UrlSchemes
Url::getRegisteredSchemes()
{
- return g_urlSchemeRepository.getRegisteredSchemes();
+ return g_urlSchemeRepository().getRegisteredSchemes();
}
bool
Url::isRegisteredScheme(const std::string &scheme)
{
- return g_urlSchemeRepository.isRegisteredScheme(scheme);
+ return g_urlSchemeRepository().isRegisteredScheme(scheme);
}
// -----------------------------------------------------------------
std::string
+ Url::asCompleteString() const
+ {
+ // make sure, all url components are included;
+ // regardless of the current configuration...
+ ViewOptions opts(getViewOptions() +
+ ViewOption::WITH_SCHEME +
+ ViewOption::WITH_USERNAME +
+ ViewOption::WITH_PASSWORD +
+ ViewOption::WITH_HOST +
+ ViewOption::WITH_PORT +
+ ViewOption::WITH_PATH_NAME +
+ ViewOption::WITH_PATH_PARAMS +
+ ViewOption::WITH_QUERY_STR +
+ ViewOption::WITH_FRAGMENT);
+ return m_impl->asString(opts);
+ }
+
+
+ // -----------------------------------------------------------------
+ std::string
Url::asString(const ViewOptions &opts) const
{
return m_impl->asString(opts);
return;
}
- UrlRef url = g_urlSchemeRepository.getUrlByScheme(scheme);
+ UrlRef url = g_urlSchemeRepository().getUrlByScheme(scheme);
if( !url)
{
url.reset( new UrlBase());
m_impl->setQueryParam(param, value);
}
+ // -----------------------------------------------------------------
+ ViewOptions
+ Url::getViewOptions() const
+ {
+ return m_impl->getViewOptions();
+ }
+
+ // -----------------------------------------------------------------
+ void
+ Url::setViewOptions(const ViewOptions &vopts)
+ {
+ m_impl->setViewOptions(vopts);
+ }
// -----------------------------------------------------------------
std::ostream & operator<<( std::ostream & str, const Url & url )
return str << url.asString();
}
+ bool operator<( const Url &lhs, const Url &rhs )
+ {
+ return (lhs.asCompleteString() < rhs.asCompleteString());
+ }
+ bool operator==( const Url &lhs, const Url &rhs )
+ {
+ return (lhs.asCompleteString() == rhs.asCompleteString());
+ }
+
+ bool operator!=( const Url &lhs, const Url &rhs )
+ {
+ return (lhs.asCompleteString() != rhs.asCompleteString());
+ }
+
////////////////////////////////////////////////////////////////////
} // namespace zypp
//////////////////////////////////////////////////////////////////////