SOUND4 BIGVOICE.CL Library [1.1.7]
Loading...
Searching...
No Matches
Macros | Functions
Web server

Web server configuring. More...

Macros

#define SOUND4_INVALID_WEBSERVER_ID   ((uint64_t)-1)
 
#define SOUND4_WEBSERVER_HTTP_OK   (1<<0)
 
#define SOUND4_WEBSERVER_HTTPS_OK   (1<<1)
 

Functions

uint64_t bigvoice_Webserver_tcp (unsigned int listenport, unsigned int listenport_secure, const char *socket_ip, unsigned int socket_port)
 
uint64_t bigvoice_Webserver_tcp2 (unsigned int listenport, unsigned int listenport_secure, const char *socket_ip, unsigned int socket_port, const struct bigvoice_CParameters *parameters)
 
uint64_t bigvoice_Webserver (unsigned int listenport, unsigned int listenport_secure, struct bigvoice_CInstance *instance)
 
int bigvoice_Webserver_Stop (uint64_t id, int timeout_ms)
 
int bigvoice_Webserver_Status (uint64_t id)
 
void bigvoice_Webserver_SetAppHealth (struct bigvoice_CInstance *instance, int httpcode, const char *contenttype, const char *content)
 
void bigvoice_Webserver_GetAppHealth (struct bigvoice_CInstance *instance, int *httpcode, char **contenttype, char **content)
 
void bigvoice_Webserver_FreeString (char *str)
 

Detailed Description

Run a web server to configure the processor

The web server also expose /health which should always answer 200.

The web server also expose /licvalid which should answer 200 when license is valid, 402 when it is not valid, other standard code for other errors.

See also how to setup authentication with Environment variables and parameters. Their use is documented in bigvoice_InitProcess3.

Macro Definition Documentation

◆ SOUND4_INVALID_WEBSERVER_ID

#define SOUND4_INVALID_WEBSERVER_ID   ((uint64_t)-1)

This represents an invalid webserver id bigvoice_Webserver and bigvoice_Webserver_tcp will never return this value

Definition at line 1199 of file sound4.bigvoice.cl.h.

◆ SOUND4_WEBSERVER_HTTP_OK

#define SOUND4_WEBSERVER_HTTP_OK   (1<<0)

If this bit is set in the return value from bigvoice_Webserver_Status, then HTTP server is OK

Definition at line 1204 of file sound4.bigvoice.cl.h.

◆ SOUND4_WEBSERVER_HTTPS_OK

#define SOUND4_WEBSERVER_HTTPS_OK   (1<<1)

If this bit is set in the return value from bigvoice_Webserver_Status, then HTTPS server is OK

Definition at line 1208 of file sound4.bigvoice.cl.h.

Function Documentation

◆ bigvoice_Webserver()

uint64_t bigvoice_Webserver ( unsigned int  listenport,
unsigned int  listenport_secure,
struct bigvoice_CInstance instance 
)

Run a web server, connecting to local instance internally (no expose port needed)

This function returns after connecting to the process, and continue to run in background See bigvoice_Webserver_Stop too stop it gracefully

For secure connection, it will use privatekey.pem and certificate.pem from current directory. Environment variables SSL_PRIVATE_PATH and SSL_CERTIFICATE_PATH can override those (see Environment variables and parameters). If none is valid, it will try also /etc/ssl/certs/server.key and /etc/ssl/certs/server.crt.

Warning
On Windows, calling this from Go<1.20 code will crash.
Parameters
listenportThe port to listen for HTTP connections (0 to disable)
listenport_secureThe port to listen for HTTPS connections (0 to disable)
instanceThe process instance to connect to
Returns
id of webserver (starting at 0), to use with bigvoice_Webserver_Stop

◆ bigvoice_Webserver_FreeString()

void bigvoice_Webserver_FreeString ( char *  str)

Free a a string returned by bigvoice_Webserver_GetAppHealth

Parameters
strthe string to free

◆ bigvoice_Webserver_GetAppHealth()

void bigvoice_Webserver_GetAppHealth ( struct bigvoice_CInstance instance,
int *  httpcode,
char **  contenttype,
char **  content 
)

Get the current web server /apphealth returned http code,content-type and content

Parameters
instanceThe process instance
httpcodeThe http code pointer
contenttypeThe http Content-Type header pointer (to be freed with bigvoice_Webserver_FreeString)
contentThe http body content pointer (to be freed with bigvoice_Webserver_FreeString)

◆ bigvoice_Webserver_SetAppHealth()

void bigvoice_Webserver_SetAppHealth ( struct bigvoice_CInstance instance,
int  httpcode,
const char *  contenttype,
const char *  content 
)

Set the web server /apphealth status info

The hosting application can use this to customize the handling of /apphealth path.

Parameters
instanceThe process instance
httpcodeThe http code
contenttypeThe http Content-Type header
contentThe http body content

◆ bigvoice_Webserver_Status()

int bigvoice_Webserver_Status ( uint64_t  id)

Get the web server status

Warning
On Windows, calling this from Go<1.20 code will crash.
Parameters
idThe web server Id, returned by bigvoice_Webserver_tcp or bigvoice_Webserver
Returns
a combinaison of SOUND4_WEBSERVER_HTTP_OK and SOUND4_WEBSERVER_HTTPS_OK depending on the server status

◆ bigvoice_Webserver_Stop()

int bigvoice_Webserver_Stop ( uint64_t  id,
int  timeout_ms 
)

Stop a web server started with bigvoice_Webserver_tcp

Warning
On Windows, calling this from Go<1.20 code will crash.
Parameters
idThe web server Id, returned by bigvoice_Webserver_tcp or bigvoice_Webserver
timeout_msThe timeout to wait gracefull shutdown
Returns
0 if succeed, -1 if the id is not found

◆ bigvoice_Webserver_tcp()

uint64_t bigvoice_Webserver_tcp ( unsigned int  listenport,
unsigned int  listenport_secure,
const char *  socket_ip,
unsigned int  socket_port 
)

Run a web server, connecting to process with JSON over TCP

Same as bigvoice_Webserver_tcp2, but with default parameters (from env)

Deprecated:
Use bigvoice_Webserver_tcp2

◆ bigvoice_Webserver_tcp2()

uint64_t bigvoice_Webserver_tcp2 ( unsigned int  listenport,
unsigned int  listenport_secure,
const char *  socket_ip,
unsigned int  socket_port,
const struct bigvoice_CParameters parameters 
)

Run a web server, connecting to process with JSON over TCP, using parameters

This function returns after connecting to the process, and continue to run in background See bigvoice_Webserver_Stop too stop it gracefully

For secure connection, it will use privatekey.pem and certificate.pem from current directory. Environment variables SSL_PRIVATE_PATH and SSL_CERTIFICATE_PATH can override those (see Environment variables and parameters). If none is valid, it will try also /etc/ssl/certs/server.key and /etc/ssl/certs/server.crt.

Warning
On Windows, calling this from Go<1.20 code will crash.
Parameters
listenportThe port to listen for HTTP connections
listenport_secureThe port to listen for HTTPS connections
socket_ipThe ip of the process to connect to
socket_portThe port of the process's JSON server to connect to
parametersThe parameters to use, created with bigvoice_NewParameters
Returns
id of webserver (starting at 0), to use with bigvoice_Webserver_Stop