poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_TcpServerOpts Class Reference

Options for creating a TCP server. More...

#include <poser/core/server.h>

Public Member Functions

PSC_TcpServerOptsPSC_TcpServerOpts_create (int port)
 PSC_TcpServerOpts constructor.
 
void PSC_TcpServerOpts_bind (PSC_TcpServerOpts *self, const char *bindhost)
 Bind to a specific hostname or address.
 
void PSC_TcpServerOpts_readBufSize (PSC_TcpServerOpts *self, size_t sz)
 Set read buffer size.
 
void PSC_TcpServerOpts_enableTls (PSC_TcpServerOpts *self, const char *certfile, const char *keyfile)
 Enable TLS for the server.
 
void PSC_TcpServerOpts_enableClientCert (PSC_TcpServerOpts *self, const char *cafile)
 Enable checking of an optional client certificate.
 
void PSC_TcpServerOpts_requireClientCert (PSC_TcpServerOpts *self, const char *cafile)
 Request a certificate from connecting clients.
 
void PSC_TcpServerOpts_validateClientCert (PSC_TcpServerOpts *self, void *receiver, PSC_CertValidator validator)
 Configure a custom validator for client certificates.
 
void PSC_TcpServerOpts_setProto (PSC_TcpServerOpts *self, PSC_Proto proto)
 Set a specific protocol (IPv4 or IPv6).
 
void PSC_TcpServerOpts_numericHosts (PSC_TcpServerOpts *self)
 Only use numeric hosts, don't attempt to resolve addresses.
 
void PSC_TcpServerOpts_destroy (PSC_TcpServerOpts *self)
 PSC_TcpServerOpts destructor.
 

Detailed Description

Options for creating a TCP server.

Member Function Documentation

◆ PSC_TcpServerOpts_bind()

void PSC_TcpServerOpts_bind ( PSC_TcpServerOpts self,
const char *  bindhost 
)

Bind to a specific hostname or address.

This can be called multiple times to bind to multiple names or addresses. If it isn't called at all, the server will listen on any interface/address.

Parameters
selfthe PSC_TcpServerOpts
bindhosthostname or address to bind to

◆ PSC_TcpServerOpts_create()

PSC_TcpServerOpts * PSC_TcpServerOpts_create ( int  port)

PSC_TcpServerOpts constructor.

Creates an options object initialized to default values.

Parameters
portthe port to listen on
Returns
a newly created options object

◆ PSC_TcpServerOpts_destroy()

void PSC_TcpServerOpts_destroy ( PSC_TcpServerOpts self)

PSC_TcpServerOpts destructor.

Parameters
selfthe PSC_TcpServerOpts

◆ PSC_TcpServerOpts_enableClientCert()

void PSC_TcpServerOpts_enableClientCert ( PSC_TcpServerOpts self,
const char *  cafile 
)

Enable checking of an optional client certificate.

If the client presents a client certificate, enable checking it. When a CA file is given, the certificate must be issued from one of the CAs contained in it. When the client presents a client certificate that doesn't validate, handshake fails.

If no CA file is given, any client certificate will fail validation unless a custom validation function is configured with PSC_TcpServerOpts_validateClientCert().

To strictly require a client certificate, use PSC_TcpServerOpts_requireClientCert() instead.

Parameters
selfthe PSC_TcpServerOpts
cafileCA file (containing PEM certificates)

◆ PSC_TcpServerOpts_enableTls()

void PSC_TcpServerOpts_enableTls ( PSC_TcpServerOpts self,
const char *  certfile,
const char *  keyfile 
)

Enable TLS for the server.

Causes TLS to be enabled for any incoming connection, using a server certificate. Note the certificate is required.

Parameters
selfthe PSC_TcpServerOpts
certfilecertificate file for the server certificate
keyfileprivate key file for the server certificate

◆ PSC_TcpServerOpts_numericHosts()

void PSC_TcpServerOpts_numericHosts ( PSC_TcpServerOpts self)

Only use numeric hosts, don't attempt to resolve addresses.

Parameters
selfthe PSC_TcpServerOpts

◆ PSC_TcpServerOpts_readBufSize()

void PSC_TcpServerOpts_readBufSize ( PSC_TcpServerOpts self,
size_t  sz 
)

Set read buffer size.

Sets the size of the buffer used for connections accepted from this server, in bytes. The default value is 16 kiB.

Parameters
selfthe PSC_TcpServerOpts
szthe size of the read buffer, must be > 0

◆ PSC_TcpServerOpts_requireClientCert()

void PSC_TcpServerOpts_requireClientCert ( PSC_TcpServerOpts self,
const char *  cafile 
)

Request a certificate from connecting clients.

Causes the server to request a client certificate from every connecting client. If the client doesn't present a certificate, or the certificate is not signed by a CA present in the given CA file, handshake fails.

If no CA file is given, any client certificate will fail validation unless a custom validation function is configured with PSC_TcpServerOpts_validateClientCert().

To optionally enable validation of a client certificate if presented, use PSC_TcpServerOpts_enableClientCert() instead.

Parameters
selfthe PSC_TcpServerOpts
cafileCA file (containing PEM certificates)

◆ PSC_TcpServerOpts_setProto()

void PSC_TcpServerOpts_setProto ( PSC_TcpServerOpts self,
PSC_Proto  proto 
)

Set a specific protocol (IPv4 or IPv6).

Parameters
selfthe PSC_TcpServerOpts
protoprotocol the server should use

◆ PSC_TcpServerOpts_validateClientCert()

void PSC_TcpServerOpts_validateClientCert ( PSC_TcpServerOpts self,
void *  receiver,
PSC_CertValidator  validator 
)

Configure a custom validator for client certificates.

When this is used, the given validator will be called after default validation of client certificates, so the application can still reject or accept certificates based on custom logic.

One of PSC_TcpServerOpts_enableClientCert() or PSC_TcpServerOpts_requireClientCert() must be called for this to have any effect. If a CA file is given there, this callback will only be called after successful validation against the CA file.

Parameters
selfthe PSC_TcpServerOpts
receiverthe object handling the validation (or 0 for static)
validatorthe custom validator function

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