mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 12:12:15 +02:00
Removed OPENVPN_LEGACY_TITLE_ABSTRACTION
The recent commit "IP address/route classes: cleanup title usage with template approach" left in the old code and allowed it to be re-enabled by defining OPENVPN_LEGACY_TITLE_ABSTRACTION. This commit removes OPENVPN_LEGACY_TITLE_ABSTRACTION and makes the new code permanent. Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
parent
d7f4c1611d
commit
6c9f89b092
@ -56,8 +56,6 @@ namespace openvpn {
|
|||||||
V6_SIZE = IPv6::Addr::SIZE,
|
V6_SIZE = IPv6::Addr::SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
|
|
||||||
template <typename TITLE>
|
template <typename TITLE>
|
||||||
Addr(const Addr& other, const TITLE& title, const Version required_version)
|
Addr(const Addr& other, const TITLE& title, const Version required_version)
|
||||||
: ver(other.ver)
|
: ver(other.ver)
|
||||||
@ -157,81 +155,6 @@ namespace openvpn {
|
|||||||
throw ip_exception(internal::format_error(to_string(), title, version_string_static(required_version), "wrong IP version"));
|
throw ip_exception(internal::format_error(to_string(), title, version_string_static(required_version), "wrong IP version"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
Addr(const Addr& other, const char *title = nullptr, Version required_version = UNSPEC)
|
|
||||||
: ver(other.ver)
|
|
||||||
{
|
|
||||||
other.validate_version(title, required_version);
|
|
||||||
switch (ver)
|
|
||||||
{
|
|
||||||
case V4:
|
|
||||||
u.v4 = other.u.v4;
|
|
||||||
break;
|
|
||||||
case V6:
|
|
||||||
u.v6 = other.u.v6;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Addr(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC)
|
|
||||||
: Addr(from_string(ipstr, title, required_version))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SWIGPYTHON
|
|
||||||
// When calling IP:Addr with None as the second parameter, Swig will
|
|
||||||
// always pick this function and complain about not being able to convert
|
|
||||||
// a null pointer to a const std::string reference. Hide this function, so
|
|
||||||
// swig is forced to take the const char* variant of this function instead
|
|
||||||
Addr(const std::string& ipstr, const std::string& title, Version required_version = UNSPEC)
|
|
||||||
: Addr(from_string(ipstr, title.c_str(), required_version))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void validate_version(const char *title, Version required_version) const
|
|
||||||
{
|
|
||||||
if (required_version != UNSPEC && required_version != ver)
|
|
||||||
throw ip_exception(internal::format_error(to_string(), title, version_string_static(required_version), "wrong IP version"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SWIGPYTHON
|
|
||||||
void validate_version(const std::string& title, Version required_version) const
|
|
||||||
{
|
|
||||||
validate_version(title.c_str(), required_version);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static std::string validate(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC)
|
|
||||||
{
|
|
||||||
Addr a = from_string(ipstr, title, required_version);
|
|
||||||
return a.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef SWIGPYTHON
|
|
||||||
static std::string validate(const std::string& ipstr, const std::string& title, Version required_version = UNSPEC)
|
|
||||||
{
|
|
||||||
return validate(ipstr, title.c_str(), required_version);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static Addr from_string(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC)
|
|
||||||
{
|
|
||||||
openvpn_io::error_code ec;
|
|
||||||
openvpn_io::ip::address a = openvpn_io::ip::make_address(ipstr, ec);
|
|
||||||
if (ec)
|
|
||||||
throw ip_exception(internal::format_error(ipstr, title, "", ec));
|
|
||||||
const Addr ret = from_asio(a);
|
|
||||||
if (required_version != UNSPEC && required_version != ret.ver)
|
|
||||||
throw ip_exception(internal::format_error(ipstr, title, version_string_static(required_version), "wrong IP version"));
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool is_valid(const std::string& ipstr)
|
static bool is_valid(const std::string& ipstr)
|
||||||
{
|
{
|
||||||
// fast path -- rule out validity if invalid chars
|
// fast path -- rule out validity if invalid chars
|
||||||
|
@ -27,16 +27,12 @@
|
|||||||
|
|
||||||
#include <openvpn/io/io.hpp>
|
#include <openvpn/io/io.hpp>
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
#include <openvpn/common/stringtempl2.hpp>
|
#include <openvpn/common/stringtempl2.hpp>
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace openvpn {
|
namespace openvpn {
|
||||||
namespace IP {
|
namespace IP {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
|
|
||||||
template <typename TITLE>
|
template <typename TITLE>
|
||||||
inline std::string format_error(const std::string& ipstr,
|
inline std::string format_error(const std::string& ipstr,
|
||||||
const TITLE& title,
|
const TITLE& title,
|
||||||
@ -71,47 +67,6 @@ namespace openvpn {
|
|||||||
return format_error(ipstr, title, ipver, ec.message());
|
return format_error(ipstr, title, ipver, ec.message());
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
inline std::string format_error(const std::string& ipstr, const char *title, const char *ipver, const openvpn_io::error_code& ec)
|
|
||||||
{
|
|
||||||
std::string err = "error parsing";
|
|
||||||
if (title)
|
|
||||||
{
|
|
||||||
err += ' ';
|
|
||||||
err += title;
|
|
||||||
}
|
|
||||||
err += " IP";
|
|
||||||
err += ipver;
|
|
||||||
err += " address '";
|
|
||||||
err += ipstr;
|
|
||||||
err += "' : ";
|
|
||||||
err += ec.message();
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::string format_error(const std::string& ipstr, const char *title, const char *ipver, const char *message)
|
|
||||||
{
|
|
||||||
std::string err = "error parsing";
|
|
||||||
if (title)
|
|
||||||
{
|
|
||||||
err += ' ';
|
|
||||||
err += title;
|
|
||||||
}
|
|
||||||
err += " IP";
|
|
||||||
err += ipver;
|
|
||||||
err += " address '";
|
|
||||||
err += ipstr;
|
|
||||||
err += '\'';
|
|
||||||
if (message)
|
|
||||||
{
|
|
||||||
err += " : ";
|
|
||||||
err += message;
|
|
||||||
}
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,8 +206,6 @@ namespace openvpn {
|
|||||||
return netmask_from_prefix_len(SIZE - lb);
|
return netmask_from_prefix_len(SIZE - lb);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
|
|
||||||
template <typename TITLE>
|
template <typename TITLE>
|
||||||
static Addr from_string(const std::string& ipstr, const TITLE& title)
|
static Addr from_string(const std::string& ipstr, const TITLE& title)
|
||||||
{
|
{
|
||||||
@ -223,19 +221,6 @@ namespace openvpn {
|
|||||||
return from_string(ipstr, nullptr);
|
return from_string(ipstr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static Addr from_string(const std::string& ipstr, const char *title = nullptr)
|
|
||||||
{
|
|
||||||
openvpn_io::error_code ec;
|
|
||||||
openvpn_io::ip::address_v4 a = openvpn_io::ip::make_address_v4(ipstr, ec);
|
|
||||||
if (ec)
|
|
||||||
throw ipv4_exception(IP::internal::format_error(ipstr, title, "v4", ec));
|
|
||||||
return from_asio(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
const openvpn_io::ip::address_v4 a = to_asio();
|
const openvpn_io::ip::address_v4 a = to_asio();
|
||||||
|
@ -100,8 +100,6 @@ namespace openvpn {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
|
|
||||||
template <typename TITLE>
|
template <typename TITLE>
|
||||||
static Addr from_string(const std::string& ipstr, const TITLE& title)
|
static Addr from_string(const std::string& ipstr, const TITLE& title)
|
||||||
{
|
{
|
||||||
@ -117,19 +115,6 @@ namespace openvpn {
|
|||||||
return from_string(ipstr, nullptr);
|
return from_string(ipstr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static Addr from_string(const std::string& ipstr, const char *title = nullptr)
|
|
||||||
{
|
|
||||||
openvpn_io::error_code ec;
|
|
||||||
openvpn_io::ip::address_v6 a = openvpn_io::ip::make_address_v6(ipstr, ec);
|
|
||||||
if (ec)
|
|
||||||
throw ipv6_exception(IP::internal::format_error(ipstr, title, "v6", ec));
|
|
||||||
return from_asio(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::string to_string() const
|
std::string to_string() const
|
||||||
{
|
{
|
||||||
const openvpn_io::ip::address_v6 a = to_asio();
|
const openvpn_io::ip::address_v6 a = to_asio();
|
||||||
|
@ -62,8 +62,6 @@ namespace openvpn {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
|
|
||||||
template <typename TITLE>
|
template <typename TITLE>
|
||||||
RouteType(const std::string& rtstr, const TITLE& title)
|
RouteType(const std::string& rtstr, const TITLE& title)
|
||||||
: RouteType(RouteType::from_string(rtstr, title))
|
: RouteType(RouteType::from_string(rtstr, title))
|
||||||
@ -99,38 +97,6 @@ namespace openvpn {
|
|||||||
return from_string(rtstr, nullptr);
|
return from_string(rtstr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
RouteType(const std::string& rtstr, const char *title = nullptr)
|
|
||||||
: RouteType(RouteType::from_string(rtstr, title))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
RouteType(const std::string& rtstr, const std::string& title)
|
|
||||||
: RouteType(RouteType::from_string(rtstr, title.c_str()))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static RouteType from_string(const std::string& rtstr, const char *title = nullptr)
|
|
||||||
{
|
|
||||||
RouteType r;
|
|
||||||
std::vector<std::string> pair;
|
|
||||||
pair.reserve(2);
|
|
||||||
Split::by_char_void<std::vector<std::string>, NullLex, Split::NullLimit>(pair, rtstr, '/', 0, 1);
|
|
||||||
r.addr = ADDR::from_string(pair[0], title);
|
|
||||||
if (pair.size() >= 2)
|
|
||||||
{
|
|
||||||
r.prefix_len = parse_number_throw<unsigned int>(pair[1], "prefix length");
|
|
||||||
if (r.prefix_len > r.addr.size())
|
|
||||||
OPENVPN_THROW(route_error, (title ? title : "route") << " : bad prefix length : " << rtstr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
r.prefix_len = r.addr.size();
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool defined() const
|
bool defined() const
|
||||||
{
|
{
|
||||||
return addr.defined();
|
return addr.defined();
|
||||||
@ -352,8 +318,6 @@ namespace openvpn {
|
|||||||
OPENVPN_OSTREAM(Route4List, to_string);
|
OPENVPN_OSTREAM(Route4List, to_string);
|
||||||
OPENVPN_OSTREAM(Route6List, to_string);
|
OPENVPN_OSTREAM(Route6List, to_string);
|
||||||
|
|
||||||
#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
|
|
||||||
|
|
||||||
template <typename TITLE>
|
template <typename TITLE>
|
||||||
inline Route route_from_string_prefix(const std::string& addrstr,
|
inline Route route_from_string_prefix(const std::string& addrstr,
|
||||||
const unsigned int prefix_len,
|
const unsigned int prefix_len,
|
||||||
@ -378,32 +342,6 @@ namespace openvpn {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
inline Route route_from_string_prefix(const std::string& addrstr,
|
|
||||||
const unsigned int prefix_len,
|
|
||||||
const std::string& title,
|
|
||||||
const IP::Addr::Version required_version = IP::Addr::UNSPEC)
|
|
||||||
{
|
|
||||||
Route r;
|
|
||||||
r.addr = IP::Addr(addrstr, title, required_version);
|
|
||||||
r.prefix_len = prefix_len;
|
|
||||||
if (r.prefix_len > r.addr.size())
|
|
||||||
OPENVPN_THROW(Route::route_error, title << " : bad prefix length : " << addrstr);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Route route_from_string(const std::string& rtstr,
|
|
||||||
const std::string& title,
|
|
||||||
const IP::Addr::Version required_version = IP::Addr::UNSPEC)
|
|
||||||
{
|
|
||||||
Route r(rtstr, title);
|
|
||||||
r.addr.validate_version(title, required_version);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user