/**
* \file zypp/url/UrlBase.cc
*/
-#include <zypp/url/UrlBase.h>
-#include <zypp/base/String.h>
-#include <zypp/base/Gettext.h>
-
+#include "zypp/url/UrlBase.h"
+#include "zypp/base/String.h"
+#include "zypp/base/Gettext.h"
+#include "zypp/base/Regex.h"
+
#include <stdexcept>
#include <climits>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <iostream>
+
+// in the Estonian locale, a-z excludes t, for example. #302525
+// http://en.wikipedia.org/wiki/Estonian_alphabet
+#define a_zA_Z "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// ---------------------------------------------------------------
/*
**
** host = hostname | IPv4 | "[" IPv6-IP "]" | "[v...]"
*/
-#define RX_SPLIT_AUTHORITY \
- "^(([^:@]*)([:]([^@]*))?@)?(\\[[^]]+\\]|[^:]+)?([:](.*))?"
-
-#define RX_VALID_SCHEME "^[a-zA-Z][a-zA-Z0-9\\.+-]*$"
+#define RX_VALID_SCHEME "^[" a_zA_Z "][" a_zA_Z "0-9\\.+-]*$"
#define RX_VALID_PORT "^[0-9]{1,5}$"
const std::string &querystr,
const std::string &fragment)
{
- setScheme(scheme);
+ if ( scheme.empty() && *pathdata.c_str() == '/' )
+ setScheme("file");
+ else
+ setScheme(scheme);
+
setAuthority(authority);
setPathData(pathdata);
setQueryString(querystr);
// n=no (don't encode 2. slash if authority present)
config("path_encode_slash2", "n");
- config("rx_username", "^([a-zA-Z0-9!$&'\\(\\)*+=,;~\\._-]|%[a-fA-F0-9]{2})+$");
- config("rx_password", "^([a-zA-Z0-9!$&'\\(\\)*+=,:;~\\._-]|%[a-fA-F0-9]{2})+$");
+ config("rx_username", "^([" a_zA_Z "0-9!$&'\\(\\)*+=,;~\\._-]|%[a-fA-F0-9]{2})+$");
+ config("rx_password", "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;~\\._-]|%[a-fA-F0-9]{2})+$");
- config("rx_pathname", "^([a-zA-Z0-9!$&'\\(\\)*+=,:@/~\\._-]|%[a-fA-F0-9]{2})+$");
- config("rx_pathparams", "^([a-zA-Z0-9!$&'\\(\\)*+=,:;@/~\\._-]|%[a-fA-F0-9]{2})+$");
+ config("rx_pathname", "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:@/~\\._-]|%[a-fA-F0-9]{2})+$");
+ config("rx_pathparams", "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;@/~\\._-]|%[a-fA-F0-9]{2})+$");
- config("rx_querystr", "^([a-zA-Z0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
- config("rx_fragment", "^([a-zA-Z0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
+ config("rx_querystr", "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
+ config("rx_fragment", "^([" a_zA_Z "0-9!$&'\\(\\)*+=,:;@/?~\\._-]|%[a-fA-F0-9]{2})+$");
}
config("vsep_pathparam").empty())
{
ZYPP_THROW(UrlNotSupportedException(
- _("Path parameter parsing not supported for this URL")
+ "Path parameter parsing not supported for this URL"
));
}
zypp::url::ParamMap pmap;
void
UrlBase::setAuthority(const std::string &authority)
{
- str::smatch out;
- bool ret = false;
+ std::string s = authority;
+ std::string::size_type p,q;
- try
- {
- str::regex rex(RX_SPLIT_AUTHORITY);
- ret = str::regex_match(authority, out, rex);
- }
- catch( ... )
- {}
+ std::string username, password, host, port;
- if( ret && out.size() == 8)
+ if ((p=s.find('@')) != std::string::npos)
{
- setUsername(out[2].str(), zypp::url::E_ENCODED);
- setPassword(out[4].str(), zypp::url::E_ENCODED);
- setHost(out[5].str());
- setPort(out[7].str());
+ q = s.find(':');
+ if (q != std::string::npos && q < p)
+ {
+ setUsername(s.substr(0, q), zypp::url::E_ENCODED);
+ setPassword(s.substr(q+1, p-q-1), zypp::url::E_ENCODED);
+ }
+ else
+ setUsername(s.substr(0, p), zypp::url::E_ENCODED);
+ s = s.substr(p+1);
}
- else
+ if ((p = s.rfind(':')) != std::string::npos && ( (q = s.rfind(']')) == std::string::npos || q < p) )
{
- ZYPP_THROW(UrlParsingException(
- _("Unable to parse Url authority")
- ));
+ setHost(s.substr(0, p));
+ setPort(s.substr(p+1));
}
+ else
+ setHost(s);
}
// ---------------------------------------------------------------
config("vsep_pathparam").empty())
{
ZYPP_THROW(UrlNotSupportedException(
- _("Path Parameter parsing not supported for this URL")
+ "Path Parameter parsing not supported for this URL"
));
}
setPathParams(
setQueryStringMap(pmap);
}
+ // ---------------------------------------------------------------
+ void
+ UrlBase::delQueryParam(const std::string ¶m)
+ {
+ zypp::url::ParamMap pmap( getQueryStringMap(zypp::url::E_DECODED));
+ pmap.erase(param);
+ setQueryStringMap(pmap);
+ }
+
// ---------------------------------------------------------------
std::string
{
struct in6_addr ip;
std::string temp( host.substr(1, host.size()-2));
-
+
return inet_pton(AF_INET6, temp.c_str(), &ip) > 0;
}
else
}
catch( ... )
{}
-
return false;
}