diff --git a/src/beast/beast/net/IPAddress.h b/src/beast/beast/net/IPAddress.h index fa98ee344..a0e1af1d7 100644 --- a/src/beast/beast/net/IPAddress.h +++ b/src/beast/beast/net/IPAddress.h @@ -334,7 +334,6 @@ private: /** Comparison. */ /** @{ */ -int compare (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); @@ -342,7 +341,6 @@ bool operator<= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs); -int compare (IPAddress const& lhs, IPAddress const& rhs); bool operator== (IPAddress const& lhs, IPAddress const& rhs); bool operator!= (IPAddress const& lhs, IPAddress const& rhs); bool operator< (IPAddress const& lhs, IPAddress const& rhs); diff --git a/src/beast/beast/net/impl/IPAddress.cpp b/src/beast/beast/net/impl/IPAddress.cpp index f6a75f179..10701a11f 100644 --- a/src/beast/beast/net/impl/IPAddress.cpp +++ b/src/beast/beast/net/impl/IPAddress.cpp @@ -554,58 +554,71 @@ IPAddress IPAddress::from_string_altform (std::string const& s) //------------------------------------------------------------------------------ -int compare (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) +bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) + { return lhs.value == rhs.value; } + +bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) + { return lhs.value < rhs.value; } + +bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) + { return ! (lhs == rhs); } + +bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) + { return rhs < lhs; } + +bool operator<= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) + { return ! (rhs < lhs); } + +bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) + { return ! (lhs < rhs); } + +//------------------------------------------------------------------------------ + +bool operator== (IPAddress const& lhs, IPAddress const& rhs) { - if (lhs.value < rhs.value) - return -1; - else if (lhs.value > rhs.value) - return 1; - return 0; -} - -bool operator== (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) == 0; } -bool operator!= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) != 0; } -bool operator< (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) < 0; } -bool operator<= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) <= 0; } -bool operator> (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) > 0; } -bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) >= 0; } - -static int type_compare (IPAddress const& lhs, IPAddress const& rhs) -{ - if (lhs.type() < rhs.type()) - return -1; - else if (lhs.type() > rhs.type()) - return 1; - return 0; -} - -int compare (IPAddress const& lhs, IPAddress const& rhs) -{ - int const tc (type_compare (lhs, rhs)); - - if (tc < 0) - return -1; - else if (tc > 0) - return 1; - + if (lhs.type() != rhs.type()) + return false; switch (lhs.type()) { - case IPAddress::none: return 0; - case IPAddress::ipv4: return compare (lhs.v4(), rhs.v4()); - default: + case IPAddress::none: return true; + case IPAddress::ipv4: return lhs.v4() == rhs.v4(); case IPAddress::ipv6: - break; - }; - bassertfalse; - return 0; + default: + bassertfalse; + } + return false; } -bool operator== (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) == 0; } -bool operator!= (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) != 0; } -bool operator< (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) < 0; } -bool operator<= (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) <= 0; } -bool operator> (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) > 0; } -bool operator>= (IPAddress const& lhs, IPAddress const& rhs) { return compare (lhs, rhs) >= 0; } +bool operator< (IPAddress const& lhs, IPAddress const& rhs) +{ + if (lhs.type() > rhs.type()) + return false; + if (lhs.type() < rhs.type()) + return true; + switch (lhs.type()) + { + case IPAddress::none: return true; + case IPAddress::ipv4: return lhs.v4() < rhs.v4(); + case IPAddress::ipv6: + default: + bassertfalse; + } + return false; +} + +bool operator!= (IPAddress const& lhs, IPAddress const& rhs) + { return ! (lhs == rhs); } + +bool operator> (IPAddress const& lhs, IPAddress const& rhs) + { return rhs < lhs; } + +bool operator<= (IPAddress const& lhs, IPAddress const& rhs) + { return ! (rhs < lhs); } + +bool operator>= (IPAddress const& lhs, IPAddress const& rhs) + { return ! (lhs < rhs); } + +//------------------------------------------------------------------------------ std::ostream& operator<< (std::ostream &os, IPAddress::V4 const& addr) { diff --git a/src/ripple/http/api/Port.h b/src/ripple/http/api/Port.h index fd7d72226..eff163c2d 100644 --- a/src/ripple/http/api/Port.h +++ b/src/ripple/http/api/Port.h @@ -47,7 +47,6 @@ struct Port SSLContext* context; }; -int compare (Port const& lhs, Port const& rhs); bool operator== (Port const& lhs, Port const& rhs); bool operator!= (Port const& lhs, Port const& rhs); bool operator< (Port const& lhs, Port const& rhs); diff --git a/src/ripple/http/impl/Port.cpp b/src/ripple/http/impl/Port.cpp index 235d25499..ec308ce91 100644 --- a/src/ripple/http/impl/Port.cpp +++ b/src/ripple/http/impl/Port.cpp @@ -56,35 +56,50 @@ Port::Port ( { } -int compare (Port const& lhs, Port const& rhs) +bool operator== (Port const& lhs, Port const& rhs) { - int comp; - - comp = compare (lhs.addr, rhs.addr); - if (comp != 0) - return comp; - - if (lhs.port < rhs.port) - return -1; - else if (lhs.port > rhs.port) - return 1; - - if (lhs.security < rhs.security) - return -1; - else if (lhs.security > rhs.security) - return 1; - + if (lhs.addr != rhs.addr) + return false; + if (lhs.port != rhs.port) + return false; + if (lhs.security != rhs.security) + return false; // 'context' does not participate in the comparison - - return 0; + return true; } -bool operator== (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) == 0; } -bool operator!= (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) != 0; } -bool operator< (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) < 0; } -bool operator<= (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) <= 0; } -bool operator> (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) > 0; } -bool operator>= (Port const& lhs, Port const& rhs) { return compare (lhs, rhs) >= 0; } +bool operator< (Port const& lhs, Port const& rhs) +{ + if (lhs.addr > rhs.addr) + return false; + else if (lhs.addr < rhs.addr) + return true; + + if (lhs.port > rhs.port) + return false; + else if (lhs.port < rhs.port) + return true; + + if (lhs.security > rhs.security) + return false; + else if (lhs.security < rhs.security) + return true; + + return true; +} + +bool operator!= (Port const& lhs, Port const& rhs) + { return ! (lhs == rhs); } + +bool operator> (Port const& lhs, Port const& rhs) + { return rhs < lhs; } + +bool operator<= (Port const& lhs, Port const& rhs) + { return ! (rhs < lhs); } + +bool operator>= (Port const& lhs, Port const& rhs) + { return ! (lhs < rhs); } + } } diff --git a/src/ripple/http/impl/ServerImpl.cpp b/src/ripple/http/impl/ServerImpl.cpp index c7a451d64..0a9d86bfb 100644 --- a/src/ripple/http/impl/ServerImpl.cpp +++ b/src/ripple/http/impl/ServerImpl.cpp @@ -123,6 +123,16 @@ void ServerImpl::remove (Door& door) // // Thread // +//-------------------------------------------------------------------------- + +int ServerImpl::compare (Port const& lhs, Port const& rhs) +{ + if (lhs < rhs) + return -1; + else if (lhs > rhs) + return 1; + return 0; +} // Updates our Door list based on settings. // diff --git a/src/ripple/http/impl/ServerImpl.h b/src/ripple/http/impl/ServerImpl.h index 56f31f590..c8ca4160a 100644 --- a/src/ripple/http/impl/ServerImpl.h +++ b/src/ripple/http/impl/ServerImpl.h @@ -72,8 +72,11 @@ public: void handle_update (); void update (); void run (); + + static int compare (Port const& lhs, Port const& rhs); }; + } }