# ifndef CLIENTCONNECTION_HH # define CLIENTCONNECTION_HH # include # include # include # include # include # include # include "baseconnection.hh" class ClientConnection : public BaseConnection { Q_OBJECT public: /** * Explicit default constructor. */ explicit ClientConnection ( void ); /** * Virtual destructor. */ virtual ~ClientConnection ( void ) override; /** * Member function used to get access to the connection socket to send information. * * @returns Shared pointer to the connection socket being used. */ QSharedPointer< QSslSocket > connectionSocket ( void ) const; /** * Public virtual override member function used to drop the connection to the client if there * was an error or problem in general. This membert function emits the * "disconnectedFromClient" signal. */ virtual void disconnectFromClient ( void ) override; /** * Member function used to get the assigned ID to this client. * * @returns ID of the client assigned during identification. */ qint32 id ( void ) const; /** * Member function used to ask if this client is still connected. * * @returns "true" if the connection is still there, "false" if not. */ bool isConnected ( void ) const; /** * Member function used to ask for the pending messages, if any. * * @returns A copy of the messages left to be processes. */ QSharedPointer< QList< QByteArray > > pendingMessages ( void ) const; /** * Member function used to set the pointer to the connection socket used for this client. * * @param[in] pConnectionSocket Pointer to the QSslSocket connection. */ virtual void setConnectionSocket ( QSharedPointer< QSslSocket > pConnectionSocket ); /** * Member function used to set the ID considered during identification. * * @param[in] pNewID ID to set to this client. */ void setID ( const qint32& pNewID ); signals: /** * Signal raised when there is at least one new message to be processed by either MyApplication or the * Plugin controllers. */ void newMessagesReady ( void ); /** * Signal raised when the connection has been identified as a Plugin instance. * * @param[in] pConnectionID ID of this pending connection instance. */ void newPluginConnection ( const qint32& pConnectionID ); /** * Signal raised when the connection has been identified as a MyApplication instance. * * @param[in] pConnectionID ID of this pending connection instance. */ void newMyApplicationConnection ( const qint32& pConnectionID ); private slots: /** * Private slot used to detect when the connection socket is ready for reading. */ void onReadyRead ( void ); /** * Protected slot used to detect when a connection detects an SSL alert. * * @param[in] pLevel Level of priority of the error. * @param[in] pType Type of the error generated. * @param[in] pDescription Description of the error generated, according to Qt. */ void onSocketAlertReceived ( QSsl::AlertLevel pLevel , QSsl::AlertType pType , const QString& pDescription ); /** * Protected slot used to detect when a connection detects an SSL alert that has been sent. * * @param[in] pLevel Level of priority of the error. * @param[in] pType Type of the error generated. * @param[in] pDescription Description of the error generated, according to Qt. */ void onSocketAlertSent ( QSsl::AlertLevel pLevel , QSsl::AlertType pType , const QString& pDescription ); /** * Protected slot used to detect when a connection status has changed. The most common problem * is the client being disconnected. * * @param[in] pSocketError Error detected on the connection. */ void onSocketConnectionError ( QAbstractSocket::SocketError pSocketError ); /** * Protected slot used to detect when the socket has become encrypted. */ void onSocketEncrypted ( void ); /** * Protected slot used to detect when encrypted bytes have been writen to the connection. * * @param[in] pBytesWritten Amount of bytes writen. */ void onSocketEncryptedBytesWritten ( qint64 pBytesWritten ); /** * Protected slot used to detect when the handshake has been halted due to an error. * * @param[in] pError Error detected. */ void onSocketHandshakeInterruptedOnError ( const QSslError& pError ); /** * Protected slot used to detect when a connection mode has changed. * * @param[in] pMode New connection mode. */ void onSocketModeChanged ( QSslSocket::SslMode pMode ); /** * Protected slot used to detect when a new session ticket has been received. */ void onSocketNewSessionTicketReceived ( void ); /** * Protected slot used to detect when the Peer Verify operation has encountered an error. * * @param[in] pError Error detected. */ void onSocketPeerVerifyError ( const QSslError& pError ); /** * Protected slot used to detect when the Pre Shared Key Authentication is required. * * @param[in] pAuthenticator Pointer to the authenticator to use. */ void onSocketPreSharedKeyAuthenticationRequired ( QSslPreSharedKeyAuthenticator* pAuthenticator ); /** * Protected slot used to detect SSL errors. * * @param[in] pSslErrors Socket SSL errors identified. */ void onSocketSslErrors ( const QList< QSslError >& pSslErrors ); /** * Protected slot used to detect when a connection is lost from a client. The most common * operation is to disconnect. */ void onValidateConnectionLost ( void ); private: /** * Private member function used to try to identify the message considered. * * @param[in] pMessage Message buffer to be parsed. * @param[out] pIdentificationType Kind of Product being identified, either nothing (0), * MyApplication (1) or PLUGIN (2) * * @returns True if the message is identified as an identification, either from MyApplication or a * Plugin. False if not. */ bool isMessageIdentificationMessage ( const QByteArray& pMessage , unsigned int& pIdentificationType ); /** * Private member function used to parse the incomming message and validate it. * * @param[in] pMessage Message to parse. */ void parseMessage ( const QByteArray& pMessage ); private: QSharedPointer< QSslSocket > mConnectionSocket; /**< Pointer to the socket used for connections. */ QSharedPointer< QList< QByteArray > > mPendingMessages; /**< Pointer to the remaining messages to parse and validate. */ bool mConnectionAlreadyIdentified; /**< Flag used to remember if the current connection has already been identified. */ qint32 mID; /**< ID of the client. Assigned during identification. */ QByteArray mInputBuffer; /**< Input buffer array for the incomming messages. */ }; # endif // CLIENTCONNECTION_HH