Hobrasoft httpd server
Embedded HTTP server for Qt and C++
Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
HobrasoftHttpd::HttpTcpServer Class Reference

Listens for incoming TCP connections, supports plain and ssl connections. More...

#include <httptcpserver.h>

Inheritance diagram for HobrasoftHttpd::HttpTcpServer:

Public Member Functions

 HttpTcpServer (HttpServer *)
 Constructor creates the class instance.
 
bool verified (QTcpSocket *) const
 Returns true if the peer's certificate is valid and signed with server's CA certificate.
 
QSslCertificate peerCertificate (QTcpSocket *) const
 Returns peer's certificate.
 

Private Slots

void slotEncrypted ()
 Slot is invoked when the SSL hanshake is complete and connection is established. More...
 
void slotSslErrors (const QList< QSslError > &)
 Slot is called when an SSL error occured.
 
void slotPeerVerifyError (const QSslError &)
 Slot is called when the peer's certificate is not verified.
 
void slotDisconnected ()
 Slot is invoked when the socket disconnets. More...
 

Private Member Functions

void incomingConnection (QINTPTR socketDescriptor)
 Method is invoked when incoming connection arrived. More...
 

Private Attributes

const HttpSettingsm_settings
 
QHash< QTcpSocket *, bool > m_verified
 Verified status of each socket.
 
QHash< QTcpSocket *, QSslCertificate > m_peerCert
 Peer's certificate of each socket.
 

Detailed Description

Listens for incoming TCP connections, supports plain and ssl connections.

Class stores information of each connection - its verification status and peer's certificate.

Definition at line 32 of file httptcpserver.h.

Member Function Documentation

◆ incomingConnection()

void HttpTcpServer::incomingConnection ( QINTPTR  socketDescriptor)
private

Method is invoked when incoming connection arrived.

Overwrites QTctpServer::incomingConnection()

If no SSL is used then the original QTcpServer::incomingConnection() is called.

If SSL is on then the original QTcpServer::incomingConnection() is unuseable and SSL must be initialized.

Signals of the QSslSocket are connected to slots to watch for SSL errors: slotSslErrors() and slotPeerVerifyError().. When the SSL handshake is complete and the connection is encrypted() then the slotEncrypted() is called and signal newConnection() is emited from that slot.

FIX: this code should load all certificates in the chain not only the first one.

Sets the private key, local certificate and CA certificates chain to the QSslSocket.

Definition at line 31 of file httptcpserver.cpp.

◆ slotDisconnected

void HttpTcpServer::slotDisconnected ( )
privateslot

Slot is invoked when the socket disconnets.

Removes socket verified status and peer's certificate from inner containers.

Definition at line 96 of file httptcpserver.cpp.

◆ slotEncrypted

void HttpTcpServer::slotEncrypted ( )
privateslot

Slot is invoked when the SSL hanshake is complete and connection is established.

Each socket and its peer's certificate is registered in m_peerCert. Then newConnectio() signal is emited.

Compilation is different in various version of Qt. In earlier Qt versions prior to 4.7 the QSslSocket missed the addPendingConnection() method. I'm not sure if the ssl works properly in older Qt versions.

Definition at line 113 of file httptcpserver.cpp.


The documentation for this class was generated from the following files: