diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj
index 455746b30..cdaea28a8 100644
--- a/Builds/VisualStudio2012/beast.vcxproj
+++ b/Builds/VisualStudio2012/beast.vcxproj
@@ -137,7 +137,7 @@
-
+
@@ -303,7 +303,6 @@
-
@@ -490,7 +489,7 @@
true
true
-
+
true
true
true
@@ -1033,12 +1032,6 @@
true
true
-
- true
- true
- true
- true
-
true
true
diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters
index 077df7635..1f927cb51 100644
--- a/Builds/VisualStudio2012/beast.vcxproj.filters
+++ b/Builds/VisualStudio2012/beast.vcxproj.filters
@@ -416,9 +416,6 @@
beast_core\native
-
- beast_core\network
-
beast_core\network
@@ -932,9 +929,6 @@
beast_core\memory
-
- beast\net
-
beast
@@ -1254,6 +1248,9 @@
beast\utility
+
+ beast\net
+
@@ -1361,9 +1358,6 @@
beast_core\native
-
- beast_core\network
-
beast_core\network
@@ -1682,9 +1676,6 @@
beast_extras
-
- beast\net\impl
-
beast\net
@@ -1805,6 +1796,9 @@
beast\utility\impl
+
+ beast\net\impl
+
diff --git a/beast/Net.h b/beast/Net.h
index 091c940f0..79515845a 100644
--- a/beast/Net.h
+++ b/beast/Net.h
@@ -23,6 +23,6 @@
#include "net/BufferType.h"
#include "net/DynamicBuffer.h"
-#include "net/IPEndpoint.h"
+#include "net/IPAddress.h"
#endif
diff --git a/beast/net/IPEndpoint.h b/beast/net/IPAddress.h
similarity index 75%
rename from beast/net/IPEndpoint.h
rename to beast/net/IPAddress.h
index 185229717..1903f89f4 100644
--- a/beast/net/IPEndpoint.h
+++ b/beast/net/IPAddress.h
@@ -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
#include
@@ -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;
}
diff --git a/beast/net/Net.cpp b/beast/net/Net.cpp
index 6a84e2185..a176d962f 100644
--- a/beast/net/Net.cpp
+++ b/beast/net/Net.cpp
@@ -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"
diff --git a/beast/net/impl/IPEndpoint.cpp b/beast/net/impl/IPAddress.cpp
similarity index 69%
rename from beast/net/impl/IPEndpoint.cpp
rename to beast/net/impl/IPAddress.cpp
index ffa2bf77b..fb6855233 100644
--- a/beast/net/impl/IPEndpoint.cpp
+++ b/beast/net/impl/IPAddress.cpp
@@ -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 IPEndpoint::V4::operator[] (std::size_t index) const
+IPAddress::V4::Proxy IPAddress::V4::operator[] (std::size_t index) const
{
switch (index)
{
@@ -116,7 +115,7 @@ IPEndpoint::V4::Proxy IPEndpoint::V4::operator[] (std::size_t index) cons
};
};
-IPEndpoint::V4::Proxy IPEndpoint::V4::operator[] (std::size_t index)
+IPAddress::V4::Proxy IPAddress::V4::operator[] (std::size_t index)
{
switch (index)
{
@@ -129,7 +128,7 @@ IPEndpoint::V4::Proxy 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 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;
}
diff --git a/modules/beast_core/beast_core.cpp b/modules/beast_core/beast_core.cpp
index 8608e180d..92abf6fb4 100644
--- a/modules/beast_core/beast_core.cpp
+++ b/modules/beast_core/beast_core.cpp
@@ -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"
diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h
index fff039ba9..e095d1d27 100644
--- a/modules/beast_core/beast_core.h
+++ b/modules/beast_core/beast_core.h
@@ -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"
diff --git a/modules/beast_core/native/win32_Network.cpp b/modules/beast_core/native/win32_Network.cpp
index d85cc01de..231b897ab 100644
--- a/modules/beast_core/native/win32_Network.cpp
+++ b/modules/beast_core/native/win32_Network.cpp
@@ -112,24 +112,6 @@ void MACAddress::findAllAddresses (Array& result)
MACAddressHelpers::getViaNetBios (result);
}
-void IPAddress::findAllAddresses (Array& 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,
diff --git a/modules/beast_core/network/IPAddress.cpp b/modules/beast_core/network/IPAddress.cpp
deleted file mode 100644
index 08e69bee3..000000000
--- a/modules/beast_core/network/IPAddress.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- This file is part of Beast: https://github.com/vinniefalco/Beast
- Copyright 2013, Vinnie Falco
-
- 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& 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& result)
-{
- ifconf cfg;
- HeapBlock 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& 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
diff --git a/modules/beast_core/network/IPAddress.h b/modules/beast_core/network/IPAddress.h
deleted file mode 100644
index 6847d7aef..000000000
--- a/modules/beast_core/network/IPAddress.h
+++ /dev/null
@@ -1,77 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- This file is part of Beast: https://github.com/vinniefalco/Beast
- Copyright 2013, Vinnie Falco
-
- 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& 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
diff --git a/modules/beast_core/network/URL.cpp b/modules/beast_core/network/URL.cpp
deleted file mode 100644
index 8e71c6db9..000000000
--- a/modules/beast_core/network/URL.cpp
+++ /dev/null
@@ -1,468 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- This file is part of Beast: https://github.com/vinniefalco/Beast
- Copyright 2013, Vinnie Falco
-
- 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::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 in (createInputStream (usePostCommand));
-
- if (in != nullptr)
- {
- in->readIntoMemoryBlock (destData);
- return true;
- }
-
- return false;
-}
-
-String URL::readEntireTextStream (const bool usePostCommand) const
-{
- const ScopedPointer 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 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 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);
-}
diff --git a/modules/beast_core/network/URL.h b/modules/beast_core/network/URL.h
deleted file mode 100644
index 589f974f0..000000000
--- a/modules/beast_core/network/URL.h
+++ /dev/null
@@ -1,342 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- This file is part of Beast: https://github.com/vinniefalco/Beast
- Copyright 2013, Vinnie Falco
-
- 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
-{
-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