Rename to IPAddress and remove unused files

This commit is contained in:
Vinnie Falco
2013-10-18 15:30:13 -07:00
parent 1c41dae51c
commit 2427cce2c8
46 changed files with 250 additions and 1315 deletions

View File

@@ -29,7 +29,7 @@ David Features:
- Look into using CMake
- IPv6 support in IPEndpoint
- IPv6 support in IPAddress
- Configuration list for Jenkins

View File

@@ -137,7 +137,7 @@
<ClInclude Include="..\..\beast\Net.h" />
<ClInclude Include="..\..\beast\net\BufferType.h" />
<ClInclude Include="..\..\beast\net\DynamicBuffer.h" />
<ClInclude Include="..\..\beast\net\IPEndpoint.h" />
<ClInclude Include="..\..\beast\net\IPAddress.h" />
<ClInclude Include="..\..\beast\SafeBool.h" />
<ClInclude Include="..\..\beast\SmartPtr.h" />
<ClInclude Include="..\..\beast\smart_ptr\ContainerDeletePolicy.h" />
@@ -303,7 +303,6 @@
<ClInclude Include="..\..\modules\beast_core\native\osx_ObjCHelpers.h" />
<ClInclude Include="..\..\modules\beast_core\native\posix_SharedCode.h" />
<ClInclude Include="..\..\modules\beast_core\native\win32_ComSmartPtr.h" />
<ClInclude Include="..\..\modules\beast_core\network\IPAddress.h" />
<ClInclude Include="..\..\modules\beast_core\network\MACAddress.h" />
<ClInclude Include="..\..\modules\beast_core\network\NamedPipe.h" />
<ClInclude Include="..\..\modules\beast_core\network\Socket.h" />
@@ -490,7 +489,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\beast\net\impl\IPEndpoint.cpp">
<ClCompile Include="..\..\beast\net\impl\IPAddress.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
@@ -1033,12 +1032,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\network\IPAddress.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\network\MACAddress.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>

View File

@@ -416,9 +416,6 @@
<ClInclude Include="..\..\modules\beast_core\native\win32_ComSmartPtr.h">
<Filter>beast_core\native</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\network\IPAddress.h">
<Filter>beast_core\network</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\network\MACAddress.h">
<Filter>beast_core\network</Filter>
</ClInclude>
@@ -932,9 +929,6 @@
<ClInclude Include="..\..\modules\beast_core\memory\SharedFunction.h">
<Filter>beast_core\memory</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\net\IPEndpoint.h">
<Filter>beast\net</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\Config.h">
<Filter>beast</Filter>
</ClInclude>
@@ -1254,6 +1248,9 @@
<ClInclude Include="..\..\beast\utility\BaseFromMember.h">
<Filter>beast\utility</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\net\IPAddress.h">
<Filter>beast\net</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
@@ -1361,9 +1358,6 @@
<ClCompile Include="..\..\modules\beast_core\native\win32_Threads.cpp">
<Filter>beast_core\native</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\network\IPAddress.cpp">
<Filter>beast_core\network</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\network\MACAddress.cpp">
<Filter>beast_core\network</Filter>
</ClCompile>
@@ -1682,9 +1676,6 @@
<ClCompile Include="..\..\modules\beast_extras\beast_extras.cpp">
<Filter>beast_extras</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\net\impl\IPEndpoint.cpp">
<Filter>beast\net\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\net\Net.cpp">
<Filter>beast\net</Filter>
</ClCompile>
@@ -1805,6 +1796,9 @@
<ClCompile Include="..\..\beast\utility\impl\PropertyStream.cpp">
<Filter>beast\utility\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\net\impl\IPAddress.cpp">
<Filter>beast\net\impl</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\TODO.txt">

View File

@@ -23,6 +23,6 @@
#include "net/BufferType.h"
#include "net/DynamicBuffer.h"
#include "net/IPEndpoint.h"
#include "net/IPAddress.h"
#endif

View File

@@ -17,8 +17,8 @@
*/
//==============================================================================
#ifndef BEAST_NET_IPENDPOINT_H_INCLUDED
#define BEAST_NET_IPENDPOINT_H_INCLUDED
#ifndef BEAST_NET_IPADDRESS_H_INCLUDED
#define BEAST_NET_IPADDRESS_H_INCLUDED
#include <string>
#include <ios>
@@ -27,11 +27,10 @@
#include "../CStdInt.h"
#include "../mpl/IfCond.h"
namespace beast
{
namespace beast {
/** Represents an IP address (v4 or v6) and port combination. */
class IPEndpoint
class IPAddress
{
public:
enum Type
@@ -216,62 +215,62 @@ public:
//--------------------------------------------------------------------------
/** Create an empty address. */
IPEndpoint ();
IPAddress ();
/** Create an IPv4 address with optional port. */
IPEndpoint (V4 const& v4, uint16 port = 0);
IPAddress (V4 const& v4, uint16 port = 0);
/** Create an IPv6 address with optional port. */
IPEndpoint (V6 const& v6, uint16 port = 0);
IPAddress (V6 const& v6, uint16 port = 0);
/** Create a copy of another IPEndpoint. */
IPEndpoint (IPEndpoint const& other);
/** Create a copy of another IPAddress. */
IPAddress (IPAddress const& other);
/** Copy assign another IPEndpoint. */
IPEndpoint& operator= (IPEndpoint const& other);
/** Copy assign another IPAddress. */
IPAddress& operator= (IPAddress const& other);
/** Create an IPEndpoint from a string.
/** Create an IPAddress from a string.
If a parsing error occurs, the endpoint will be empty.
*/
static IPEndpoint from_string (std::string const& s);
static IPAddress from_string (std::string const& s);
/** Create an IPEndpoint from a string.
/** Create an IPAddress from a string.
If a parsing error occurs, the endpoint will be empty.
This recognizes an alternate form of the text. Instead of a colon
separating the optional port specification, any amount of whitespace
is allowed.
*/
static IPEndpoint from_string_altform (std::string const& s);
static IPAddress from_string_altform (std::string const& s);
/** Copy assign an IPv4 address.
The port is set to zero.
*/
IPEndpoint& operator= (V4 const& address);
IPAddress& operator= (V4 const& address);
/** Copy assign an IPv6 address.
The port is set to zero.
*/
IPEndpoint& operator= (V6 const& address);
IPAddress& operator= (V6 const& address);
/** Returns a new IPEndpoint with this address, and the given port. */
IPEndpoint withPort (uint16 port) const;
/** Returns a new IPAddress with this address, and the given port. */
IPAddress withPort (uint16 port) const;
/** Returns `true` if this IPEndpoint refers to nothing. */
/** Returns `true` if this IPAddress refers to nothing. */
bool empty () const;
/** Returns `true` if this IPEndpoint refers to nothing. */
/** Returns `true` if this IPAddress refers to nothing. */
bool isNull () const;
/** Returns `true` if this IPEndpoint refers to something. */
/** Returns `true` if this IPAddress refers to something. */
bool isNotNull () const;
/** Returns the type of this IPEndpoint. */
/** Returns the type of this IPAddress. */
Type type () const;
/** Returns `true` if this IPEndpoint represents an IPv4 address. */
/** Returns `true` if this IPAddress represents an IPv4 address. */
bool isV4 () const;
/** Returns `true` if this IPEndpoint represents an IPv6 address. */
/** Returns `true` if this IPAddress represents an IPv6 address. */
bool isV6 () const;
/** Returns the IPv4 address.
@@ -312,7 +311,7 @@ public:
struct hasher
{
std::size_t operator() (IPEndpoint const& value) const
std::size_t operator() (IPAddress const& value) const
{
std::size_t hash (0);
if (value.isV4())
@@ -335,39 +334,39 @@ private:
/** Comparison. */
/** @{ */
int compare (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
bool operator== (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
bool operator!= (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
bool operator< (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
bool operator<= (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
bool operator> (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
bool operator>= (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs);
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);
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 (IPEndpoint const& lhs, IPEndpoint const& rhs);
bool operator== (IPEndpoint const& lhs, IPEndpoint const& rhs);
bool operator!= (IPEndpoint const& lhs, IPEndpoint const& rhs);
bool operator< (IPEndpoint const& lhs, IPEndpoint const& rhs);
bool operator<= (IPEndpoint const& lhs, IPEndpoint const& rhs);
bool operator> (IPEndpoint const& lhs, IPEndpoint const& rhs);
bool operator>= (IPEndpoint const& lhs, IPEndpoint 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);
bool operator<= (IPAddress const& lhs, IPAddress const& rhs);
bool operator> (IPAddress const& lhs, IPAddress const& rhs);
bool operator>= (IPAddress const& lhs, IPAddress const& rhs);
/** Output stream conversions. */
/** @{ */
std::ostream& operator<< (std::ostream& os, IPEndpoint::V4 const& addr);
std::ostream& operator<< (std::ostream& os, IPEndpoint::V6 const& addr);
std::ostream& operator<< (std::ostream& os, IPEndpoint const& ep);
std::ostream& operator<< (std::ostream& os, IPAddress::V4 const& addr);
std::ostream& operator<< (std::ostream& os, IPAddress::V6 const& addr);
std::ostream& operator<< (std::ostream& os, IPAddress const& ep);
/** @} */
/** Input stream conversions. */
/** @{ */
std::istream& operator>> (std::istream& is, IPEndpoint::V4& addr);
std::istream& operator>> (std::istream& is, IPEndpoint& ep);
//std::istream& operator>> (std::istream &is, IPEndpoint::V6&);
std::istream& operator>> (std::istream& is, IPAddress::V4& addr);
std::istream& operator>> (std::istream& is, IPAddress& ep);
//std::istream& operator>> (std::istream &is, IPAddress::V6&);
/** @} */
struct IPEndpoint::key_equal
struct IPAddress::key_equal
{
bool operator() (IPEndpoint const& lhs, IPEndpoint const& rhs) const
bool operator() (IPAddress const& lhs, IPAddress const& rhs) const
{
return lhs == rhs;
}

View File

@@ -24,4 +24,4 @@
#include "../../modules/beast_core/beast_core.h" // for UnitTest
#include "impl/DynamicBuffer.cpp"
#include "impl/IPEndpoint.cpp"
#include "impl/IPAddress.cpp"

View File

@@ -17,43 +17,42 @@
*/
//==============================================================================
#include "../IPEndpoint.h"
#include "../IPAddress.h"
namespace beast
{
namespace beast {
IPEndpoint::V4::V4 ()
IPAddress::V4::V4 ()
: value (0)
{
}
IPEndpoint::V4::V4 (uint32 value_)
IPAddress::V4::V4 (uint32 value_)
: value (value_)
{
}
IPEndpoint::V4::V4 (uint8 a, uint8 b, uint8 c, uint8 d)
IPAddress::V4::V4 (uint8 a, uint8 b, uint8 c, uint8 d)
: value ((a<<24)|(b<<16)|(c<<8)|d)
{
}
IPEndpoint::V4::V4 (V4 const& other)
IPAddress::V4::V4 (V4 const& other)
: value (other.value)
{
}
IPEndpoint::V4& IPEndpoint::V4::operator= (V4 const& other)
IPAddress::V4& IPAddress::V4::operator= (V4 const& other)
{
value = other.value;
return *this;
}
IPEndpoint::V4 IPEndpoint::V4::localBroadcastAddress ()
IPAddress::V4 IPAddress::V4::localBroadcastAddress ()
{
return V4 (0xffffffff);
}
IPEndpoint::V4 IPEndpoint::V4::broadcastAddress () const
IPAddress::V4 IPAddress::V4::broadcastAddress () const
{
switch (getClass())
{
@@ -68,18 +67,18 @@ IPEndpoint::V4 IPEndpoint::V4::broadcastAddress () const
return V4();
}
char IPEndpoint::V4::getClass () const
char IPAddress::V4::getClass () const
{
static char const* table = "AAAABBCD";
return table[(value&0xE0000000)>>29];
}
bool IPEndpoint::V4::isPublic () const
bool IPAddress::V4::isPublic () const
{
return !isPrivate() && !isBroadcast() && !isMulticast();
}
bool IPEndpoint::V4::isPrivate () const
bool IPAddress::V4::isPrivate () const
{
return
((value&0xff000000)==0x0a000000) || // Prefix /8, 10.##.#.#
@@ -88,22 +87,22 @@ bool IPEndpoint::V4::isPrivate () const
isLoopback();
}
bool IPEndpoint::V4::isBroadcast () const
bool IPAddress::V4::isBroadcast () const
{
return (value == broadcastAddress().value);
}
bool IPEndpoint::V4::isMulticast () const
bool IPAddress::V4::isMulticast () const
{
return getClass() == 'D';
}
bool IPEndpoint::V4::isLoopback () const
bool IPAddress::V4::isLoopback () const
{
return (value&0xff000000)==0x7f000000;
}
IPEndpoint::V4::Proxy <true> IPEndpoint::V4::operator[] (std::size_t index) const
IPAddress::V4::Proxy <true> IPAddress::V4::operator[] (std::size_t index) const
{
switch (index)
{
@@ -116,7 +115,7 @@ IPEndpoint::V4::Proxy <true> IPEndpoint::V4::operator[] (std::size_t index) cons
};
};
IPEndpoint::V4::Proxy <false> IPEndpoint::V4::operator[] (std::size_t index)
IPAddress::V4::Proxy <false> IPAddress::V4::operator[] (std::size_t index)
{
switch (index)
{
@@ -129,7 +128,7 @@ IPEndpoint::V4::Proxy <false> IPEndpoint::V4::operator[] (std::size_t index)
};
};
std::string IPEndpoint::V4::to_string () const
std::string IPAddress::V4::to_string () const
{
std::string s;
s.reserve (15);
@@ -140,33 +139,33 @@ std::string IPEndpoint::V4::to_string () const
return s;
}
IPEndpoint::V4::operator std::string () const
IPAddress::V4::operator std::string () const
{
return to_string();
}
//------------------------------------------------------------------------------
IPEndpoint::IPEndpoint ()
IPAddress::IPAddress ()
: m_type (none)
{
}
IPEndpoint::IPEndpoint (V4 const& v4, uint16 port)
IPAddress::IPAddress (V4 const& v4, uint16 port)
: m_type (ipv4)
, m_port (port)
, m_v4 (v4)
{
}
IPEndpoint::IPEndpoint (V6 const& v6, uint16 port)
IPAddress::IPAddress (V6 const& v6, uint16 port)
: m_type (ipv6)
, m_port (port)
, m_v6 (v6)
{
}
IPEndpoint::IPEndpoint (IPEndpoint const& other)
IPAddress::IPAddress (IPAddress const& other)
: m_type (other.m_type)
, m_port (other.m_port)
{
@@ -180,7 +179,7 @@ IPEndpoint::IPEndpoint (IPEndpoint const& other)
};
}
IPEndpoint& IPEndpoint::operator= (IPEndpoint const& other)
IPAddress& IPAddress::operator= (IPAddress const& other)
{
m_type = other.m_type;
m_port = other.m_port;
@@ -195,17 +194,17 @@ IPEndpoint& IPEndpoint::operator= (IPEndpoint const& other)
return *this;
}
IPEndpoint IPEndpoint::from_string (std::string const& s)
IPAddress IPAddress::from_string (std::string const& s)
{
std::stringstream is (s);
IPEndpoint ep;
IPAddress ep;
is >> ep;
if (! is.fail() && is.rdbuf()->in_avail() == 0)
return ep;
return IPEndpoint();
return IPAddress();
}
IPEndpoint& IPEndpoint::operator= (V4 const& address)
IPAddress& IPAddress::operator= (V4 const& address)
{
m_type = ipv4;
m_port = 0;
@@ -213,7 +212,7 @@ IPEndpoint& IPEndpoint::operator= (V4 const& address)
return *this;
}
IPEndpoint& IPEndpoint::operator= (V6 const& address)
IPAddress& IPAddress::operator= (V6 const& address)
{
m_type = ipv6;
m_port = 0;
@@ -221,66 +220,66 @@ IPEndpoint& IPEndpoint::operator= (V6 const& address)
return *this;
}
IPEndpoint IPEndpoint::withPort (uint16 port) const
IPAddress IPAddress::withPort (uint16 port) const
{
switch (m_type)
{
case ipv4: return IPEndpoint (m_v4, port);
case ipv6: return IPEndpoint (m_v6, port);
case ipv4: return IPAddress (m_v4, port);
case ipv6: return IPAddress (m_v6, port);
default:
case none:
bassertfalse;
break;
};
return IPEndpoint();
return IPAddress();
}
bool IPEndpoint::empty () const
bool IPAddress::empty () const
{
return m_type == none;
}
bool IPEndpoint::isNull () const
bool IPAddress::isNull () const
{
return empty ();
}
bool IPEndpoint::isNotNull () const
bool IPAddress::isNotNull () const
{
return ! empty ();
}
IPEndpoint::Type IPEndpoint::type () const
IPAddress::Type IPAddress::type () const
{
return m_type;
}
bool IPEndpoint::isV4 () const
bool IPAddress::isV4 () const
{
return m_type == ipv4;
}
bool IPEndpoint::isV6 () const
bool IPAddress::isV6 () const
{
return m_type == ipv6;
}
IPEndpoint::V4 const& IPEndpoint::v4 () const
IPAddress::V4 const& IPAddress::v4 () const
{
return m_v4;
}
IPEndpoint::V6 const& IPEndpoint::v6 () const
IPAddress::V6 const& IPAddress::v6 () const
{
return m_v6;
}
uint16 IPEndpoint::port () const
uint16 IPAddress::port () const
{
return m_port;
}
bool IPEndpoint::isPublic () const
bool IPAddress::isPublic () const
{
switch (m_type)
{
@@ -294,7 +293,7 @@ bool IPEndpoint::isPublic () const
return false;
}
bool IPEndpoint::isPrivate () const
bool IPAddress::isPrivate () const
{
switch (m_type)
{
@@ -308,7 +307,7 @@ bool IPEndpoint::isPrivate () const
return false;
}
bool IPEndpoint::isBroadcast () const
bool IPAddress::isBroadcast () const
{
switch (m_type)
{
@@ -322,7 +321,7 @@ bool IPEndpoint::isBroadcast () const
return false;
}
bool IPEndpoint::isMulticast () const
bool IPAddress::isMulticast () const
{
switch (m_type)
{
@@ -336,7 +335,7 @@ bool IPEndpoint::isMulticast () const
return false;
}
bool IPEndpoint::isLoopback () const
bool IPAddress::isLoopback () const
{
switch (m_type)
{
@@ -350,7 +349,7 @@ bool IPEndpoint::isLoopback () const
return false;
}
std::string IPEndpoint::to_string () const
std::string IPAddress::to_string () const
{
switch (m_type)
{
@@ -376,7 +375,7 @@ std::string IPEndpoint::to_string () const
return std::string();
}
IPEndpoint::operator std::string () const
IPAddress::operator std::string () const
{
return to_string();
}
@@ -446,7 +445,7 @@ detail::integer_holder <IntType> integer (IntType& i)
}
/** Parse IPv4 address. */
std::istream& operator>> (std::istream &is, IPEndpoint::V4& addr)
std::istream& operator>> (std::istream &is, IPAddress::V4& addr)
{
uint8 octets [4];
is >> parse::integer (octets [0]);
@@ -458,16 +457,16 @@ std::istream& operator>> (std::istream &is, IPEndpoint::V4& addr)
if (!is)
return is;
}
addr = IPEndpoint::V4 (octets[0], octets[1], octets[2], octets[3]);
addr = IPAddress::V4 (octets[0], octets[1], octets[2], octets[3]);
return is;
}
/** Parse an IPEndpoint.
/** Parse an IPAddress.
@note Currently only IPv4 addresses are supported.
*/
std::istream& operator>> (std::istream &is, IPEndpoint& ep)
std::istream& operator>> (std::istream &is, IPAddress& ep)
{
IPEndpoint::V4 v4;
IPAddress::V4 v4;
is >> v4;
if (is.fail())
return is;
@@ -479,7 +478,7 @@ std::istream& operator>> (std::istream &is, IPEndpoint& ep)
if (c != ':')
{
is.unget();
ep = IPEndpoint (v4);
ep = IPAddress (v4);
return is;
}
@@ -488,11 +487,11 @@ std::istream& operator>> (std::istream &is, IPEndpoint& ep)
if (is.fail())
return is;
ep = IPEndpoint (v4, port);
ep = IPAddress (v4, port);
}
else
{
ep = IPEndpoint (v4);
ep = IPAddress (v4);
}
return is;
@@ -500,11 +499,11 @@ std::istream& operator>> (std::istream &is, IPEndpoint& ep)
//------------------------------------------------------------------------------
IPEndpoint IPEndpoint::from_string_altform (std::string const& s)
IPAddress IPAddress::from_string_altform (std::string const& s)
{
// Accept the regular form if it parses
{
IPEndpoint ep (IPEndpoint::from_string (s));
IPAddress ep (IPAddress::from_string (s));
if (! ep.empty())
return ep;
}
@@ -512,16 +511,16 @@ IPEndpoint IPEndpoint::from_string_altform (std::string const& s)
// Now try the alt form
std::stringstream is (s);
IPEndpoint::V4 v4;
IPAddress::V4 v4;
is >> v4;
if (! is.fail())
{
IPEndpoint ep (v4);
IPAddress ep (v4);
if (is.rdbuf()->in_avail()>0)
{
if (! parse::expect (is, ' '))
return IPEndpoint();
return IPAddress();
while (is.rdbuf()->in_avail()>0)
{
@@ -537,7 +536,7 @@ IPEndpoint IPEndpoint::from_string_altform (std::string const& s)
uint16 port;
is >> port;
if (is.fail())
return IPEndpoint();
return IPAddress();
return ep.withPort (port);
}
@@ -550,12 +549,12 @@ IPEndpoint IPEndpoint::from_string_altform (std::string const& s)
// Could be V6 here...
return IPEndpoint();
return IPAddress();
}
//------------------------------------------------------------------------------
int compare (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs)
int compare (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs)
{
if (lhs.value < rhs.value)
return -1;
@@ -564,14 +563,14 @@ int compare (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs)
return 0;
}
bool operator== (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs) { return compare (lhs, rhs) == 0; }
bool operator!= (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs) { return compare (lhs, rhs) != 0; }
bool operator< (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs) { return compare (lhs, rhs) < 0; }
bool operator<= (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs) { return compare (lhs, rhs) <= 0; }
bool operator> (IPEndpoint::V4 const& lhs, IPEndpoint::V4 const& rhs) { return compare (lhs, rhs) > 0; }
bool operator>= (IPEndpoint::V4 const& lhs, IPEndpoint::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; }
bool operator>= (IPAddress::V4 const& lhs, IPAddress::V4 const& rhs) { return compare (lhs, rhs) >= 0; }
static int type_compare (IPEndpoint const& lhs, IPEndpoint const& rhs)
static int type_compare (IPAddress const& lhs, IPAddress const& rhs)
{
if (lhs.type() < rhs.type())
return -1;
@@ -580,7 +579,7 @@ static int type_compare (IPEndpoint const& lhs, IPEndpoint const& rhs)
return 0;
}
int compare (IPEndpoint const& lhs, IPEndpoint const& rhs)
int compare (IPAddress const& lhs, IPAddress const& rhs)
{
int const tc (type_compare (lhs, rhs));
@@ -591,36 +590,36 @@ int compare (IPEndpoint const& lhs, IPEndpoint const& rhs)
switch (lhs.type())
{
case IPEndpoint::none: return 0;
case IPEndpoint::ipv4: return compare (lhs.v4(), rhs.v4());
case IPAddress::none: return 0;
case IPAddress::ipv4: return compare (lhs.v4(), rhs.v4());
default:
case IPEndpoint::ipv6:
case IPAddress::ipv6:
break;
};
bassertfalse;
return 0;
}
bool operator== (IPEndpoint const& lhs, IPEndpoint const& rhs) { return compare (lhs, rhs) == 0; }
bool operator!= (IPEndpoint const& lhs, IPEndpoint const& rhs) { return compare (lhs, rhs) != 0; }
bool operator< (IPEndpoint const& lhs, IPEndpoint const& rhs) { return compare (lhs, rhs) < 0; }
bool operator<= (IPEndpoint const& lhs, IPEndpoint const& rhs) { return compare (lhs, rhs) <= 0; }
bool operator> (IPEndpoint const& lhs, IPEndpoint const& rhs) { return compare (lhs, rhs) > 0; }
bool operator>= (IPEndpoint const& lhs, IPEndpoint 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) { return compare (lhs, rhs) >= 0; }
std::ostream& operator<< (std::ostream &os, IPEndpoint::V4 const& addr)
std::ostream& operator<< (std::ostream &os, IPAddress::V4 const& addr)
{
os << addr.to_string();
return os;
}
std::ostream& operator<< (std::ostream &os, IPEndpoint::V6 const& addr)
std::ostream& operator<< (std::ostream &os, IPAddress::V6 const& addr)
{
os << addr.to_string();
return os;
}
std::ostream& operator<< (std::ostream &os, IPEndpoint const& ep)
std::ostream& operator<< (std::ostream &os, IPAddress const& ep)
{
os << ep.to_string();
return os;
@@ -628,10 +627,10 @@ std::ostream& operator<< (std::ostream &os, IPEndpoint const& ep)
//------------------------------------------------------------------------------
class IPEndpointTests : public UnitTest
class IPAddressTests : public UnitTest
{
public:
bool parse (char const* text, IPEndpoint& ep)
bool parse (char const* text, IPAddress& ep)
{
std::string input (text);
std::istringstream stream (input);
@@ -641,14 +640,14 @@ public:
void shouldPass (char const* text)
{
IPEndpoint ep;
IPAddress ep;
expect (parse (text, ep));
expect (ep.to_string() == std::string(text));
}
void shouldFail (char const* text)
{
IPEndpoint ep;
IPAddress ep;
unexpected (parse (text, ep));
}
@@ -673,9 +672,9 @@ public:
{
beginTestCase ("addresses");
IPEndpoint ep;
IPAddress ep;
ep = IPEndpoint(IPEndpoint::V4(127,0,0,1)).withPort (80);
ep = IPAddress(IPAddress::V4(127,0,0,1)).withPort (80);
expect (!ep.isPublic());
expect ( ep.isPrivate());
expect (!ep.isBroadcast());
@@ -683,7 +682,7 @@ public:
expect ( ep.isLoopback());
expect (ep.to_string() == "127.0.0.1:80");
ep = IPEndpoint::V4(10,0,0,1);
ep = IPAddress::V4(10,0,0,1);
expect ( ep.v4().getClass() == 'A');
expect (!ep.isPublic());
expect ( ep.isPrivate());
@@ -692,7 +691,7 @@ public:
expect (!ep.isLoopback());
expect (ep.to_string() == "10.0.0.1");
ep = IPEndpoint::V4(166,78,151,147);
ep = IPAddress::V4(166,78,151,147);
expect ( ep.isPublic());
expect (!ep.isPrivate());
expect (!ep.isBroadcast());
@@ -707,11 +706,11 @@ public:
testParse();
}
IPEndpointTests () : UnitTest ("IPEndpoint", "beast")
IPAddressTests () : UnitTest ("IPAddress", "beast")
{
}
};
static IPEndpointTests ipEndpointTests;
static IPAddressTests ipEndpointTests;
}

View File

@@ -168,7 +168,6 @@ namespace beast
#include "network/MACAddress.cpp"
#include "network/NamedPipe.cpp"
#include "network/Socket.cpp"
#include "network/IPAddress.cpp"
#include "streams/BufferedInputStream.cpp"
#include "streams/FileInputSource.cpp"

View File

@@ -195,7 +195,6 @@ class FileOutputStream;
#include "misc/Main.h"
#include "misc/Uuid.h"
#include "misc/WindowsRegistry.h"
#include "network/IPAddress.h"
#include "network/MACAddress.h"
#include "threads/ReadWriteLock.h"
#include "network/NamedPipe.h"

View File

@@ -112,24 +112,6 @@ void MACAddress::findAllAddresses (Array<MACAddress>& result)
MACAddressHelpers::getViaNetBios (result);
}
void IPAddress::findAllAddresses (Array<IPAddress>& result)
{
result.addIfNotAlreadyThere (IPAddress::local());
GetAdaptersInfoHelper gah;
if (gah.callGetAdaptersInfo())
{
for (PIP_ADAPTER_INFO adapter = gah.adapterInfo; adapter != nullptr; adapter = adapter->Next)
{
IPAddress ip (adapter->IpAddressList.IpAddress.String);
if (ip != IPAddress::any())
result.addIfNotAlreadyThere (ip);
}
}
}
//==============================================================================
bool Process::openEmailWithAttachments (const String& targetEmailAddress,
const String& emailSubject,

View File

@@ -1,144 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Portions of this file are from JUCE.
Copyright (c) 2013 - Raw Material Software Ltd.
Please visit http://www.juce.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
IPAddress::IPAddress() noexcept
{
address[0] = 0; address[1] = 0;
address[2] = 0; address[3] = 0;
}
IPAddress::IPAddress (const uint8 bytes[4]) noexcept
{
address[0] = bytes[0]; address[1] = bytes[1];
address[2] = bytes[2]; address[3] = bytes[3];
}
IPAddress::IPAddress (uint8 a0, uint8 a1, uint8 a2, uint8 a3) noexcept
{
address[0] = a0; address[1] = a1;
address[2] = a2; address[3] = a3;
}
IPAddress::IPAddress (uint32 n) noexcept
{
address[0] = (n >> 24);
address[1] = (n >> 16) & 255;
address[2] = (n >> 8) & 255;
address[3] = (n & 255);
}
IPAddress::IPAddress (const String& adr)
{
StringArray tokens;
tokens.addTokens (adr, ".", String::empty);
for (int i = 0; i < 4; ++i)
address[i] = (uint8) tokens[i].getIntValue();
}
String IPAddress::toString() const
{
String s ((int) address[0]);
for (int i = 1; i < 4; ++i)
s << '.' << (int) address[i];
return s;
}
IPAddress IPAddress::any() noexcept { return IPAddress(); }
IPAddress IPAddress::broadcast() noexcept { return IPAddress (255, 255, 255, 255); }
IPAddress IPAddress::local() noexcept { return IPAddress (127, 0, 0, 1); }
bool IPAddress::operator== (const IPAddress& other) const noexcept
{
return address[0] == other.address[0]
&& address[1] == other.address[1]
&& address[2] == other.address[2]
&& address[3] == other.address[3];
}
bool IPAddress::operator!= (const IPAddress& other) const noexcept
{
return ! operator== (other);
}
#if ! BEAST_WINDOWS
static void addAddress (const sockaddr_in* addr_in, Array<IPAddress>& result)
{
in_addr_t addr = addr_in->sin_addr.s_addr;
if (addr != INADDR_NONE)
result.addIfNotAlreadyThere (IPAddress (ntohl (addr)));
}
static void findIPAddresses (int sock, Array<IPAddress>& result)
{
ifconf cfg;
HeapBlock<char> buffer;
int bufferSize = 1024;
do
{
bufferSize *= 2;
buffer.calloc ((size_t)bufferSize);
cfg.ifc_len = bufferSize;
cfg.ifc_buf = buffer;
if (ioctl (sock, SIOCGIFCONF, &cfg) < 0 && errno != EINVAL)
return;
} while (bufferSize < cfg.ifc_len + 2 * (int) (IFNAMSIZ + sizeof (struct sockaddr_in6)));
#if BEAST_MAC || BEAST_IOS
while (cfg.ifc_len >= (int) (IFNAMSIZ + sizeof (struct sockaddr_in)))
{
if (cfg.ifc_req->ifr_addr.sa_family == AF_INET) // Skip non-internet addresses
addAddress ((const sockaddr_in*) &cfg.ifc_req->ifr_addr, result);
cfg.ifc_len -= IFNAMSIZ + cfg.ifc_req->ifr_addr.sa_len;
cfg.ifc_buf += IFNAMSIZ + cfg.ifc_req->ifr_addr.sa_len;
}
#else
for (size_t i = 0; i < cfg.ifc_len / sizeof (struct ifreq); ++i)
{
const ifreq& item = cfg.ifc_req[i];
if (item.ifr_addr.sa_family == AF_INET)
addAddress ((const sockaddr_in*) &item.ifr_addr, result);
}
#endif
}
void IPAddress::findAllAddresses (Array<IPAddress>& result)
{
const int sock = socket (AF_INET, SOCK_DGRAM, 0); // a dummy socket to execute the IO control
if (sock >= 0)
{
findIPAddresses (sock, result);
::close (sock);
}
}
#endif

View File

@@ -1,77 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Portions of this file are from JUCE.
Copyright (c) 2013 - Raw Material Software Ltd.
Please visit http://www.juce.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_IPADDRESS_H_INCLUDED
#define BEAST_IPADDRESS_H_INCLUDED
//==============================================================================
/**
An IPV4 address.
*/
class BEAST_API IPAddress
{
public:
//==============================================================================
/** Populates a list of all the IP addresses that this machine is using. */
static void findAllAddresses (Array<IPAddress>& results);
//==============================================================================
/** Creates a null address (0.0.0.0). */
IPAddress() noexcept;
/** Creates an address from 4 bytes. */
explicit IPAddress (const uint8 bytes[4]) noexcept;
/** Creates an address from 4 bytes. */
IPAddress (uint8 address1, uint8 address2, uint8 address3, uint8 address4) noexcept;
/** Creates an address from a packed 32-bit integer, where the MSB is
the first number in the address, and the LSB is the last.
*/
explicit IPAddress (uint32 asNativeEndian32Bit) noexcept;
/** Parses a string IP address of the form "a.b.c.d". */
explicit IPAddress (const String& address);
/** Returns a dot-separated string in the form "1.2.3.4" */
String toString() const;
/** Returns an address meaning "any" (0.0.0.0) */
static IPAddress any() noexcept;
/** Returns an address meaning "broadcast" (255.255.255.255) */
static IPAddress broadcast() noexcept;
/** Returns an address meaning "localhost" (127.0.0.1) */
static IPAddress local() noexcept;
bool operator== (const IPAddress& other) const noexcept;
bool operator!= (const IPAddress& other) const noexcept;
/** The elements of the IP address. */
uint8 address[4];
};
#endif // BEAST_IPADDRESS_H_INCLUDED

View File

@@ -1,468 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Portions of this file are from JUCE.
Copyright (c) 2013 - Raw Material Software Ltd.
Please visit http://www.juce.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
URL::URL()
{
}
URL::URL (const String& url_)
: url (url_)
{
int i = url.indexOfChar ('?');
if (i >= 0)
{
do
{
const int nextAmp = url.indexOfChar (i + 1, '&');
const int equalsPos = url.indexOfChar (i + 1, '=');
if (equalsPos > i + 1)
{
if (nextAmp < 0)
{
addParameter (removeEscapeChars (url.substring (i + 1, equalsPos)),
removeEscapeChars (url.substring (equalsPos + 1)));
}
else if (nextAmp > 0 && equalsPos < nextAmp)
{
addParameter (removeEscapeChars (url.substring (i + 1, equalsPos)),
removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
}
}
i = nextAmp;
}
while (i >= 0);
url = url.upToFirstOccurrenceOf ("?", false, false);
}
}
URL::URL (const URL& other)
: url (other.url),
postData (other.postData),
parameterNames (other.parameterNames),
parameterValues (other.parameterValues),
filesToUpload (other.filesToUpload),
mimeTypes (other.mimeTypes)
{
}
URL& URL::operator= (const URL& other)
{
url = other.url;
postData = other.postData;
parameterNames = other.parameterNames;
parameterValues = other.parameterValues;
filesToUpload = other.filesToUpload;
mimeTypes = other.mimeTypes;
return *this;
}
bool URL::operator== (const URL& other) const
{
return url == other.url
&& postData == other.postData
&& parameterNames == other.parameterNames
&& parameterValues == other.parameterValues
&& filesToUpload == other.filesToUpload
&& mimeTypes == other.mimeTypes;
}
bool URL::operator!= (const URL& other) const
{
return ! operator== (other);
}
URL::~URL()
{
}
namespace URLHelpers
{
static String getMangledParameters (const URL& url)
{
bassert (url.getParameterNames().size() == url.getParameterValues().size());
String p;
for (int i = 0; i < url.getParameterNames().size(); ++i)
{
if (i > 0)
p << '&';
p << URL::addEscapeChars (url.getParameterNames()[i], true)
<< '='
<< URL::addEscapeChars (url.getParameterValues()[i], true);
}
return p;
}
static int findEndOfScheme (const String& url)
{
int i = 0;
while (CharacterFunctions::isLetterOrDigit (url[i])
|| url[i] == '+' || url[i] == '-' || url[i] == '.')
++i;
return url[i] == ':' ? i + 1 : 0;
}
static int findStartOfNetLocation (const String& url)
{
int start = findEndOfScheme (url);
while (url[start] == '/')
++start;
return start;
}
static int findStartOfPath (const String& url)
{
return url.indexOfChar (findStartOfNetLocation (url), '/') + 1;
}
static void createHeadersAndPostData (const URL& url, String& headers, MemoryBlock& postData)
{
MemoryOutputStream data (postData, false);
if (url.getFilesToUpload().size() > 0)
{
// need to upload some files, so do it as multi-part...
const String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
data << "--" << boundary;
for (int i = 0; i < url.getParameterNames().size(); ++i)
{
data << "\r\nContent-Disposition: form-data; name=\""
<< url.getParameterNames() [i]
<< "\"\r\n\r\n"
<< url.getParameterValues() [i]
<< "\r\n--"
<< boundary;
}
for (int i = 0; i < url.getFilesToUpload().size(); ++i)
{
const File file (url.getFilesToUpload().getAllValues() [i]);
const String paramName (url.getFilesToUpload().getAllKeys() [i]);
data << "\r\nContent-Disposition: form-data; name=\"" << paramName
<< "\"; filename=\"" << file.getFileName() << "\"\r\n";
const String mimeType (url.getMimeTypesOfUploadFiles()
.getValue (paramName, String::empty));
if (mimeType.isNotEmpty())
data << "Content-Type: " << mimeType << "\r\n";
data << "Content-Transfer-Encoding: binary\r\n\r\n"
<< file << "\r\n--" << boundary;
}
data << "--\r\n";
}
else
{
data << getMangledParameters (url)
<< url.getPostData();
// just a short text attachment, so use simple url encoding..
headers << "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
<< (int) data.getDataSize() << "\r\n";
}
}
static void concatenatePaths (String& path, const String& suffix)
{
if (! path.endsWithChar ('/'))
path << '/';
if (suffix.startsWithChar ('/'))
path += suffix.substring (1);
else
path += suffix;
}
}
void URL::addParameter (const String& name, const String& value)
{
parameterNames.add (name);
parameterValues.add (value);
}
String URL::toString (const bool includeGetParameters) const
{
if (includeGetParameters && parameterNames.size() > 0)
return url + "?" + URLHelpers::getMangledParameters (*this);
return url;
}
bool URL::isWellFormed() const
{
//xxx TODO
return url.isNotEmpty();
}
String URL::getDomain() const
{
const int start = URLHelpers::findStartOfNetLocation (url);
const int end1 = url.indexOfChar (start, '/');
const int end2 = url.indexOfChar (start, ':');
const int end = (end1 < 0 && end2 < 0) ? std::numeric_limits<int>::max()
: ((end1 < 0 || end2 < 0) ? bmax (end1, end2)
: bmin (end1, end2));
return url.substring (start, end);
}
String URL::getSubPath() const
{
const int startOfPath = URLHelpers::findStartOfPath (url);
return startOfPath <= 0 ? String::empty
: url.substring (startOfPath);
}
String URL::getScheme() const
{
return url.substring (0, URLHelpers::findEndOfScheme (url) - 1);
}
int URL::getPort() const
{
const int colonPos = url.indexOfChar (URLHelpers::findStartOfNetLocation (url), ':');
return colonPos > 0 ? url.substring (colonPos + 1).getIntValue() : 0;
}
URL URL::withNewSubPath (const String& newPath) const
{
const int startOfPath = URLHelpers::findStartOfPath (url);
URL u (*this);
if (startOfPath > 0)
u.url = url.substring (0, startOfPath);
URLHelpers::concatenatePaths (u.url, newPath);
return u;
}
URL URL::getChildURL (const String& subPath) const
{
URL u (*this);
URLHelpers::concatenatePaths (u.url, subPath);
return u;
}
//==============================================================================
bool URL::isProbablyAWebsiteURL (const String& possibleURL)
{
const char* validProtocols[] = { "http:", "ftp:", "https:" };
for (int i = 0; i < numElementsInArray (validProtocols); ++i)
if (possibleURL.startsWithIgnoreCase (validProtocols[i]))
return true;
if (possibleURL.containsChar ('@')
|| possibleURL.containsChar (' '))
return false;
const String topLevelDomain (possibleURL.upToFirstOccurrenceOf ("/", false, false)
.fromLastOccurrenceOf (".", false, false));
return topLevelDomain.isNotEmpty() && topLevelDomain.length() <= 3;
}
bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
{
const int atSign = possibleEmailAddress.indexOfChar ('@');
return atSign > 0
&& possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
&& (! possibleEmailAddress.endsWithChar ('.'));
}
//==============================================================================
InputStream* URL::createInputStream (const bool usePostCommand,
OpenStreamProgressCallback* const progressCallback,
void* const progressCallbackContext,
const String& extraHeaders,
const int timeOutMs,
StringPairArray* const responseHeaders) const
{
String headers;
MemoryBlock headersAndPostData;
if (usePostCommand)
URLHelpers::createHeadersAndPostData (*this, headers, headersAndPostData);
headers += extraHeaders;
if (! headers.endsWithChar ('\n'))
headers << "\r\n";
return createNativeStream (toString (! usePostCommand), usePostCommand, headersAndPostData,
progressCallback, progressCallbackContext,
headers, timeOutMs, responseHeaders);
}
//==============================================================================
bool URL::readEntireBinaryStream (MemoryBlock& destData,
const bool usePostCommand) const
{
const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
if (in != nullptr)
{
in->readIntoMemoryBlock (destData);
return true;
}
return false;
}
String URL::readEntireTextStream (const bool usePostCommand) const
{
const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
if (in != nullptr)
return in->readEntireStreamAsString();
return String::empty;
}
XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
{
return XmlDocument::parse (readEntireTextStream (usePostCommand));
}
//==============================================================================
URL URL::withParameter (const String& parameterName,
const String& parameterValue) const
{
URL u (*this);
u.addParameter (parameterName, parameterValue);
return u;
}
URL URL::withFileToUpload (const String& parameterName,
const File& fileToUpload,
const String& mimeType) const
{
bassert (mimeType.isNotEmpty()); // You need to supply a mime type!
URL u (*this);
u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
u.mimeTypes.set (parameterName, mimeType);
return u;
}
URL URL::withPOSTData (const String& postData_) const
{
URL u (*this);
u.postData = postData_;
return u;
}
const StringPairArray& URL::getFilesToUpload() const
{
return filesToUpload;
}
const StringPairArray& URL::getMimeTypesOfUploadFiles() const
{
return mimeTypes;
}
//==============================================================================
String URL::removeEscapeChars (const String& s)
{
String result (s.replaceCharacter ('+', ' '));
if (! result.containsChar ('%'))
return result;
// We need to operate on the string as raw UTF8 chars, and then recombine them into unicode
// after all the replacements have been made, so that multi-byte chars are handled.
Array<char> utf8 (result.toRawUTF8(), (int) result.getNumBytesAsUTF8());
for (int i = 0; i < utf8.size(); ++i)
{
if (utf8.getUnchecked(i) == '%')
{
const int hexDigit1 = CharacterFunctions::getHexDigitValue ((beast_wchar) (uint8) utf8 [i + 1]);
const int hexDigit2 = CharacterFunctions::getHexDigitValue ((beast_wchar) (uint8) utf8 [i + 2]);
if (hexDigit1 >= 0 && hexDigit2 >= 0)
{
utf8.set (i, (char) ((hexDigit1 << 4) + hexDigit2));
utf8.removeRange (i + 1, 2);
}
}
}
return String::fromUTF8 (utf8.getRawDataPointer(), utf8.size());
}
String URL::addEscapeChars (const String& s, const bool isParameter)
{
const CharPointer_UTF8 legalChars (isParameter ? "_-.*!'()"
: ",$_-.*!'()");
Array<char> utf8 (s.toRawUTF8(), (int) s.getNumBytesAsUTF8());
for (int i = 0; i < utf8.size(); ++i)
{
const char c = utf8.getUnchecked(i);
if (! (CharacterFunctions::isLetterOrDigit (c)
|| legalChars.indexOf ((beast_wchar) c) >= 0))
{
utf8.set (i, '%');
utf8.insert (++i, "0123456789abcdef" [((uint8) c) >> 4]);
utf8.insert (++i, "0123456789abcdef" [c & 15]);
}
}
return String::fromUTF8 (utf8.getRawDataPointer(), utf8.size());
}
//==============================================================================
bool URL::launchInDefaultBrowser() const
{
String u (toString (true));
if (u.containsChar ('@') && ! u.containsChar (':'))
u = "mailto:" + u;
return Process::openDocument (u, String::empty);
}

View File

@@ -1,342 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
Portions of this file are from JUCE.
Copyright (c) 2013 - Raw Material Software Ltd.
Please visit http://www.juce.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef BEAST_URL_H_INCLUDED
#define BEAST_URL_H_INCLUDED
class InputStream;
class XmlElement;
//==============================================================================
/**
Represents a URL and has a bunch of useful functions to manipulate it.
This class can be used to launch URLs in browsers, and also to create
InputStreams that can read from remote http or ftp sources.
*/
class BEAST_API URL : LeakChecked <URL>
{
public:
//==============================================================================
/** Creates an empty URL. */
URL();
/** Creates a URL from a string. */
URL (const String& url);
/** Creates a copy of another URL. */
URL (const URL& other);
/** Destructor. */
~URL();
/** Copies this URL from another one. */
URL& operator= (const URL& other);
/** Compares two URLs.
All aspects of the URLs must be identical for them to match, including any parameters,
upload files, etc.
*/
bool operator== (const URL&) const;
bool operator!= (const URL&) const;
//==============================================================================
/** Returns a string version of the URL.
If includeGetParameters is true and any parameters have been set with the
withParameter() method, then the string will have these appended on the
end and url-encoded.
*/
String toString (bool includeGetParameters) const;
/** True if it seems to be valid. */
bool isWellFormed() const;
/** Returns just the domain part of the URL.
E.g. for "http://www.xyz.com/foobar", this will return "www.xyz.com".
*/
String getDomain() const;
/** Returns the path part of the URL.
E.g. for "http://www.xyz.com/foo/bar?x=1", this will return "foo/bar".
*/
String getSubPath() const;
/** Returns the scheme of the URL.
E.g. for "http://www.xyz.com/foobar", this will return "http". (It won't
include the colon).
*/
String getScheme() const;
/** Attempts to read a port number from the URL.
@returns the port number, or 0 if none is explicitly specified.
*/
int getPort() const;
/** Returns a new version of this URL that uses a different sub-path.
E.g. if the URL is "http://www.xyz.com/foo?x=1" and you call this with
"bar", it'll return "http://www.xyz.com/bar?x=1".
*/
URL withNewSubPath (const String& newPath) const;
/** Returns a new URL that refers to a sub-path relative to this one.
E.g. if the URL is "http://www.xyz.com/foo" and you call this with
"bar", it'll return "http://www.xyz.com/foo/bar". Note that there's no way for
this method to know whether the original URL is a file or directory, so it's
up to you to make sure it's a directory. It also won't attempt to be smart about
the content of the childPath string, so if this string is an absolute URL, it'll
still just get bolted onto the end of the path.
@see File::getChildFile
*/
URL getChildURL (const String& subPath) const;
//==============================================================================
/** Returns a copy of this URL, with a GET or POST parameter added to the end.
Any control characters in the value will be encoded.
e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com"
would produce a new url whose toString(true) method would return
"www.fish.com?amount=some+fish".
@see getParameterNames, getParameterValues
*/
URL withParameter (const String& parameterName,
const String& parameterValue) const;
/** Returns a copy of this URl, with a file-upload type parameter added to it.
When performing a POST where one of your parameters is a binary file, this
lets you specify the file.
Note that the filename is stored, but the file itself won't actually be read
until this URL is later used to create a network input stream.
*/
URL withFileToUpload (const String& parameterName,
const File& fileToUpload,
const String& mimeType) const;
/** Returns an array of the names of all the URL's parameters.
E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would
contain two items: "type" and "amount".
You can call getParameterValues() to get the corresponding value of each
parameter. Note that the list can contain multiple parameters with the same name.
@see getParameterValues, withParameter
*/
const StringArray& getParameterNames() const noexcept { return parameterNames; }
/** Returns an array of the values of all the URL's parameters.
E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would
contain two items: "haddock" and "some fish".
The values returned will have been cleaned up to remove any escape characters.
You can call getParameterNames() to get the corresponding name of each
parameter. Note that the list can contain multiple parameters with the same name.
@see getParameterNames, withParameter
*/
const StringArray& getParameterValues() const noexcept { return parameterValues; }
/** Returns the set of files that should be uploaded as part of a POST operation.
This is the set of files that were added to the URL with the withFileToUpload()
method.
*/
const StringPairArray& getFilesToUpload() const;
/** Returns the set of mime types associated with each of the upload files.
*/
const StringPairArray& getMimeTypesOfUploadFiles() const;
/** Returns a copy of this URL, with a block of data to send as the POST data.
If you're setting the POST data, be careful not to have any parameters set
as well, otherwise it'll all get thrown in together, and might not have the
desired effect.
If the URL already contains some POST data, this will replace it, rather
than being appended to it.
This data will only be used if you specify a post operation when you call
createInputStream().
*/
URL withPOSTData (const String& postData) const;
/** Returns the data that was set using withPOSTData(). */
const String& getPostData() const noexcept { return postData; }
//==============================================================================
/** Tries to launch the system's default browser to open the URL.
Returns true if this seems to have worked.
*/
bool launchInDefaultBrowser() const;
//==============================================================================
/** Takes a guess as to whether a string might be a valid website address.
This isn't foolproof!
*/
static bool isProbablyAWebsiteURL (const String& possibleURL);
/** Takes a guess as to whether a string might be a valid email address.
This isn't foolproof!
*/
static bool isProbablyAnEmailAddress (const String& possibleEmailAddress);
//==============================================================================
/** This callback function can be used by the createInputStream() method.
It allows your app to receive progress updates during a lengthy POST operation. If you
want to continue the operation, this should return true, or false to abort.
*/
typedef bool (OpenStreamProgressCallback) (void* context, int bytesSent, int totalBytes);
/** Attempts to open a stream that can read from this URL.
@param usePostCommand if true, it will try to do use a http 'POST' to pass
the paramters, otherwise it'll encode them into the
URL and do a 'GET'.
@param progressCallback if this is non-zero, it lets you supply a callback function
to keep track of the operation's progress. This can be useful
for lengthy POST operations, so that you can provide user feedback.
@param progressCallbackContext if a callback is specified, this value will be passed to
the function
@param extraHeaders if not empty, this string is appended onto the headers that
are used for the request. It must therefore be a valid set of HTML
header directives, separated by newlines.
@param connectionTimeOutMs if 0, this will use whatever default setting the OS chooses. If
a negative number, it will be infinite. Otherwise it specifies a
time in milliseconds.
@param responseHeaders if this is non-zero, all the (key, value) pairs received as headers
in the response will be stored in this array
@returns an input stream that the caller must delete, or a null pointer if there was an
error trying to open it.
*/
InputStream* createInputStream (bool usePostCommand,
OpenStreamProgressCallback* progressCallback = nullptr,
void* progressCallbackContext = nullptr,
const String& extraHeaders = String::empty,
int connectionTimeOutMs = 0,
StringPairArray* responseHeaders = nullptr) const;
//==============================================================================
/** Tries to download the entire contents of this URL into a binary data block.
If it succeeds, this will return true and append the data it read onto the end
of the memory block.
@param destData the memory block to append the new data to
@param usePostCommand whether to use a POST command to get the data (uses
a GET command if this is false)
@see readEntireTextStream, readEntireXmlStream
*/
bool readEntireBinaryStream (MemoryBlock& destData,
bool usePostCommand = false) const;
/** Tries to download the entire contents of this URL as a string.
If it fails, this will return an empty string, otherwise it will return the
contents of the downloaded file. If you need to distinguish between a read
operation that fails and one that returns an empty string, you'll need to use
a different method, such as readEntireBinaryStream().
@param usePostCommand whether to use a POST command to get the data (uses
a GET command if this is false)
@see readEntireBinaryStream, readEntireXmlStream
*/
String readEntireTextStream (bool usePostCommand = false) const;
/** Tries to download the entire contents of this URL and parse it as XML.
If it fails, or if the text that it reads can't be parsed as XML, this will
return 0.
When it returns a valid XmlElement object, the caller is responsibile for deleting
this object when no longer needed.
@param usePostCommand whether to use a POST command to get the data (uses
a GET command if this is false)
@see readEntireBinaryStream, readEntireTextStream
*/
XmlElement* readEntireXmlStream (bool usePostCommand = false) const;
//==============================================================================
/** Adds escape sequences to a string to encode any characters that aren't
legal in a URL.
E.g. any spaces will be replaced with "%20".
This is the opposite of removeEscapeChars().
If isParameter is true, it means that the string is going to be used
as a parameter, so it also encodes '$' and ',' (which would otherwise
be legal in a URL.
@see removeEscapeChars
*/
static String addEscapeChars (const String& stringToAddEscapeCharsTo,
bool isParameter);
/** Replaces any escape character sequences in a string with their original
character codes.
E.g. any instances of "%20" will be replaced by a space.
This is the opposite of addEscapeChars().
@see addEscapeChars
*/
static String removeEscapeChars (const String& stringToRemoveEscapeCharsFrom);
private:
//==============================================================================
String url, postData;
StringArray parameterNames, parameterValues;
StringPairArray filesToUpload, mimeTypes;
void addParameter (const String&, const String&);
static InputStream* createNativeStream (const String& address, bool isPost, const MemoryBlock& postData,
OpenStreamProgressCallback* progressCallback,
void* progressCallbackContext, const String& headers,
const int timeOutMs, StringPairArray* responseHeaders);
};
#endif // BEAST_URL_H_INCLUDED

View File

@@ -39,11 +39,11 @@ struct Port
Port ();
Port (Port const& other);
Port& operator= (Port const& other);
Port (uint16 port_, IPEndpoint const& addr_,
Port (uint16 port_, IPAddress const& addr_,
Security security_, SSLContext* context_);
uint16 port;
IPEndpoint addr;
IPAddress addr;
Security security;
SSLContext* context;
};

View File

@@ -46,7 +46,7 @@ public:
virtual Journal journal() = 0;
/** Returns the remote address of the connection. */
virtual IPEndpoint remoteAddress() = 0;
virtual IPAddress remoteAddress() = 0;
/** Returns `true` if the full HTTP headers have been received. */
virtual bool headersComplete() = 0;

View File

@@ -117,7 +117,7 @@ public:
return m_impl.journal();
}
IPEndpoint remoteAddress()
IPAddress remoteAddress()
{
return from_asio (get_socket().remote_endpoint());
}

View File

@@ -47,7 +47,7 @@ Port& Port::operator= (Port const& other)
Port::Port (
uint16 port_,
IPEndpoint const& addr_,
IPAddress const& addr_,
Security security_,
SSLContext* context_)
: port (port_)

View File

@@ -49,19 +49,19 @@ inline endpoint_t to_asio (Port const& port)
{
if (port.addr.isV4())
{
IPEndpoint::V4 v4 (port.addr.v4());
IPAddress::V4 v4 (port.addr.v4());
std::string const& s (v4.to_string());
return endpoint_t (address().from_string (s), port.port);
}
//IPEndpoint::V6 v6 (ep.v6());
//IPAddress::V6 v6 (ep.v6());
return endpoint_t ();
}
inline IPEndpoint from_asio (endpoint_t const& endpoint)
inline IPAddress from_asio (endpoint_t const& endpoint)
{
std::stringstream ss (to_string (endpoint));
IPEndpoint ep;
IPAddress ep;
ss >> ep;
return ep;
}

View File

@@ -35,7 +35,7 @@ struct Callback
std::vector <Endpoint> const& endpoints) = 0;
/** Initiate outgoing Peer connections to the specified set of endpoints. */
virtual void connectPeerEndpoints (std::vector <IPEndpoint> const& list) = 0;
virtual void connectPeerEndpoints (std::vector <IPAddress> const& list) = 0;
/** Impose a load charge on the specified peer. */
virtual void chargePeerLoadPenalty (PeerID const& id) = 0;

View File

@@ -28,7 +28,7 @@ struct Endpoint
{
Endpoint ();
IPEndpoint address;
IPAddress address;
int hops;
uint32 incomingSlotsAvailable;
uint32 incomingSlotsMax;

View File

@@ -58,13 +58,13 @@ public:
virtual void addFixedPeers (
std::vector <std::string> const& strings) = 0;
/** Add a set of strings as fallback IPEndpoint sources.
/** Add a set of strings as fallback IPAddress sources.
@param name A label used for diagnostics.
*/
virtual void addFallbackStrings (std::string const& name,
std::vector <std::string> const& strings) = 0;
/** Add a URL as a fallback location to obtain IPEndpoint sources.
/** Add a URL as a fallback location to obtain IPAddress sources.
@param name A label used for diagnostics.
*/
virtual void addFallbackURL (std::string const& name,
@@ -76,7 +76,7 @@ public:
we are sure that its connection is stable.
*/
virtual void onPeerConnected (PeerID const& id,
IPEndpoint const& address,
IPAddress const& address,
bool inbound) = 0;
/** Called when an existing peer connection drops for whatever reason.
@@ -91,7 +91,7 @@ public:
std::vector <Endpoint> const& endpoints) = 0;
/** Called when a legacy IP/port address is received (from mtPEER). */
virtual void onPeerLegacyEndpoint (IPEndpoint const& ep) = 0;
virtual void onPeerLegacyEndpoint (IPAddress const& ep) = 0;
};
}

View File

@@ -29,7 +29,7 @@ class Cache
{
private:
typedef boost::unordered_map <
IPEndpoint, CachedEndpoint, IPEndpoint::hasher> Table;
IPAddress, CachedEndpoint, IPAddress::hasher> Table;
Journal m_journal;

View File

@@ -41,8 +41,8 @@ private:
//--------------------------------------------------------------------------
static boost::asio::ip::tcp::endpoint fromIPEndpoint (
IPEndpoint const& ipEndpoint)
static boost::asio::ip::tcp::endpoint fromIPAddress (
IPAddress const& ipEndpoint)
{
if (ipEndpoint.isV4 ())
{
@@ -71,14 +71,14 @@ private:
CheckerImp& m_owner;
boost::asio::io_service& m_io_service;
IPEndpoint m_address;
IPAddress m_address;
AbstractHandler <void (Result)> m_handler;
socket_type m_socket;
boost::system::error_code m_error;
bool m_canAccept;
Request (CheckerImp& owner, boost::asio::io_service& io_service,
IPEndpoint const& address, AbstractHandler <void (Result)> handler)
IPAddress const& address, AbstractHandler <void (Result)> handler)
: m_owner (owner)
, m_io_service (io_service)
, m_address (address)
@@ -88,7 +88,7 @@ private:
{
m_owner.add (*this);
m_socket.async_connect (fromIPEndpoint (m_address),
m_socket.async_connect (fromIPAddress (m_address),
wrapHandler (boost::bind (&Request::handle_connect, Ptr(this),
boost::asio::placeholders::error), m_handler));
}
@@ -165,7 +165,7 @@ public:
iter->cancel();
}
void async_test (IPEndpoint const& endpoint,
void async_test (IPAddress const& endpoint,
AbstractHandler <void (Result)> handler)
{
new Request (*this, m_io_service, endpoint, handler);

View File

@@ -54,7 +54,7 @@ public:
{ }
/** The original address. */
IPEndpoint address;
IPAddress address;
/** The error code from the operation. */
boost::system::error_code error;
@@ -71,7 +71,7 @@ public:
void (Result const& result);
*/
template <typename Handler>
void async_test (IPEndpoint const& endpoint,
void async_test (IPAddress const& endpoint,
BEAST_MOVE_ARG(Handler) handler)
{
async_test (endpoint,
@@ -79,7 +79,7 @@ public:
BEAST_MOVE_CAST(Handler)(handler)));
}
virtual void async_test (IPEndpoint const& endpoint,
virtual void async_test (IPAddress const& endpoint,
AbstractHandler <void (Result)> handler) = 0;
};

View File

@@ -86,7 +86,7 @@ public:
m_checker->cancel();
}
void async_test (IPEndpoint const& endpoint,
void async_test (IPAddress const& endpoint,
AbstractHandler <void (Checker::Result)> handler)
{
m_checker->async_test (endpoint, Handler (

View File

@@ -32,13 +32,13 @@ struct LegacyEndpoint
, canAccept (false)
{ }
LegacyEndpoint (IPEndpoint const& address_, DiscreteTime now)
LegacyEndpoint (IPAddress const& address_, DiscreteTime now)
: address (address_)
, whenInserted (now)
, lastGet(0)
{ }
IPEndpoint address;
IPAddress address;
// When we inserted the endpoint into the cache
DiscreteTime mutable whenInserted;

View File

@@ -33,8 +33,8 @@ private:
typedef boost::multi_index_container <
LegacyEndpoint, boost::multi_index::indexed_by <
boost::multi_index::hashed_unique <
BOOST_MULTI_INDEX_MEMBER(PeerFinder::LegacyEndpoint,IPEndpoint,address),
IPEndpoint::hasher>
BOOST_MULTI_INDEX_MEMBER(PeerFinder::LegacyEndpoint,IPAddress,address),
IPAddress::hasher>
>
> MapType;
@@ -166,7 +166,7 @@ public:
/** Load the legacy endpoints cache from the database. */
void load (DiscreteTime now)
{
typedef std::vector <IPEndpoint> List;
typedef std::vector <IPAddress> List;
List list;
m_store.loadLegacyEndpoints (list);
std::size_t n (0);
@@ -186,7 +186,7 @@ public:
The return value provides a reference to the new or existing endpoint.
The bool indicates whether or not the insertion took place.
*/
std::pair <LegacyEndpoint const&, bool> insert (IPEndpoint const& address, DiscreteTime now)
std::pair <LegacyEndpoint const&, bool> insert (IPAddress const& address, DiscreteTime now)
{
std::pair <MapType::iterator, bool> result (
m_map.insert (LegacyEndpoint (address, now)));
@@ -198,7 +198,7 @@ public:
}
/** Returns a pointer to the legacy endpoint if it exists, else nullptr. */
LegacyEndpoint const* find (IPEndpoint const& address)
LegacyEndpoint const* find (IPAddress const& address)
{
MapType::iterator iter (m_map.find (address));
if (iter != m_map.end())
@@ -209,7 +209,7 @@ public:
/** Updates the metadata following a connection attempt.
@param canAccept A flag indicating if the connection succeeded.
*/
void checked (IPEndpoint const& address, bool canAccept)
void checked (IPAddress const& address, bool canAccept)
{
LegacyEndpoint const* endpoint (find (address));
if (endpoint != nullptr)
@@ -224,7 +224,7 @@ public:
Also updates the lastGet field of the LegacyEndpoint so we will avoid
re-using the address until we have tried all the others.
*/
void get (std::size_t n, std::vector <IPEndpoint>& result, DiscreteTime now) const
void get (std::size_t n, std::vector <IPAddress>& result, DiscreteTime now) const
{
FlattenedList list (flatten());
std::random_shuffle (list.begin(), list.end());

View File

@@ -42,8 +42,8 @@ typedef boost::multi_index_container <
BOOST_MULTI_INDEX_MEMBER(PeerFinder::PeerInfo,PeerID,id),
PeerID::hasher>,
boost::multi_index::hashed_non_unique <
BOOST_MULTI_INDEX_MEMBER(PeerFinder::PeerInfo,IPEndpoint,address),
IPEndpoint::hasher>
BOOST_MULTI_INDEX_MEMBER(PeerFinder::PeerInfo,IPAddress,address),
IPAddress::hasher>
>
> Peers;
@@ -87,7 +87,7 @@ public:
int m_fixedPeersConnected;
// A list of peers that should always be connected
typedef std::set <IPEndpoint> FixedPeers;
typedef std::set <IPAddress> FixedPeers;
FixedPeers m_fixedPeers;
// A list of dynamic sources to consult as a fallback
@@ -151,8 +151,8 @@ public:
bassert (m_config.wantIncoming);
Endpoint ep;
ep.address = IPEndpoint (
IPEndpoint::V4 ()).withPort (m_config.listeningPort);
ep.address = IPAddress (
IPAddress::V4 ()).withPort (m_config.listeningPort);
ep.hops = 0;
ep.incomingSlotsAvailable = m_slots.inboundSlots;
ep.incomingSlotsMax = m_slots.inboundSlotsMaximum;
@@ -161,9 +161,9 @@ public:
return ep;
}
// Returns true if the IPEndpoint contains no invalid data.
// Returns true if the IPAddress contains no invalid data.
//
bool validIPEndpoint (IPEndpoint const& address)
bool validIPAddress (IPAddress const& address)
{
if (! address.isPublic())
return false;
@@ -180,7 +180,7 @@ public:
if (m_config.connectAutomatically)
return;
std::vector <IPEndpoint> list;
std::vector <IPAddress> list;
if (m_slots.outDesired > m_slots.outboundCount)
{
@@ -233,7 +233,7 @@ public:
for (std::vector <std::string>::const_iterator iter (strings.begin());
iter != strings.end(); ++iter)
{
IPEndpoint ep (IPEndpoint::from_string (*iter));
IPAddress ep (IPAddress::from_string (*iter));
if (! ep.empty ())
{
m_fixedPeers.insert (ep);
@@ -275,7 +275,7 @@ public:
// but we are *NOT* guaranteed that the IP isn't. So we need
// to be careful.
void onPeerConnected (PeerID const& id,
IPEndpoint const& address, bool inbound)
IPAddress const& address, bool inbound)
{
m_journal.debug << "Peer connected: " << address;
// If this is outgoing, record the success
@@ -316,7 +316,7 @@ public:
// This function is here in case we add more stuff
// we want to validate to the Endpoint struct.
//
return validIPEndpoint (endpoint.address);
return validIPAddress (endpoint.address);
}
// Prunes invalid endpoints from a list.
@@ -385,7 +385,7 @@ public:
// Called when the Checker completes a connectivity test
//
void onCheckEndpoint (PeerID const& id,
IPEndpoint address, Checker::Result const& result)
IPAddress address, Checker::Result const& result)
{
if (result.error == boost::asio::error::operation_aborted)
return;
@@ -562,7 +562,7 @@ public:
std::size_t newEntries (0);
DiscreteTime now (get_now());
for (std::vector <IPEndpoint>::const_iterator iter (results.list.begin());
for (std::vector <IPAddress>::const_iterator iter (results.list.begin());
iter != results.list.end(); ++iter)
{
std::pair <LegacyEndpoint const&, bool> result (
@@ -586,7 +586,7 @@ public:
// Completion handler for a LegacyEndpoint listening test.
//
void onCheckLegacyEndpoint (IPEndpoint const& endpoint,
void onCheckLegacyEndpoint (IPAddress const& endpoint,
Checker::Result const& result)
{
if (result.error == boost::asio::error::operation_aborted)
@@ -608,9 +608,9 @@ public:
}
}
void onPeerLegacyEndpoint (IPEndpoint const& address)
void onPeerLegacyEndpoint (IPAddress const& address)
{
if (! validIPEndpoint (address))
if (! validIPAddress (address))
return;
std::pair <LegacyEndpoint const&, bool> result (
m_legacyCache.insert (address, get_now()));

View File

@@ -268,7 +268,7 @@ public:
}
void onPeerConnected (PeerID const& id,
IPEndpoint const& address, bool incoming)
IPAddress const& address, bool incoming)
{
m_queue.dispatch (
m_context.wrap (
@@ -284,7 +284,7 @@ public:
id)));
}
void onPeerLegacyEndpoint (IPEndpoint const& ep)
void onPeerLegacyEndpoint (IPAddress const& ep)
{
m_queue.dispatch (
m_context.wrap (

View File

@@ -31,7 +31,7 @@ namespace PeerFinder {
struct PeerInfo
{
PeerInfo (PeerID const& id_,
IPEndpoint const& address_,
IPAddress const& address_,
bool inbound_,
DiscreteTime now)
: id (id_)
@@ -46,7 +46,7 @@ struct PeerInfo
}
PeerID id;
IPEndpoint address;
IPAddress address;
bool inbound;
// Tells us if we checked the connection. Outbound connections
@@ -70,12 +70,12 @@ struct PeerInfo
//
DiscreteTime mutable whenAcceptEndpoints;
// The set of all recent IPEndpoint that we have seen from this peer.
// The set of all recent IPAddress that we have seen from this peer.
// We try to avoid sending a peer the same addresses they gave us.
//
CycledSet <IPEndpoint,
IPEndpoint::hasher,
IPEndpoint::key_equal> mutable received;
CycledSet <IPAddress,
IPAddress::hasher,
IPAddress::key_equal> mutable received;
};
}

View File

@@ -41,7 +41,7 @@ public:
ErrorCode error;
// list of fetched endpoints
std::vector <IPEndpoint> list;
std::vector <IPAddress> list;
};
virtual ~Source () { }

View File

@@ -44,8 +44,8 @@ public:
results.list.reserve (m_strings.size());
for (int i = 0; i < m_strings.size (); ++i)
{
IPEndpoint ep (
IPEndpoint::from_string_altform (
IPAddress ep (
IPAddress::from_string_altform (
m_strings [i]));
if (! ep.empty())
results.list.push_back (ep);

View File

@@ -30,7 +30,7 @@ public:
virtual ~Store () { }
virtual void loadLegacyEndpoints (
std::vector <IPEndpoint>& list) = 0;
std::vector <IPAddress>& list) = 0;
virtual void updateLegacyEndpoints (
std::vector <LegacyEndpoint const*> const& list) = 0;

View File

@@ -64,7 +64,7 @@ public:
}
void loadLegacyEndpoints (
std::vector <IPEndpoint>& list)
std::vector <IPAddress>& list)
{
list.clear ();
@@ -99,7 +99,7 @@ public:
{
do
{
IPEndpoint ep (IPEndpoint::from_string (s));
IPAddress ep (IPAddress::from_string (s));
if (! ep.empty())
list.push_back (ep);
}
@@ -140,7 +140,7 @@ public:
for (List::const_iterator iter (list.begin());
!error && iter != list.end(); ++iter)
{
IPEndpoint const& ep ((*iter)->address);
IPAddress const& ep ((*iter)->address);
s = ep.to_string();
st.execute_and_fetch (error);
}

View File

@@ -30,7 +30,7 @@ struct Gossip
struct Item
{
int balance;
IPEndpoint address;
IPAddress address;
};
std::vector <Item> items;

View File

@@ -35,10 +35,10 @@ public:
virtual ~Manager() { }
/** Create a new endpoint keyed by inbound IP address. */
virtual Consumer newInboundEndpoint (IPEndpoint const& address) = 0;
virtual Consumer newInboundEndpoint (IPAddress const& address) = 0;
/** Create a new endpoint keyed by outbound IP address and port. */
virtual Consumer newOutboundEndpoint (IPEndpoint const& address) = 0;
virtual Consumer newOutboundEndpoint (IPAddress const& address) = 0;
/** Create a new endpoint keyed by name. */
virtual Consumer newAdminEndpoint (std::string const& name) = 0;

View File

@@ -27,7 +27,7 @@ namespace Resource {
struct Key
{
Kind kind;
IPEndpoint address;
IPAddress address;
std::string name;
struct hasher
@@ -51,7 +51,7 @@ struct Key
}
private:
IPEndpoint::hasher m_addr_hash;
IPAddress::hasher m_addr_hash;
boost::hash <std::string> m_name_hash;
};

View File

@@ -85,7 +85,7 @@ public:
state->table.clear();
}
Consumer newInboundEndpoint (IPEndpoint const& address)
Consumer newInboundEndpoint (IPAddress const& address)
{
if (isWhitelisted (address))
return newAdminEndpoint (address.to_string());
@@ -117,7 +117,7 @@ public:
return Consumer (*this, *entry);
}
Consumer newOutboundEndpoint (IPEndpoint const& address)
Consumer newOutboundEndpoint (IPAddress const& address)
{
if (isWhitelisted (address))
return newAdminEndpoint (address.to_string());
@@ -294,7 +294,7 @@ public:
//--------------------------------------------------------------------------
bool isWhitelisted (IPEndpoint const& address)
bool isWhitelisted (IPAddress const& address)
{
if (! address.isPublic())
return true;

View File

@@ -41,12 +41,12 @@ public:
stopThread ();
}
Consumer newInboundEndpoint (IPEndpoint const& address)
Consumer newInboundEndpoint (IPAddress const& address)
{
return m_logic.newInboundEndpoint (address);
}
Consumer newOutboundEndpoint (IPEndpoint const& address)
Consumer newOutboundEndpoint (IPAddress const& address)
{
return m_logic.newOutboundEndpoint (address);
}

View File

@@ -32,7 +32,7 @@ public:
{
Gossip::Item item;
item.balance = 100 + random().nextInt (500);
item.address = IPEndpoint (IPEndpoint::V4 (
item.address = IPAddress (IPAddress::V4 (
207, 127, 82, v + i));
gossip.items.push_back (item);
}
@@ -64,7 +64,7 @@ public:
Gossip g;
Gossip::Item item;
item.balance = 100;
item.address = IPEndpoint (IPEndpoint::V4 (207, 127, 82, 1));
item.address = IPAddress (IPAddress::V4 (207, 127, 82, 1));
g.items.push_back (item);
logic.importConsumers ("g", g);
@@ -79,7 +79,7 @@ public:
LogicType <ManualClock> logic (journal());
{
IPEndpoint address (IPEndpoint::from_string ("207.127.82.1"));
IPAddress address (IPAddress::from_string ("207.127.82.1"));
Consumer c (logic.newInboundEndpoint (address));
logMessage ("Charging " + c.label() + " 10,000 units");
c.charge (10000);
@@ -93,7 +93,7 @@ public:
}
{
IPEndpoint address (IPEndpoint::from_string ("207.127.82.2"));
IPAddress address (IPAddress::from_string ("207.127.82.2"));
Consumer c (logic.newInboundEndpoint (address));
logMessage ("Charging " + c.label() + " 1000 units per second");
for (int i = 0; i < 128; ++i)

View File

@@ -65,7 +65,7 @@ public:
if (! getConfig ().getRpcIP().empty () &&
getConfig ().getRpcPort() != 0)
{
IPEndpoint ep (IPEndpoint::from_string (getConfig().getRpcIP()));
IPAddress ep (IPAddress::from_string (getConfig().getRpcIP()));
if (! ep.empty())
{
HTTP::Port port;

View File

@@ -119,7 +119,7 @@ private:
protocol::TMHello mHello;
bool m_remoteAddressSet;
IPEndpoint m_remoteAddress;
IPAddress m_remoteAddress;
Resource::Consumer m_usage;
public:
@@ -215,7 +215,7 @@ public:
return (uMin >= mMinLedger) && (uMax <= mMaxLedger);
}
IPEndpoint getPeerEndpoint() const
IPAddress getPeerEndpoint() const
{
return m_remoteAddress;
}
@@ -308,6 +308,7 @@ private:
}
else
{
if (m_socket->getFlags ().set (MultiSocket::Flag::proxy) && m_isInbound)
{
MultiSocket::ProxyInfo const proxyInfo (m_socket->getProxyInfo ());
@@ -315,7 +316,7 @@ private:
if (proxyInfo.protocol == "TCP4")
{
m_remoteAddressSet = true;
m_remoteAddress = IPEndpoint (IPEndpoint::V4 (
m_remoteAddress = IPAddress (IPAddress::V4 (
proxyInfo.sourceAddress.value [0],
proxyInfo.sourceAddress.value [1],
proxyInfo.sourceAddress.value [2],
@@ -359,7 +360,7 @@ private:
if (addr.is_v4())
{
boost::asio::ip::address_v4::bytes_type bytes (addr.to_v4().to_bytes());
m_remoteAddress = IPEndpoint (IPEndpoint::V4 (
m_remoteAddress = IPAddress (IPAddress::V4 (
bytes[0], bytes[1], bytes[2], bytes[3]), 0);
if (! m_isInbound)
m_remoteAddress = m_remoteAddress.withPort (
@@ -1693,8 +1694,8 @@ void PeerImp::recvPeers (protocol::TMPeers& packet)
addr.s_addr = packet.nodes (i).ipv4 ();
{
IPEndpoint::V4 v4 (ntohl (addr.s_addr));
IPEndpoint ep (v4, packet.nodes (i).ipv4port ());
IPAddress::V4 v4 (ntohl (addr.s_addr));
IPAddress ep (v4, packet.nodes (i).ipv4port ());
getApp().getPeers().getPeerFinder().onPeerLegacyEndpoint (ep);
}
@@ -1729,8 +1730,8 @@ void PeerImp::recvEndpoints (protocol::TMEndpoints& packet)
{
in_addr addr;
addr.s_addr = tm.ipv4().ipv4();
IPEndpoint::V4 v4 (ntohl (addr.s_addr));
endpoint.address = IPEndpoint (v4, tm.ipv4().ipv4port ());
IPAddress::V4 v4 (ntohl (addr.s_addr));
endpoint.address = IPAddress (v4, tm.ipv4().ipv4port ());
}
else
{

View File

@@ -109,7 +109,7 @@ public:
virtual bool hasRange (uint32 uMin, uint32 uMax) = 0;
virtual IPEndpoint getPeerEndpoint() const = 0;
virtual IPAddress getPeerEndpoint() const = 0;
//--------------------------------------------------------------------------

View File

@@ -189,9 +189,9 @@ public:
}
}
void connectPeerEndpoints (std::vector <IPEndpoint> const& list)
void connectPeerEndpoints (std::vector <IPAddress> const& list)
{
typedef std::vector <IPEndpoint> List;
typedef std::vector <IPAddress> List;
for (List::const_iterator iter (list.begin());
iter != list.end(); ++iter)

View File

@@ -92,10 +92,10 @@ public:
typedef WSServerHandler <endpoint_type> server_type;
public:
static IPEndpoint from_address (boost::asio::ip::address const& addr)
static IPAddress from_address (boost::asio::ip::address const& addr)
{
boost::asio::ip::address_v4::bytes_type bytes (addr.to_v4().to_bytes());
IPEndpoint ep (IPEndpoint::V4 (bytes[0], bytes[1], bytes[2], bytes[3]), 0);
IPAddress ep (IPAddress::V4 (bytes[0], bytes[1], bytes[2], bytes[3]), 0);
return ep;
}