diff --git a/include/eepp/network.hpp b/include/eepp/network.hpp index e70e79350..220f63eda 100644 --- a/include/eepp/network.hpp +++ b/include/eepp/network.hpp @@ -1,16 +1,16 @@ #ifndef EEPP_NETWORK_HPP #define EEPP_NETWORK_HPP -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #endif diff --git a/include/eepp/network/cftp.hpp b/include/eepp/network/ftp.hpp similarity index 93% rename from include/eepp/network/cftp.hpp rename to include/eepp/network/ftp.hpp index f87b8c9c2..d17957c42 100644 --- a/include/eepp/network/cftp.hpp +++ b/include/eepp/network/ftp.hpp @@ -2,7 +2,7 @@ #define EE_NETWORKCFTP_HPP #include -#include +#include #include #include #include @@ -12,10 +12,10 @@ using namespace EE::System; namespace EE { namespace Network { -class cIpAddress; +class IpAddress; /** @brief A FTP client */ -class EE_API cFtp : NonCopyable { +class EE_API Ftp : NonCopyable { public: /** @brief Enumeration of transfer modes */ enum TransferMode @@ -164,7 +164,7 @@ public: /** @brief Destructor ** Automatically closes the connection with the server if ** it is still opened. */ - ~cFtp(); + ~Ftp(); /** @brief Connect to the specified FTP server @@ -181,7 +181,7 @@ public: ** @param timeout Maximum time to wait ** @return Server response to the request ** @see Disconnect */ - Response Connect(const cIpAddress& server, unsigned short port = 21, cTime timeout = cTime::Zero); + Response Connect(const IpAddress& server, unsigned short port = 21, cTime timeout = cTime::Zero); /** @brief Close the connection with the server ** @return Server response to the request @@ -319,7 +319,7 @@ private : friend class DataChannel; // Member data - cTcpSocket mCommandSocket; ///< Socket holding the control connection with the server + TcpSocket mCommandSocket; ///< Socket holding the control connection with the server }; }} @@ -327,10 +327,10 @@ private : #endif // EE_NETWORKCFTP_HPP /** -@class cFtp +@class Ftp @ingroup Network -cFtp is a very simple FTP client that allows you +Ftp is a very simple FTP client that allows you to communicate with a FTP server. The FTP protocol allows you to manipulate a remote file system (list files, upload, download, create, remove, ...). @@ -343,7 +343,7 @@ Every command returns a FTP response, which contains the status code as well as a message from the server. Some commands such as GetWorkingDirectory and GetDirectoryListing return additional data, and use a class derived from -cFtp::Response to provide this data. +Ftp::Response to provide this data. All commands, especially upload and download, may take some time to complete. This is important to know if you don't want to block your application while the server is completing @@ -351,10 +351,10 @@ the task. Usage example: @code // Create a new FTP client -cFtp ftp; +Ftp ftp; // Connect to the server -cFtp::Response response = ftp.Connect("ftp://ftp.myserver.com"); +Ftp::Response response = ftp.Connect("ftp://ftp.myserver.com"); if (response.IsOk()) std::cout << "Connected" << std::endl; @@ -364,7 +364,7 @@ if (response.IsOk()) std::cout << "Logged in" << std::endl; // Print the working directory -cFtp::DirectoryResponse directory = ftp.GetWorkingDirectory(); +Ftp::DirectoryResponse directory = ftp.GetWorkingDirectory(); if (directory.IsOk()) std::cout << "Working directory: " << directory.GetDirectory() << std::endl; @@ -374,7 +374,7 @@ if (response.IsOk()) std::cout << "Created new directory" << std::endl; // Upload a file to this new directory -response = ftp.Upload("local-path/file.txt", "files", cFtp::Ascii); +response = ftp.Upload("local-path/file.txt", "files", Ftp::Ascii); if (response.IsOk()) std::cout << "File uploaded" << std::endl; diff --git a/include/eepp/network/chttp.hpp b/include/eepp/network/http.hpp similarity index 87% rename from include/eepp/network/chttp.hpp rename to include/eepp/network/http.hpp index 1ebd9a1c9..2d2d968d2 100644 --- a/include/eepp/network/chttp.hpp +++ b/include/eepp/network/http.hpp @@ -2,8 +2,8 @@ #define EE_NETWORKCHTTP_HPP #include -#include -#include +#include +#include #include #include #include @@ -20,7 +20,7 @@ using namespace EE::System; namespace EE { namespace Network { /** @brief A HTTP client */ -class EE_API cHttp : NonCopyable { +class EE_API Http : NonCopyable { public : /** @brief Define a HTTP request */ class EE_API Request { @@ -57,7 +57,7 @@ class EE_API cHttp : NonCopyable { /** @brief Set the request method ** See the Method enumeration for a complete list of all ** the availale methods. - ** The method is cHttp::Request::Get by default. + ** The method is Http::Request::Get by default. ** @param method Method to use for the request */ void SetMethod(Method method); @@ -96,10 +96,10 @@ class EE_API cHttp : NonCopyable { /** Enable/disable SSL hostname validation */ void ValidateHostname( bool enable ); private: - friend class cHttp; + friend class Http; /** @brief Prepare the final request to send to the server - ** This is used internally by cHttp before sending the + ** This is used internally by Http before sending the ** request to the web server. ** @return String containing the request, ready to be sent */ std::string Prepare() const; @@ -203,10 +203,10 @@ class EE_API cHttp : NonCopyable { ** @return The response body */ const std::string& GetBody() const; private : - friend class cHttp; + friend class Http; /** @brief Construct the header from a response string - ** This function is used by cHttp to build the response + ** This function is used by Http to build the response ** of a request. ** @param data Content of the response to parse */ void Parse(const std::string& data); @@ -229,7 +229,7 @@ class EE_API cHttp : NonCopyable { }; /** @brief Default constructor */ - cHttp(); + Http(); /** @brief Construct the HTTP client with the target host ** This is equivalent to calling SetHost(host, port). @@ -241,9 +241,9 @@ class EE_API cHttp : NonCopyable { ** @param host Web server to connect to ** @param port Port to use for connection ** @param useSSL force the SSL usage ( if compiled with the support of it ). If the host starts with https:// it will use it by default. */ - cHttp(const std::string& host, unsigned short port = 0, bool useSSL = false); + Http(const std::string& host, unsigned short port = 0, bool useSSL = false); - ~cHttp(); + ~Http(); /** @brief Set the target host ** This function just stores the host address and port, it @@ -273,15 +273,15 @@ class EE_API cHttp : NonCopyable { Response SendRequest(const Request& request, cTime timeout = cTime::Zero); /** Definition of the async callback response */ - typedef cb::Callback3 AsyncResponseCallback; + typedef cb::Callback3 AsyncResponseCallback; /** @brief Sends the request and creates a new thread, when got the response informs the result to the callback. ** This function does not lock the caller thread. ** @see SendRequest */ - void SendAsyncRequest( AsyncResponseCallback cb, const cHttp::Request& request, cTime timeout = cTime::Zero ); + void SendAsyncRequest( AsyncResponseCallback cb, const Http::Request& request, cTime timeout = cTime::Zero ); /** @return The host address */ - const cIpAddress& GetHost() const; + const IpAddress& GetHost() const; /** @return The host name */ const std::string& GetHostName() const; @@ -291,20 +291,20 @@ class EE_API cHttp : NonCopyable { private: class cAsyncRequest : public cThread { public: - cAsyncRequest( cHttp * http, AsyncResponseCallback cb, cHttp::Request request, cTime timeout ); + cAsyncRequest( Http * http, AsyncResponseCallback cb, Http::Request request, cTime timeout ); void Run(); protected: - friend class cHttp; - cHttp * mHttp; + friend class Http; + Http * mHttp; AsyncResponseCallback mCb; - cHttp::Request mRequest; + Http::Request mRequest; cTime mTimeout; bool mRunning; }; friend class cAsyncRequest; - tThreadLocalPtr mConnection; ///< Connection to the host - cIpAddress mHost; ///< Web host address + tThreadLocalPtr mConnection; ///< Connection to the host + IpAddress mHost; ///< Web host address std::string mHostName; ///< Web host name unsigned short mPort; ///< Port used for connection with host std::list mThreads; @@ -319,47 +319,47 @@ class EE_API cHttp : NonCopyable { #endif // EE_NETWORKCHTTP_HPP /** -@class cHttp +@class Http @ingroup Network -cHttp is a very simple HTTP client that allows you +Http is a very simple HTTP client that allows you to communicate with a web server. You can retrieve web pages, send data to an interactive resource, download a remote file, etc. The HTTP client is split into 3 classes: -@li cHttp::Request -@li cHttp::Response -@li cHttp -cHttp::Request builds the request that will be +@li Http::Request +@li Http::Response +@li Http +Http::Request builds the request that will be sent to the server. A request is made of: @li a method (what you want to do) @li a target URI (usually the name of the web page or file) @li one or more header fields (options that you can pass to the server) @li an optional body (for POST requests) -cHttp::Response parse the response from the web server +Http::Response parse the response from the web server and provides getters to read them. The response contains: @li a status code @li header fields (that may be answers to the ones that you requested) @li a body, which contains the contents of the requested resource -cHttp provides a simple function, SendRequest, to send a -cHttp::Request and return the corresponding cHttp::Response +Http provides a simple function, SendRequest, to send a +Http::Request and return the corresponding Http::Response from the server. Usage example: @code // Create a new HTTP client -cHttp http; +Http http; // We'll work on http://www.google.com http.SetHost("http://www.google.com"); // Prepare a request to get the 'features.php' page -cHttp::Request request("features.php"); +Http::Request request("features.php"); // Send the request -cHttp::Response response = http.SendRequest(request); +Http::Response response = http.SendRequest(request); // Check the status code and display the result -cHttp::Response::Status status = response.GetStatus(); -if (status == cHttp::Response::Ok) +Http::Response::Status status = response.GetStatus(); +if (status == Http::Response::Ok) { std::cout << response.GetBody() << std::endl; } diff --git a/include/eepp/network/cipaddress.hpp b/include/eepp/network/ipaddress.hpp similarity index 69% rename from include/eepp/network/cipaddress.hpp rename to include/eepp/network/ipaddress.hpp index 2013b3a2c..89a877ee7 100644 --- a/include/eepp/network/cipaddress.hpp +++ b/include/eepp/network/ipaddress.hpp @@ -12,46 +12,46 @@ using namespace EE::System; namespace EE { namespace Network { /** @brief Encapsulate an IPv4 network address */ -class EE_API cIpAddress +class EE_API IpAddress { public: /** @brief Default constructor ** This constructor creates an empty (invalid) address */ - cIpAddress(); + IpAddress(); /** @brief Construct the address from a string ** Here @a address can be either a decimal address ** (ex: "192.168.1.56") or a network name (ex: "localhost"). ** @param address IP address or network name */ - cIpAddress(const std::string& address); + IpAddress(const std::string& address); /** @brief Construct the address from a string ** Here @a address can be either a decimal address ** (ex: "192.168.1.56") or a network name (ex: "localhost"). ** This is equivalent to the constructor taking a std::string ** parameter, it is defined for convenience so that the - ** implicit conversions from literal strings to cIpAddress work. + ** implicit conversions from literal strings to IpAddress work. ** @param address IP address or network name */ - cIpAddress(const char* address); + IpAddress(const char* address); /** @brief Construct the address from 4 bytes - ** Calling cIpAddress(a, b, c, d) is equivalent to calling - ** cIpAddress("a.b.c.d"), but safer as it doesn't have to + ** Calling IpAddress(a, b, c, d) is equivalent to calling + ** IpAddress("a.b.c.d"), but safer as it doesn't have to ** parse a string to get the address components. ** @param byte0 First byte of the address ** @param byte1 Second byte of the address ** @param byte2 Third byte of the address ** @param byte3 Fourth byte of the address */ - cIpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3); + IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3); /** @brief Construct the address from a 32-bits integer ** This constructor uses the internal representation of ** the address directly. It should be used for optimization ** purposes, and only if you got that representation from - ** cIpAddress::ToInteger(). + ** IpAddress::ToInteger(). ** @param address 4 bytes of the address packed into a 32-bits integer ** @see ToInteger */ - explicit cIpAddress(Uint32 address); + explicit IpAddress(Uint32 address); /** @brief Get a string representation of the address ** The returned string is the decimal representation of the @@ -66,7 +66,7 @@ class EE_API cIpAddress ** address, and should be used for optimization purposes only ** (like sending the address through a socket). ** The integer produced by this function can then be converted - ** back to a cIpAddress with the proper constructor. + ** back to a IpAddress with the proper constructor. ** @return 32-bits unsigned integer representation of the address ** @see ToString */ Uint32 ToInteger() const; @@ -79,7 +79,7 @@ class EE_API cIpAddress ** used safely anywhere. ** @return Local IP address of the computer ** @see GetPublicAddress */ - static cIpAddress GetLocalAddress(); + static IpAddress GetLocalAddress(); /** @brief Get the computer's public address ** The public address is the address of the computer from the @@ -96,12 +96,12 @@ class EE_API cIpAddress ** @param timeout Maximum time to wait ** @return Public IP address of the computer ** @see GetLocalAddress */ - static cIpAddress GetPublicAddress(cTime timeout = cTime::Zero); + static IpAddress GetPublicAddress(cTime timeout = cTime::Zero); // Static member data - static const cIpAddress None; ///< Value representing an empty/invalid address - static const cIpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally) - static const cIpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network) + static const IpAddress None; ///< Value representing an empty/invalid address + static const IpAddress LocalHost; ///< The "localhost" address (for connecting a computer to itself locally) + static const IpAddress Broadcast; ///< The "broadcast" address (for sending UDP messages to everyone on a local network) private : // Member data Uint32 mAddress; ///< Address stored as an unsigned 32 bits integer @@ -111,75 +111,75 @@ class EE_API cIpAddress ** @param left Left operand (a IP address) ** @param right Right operand (a IP address) ** @return True if both addresses are equal */ -EE_API bool operator ==(const cIpAddress& left, const cIpAddress& right); +EE_API bool operator ==(const IpAddress& left, const IpAddress& right); /** @brief Overload of != operator to compare two IP addresses ** @param left Left operand (a IP address) ** @param right Right operand (a IP address) ** @return True if both addresses are different */ -EE_API bool operator !=(const cIpAddress& left, const cIpAddress& right); +EE_API bool operator !=(const IpAddress& left, const IpAddress& right); /** @brief Overload of < operator to compare two IP addresses ** @param left Left operand (a IP address) ** @param right Right operand (a IP address) ** @return True if @a left is lesser than @a right */ -EE_API bool operator <(const cIpAddress& left, const cIpAddress& right); +EE_API bool operator <(const IpAddress& left, const IpAddress& right); /** @brief Overload of > operator to compare two IP addresses ** @param left Left operand (a IP address) ** @param right Right operand (a IP address) ** @return True if @a left is greater than @a right */ -EE_API bool operator >(const cIpAddress& left, const cIpAddress& right); +EE_API bool operator >(const IpAddress& left, const IpAddress& right); /** @brief Overload of <= operator to compare two IP addresses ** @param left Left operand (a IP address) ** @param right Right operand (a IP address) ** @return True if @a left is lesser or equal than @a right */ -EE_API bool operator <=(const cIpAddress& left, const cIpAddress& right); +EE_API bool operator <=(const IpAddress& left, const IpAddress& right); /** @brief Overload of >= operator to compare two IP addresses ** @param left Left operand (a IP address) ** @param right Right operand (a IP address) ** @return True if @a left is greater or equal than @a right */ -EE_API bool operator >=(const cIpAddress& left, const cIpAddress& right); +EE_API bool operator >=(const IpAddress& left, const IpAddress& right); /** @brief Overload of >> operator to extract an IP address from an input stream ** @param stream Input stream ** @param address IP address to extract ** @return Reference to the input stream */ -EE_API std::istream& operator >>(std::istream& stream, cIpAddress& address); +EE_API std::istream& operator >>(std::istream& stream, IpAddress& address); /** @brief Overload of << operator to print an IP address to an output stream ** @param stream Output stream ** @param address IP address to print ** @return Reference to the output stream */ -EE_API std::ostream& operator <<(std::ostream& stream, const cIpAddress& address); +EE_API std::ostream& operator <<(std::ostream& stream, const IpAddress& address); }} #endif // EE_NETWORKCIPADDRESS_HPP /** -@class cIpAddress +@class IpAddress @ingroup Network -cIpAddress is a utility class for manipulating network +IpAddress is a utility class for manipulating network addresses. It provides a set a implicit constructors and conversion functions to easily build or transform an IP address from/to various representations. Usage example: @code -cIpAddress a0; // an invalid address -cIpAddress a1 = cIpAddress::None; // an invalid address (same as a0) -cIpAddress a2("127.0.0.1"); // the local host address -cIpAddress a3 = cIpAddress::Broadcast; // the broadcast address -cIpAddress a4(192, 168, 1, 56); // a local address -cIpAddress a5("my_computer"); // a local address created from a network name -cIpAddress a6("89.54.1.169"); // a distant address -cIpAddress a7("www.google.com"); // a distant address created from a network name -cIpAddress a8 = cIpAddress::GetLocalAddress(); // my address on the local network -cIpAddress a9 = cIpAddress::GetPublicAddress(); // my address on the internet +IpAddress a0; // an invalid address +IpAddress a1 = IpAddress::None; // an invalid address (same as a0) +IpAddress a2("127.0.0.1"); // the local host address +IpAddress a3 = IpAddress::Broadcast; // the broadcast address +IpAddress a4(192, 168, 1, 56); // a local address +IpAddress a5("my_computer"); // a local address created from a network name +IpAddress a6("89.54.1.169"); // a distant address +IpAddress a7("www.google.com"); // a distant address created from a network name +IpAddress a8 = IpAddress::GetLocalAddress(); // my address on the local network +IpAddress a9 = IpAddress::GetPublicAddress(); // my address on the internet @endcode -Note that cIpAddress currently doesn't support IPv6 +Note that IpAddress currently doesn't support IPv6 nor other types of network addresses. */ diff --git a/include/eepp/network/cpacket.hpp b/include/eepp/network/packet.hpp similarity index 73% rename from include/eepp/network/cpacket.hpp rename to include/eepp/network/packet.hpp index 9a987bc7b..327fbf8b7 100644 --- a/include/eepp/network/cpacket.hpp +++ b/include/eepp/network/packet.hpp @@ -7,21 +7,21 @@ namespace EE { namespace Network { -class cTcpSocket; -class cUdpSocket; +class TcpSocket; +class UdpSocket; /** @brief Utility class to build blocks of data to transfer over the network */ -class EE_API cPacket { +class EE_API Packet { // A bool-like type that cannot be converted to integer or pointer types - typedef bool (cPacket::*BoolType)(std::size_t); + typedef bool (Packet::*BoolType)(std::size_t); public: /** @brief Default constructor ** Creates an empty packet. */ - cPacket(); + Packet(); /** @brief Virtual destructor */ - virtual ~cPacket(); + virtual ~Packet(); /** @brief Append data to the end of the packet ** @param data Pointer to the sequence of bytes to append @@ -56,7 +56,7 @@ class EE_API cPacket { ** left to be read, without actually reading it. ** @return True if all data was read, false otherwise ** @see operator bool */ - bool EndOfcPacket() const; + bool EndOfPacket() const; /** @brief Test the validity of the packet, for reading ** This operator allows to test the packet as a boolean @@ -88,47 +88,47 @@ class EE_API cPacket { /// ** @return True if last data extraction from packet was successful /// - ** @see EndOfcPacket */ + ** @see EndOfPacket */ operator BoolType() const; /** Overloads of operator >> to read data from the packet */ - cPacket& operator >>(bool& data); - cPacket& operator >>(Int8& data); - cPacket& operator >>(Uint8& data); - cPacket& operator >>(Int16& data); - cPacket& operator >>(Uint16& data); - cPacket& operator >>(Int32& data); - cPacket& operator >>(Uint32& data); - cPacket& operator >>(float& data); - cPacket& operator >>(double& data); - cPacket& operator >>(char* data); - cPacket& operator >>(std::string& data); + Packet& operator >>(bool& data); + Packet& operator >>(Int8& data); + Packet& operator >>(Uint8& data); + Packet& operator >>(Int16& data); + Packet& operator >>(Uint16& data); + Packet& operator >>(Int32& data); + Packet& operator >>(Uint32& data); + Packet& operator >>(float& data); + Packet& operator >>(double& data); + Packet& operator >>(char* data); + Packet& operator >>(std::string& data); #ifndef EE_NO_WIDECHAR - cPacket& operator >>(wchar_t* data); - cPacket& operator >>(std::wstring& data); + Packet& operator >>(wchar_t* data); + Packet& operator >>(std::wstring& data); #endif - cPacket& operator >>(String& data); + Packet& operator >>(String& data); /** Overloads of operator << to write data into the packet */ - cPacket& operator <<(bool data); - cPacket& operator <<(Int8 data); - cPacket& operator <<(Uint8 data); - cPacket& operator <<(Int16 data); - cPacket& operator <<(Uint16 data); - cPacket& operator <<(Int32 data); - cPacket& operator <<(Uint32 data); - cPacket& operator <<(float data); - cPacket& operator <<(double data); - cPacket& operator <<(const char* data); - cPacket& operator <<(const std::string& data); + Packet& operator <<(bool data); + Packet& operator <<(Int8 data); + Packet& operator <<(Uint8 data); + Packet& operator <<(Int16 data); + Packet& operator <<(Uint16 data); + Packet& operator <<(Int32 data); + Packet& operator <<(Uint32 data); + Packet& operator <<(float data); + Packet& operator <<(double data); + Packet& operator <<(const char* data); + Packet& operator <<(const std::string& data); #ifndef EE_NO_WIDECHAR - cPacket& operator <<(const wchar_t* data); - cPacket& operator <<(const std::wstring& data); + Packet& operator <<(const wchar_t* data); + Packet& operator <<(const std::wstring& data); #endif - cPacket& operator <<(const String& data); + Packet& operator <<(const String& data); protected: - friend class cTcpSocket; - friend class cUdpSocket; + friend class TcpSocket; + friend class UdpSocket; /** @brief Called before the packet is sent over the network ** This function can be defined by derived classes to @@ -157,8 +157,8 @@ protected: virtual void OnReceive(const void* data, std::size_t size); private: /** Disallow comparisons between packets */ - bool operator ==(const cPacket& right) const; - bool operator !=(const cPacket& right) const; + bool operator ==(const Packet& right) const; + bool operator !=(const Packet& right) const; /** @brief Check if the packet can extract a given number of bytes ** This function updates accordingly the state of the packet. @@ -177,19 +177,19 @@ private: #endif // EE_NETWORKCPACKET_HPP /** -@class cPacket +@class Packet @ingroup Network -cPackets provide a safe and easy way to serialize data, +Packets provide a safe and easy way to serialize data, in order to send it over the network using sockets -(cTcpSocket, cUdpSocket). +(TcpSocket, UdpSocket). -cPackets solve 2 fundamental problems that arise when +Packets solve 2 fundamental problems that arise when transfering data over the network: @li data is interpreted correctly according to the endianness @li the bounds of the packet are preserved (one send == one receive) -The cPacket class provides both input and output modes. +The Packet class provides both input and output modes. It is designed to follow the behaviour of standard C++ streams, using operators >> and << to extract and insert data. @@ -205,16 +205,16 @@ std::string s = "hello"; double d = 5.89; // Group the variables to send into a packet -cPacket packet; +Packet packet; packet << x << s << d; -// Send it over the network (socket is a valid cTcpSocket) +// Send it over the network (socket is a valid TcpSocket) socket.Send(packet); ----------------------------------------------------------------- // Receive the packet at the other end -cPacket packet; +Packet packet; socket.Receive(packet); // Extract the variables contained in the packet @@ -227,7 +227,7 @@ if (packet >> x >> s >> d) } @endcode -cPackets have built-in operator >> and << overloads for +Packets have built-in operator >> and << overloads for standard types: @li bool @li fixed-size integer types (Int8/16/32, Uint8/16/32) @@ -246,27 +246,27 @@ struct MyStruct std::string str; }; -cPacket& operator <<(cPacket& packet, const MyStruct& m) +Packet& operator <<(Packet& packet, const MyStruct& m) { return packet << m.number << m.integer << m.str; } -cPacket& operator >>(cPacket& packet, MyStruct& m) +Packet& operator >>(Packet& packet, MyStruct& m) { return packet >> m.number >> m.integer >> m.str; } @endcode -cPackets also provide an extra feature that allows to apply +Packets also provide an extra feature that allows to apply custom transformations to the data before it is sent, and after it is received. This is typically used to handle automatic compression or encryption of the data. -This is achieved by inheriting from cPacket, and overriding +This is achieved by inheriting from Packet, and overriding the OnSend and OnReceive functions. Here is an example: @code -class ZipcPacket : public cPacket +class ZipPacket : public Packet { virtual const void* OnSend(std::size_t& size) { @@ -286,10 +286,10 @@ class ZipcPacket : public cPacket }; // Use like regular packets: -ZipcPacket packet; +ZipPacket packet; packet << x << s << d; ... @endcode -@see cTcpSocket, cUdpSocket +@see TcpSocket, UdpSocket */ diff --git a/include/eepp/network/csocket.hpp b/include/eepp/network/socket.hpp similarity index 91% rename from include/eepp/network/csocket.hpp rename to include/eepp/network/socket.hpp index 1ddca6b2d..e869dcb77 100644 --- a/include/eepp/network/csocket.hpp +++ b/include/eepp/network/socket.hpp @@ -7,10 +7,10 @@ #include namespace EE { namespace Network { -class cSocketSelector; +class SocketSelector; /** @brief Base class for all the socket types */ -class EE_API cSocket : NonCopyable { +class EE_API Socket : NonCopyable { public: /** @brief Status codes that may be returned by socket functions */ enum Status { @@ -26,7 +26,7 @@ class EE_API cSocket : NonCopyable { }; /** @brief Destructor */ - virtual ~cSocket(); + virtual ~Socket(); /** @brief Set the blocking state of the socket ** In blocking mode, calls will not return until they have @@ -56,7 +56,7 @@ protected : /** @brief Default constructor ** This constructor can only be accessed by derived classes. ** @param type Type of the socket (TCP or UDP) */ - cSocket(Type type); + Socket(Type type); /** @brief Return the internal handle of the socket ** The returned handle may be invalid if the socket @@ -80,7 +80,7 @@ protected : ** This function can only be accessed by derived classes. */ void Close(); protected : - friend class cSocketSelector; + friend class SocketSelector; // Member data Type mType; ///< Type of the socket (TCP or UDP) SocketHandle mSocket; ///< Socket descriptor @@ -92,7 +92,7 @@ protected : #endif // EE_NETWORKCSOCKET_HPP /** -@class cSocket +@class Socket @ingroup Network This class mainly defines internal stuff to be used by derived classes. @@ -111,7 +111,7 @@ operation to complete. In non-blocking mode, all the socket functions will return immediately. If the socket is not ready to complete the requested operation, the function simply returns -the proper status code (cSocket::NotReady). +the proper status code (Socket::NotReady). The default mode, which is blocking, is the one that is generally used, in combination with threads or selectors. @@ -120,5 +120,5 @@ applications that run an endless loop that can poll the socket often enough, and cannot afford blocking this loop. -@see cTcpListener, cTcpSocket, cUdpSocket +@see TcpListener, TcpSocket, UdpSocket */ diff --git a/include/eepp/network/csocketselector.hpp b/include/eepp/network/socketselector.hpp similarity index 78% rename from include/eepp/network/csocketselector.hpp rename to include/eepp/network/socketselector.hpp index 25d7625c8..1cebe75ad 100644 --- a/include/eepp/network/csocketselector.hpp +++ b/include/eepp/network/socketselector.hpp @@ -7,21 +7,21 @@ using namespace EE::System; namespace EE { namespace Network { -class cSocket; +class Socket; /** @brief Multiplexer that allows to read from multiple sockets */ -class EE_API cSocketSelector +class EE_API SocketSelector { public : /** @brief Default constructor */ - cSocketSelector(); + SocketSelector(); /** @brief Copy constructor ** @param copy Instance to copy */ - cSocketSelector(const cSocketSelector& copy); + SocketSelector(const SocketSelector& copy); /** @brief Destructor */ - ~cSocketSelector(); + ~SocketSelector(); /** @brief Add a new socket to the selector ** This function keeps a weak reference to the socket, @@ -30,14 +30,14 @@ class EE_API cSocketSelector ** This function does nothing if the socket is not valid. ** @param socket Reference to the socket to add ** @see Remove, Clear */ - void Add(cSocket& socket); + void Add(Socket& socket); /** @brief Remove a socket from the selector ** This function doesn't destroy the socket, it simply ** removes the reference that the selector has to it. ** @param socket Reference to the socket to remove ** @see Add, Clear */ - void Remove(cSocket& socket); + void Remove(Socket& socket); /** @brief Remove all the sockets stored in the selector ** This function doesn't destroy any instance, it simply @@ -62,22 +62,22 @@ class EE_API cSocketSelector ** which sockets are ready to receive data. If a socket is ** ready, a call to receive will never block because we know ** that there is data available to read. - ** Note that if this function returns true for a cTcpListener, + ** Note that if this function returns true for a TcpListener, ** this means that it is ready to accept a new connection. - ** @param socket cSocket to test + ** @param socket Socket to test ** @return True if the socket is ready to read, false otherwise ** @see IsReady */ - bool IsReady(cSocket& socket) const; + bool IsReady(Socket& socket) const; /** @brief Overload of assignment operator ** @param right Instance to assign ** @return Reference to self */ - cSocketSelector& operator =(const cSocketSelector& right); + SocketSelector& operator =(const SocketSelector& right); private : - struct cSocketSelectorImpl; + struct SocketSelectorImpl; // Member data - cSocketSelectorImpl* mImpl; ///< Opaque pointer to the implementation (which requires OS-specific types) + SocketSelectorImpl* mImpl; ///< Opaque pointer to the implementation (which requires OS-specific types) }; }} @@ -85,10 +85,10 @@ class EE_API cSocketSelector #endif // EE_NETWORKCSOCKETSELECTOR_HPP /** -@class cSocketSelector +@class SocketSelector @ingroup Network -cSocket selectors provide a way to wait until some data is +Socket selectors provide a way to wait until some data is available on a set of sockets, instead of just one. This is convenient when you have multiple sockets that may possibly receive data, but you don't know which one will @@ -97,9 +97,9 @@ for each socket; with selectors, a single thread can handle all the sockets. All types of sockets can be used in a selector: -@li cTcpListener -@li cTcpSocket -@li cUdpSocket +@li TcpListener +@li TcpSocket +@li UdpSocket A selector doesn't store its own copies of the sockets (socket classes are not copyable anyway), it simply keeps @@ -116,14 +116,14 @@ Using a selector is simple: Usage example: @code // Create a socket to listen to new connections -cTcpListener listener; +TcpListener listener; listener.Listen(55001); // Create a list to store the future clients -std::list clients; +std::list clients; // Create a selector -cSocketSelector selector; +SocketSelector selector; // Add the listener to the selector selector.Add(listener); @@ -138,8 +138,8 @@ while (running) if (selector.IsReady(listener)) { // The listener is ready: there is a pending connection - cTcpSocket* client = new cTcpSocket; - if (listener.Accept(*client) == cSocket::Done) + TcpSocket* client = new TcpSocket; + if (listener.Accept(*client) == Socket::Done) { // Add the new client to the clients list clients.push_back(client); @@ -157,14 +157,14 @@ while (running) else { // The listener socket is not ready, test all other sockets (the clients) - for (std::list::iterator it = clients.begin(); it != clients.end(); ++it) + for (std::list::iterator it = clients.begin(); it != clients.end(); ++it) { - cTcpSocket& client = **it; + TcpSocket& client = **it; if (selector.IsReady(client)) { // The client has sent some data, we can receive it - cPacket packet; - if (client.Receive(packet) == cSocket::Done) + Packet packet; + if (client.Receive(packet) == Socket::Done) { ... } @@ -175,5 +175,5 @@ while (running) } @endcode -@see cSocket +@see Socket */ diff --git a/include/eepp/network/ssl/csslsocket.hpp b/include/eepp/network/ssl/sslsocket.hpp similarity index 59% rename from include/eepp/network/ssl/csslsocket.hpp rename to include/eepp/network/ssl/sslsocket.hpp index ec0f23d65..a2d3d2eb9 100644 --- a/include/eepp/network/ssl/csslsocket.hpp +++ b/include/eepp/network/ssl/sslsocket.hpp @@ -1,13 +1,13 @@ #ifndef EE_NETWORKCSSLSOCKET_HPP #define EE_NETWORKCSSLSOCKET_HPP -#include +#include namespace EE { namespace Network { namespace SSL { -class cSSLSocketImpl; +class SSLSocketImpl; -class EE_API cSSLSocket : public cTcpSocket { +class EE_API SSLSocket : public TcpSocket { public: static std::string CertificatesPath; @@ -18,11 +18,11 @@ class EE_API cSSLSocket : public cTcpSocket { /** @return True when the library was compiled with SSL support. */ static bool IsSupported(); - cSSLSocket( std::string hostname, bool validateCertificate, bool validateHostname ); + SSLSocket( std::string hostname, bool validateCertificate, bool validateHostname ); - virtual ~cSSLSocket(); + virtual ~SSLSocket(); - Status Connect(const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero); + Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero); void Disconnect(); @@ -30,14 +30,14 @@ class EE_API cSSLSocket : public cTcpSocket { Status Receive(void* data, std::size_t size, std::size_t& received); - Status Send(cPacket& packet); + Status Send(Packet& packet); - Status Receive(cPacket& packet); + Status Receive(Packet& packet); protected: - friend class cSSLSocketImpl; - friend class cOpenSSLSocket; + friend class SSLSocketImpl; + friend class OpenSSLSocket; - cSSLSocketImpl * mImpl; + SSLSocketImpl * mImpl; std::string mHostName; bool mValidateCertificate; bool mValidateHostname; diff --git a/include/eepp/network/ctcplistener.hpp b/include/eepp/network/tcplistener.hpp similarity index 82% rename from include/eepp/network/ctcplistener.hpp rename to include/eepp/network/tcplistener.hpp index 3e63ea34c..e9f13050e 100644 --- a/include/eepp/network/ctcplistener.hpp +++ b/include/eepp/network/tcplistener.hpp @@ -1,19 +1,19 @@ #ifndef EE_NETWORKCTCPLISTENER_HPP #define EE_NETWORKCTCPLISTENER_HPP -#include +#include namespace EE { namespace Network { -class cTcpSocket; +class TcpSocket; /** @brief Socket that listens to new TCP connections */ -class EE_API cTcpListener : public cSocket +class EE_API TcpListener : public Socket { public : /** @brief Default constructor */ - cTcpListener(); + TcpListener(); /** @brief Get the port to which the socket is bound locally ** If the socket is not listening to a port, this function @@ -44,7 +44,7 @@ public : ** @param socket Socket that will hold the new connection ** @return Status code ** @see Listen */ - Status Accept(cTcpSocket& socket); + Status Accept(TcpSocket& socket); }; }} @@ -52,7 +52,7 @@ public : #endif // EE_NETWORKCTCPLISTENER_HPP /** -@class cTcpListener +@class TcpListener @ingroup Network A listener socket is a special type of socket that listens to @@ -60,14 +60,14 @@ a given port and waits for connections on that port. This is all it can do. When a new connection is received, you must call accept and -the listener returns a new instance of cTcpSocket that +the listener returns a new instance of TcpSocket that is properly initialized and can be used to communicate with the new client. Listener sockets are specific to the TCP protocol, UDP sockets are connectionless and can therefore communicate directly. As a consequence, a listener socket will always -return the new connections as cTcpSocket instances. +return the new connections as TcpSocket instances. A listener is automatically closed on destruction, like all other types of socket. However if you want to stop listening @@ -78,14 +78,14 @@ Usage example: @code // Create a listener socket and make it wait for new // connections on port 55001 -cTcpListener listener; +TcpListener listener; listener.Listen(55001); // Endless loop that waits for new connections while (running) { - cTcpSocket client; - if (listener.Accept(client) == cSocket::Done) + TcpSocket client; + if (listener.Accept(client) == Socket::Done) { // A new client just connected! std::cout << "New connection received from " << client.GetRemoteAddress() << std::endl; @@ -94,5 +94,5 @@ while (running) } @endcode -@see cTcpSocket, cSocket +@see TcpSocket, Socket */ diff --git a/include/eepp/network/ctcpsocket.hpp b/include/eepp/network/tcpsocket.hpp similarity index 85% rename from include/eepp/network/ctcpsocket.hpp rename to include/eepp/network/tcpsocket.hpp index a702ff251..af52ca7dd 100644 --- a/include/eepp/network/ctcpsocket.hpp +++ b/include/eepp/network/tcpsocket.hpp @@ -1,22 +1,22 @@ #ifndef EE_NETWORKCTCPSOCKET_HPP #define EE_NETWORKCTCPSOCKET_HPP -#include +#include #include using namespace EE::System; namespace EE { namespace Network { -class cTcpListener; -class cIpAddress; -class cPacket; +class TcpListener; +class IpAddress; +class Packet; /** @brief Specialized socket using the TCP protocol */ -class EE_API cTcpSocket : public cSocket { +class EE_API TcpSocket : public Socket { public: /** @brief Default constructor */ - cTcpSocket(); + TcpSocket(); /** @brief Get the port to which the socket is bound locally ** If the socket is not connected, this function returns 0. @@ -26,10 +26,10 @@ class EE_API cTcpSocket : public cSocket { /** @brief Get the address of the connected peer ** It the socket is not connected, this function returns - ** cIpAddress::None. + ** IpAddress::None. ** @return Address of the remote peer ** @see GetRemotePort */ - cIpAddress GetRemoteAddress() const; + IpAddress GetRemoteAddress() const; /** @brief Get the port of the connected peer to which the socket is connected @@ -48,7 +48,7 @@ class EE_API cTcpSocket : public cSocket { ** @param timeout Optional maximum time to wait ** @return Status code ** @see Disconnect */ - virtual Status Connect(const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero); + virtual Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero); /** @brief Disconnect the socket from its remote peer ** This function gracefully closes the connection. If the @@ -77,23 +77,23 @@ class EE_API cTcpSocket : public cSocket { /** @brief Send a formatted packet of data to the remote peer ** This function will fail if the socket is not connected. - ** @param packet cPacket to send + ** @param packet Packet to send ** @return Status code ** @see Receive */ - virtual Status Send(cPacket& packet); + virtual Status Send(Packet& packet); /** @brief Receive a formatted packet of data from the remote peer ** In blocking mode, this function will wait until the whole packet ** has been received. ** This function will fail if the socket is not connected. - ** @param packet cPacket to fill with the received data + ** @param packet Packet to fill with the received data ** @return Status code ** @see Send */ - virtual Status Receive(cPacket& packet); + virtual Status Receive(Packet& packet); private: - friend class cTcpListener; + friend class TcpListener; /** @brief Structure holding the data of a pending packet */ struct PendingPacket { @@ -113,7 +113,7 @@ class EE_API cTcpSocket : public cSocket { #endif // EE_NETWORKCTCPSOCKET_HPP /** -@class cTcpSocket +@class TcpSocket @ingroup Network TCP is a connected protocol, which means that a TCP @@ -137,9 +137,9 @@ process a raw sequence of bytes, and cannot ensure that one call to Send will exactly match one call to Receive at the other end of the socket. -The high-level interface uses packets (see cPacket), +The high-level interface uses packets (see Packet), which are easier to use and provide more safety regarding -the data that is exchanged. You can look at the cPacket +the data that is exchanged. You can look at the Packet class to get more details about how they work. The socket is automatically disconnected when it is destroyed, @@ -151,7 +151,7 @@ Usage example: // ----- The client ----- // Create a socket and connect it to 192.168.1.50 on port 55001 -cTcpSocket socket; +TcpSocket socket; socket.Connect("192.168.1.50", 55001); // Send a message to the connected host @@ -167,11 +167,11 @@ std::cout << "The server said: " << buffer << std::endl; // ----- The server ----- // Create a listener to wait for incoming connections on port 55001 -cTcpListener listener; +TcpListener listener; listener.Listen(55001); // Wait for a connection -cTcpSocket socket; +TcpSocket socket; listener.Accept(socket); std::cout << "New client connected: " << socket.GetRemoteAddress() << std::endl; @@ -186,5 +186,5 @@ std::string message = "Welcome, client"; socket.Send(message.c_str(), message.size() + 1); @endcode -@see cSocket, cUdpSocket, cPacket +@see Socket, UdpSocket, Packet */ diff --git a/include/eepp/network/cudpsocket.hpp b/include/eepp/network/udpsocket.hpp similarity index 81% rename from include/eepp/network/cudpsocket.hpp rename to include/eepp/network/udpsocket.hpp index 93dc929ee..ac3c2a85d 100644 --- a/include/eepp/network/cudpsocket.hpp +++ b/include/eepp/network/udpsocket.hpp @@ -1,16 +1,16 @@ #ifndef EE_NETWORKCUDPSOCKET_HPP #define EE_NETWORKCUDPSOCKET_HPP -#include +#include #include namespace EE { namespace Network { -class cIpAddress; -class cPacket; +class IpAddress; +class Packet; /** @brief Specialized socket using the UDP protocol */ -class EE_API cUdpSocket : public cSocket { +class EE_API UdpSocket : public Socket { public: // Constants @@ -19,7 +19,7 @@ class EE_API cUdpSocket : public cSocket { }; /** @brief Default constructor */ - cUdpSocket(); + UdpSocket(); /** @brief Get the port to which the socket is bound locally ** If the socket is not bound to a port, this function @@ -31,7 +31,7 @@ class EE_API cUdpSocket : public cSocket { /** @brief Bind the socket to a specific port ** Binding the socket to a port is necessary for being ** able to receive data on that port. - ** You can use the special value cSocket::AnyPort to tell the + ** You can use the special value Socket::AnyPort to tell the ** system to automatically pick an available port, and then ** call GetLocalPort to retrieve the chosen port. ** @param port Port to Bind the socket to @@ -48,7 +48,7 @@ class EE_API cUdpSocket : public cSocket { /** @brief Send raw data to a remote peer ** Make sure that @a size is not greater than - ** cUdpSocket::MaxDatagramSize, otherwise this function will + ** UdpSocket::MaxDatagramSize, otherwise this function will ** fail and no data will be sent. ** @param data Pointer to the sequence of bytes to send ** @param size Number of bytes to send @@ -56,7 +56,7 @@ class EE_API cUdpSocket : public cSocket { ** @param remotePort Port of the receiver to send the data to ** @return Status code ** @see Receive */ - Status Send(const void* data, std::size_t size, const cIpAddress& remoteAddress, unsigned short remotePort); + Status Send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort); /** @brief Receive raw data from a remote peer ** In blocking mode, this function will wait until some @@ -72,31 +72,31 @@ class EE_API cUdpSocket : public cSocket { ** @param remotePort Port of the peer that sent the data ** @return Status code ** @see Send */ - Status Receive(void* data, std::size_t size, std::size_t& received, cIpAddress& remoteAddress, unsigned short& remotePort); + Status Receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort); /** @brief Send a formatted packet of data to a remote peer ** Make sure that the packet size is not greater than - ** cUdpSocket::MaxDatagramSize, otherwise this function will + ** UdpSocket::MaxDatagramSize, otherwise this function will ** fail and no data will be sent. - ** @param packet cPacket to send + ** @param packet Packet to send ** @param remoteAddress Address of the receiver ** @param remotePort Port of the receiver to send the data to ** @return Status code ** @see Receive */ - Status Send(cPacket& packet, const cIpAddress& remoteAddress, unsigned short remotePort); + Status Send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort); /** @brief Receive a formatted packet of data from a remote peer ** In blocking mode, this function will wait until the whole packet ** has been received. - ** @param packet cPacket to fill with the received data + ** @param packet Packet to fill with the received data ** @param remoteAddress Address of the peer that sent the data ** @param remotePort Port of the peer that sent the data ** @return Status code ** @see Send */ - Status Receive(cPacket& packet, cIpAddress& remoteAddress, unsigned short& remotePort); + Status Receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort); private: // Member data - std::vector mBuffer; ///< Temporary buffer holding the received data in Receive(cPacket) + std::vector mBuffer; ///< Temporary buffer holding the received data in Receive(Packet) }; }} @@ -104,7 +104,7 @@ private: #endif // EE_NETWORKCUDPSOCKET_HPP /** -@class cUdpSocket +@class UdpSocket @ingroup Network A UDP socket is a connectionless socket. Instead of @@ -129,12 +129,12 @@ speed is crucial and lost data doesn't matter much. Sending and receiving data can use either the low-level or the high-level functions. The low-level functions process a raw sequence of bytes, whereas the high-level -interface uses packets (see cPacket), which are easier +interface uses packets (see Packet), which are easier to use and provide more safety regarding the data that is -exchanged. You can look at the cPacket class to get +exchanged. You can look at the Packet class to get more details about how they work. -It is important to note that cUdpSocket is unable to send +It is important to note that UdpSocket is unable to send datagrams bigger than MaxDatagramSize. In this case, it returns an error and doesn't send anything. This applies to both raw data and packets. Indeed, even packets are @@ -153,17 +153,17 @@ Usage example: // ----- The client ----- // Create a socket and bind it to the port 55001 -cUdpSocket socket; +UdpSocket socket; socket.Bind(55001); // Send a message to 192.168.1.50 on port 55002 -std::string message = "Hi, I am " + cIpAddress::GetLocalAddress().ToString(); +std::string message = "Hi, I am " + IpAddress::GetLocalAddress().ToString(); socket.Send(message.c_str(), message.size() + 1, "192.168.1.50", 55002); // Receive an answer (most likely from 192.168.1.50, but could be anyone else) char buffer[1024]; std::size_t received = 0; -cIpAddress sender; +IpAddress sender; unsigned short port; socket.Receive(buffer, sizeof(buffer), received, sender, port); std::cout << sender.ToString() << " said: " << buffer << std::endl; @@ -171,13 +171,13 @@ std::cout << sender.ToString() << " said: " << buffer << std::endl; // ----- The server ----- // Create a socket and bind it to the port 55002 -cUdpSocket socket; +UdpSocket socket; socket.Bind(55002); // Receive a message from anyone char buffer[1024]; std::size_t received = 0; -cIpAddress sender; +IpAddress sender; unsigned short port; socket.Receive(buffer, sizeof(buffer), received, sender, port); std::cout << sender.ToString() << " said: " << buffer << std::endl; @@ -187,5 +187,5 @@ std::string message = "Welcome " + sender.ToString(); socket.Send(message.c_str(), message.size() + 1, sender, port); @endcode -@see cSocket, cTcpSocket, cPacket +@see Socket, TcpSocket, Packet */ diff --git a/projects/linux/ee.files b/projects/linux/ee.files index 291adf775..69c55e111 100644 --- a/projects/linux/ee.files +++ b/projects/linux/ee.files @@ -620,27 +620,27 @@ ../../include/eepp/system/ctime.hpp ../../src/eepp/graphics/ctexturesaver.hpp ../../src/eepp/graphics/ctexturesaver.cpp -../../include/eepp/network/cudpsocket.hpp -../../include/eepp/network/ctcpsocket.hpp -../../include/eepp/network/ctcplistener.hpp +../../include/eepp/network/udpsocket.hpp +../../include/eepp/network/tcpsocket.hpp +../../include/eepp/network/tcplistener.hpp ../../include/eepp/network/base.hpp -../../include/eepp/network/csocketselector.hpp +../../include/eepp/network/socketselector.hpp ../../include/eepp/network/sockethandle.hpp -../../include/eepp/network/csocket.hpp -../../include/eepp/network/cpacket.hpp -../../include/eepp/network/cipaddress.hpp -../../include/eepp/network/chttp.hpp -../../include/eepp/network/cftp.hpp +../../include/eepp/network/socket.hpp +../../include/eepp/network/packet.hpp +../../include/eepp/network/ipaddress.hpp +../../include/eepp/network/http.hpp +../../include/eepp/network/ftp.hpp ../../include/eepp/network.hpp -../../src/eepp/network/cudpsocket.cpp -../../src/eepp/network/ctcpsocket.cpp -../../src/eepp/network/ctcplistener.cpp -../../src/eepp/network/csocketselector.cpp -../../src/eepp/network/csocket.cpp -../../src/eepp/network/cpacket.cpp -../../src/eepp/network/cipaddress.cpp -../../src/eepp/network/chttp.cpp -../../src/eepp/network/cftp.cpp +../../src/eepp/network/udpsocket.cpp +../../src/eepp/network/tcpsocket.cpp +../../src/eepp/network/tcplistener.cpp +../../src/eepp/network/socketselector.cpp +../../src/eepp/network/socket.cpp +../../src/eepp/network/packet.cpp +../../src/eepp/network/ipaddress.cpp +../../src/eepp/network/http.cpp +../../src/eepp/network/ftp.cpp ../../src/eepp/network/platform/unix/csocketimpl.hpp ../../src/eepp/network/platform/unix/csocketimpl.cpp ../../src/eepp/network/platform/win/csocketimpl.hpp @@ -665,11 +665,11 @@ ../../src/eepp/graphics/renderer/shaders/basegl3cp.frag ../../src/eepp/window/backend/SDL/cbackendsdl.cpp ../../bin/assets/ee.ini -../../src/eepp/network/ssl/csslsocket.cpp -../../src/eepp/network/ssl/csslsocketimpl.hpp -../../src/eepp/network/ssl/backend/openssl/copensslsocket.hpp -../../src/eepp/network/ssl/backend/openssl/copensslsocket.cpp -../../include/eepp/network/ssl/csslsocket.hpp +../../src/eepp/network/ssl/sslsocket.cpp +../../src/eepp/network/ssl/sslsocketimpl.hpp +../../src/eepp/network/ssl/backend/openssl/opensslsocket.hpp +../../src/eepp/network/ssl/backend/openssl/opensslsocket.cpp +../../include/eepp/network/ssl/sslsocket.hpp ../../src/eepp/network/ssl/backend/openssl/curl_hostcheck.cpp ../../src/eepp/network/ssl/backend/openssl/curl_hostcheck.h ../../src/eepp/core/debug.cpp diff --git a/src/eepp/network/cftp.cpp b/src/eepp/network/ftp.cpp similarity index 75% rename from src/eepp/network/cftp.cpp rename to src/eepp/network/ftp.cpp index 063cfea6f..322fe40ba 100644 --- a/src/eepp/network/cftp.cpp +++ b/src/eepp/network/ftp.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include @@ -7,42 +7,42 @@ namespace EE { namespace Network { -class cFtp::DataChannel : NonCopyable { +class Ftp::DataChannel : NonCopyable { public : - DataChannel(cFtp& owner); + DataChannel(Ftp& owner); - cFtp::Response Open(cFtp::TransferMode mode); + Ftp::Response Open(Ftp::TransferMode mode); void Send(const std::vector& data); void Receive(std::vector& data); private: // Member data - cFtp& mFtp; ///< Reference to the owner cFtp instance - cTcpSocket mDataSocket; ///< Socket used for data transfers + Ftp& mFtp; ///< Reference to the owner Ftp instance + TcpSocket mDataSocket; ///< Socket used for data transfers }; -cFtp::Response::Response(Status code, const std::string& message) : +Ftp::Response::Response(Status code, const std::string& message) : mStatus (code), mMessage(message) { } -bool cFtp::Response::IsOk() const { +bool Ftp::Response::IsOk() const { return mStatus < 400; } -cFtp::Response::Status cFtp::Response::GetStatus() const { +Ftp::Response::Status Ftp::Response::GetStatus() const { return mStatus; } -const std::string& cFtp::Response::GetMessage() const { +const std::string& Ftp::Response::GetMessage() const { return mMessage; } -cFtp::DirectoryResponse::DirectoryResponse(const cFtp::Response& response) : - cFtp::Response(response) +Ftp::DirectoryResponse::DirectoryResponse(const Ftp::Response& response) : + Ftp::Response(response) { if ( IsOk() ) { // Extract the directory from the server response @@ -52,12 +52,12 @@ cFtp::DirectoryResponse::DirectoryResponse(const cFtp::Response& response) : } } -const std::string& cFtp::DirectoryResponse::GetDirectory() const { +const std::string& Ftp::DirectoryResponse::GetDirectory() const { return mDirectory; } -cFtp::ListingResponse::ListingResponse(const cFtp::Response& response, const std::vector& data) : - cFtp::Response(response) +Ftp::ListingResponse::ListingResponse(const Ftp::Response& response, const std::vector& data) : + Ftp::Response(response) { if ( IsOk() ) { // Fill the array of strings @@ -71,28 +71,28 @@ cFtp::ListingResponse::ListingResponse(const cFtp::Response& response, const std } } -const std::vector& cFtp::ListingResponse::getListing() const { +const std::vector& Ftp::ListingResponse::getListing() const { return mListing; } -cFtp::~cFtp() { +Ftp::~Ftp() { Disconnect(); } -cFtp::Response cFtp::Connect(const cIpAddress& server, unsigned short port, cTime timeout) { +Ftp::Response Ftp::Connect(const IpAddress& server, unsigned short port, cTime timeout) { // Connect to the server - if (mCommandSocket.Connect(server, port, timeout) != cSocket::Done) + if (mCommandSocket.Connect(server, port, timeout) != Socket::Done) return Response(Response::ConnectionFailed); // Get the response to the connection return GetResponse(); } -cFtp::Response cFtp::Login() { +Ftp::Response Ftp::Login() { return Login("anonymous", "user@eepp.com.ar"); } -cFtp::Response cFtp::Login(const std::string& name, const std::string& password) { +Ftp::Response Ftp::Login(const std::string& name, const std::string& password) { Response response = SendCommand("USER", name); if (response.IsOk()) response = SendCommand("PASS", password); @@ -100,7 +100,7 @@ cFtp::Response cFtp::Login(const std::string& name, const std::string& password) return response; } -cFtp::Response cFtp::Disconnect() { +Ftp::Response Ftp::Disconnect() { // Send the exit command Response response = SendCommand("QUIT"); if (response.IsOk()) @@ -109,15 +109,15 @@ cFtp::Response cFtp::Disconnect() { return response; } -cFtp::Response cFtp::KeepAlive() { +Ftp::Response Ftp::KeepAlive() { return SendCommand("NOOP"); } -cFtp::DirectoryResponse cFtp::GetWorkingDirectory() { +Ftp::DirectoryResponse Ftp::GetWorkingDirectory() { return DirectoryResponse(SendCommand("PWD")); } -cFtp::ListingResponse cFtp::GetDirectoryListing(const std::string& directory) { +Ftp::ListingResponse Ftp::GetDirectoryListing(const std::string& directory) { // Open a data channel on default port (20) using ASCII transfer mode std::vector directoryData; DataChannel data(*this); @@ -138,23 +138,23 @@ cFtp::ListingResponse cFtp::GetDirectoryListing(const std::string& directory) { return ListingResponse(response, directoryData); } -cFtp::Response cFtp::ChangeDirectory(const std::string& directory) { +Ftp::Response Ftp::ChangeDirectory(const std::string& directory) { return SendCommand("CWD", directory); } -cFtp::Response cFtp::ParentDirectory() { +Ftp::Response Ftp::ParentDirectory() { return SendCommand("CDUP"); } -cFtp::Response cFtp::CreateDirectory(const std::string& name) { +Ftp::Response Ftp::CreateDirectory(const std::string& name) { return SendCommand("MKD", name); } -cFtp::Response cFtp::DeleteDirectory(const std::string& name) { +Ftp::Response Ftp::DeleteDirectory(const std::string& name) { return SendCommand("RMD", name); } -cFtp::Response cFtp::RenameFile(const std::string& file, const std::string& newName) { +Ftp::Response Ftp::RenameFile(const std::string& file, const std::string& newName) { Response response = SendCommand("RNFR", file); if (response.IsOk()) response = SendCommand("RNTO", newName); @@ -162,11 +162,11 @@ cFtp::Response cFtp::RenameFile(const std::string& file, const std::string& newN return response; } -cFtp::Response cFtp::DeleteFile(const std::string& name) { +Ftp::Response Ftp::DeleteFile(const std::string& name) { return SendCommand("DELE", name); } -cFtp::Response cFtp::Download(const std::string& remoteFile, const std::string& localPath, TransferMode mode) { +Ftp::Response Ftp::Download(const std::string& remoteFile, const std::string& localPath, TransferMode mode) { // Open a data channel using the given transfer mode DataChannel data(*this); Response response = data.Open(mode); @@ -208,7 +208,7 @@ cFtp::Response cFtp::Download(const std::string& remoteFile, const std::string& return response; } -cFtp::Response cFtp::Upload(const std::string& localFile, const std::string& remotePath, TransferMode mode) { +Ftp::Response Ftp::Upload(const std::string& localFile, const std::string& remotePath, TransferMode mode) { // Get the contents of the file to send std::ifstream file(localFile.c_str(), std::ios_base::binary); if (!file) @@ -250,7 +250,7 @@ cFtp::Response cFtp::Upload(const std::string& localFile, const std::string& rem return response; } -cFtp::Response cFtp::SendCommand(const std::string& command, const std::string& parameter) { +Ftp::Response Ftp::SendCommand(const std::string& command, const std::string& parameter) { // Build the command string std::string commandStr; if (parameter != "") @@ -259,14 +259,14 @@ cFtp::Response cFtp::SendCommand(const std::string& command, const std::string& commandStr = command + "\r\n"; // Send it to the server - if (mCommandSocket.Send(commandStr.c_str(), commandStr.length()) != cSocket::Done) + if (mCommandSocket.Send(commandStr.c_str(), commandStr.length()) != Socket::Done) return Response(Response::ConnectionClosed); // Get the response return GetResponse(); } -cFtp::Response cFtp::GetResponse() { +Ftp::Response Ftp::GetResponse() { // We'll use a variable to keep track of the last valid code. // It is useful in case of multi-lines responses, because the end of such a response // will start by the same code @@ -278,7 +278,7 @@ cFtp::Response cFtp::GetResponse() { // Receive the response from the server char buffer[1024]; std::size_t length; - if (mCommandSocket.Receive(buffer, sizeof(buffer), length) != cSocket::Done) + if (mCommandSocket.Receive(buffer, sizeof(buffer), length) != Socket::Done) return Response(Response::ConnectionClosed); // There can be several lines inside the received buffer, extract them all @@ -375,14 +375,14 @@ cFtp::Response cFtp::GetResponse() { // We never reach there } -cFtp::DataChannel::DataChannel(cFtp& owner) : +Ftp::DataChannel::DataChannel(Ftp& owner) : mFtp(owner) { } -cFtp::Response cFtp::DataChannel::Open(cFtp::TransferMode mode) { +Ftp::Response Ftp::DataChannel::Open(Ftp::TransferMode mode) { // Open a data connection in active mode (we connect to the server) - cFtp::Response response = mFtp.SendCommand("PASV"); + Ftp::Response response = mFtp.SendCommand("PASV"); if (response.IsOk()) { // Extract the connection address and port from the response @@ -407,26 +407,26 @@ cFtp::Response cFtp::DataChannel::Open(cFtp::TransferMode mode) { // Reconstruct connection port and address unsigned short port = data[4] * 256 + data[5]; - cIpAddress address(static_cast(data[0]), + IpAddress address(static_cast(data[0]), static_cast(data[1]), static_cast(data[2]), static_cast(data[3])); // Connect the data channel to the server - if (mDataSocket.Connect(address, port) == cSocket::Done) { + if (mDataSocket.Connect(address, port) == Socket::Done) { // Translate the transfer mode to the corresponding FTP parameter std::string modeStr; switch (mode) { - case cFtp::Binary : modeStr = "I"; break; - case cFtp::Ascii : modeStr = "A"; break; - case cFtp::Ebcdic : modeStr = "E"; break; + case Ftp::Binary : modeStr = "I"; break; + case Ftp::Ascii : modeStr = "A"; break; + case Ftp::Ebcdic : modeStr = "E"; break; } // Set the transfer mode response = mFtp.SendCommand("TYPE", modeStr); } else { // Failed to connect to the server - response = cFtp::Response(cFtp::Response::ConnectionFailed); + response = Ftp::Response(Ftp::Response::ConnectionFailed); } } } @@ -434,13 +434,13 @@ cFtp::Response cFtp::DataChannel::Open(cFtp::TransferMode mode) { return response; } -void cFtp::DataChannel::Receive(std::vector& data) { +void Ftp::DataChannel::Receive(std::vector& data) { // Receive data data.clear(); char buffer[1024]; std::size_t received; - while (mDataSocket.Receive(buffer, sizeof(buffer), received) == cSocket::Done) { + while (mDataSocket.Receive(buffer, sizeof(buffer), received) == Socket::Done) { std::copy(buffer, buffer + received, std::back_inserter(data)); } @@ -448,7 +448,7 @@ void cFtp::DataChannel::Receive(std::vector& data) { mDataSocket.Disconnect(); } -void cFtp::DataChannel::Send(const std::vector& data) { +void Ftp::DataChannel::Send(const std::vector& data) { // Send data if (!data.empty()) mDataSocket.Send(&data[0], data.size()); diff --git a/src/eepp/network/chttp.cpp b/src/eepp/network/http.cpp similarity index 73% rename from src/eepp/network/chttp.cpp rename to src/eepp/network/http.cpp index 0e670f3e6..2818ef9e4 100644 --- a/src/eepp/network/chttp.cpp +++ b/src/eepp/network/http.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include @@ -19,7 +19,7 @@ namespace { namespace EE { namespace Network { -cHttp::Request::Request(const std::string& uri, Method method, const std::string& body, bool validateCertificate, bool validateHostname ) : +Http::Request::Request(const std::string& uri, Method method, const std::string& body, bool validateCertificate, bool validateHostname ) : mValidateCertificate( validateCertificate ), mValidateHostname( validateHostname ) { @@ -29,15 +29,15 @@ cHttp::Request::Request(const std::string& uri, Method method, const std::string SetBody(body); } -void cHttp::Request::SetField(const std::string& field, const std::string& value) { +void Http::Request::SetField(const std::string& field, const std::string& value) { mFields[toLower(field)] = value; } -void cHttp::Request::SetMethod(cHttp::Request::Method method) { +void Http::Request::SetMethod(Http::Request::Method method) { mMethod = method; } -void cHttp::Request::SetUri(const std::string& uri) { +void Http::Request::SetUri(const std::string& uri) { mUri = uri; // Make sure it starts with a '/' @@ -45,36 +45,36 @@ void cHttp::Request::SetUri(const std::string& uri) { mUri.insert(0, "/"); } -void cHttp::Request::SetHttpVersion(unsigned int major, unsigned int minor) { +void Http::Request::SetHttpVersion(unsigned int major, unsigned int minor) { mMajorVersion = major; mMinorVersion = minor; } -void cHttp::Request::SetBody(const std::string& body) { +void Http::Request::SetBody(const std::string& body) { mBody = body; } -const std::string &cHttp::Request::GetUri() const { +const std::string &Http::Request::GetUri() const { return mUri; } -const bool& cHttp::Request::ValidateCertificate() const { +const bool& Http::Request::ValidateCertificate() const { return mValidateCertificate; } -void cHttp::Request::ValidateCertificate(bool enable) { +void Http::Request::ValidateCertificate(bool enable) { mValidateCertificate = enable; } -const bool &cHttp::Request::ValidateHostname() const { +const bool &Http::Request::ValidateHostname() const { return mValidateHostname; } -void cHttp::Request::ValidateHostname(bool enable) { +void Http::Request::ValidateHostname(bool enable) { mValidateHostname = enable; } -std::string cHttp::Request::Prepare() const { +std::string Http::Request::Prepare() const { std::ostringstream out; // Convert the method to its string representation @@ -106,18 +106,18 @@ std::string cHttp::Request::Prepare() const { return out.str(); } -bool cHttp::Request::HasField(const std::string& field) const { +bool Http::Request::HasField(const std::string& field) const { return mFields.find(toLower(field)) != mFields.end(); } -cHttp::Response::Response() : +Http::Response::Response() : mStatus (ConnectionFailed), mMajorVersion(0), mMinorVersion(0) { } -const std::string& cHttp::Response::GetField(const std::string& field) const { +const std::string& Http::Response::GetField(const std::string& field) const { FieldTable::const_iterator it = mFields.find(toLower(field)); if (it != mFields.end()) { return it->second; @@ -127,23 +127,23 @@ const std::string& cHttp::Response::GetField(const std::string& field) const { } } -cHttp::Response::Status cHttp::Response::GetStatus() const { +Http::Response::Status Http::Response::GetStatus() const { return mStatus; } -unsigned int cHttp::Response::GetMajorHttpVersion() const { +unsigned int Http::Response::GetMajorHttpVersion() const { return mMajorVersion; } -unsigned int cHttp::Response::GetMinorHttpVersion() const { +unsigned int Http::Response::GetMinorHttpVersion() const { return mMinorVersion; } -const std::string& cHttp::Response::GetBody() const { +const std::string& Http::Response::GetBody() const { return mBody; } -void cHttp::Response::Parse(const std::string& data) { +void Http::Response::Parse(const std::string& data) { std::istringstream in(data); // Extract the HTTP version from the first line @@ -210,7 +210,7 @@ void cHttp::Response::Parse(const std::string& data) { } } -void cHttp::Response::ParseFields(std::istream &in) { +void Http::Response::ParseFields(std::istream &in) { std::string line; while (std::getline(in, line) && (line.size() > 2)) { std::string::size_type pos = line.find(": "); @@ -230,7 +230,7 @@ void cHttp::Response::ParseFields(std::istream &in) { } } -cHttp::cHttp() : +Http::Http() : mConnection( NULL ), mHost(), mPort(0), @@ -238,14 +238,14 @@ cHttp::cHttp() : { } -cHttp::cHttp(const std::string& host, unsigned short port, bool useSSL) : +Http::Http(const std::string& host, unsigned short port, bool useSSL) : mConnection( NULL ), mIsSSL( false ) { SetHost(host, port, useSSL); } -cHttp::~cHttp() { +Http::~Http() { std::list::iterator itt; // First we wait to finish any request pending @@ -258,12 +258,12 @@ cHttp::~cHttp() { } // Then we destroy the last open connection - cTcpSocket * tcp = mConnection; + TcpSocket * tcp = mConnection; eeSAFE_DELETE( tcp ); } -void cHttp::SetHost(const std::string& host, unsigned short port, bool useSSL) { +void Http::SetHost(const std::string& host, unsigned short port, bool useSSL) { // Check the protocol if (toLower(host.substr(0, 7)) == "http://") { // HTTP protocol @@ -294,12 +294,12 @@ void cHttp::SetHost(const std::string& host, unsigned short port, bool useSSL) { if (!mHostName.empty() && (*mHostName.rbegin() == '/')) mHostName.erase(mHostName.size() - 1); - mHost = cIpAddress(mHostName); + mHost = IpAddress(mHostName); } -cHttp::Response cHttp::SendRequest(const cHttp::Request& request, cTime timeout) { +Http::Response Http::SendRequest(const Http::Request& request, cTime timeout) { if ( NULL == mConnection ) { - cTcpSocket * Conn = mIsSSL ? eeNew( cSSLSocket, ( mHostName, request.ValidateCertificate(), request.ValidateHostname() ) ) : eeNew( cTcpSocket, () ); + TcpSocket * Conn = mIsSSL ? eeNew( SSLSocket, ( mHostName, request.ValidateCertificate(), request.ValidateHostname() ) ) : eeNew( TcpSocket, () ); mConnection = Conn; } @@ -336,19 +336,19 @@ cHttp::Response cHttp::SendRequest(const cHttp::Request& request, cTime timeout) Response received; // Connect the socket to the host - if (mConnection->Connect(mHost, mPort, timeout) == cSocket::Done) { + if (mConnection->Connect(mHost, mPort, timeout) == Socket::Done) { // Convert the request to string and send it through the connected socket std::string requestStr = toSend.Prepare(); if (!requestStr.empty()) { // Send it through the socket - if (mConnection->Send(requestStr.c_str(), requestStr.size()) == cSocket::Done) { + if (mConnection->Send(requestStr.c_str(), requestStr.size()) == Socket::Done) { // Wait for the server's response std::string receivedStr; std::size_t size = 0; char buffer[1024]; - while (mConnection->Receive(buffer, sizeof(buffer), size) == cSocket::Done) { + while (mConnection->Receive(buffer, sizeof(buffer), size) == Socket::Done) { receivedStr.append(buffer, buffer + size); } @@ -364,7 +364,7 @@ cHttp::Response cHttp::SendRequest(const cHttp::Request& request, cTime timeout) return received; } -cHttp::cAsyncRequest::cAsyncRequest(cHttp *http, AsyncResponseCallback cb, cHttp::Request request, cTime timeout) : +Http::cAsyncRequest::cAsyncRequest(Http *http, AsyncResponseCallback cb, Http::Request request, cTime timeout) : mHttp( http ), mCb( cb ), mRequest( request ), @@ -373,20 +373,20 @@ cHttp::cAsyncRequest::cAsyncRequest(cHttp *http, AsyncResponseCallback cb, cHttp { } -void cHttp::cAsyncRequest::Run() { - cHttp::Response response = mHttp->SendRequest( mRequest, mTimeout ); +void Http::cAsyncRequest::Run() { + Http::Response response = mHttp->SendRequest( mRequest, mTimeout ); mCb( *mHttp, mRequest, response ); // The Async Request destroys the socket used to create the request - cTcpSocket * tcp = mHttp->mConnection; + TcpSocket * tcp = mHttp->mConnection; eeSAFE_DELETE( tcp ); mHttp->mConnection = NULL; mRunning = false; } -void cHttp::RemoveOldThreads() { +void Http::RemoveOldThreads() { std::list remove; std::list::iterator it = mThreads.begin(); @@ -409,7 +409,7 @@ void cHttp::RemoveOldThreads() { } } -void cHttp::SendAsyncRequest( AsyncResponseCallback cb, const cHttp::Request& request, cTime timeout ) { +void Http::SendAsyncRequest( AsyncResponseCallback cb, const Http::Request& request, cTime timeout ) { cAsyncRequest * thread = eeNew( cAsyncRequest, ( this, cb, request, timeout ) ); thread->Launch(); @@ -422,15 +422,15 @@ void cHttp::SendAsyncRequest( AsyncResponseCallback cb, const cHttp::Request& re mThreads.push_back( thread ); } -const cIpAddress &cHttp::GetHost() const { +const IpAddress &Http::GetHost() const { return mHost; } -const std::string &cHttp::GetHostName() const { +const std::string &Http::GetHostName() const { return mHostName; } -const unsigned short& cHttp::GetPort() const { +const unsigned short& Http::GetPort() const { return mPort; } diff --git a/src/eepp/network/cipaddress.cpp b/src/eepp/network/ipaddress.cpp similarity index 59% rename from src/eepp/network/cipaddress.cpp rename to src/eepp/network/ipaddress.cpp index b3acfb646..d92be13bb 100644 --- a/src/eepp/network/cipaddress.cpp +++ b/src/eepp/network/ipaddress.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include @@ -37,11 +37,11 @@ namespace { namespace EE { namespace Network { -const cIpAddress cIpAddress::None; -const cIpAddress cIpAddress::LocalHost(127, 0, 0, 1); -const cIpAddress cIpAddress::Broadcast(255, 255, 255, 255); +const IpAddress IpAddress::None; +const IpAddress IpAddress::LocalHost(127, 0, 0, 1); +const IpAddress IpAddress::Broadcast(255, 255, 255, 255); -cIpAddress::cIpAddress() : +IpAddress::IpAddress() : mAddress(0) { // We're using 0 (INADDR_ANY) instead of INADDR_NONE to represent the invalid address, @@ -49,27 +49,27 @@ cIpAddress::cIpAddress() : // eepp doesn't publicly use INADDR_ANY (it is always used implicitely) } -cIpAddress::cIpAddress(const std::string& address) : +IpAddress::IpAddress(const std::string& address) : mAddress(Resolve(address)) { } -cIpAddress::cIpAddress(const char* address) : +IpAddress::IpAddress(const char* address) : mAddress(Resolve(address)) { } -cIpAddress::cIpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) : +IpAddress::IpAddress(Uint8 byte0, Uint8 byte1, Uint8 byte2, Uint8 byte3) : mAddress(htonl((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3)) { } -cIpAddress::cIpAddress(Uint32 address) : +IpAddress::IpAddress(Uint32 address) : mAddress(htonl(address)) { } -std::string cIpAddress::ToString() const { +std::string IpAddress::ToString() const { in_addr address; address.s_addr = mAddress; @@ -77,94 +77,94 @@ std::string cIpAddress::ToString() const { } -Uint32 cIpAddress::ToInteger() const { +Uint32 IpAddress::ToInteger() const { return ntohl(mAddress); } -cIpAddress cIpAddress::GetLocalAddress() { +IpAddress IpAddress::GetLocalAddress() { // The method here is to connect a UDP socket to anyone (here to localhost), // and get the local socket address with the getsockname function. // UDP connection will not send anything to the network, so this function won't cause any overhead. - cIpAddress localAddress; + IpAddress localAddress; // Create the socket SocketHandle sock = socket(PF_INET, SOCK_DGRAM, 0); - if (sock == Private::cSocketImpl::InvalidSocket()) + if (sock == Private::SocketImpl::InvalidSocket()) return localAddress; // Connect the socket to localhost on any port - sockaddr_in address = Private::cSocketImpl::CreateAddress(ntohl(INADDR_LOOPBACK), 9); + sockaddr_in address = Private::SocketImpl::CreateAddress(ntohl(INADDR_LOOPBACK), 9); if (connect(sock, reinterpret_cast(&address), sizeof(address)) == -1) { - Private::cSocketImpl::Close(sock); + Private::SocketImpl::Close(sock); return localAddress; } // Get the local address of the socket connection - Private::cSocketImpl::AddrLength size = sizeof(address); + Private::SocketImpl::AddrLength size = sizeof(address); if (getsockname(sock, reinterpret_cast(&address), &size) == -1) { - Private::cSocketImpl::Close(sock); + Private::SocketImpl::Close(sock); return localAddress; } // Close the socket - Private::cSocketImpl::Close(sock); + Private::SocketImpl::Close(sock); // Finally build the IP address - localAddress = cIpAddress(ntohl(address.sin_addr.s_addr)); + localAddress = IpAddress(ntohl(address.sin_addr.s_addr)); return localAddress; } -cIpAddress cIpAddress::GetPublicAddress(cTime timeout) { +IpAddress IpAddress::GetPublicAddress(cTime timeout) { // The trick here is more complicated, because the only way // to get our public IP address is to get it from a distant computer. // Here we get the web page from http://www.sfml-dev.org/ip-provider.php // and parse the result to extract our IP address // (not very hard: the web page contains only our IP address). - cHttp server("www.sfml-dev.org"); - cHttp::Request request("/ip-provider.php", cHttp::Request::Get); - cHttp::Response page = server.SendRequest(request, timeout); - if (page.GetStatus() == cHttp::Response::Ok) - return cIpAddress(page.GetBody()); + Http server("www.sfml-dev.org"); + Http::Request request("/ip-provider.php", Http::Request::Get); + Http::Response page = server.SendRequest(request, timeout); + if (page.GetStatus() == Http::Response::Ok) + return IpAddress(page.GetBody()); // Something failed: return an invalid address - return cIpAddress(); + return IpAddress(); } -bool operator ==(const cIpAddress& left, const cIpAddress& right) { +bool operator ==(const IpAddress& left, const IpAddress& right) { return left.ToInteger() == right.ToInteger(); } -bool operator !=(const cIpAddress& left, const cIpAddress& right) { +bool operator !=(const IpAddress& left, const IpAddress& right) { return !(left == right); } -bool operator <(const cIpAddress& left, const cIpAddress& right) { +bool operator <(const IpAddress& left, const IpAddress& right) { return left.ToInteger() < right.ToInteger(); } -bool operator >(const cIpAddress& left, const cIpAddress& right) { +bool operator >(const IpAddress& left, const IpAddress& right) { return right < left; } -bool operator <=(const cIpAddress& left, const cIpAddress& right) { +bool operator <=(const IpAddress& left, const IpAddress& right) { return !(right < left); } -bool operator >=(const cIpAddress& left, const cIpAddress& right) { +bool operator >=(const IpAddress& left, const IpAddress& right) { return !(left < right); } -std::istream& operator >>(std::istream& stream, cIpAddress& address) { +std::istream& operator >>(std::istream& stream, IpAddress& address) { std::string str; stream >> str; - address = cIpAddress(str); + address = IpAddress(str); return stream; } -std::ostream& operator <<(std::ostream& stream, const cIpAddress& address) { +std::ostream& operator <<(std::ostream& stream, const IpAddress& address) { return stream << address.ToString(); } diff --git a/src/eepp/network/cpacket.cpp b/src/eepp/network/packet.cpp similarity index 70% rename from src/eepp/network/cpacket.cpp rename to src/eepp/network/packet.cpp index a306fb9d3..143e49881 100644 --- a/src/eepp/network/cpacket.cpp +++ b/src/eepp/network/packet.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -8,17 +8,17 @@ namespace EE { namespace Network { -cPacket::cPacket() : +Packet::Packet() : mReadPos(0), mIsValid(true) { } -cPacket::~cPacket() +Packet::~Packet() { } -void cPacket::Append(const void* data, std::size_t sizeInBytes) { +void Packet::Append(const void* data, std::size_t sizeInBytes) { if (data && (sizeInBytes > 0)) { std::size_t start = mData.size(); mData.resize(start + sizeInBytes); @@ -26,29 +26,29 @@ void cPacket::Append(const void* data, std::size_t sizeInBytes) { } } -void cPacket::Clear() { +void Packet::Clear() { mData.clear(); mReadPos = 0; mIsValid = true; } -const void* cPacket::GetData() const { +const void* Packet::GetData() const { return !mData.empty() ? &mData[0] : NULL; } -std::size_t cPacket::GetDataSize() const { +std::size_t Packet::GetDataSize() const { return mData.size(); } -bool cPacket::EndOfcPacket() const { +bool Packet::EndOfPacket() const { return mReadPos >= mData.size(); } -cPacket::operator BoolType() const { - return mIsValid ? &cPacket::CheckSize : NULL; +Packet::operator BoolType() const { + return mIsValid ? &Packet::CheckSize : NULL; } -cPacket& cPacket::operator >>(bool& data) { +Packet& Packet::operator >>(bool& data) { Uint8 value; if (*this >> value) data = (value != 0); @@ -56,7 +56,7 @@ cPacket& cPacket::operator >>(bool& data) { return *this; } -cPacket& cPacket::operator >>(Int8& data) { +Packet& Packet::operator >>(Int8& data) { if (CheckSize(sizeof(data))) { data = *reinterpret_cast(&mData[mReadPos]); mReadPos += sizeof(data); @@ -65,7 +65,7 @@ cPacket& cPacket::operator >>(Int8& data) { return *this; } -cPacket& cPacket::operator >>(Uint8& data) { +Packet& Packet::operator >>(Uint8& data) { if (CheckSize(sizeof(data))) { data = *reinterpret_cast(&mData[mReadPos]); mReadPos += sizeof(data); @@ -74,7 +74,7 @@ cPacket& cPacket::operator >>(Uint8& data) { return *this; } -cPacket& cPacket::operator >>(Int16& data) { +Packet& Packet::operator >>(Int16& data) { if (CheckSize(sizeof(data))) { data = ntohs(*reinterpret_cast(&mData[mReadPos])); mReadPos += sizeof(data); @@ -83,7 +83,7 @@ cPacket& cPacket::operator >>(Int16& data) { return *this; } -cPacket& cPacket::operator >>(Uint16& data) { +Packet& Packet::operator >>(Uint16& data) { if (CheckSize(sizeof(data))) { data = ntohs(*reinterpret_cast(&mData[mReadPos])); mReadPos += sizeof(data); @@ -93,7 +93,7 @@ cPacket& cPacket::operator >>(Uint16& data) { } -cPacket& cPacket::operator >>(Int32& data) { +Packet& Packet::operator >>(Int32& data) { if (CheckSize(sizeof(data))) { data = ntohl(*reinterpret_cast(&mData[mReadPos])); mReadPos += sizeof(data); @@ -102,7 +102,7 @@ cPacket& cPacket::operator >>(Int32& data) { return *this; } -cPacket& cPacket::operator >>(Uint32& data) { +Packet& Packet::operator >>(Uint32& data) { if (CheckSize(sizeof(data))) { data = ntohl(*reinterpret_cast(&mData[mReadPos])); mReadPos += sizeof(data); @@ -111,7 +111,7 @@ cPacket& cPacket::operator >>(Uint32& data) { return *this; } -cPacket& cPacket::operator >>(float& data) { +Packet& Packet::operator >>(float& data) { if (CheckSize(sizeof(data))) { data = *reinterpret_cast(&mData[mReadPos]); mReadPos += sizeof(data); @@ -120,7 +120,7 @@ cPacket& cPacket::operator >>(float& data) { return *this; } -cPacket& cPacket::operator >>(double& data) { +Packet& Packet::operator >>(double& data) { if (CheckSize(sizeof(data))) { data = *reinterpret_cast(&mData[mReadPos]); mReadPos += sizeof(data); @@ -129,7 +129,7 @@ cPacket& cPacket::operator >>(double& data) { return *this; } -cPacket& cPacket::operator >>(char* data) { +Packet& Packet::operator >>(char* data) { // First extract string length Uint32 length = 0; *this >> length; @@ -146,7 +146,7 @@ cPacket& cPacket::operator >>(char* data) { return *this; } -cPacket& cPacket::operator >>(std::string& data) { +Packet& Packet::operator >>(std::string& data) { // First extract string length Uint32 length = 0; *this >> length; @@ -165,7 +165,7 @@ cPacket& cPacket::operator >>(std::string& data) { } #ifndef EE_NO_WIDECHAR -cPacket& cPacket::operator >>(wchar_t* data) { +Packet& Packet::operator >>(wchar_t* data) { // First extract string length Uint32 length = 0; *this >> length; @@ -184,7 +184,7 @@ cPacket& cPacket::operator >>(wchar_t* data) { return *this; } -cPacket& cPacket::operator >>(std::wstring& data) { +Packet& Packet::operator >>(std::wstring& data) { // First extract string length Uint32 length = 0; *this >> length; @@ -203,7 +203,7 @@ cPacket& cPacket::operator >>(std::wstring& data) { } #endif -cPacket& cPacket::operator >>(String& data) { +Packet& Packet::operator >>(String& data) { // First extract the string length Uint32 length = 0; *this >> length; @@ -221,56 +221,56 @@ cPacket& cPacket::operator >>(String& data) { return *this; } -cPacket& cPacket::operator <<(bool data) { +Packet& Packet::operator <<(bool data) { *this << static_cast(data); return *this; } -cPacket& cPacket::operator <<(Int8 data) { +Packet& Packet::operator <<(Int8 data) { Append(&data, sizeof(data)); return *this; } -cPacket& cPacket::operator <<(Uint8 data) { +Packet& Packet::operator <<(Uint8 data) { Append(&data, sizeof(data)); return *this; } -cPacket& cPacket::operator <<(Int16 data) { +Packet& Packet::operator <<(Int16 data) { Int16 toWrite = htons(data); Append(&toWrite, sizeof(toWrite)); return *this; } -cPacket& cPacket::operator <<(Uint16 data) { +Packet& Packet::operator <<(Uint16 data) { Uint16 toWrite = htons(data); Append(&toWrite, sizeof(toWrite)); return *this; } -cPacket& cPacket::operator <<(Int32 data) { +Packet& Packet::operator <<(Int32 data) { Int32 toWrite = htonl(data); Append(&toWrite, sizeof(toWrite)); return *this; } -cPacket& cPacket::operator <<(Uint32 data) { +Packet& Packet::operator <<(Uint32 data) { Uint32 toWrite = htonl(data); Append(&toWrite, sizeof(toWrite)); return *this; } -cPacket& cPacket::operator <<(float data) { +Packet& Packet::operator <<(float data) { Append(&data, sizeof(data)); return *this; } -cPacket& cPacket::operator <<(double data) { +Packet& Packet::operator <<(double data) { Append(&data, sizeof(data)); return *this; } -cPacket& cPacket::operator <<(const char* data) { +Packet& Packet::operator <<(const char* data) { // First insert string length Uint32 length = std::strlen(data); *this << length; @@ -281,7 +281,7 @@ cPacket& cPacket::operator <<(const char* data) { return *this; } -cPacket& cPacket::operator <<(const std::string& data) { +Packet& Packet::operator <<(const std::string& data) { // First insert string length Uint32 length = static_cast(data.size()); *this << length; @@ -294,7 +294,7 @@ cPacket& cPacket::operator <<(const std::string& data) { } #ifndef EE_NO_WIDECHAR -cPacket& cPacket::operator <<(const wchar_t* data) { +Packet& Packet::operator <<(const wchar_t* data) { // First insert string length Uint32 length = std::wcslen(data); *this << length; @@ -306,7 +306,7 @@ cPacket& cPacket::operator <<(const wchar_t* data) { return *this; } -cPacket& cPacket::operator <<(const std::wstring& data) { +Packet& Packet::operator <<(const std::wstring& data) { // First insert string length Uint32 length = static_cast(data.size()); *this << length; @@ -321,7 +321,7 @@ cPacket& cPacket::operator <<(const std::wstring& data) { } #endif -cPacket& cPacket::operator <<(const String& data) { +Packet& Packet::operator <<(const String& data) { // First insert the string length Uint32 length = static_cast(data.size()); *this << length; @@ -335,17 +335,17 @@ cPacket& cPacket::operator <<(const String& data) { return *this; } -bool cPacket::CheckSize(std::size_t size) { +bool Packet::CheckSize(std::size_t size) { mIsValid = mIsValid && (mReadPos + size <= mData.size()); return mIsValid; } -const void* cPacket::OnSend(std::size_t& size) { +const void* Packet::OnSend(std::size_t& size) { size = GetDataSize(); return GetData(); } -void cPacket::OnReceive(const void* data, std::size_t size) { +void Packet::OnReceive(const void* data, std::size_t size) { Append(data, size); } diff --git a/src/eepp/network/platform/unix/csocketimpl.cpp b/src/eepp/network/platform/unix/csocketimpl.cpp index 230cb16a0..da319b3eb 100644 --- a/src/eepp/network/platform/unix/csocketimpl.cpp +++ b/src/eepp/network/platform/unix/csocketimpl.cpp @@ -8,7 +8,7 @@ namespace EE { namespace Network { namespace Private { -sockaddr_in cSocketImpl::CreateAddress(Uint32 address, unsigned short port) { +sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port) { sockaddr_in addr; std::memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(address); @@ -22,15 +22,15 @@ sockaddr_in cSocketImpl::CreateAddress(Uint32 address, unsigned short port) { return addr; } -SocketHandle cSocketImpl::InvalidSocket() { +SocketHandle SocketImpl::InvalidSocket() { return -1; } -void cSocketImpl::Close(SocketHandle sock) { +void SocketImpl::Close(SocketHandle sock) { ::close(sock); } -void cSocketImpl::SetBlocking(SocketHandle sock, bool block) { +void SocketImpl::SetBlocking(SocketHandle sock, bool block) { int status = fcntl(sock, F_GETFL); if (block) fcntl(sock, F_SETFL, status & ~O_NONBLOCK); @@ -38,22 +38,22 @@ void cSocketImpl::SetBlocking(SocketHandle sock, bool block) { fcntl(sock, F_SETFL, status | O_NONBLOCK); } -cSocket::Status cSocketImpl::GetErrorStatus() { +Socket::Status SocketImpl::GetErrorStatus() { // The followings are sometimes equal to EWOULDBLOCK, // so we have to make a special case for them in order // to avoid having double values in the switch case if ((errno == EAGAIN) || (errno == EINPROGRESS)) - return cSocket::NotReady; + return Socket::NotReady; switch (errno) { - case EWOULDBLOCK: return cSocket::NotReady; - case ECONNABORTED: return cSocket::Disconnected; - case ECONNRESET: return cSocket::Disconnected; - case ETIMEDOUT: return cSocket::Disconnected; - case ENETRESET: return cSocket::Disconnected; - case ENOTCONN: return cSocket::Disconnected; - case EPIPE: return cSocket::Disconnected; - default: return cSocket::Error; + case EWOULDBLOCK: return Socket::NotReady; + case ECONNABORTED: return Socket::Disconnected; + case ECONNRESET: return Socket::Disconnected; + case ETIMEDOUT: return Socket::Disconnected; + case ENETRESET: return Socket::Disconnected; + case ENOTCONN: return Socket::Disconnected; + case EPIPE: return Socket::Disconnected; + default: return Socket::Error; } } diff --git a/src/eepp/network/platform/unix/csocketimpl.hpp b/src/eepp/network/platform/unix/csocketimpl.hpp index 2a7388c92..3d941aa26 100644 --- a/src/eepp/network/platform/unix/csocketimpl.hpp +++ b/src/eepp/network/platform/unix/csocketimpl.hpp @@ -5,7 +5,7 @@ #if defined( EE_PLATFORM_POSIX ) -#include +#include #include #include #include @@ -17,7 +17,7 @@ namespace EE { namespace Network { namespace Private { /** @brief Helper class implementing all the non-portable socket stuff; this is the Unix version */ -class cSocketImpl { +class SocketImpl { public : // Types typedef socklen_t AddrLength; @@ -43,7 +43,7 @@ class cSocketImpl { /** Get the last socket error status ** @return Status corresponding to the last socket error */ - static cSocket::Status GetErrorStatus(); + static Socket::Status GetErrorStatus(); }; }}} diff --git a/src/eepp/network/platform/win/csocketimpl.cpp b/src/eepp/network/platform/win/csocketimpl.cpp index 91b3e9a70..d835674d1 100644 --- a/src/eepp/network/platform/win/csocketimpl.cpp +++ b/src/eepp/network/platform/win/csocketimpl.cpp @@ -5,7 +5,7 @@ namespace EE { namespace Network { namespace Private { -sockaddr_in cSocketImpl::CreateAddress(Uint32 address, unsigned short port) { +sockaddr_in SocketImpl::CreateAddress(Uint32 address, unsigned short port) { sockaddr_in addr; std::memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(address); @@ -15,30 +15,30 @@ sockaddr_in cSocketImpl::CreateAddress(Uint32 address, unsigned short port) { return addr; } -SocketHandle cSocketImpl::InvalidSocket() { +SocketHandle SocketImpl::InvalidSocket() { return INVALID_SOCKET; } -void cSocketImpl::Close(SocketHandle sock) { +void SocketImpl::Close(SocketHandle sock) { closesocket(sock); } -void cSocketImpl::SetBlocking(SocketHandle sock, bool block) { +void SocketImpl::SetBlocking(SocketHandle sock, bool block) { u_long blocking = block ? 0 : 1; ioctlsocket(sock, FIONBIO, &blocking); } -cSocket::Status cSocketImpl::GetErrorStatus() { +Socket::Status SocketImpl::GetErrorStatus() { switch (WSAGetLastError()) { - case WSAEWOULDBLOCK: return cSocket::NotReady; - case WSAEALREADY: return cSocket::NotReady; - case WSAECONNABORTED: return cSocket::Disconnected; - case WSAECONNRESET: return cSocket::Disconnected; - case WSAETIMEDOUT: return cSocket::Disconnected; - case WSAENETRESET: return cSocket::Disconnected; - case WSAENOTCONN: return cSocket::Disconnected; - case WSAEISCONN: return cSocket::Done; // when connecting a non-blocking socket - default: return cSocket::Error; + case WSAEWOULDBLOCK: return Socket::NotReady; + case WSAEALREADY: return Socket::NotReady; + case WSAECONNABORTED: return Socket::Disconnected; + case WSAECONNRESET: return Socket::Disconnected; + case WSAETIMEDOUT: return Socket::Disconnected; + case WSAENETRESET: return Socket::Disconnected; + case WSAENOTCONN: return Socket::Disconnected; + case WSAEISCONN: return Socket::Done; // when connecting a non-blocking socket + default: return Socket::Error; } } diff --git a/src/eepp/network/platform/win/csocketimpl.hpp b/src/eepp/network/platform/win/csocketimpl.hpp index 2b2efb17c..3e0a1ddce 100644 --- a/src/eepp/network/platform/win/csocketimpl.hpp +++ b/src/eepp/network/platform/win/csocketimpl.hpp @@ -13,14 +13,14 @@ #endif #define _WIN32_WINDOWS 0x0501 #define _WIN32_WINNT 0x0501 -#include +#include #include #include namespace EE { namespace Network { namespace Private { /** @brief Helper class implementing all the non-portable socket stuff; this is the Windows version */ -class cSocketImpl { +class SocketImpl { public : // Types typedef socklen_t AddrLength; @@ -46,7 +46,7 @@ class cSocketImpl { /** Get the last socket error status ** @return Status corresponding to the last socket error */ - static cSocket::Status GetErrorStatus(); + static Socket::Status GetErrorStatus(); }; }}} diff --git a/src/eepp/network/csocket.cpp b/src/eepp/network/socket.cpp similarity index 65% rename from src/eepp/network/csocket.cpp rename to src/eepp/network/socket.cpp index 5a5952673..b46edee97 100644 --- a/src/eepp/network/csocket.cpp +++ b/src/eepp/network/socket.cpp @@ -1,47 +1,47 @@ -#include +#include #include namespace EE { namespace Network { -cSocket::cSocket(Type type) : +Socket::Socket(Type type) : mType(type), - mSocket (Private::cSocketImpl::InvalidSocket()), + mSocket (Private::SocketImpl::InvalidSocket()), mIsBlocking(true) { } -cSocket::~cSocket() { +Socket::~Socket() { // Close the socket before it gets destructed Close(); } -void cSocket::SetBlocking(bool blocking) { +void Socket::SetBlocking(bool blocking) { // Apply if the socket is already created - if (mSocket != Private::cSocketImpl::InvalidSocket()) - Private::cSocketImpl::SetBlocking(mSocket, blocking); + if (mSocket != Private::SocketImpl::InvalidSocket()) + Private::SocketImpl::SetBlocking(mSocket, blocking); mIsBlocking = blocking; } -bool cSocket::IsBlocking() const { +bool Socket::IsBlocking() const { return mIsBlocking; } -SocketHandle cSocket::GetHandle() const { +SocketHandle Socket::GetHandle() const { return mSocket; } -void cSocket::Create() { +void Socket::Create() { // Don't create the socket if it already exists - if (mSocket == Private::cSocketImpl::InvalidSocket()) { + if (mSocket == Private::SocketImpl::InvalidSocket()) { SocketHandle handle = socket(PF_INET, mType == Tcp ? SOCK_STREAM : SOCK_DGRAM, 0); Create(handle); } } -void cSocket::Create(SocketHandle handle) { +void Socket::Create(SocketHandle handle) { // Don't create the socket if it already exists - if (mSocket == Private::cSocketImpl::InvalidSocket()) { + if (mSocket == Private::SocketImpl::InvalidSocket()) { // Assign the new handle mSocket = handle; @@ -73,11 +73,11 @@ void cSocket::Create(SocketHandle handle) { } } -void cSocket::Close() { +void Socket::Close() { // Close the socket - if (mSocket != Private::cSocketImpl::InvalidSocket()) { - Private::cSocketImpl::Close(mSocket); - mSocket = Private::cSocketImpl::InvalidSocket(); + if (mSocket != Private::SocketImpl::InvalidSocket()) { + Private::SocketImpl::Close(mSocket); + mSocket = Private::SocketImpl::InvalidSocket(); } } diff --git a/src/eepp/network/csocketselector.cpp b/src/eepp/network/socketselector.cpp similarity index 64% rename from src/eepp/network/csocketselector.cpp rename to src/eepp/network/socketselector.cpp index 236d4c143..c15e9fde3 100644 --- a/src/eepp/network/csocketselector.cpp +++ b/src/eepp/network/socketselector.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include @@ -9,31 +9,31 @@ namespace EE { namespace Network { -struct cSocketSelector::cSocketSelectorImpl { +struct SocketSelector::SocketSelectorImpl { fd_set AllSockets; ///< Set containing all the sockets handles fd_set SocketsReady; ///< Set containing handles of the sockets that are ready int MaxSocket; ///< Maximum socket handle }; -cSocketSelector::cSocketSelector() : - mImpl( eeNew( cSocketSelectorImpl, () ) ) +SocketSelector::SocketSelector() : + mImpl( eeNew( SocketSelectorImpl, () ) ) { Clear(); } -cSocketSelector::cSocketSelector(const cSocketSelector& copy) : - mImpl( eeNew( cSocketSelectorImpl, (*copy.mImpl) ) ) +SocketSelector::SocketSelector(const SocketSelector& copy) : + mImpl( eeNew( SocketSelectorImpl, (*copy.mImpl) ) ) { } -cSocketSelector::~cSocketSelector() { +SocketSelector::~SocketSelector() { eeSAFE_DELETE( mImpl ); } -void cSocketSelector::Add(cSocket& socket) { +void SocketSelector::Add(Socket& socket) { SocketHandle handle = socket.GetHandle(); - if (handle != Private::cSocketImpl::InvalidSocket()) { + if (handle != Private::SocketImpl::InvalidSocket()) { FD_SET(handle, &mImpl->AllSockets); int size = static_cast(handle); @@ -42,19 +42,19 @@ void cSocketSelector::Add(cSocket& socket) { } } -void cSocketSelector::Remove(cSocket& socket) { +void SocketSelector::Remove(Socket& socket) { FD_CLR(socket.GetHandle(), &mImpl->AllSockets); FD_CLR(socket.GetHandle(), &mImpl->SocketsReady); } -void cSocketSelector::Clear() { +void SocketSelector::Clear() { FD_ZERO(&mImpl->AllSockets); FD_ZERO(&mImpl->SocketsReady); mImpl->MaxSocket = 0; } -bool cSocketSelector::Wait(cTime timeout) { +bool SocketSelector::Wait(cTime timeout) { // Setup the timeout timeval time; time.tv_sec = static_cast(timeout.AsMicroseconds() / 1000000); @@ -69,12 +69,12 @@ bool cSocketSelector::Wait(cTime timeout) { return count > 0; } -bool cSocketSelector::IsReady(cSocket& socket) const { +bool SocketSelector::IsReady(Socket& socket) const { return FD_ISSET(socket.GetHandle(), &mImpl->SocketsReady) != 0; } -cSocketSelector& cSocketSelector::operator =(const cSocketSelector& right) { - cSocketSelector temp(right); +SocketSelector& SocketSelector::operator =(const SocketSelector& right) { + SocketSelector temp(right); std::swap(mImpl, temp.mImpl); diff --git a/src/eepp/network/ssl/backend/openssl/copensslsocket.cpp b/src/eepp/network/ssl/backend/openssl/opensslsocket.cpp similarity index 83% rename from src/eepp/network/ssl/backend/openssl/copensslsocket.cpp rename to src/eepp/network/ssl/backend/openssl/opensslsocket.cpp index c333d516b..4848e99ae 100644 --- a/src/eepp/network/ssl/backend/openssl/copensslsocket.cpp +++ b/src/eepp/network/ssl/backend/openssl/opensslsocket.cpp @@ -1,10 +1,10 @@ -#include +#include /** This implementation is based on the Godo Game Engine implementation ( https://github.com/okamstudio/godot ), MIT licensed. */ #ifdef EE_OPENSSL -#include +#include #include #include @@ -12,11 +12,11 @@ namespace EE { namespace Network { namespace SSL { static std::vector sCerts; -bool cOpenSSLSocket::MatchHostname( const char * name, const char * hostname ) { +bool OpenSSLSocket::MatchHostname( const char * name, const char * hostname ) { return Tool_Curl_cert_hostcheck( name, hostname )==CURL_HOST_MATCH; } -bool cOpenSSLSocket::MatchCommonName( const char * hostname, const X509 * server_cert ) { +bool OpenSSLSocket::MatchCommonName( const char * hostname, const X509 * server_cert ) { int common_name_loc = -1; X509_NAME_ENTRY *common_name_entry = NULL; ASN1_STRING *common_name_asn1 = NULL; @@ -45,7 +45,7 @@ bool cOpenSSLSocket::MatchCommonName( const char * hostname, const X509 * server } /** Tries to find a match for hostname in the certificate's Subject Alternative Name extension. */ -bool cOpenSSLSocket::MatchSubjectAlternativeName( const char * hostname, const X509 * server_cert ) { +bool OpenSSLSocket::MatchSubjectAlternativeName( const char * hostname, const X509 * server_cert ) { bool result = false; int i; int san_names_nb = -1; @@ -87,7 +87,7 @@ bool cOpenSSLSocket::MatchSubjectAlternativeName( const char * hostname, const X return result; } -int cOpenSSLSocket::CertVerifyCb( X509_STORE_CTX * x509_ctx, void * arg ) { +int OpenSSLSocket::CertVerifyCb( X509_STORE_CTX * x509_ctx, void * arg ) { /* This is the function that OpenSSL would call if we hadn't called * SSL_CTX_set_cert_verify_callback(). Therefore, we are "wrapping" * the default functionality, rather than replacing it. */ @@ -110,7 +110,7 @@ int cOpenSSLSocket::CertVerifyCb( X509_STORE_CTX * x509_ctx, void * arg ) { return 0; } - cOpenSSLSocket * ssl = (cOpenSSLSocket *)arg; + OpenSSLSocket * ssl = (OpenSSLSocket *)arg; if ( ssl->mSSLSocket->mValidateHostname ) { bool err = !MatchSubjectAlternativeName( ssl->mSSLSocket->mHostName.c_str(), server_cert ); @@ -120,7 +120,7 @@ int cOpenSSLSocket::CertVerifyCb( X509_STORE_CTX * x509_ctx, void * arg ) { } if ( err ) { - ssl->mStatus = cSocket::Error; + ssl->mStatus = Socket::Error; return 0; } } @@ -128,7 +128,7 @@ int cOpenSSLSocket::CertVerifyCb( X509_STORE_CTX * x509_ctx, void * arg ) { return 1; } -bool cOpenSSLSocket::Init() { +bool OpenSSLSocket::Init() { CRYPTO_malloc_init(); // Initialize malloc, free, etc for OpenSSL's use SSL_library_init(); // Initialize OpenSSL's SSL libraries @@ -140,9 +140,9 @@ bool cOpenSSLSocket::Init() { OpenSSL_add_all_algorithms(); // Load all available encryption algorithms //! Load the certificates and config - if ( FileSystem::FileExists( cSSLSocket::CertificatesPath ) ) { + if ( FileSystem::FileExists( SSLSocket::CertificatesPath ) ) { SafeDataPointer data; - FileSystem::FileGet( cSSLSocket::CertificatesPath, data ); + FileSystem::FileGet( SSLSocket::CertificatesPath, data ); if ( data.DataSize > 0 ) { BIO* mem = BIO_new(BIO_s_mem()); @@ -161,13 +161,13 @@ bool cOpenSSLSocket::Init() { BIO_free(mem); } - eePRINTL( "Loaded certs from '%s': %d", cSSLSocket::CertificatesPath.c_str(), (int)sCerts.size() ); + eePRINTL( "Loaded certs from '%s': %d", SSLSocket::CertificatesPath.c_str(), (int)sCerts.size() ); } return true; } -bool cOpenSSLSocket::End() { +bool OpenSSLSocket::End() { if ( !sCerts.empty() ) { for( size_t i = 0; i < sCerts.size(); i++ ) { X509_free(sCerts[i]); @@ -179,23 +179,23 @@ bool cOpenSSLSocket::End() { return true; } -cOpenSSLSocket::cOpenSSLSocket( cSSLSocket * socket ) : - cSSLSocketImpl( socket ), +OpenSSLSocket::OpenSSLSocket( SSLSocket * socket ) : + SSLSocketImpl( socket ), mCTX( NULL ), mSSL( NULL ), mBIO( NULL ), mConnected( false ), - mStatus( cSocket::Disconnected ), + mStatus( Socket::Disconnected ), mMaxCertChainDepth( 9 ) { mSSLSocket = socket; } -cOpenSSLSocket::~cOpenSSLSocket() { +OpenSSLSocket::~OpenSSLSocket() { Disconnect(); } -cSocket::Status cOpenSSLSocket::Connect( const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout ) { +Socket::Status OpenSSLSocket::Connect( const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout ) { if ( mConnected ) { Disconnect(); } @@ -249,7 +249,7 @@ cSocket::Status cOpenSSLSocket::Connect( const cIpAddress& remoteAddress, unsign // Set the SSL to automatically retry on failure. SSL_set_mode( mSSL , SSL_MODE_AUTO_RETRY ); - mStatus = cSocket::Done; + mStatus = Socket::Done; // Same as before, try to connect. int result = SSL_connect( mSSL ); @@ -261,7 +261,7 @@ cSocket::Status cOpenSSLSocket::Connect( const cIpAddress& remoteAddress, unsign _print_error(result); - mStatus = cSocket::Error; + mStatus = Socket::Error; return mStatus; } @@ -273,19 +273,19 @@ cSocket::Status cOpenSSLSocket::Connect( const cIpAddress& remoteAddress, unsign eePRINTL( "cert_ok: %d", (int)cert_ok ); - mStatus = cSocket::Done; + mStatus = Socket::Done; } else if ( mSSLSocket->mValidateCertificate ) { - mStatus = cSocket::Error; + mStatus = Socket::Error; } - if ( mStatus == cSocket::Done ) { + if ( mStatus == Socket::Done ) { mConnected = true; } return mStatus; } -void cOpenSSLSocket::Disconnect() { +void OpenSSLSocket::Disconnect() { if (!mConnected) return; @@ -296,10 +296,10 @@ void cOpenSSLSocket::Disconnect() { mSSL = NULL; mCTX = NULL; mConnected = false; - mStatus = cSocket::Disconnected; + mStatus = Socket::Disconnected; } -void cOpenSSLSocket::_print_error(int err) { +void OpenSSLSocket::_print_error(int err) { err = SSL_get_error(mSSL,err); switch(err) { @@ -320,7 +320,7 @@ void cOpenSSLSocket::_print_error(int err) { } } -cSocket::Status cOpenSSLSocket::Send( const void * data, std::size_t size ) { +Socket::Status OpenSSLSocket::Send( const void * data, std::size_t size ) { Uint8 * buf = (Uint8*)data; while( size > 0 ) { @@ -331,20 +331,20 @@ cSocket::Status cOpenSSLSocket::Send( const void * data, std::size_t size ) { Disconnect(); - return cSocket::Disconnected; + return Socket::Disconnected; } buf+=ret; size-=ret; } - return cSocket::Done; + return Socket::Done; } -cSocket::Status cOpenSSLSocket::Receive( void * data, std::size_t size, std::size_t& received ) { +Socket::Status OpenSSLSocket::Receive( void * data, std::size_t size, std::size_t& received ) { if ( size==0 ) { received = 0; - return cSocket::Done; + return Socket::Done; } size_t iniSize = size; @@ -359,15 +359,15 @@ cSocket::Status cOpenSSLSocket::Receive( void * data, std::size_t size, std::siz Disconnect(); - return cSocket::Disconnected; + return Socket::Disconnected; } else if ( 0 == ret ) { if ( size == iniSize ) { - return cSocket::Disconnected; + return Socket::Disconnected; } received = iniSize - size; - return cSocket::Done; + return Socket::Done; } buf+=ret; @@ -376,7 +376,7 @@ cSocket::Status cOpenSSLSocket::Receive( void * data, std::size_t size, std::siz received = iniSize; - return cSocket::Done; + return Socket::Done; } }}} diff --git a/src/eepp/network/ssl/backend/openssl/copensslsocket.hpp b/src/eepp/network/ssl/backend/openssl/opensslsocket.hpp similarity index 70% rename from src/eepp/network/ssl/backend/openssl/copensslsocket.hpp rename to src/eepp/network/ssl/backend/openssl/opensslsocket.hpp index f7edff827..4e40785a8 100644 --- a/src/eepp/network/ssl/backend/openssl/copensslsocket.hpp +++ b/src/eepp/network/ssl/backend/openssl/opensslsocket.hpp @@ -1,7 +1,7 @@ #ifndef EE_NETWORKCOPENLSSLSOCKET_HPP #define EE_NETWORKCOPENLSSLSOCKET_HPP -#include +#include #ifdef EE_OPENSSL @@ -23,30 +23,30 @@ extern "C" { namespace EE { namespace Network { namespace SSL { -class cOpenSSLSocket : public cSSLSocketImpl { +class OpenSSLSocket : public SSLSocketImpl { public: static bool Init(); static bool End(); - cOpenSSLSocket( cSSLSocket * socket ); + OpenSSLSocket( SSLSocket * socket ); - ~cOpenSSLSocket(); + ~OpenSSLSocket(); - cSocket::Status Connect(const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero); + Socket::Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero); void Disconnect(); - cSocket::Status Send(const void* data, std::size_t size); + Socket::Status Send(const void* data, std::size_t size); - cSocket::Status Receive(void* data, std::size_t size, std::size_t& received); + Socket::Status Receive(void* data, std::size_t size, std::size_t& received); protected: SSL_CTX * mCTX; ::SSL * mSSL; BIO * mBIO; - cSSLSocket * mSSLSocket; + SSLSocket * mSSLSocket; bool mConnected; - cSocket::Status mStatus; + Socket::Status mStatus; int mMaxCertChainDepth; private: diff --git a/src/eepp/network/ssl/csslsocketimpl.hpp b/src/eepp/network/ssl/csslsocketimpl.hpp deleted file mode 100644 index 33a80ae88..000000000 --- a/src/eepp/network/ssl/csslsocketimpl.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef EE_NETWORKCSSLSOCKETIMPL_HPP -#define EE_NETWORKCSSLSOCKETIMPL_HPP - -#include - -namespace EE { namespace Network { namespace SSL { - -class cSSLSocketImpl { - public: - cSSLSocketImpl( cSSLSocket * socket ) : - mSSLSocket( socket ) - {} - - virtual ~cSSLSocketImpl() {} - - virtual cSocket::Status Connect(const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero) = 0; - - virtual void Disconnect() = 0; - - virtual cSocket::Status Send(const void* data, std::size_t size) = 0; - - virtual cSocket::Status Receive(void* data, std::size_t size, std::size_t& received) = 0; - protected: - cSSLSocket * mSSLSocket; -}; - -}}} - -#endif diff --git a/src/eepp/network/ssl/csslsocket.cpp b/src/eepp/network/ssl/sslsocket.cpp similarity index 59% rename from src/eepp/network/ssl/csslsocket.cpp rename to src/eepp/network/ssl/sslsocket.cpp index b972c52f9..d8dfa259c 100644 --- a/src/eepp/network/ssl/csslsocket.cpp +++ b/src/eepp/network/ssl/sslsocket.cpp @@ -1,18 +1,18 @@ -#include -#include +#include +#include #include #ifdef EE_OPENSSL -#include +#include #endif namespace EE { namespace Network { namespace SSL { static bool ssl_initialized = false; -std::string cSSLSocket::CertificatesPath = ""; +std::string SSLSocket::CertificatesPath = ""; -bool cSSLSocket::Init() { +bool SSLSocket::Init() { bool ret = false; if ( !ssl_initialized ) { @@ -47,7 +47,7 @@ bool cSSLSocket::Init() { } #ifdef EE_OPENSSL - ret = cOpenSSLSocket::Init(); + ret = OpenSSLSocket::Init(); #endif ssl_initialized = true; @@ -56,12 +56,12 @@ bool cSSLSocket::Init() { return ret; } -bool cSSLSocket::End() { +bool SSLSocket::End() { bool ret = false; if ( ssl_initialized ) { #ifdef EE_OPENSSL - ret = cOpenSSLSocket::End(); + ret = OpenSSLSocket::End(); #endif ssl_initialized = false; @@ -70,7 +70,7 @@ bool cSSLSocket::End() { return ret; } -bool cSSLSocket::IsSupported() { +bool SSLSocket::IsSupported() { #ifdef EE_SSL_SUPPORT return true; #else @@ -78,9 +78,9 @@ bool cSSLSocket::IsSupported() { #endif } -cSSLSocket::cSSLSocket( std::string hostname , bool validateCertificate, bool validateHostname ) : +SSLSocket::SSLSocket( std::string hostname , bool validateCertificate, bool validateHostname ) : #ifdef EE_OPENSSL - mImpl( eeNew( cOpenSSLSocket, ( this ) ) ), + mImpl( eeNew( OpenSSLSocket, ( this ) ) ), #else mImpl( NULL ), #endif @@ -91,47 +91,47 @@ cSSLSocket::cSSLSocket( std::string hostname , bool validateCertificate, bool va Init(); } -cSSLSocket::~cSSLSocket() { +SSLSocket::~SSLSocket() { eeSAFE_DELETE( mImpl ); } -cSocket::Status cSSLSocket::Connect( const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout ) { - Status status = cSocket::Disconnected; +Socket::Status SSLSocket::Connect( const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout ) { + Status status = Socket::Disconnected; - if ( ( status = cTcpSocket::Connect( remoteAddress, remotePort, timeout ) ) == cSocket::Done ) { + if ( ( status = TcpSocket::Connect( remoteAddress, remotePort, timeout ) ) == Socket::Done ) { status = mImpl->Connect( remoteAddress, remotePort, timeout ); } return status; } -void cSSLSocket::Disconnect() { +void SSLSocket::Disconnect() { mImpl->Disconnect(); - cTcpSocket::Disconnect(); + TcpSocket::Disconnect(); } -cSocket::Status cSSLSocket::Send(const void* data, std::size_t size) { +Socket::Status SSLSocket::Send(const void* data, std::size_t size) { return mImpl->Send( data, size ); } -cSocket::Status cSSLSocket::Receive(void* data, std::size_t size, std::size_t& received) { +Socket::Status SSLSocket::Receive(void* data, std::size_t size, std::size_t& received) { return mImpl->Receive( data, size, received ); } -cSocket::Status cSSLSocket::Send(cPacket& packet) { - return cTcpSocket::Send( packet ); +Socket::Status SSLSocket::Send(Packet& packet) { + return TcpSocket::Send( packet ); } -cSocket::Status cSSLSocket::Receive(cPacket& packet) { - return cTcpSocket::Receive( packet ); +Socket::Status SSLSocket::Receive(Packet& packet) { + return TcpSocket::Receive( packet ); } -cSocket::Status cSSLSocket::TcpSend(const void* data, std::size_t size) { - return cTcpSocket::Send( data, size ); +Socket::Status SSLSocket::TcpSend(const void* data, std::size_t size) { + return TcpSocket::Send( data, size ); } -cSocket::Status cSSLSocket::TcpReceive(void* data, std::size_t size, std::size_t& received) { - return cTcpSocket::Receive( data, size, received ); +Socket::Status SSLSocket::TcpReceive(void* data, std::size_t size, std::size_t& received) { + return TcpSocket::Receive( data, size, received ); } }}} diff --git a/src/eepp/network/ssl/sslsocketimpl.hpp b/src/eepp/network/ssl/sslsocketimpl.hpp new file mode 100644 index 000000000..a49e86678 --- /dev/null +++ b/src/eepp/network/ssl/sslsocketimpl.hpp @@ -0,0 +1,29 @@ +#ifndef EE_NETWORKCSSLSOCKETIMPL_HPP +#define EE_NETWORKCSSLSOCKETIMPL_HPP + +#include + +namespace EE { namespace Network { namespace SSL { + +class SSLSocketImpl { + public: + SSLSocketImpl( SSLSocket * socket ) : + mSSLSocket( socket ) + {} + + virtual ~SSLSocketImpl() {} + + virtual Socket::Status Connect(const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout = cTime::Zero) = 0; + + virtual void Disconnect() = 0; + + virtual Socket::Status Send(const void* data, std::size_t size) = 0; + + virtual Socket::Status Receive(void* data, std::size_t size, std::size_t& received) = 0; + protected: + SSLSocket * mSSLSocket; +}; + +}}} + +#endif diff --git a/src/eepp/network/ctcplistener.cpp b/src/eepp/network/tcplistener.cpp similarity index 60% rename from src/eepp/network/ctcplistener.cpp rename to src/eepp/network/tcplistener.cpp index f40c1cca2..789818578 100644 --- a/src/eepp/network/ctcplistener.cpp +++ b/src/eepp/network/tcplistener.cpp @@ -1,19 +1,19 @@ -#include -#include +#include +#include #include namespace EE { namespace Network { -cTcpListener::cTcpListener() : - cSocket(Tcp) +TcpListener::TcpListener() : + Socket(Tcp) { } -unsigned short cTcpListener::GetLocalPort() const { - if (GetHandle() != Private::cSocketImpl::InvalidSocket()) { +unsigned short TcpListener::GetLocalPort() const { + if (GetHandle() != Private::SocketImpl::InvalidSocket()) { // Retrieve informations about the local end of the socket sockaddr_in address; - Private::cSocketImpl::AddrLength size = sizeof(address); + Private::SocketImpl::AddrLength size = sizeof(address); if (getsockname(GetHandle(), reinterpret_cast(&address), &size) != -1) { return ntohs(address.sin_port); @@ -24,12 +24,12 @@ unsigned short cTcpListener::GetLocalPort() const { return 0; } -cSocket::Status cTcpListener::Listen(unsigned short port) { +Socket::Status TcpListener::Listen(unsigned short port) { // Create the internal socket if it doesn't exist Create(); // Bind the socket to the specified port - sockaddr_in address = Private::cSocketImpl::CreateAddress(INADDR_ANY, port); + sockaddr_in address = Private::SocketImpl::CreateAddress(INADDR_ANY, port); if (bind(GetHandle(), reinterpret_cast(&address), sizeof(address)) == -1) { // Not likely to happen, but... eePRINTL( "Failed to bind listener socket to port %d", port ); @@ -46,26 +46,26 @@ cSocket::Status cTcpListener::Listen(unsigned short port) { return Done; } -void cTcpListener::Close() { +void TcpListener::Close() { // Simply close the socket - cSocket::Close(); + Socket::Close(); } -cSocket::Status cTcpListener::Accept(cTcpSocket& socket) { +Socket::Status TcpListener::Accept(TcpSocket& socket) { // Make sure that we're listening - if (GetHandle() == Private::cSocketImpl::InvalidSocket()) { + if (GetHandle() == Private::SocketImpl::InvalidSocket()) { eePRINTL( "Failed to accept a new connection, the socket is not listening" ); return Error; } // Accept a new connection sockaddr_in address; - Private::cSocketImpl::AddrLength length = sizeof(address); + Private::SocketImpl::AddrLength length = sizeof(address); SocketHandle remote = ::accept(GetHandle(), reinterpret_cast(&address), &length); // Check for errors - if (remote == Private::cSocketImpl::InvalidSocket()) - return Private::cSocketImpl::GetErrorStatus(); + if (remote == Private::SocketImpl::InvalidSocket()) + return Private::SocketImpl::GetErrorStatus(); // Initialize the new connected socket socket.Close(); diff --git a/src/eepp/network/ctcpsocket.cpp b/src/eepp/network/tcpsocket.cpp similarity index 78% rename from src/eepp/network/ctcpsocket.cpp rename to src/eepp/network/tcpsocket.cpp index 68cadbc02..b719c7c37 100644 --- a/src/eepp/network/ctcpsocket.cpp +++ b/src/eepp/network/tcpsocket.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include #include #include @@ -21,16 +21,16 @@ namespace namespace EE { namespace Network { -cTcpSocket::cTcpSocket() : - cSocket(Tcp) +TcpSocket::TcpSocket() : + Socket(Tcp) { } -unsigned short cTcpSocket::GetLocalPort() const { - if (GetHandle() != Private::cSocketImpl::InvalidSocket()) { +unsigned short TcpSocket::GetLocalPort() const { + if (GetHandle() != Private::SocketImpl::InvalidSocket()) { // Retrieve informations about the local end of the socket sockaddr_in address; - Private::cSocketImpl::AddrLength size = sizeof(address); + Private::SocketImpl::AddrLength size = sizeof(address); if (getsockname(GetHandle(), reinterpret_cast(&address), &size) != -1) { return ntohs(address.sin_port); } @@ -40,25 +40,25 @@ unsigned short cTcpSocket::GetLocalPort() const { return 0; } -cIpAddress cTcpSocket::GetRemoteAddress() const { - if (GetHandle() != Private::cSocketImpl::InvalidSocket()) { +IpAddress TcpSocket::GetRemoteAddress() const { + if (GetHandle() != Private::SocketImpl::InvalidSocket()) { // Retrieve informations about the remote end of the socket sockaddr_in address; - Private::cSocketImpl::AddrLength size = sizeof(address); + Private::SocketImpl::AddrLength size = sizeof(address); if (getpeername(GetHandle(), reinterpret_cast(&address), &size) != -1) { - return cIpAddress(ntohl(address.sin_addr.s_addr)); + return IpAddress(ntohl(address.sin_addr.s_addr)); } } // We failed to retrieve the address - return cIpAddress::None; + return IpAddress::None; } -unsigned short cTcpSocket::GetRemotePort() const { - if (GetHandle() != Private::cSocketImpl::InvalidSocket()) { +unsigned short TcpSocket::GetRemotePort() const { + if (GetHandle() != Private::SocketImpl::InvalidSocket()) { // Retrieve informations about the remote end of the socket sockaddr_in address; - Private::cSocketImpl::AddrLength size = sizeof(address); + Private::SocketImpl::AddrLength size = sizeof(address); if (getpeername(GetHandle(), reinterpret_cast(&address), &size) != -1) { return ntohs(address.sin_port); } @@ -68,19 +68,19 @@ unsigned short cTcpSocket::GetRemotePort() const { return 0; } -cSocket::Status cTcpSocket::Connect(const cIpAddress& remoteAddress, unsigned short remotePort, cTime timeout) { +Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short remotePort, cTime timeout) { // Create the internal socket if it doesn't exist Create(); // Create the remote address - sockaddr_in address = Private::cSocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort); + sockaddr_in address = Private::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort); if (timeout <= cTime::Zero) { // ----- We're not using a timeout: just try to connect ----- // Connect the socket if (::connect(GetHandle(), reinterpret_cast(&address), sizeof(address)) == -1) - return Private::cSocketImpl::GetErrorStatus(); + return Private::SocketImpl::GetErrorStatus(); // Connection succeeded return Done; @@ -102,14 +102,14 @@ cSocket::Status cTcpSocket::Connect(const cIpAddress& remoteAddress, unsigned sh } // Get the error status - Status status = Private::cSocketImpl::GetErrorStatus(); + Status status = Private::SocketImpl::GetErrorStatus(); // If we were in non-blocking mode, return immediatly if (!blocking) return status; // Otherwise, wait until something happens to our socket (success, timeout or error) - if (status == cSocket::NotReady) { + if (status == Socket::NotReady) { // Setup the selector fd_set selector; FD_ZERO(&selector); @@ -124,16 +124,16 @@ cSocket::Status cTcpSocket::Connect(const cIpAddress& remoteAddress, unsigned sh if (select(static_cast(GetHandle() + 1), NULL, &selector, NULL, &time) > 0) { // At this point the connection may have been either accepted or refused. // To know whether it's a success or a failure, we must check the address of the connected peer - if (GetRemoteAddress() != cIpAddress::None) { + if (GetRemoteAddress() != IpAddress::None) { // Connection accepted status = Done; } else { // Connection refused - status = Private::cSocketImpl::GetErrorStatus(); + status = Private::SocketImpl::GetErrorStatus(); } } else { // Failed to connect before timeout is over - status = Private::cSocketImpl::GetErrorStatus(); + status = Private::SocketImpl::GetErrorStatus(); } } @@ -144,7 +144,7 @@ cSocket::Status cTcpSocket::Connect(const cIpAddress& remoteAddress, unsigned sh } } -void cTcpSocket::Disconnect() { +void TcpSocket::Disconnect() { // Close the socket Close(); @@ -152,7 +152,7 @@ void cTcpSocket::Disconnect() { mPendingPacket = PendingPacket(); } -cSocket::Status cTcpSocket::Send(const void* data, std::size_t size) { +Socket::Status TcpSocket::Send(const void* data, std::size_t size) { // Check the parameters if (!data || (size == 0)) { eePRINTL( "Cannot send data over the network (no data to send)" ); @@ -168,13 +168,13 @@ cSocket::Status cTcpSocket::Send(const void* data, std::size_t size) { // Check for errors if (sent < 0) - return Private::cSocketImpl::GetErrorStatus(); + return Private::SocketImpl::GetErrorStatus(); } return Done; } -cSocket::Status cTcpSocket::Receive(void* data, std::size_t size, std::size_t& received) { +Socket::Status TcpSocket::Receive(void* data, std::size_t size, std::size_t& received) { // First clear the variables to fill received = 0; @@ -192,13 +192,13 @@ cSocket::Status cTcpSocket::Receive(void* data, std::size_t size, std::size_t& r received = static_cast(sizeReceived); return Done; } else if (sizeReceived == 0) { - return cSocket::Disconnected; + return Socket::Disconnected; } else { - return Private::cSocketImpl::GetErrorStatus(); + return Private::SocketImpl::GetErrorStatus(); } } -cSocket::Status cTcpSocket::Send(cPacket& packet) { +Socket::Status TcpSocket::Send(Packet& packet) { // TCP is a stream protocol, it doesn't preserve messages boundaries. // This means that we have to send the packet size first, so that the // receiver knows the actual end of the packet in the data stream. @@ -227,7 +227,7 @@ cSocket::Status cTcpSocket::Send(cPacket& packet) { return Send(&blockToSend[0], blockToSend.size()); } -cSocket::Status cTcpSocket::Receive(cPacket& packet) { +Socket::Status TcpSocket::Receive(Packet& packet) { // First clear the variables to fill packet.Clear(); @@ -280,7 +280,7 @@ cSocket::Status cTcpSocket::Receive(cPacket& packet) { return Done; } -cTcpSocket::PendingPacket::PendingPacket() : +TcpSocket::PendingPacket::PendingPacket() : Size (0), SizeReceived(0), Data () diff --git a/src/eepp/network/cudpsocket.cpp b/src/eepp/network/udpsocket.cpp similarity index 64% rename from src/eepp/network/cudpsocket.cpp rename to src/eepp/network/udpsocket.cpp index 11eecfd34..000e802d1 100644 --- a/src/eepp/network/cudpsocket.cpp +++ b/src/eepp/network/udpsocket.cpp @@ -1,22 +1,22 @@ -#include -#include -#include +#include +#include +#include #include #include namespace EE { namespace Network { -cUdpSocket::cUdpSocket() : - cSocket (Udp), +UdpSocket::UdpSocket() : + Socket (Udp), mBuffer(MaxDatagramSize) { } -unsigned short cUdpSocket::GetLocalPort() const { - if (GetHandle() != Private::cSocketImpl::InvalidSocket()) { +unsigned short UdpSocket::GetLocalPort() const { + if (GetHandle() != Private::SocketImpl::InvalidSocket()) { // Retrieve informations about the local end of the socket sockaddr_in address; - Private::cSocketImpl::AddrLength size = sizeof(address); + Private::SocketImpl::AddrLength size = sizeof(address); if (getsockname(GetHandle(), reinterpret_cast(&address), &size) != -1) { return ntohs(address.sin_port); } @@ -26,12 +26,12 @@ unsigned short cUdpSocket::GetLocalPort() const { return 0; } -cSocket::Status cUdpSocket::Bind(unsigned short port) { +Socket::Status UdpSocket::Bind(unsigned short port) { // Create the internal socket if it doesn't exist Create(); // Bind the socket - sockaddr_in address = Private::cSocketImpl::CreateAddress(INADDR_ANY, port); + sockaddr_in address = Private::SocketImpl::CreateAddress(INADDR_ANY, port); if (::bind(GetHandle(), reinterpret_cast(&address), sizeof(address)) == -1) { eePRINTL( "Failed to bind socket to port %d", port ); return Error; @@ -40,39 +40,39 @@ cSocket::Status cUdpSocket::Bind(unsigned short port) { return Done; } -void cUdpSocket::Unbind() { +void UdpSocket::Unbind() { // Simply close the socket Close(); } -cSocket::Status cUdpSocket::Send(const void* data, std::size_t size, const cIpAddress& remoteAddress, unsigned short remotePort) { +Socket::Status UdpSocket::Send(const void* data, std::size_t size, const IpAddress& remoteAddress, unsigned short remotePort) { // Create the internal socket if it doesn't exist Create(); // Make sure that all the data will fit in one datagram if (size > MaxDatagramSize) { - eePRINTL( "Cannot send data over the network (the number of bytes to send is greater than cUdpSocket::MaxDatagramSize)" ); + eePRINTL( "Cannot send data over the network (the number of bytes to send is greater than UdpSocket::MaxDatagramSize)" ); return Error; } // Build the target address - sockaddr_in address = Private::cSocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort); + sockaddr_in address = Private::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort); // Send the data (unlike TCP, all the data is always sent in one call) int sent = sendto(GetHandle(), static_cast(data), static_cast(size), 0, reinterpret_cast(&address), sizeof(address)); // Check for errors if (sent < 0) - return Private::cSocketImpl::GetErrorStatus(); + return Private::SocketImpl::GetErrorStatus(); return Done; } -cSocket::Status cUdpSocket::Receive(void* data, std::size_t size, std::size_t& received, cIpAddress& remoteAddress, unsigned short& remotePort) { +Socket::Status UdpSocket::Receive(void* data, std::size_t size, std::size_t& received, IpAddress& remoteAddress, unsigned short& remotePort) { // First clear the variables to fill received = 0; - remoteAddress = cIpAddress(); + remoteAddress = IpAddress(); remotePort = 0; // Check the destination buffer @@ -82,25 +82,25 @@ cSocket::Status cUdpSocket::Receive(void* data, std::size_t size, std::size_t& r } // Data that will be filled with the other computer's address - sockaddr_in address = Private::cSocketImpl::CreateAddress(INADDR_ANY, 0); + sockaddr_in address = Private::SocketImpl::CreateAddress(INADDR_ANY, 0); // Receive a chunk of bytes - Private::cSocketImpl::AddrLength addressSize = sizeof(address); + Private::SocketImpl::AddrLength addressSize = sizeof(address); int sizeReceived = recvfrom(GetHandle(), static_cast(data), static_cast(size), 0, reinterpret_cast(&address), &addressSize); // Check for errors if (sizeReceived < 0) - return Private::cSocketImpl::GetErrorStatus(); + return Private::SocketImpl::GetErrorStatus(); // Fill the sender informations received = static_cast(sizeReceived); - remoteAddress = cIpAddress(ntohl(address.sin_addr.s_addr)); + remoteAddress = IpAddress(ntohl(address.sin_addr.s_addr)); remotePort = ntohs(address.sin_port); return Done; } -cSocket::Status cUdpSocket::Send(cPacket& packet, const cIpAddress& remoteAddress, unsigned short remotePort) { +Socket::Status UdpSocket::Send(Packet& packet, const IpAddress& remoteAddress, unsigned short remotePort) { // UDP is a datagram-oriented protocol (as opposed to TCP which is a stream protocol). // Sending one datagram is almost safe: it may be lost but if it's received, then its data // is guaranteed to be ok. However, splitting a packet into multiple datagrams would be highly @@ -117,8 +117,8 @@ cSocket::Status cUdpSocket::Send(cPacket& packet, const cIpAddress& remoteAddres return Send(data, size, remoteAddress, remotePort); } -cSocket::Status cUdpSocket::Receive(cPacket& packet, cIpAddress& remoteAddress, unsigned short& remotePort) { - // See the detailed comment in Send(cPacket) above. +Socket::Status UdpSocket::Receive(Packet& packet, IpAddress& remoteAddress, unsigned short& remotePort) { + // See the detailed comment in Send(Packet) above. // Receive the datagram std::size_t received = 0; diff --git a/src/eepp/window/cengine.cpp b/src/eepp/window/cengine.cpp index e29951248..32df78d75 100755 --- a/src/eepp/window/cengine.cpp +++ b/src/eepp/window/cengine.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -76,7 +76,7 @@ cEngine::~cEngine() { HaikuTTF::hkFontManager::DestroySingleton(); #ifdef EE_SSL_SUPPORT - Network::SSL::cSSLSocket::End(); + Network::SSL::SSLSocket::End(); #endif Destroy(); diff --git a/src/examples/http_request/http_request.cpp b/src/examples/http_request/http_request.cpp index b48688843..bcfe19e1b 100644 --- a/src/examples/http_request/http_request.cpp +++ b/src/examples/http_request/http_request.cpp @@ -1,9 +1,9 @@ #include -void AsyncRequestCallback( const cHttp& http, cHttp::Request& request, cHttp::Response& response ) { +void AsyncRequestCallback( const Http& http, Http::Request& request, Http::Response& response ) { std::cout << "Got response from request: " << http.GetHostName() << request.GetUri() << std::endl; - if ( response.GetStatus() == cHttp::Response::Ok ) { + if ( response.GetStatus() == Http::Response::Ok ) { std::cout << response.GetBody() << std::endl; } else { std::cout << "Error " << response.GetStatus() << std::endl; @@ -13,31 +13,31 @@ void AsyncRequestCallback( const cHttp& http, cHttp::Request& request, cHttp::Re EE_MAIN_FUNC int main (int argc, char * argv []) { { // Create a new HTTP client - cHttp http; + Http http; // We'll work on http://en.wikipedia.org - if ( cSSLSocket::IsSupported() ) { + if ( SSLSocket::IsSupported() ) { http.SetHost("https://en.wikipedia.org"); } else { http.SetHost("http://en.wikipedia.org"); } // Prepare a request to get the wikipedia main page - cHttp::Request request("/wiki/Main_Page"); + Http::Request request("/wiki/Main_Page"); // Send the request - cHttp::Response response = http.SendRequest(request); + Http::Response response = http.SendRequest(request); // Check the status code and display the result - cHttp::Response::Status status = response.GetStatus(); + Http::Response::Status status = response.GetStatus(); - if ( status == cHttp::Response::Ok ) { + if ( status == Http::Response::Ok ) { std::cout << response.GetBody() << std::endl; } else { std::cout << "Error " << status << std::endl; } - cHttp::Request asyncRequest( "/wiki/" + Version::GetCodename() ); + Http::Request asyncRequest( "/wiki/" + Version::GetCodename() ); http.SendAsyncRequest( cb::Make3( AsyncRequestCallback ), asyncRequest, Seconds( 5 ) ); }