Sagui library v3.5.0
Cross-platform library which helps to develop web servers or frameworks.
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
HTTP server

Data Structures

struct  sg_httpauth
 
struct  sg_httpupld
 
struct  sg_httpreq
 
struct  sg_httpres
 
struct  sg_httpsrv
 

Macros

#define sg_httpres_send(res, val, content_type, status)
 
#define sg_httpres_download(res, filename, status)    sg_httpres_sendfile2((res), 0, 0, 0, (filename), "attachment", (status))
 
#define sg_httpres_render(res, filename, status)    sg_httpres_sendfile2((res), 0, 0, 0, (filename), "inline", (status))
 
#define sg_httpres_zsend(res, val, content_type, status)
 
#define sg_httpres_zdownload(res, filename, status)    sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "attachment", (status))
 
#define sg_httpres_zrender(res, filename, status)    sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "inline", (status))
 

Typedefs

typedef void(* sg_httpsrv_cli_cb) (void *cls, const void *client, bool *closed)
 
typedef bool(* sg_httpauth_cb) (void *cls, struct sg_httpauth *auth, struct sg_httpreq *req, struct sg_httpres *res)
 
typedef int(* sg_httpupld_cb) (void *cls, void **handle, const char *dir, const char *field, const char *name, const char *mime, const char *encoding)
 
typedef int(* sg_httpuplds_iter_cb) (void *cls, struct sg_httpupld *upld)
 
typedef void(* sg_httpreq_cb) (void *cls, struct sg_httpreq *req, struct sg_httpres *res)
 

Functions

int sg_httpauth_set_realm (struct sg_httpauth *auth, const char *realm)
 
const char * sg_httpauth_realm (struct sg_httpauth *auth)
 
int sg_httpauth_deny2 (struct sg_httpauth *auth, const char *reason, const char *content_type, unsigned int status)
 
int sg_httpauth_deny (struct sg_httpauth *auth, const char *reason, const char *content_type)
 
int sg_httpauth_cancel (struct sg_httpauth *auth)
 
const char * sg_httpauth_usr (struct sg_httpauth *auth)
 
const char * sg_httpauth_pwd (struct sg_httpauth *auth)
 
int sg_httpuplds_iter (struct sg_httpupld *uplds, sg_httpuplds_iter_cb cb, void *cls)
 
int sg_httpuplds_next (struct sg_httpupld **upld)
 
unsigned int sg_httpuplds_count (struct sg_httpupld *uplds)
 
void * sg_httpupld_handle (struct sg_httpupld *upld)
 
const char * sg_httpupld_dir (struct sg_httpupld *upld)
 
const char * sg_httpupld_field (struct sg_httpupld *upld)
 
const char * sg_httpupld_name (struct sg_httpupld *upld)
 
const char * sg_httpupld_mime (struct sg_httpupld *upld)
 
const char * sg_httpupld_encoding (struct sg_httpupld *upld)
 
uint64_t sg_httpupld_size (struct sg_httpupld *upld)
 
int sg_httpupld_save (struct sg_httpupld *upld, bool overwritten)
 
int sg_httpupld_save_as (struct sg_httpupld *upld, const char *path, bool overwritten)
 
struct sg_httpsrvsg_httpreq_srv (struct sg_httpreq *req)
 
struct sg_strmap ** sg_httpreq_headers (struct sg_httpreq *req)
 
struct sg_strmap ** sg_httpreq_cookies (struct sg_httpreq *req)
 
struct sg_strmap ** sg_httpreq_params (struct sg_httpreq *req)
 
struct sg_strmap ** sg_httpreq_fields (struct sg_httpreq *req)
 
const char * sg_httpreq_version (struct sg_httpreq *req)
 
const char * sg_httpreq_method (struct sg_httpreq *req)
 
const char * sg_httpreq_path (struct sg_httpreq *req)
 
struct sg_strsg_httpreq_payload (struct sg_httpreq *req)
 
bool sg_httpreq_is_uploading (struct sg_httpreq *req)
 
struct sg_httpupldsg_httpreq_uploads (struct sg_httpreq *req)
 
const void * sg_httpreq_client (struct sg_httpreq *req)
 
void * sg_httpreq_tls_session (struct sg_httpreq *req)
 
int sg_httpreq_isolate (struct sg_httpreq *req, sg_httpreq_cb cb, void *cls)
 
int sg_httpreq_set_user_data (struct sg_httpreq *req, void *data)
 
void * sg_httpreq_user_data (struct sg_httpreq *req)
 
struct sg_strmap ** sg_httpres_headers (struct sg_httpres *res)
 
int sg_httpres_set_cookie (struct sg_httpres *res, const char *name, const char *val)
 
int sg_httpres_sendbinary (struct sg_httpres *res, void *buf, size_t size, const char *content_type, unsigned int status)
 
int sg_httpres_sendfile2 (struct sg_httpres *res, uint64_t size, uint64_t max_size, uint64_t offset, const char *filename, const char *disposition, unsigned int status)
 
int sg_httpres_sendfile (struct sg_httpres *res, uint64_t size, uint64_t max_size, uint64_t offset, const char *filename, bool downloaded, unsigned int status)
 
int sg_httpres_sendstream (struct sg_httpres *res, uint64_t size, sg_read_cb read_cb, void *handle, sg_free_cb free_cb, unsigned int status)
 
int sg_httpres_zsendbinary2 (struct sg_httpres *res, int level, void *buf, size_t size, const char *content_type, unsigned int status)
 
int sg_httpres_zsendbinary (struct sg_httpres *res, void *buf, size_t size, const char *content_type, unsigned int status)
 
int sg_httpres_zsendstream2 (struct sg_httpres *res, int level, uint64_t size, sg_read_cb read_cb, void *handle, sg_free_cb free_cb, unsigned int status)
 
int sg_httpres_zsendstream (struct sg_httpres *res, sg_read_cb read_cb, void *handle, sg_free_cb free_cb, unsigned int status)
 
int sg_httpres_zsendfile2 (struct sg_httpres *res, int level, uint64_t size, uint64_t max_size, uint64_t offset, const char *filename, const char *disposition, unsigned int status)
 
int sg_httpres_zsendfile (struct sg_httpres *res, uint64_t size, uint64_t max_size, uint64_t offset, const char *filename, bool downloaded, unsigned int status)
 
int sg_httpres_reset (struct sg_httpres *res)
 
int sg_httpres_clear (struct sg_httpres *res)
 
bool sg_httpres_is_empty (struct sg_httpres *res)
 
struct sg_httpsrvsg_httpsrv_new2 (sg_httpauth_cb auth_cb, sg_httpreq_cb req_cb, sg_err_cb err_cb, void *cls) __attribute__((malloc))
 
struct sg_httpsrvsg_httpsrv_new (sg_httpreq_cb cb, void *cls) __attribute__((malloc))
 
void sg_httpsrv_free (struct sg_httpsrv *srv)
 
bool sg_httpsrv_tls_listen4 (struct sg_httpsrv *srv, const char *key, const char *pwd, const char *cert, const char *trust, const char *dhparams, const char *priorities, const char *hostname, uint16_t port, uint32_t backlog, bool threaded)
 
bool sg_httpsrv_tls_listen3 (struct sg_httpsrv *srv, const char *key, const char *pwd, const char *cert, const char *trust, const char *dhparams, const char *priorities, uint16_t port, bool threaded)
 
bool sg_httpsrv_tls_listen2 (struct sg_httpsrv *srv, const char *key, const char *pwd, const char *cert, const char *trust, const char *dhparams, uint16_t port, bool threaded)
 
bool sg_httpsrv_tls_listen (struct sg_httpsrv *srv, const char *key, const char *cert, uint16_t port, bool threaded)
 
bool sg_httpsrv_listen2 (struct sg_httpsrv *srv, const char *hostname, uint16_t port, uint32_t backlog, bool threaded)
 
bool sg_httpsrv_listen (struct sg_httpsrv *srv, uint16_t port, bool threaded)
 
int sg_httpsrv_shutdown (struct sg_httpsrv *srv)
 
uint16_t sg_httpsrv_port (struct sg_httpsrv *srv)
 
bool sg_httpsrv_is_threaded (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_cli_cb (struct sg_httpsrv *srv, sg_httpsrv_cli_cb cb, void *cls)
 
int sg_httpsrv_set_upld_cbs (struct sg_httpsrv *srv, sg_httpupld_cb cb, void *cls, sg_write_cb write_cb, sg_free_cb free_cb, sg_save_cb save_cb, sg_save_as_cb save_as_cb)
 
int sg_httpsrv_set_upld_dir (struct sg_httpsrv *srv, const char *dir)
 
const char * sg_httpsrv_upld_dir (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_post_buf_size (struct sg_httpsrv *srv, size_t size)
 
size_t sg_httpsrv_post_buf_size (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_payld_limit (struct sg_httpsrv *srv, size_t limit)
 
size_t sg_httpsrv_payld_limit (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_uplds_limit (struct sg_httpsrv *srv, uint64_t limit)
 
uint64_t sg_httpsrv_uplds_limit (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_thr_pool_size (struct sg_httpsrv *srv, unsigned int size)
 
unsigned int sg_httpsrv_thr_pool_size (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_con_timeout (struct sg_httpsrv *srv, unsigned int timeout)
 
unsigned int sg_httpsrv_con_timeout (struct sg_httpsrv *srv)
 
int sg_httpsrv_set_con_limit (struct sg_httpsrv *srv, unsigned int limit)
 
unsigned int sg_httpsrv_con_limit (struct sg_httpsrv *srv)
 
void * sg_httpsrv_handle (struct sg_httpsrv *srv)
 

Detailed Description

Fast event-driven HTTP server.

Macro Definition Documentation

◆ sg_httpres_send

#define sg_httpres_send (   res,
  val,
  content_type,
  status 
)
Value:
sg_httpres_sendbinary((res), (void *) (val), \
(((val) != NULL) ? strlen((val)) : 0), (content_type), \
(status))
int sg_httpres_sendbinary(struct sg_httpres *res, void *buf, size_t size, const char *content_type, unsigned int status)

Sends a null-terminated string content to the client.

Parameters
[in]resResponse handle.
[in]valNull-terminated string.
[in]content_typeContent type.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
ENOMEMOut of memory.
Examples
example_httpauth.c, example_httpcookie.c, example_httpreq_form.c, example_httpreq_isolate.c, example_httpreq_payload.c, example_httpsrv.c, example_httpsrv_benchmark.c, example_httpsrv_sse.c, example_httpsrv_tls.c, example_httpsrv_tls_cert_auth.c, example_httpuplds.c, and example_router_srv.c.

◆ sg_httpres_download

#define sg_httpres_download (   res,
  filename,
  status 
)     sg_httpres_sendfile2((res), 0, 0, 0, (filename), "attachment", (status))

Offers a file as download.

Parameters
[in]resResponse handle.
[in]filenamePath of the file to be sent.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
ENOMEMOut of memory.
Examples
example_httpuplds.c.

◆ sg_httpres_render

#define sg_httpres_render (   res,
  filename,
  status 
)     sg_httpres_sendfile2((res), 0, 0, 0, (filename), "inline", (status))

Sends a file to be rendered.

Parameters
[in]resResponse handle.
[in]filenamePath of the file to be sent.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
ENOMEMOut of memory.

◆ sg_httpres_zsend

#define sg_httpres_zsend (   res,
  val,
  content_type,
  status 
)
Value:
sg_httpres_zsendbinary((res), (void *) (val), \
(((val) != NULL) ? strlen((val)) : 0), \
(content_type), (status))
int sg_httpres_zsendbinary(struct sg_httpres *res, void *buf, size_t size, const char *content_type, unsigned int status)

Compresses a null-terminated string content and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]valNull-terminated string.
[in]content_typeContent type.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
ENOBUFSNo buffer space available.
EALREADYOperation already in progress.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: deflate is automatically added to the response.

◆ sg_httpres_zdownload

#define sg_httpres_zdownload (   res,
  filename,
  status 
)     sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "attachment", (status))

Compresses a file in Gzip format and offers it as download. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]filenamePath of the file to be compressed and sent.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
ENOMEMOut of memory.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: gzip is automatically added to the response.

◆ sg_httpres_zrender

#define sg_httpres_zrender (   res,
  filename,
  status 
)     sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "inline", (status))

Compresses a file in Gzip format and sends it to be rendered. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]filenamePath of the file to be sent.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
ENOMEMOut of memory.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: gzip is automatically added to the response.

Typedef Documentation

◆ sg_httpsrv_cli_cb

typedef void(* sg_httpsrv_cli_cb) (void *cls, const void *client, bool *closed)

Callback signature used to handle client connection events.

Parameters
[out]clsUser-defined closure.
[out]clientSocket handle of the client.
[in,out]closedIndicates if the client is connected allowing to close it.

◆ sg_httpauth_cb

typedef bool(* sg_httpauth_cb) (void *cls, struct sg_httpauth *auth, struct sg_httpreq *req, struct sg_httpres *res)

Callback signature used to grant or deny the user access to the server resources.

Parameters
[out]clsUser-defined closure.
[out]authAuthentication handle.
[out]reqRequest handle.
[out]resResponse handle.
Return values
trueGrants the user access.
falseDenies the user access.

◆ sg_httpupld_cb

typedef int(* sg_httpupld_cb) (void *cls, void **handle, const char *dir, const char *field, const char *name, const char *mime, const char *encoding)

Callback signature used to handle uploaded files and/or fields.

Parameters
[out]clsUser-defined closure.
[in,out]handleStream handle pointer.
[out]dirDirectory to store the uploaded files.
[out]fieldPosted field.
[out]nameUploaded file name.
[out]mimeUploaded file content-type (e.g.: text/plain, image/png, application/json etc.).
[out]encodingUploaded file transfer-encoding (e.g.: chunked, deflate, gzip etc.).
Return values
0Success.
E<ERROR>User-defined error to refuse the upload.

◆ sg_httpuplds_iter_cb

typedef int(* sg_httpuplds_iter_cb) (void *cls, struct sg_httpupld *upld)

Callback signature used to iterate uploaded files.

Parameters
[out]clsUser-defined closure.
[out]upldCurrent upload item.
Return values
0Success.
E<ERROR>User-defined error to stop list iteration.

◆ sg_httpreq_cb

typedef void(* sg_httpreq_cb) (void *cls, struct sg_httpreq *req, struct sg_httpres *res)

Callback signature used to handle requests and responses.

Parameters
[out]clsUser-defined closure.
[out]reqRequest handle.
[out]resResponse handle.

Function Documentation

◆ sg_httpauth_set_realm()

int sg_httpauth_set_realm ( struct sg_httpauth auth,
const char *  realm 
)

Sets the authentication protection space (realm).

Parameters
[in]authAuthentication handle.
[in]realmRealm string.
Return values
0Success.
EINVALInvalid argument.
EALREADYRealm already set.
ENOMEMOut of memory.
Examples
example_httpauth.c.

◆ sg_httpauth_realm()

const char * sg_httpauth_realm ( struct sg_httpauth auth)

Gets the authentication protection space (realm).

Parameters
[in]authAuthentication handle.
Returns
Realm as a null-terminated string.
Return values
NULLIf auth is null and set the errno to EINVAL.

◆ sg_httpauth_deny2()

int sg_httpauth_deny2 ( struct sg_httpauth auth,
const char *  reason,
const char *  content_type,
unsigned int  status 
)

Deny the authentication sending the reason to the user.

Parameters
[in]authAuthentication handle.
[in]reasonDenial reason.
[in]content_typeContent type.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYAlready denied.
ENOMEMOut of memory.

◆ sg_httpauth_deny()

int sg_httpauth_deny ( struct sg_httpauth auth,
const char *  reason,
const char *  content_type 
)

Deny the authentication sending the reason to the user.

Parameters
[in]authAuthentication handle.
[in]reasonDenial reason.
[in]content_typeContent type.
Return values
0Success.
EINVALInvalid argument.
EALREADYAlready denied.
ENOMEMOut of memory.
Examples
example_httpauth.c.

◆ sg_httpauth_cancel()

int sg_httpauth_cancel ( struct sg_httpauth auth)

Cancels the authentication loop while the user is trying to access the server.

Parameters
[in]authAuthentication handle.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpauth_usr()

const char * sg_httpauth_usr ( struct sg_httpauth auth)

Returns the authentication user.

Parameters
[in]authAuthentication handle.
Returns
User as a null-terminated string.
Return values
NULLIf auth is null and set the errno to EINVAL.
Examples
example_httpauth.c.

◆ sg_httpauth_pwd()

const char * sg_httpauth_pwd ( struct sg_httpauth auth)

Returns the authentication password.

Parameters
[in]authAuthentication handle.
Returns
Password as a null-terminated string.
Return values
NULLIf auth is null and set the errno to EINVAL.
Examples
example_httpauth.c.

◆ sg_httpuplds_iter()

int sg_httpuplds_iter ( struct sg_httpupld uplds,
sg_httpuplds_iter_cb  cb,
void *  cls 
)

Iterates over all the upload items in the uplds list.

Parameters
[in]upldsUploads list handle.
[in]cbCallback to iterate over upload items.
[in]clsUser-defined closure.
Return values
0Success.
EINVALInvalid argument.
E<ERROR>User-defined error to abort the list iteration.

◆ sg_httpuplds_next()

int sg_httpuplds_next ( struct sg_httpupld **  upld)

Gets the next upload item starting from the first item pointer upld.

Parameters
[in,out]upldNext upload item starting from the first item pointer.
Return values
0Success.
EINVALInvalid argument.
Examples
example_httpuplds.c.

◆ sg_httpuplds_count()

unsigned int sg_httpuplds_count ( struct sg_httpupld uplds)

Counts the total upload items in the list uplds.

Parameters
[in]upldsUploads list.
Returns
Total of items.
Return values
0If the list is empty or null.

◆ sg_httpupld_handle()

void * sg_httpupld_handle ( struct sg_httpupld upld)

Returns the stream handle of the upload handle upld.

Parameters
[in]upldUpload handle.
Returns
Stream handle.
Return values
NULLIf upld is null and set the errno to EINVAL.

◆ sg_httpupld_dir()

const char * sg_httpupld_dir ( struct sg_httpupld upld)

Returns the directory of the upload handle upld.

Parameters
[in]upldUpload handle.
Returns
Upload directory as a null-terminated string.
Return values
NULLIf upld is null and set the errno to EINVAL.

◆ sg_httpupld_field()

const char * sg_httpupld_field ( struct sg_httpupld upld)

Returns the field of the upload handle upld.

Parameters
[in]upldUpload handle.
Returns
Upload field as a null-terminated string.
Return values
NULLIf upld is null and set the errno to EINVAL.

◆ sg_httpupld_name()

const char * sg_httpupld_name ( struct sg_httpupld upld)

Returns the name of the upload handle upld.

Parameters
[in]upldUpload handle.
Returns
Upload name as a null-terminated string.
Return values
NULLIf upld is null and set the errno to EINVAL.
Examples
example_httpuplds.c.

◆ sg_httpupld_mime()

const char * sg_httpupld_mime ( struct sg_httpupld upld)

Returns the MIME (content-type) of the upload.

Parameters
[in]upldUpload handle.
Returns
Upload MIME as a null-terminated string.
Return values
NULLIf upld is null and set the errno to EINVAL.

◆ sg_httpupld_encoding()

const char * sg_httpupld_encoding ( struct sg_httpupld upld)

Returns the encoding (transfer-encoding) of the upload.

Parameters
[in]upldUpload handle.
Returns
Upload encoding as a null-terminated string.
Return values
NULLIf upld is null and set the errno to EINVAL.

◆ sg_httpupld_size()

uint64_t sg_httpupld_size ( struct sg_httpupld upld)

Returns the size of the upload.

Parameters
[in]upldUpload handle.
Returns
Upload size into uint64. If upld is null, set the errno to EINVAL.

◆ sg_httpupld_save()

int sg_httpupld_save ( struct sg_httpupld upld,
bool  overwritten 
)

Saves the uploaded file defining the destination path by upload name and directory.

Parameters
[in]upldUpload handle.
[in]overwrittenOverwrite upload file if it exists.
Return values
0Success.
EINVALInvalid argument.
EEXISTFile already exists (if overwritten is false).
EISDIRDestination file is a directory.
Examples
example_httpuplds.c.

◆ sg_httpupld_save_as()

int sg_httpupld_save_as ( struct sg_httpupld upld,
const char *  path,
bool  overwritten 
)

Saves the uploaded file allowing to define the destination path.

Parameters
[in]upldUpload handle.
[in]pathAbsolute destination path.
[in]overwrittenOverwrite upload file if it exists.
Return values
0Success.
EINVALInvalid argument.
EEXISTFile already exists (if overwritten is true).
EISDIRDestination file is a directory.

◆ sg_httpreq_srv()

struct sg_httpsrv * sg_httpreq_srv ( struct sg_httpreq req)

Returns the server instance.

Parameters
[in]reqRequest handle.
Returns
Reference to the server instance.
Return values
NULLIf req is null and set the errno to EINVAL
Examples
example_httpuplds.c.

◆ sg_httpreq_headers()

struct sg_strmap ** sg_httpreq_headers ( struct sg_httpreq req)

Returns the client headers into sg_strmap map.

Parameters
[in]reqRequest handle.
Returns
Reference to the client headers map.
Return values
NULLIf req is null and set the errno to EINVAL
Note
The headers map is automatically freed by the library.
Examples
example_httpcomp.c, and example_httpsrv_sse.c.

◆ sg_httpreq_cookies()

struct sg_strmap ** sg_httpreq_cookies ( struct sg_httpreq req)

Returns the client cookies into sg_strmap map.

Parameters
[in]reqRequest handle.
Returns
Reference to the client cookies map.
Return values
NULLIf req is null and set the errno to EINVAL
Note
The cookies map is automatically freed by the library.
Examples
example_httpcookie.c.

◆ sg_httpreq_params()

struct sg_strmap ** sg_httpreq_params ( struct sg_httpreq req)

Returns the query-string into sg_strmap map.

Parameters
[in]reqRequest handle.
Returns
Reference to the query-string map.
Return values
NULLIf req is null and set the errno to EINVAL
Note
The query-string map is automatically freed by the library.
Examples
example_httpuplds.c.

◆ sg_httpreq_fields()

struct sg_strmap ** sg_httpreq_fields ( struct sg_httpreq req)

Returns the fields of a HTML form into sg_strmap map.

Parameters
[in]reqRequest handle.
Returns
Reference to the form fields map.
Return values
NULLIf req is null and set the errno to EINVAL
Note
The form fields map is automatically freed by the library.
Examples
example_httpreq_form.c.

◆ sg_httpreq_version()

const char * sg_httpreq_version ( struct sg_httpreq req)

Returns the HTTP version.

Parameters
[in]reqRequest handle.
Returns
HTTP version as a null-terminated string.
Return values
NULLIf req is null and set the errno to EINVAL.

◆ sg_httpreq_method()

const char * sg_httpreq_method ( struct sg_httpreq req)

Returns the HTTP method.

Parameters
[in]reqRequest handle.
Returns
HTTP method as a null-terminated string.
Return values
NULLIf req is null and set the errno to EINVAL.

◆ sg_httpreq_path()

const char * sg_httpreq_path ( struct sg_httpreq req)

Returns the path component.

Parameters
[in]reqRequest handle.
Returns
Path component as a null-terminated string.
Return values
NULLIf req is null and set the errno to EINVAL.
Examples
example_httpcookie.c, example_httpreq_isolate.c, example_httpsrv_sse.c, and example_router_srv.c.

◆ sg_httpreq_payload()

struct sg_str * sg_httpreq_payload ( struct sg_httpreq req)

Returns the posting payload into a sg_str instance.

Parameters
[in]reqRequest handle.
Returns
Instance of the payload.
Return values
NULLIf req is null and set the errno to EINVAL.
Note
The form payload instance is automatically freed by the library.
Examples
example_httpreq_payload.c.

◆ sg_httpreq_is_uploading()

bool sg_httpreq_is_uploading ( struct sg_httpreq req)

Checks if the client is uploading data.

Parameters
[in]reqRequest handle.
Return values
trueIf the client is uploading data, false otherwise. If req is null, set the errno to EINVAL.
Examples
example_httpuplds.c.

◆ sg_httpreq_uploads()

struct sg_httpupld * sg_httpreq_uploads ( struct sg_httpreq req)

Returns the list of the uploaded files.

Parameters
[in]reqRequest handle.
Returns
List of the uploaded files.
Return values
NULLIf req is null and set the errno to EINVAL.
Note
The uploads list is automatically freed by the library.
Examples
example_httpuplds.c.

◆ sg_httpreq_client()

const void * sg_httpreq_client ( struct sg_httpreq req)

Gets the socket handle of the client.

Parameters
[in]reqRequest handle.
Returns
Socket address of the client.
Return values
NULLIf req is null and set the errno to EINVAL.

◆ sg_httpreq_tls_session()

void * sg_httpreq_tls_session ( struct sg_httpreq req)

Returns the GnuTLS session handle.

Parameters
[in]reqRequest handle.
Return values
0Success.
EINVALInvalid argument.
Examples
example_httpsrv_tls_cert_auth.c.

◆ sg_httpreq_isolate()

int sg_httpreq_isolate ( struct sg_httpreq req,
sg_httpreq_cb  cb,
void *  cls 
)

Isolates a request from the main event loop to an own dedicated thread, bringing it back when the request finishes.

Parameters
[in]reqRequest handle.
[in]cbCallback to handle requests and responses isolated from the main event loop.
[in]clsUser-defined closure.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
E<ERROR>Any returned error from the OS threading library.
Note
Isolated requests will not time out.
While a request is isolated, the library will not detect disconnects by the client.
Examples
example_httpreq_isolate.c.

◆ sg_httpreq_set_user_data()

int sg_httpreq_set_user_data ( struct sg_httpreq req,
void *  data 
)

Sets user data to the request handle.

Parameters
[in]reqRequest handle.
[in]dataUser data pointer.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpreq_user_data()

void * sg_httpreq_user_data ( struct sg_httpreq req)

Gets user data from the request handle.

Parameters
[in]reqRequest handle.
Returns
User data pointer.
Return values
NULLIf req is null and set the errno to EINVAL.

◆ sg_httpres_headers()

struct sg_strmap ** sg_httpres_headers ( struct sg_httpres res)

Returns the server headers into sg_strmap map.

Parameters
[in]resResponse handle.
Returns
Reference to the server headers map.
Return values
NULLIf res is null and set the errno to EINVAL
Note
The headers map is automatically freed by the library.
Examples
example_httpsrv_sse.c.

◆ sg_httpres_set_cookie()

int sg_httpres_set_cookie ( struct sg_httpres res,
const char *  name,
const char *  val 
)

Sets server cookie to the response handle.

Parameters
[in]resResponse handle.
[in]nameCookie name.
[in]valCookie value.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
Examples
example_httpcookie.c.

◆ sg_httpres_sendbinary()

int sg_httpres_sendbinary ( struct sg_httpres res,
void *  buf,
size_t  size,
const char *  content_type,
unsigned int  status 
)

Sends a binary content to the client.

Parameters
[in]resResponse handle.
[in]bufBinary content.
[in]sizeContent size.
[in]content_typeContent type.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
ENOMEMOut of memory.
Examples
example_httpcomp.c.

◆ sg_httpres_sendfile2()

int sg_httpres_sendfile2 ( struct sg_httpres res,
uint64_t  size,
uint64_t  max_size,
uint64_t  offset,
const char *  filename,
const char *  disposition,
unsigned int  status 
)

Sends a file to the client.

Parameters
[in]resResponse handle.
[in]sizeSize of the file to be sent. Use zero to calculate automatically.
[in]max_sizeMaximum allowed file size. Use zero for no limit.
[in]offsetOffset to start reading from in the file to be sent.
[in]filenamePath of the file to be sent.
[in]dispositionContent disposition as a null-terminated string (attachment or inline).
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
EFBIGFile too large.
ENOMEMOut of memory.
Warning
The parameter disposition is not checked internally, thus any non-NULL value is passed directly to the header Content-Disposition.

◆ sg_httpres_sendfile()

int sg_httpres_sendfile ( struct sg_httpres res,
uint64_t  size,
uint64_t  max_size,
uint64_t  offset,
const char *  filename,
bool  downloaded,
unsigned int  status 
)

Sends a file to the client.

Parameters
[in]resResponse handle.
[in]sizeSize of the file to be sent. Use zero to calculate automatically.
[in]max_sizeMaximum allowed file size. Use zero for no limit.
[in]offsetOffset to start reading from in the file to be sent.
[in]filenamePath of the file to be sent.
[in]downloadedIf true it offers the file as download.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
EFBIGFile too large.
ENOMEMOut of memory.

◆ sg_httpres_sendstream()

int sg_httpres_sendstream ( struct sg_httpres res,
uint64_t  size,
sg_read_cb  read_cb,
void *  handle,
sg_free_cb  free_cb,
unsigned int  status 
)

Sends a stream to the client.

Parameters
[in]resResponse handle.
[in]sizeSize of the stream.
[in]read_cbCallback to read data from stream handle.
[in]handleStream handle.
[in]free_cbCallback to free the stream handle.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
ENOMEMOut of memory.
Note
Use size = 0 if the stream size is unknown.
Examples
example_httpsrv_sse.c.

◆ sg_httpres_zsendbinary2()

int sg_httpres_zsendbinary2 ( struct sg_httpres res,
int  level,
void *  buf,
size_t  size,
const char *  content_type,
unsigned int  status 
)

Compresses a binary content and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]levelCompression level (1..9 or -1 for default).
[in]bufBinary content.
[in]sizeContent size.
[in]content_typeContent type.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
ENOBUFSNo buffer space available.
EALREADYOperation already in progress.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: deflate is automatically added to the response.

◆ sg_httpres_zsendbinary()

int sg_httpres_zsendbinary ( struct sg_httpres res,
void *  buf,
size_t  size,
const char *  content_type,
unsigned int  status 
)

Compresses a binary content and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]bufBinary content.
[in]sizeContent size.
[in]content_typeContent type.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
ENOMEMOut of memory.
ENOBUFSNo buffer space available.
EALREADYOperation already in progress.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: deflate is automatically added to the response.
Examples
example_httpcomp.c.

◆ sg_httpres_zsendstream2()

int sg_httpres_zsendstream2 ( struct sg_httpres res,
int  level,
uint64_t  size,
sg_read_cb  read_cb,
void *  handle,
sg_free_cb  free_cb,
unsigned int  status 
)

Compresses a stream and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]levelCompression level (1..9 or -1 for default).
[in]sizeSize of the stream.
[in]read_cbCallback to read data from stream handle.
[in]handleStream handle.
[in]free_cbCallback to free the stream handle.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
ENOMEMOut of memory.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: deflate is automatically added to the response.

◆ sg_httpres_zsendstream()

int sg_httpres_zsendstream ( struct sg_httpres res,
sg_read_cb  read_cb,
void *  handle,
sg_free_cb  free_cb,
unsigned int  status 
)

Compresses a stream and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]read_cbCallback to read data from stream handle.
[in]handleStream handle.
[in]free_cbCallback to free the stream handle.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
ENOMEMOut of memory.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: deflate is automatically added to the response.

◆ sg_httpres_zsendfile2()

int sg_httpres_zsendfile2 ( struct sg_httpres res,
int  level,
uint64_t  size,
uint64_t  max_size,
uint64_t  offset,
const char *  filename,
const char *  disposition,
unsigned int  status 
)

Compresses a file in Gzip format and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]levelCompression level (1..9 or -1 for default).
[in]sizeSize of the file to be sent. Use zero to calculate automatically.
[in]max_sizeMaximum allowed file size. Use zero for no limit.
[in]offsetOffset to start reading from in the file to be sent.
[in]filenamePath of the file to be sent.
[in]dispositionContent disposition as a null-terminated string (attachment or inline).
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
EFBIGFile too large.
ENOMEMOut of memory.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: gzip is automatically added to the response.
Warning
The parameter disposition is not checked internally, thus any non-NULL value is passed directly to the header Content-Disposition.

◆ sg_httpres_zsendfile()

int sg_httpres_zsendfile ( struct sg_httpres res,
uint64_t  size,
uint64_t  max_size,
uint64_t  offset,
const char *  filename,
bool  downloaded,
unsigned int  status 
)

Compresses a file in Gzip format and sends it to the client. The compression is done by zlib library using the DEFLATE compression algorithm.

Parameters
[in]resResponse handle.
[in]sizeSize of the file to be sent. Use zero to calculate automatically.
[in]max_sizeMaximum allowed file size. Use zero for no limit.
[in]offsetOffset to start reading from in the file to be sent.
[in]filenamePath of the file to be sent.
[in]downloadedIf true it offers the file as download.
[in]statusHTTP status code.
Return values
0Success.
EINVALInvalid argument.
EALREADYOperation already in progress.
EISDIRIs a directory.
EBADFBad file number.
EFBIGFile too large.
ENOMEMOut of memory.
Z_<ERROR>zlib error as negative number.
Note
When compression succeeds, the header Content-Encoding: gzip is automatically added to the response.

◆ sg_httpres_reset()

int sg_httpres_reset ( struct sg_httpres res)

Resets status and internal buffers of the response handle preserving all headers and cookies.

Parameters
[in]resResponse handle.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpres_clear()

int sg_httpres_clear ( struct sg_httpres res)

Clears all headers, cookies, status and internal buffers of the response handle.

Parameters
[in]resResponse handle.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpres_is_empty()

bool sg_httpres_is_empty ( struct sg_httpres res)

Checks if the response is empty.

Parameters
[in]resResponse handle.
Return values
trueIf the response is empty, false otherwise. If res is null, set the errno to EINVAL.

◆ sg_httpsrv_new2()

struct sg_httpsrv * sg_httpsrv_new2 ( sg_httpauth_cb  auth_cb,
sg_httpreq_cb  req_cb,
sg_err_cb  err_cb,
void *  cls 
)

Creates a new HTTP server handle.

Parameters
[in]auth_cbCallback to grant/deny user access to the server resources.
[in]req_cbCallback to handle requests and responses.
[in]err_cbCallback to handle server errors.
[in]clsUser-defined closure.
Returns
New HTTP server handle.
Return values
NULL
  • If no memory space is available.
  • If the req_cb or err_cb is null and set the errno to EINVAL.
  • If a threading operation fails and set its error to errno.
Examples
example_httpauth.c.

◆ sg_httpsrv_new()

struct sg_httpsrv * sg_httpsrv_new ( sg_httpreq_cb  cb,
void *  cls 
)

Creates a new HTTP server handle.

Parameters
[in]cbCallback to handle requests and responses.
[in]clsUser-defined closure.
Returns
New HTTP server handle.
Return values
NULL
  • If the cb is null and set the errno to EINVAL.
  • If a threading operation fails and set its error to errno.
Examples
example_httpcomp.c, example_httpcookie.c, example_httpreq_form.c, example_httpreq_isolate.c, example_httpreq_payload.c, example_httpsrv.c, example_httpsrv_benchmark.c, example_httpsrv_sse.c, example_httpsrv_tls.c, example_httpsrv_tls_cert_auth.c, example_httpuplds.c, and example_router_srv.c.

◆ sg_httpsrv_free()

void sg_httpsrv_free ( struct sg_httpsrv srv)

◆ sg_httpsrv_tls_listen4()

bool sg_httpsrv_tls_listen4 ( struct sg_httpsrv srv,
const char *  key,
const char *  pwd,
const char *  cert,
const char *  trust,
const char *  dhparams,
const char *  priorities,
const char *  hostname,
uint16_t  port,
uint32_t  backlog,
bool  threaded 
)

Starts the HTTPS server.

Parameters
[in]srvServer handle.
[in]keyMemory pointer for the private key (key.pem) to be used by the HTTPS server.
[in]pwdPassword for the private key.
[in]certMemory pointer for the certificate (cert.pem) to be used by the HTTPS server.
[in]trustMemory pointer for the certificate (ca.pem) to be used by the HTTPS server for client authentication.
[in]dhparamsMemory pointer for the Diffie Hellman parameters (dh.pem) to be used by the HTTPS server for key exchange.
[in]prioritiesMemory pointer specifying the cipher algorithm. Default: "NORMAL".
[in]hostnameHost name for listening to connections.
[in]portPort for listening to connections.
[in]backlogMaximum length of the queue of pending connections. Default: 511.
[in]threadedEnables/disables the threaded mode. If true, the server creates one thread per connection.
Return values
trueIf the server is started, false otherwise. If srv is null, set the errno to EINVAL.
Note
If port is 0, the operating system will assign an unused port randomly.

◆ sg_httpsrv_tls_listen3()

bool sg_httpsrv_tls_listen3 ( struct sg_httpsrv srv,
const char *  key,
const char *  pwd,
const char *  cert,
const char *  trust,
const char *  dhparams,
const char *  priorities,
uint16_t  port,
bool  threaded 
)

Starts the HTTPS server.

Parameters
[in]srvServer handle.
[in]keyMemory pointer for the private key (key.pem) to be used by the HTTPS server.
[in]pwdPassword for the private key.
[in]certMemory pointer for the certificate (cert.pem) to be used by the HTTPS server.
[in]trustMemory pointer for the certificate (ca.pem) to be used by the HTTPS server for client authentication.
[in]dhparamsMemory pointer for the Diffie Hellman parameters (dh.pem) to be used by the HTTPS server for key exchange.
[in]prioritiesMemory pointer specifying the cipher algorithm. Default: "NORMAL".
[in]portPort for listening to connections.
[in]threadedEnables/disables the threaded mode. If true, the server creates one thread per connection.
Return values
trueIf the server is started, false otherwise. If srv is null, set the errno to EINVAL.
Note
If port is 0, the operating system will assign an unused port randomly.

◆ sg_httpsrv_tls_listen2()

bool sg_httpsrv_tls_listen2 ( struct sg_httpsrv srv,
const char *  key,
const char *  pwd,
const char *  cert,
const char *  trust,
const char *  dhparams,
uint16_t  port,
bool  threaded 
)

Starts the HTTPS server.

Parameters
[in]srvServer handle.
[in]keyMemory pointer for the private key (key.pem) to be used by the HTTPS server.
[in]pwdPassword for the private key.
[in]certMemory pointer for the certificate (cert.pem) to be used by the HTTPS server.
[in]trustMemory pointer for the certificate (ca.pem) to be used by the HTTPS server for client authentication.
[in]dhparamsMemory pointer for the Diffie Hellman parameters (dh.pem) to be used by the HTTPS server for key exchange.
[in]portPort for listening to connections.
[in]threadedEnables/disables the threaded mode. If true, the server creates one thread per connection.
Return values
trueIf the server is started, false otherwise. If srv is null, set the errno to EINVAL.
Note
If port is 0, the operating system will assign an unused port randomly.
Examples
example_httpsrv_tls_cert_auth.c.

◆ sg_httpsrv_tls_listen()

bool sg_httpsrv_tls_listen ( struct sg_httpsrv srv,
const char *  key,
const char *  cert,
uint16_t  port,
bool  threaded 
)

Starts the HTTPS server.

Parameters
[in]srvServer handle.
[in]keyMemory pointer for the private key (key.pem) to be used by the HTTPS server.
[in]certMemory pointer for the certificate (cert.pem) to be used by the HTTPS server.
[in]portPort for listening to connections.
[in]threadedEnables/disables the threaded mode. If true, the server creates one thread per connection.
Return values
trueIf the server is started, false otherwise. If srv is null, set the errno to EINVAL.
Note
If port is 0, the operating system will assign an unused port randomly.
Examples
example_httpsrv_tls.c.

◆ sg_httpsrv_listen2()

bool sg_httpsrv_listen2 ( struct sg_httpsrv srv,
const char *  hostname,
uint16_t  port,
uint32_t  backlog,
bool  threaded 
)

Starts the HTTP server.

Parameters
[in]srvServer handle.
[in]hostnameHost name for listening to connections.
[in]portPort for listening to connections.
[in]backlogMaximum length of the queue of pending connections. Default: 511.
[in]threadedEnables/disables the threaded mode. If true, the server creates one thread per connection.
Return values
trueIf the server is started, false otherwise. If srv is null, set the errno to EINVAL.
Note
If port is 0, the operating system will randomly assign an unused port.

◆ sg_httpsrv_listen()

bool sg_httpsrv_listen ( struct sg_httpsrv srv,
uint16_t  port,
bool  threaded 
)

Starts the HTTP server.

Parameters
[in]srvServer handle.
[in]portPort for listening to connections.
[in]threadedEnables/disables the threaded mode. If true, the server creates one thread per connection.
Return values
trueIf the server is started, false otherwise. If srv is null, set the errno to EINVAL.
Note
If port is 0, the operating system will randomly assign an unused port.
Examples
example_httpauth.c, example_httpcomp.c, example_httpcookie.c, example_httpreq_form.c, example_httpreq_isolate.c, example_httpreq_payload.c, example_httpsrv.c, example_httpsrv_benchmark.c, example_httpsrv_sse.c, example_httpuplds.c, and example_router_srv.c.

◆ sg_httpsrv_shutdown()

int sg_httpsrv_shutdown ( struct sg_httpsrv srv)

Stops the server not to accept new connections.

Parameters
[in]srvServer handle.
Return values
0If the server is stopped.
EINVALInvalid argument.
EALREADYAlready shut down.

◆ sg_httpsrv_port()

uint16_t sg_httpsrv_port ( struct sg_httpsrv srv)

Returns the server listening port.

Parameters
[in]srvServer handle.
Returns
Server listening port, 0 otherwise. If srv is null, set the errno to EINVAL.
Examples
example_httpauth.c, example_httpcomp.c, example_httpcookie.c, example_httpreq_form.c, example_httpreq_isolate.c, example_httpreq_payload.c, example_httpsrv.c, example_httpsrv_benchmark.c, example_httpsrv_sse.c, example_httpsrv_tls.c, example_httpsrv_tls_cert_auth.c, example_httpuplds.c, and example_router_srv.c.

◆ sg_httpsrv_is_threaded()

bool sg_httpsrv_is_threaded ( struct sg_httpsrv srv)

Checks if the server was started in threaded mode.

Parameters
[in]srvServer handle.
Return values
trueIf the server is in threaded mode, false otherwise. If srv is null, set the errno to EINVAL.

◆ sg_httpsrv_set_cli_cb()

int sg_httpsrv_set_cli_cb ( struct sg_httpsrv srv,
sg_httpsrv_cli_cb  cb,
void *  cls 
)

Sets the server callback for client connection events.

Parameters
[in]srvServer handle.
[in]cbCallback to handle client events.
[in]clsUser-defined closure.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_set_upld_cbs()

int sg_httpsrv_set_upld_cbs ( struct sg_httpsrv srv,
sg_httpupld_cb  cb,
void *  cls,
sg_write_cb  write_cb,
sg_free_cb  free_cb,
sg_save_cb  save_cb,
sg_save_as_cb  save_as_cb 
)

Sets the server uploading callbacks.

Parameters
[in]srvServer handle.
[in]cbCallback to handle uploaded files and/or fields.
[in]clsUser-defined closure.
[in]write_cbCallback to write the stream of the uploaded files.
[in]free_cbCallback to free stream of the uploaded files.
[in]save_cbCallback to save the uploaded files.
[in]save_as_cbCallback to save the uploaded files defining their path.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_set_upld_dir()

int sg_httpsrv_set_upld_dir ( struct sg_httpsrv srv,
const char *  dir 
)

Sets the directory to save the uploaded files.

Parameters
[in]srvServer handle.
[in]dirDirectory as a null-terminated string.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_upld_dir()

const char * sg_httpsrv_upld_dir ( struct sg_httpsrv srv)

Gets the directory of the uploaded files.

Parameters
[in]srvServer handle.
Returns
Directory as a null-terminated string.
Return values
NULLIf the srv is null and set the errno to EINVAL.
Examples
example_httpuplds.c.

◆ sg_httpsrv_set_post_buf_size()

int sg_httpsrv_set_post_buf_size ( struct sg_httpsrv srv,
size_t  size 
)

Sets a size to the post buffering.

Parameters
[in]srvServer handle.
[in]sizePost buffering size.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_post_buf_size()

size_t sg_httpsrv_post_buf_size ( struct sg_httpsrv srv)

Gets the size of the post buffering.

Parameters
[in]srvServer handle.
Returns
Post buffering size.
Return values
0If the srv is null and set the errno to EINVAL.

◆ sg_httpsrv_set_payld_limit()

int sg_httpsrv_set_payld_limit ( struct sg_httpsrv srv,
size_t  limit 
)

Sets a limit to the total payload.

Parameters
[in]srvServer handle.
[in]limitPayload total limit. Use zero for no limit.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_payld_limit()

size_t sg_httpsrv_payld_limit ( struct sg_httpsrv srv)

Gets the limit of the total payload.

Parameters
[in]srvServer handle.
Returns
Payload total limit.
Return values
0If the srv is null and set the errno to EINVAL.

◆ sg_httpsrv_set_uplds_limit()

int sg_httpsrv_set_uplds_limit ( struct sg_httpsrv srv,
uint64_t  limit 
)

Sets a limit to the total uploads.

Parameters
[in]srvServer handle.
[in]limitUploads total limit. Use zero for no limit.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_uplds_limit()

uint64_t sg_httpsrv_uplds_limit ( struct sg_httpsrv srv)

Gets the limit of the total uploads.

Parameters
[in]srvServer handle.
Returns
Uploads total limit.
Return values
0If the srv is null and set the errno to EINVAL.

◆ sg_httpsrv_set_thr_pool_size()

int sg_httpsrv_set_thr_pool_size ( struct sg_httpsrv srv,
unsigned int  size 
)

Sets the size for the thread pool.

Parameters
[in]srvServer handle.
[in]sizeThread pool size. Size greater than 1 enables the thread pooling.
Return values
0Success.
EINVALInvalid argument.
Examples
example_httpsrv_benchmark.c.

◆ sg_httpsrv_thr_pool_size()

unsigned int sg_httpsrv_thr_pool_size ( struct sg_httpsrv srv)

Gets the size of the thread pool.

Parameters
[in]srvServer handle.
Returns
Thread pool size.
Return values
0If the srv is null and set the errno to EINVAL.

◆ sg_httpsrv_set_con_timeout()

int sg_httpsrv_set_con_timeout ( struct sg_httpsrv srv,
unsigned int  timeout 
)

Sets the inactivity time to a client to get time out.

Parameters
[in]srvServer handle.
[in]timeoutTimeout (in seconds). Use zero for infinity timeout. Default: 15 seconds.
Return values
0Success.
EINVALInvalid argument.

◆ sg_httpsrv_con_timeout()

unsigned int sg_httpsrv_con_timeout ( struct sg_httpsrv srv)

Gets the inactivity time to a client to get time out.

Parameters
[in]srvServer handle.
Returns
Timeout (in seconds).
Return values
0If the srv is null and set the errno to EINVAL.

◆ sg_httpsrv_set_con_limit()

int sg_httpsrv_set_con_limit ( struct sg_httpsrv srv,
unsigned int  limit 
)

Sets the limit of concurrent connections.

Parameters
[in]srvServer handle.
[in]limitConcurrent connections limit. Use zero for no limit.
Return values
0Success.
EINVALInvalid argument.
Examples
example_httpsrv_benchmark.c.

◆ sg_httpsrv_con_limit()

unsigned int sg_httpsrv_con_limit ( struct sg_httpsrv srv)

Gets the limit of concurrent connections.

Parameters
[in]srvServer handle.
Returns
Concurrent connections limit.
Return values
0If the srv is null and set the errno to EINVAL.

◆ sg_httpsrv_handle()

void * sg_httpsrv_handle ( struct sg_httpsrv srv)

Returns the MHD instance.

Parameters
[in]srvServer handle.
Returns
MHD instance.
NULL If the server is shut down.
Return values
NULLIf srv is null and set the errno to EINVAL.