|
typedef void *(* | sg_malloc_func) (size_t size) |
|
typedef void *(* | sg_realloc_func) (void *ptr, size_t size) |
|
typedef void(* | sg_free_func) (void *ptr) |
|
typedef double(* | sg_pow_func) (double x, double y) |
|
typedef double(* | sg_fmod_func) (double x, double y) |
|
typedef void(* | sg_err_cb) (void *cls, const char *err) |
|
typedef ssize_t(* | sg_write_cb) (void *handle, uint64_t offset, const char *buf, size_t size) |
|
typedef ssize_t(* | sg_read_cb) (void *handle, uint64_t offset, char *buf, size_t size) |
|
typedef void(* | sg_free_cb) (void *handle) |
|
typedef int(* | sg_save_cb) (void *handle, bool overwritten) |
|
typedef int(* | sg_save_as_cb) (void *handle, const char *path, bool overwritten) |
|
All utility functions of the library.
◆ sg_malloc_func
typedef void *(* sg_malloc_func) (size_t size) |
Callback signature used to override the function which allocates a new memory space.
- Parameters
-
[in] | size | Memory size to be allocated. |
- Returns
- Pointer of the allocated memory.
- Return values
-
NULL | If size is 0 or no memory space. |
◆ sg_realloc_func
typedef void *(* sg_realloc_func) (void *ptr, size_t size) |
Callback signature used to override the function which reallocates an existing memory block.
- Parameters
-
[in] | ptr | Pointer of the memory to be reallocated. |
[in] | size | Memory size to be reallocated. |
- Returns
- Pointer of the reallocated memory.
◆ sg_free_func
typedef void(* sg_free_func) (void *ptr) |
Callback signature used to override the function which frees a memory space previously allocated by sg_malloc(), sg_alloc() or sg_realloc().
- Parameters
-
[in] | ptr | Pointer of the memory to be freed. |
◆ sg_pow_func
typedef double(* sg_pow_func) (double x, double y) |
Callback signature used to override the function which returns the value of x
raised to the power of y
.
- Parameters
-
[in] | x | Floating point base value. |
[in] | y | Floating point power value. |
- Returns
- Value of
x
raised to the power of y
.
◆ sg_fmod_func
typedef double(* sg_fmod_func) (double x, double y) |
Callback signature used to override the function which returns the remainder of x
divided by y
.
- Parameters
-
[in] | x | Floating point value with the division numerator. |
[in] | y | Floating point value with the division denominator. |
- Returns
- Remainder of
x
divided by y
.
◆ sg_err_cb
typedef void(* sg_err_cb) (void *cls, const char *err) |
Callback signature used by functions that handle errors.
- Parameters
-
[out] | cls | User-defined closure. |
[out] | err | Error message. |
◆ sg_write_cb
typedef ssize_t(* sg_write_cb) (void *handle, uint64_t offset, const char *buf, size_t size) |
Callback signature used by functions that write streams.
- Parameters
-
[out] | handle | Stream handle. |
[out] | offset | Current stream offset. |
[out] | buf | Current buffer to be written. |
[out] | size | Size of the current buffer to be written. |
- Returns
- Total written buffer.
◆ sg_read_cb
typedef ssize_t(* sg_read_cb) (void *handle, uint64_t offset, char *buf, size_t size) |
Callback signature used by functions that read streams.
- Parameters
-
[out] | handle | Stream handle. |
[out] | offset | Current stream offset. |
[out] | buf | Current read buffer. |
[out] | size | Size of the current read buffer. |
- Returns
- Total read buffer.
◆ sg_free_cb
typedef void(* sg_free_cb) (void *handle) |
Callback signature used by functions that free streams.
- Parameters
-
[out] | handle | Stream handle. |
◆ sg_save_cb
typedef int(* sg_save_cb) (void *handle, bool overwritten) |
Callback signature used by functions that save streams.
- Parameters
-
[out] | handle | Stream handle. |
[out] | overwritten | Overwrite an already existed stream. |
- Return values
-
0 | Success. |
E<ERROR> | User-defined error to abort the saving. |
◆ sg_save_as_cb
typedef int(* sg_save_as_cb) (void *handle, const char *path, bool overwritten) |
Callback signature used by functions that save streams. It allows to specify the destination file path.
- Parameters
-
[out] | handle | Stream handle. |
[out] | path | Absolute path to store the stream. |
[out] | overwritten | Overwrite an already existed stream. |
- Return values
-
0 | Success. |
E<ERROR> | User-defined error to abort the saving. |
◆ sg_version()
unsigned int sg_version |
( |
void |
| ) |
|
Returns the library version number.
- Returns
- Library version packed into a single integer.
◆ sg_version_str()
const char * sg_version_str |
( |
void |
| ) |
|
Returns the library version number as string in the format <MAJOR>.<MINOR>.<PATCH>
.
- Returns
- Library version packed into a null-terminated string.
◆ sg_mm_set()
Overrides the standard functions malloc(3), realloc(3) and free(3) set by default in the memory manager.
- Parameters
-
[in] | malloc_func | Reference to override the function malloc() . |
[in] | realloc_func | Reference to override the function realloc() . |
[in] | free_func | Reference to override the function free() . |
- Return values
-
0 | Success. |
EINVAL | Invalid argument. |
- Note
- It must be called before any other Sagui function or after all resources have been freed.
◆ sg_malloc()
void * sg_malloc |
( |
size_t |
size | ) |
|
Allocates a new memory space.
- Parameters
-
[in] | size | Memory size to be allocated. |
- Returns
- Pointer of the allocated memory.
- Return values
-
NULL | If size is 0 or no memory space. |
- Note
- Equivalent to malloc(3).
◆ sg_alloc()
void * sg_alloc |
( |
size_t |
size | ) |
|
Allocates a new zero-initialized memory space.
- Parameters
-
[in] | size | Memory size to be allocated. |
- Returns
- Pointer of the zero-initialized allocated memory.
- Return values
-
NULL | If size is 0 or no memory space. |
- Examples
- example_httpsrv_tls_cert_auth.c.
◆ sg_realloc()
void * sg_realloc |
( |
void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
Reallocates an existing memory block.
- Parameters
-
[in] | ptr | Pointer of the memory to be reallocated. |
[in] | size | Memory size to be reallocated. |
- Returns
- Pointer of the reallocated memory.
- Note
- Equivalent to realloc(3).
◆ sg_free()
void sg_free |
( |
void * |
ptr | ) |
|
◆ sg_math_set()
Overrides the standard functions pow(3) and fmod(3) set by default in the math manager.
- Parameters
-
[in] | pow_func | Reference to override the function pow() . |
[in] | fmod_func | Reference to override the function fmod() . |
- Return values
-
0 | Success. |
EINVAL | Invalid argument. |
- Note
- It must be called before any other Sagui function or after all resources have been freed.
◆ sg_strerror()
char * sg_strerror |
( |
int |
errnum, |
|
|
char * |
errmsg, |
|
|
size_t |
errlen |
|
) |
| |
Returns string describing an error number.
- Parameters
-
[in] | errnum | Error number. |
[in,out] | errmsg | Pointer of a string to store the error message. |
[in] | errlen | Length of the error message. |
- Returns
- Pointer to
errmsg
.
- Examples
- example_httpsrv_tls_cert_auth.c, and example_httpuplds.c.
◆ sg_is_post()
bool sg_is_post |
( |
const char * |
method | ) |
|
Checks if a string is a HTTP post method.
- Parameters
-
[in] | method | Null-terminated string. |
- Return values
-
true | If method is POST , PUT , DELETE or OPTIONS . |
◆ sg_extract_entrypoint()
char * sg_extract_entrypoint |
( |
const char * |
path | ) |
|
Extracts the entry-point of a path or resource. For example, given a path /api1/customer
, the part considered as entry-point is /api1
.
- Parameters
-
path | Path as a null-terminated string. |
- Returns
- Entry-point as a null-terminated string.
- Return values
-
NULL | If no memory space is available. |
- Warning
- The caller must free the returned value.
◆ sg_tmpdir()
char * sg_tmpdir |
( |
void |
| ) |
|
Returns the system temporary directory.
- Returns
- Temporary directory as a null-terminated string.
- Return values
-
NULL | If no memory space is available. |
- Warning
- The caller must free the returned value.
◆ sg_eor()
ssize_t sg_eor |
( |
bool |
err | ) |
|
Indicates the end-of-read processed in sg_httpres_sendstream().
- Parameters
-
[in] | err | true to return a value indicating a stream reading error. |
- Returns
- Value to end a stream reading.
◆ sg_ip()
int sg_ip |
( |
const void * |
socket, |
|
|
char * |
buf, |
|
|
size_t |
size |
|
) |
| |
Obtains the IP of a socket handle (e.g. the one returned by sg_httpreq_client()) into a null-terminated string.
- Parameters
-
[in] | socket | Socket handle. |
[out] | buf | Pointer of the string to store the IP. |
[in] | size | Size of the string to store the IP. |
- Return values
-
0 | Success. |
EINVAL | Invalid argument. |
EAFNOSUPPORT | Address family not supported by protocol. |
ENOSPC | No space left on device. |