Sagui library v3.5.0
Cross-platform library which helps to develop web servers or frameworks.
Loading...
Searching...
No Matches
Typedefs | Functions
Utilities

Typedefs

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)
 

Functions

unsigned int sg_version (void)
 
const char * sg_version_str (void)
 
int sg_mm_set (sg_malloc_func malloc_func, sg_realloc_func realloc_func, sg_free_func free_func)
 
void * sg_malloc (size_t size) __attribute__((malloc))
 
void * sg_alloc (size_t size) __attribute__((malloc))
 
void * sg_realloc (void *ptr, size_t size) __attribute__((malloc))
 
void sg_free (void *ptr)
 
int sg_math_set (sg_pow_func pow_func, sg_fmod_func fmod_func)
 
char * sg_strerror (int errnum, char *errmsg, size_t errlen)
 
bool sg_is_post (const char *method)
 
char * sg_extract_entrypoint (const char *path) __attribute__((malloc))
 
char * sg_tmpdir (void) __attribute__((malloc))
 
ssize_t sg_eor (bool err)
 
int sg_ip (const void *socket, char *buf, size_t size)
 

Detailed Description

All utility functions of the library.

Typedef Documentation

◆ 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]sizeMemory size to be allocated.
Returns
Pointer of the allocated memory.
Return values
NULLIf 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]ptrPointer of the memory to be reallocated.
[in]sizeMemory 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]ptrPointer 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]xFloating point base value.
[in]yFloating 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]xFloating point value with the division numerator.
[in]yFloating 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]clsUser-defined closure.
[out]errError 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]handleStream handle.
[out]offsetCurrent stream offset.
[out]bufCurrent buffer to be written.
[out]sizeSize 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]handleStream handle.
[out]offsetCurrent stream offset.
[out]bufCurrent read buffer.
[out]sizeSize 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]handleStream handle.

◆ sg_save_cb

typedef int(* sg_save_cb) (void *handle, bool overwritten)

Callback signature used by functions that save streams.

Parameters
[out]handleStream handle.
[out]overwrittenOverwrite an already existed stream.
Return values
0Success.
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]handleStream handle.
[out]pathAbsolute path to store the stream.
[out]overwrittenOverwrite an already existed stream.
Return values
0Success.
E<ERROR>User-defined error to abort the saving.

Function Documentation

◆ 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()

int sg_mm_set ( sg_malloc_func  malloc_func,
sg_realloc_func  realloc_func,
sg_free_func  free_func 
)

Overrides the standard functions malloc(3), realloc(3) and free(3) set by default in the memory manager.

Parameters
[in]malloc_funcReference to override the function malloc().
[in]realloc_funcReference to override the function realloc().
[in]free_funcReference to override the function free().
Return values
0Success.
EINVALInvalid 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]sizeMemory size to be allocated.
Returns
Pointer of the allocated memory.
Return values
NULLIf 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]sizeMemory size to be allocated.
Returns
Pointer of the zero-initialized allocated memory.
Return values
NULLIf 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]ptrPointer of the memory to be reallocated.
[in]sizeMemory size to be reallocated.
Returns
Pointer of the reallocated memory.
Note
Equivalent to realloc(3).

◆ sg_free()

void sg_free ( void *  ptr)

Frees a memory space previously allocated by sg_malloc(), sg_alloc() or sg_realloc().

Parameters
[in]ptrPointer of the memory to be freed.
Note
Equivalent to free(3).
Examples
example_httpsrv_tls_cert_auth.c.

◆ sg_math_set()

int sg_math_set ( sg_pow_func  pow_func,
sg_fmod_func  fmod_func 
)

Overrides the standard functions pow(3) and fmod(3) set by default in the math manager.

Parameters
[in]pow_funcReference to override the function pow().
[in]fmod_funcReference to override the function fmod().
Return values
0Success.
EINVALInvalid 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]errnumError number.
[in,out]errmsgPointer of a string to store the error message.
[in]errlenLength 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]methodNull-terminated string.
Return values
trueIf 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
pathPath as a null-terminated string.
Returns
Entry-point as a null-terminated string.
Return values
NULLIf 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
NULLIf 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]errtrue 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]socketSocket handle.
[out]bufPointer of the string to store the IP.
[in]sizeSize of the string to store the IP.
Return values
0Success.
EINVALInvalid argument.
EAFNOSUPPORTAddress family not supported by protocol.
ENOSPCNo space left on device.