diff --git a/openvpn/addr/ip.hpp b/openvpn/addr/ip.hpp index 6ffd1e57..c1d2bc70 100644 --- a/openvpn/addr/ip.hpp +++ b/openvpn/addr/ip.hpp @@ -56,8 +56,6 @@ namespace openvpn { V6_SIZE = IPv6::Addr::SIZE, }; -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION - template Addr(const Addr& other, const TITLE& title, const Version required_version) : 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")); } -#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) { // fast path -- rule out validity if invalid chars diff --git a/openvpn/addr/iperr.hpp b/openvpn/addr/iperr.hpp index 91635eb9..5cc98a79 100644 --- a/openvpn/addr/iperr.hpp +++ b/openvpn/addr/iperr.hpp @@ -27,16 +27,12 @@ #include -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION #include -#endif namespace openvpn { namespace IP { namespace internal { -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION - template inline std::string format_error(const std::string& ipstr, const TITLE& title, @@ -71,47 +67,6 @@ namespace openvpn { 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 } } } diff --git a/openvpn/addr/ipv4.hpp b/openvpn/addr/ipv4.hpp index df892602..6adbc120 100644 --- a/openvpn/addr/ipv4.hpp +++ b/openvpn/addr/ipv4.hpp @@ -206,8 +206,6 @@ namespace openvpn { return netmask_from_prefix_len(SIZE - lb); } -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION - template static Addr from_string(const std::string& ipstr, const TITLE& title) { @@ -223,19 +221,6 @@ namespace openvpn { 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 { const openvpn_io::ip::address_v4 a = to_asio(); diff --git a/openvpn/addr/ipv6.hpp b/openvpn/addr/ipv6.hpp index 17f55cec..af0ba8a0 100644 --- a/openvpn/addr/ipv6.hpp +++ b/openvpn/addr/ipv6.hpp @@ -100,8 +100,6 @@ namespace openvpn { return ret; } -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION - template static Addr from_string(const std::string& ipstr, const TITLE& title) { @@ -117,19 +115,6 @@ namespace openvpn { 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 { const openvpn_io::ip::address_v6 a = to_asio(); diff --git a/openvpn/addr/route.hpp b/openvpn/addr/route.hpp index b57c483c..52891c60 100644 --- a/openvpn/addr/route.hpp +++ b/openvpn/addr/route.hpp @@ -62,8 +62,6 @@ namespace openvpn { { } -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION - template RouteType(const std::string& rtstr, const TITLE& title) : RouteType(RouteType::from_string(rtstr, title)) @@ -99,38 +97,6 @@ namespace openvpn { 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 pair; - pair.reserve(2); - Split::by_char_void, 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(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 { return addr.defined(); @@ -352,8 +318,6 @@ namespace openvpn { OPENVPN_OSTREAM(Route4List, to_string); OPENVPN_OSTREAM(Route6List, to_string); -#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION - template inline Route route_from_string_prefix(const std::string& addrstr, const unsigned int prefix_len, @@ -378,32 +342,6 @@ namespace openvpn { 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 - } }