#ifndef Server_H #define Server_H #include #include "Network.h" #ifndef HEADER_OPENSSL_TYPES_H struct ssl_ctx_st; struct ssl_st; #endif namespace Framework { namespace Encryption { class Key; } class Text; } // namespace Framework using namespace Framework; namespace Network { class Server; // from this file class SClient; // from this file class Server : public virtual ReferenceCounter { private: SOCKET sock; SOCKADDR_IN address; int clients; public: // Constructor __declspec(dllexport) Server(); // Destructor __declspec(dllexport) ~Server(); // non-constant __declspec(dllexport) bool connect( unsigned short port, int queueLength); // Opens the socket __declspec(dllexport) SClient* getClient(); // accepts a client __declspec(dllexport) int getClients( bool reset); // returns the number of clients __declspec(dllexport) bool disconnect(); // stops the server // constant __declspec( dllexport) unsigned short getPort() const; // returns the port __declspec(dllexport) bool isConnected() const; // returns 1 if the server is connected }; class SClient : public EncryptedConnection, public virtual ReferenceCounter { private: SOCKET sock; sockaddr_in clientAddr; Encryption::Key* sendKey; Encryption::Key* receiveKey; int downStreamBytes; int upStreamBytes; public: // Constructor __declspec(dllexport) SClient(sockaddr_in client, SOCKET sock); // Destructor __declspec(dllexport) ~SClient(); // non-constant __declspec(dllexport) void setReceiveTimeout( int miliseconds); // Sets a timeout for receiving data __declspec(dllexport) void setSendKeyZ( Encryption::Key* key); // Sets the key for sending __declspec(dllexport) void setReceiveKeyZ( Encryption::Key* key); // Sets the key for receiving __declspec(dllexport) void setSendKey( const char* key, int len); // Sets the key for sending __declspec(dllexport) void setReceiveKey( const char* key, int len); // Sets the key for receiving __declspec(dllexport) bool send( const char* message, int len) override; // sends to client __declspec(dllexport) bool getMessage( char* message, int len) override; // receives message from client __declspec(dllexport) bool sendEncrypted( const char* message, int len) override; // sends to server __declspec(dllexport) bool getMessageEncrypted( char* message, int len) override; // receives message __declspec(dllexport) int getDownloadBytes( bool reset); // returns the number of received bytes __declspec(dllexport) int getUploadBytes( bool reset); // returns the number of sent bytes __declspec(dllexport) bool disconnect(); // disconnects from client // constant __declspec(dllexport) bool hasMessage( int time) const; // Waits for a message for a given time __declspec( dllexport) unsigned short getPort() const; // returns the port __declspec(dllexport) const char* getIp() const; // returns the client's IP __declspec(dllexport) bool waitForNextMessage() const; // waits until there is something to receive }; class SSLSClient; class SSLServer : public virtual ReferenceCounter { private: SOCKET s; SOCKADDR_IN addr; ssl_ctx_st* ctx; Text* password; int clients; public: // Constructor __declspec(dllexport) SSLServer(); // Destructor __declspec(dllexport) ~SSLServer(); // non-constant // Sets the path to the file where the certificate is stored __declspec(dllexport) bool setCertificateFile(const char* file); // Sets the path to the file where the private key is stored __declspec(dllexport) bool setPrivateKeyFile(const char* file); // sets the password of the private key (must be called before // setPrivateKeyFile) __declspec(dllexport) void setPrivateKeyPassword(const char* password); // Opens the socket __declspec(dllexport) bool connect( unsigned short port, int queueLength); // accepts a client __declspec(dllexport) SSLSClient* getClient(); // returns the number of clients __declspec(dllexport) int getClients(bool reset); // stops the server __declspec(dllexport) bool disconnect(); // constant // returns the port __declspec(dllexport) unsigned short getPort() const; // returns 1 if the server is connected __declspec(dllexport) bool isConnected() const; }; class SSLSClient : public Connection, public virtual ReferenceCounter { private: SOCKET s; ssl_st* ssl; sockaddr_in clientAddr; int downStreamBytes; int upStreamBytes; public: // Constructor __declspec(dllexport) SSLSClient(sockaddr_in client, ssl_st* ssl, SOCKET s); // Destructor __declspec(dllexport) ~SSLSClient(); // non-constant __declspec(dllexport) void setReceiveTimeout( int miliseconds); // Sets a timeout for receiving data __declspec(dllexport) bool send( const char* message, int len) override; // sends to client __declspec(dllexport) bool getMessage( char* message, int len) override; // receives message from client __declspec(dllexport) int getDownloadBytes( bool reset); // returns the number of received bytes __declspec(dllexport) int getUploadBytes( bool reset); // returns the number of sent bytes __declspec(dllexport) bool disconnect(); // disconnects from client // constant __declspec(dllexport) bool hasMessage( int time) const; // Waits for a message for a given time __declspec( dllexport) unsigned short getPort() const; // returns the port __declspec(dllexport) const char* getIp() const; // returns the client's IP }; } // namespace Network #endif