poser
A C framework for POsix SERvices
|
Options for creating a TCP server. More...
#include <poser/core/server.h>
Public Member Functions | |
PSC_TcpServerOpts * | PSC_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. | |
Options for creating a TCP server.
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.
self | the PSC_TcpServerOpts |
bindhost | hostname or address to bind to |
PSC_TcpServerOpts * PSC_TcpServerOpts_create | ( | int | port | ) |
PSC_TcpServerOpts constructor.
Creates an options object initialized to default values.
port | the port to listen on |
void PSC_TcpServerOpts_destroy | ( | PSC_TcpServerOpts * | self | ) |
PSC_TcpServerOpts destructor.
self | the PSC_TcpServerOpts |
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.
self | the PSC_TcpServerOpts |
cafile | CA file (containing PEM certificates) |
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.
self | the PSC_TcpServerOpts |
certfile | certificate file for the server certificate |
keyfile | private key file for the server certificate |
void PSC_TcpServerOpts_numericHosts | ( | PSC_TcpServerOpts * | self | ) |
Only use numeric hosts, don't attempt to resolve addresses.
self | the PSC_TcpServerOpts |
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.
self | the PSC_TcpServerOpts |
sz | the size of the read buffer, must be > 0 |
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.
self | the PSC_TcpServerOpts |
cafile | CA file (containing PEM certificates) |
void PSC_TcpServerOpts_setProto | ( | PSC_TcpServerOpts * | self, |
PSC_Proto | proto | ||
) |
Set a specific protocol (IPv4 or IPv6).
self | the PSC_TcpServerOpts |
proto | protocol the server should use |
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.
self | the PSC_TcpServerOpts |
receiver | the object handling the validation (or 0 for static) |
validator | the custom validator function |