53#ifdef BUILDING_LIBSAGUI
54#define SG_EXTERN __declspec(dllexport) extern
56#define SG_EXTERN __declspec(dllimport) extern
59#define SG_EXTERN extern
64#define __SG_UNUSED __attribute__((unused))
68#define __SG_MALLOC __attribute__((malloc))
72#define __SG_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
75#define SG_VERSION_MAJOR 3
76#define SG_VERSION_MINOR 5
77#define SG_VERSION_PATCH 0
78#define SG_VERSION_HEX \
79 ((SG_VERSION_MAJOR << 16) | (SG_VERSION_MINOR << 8) | (SG_VERSION_PATCH))
81#define SG_ERR_SIZE 256
97typedef void *(*sg_malloc_func)(
size_t size);
106typedef void *(*sg_realloc_func)(
void *ptr,
size_t size);
148typedef ssize_t (*
sg_write_cb)(
void *handle, uint64_t offset,
const char *buf,
159typedef ssize_t (*
sg_read_cb)(
void *handle, uint64_t offset,
char *buf,
186typedef int (*
sg_save_as_cb)(
void *handle,
const char *path,
bool overwritten);
242SG_EXTERN
void *
sg_realloc(
void *ptr,
size_t size) __SG_MALLOC;
272SG_EXTERN
char *
sg_strerror(
int errnum,
char *errmsg,
size_t errlen);
317SG_EXTERN
int sg_ip(
const void *socket,
char *buf,
size_t size);
649 const
char *field, const
char *name,
650 const
char *mime, const
char *encoding);
702 const
char *content_type,
unsigned int status);
715 const
char *content_type);
953#ifdef SG_HTTPS_SUPPORT
1032#define sg_httpres_send(res, val, content_type, status) \
1033 sg_httpres_sendbinary((res), (void *) (val), \
1034 (((val) != NULL) ? strlen((val)) : 0), (content_type), \
1050 size_t size,
const char *content_type,
1051 unsigned int status);
1065#define sg_httpres_download(res, filename, status) \
1066 sg_httpres_sendfile2((res), 0, 0, 0, (filename), "attachment", (status))
1080#define sg_httpres_render(res, filename, status) \
1081 sg_httpres_sendfile2((res), 0, 0, 0, (filename), "inline", (status))
1105 uint64_t max_size, uint64_t offset,
1106 const char *filename,
1107 const char *disposition,
1108 unsigned int status);
1129 uint64_t max_size, uint64_t offset,
1130 const char *filename,
bool downloaded,
1131 unsigned int status);
1151#ifdef SG_HTTP_COMPRESSION
1169#define sg_httpres_zsend(res, val, content_type, status) \
1170 sg_httpres_zsendbinary((res), (void *) (val), \
1171 (((val) != NULL) ? strlen((val)) : 0), \
1172 (content_type), (status))
1193 void *buf,
size_t size,
1194 const char *content_type,
1195 unsigned int status);
1215 size_t size,
const char *content_type,
1216 unsigned int status);
1239 unsigned int status);
1259 unsigned int status);
1277#define sg_httpres_zdownload(res, filename, status) \
1278 sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "attachment", (status))
1296#define sg_httpres_zrender(res, filename, status) \
1297 sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "inline", (status))
1326 uint64_t size, uint64_t max_size,
1327 uint64_t offset,
const char *filename,
1328 const char *disposition,
1329 unsigned int status);
1354 uint64_t max_size, uint64_t offset,
1355 const char *filename,
bool downloaded,
1356 unsigned int status);
1403 void *cls) __SG_MALLOC;
1415 void *cls) __SG_MALLOC;
1425#ifdef SG_HTTPS_SUPPORT
1453 const char *pwd,
const char *cert,
1454 const char *trust,
const char *dhparams,
1455 const char *priorities,
1456 const char *hostname, uint16_t port,
1457 uint32_t backlog,
bool threaded);
1482 const char *pwd,
const char *cert,
1483 const char *trust,
const char *dhparams,
1484 const char *priorities, uint16_t port,
1508 const char *pwd,
const char *cert,
1509 const char *trust,
const char *dhparams,
1510 uint16_t port,
bool threaded);
1528 const char *cert, uint16_t port,
1548 uint16_t port, uint32_t backlog,
1715 unsigned int timeout);
1733 unsigned int limit);
1754#ifdef SG_PATH_ROUTING
1839 const char *path,
void *user_data);
1905 const char *segment);
2033 const char *pattern,
char *errmsg,
size_t errlen,
2193#ifdef SG_MATH_EXPR_EVAL
2256 const char *identifier);
2345 size_t len,
double val);
enum sg_expr_err_type sg_expr_err(struct sg_expr *expr)
int sg_expr_compile(struct sg_expr *expr, const char *str, size_t len, struct sg_expr_extension *extensions)
void sg_expr_free(struct sg_expr *expr)
struct sg_expr * sg_expr_new(void) __attribute__((malloc))
double sg_expr_calc(const char *str, size_t len)
double sg_expr_var(struct sg_expr *expr, const char *name, size_t len)
int sg_expr_clear(struct sg_expr *expr)
const char * sg_expr_strerror(struct sg_expr *expr)
sg_expr_err_type
Definition sagui.h:2212
double sg_expr_eval(struct sg_expr *expr)
int sg_expr_near(struct sg_expr *expr)
double sg_expr_arg(struct sg_expr_argument *args, int index)
double(* sg_expr_func)(void *cls, struct sg_expr_argument *args, const char *identifier)
Definition sagui.h:2255
int sg_expr_set_var(struct sg_expr *expr, const char *name, size_t len, double val)
@ SG_EXPR_ERR_UNKNOWN_OPERATOR
Definition sagui.h:2224
@ SG_EXPR_ERR_BAD_PARENS
Definition sagui.h:2228
@ SG_EXPR_ERR_FIRST_ARG_IS_NOT_VAR
Definition sagui.h:2232
@ SG_EXPR_ERR_BAD_ASSIGNMENT
Definition sagui.h:2236
@ SG_EXPR_ERR_UNEXPECTED_NUMBER
Definition sagui.h:2216
@ SG_EXPR_ERR_MISSING_OPERAND
Definition sagui.h:2222
@ SG_EXPR_ERR_UNEXPECTED_PARENS
Definition sagui.h:2220
@ SG_EXPR_ERR_UNKNOWN
Definition sagui.h:2214
@ SG_EXPR_ERR_TOO_FEW_FUNC_ARGS
Definition sagui.h:2230
@ SG_EXPR_ERR_BAD_VARIABLE_NAME
Definition sagui.h:2234
@ SG_EXPR_ERR_UNEXPECTED_WORD
Definition sagui.h:2218
@ SG_EXPR_ERR_INVALID_FUNC_NAME
Definition sagui.h:2226
int sg_httpres_sendbinary(struct sg_httpres *res, void *buf, size_t size, const char *content_type, unsigned int status)
void * sg_httpsrv_handle(struct sg_httpsrv *srv)
int sg_httpreq_isolate(struct sg_httpreq *req, sg_httpreq_cb cb, void *cls)
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_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)
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)
struct sg_strmap ** sg_httpres_headers(struct sg_httpres *res)
bool(* sg_httpauth_cb)(void *cls, struct sg_httpauth *auth, struct sg_httpreq *req, struct sg_httpres *res)
Definition sagui.h:631
struct sg_httpsrv * sg_httpreq_srv(struct sg_httpreq *req)
int sg_httpsrv_set_upld_dir(struct sg_httpsrv *srv, const char *dir)
struct sg_httpsrv * sg_httpsrv_new2(sg_httpauth_cb auth_cb, sg_httpreq_cb req_cb, sg_err_cb err_cb, void *cls) __attribute__((malloc))
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_listen2(struct sg_httpsrv *srv, const char *hostname, uint16_t port, uint32_t backlog, bool threaded)
struct sg_httpupld * sg_httpreq_uploads(struct sg_httpreq *req)
bool sg_httpres_is_empty(struct sg_httpres *res)
int sg_httpres_reset(struct sg_httpres *res)
const char * sg_httpreq_method(struct sg_httpreq *req)
const char * sg_httpauth_usr(struct sg_httpauth *auth)
size_t sg_httpsrv_payld_limit(struct sg_httpsrv *srv)
const char * sg_httpupld_mime(struct sg_httpupld *upld)
const char * sg_httpupld_field(struct sg_httpupld *upld)
int sg_httpsrv_set_post_buf_size(struct sg_httpsrv *srv, size_t size)
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)
int sg_httpsrv_set_con_limit(struct sg_httpsrv *srv, unsigned int limit)
int sg_httpuplds_iter(struct sg_httpupld *uplds, sg_httpuplds_iter_cb cb, void *cls)
unsigned int sg_httpsrv_con_timeout(struct sg_httpsrv *srv)
void * sg_httpreq_user_data(struct sg_httpreq *req)
int sg_httpreq_set_user_data(struct sg_httpreq *req, void *data)
struct sg_httpsrv * sg_httpsrv_new(sg_httpreq_cb cb, void *cls) __attribute__((malloc))
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_httpsrv_set_cli_cb(struct sg_httpsrv *srv, sg_httpsrv_cli_cb cb, void *cls)
void * sg_httpreq_tls_session(struct sg_httpreq *req)
unsigned int sg_httpsrv_con_limit(struct sg_httpsrv *srv)
int sg_httpauth_deny2(struct sg_httpauth *auth, const char *reason, const char *content_type, unsigned int status)
size_t sg_httpsrv_post_buf_size(struct sg_httpsrv *srv)
int sg_httpsrv_shutdown(struct sg_httpsrv *srv)
int sg_httpres_clear(struct sg_httpres *res)
int sg_httpauth_deny(struct sg_httpauth *auth, const char *reason, const char *content_type)
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_httpauth_set_realm(struct sg_httpauth *auth, const char *realm)
bool sg_httpreq_is_uploading(struct sg_httpreq *req)
void * sg_httpupld_handle(struct sg_httpupld *upld)
bool sg_httpsrv_tls_listen(struct sg_httpsrv *srv, const char *key, const char *cert, uint16_t port, bool threaded)
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)
const char * sg_httpauth_pwd(struct sg_httpauth *auth)
unsigned int sg_httpuplds_count(struct sg_httpupld *uplds)
int(* sg_httpuplds_iter_cb)(void *cls, struct sg_httpupld *upld)
Definition sagui.h:659
uint64_t sg_httpsrv_uplds_limit(struct sg_httpsrv *srv)
int sg_httpres_zsendbinary(struct sg_httpres *res, void *buf, size_t size, const char *content_type, unsigned int status)
int sg_httpsrv_set_uplds_limit(struct sg_httpsrv *srv, uint64_t limit)
struct sg_strmap ** sg_httpreq_headers(struct sg_httpreq *req)
int sg_httpupld_save(struct sg_httpupld *upld, bool overwritten)
const char * sg_httpsrv_upld_dir(struct sg_httpsrv *srv)
void(* sg_httpreq_cb)(void *cls, struct sg_httpreq *req, struct sg_httpres *res)
Definition sagui.h:667
struct sg_strmap ** sg_httpreq_fields(struct sg_httpreq *req)
bool sg_httpsrv_is_threaded(struct sg_httpsrv *srv)
const void * sg_httpreq_client(struct sg_httpreq *req)
const char * sg_httpreq_version(struct sg_httpreq *req)
int sg_httpsrv_set_thr_pool_size(struct sg_httpsrv *srv, unsigned int size)
int sg_httpauth_cancel(struct sg_httpauth *auth)
int sg_httpres_set_cookie(struct sg_httpres *res, const char *name, const char *val)
void sg_httpsrv_free(struct sg_httpsrv *srv)
void(* sg_httpsrv_cli_cb)(void *cls, const void *client, bool *closed)
Definition sagui.h:619
struct sg_strmap ** sg_httpreq_params(struct sg_httpreq *req)
const char * sg_httpupld_dir(struct sg_httpupld *upld)
struct sg_strmap ** sg_httpreq_cookies(struct sg_httpreq *req)
uint64_t sg_httpupld_size(struct sg_httpupld *upld)
const char * sg_httpreq_path(struct sg_httpreq *req)
const char * sg_httpauth_realm(struct sg_httpauth *auth)
int(* sg_httpupld_cb)(void *cls, void **handle, const char *dir, const char *field, const char *name, const char *mime, const char *encoding)
Definition sagui.h:648
struct sg_str * sg_httpreq_payload(struct sg_httpreq *req)
int sg_httpsrv_set_payld_limit(struct sg_httpsrv *srv, size_t limit)
int sg_httpsrv_set_con_timeout(struct sg_httpsrv *srv, unsigned int timeout)
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_httpupld_save_as(struct sg_httpupld *upld, const char *path, bool overwritten)
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_zsendstream(struct sg_httpres *res, sg_read_cb read_cb, void *handle, sg_free_cb free_cb, unsigned int status)
int sg_httpuplds_next(struct sg_httpupld **upld)
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)
const char * sg_httpupld_name(struct sg_httpupld *upld)
unsigned int sg_httpsrv_thr_pool_size(struct sg_httpsrv *srv)
bool sg_httpsrv_listen(struct sg_httpsrv *srv, uint16_t port, bool threaded)
const char * sg_httpupld_encoding(struct sg_httpupld *upld)
uint16_t sg_httpsrv_port(struct sg_httpsrv *srv)
int sg_router_dispatch(struct sg_router *router, const char *path, void *user_data)
int sg_routes_iter(struct sg_route *routes, sg_routes_iter_cb cb, void *cls)
void * sg_route_match(struct sg_route *route)
int sg_routes_rm(struct sg_route **routes, const char *pattern)
int sg_entrypoints_rm(struct sg_entrypoints *entrypoints, const char *path)
int sg_routes_next(struct sg_route **route)
int(* sg_router_dispatch_cb)(void *cls, const char *path, struct sg_route *route)
Definition sagui.h:2118
int sg_entrypoints_add(struct sg_entrypoints *entrypoints, const char *path, void *user_data)
unsigned int sg_routes_count(struct sg_route *routes)
int(* sg_router_match_cb)(void *cls, struct sg_route *route)
Definition sagui.h:2129
int sg_routes_cleanup(struct sg_route **routes)
const char * sg_entrypoint_name(struct sg_entrypoint *entrypoint)
int(* sg_routes_iter_cb)(void *cls, struct sg_route *route)
Definition sagui.h:1932
int sg_entrypoints_find(struct sg_entrypoints *entrypoints, struct sg_entrypoint **entrypoint, const char *path)
const char * sg_route_path(struct sg_route *route)
void * sg_entrypoint_user_data(struct sg_entrypoint *entrypoint)
char * sg_route_pattern(struct sg_route *route) __attribute__((malloc))
int(* sg_entrypoints_iter_cb)(void *cls, struct sg_entrypoint *entrypoint)
Definition sagui.h:1812
int sg_entrypoints_clear(struct sg_entrypoints *entrypoints)
int(* sg_segments_iter_cb)(void *cls, unsigned int index, const char *segment)
Definition sagui.h:1904
int sg_entrypoints_iter(struct sg_entrypoints *entrypoints, sg_entrypoints_iter_cb cb, void *cls)
int sg_routes_add2(struct sg_route **routes, struct sg_route **route, const char *pattern, char *errmsg, size_t errlen, sg_route_cb cb, void *cls)
void * sg_route_user_data(struct sg_route *route)
struct sg_router * sg_router_new(struct sg_route *routes) __attribute__((malloc))
bool sg_routes_add(struct sg_route **routes, const char *pattern, sg_route_cb cb, void *cls)
void sg_router_free(struct sg_router *router)
int sg_route_vars_iter(struct sg_route *route, sg_vars_iter_cb cb, void *cls)
void * sg_route_handle(struct sg_route *route)
int sg_router_dispatch2(struct sg_router *router, const char *path, void *user_data, sg_router_dispatch_cb dispatch_cb, void *cls, sg_router_match_cb match_cb)
int sg_entrypoint_set_user_data(struct sg_entrypoint *entrypoint, void *data)
const char * sg_route_rawpattern(struct sg_route *route)
void(* sg_route_cb)(void *cls, struct sg_route *route)
Definition sagui.h:1923
int(* sg_vars_iter_cb)(void *cls, const char *name, const char *val)
Definition sagui.h:1916
void sg_entrypoints_free(struct sg_entrypoints *entrypoints)
struct sg_entrypoints * sg_entrypoints_new(void) __attribute__((malloc))
int sg_route_segments_iter(struct sg_route *route, sg_segments_iter_cb cb, void *cls)
int sg_str_clear(struct sg_str *str)
int const char * sg_str_content(struct sg_str *str)
int sg_str_write(struct sg_str *str, const char *val, size_t len)
int sg_str_printf_va(struct sg_str *str, const char *fmt, va_list ap)
size_t sg_str_length(struct sg_str *str)
struct sg_str * sg_str_new(void) __attribute__((malloc))
void sg_str_free(struct sg_str *str)
int sg_str_printf(struct sg_str *str, const char *fmt,...) __attribute__((format(printf
int sg_strmap_iter(struct sg_strmap *map, sg_strmap_iter_cb cb, void *cls)
int sg_strmap_set(struct sg_strmap **map, const char *name, const char *val)
int(* sg_strmap_sort_cb)(void *cls, struct sg_strmap *pair_a, struct sg_strmap *pair_b)
Definition sagui.h:445
const char * sg_strmap_val(struct sg_strmap *pair)
const char * sg_strmap_name(struct sg_strmap *pair)
const char * sg_strmap_get(struct sg_strmap *map, const char *name)
unsigned int sg_strmap_count(struct sg_strmap *map)
int sg_strmap_sort(struct sg_strmap **map, sg_strmap_sort_cb cb, void *cls)
int sg_strmap_find(struct sg_strmap *map, const char *name, struct sg_strmap **pair)
void sg_strmap_cleanup(struct sg_strmap **map)
int(* sg_strmap_iter_cb)(void *cls, struct sg_strmap *pair)
Definition sagui.h:434
int sg_strmap_next(struct sg_strmap **next)
int sg_strmap_rm(struct sg_strmap **map, const char *name)
int sg_strmap_add(struct sg_strmap **map, const char *name, const char *val)
void *(* sg_realloc_func)(void *ptr, size_t size)
Definition sagui.h:106
void(* sg_free_func)(void *ptr)
Definition sagui.h:113
double(* sg_fmod_func)(double x, double y)
Definition sagui.h:131
ssize_t(* sg_read_cb)(void *handle, uint64_t offset, char *buf, size_t size)
Definition sagui.h:159
unsigned int sg_version(void)
bool sg_is_post(const char *method)
int(* sg_save_as_cb)(void *handle, const char *path, bool overwritten)
Definition sagui.h:186
int sg_ip(const void *socket, char *buf, size_t size)
void * sg_alloc(size_t size) __attribute__((malloc))
int(* sg_save_cb)(void *handle, bool overwritten)
Definition sagui.h:175
void *(* sg_malloc_func)(size_t size)
Definition sagui.h:97
char * sg_tmpdir(void) __attribute__((malloc))
char * sg_strerror(int errnum, char *errmsg, size_t errlen)
void(* sg_free_cb)(void *handle)
Definition sagui.h:166
int sg_mm_set(sg_malloc_func malloc_func, sg_realloc_func realloc_func, sg_free_func free_func)
const char * sg_version_str(void)
void * sg_realloc(void *ptr, size_t size) __attribute__((malloc))
int sg_math_set(sg_pow_func pow_func, sg_fmod_func fmod_func)
void * sg_malloc(size_t size) __attribute__((malloc))
void(* sg_err_cb)(void *cls, const char *err)
Definition sagui.h:138
char * sg_extract_entrypoint(const char *path) __attribute__((malloc))
ssize_t(* sg_write_cb)(void *handle, uint64_t offset, const char *buf, size_t size)
Definition sagui.h:148
double(* sg_pow_func)(double x, double y)
Definition sagui.h:122
const char * identifier
Definition sagui.h:2267
sg_expr_func func
Definition sagui.h:2265
void * cls
Definition sagui.h:2269