Sagui library v3.5.0
Cross-platform library which helps to develop web servers or frameworks.
Loading...
Searching...
No Matches
sagui.h
Go to the documentation of this file.
1/* _
2 * ___ __ _ __ _ _ _(_)
3 * / __|/ _` |/ _` | | | | |
4 * \__ \ (_| | (_| | |_| | |
5 * |___/\__,_|\__, |\__,_|_|
6 * |___/
7 *
8 * Cross-platform library which helps to develop web servers or frameworks.
9 *
10 * Copyright (C) 2016-2024 Silvio Clecio <silvioprog@gmail.com>
11 *
12 * Sagui library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * Sagui library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with Sagui library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
36#ifndef SAGUI_H
37#define SAGUI_H
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#include <stdio.h>
44#include <stddef.h>
45#include <stdbool.h>
46#include <stdint.h>
47#include <stdarg.h>
48#include <string.h>
49#include <time.h>
50
51#ifndef SG_EXTERN
52#ifdef _WIN32
53#ifdef BUILDING_LIBSAGUI
54#define SG_EXTERN __declspec(dllexport) extern
55#else /* _WIN32 */
56#define SG_EXTERN __declspec(dllimport) extern
57#endif /* _WIN32 */
58#else /* BUILDING_LIBSAGUI */
59#define SG_EXTERN extern
60#endif /* BUILDING_LIBSAGUI */
61#endif /* SG_EXTERN */
62
63#ifndef __SG_UNUSED
64#define __SG_UNUSED __attribute__((unused))
65#endif /* __SG_UNUSED */
66
67#ifndef __SG_MALLOC
68#define __SG_MALLOC __attribute__((malloc))
69#endif /* __SG_MALLOC */
70
71#ifndef __SG_FORMAT
72#define __SG_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
73#endif /* __SG_FORMAT */
74
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))
80
81#define SG_ERR_SIZE 256
82
97typedef void *(*sg_malloc_func)(size_t size);
98
106typedef void *(*sg_realloc_func)(void *ptr, size_t size);
107
113typedef void (*sg_free_func)(void *ptr);
114
122typedef double (*sg_pow_func)(double x, double y);
123
131typedef double (*sg_fmod_func)(double x, double y);
132
138typedef void (*sg_err_cb)(void *cls, const char *err);
139
148typedef ssize_t (*sg_write_cb)(void *handle, uint64_t offset, const char *buf,
149 size_t size);
150
159typedef ssize_t (*sg_read_cb)(void *handle, uint64_t offset, char *buf,
160 size_t size);
161
166typedef void (*sg_free_cb)(void *handle);
167
175typedef int (*sg_save_cb)(void *handle, bool overwritten);
176
186typedef int (*sg_save_as_cb)(void *handle, const char *path, bool overwritten);
187
192SG_EXTERN unsigned int sg_version(void);
193
199SG_EXTERN const char *sg_version_str(void);
200
215SG_EXTERN int sg_mm_set(sg_malloc_func malloc_func,
216 sg_realloc_func realloc_func, sg_free_func free_func);
217
225SG_EXTERN void *sg_malloc(size_t size) __SG_MALLOC;
226
233SG_EXTERN void *sg_alloc(size_t size) __SG_MALLOC;
234
242SG_EXTERN void *sg_realloc(void *ptr, size_t size) __SG_MALLOC;
243
250SG_EXTERN void sg_free(void *ptr);
251
263SG_EXTERN int sg_math_set(sg_pow_func pow_func, sg_fmod_func fmod_func);
264
272SG_EXTERN char *sg_strerror(int errnum, char *errmsg, size_t errlen);
273
279SG_EXTERN bool sg_is_post(const char *method);
280
289SG_EXTERN char *sg_extract_entrypoint(const char *path) __SG_MALLOC;
290
297SG_EXTERN char *sg_tmpdir(void) __SG_MALLOC;
298
304SG_EXTERN ssize_t sg_eor(bool err);
305
317SG_EXTERN int sg_ip(const void *socket, char *buf, size_t size);
318
333struct sg_str;
334
340SG_EXTERN struct sg_str *sg_str_new(void) __SG_MALLOC;
341
346SG_EXTERN void sg_str_free(struct sg_str *str);
347
357SG_EXTERN int sg_str_write(struct sg_str *str, const char *val, size_t len);
358
371SG_EXTERN int sg_str_printf_va(struct sg_str *str, const char *fmt, va_list ap);
372
384SG_EXTERN int sg_str_printf(struct sg_str *str, const char *fmt, ...)
385 __SG_FORMAT(2, 3);
386
393SG_EXTERN const char *sg_str_content(struct sg_str *str);
394
401SG_EXTERN size_t sg_str_length(struct sg_str *str);
402
409SG_EXTERN int sg_str_clear(struct sg_str *str);
410
425struct sg_strmap;
426
434typedef int (*sg_strmap_iter_cb)(void *cls, struct sg_strmap *pair);
435
445typedef int (*sg_strmap_sort_cb)(void *cls, struct sg_strmap *pair_a,
446 struct sg_strmap *pair_b);
447
454SG_EXTERN const char *sg_strmap_name(struct sg_strmap *pair);
455
462SG_EXTERN const char *sg_strmap_val(struct sg_strmap *pair);
463
475SG_EXTERN int sg_strmap_add(struct sg_strmap **map, const char *name,
476 const char *val);
477
489SG_EXTERN int sg_strmap_set(struct sg_strmap **map, const char *name,
490 const char *val);
491
502SG_EXTERN int sg_strmap_find(struct sg_strmap *map, const char *name,
503 struct sg_strmap **pair);
504
512SG_EXTERN const char *sg_strmap_get(struct sg_strmap *map, const char *name);
513
523SG_EXTERN int sg_strmap_rm(struct sg_strmap **map, const char *name);
524
534SG_EXTERN int sg_strmap_iter(struct sg_strmap *map, sg_strmap_iter_cb cb,
535 void *cls);
536
545SG_EXTERN int sg_strmap_sort(struct sg_strmap **map, sg_strmap_sort_cb cb,
546 void *cls);
547
554SG_EXTERN unsigned int sg_strmap_count(struct sg_strmap *map);
555
562SG_EXTERN int sg_strmap_next(struct sg_strmap **next);
563
568SG_EXTERN void sg_strmap_cleanup(struct sg_strmap **map);
569
583struct sg_httpauth;
584
590struct sg_httpupld;
591
597struct sg_httpreq;
598
604struct sg_httpres;
605
610struct sg_httpsrv;
611
619typedef void (*sg_httpsrv_cli_cb)(void *cls, const void *client, bool *closed);
620
631typedef bool (*sg_httpauth_cb)(void *cls, struct sg_httpauth *auth,
632 struct sg_httpreq *req, struct sg_httpres *res);
633
648typedef int (*sg_httpupld_cb)(void *cls, void **handle, const char *dir,
649 const char *field, const char *name,
650 const char *mime, const char *encoding);
651
659typedef int (*sg_httpuplds_iter_cb)(void *cls, struct sg_httpupld *upld);
660
667typedef void (*sg_httpreq_cb)(void *cls, struct sg_httpreq *req,
668 struct sg_httpres *res);
669
679SG_EXTERN int sg_httpauth_set_realm(struct sg_httpauth *auth,
680 const char *realm);
681
688SG_EXTERN const char *sg_httpauth_realm(struct sg_httpauth *auth);
689
701SG_EXTERN int sg_httpauth_deny2(struct sg_httpauth *auth, const char *reason,
702 const char *content_type, unsigned int status);
703
714SG_EXTERN int sg_httpauth_deny(struct sg_httpauth *auth, const char *reason,
715 const char *content_type);
716
724SG_EXTERN int sg_httpauth_cancel(struct sg_httpauth *auth);
725
732SG_EXTERN const char *sg_httpauth_usr(struct sg_httpauth *auth);
733
740SG_EXTERN const char *sg_httpauth_pwd(struct sg_httpauth *auth);
741
751SG_EXTERN int sg_httpuplds_iter(struct sg_httpupld *uplds,
752 sg_httpuplds_iter_cb cb, void *cls);
753
760SG_EXTERN int sg_httpuplds_next(struct sg_httpupld **upld);
761
768SG_EXTERN unsigned int sg_httpuplds_count(struct sg_httpupld *uplds);
769
776SG_EXTERN void *sg_httpupld_handle(struct sg_httpupld *upld);
777
784SG_EXTERN const char *sg_httpupld_dir(struct sg_httpupld *upld);
785
792SG_EXTERN const char *sg_httpupld_field(struct sg_httpupld *upld);
793
800SG_EXTERN const char *sg_httpupld_name(struct sg_httpupld *upld);
801
808SG_EXTERN const char *sg_httpupld_mime(struct sg_httpupld *upld);
809
816SG_EXTERN const char *sg_httpupld_encoding(struct sg_httpupld *upld);
817
824SG_EXTERN uint64_t sg_httpupld_size(struct sg_httpupld *upld);
825
836SG_EXTERN int sg_httpupld_save(struct sg_httpupld *upld, bool overwritten);
837
848SG_EXTERN int sg_httpupld_save_as(struct sg_httpupld *upld, const char *path,
849 bool overwritten);
850
857SG_EXTERN struct sg_httpsrv *sg_httpreq_srv(struct sg_httpreq *req);
858
866SG_EXTERN struct sg_strmap **sg_httpreq_headers(struct sg_httpreq *req);
867
875SG_EXTERN struct sg_strmap **sg_httpreq_cookies(struct sg_httpreq *req);
876
884SG_EXTERN struct sg_strmap **sg_httpreq_params(struct sg_httpreq *req);
885
893SG_EXTERN struct sg_strmap **sg_httpreq_fields(struct sg_httpreq *req);
894
901SG_EXTERN const char *sg_httpreq_version(struct sg_httpreq *req);
902
909SG_EXTERN const char *sg_httpreq_method(struct sg_httpreq *req);
910
917SG_EXTERN const char *sg_httpreq_path(struct sg_httpreq *req);
918
926SG_EXTERN struct sg_str *sg_httpreq_payload(struct sg_httpreq *req);
927
934SG_EXTERN bool sg_httpreq_is_uploading(struct sg_httpreq *req);
935
943SG_EXTERN struct sg_httpupld *sg_httpreq_uploads(struct sg_httpreq *req);
944
951SG_EXTERN const void *sg_httpreq_client(struct sg_httpreq *req);
952
953#ifdef SG_HTTPS_SUPPORT
954
961SG_EXTERN void *sg_httpreq_tls_session(struct sg_httpreq *req);
962
963#endif /* SG_HTTPS_SUPPORT */
964
980SG_EXTERN int sg_httpreq_isolate(struct sg_httpreq *req, sg_httpreq_cb cb,
981 void *cls);
982
990SG_EXTERN int sg_httpreq_set_user_data(struct sg_httpreq *req, void *data);
991
998SG_EXTERN void *sg_httpreq_user_data(struct sg_httpreq *req);
999
1007SG_EXTERN struct sg_strmap **sg_httpres_headers(struct sg_httpres *res);
1008
1018SG_EXTERN int sg_httpres_set_cookie(struct sg_httpres *res, const char *name,
1019 const char *val);
1020
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), \
1035 (status))
1036
1049SG_EXTERN int sg_httpres_sendbinary(struct sg_httpres *res, void *buf,
1050 size_t size, const char *content_type,
1051 unsigned int status);
1052
1065#define sg_httpres_download(res, filename, status) \
1066 sg_httpres_sendfile2((res), 0, 0, 0, (filename), "attachment", (status))
1067
1080#define sg_httpres_render(res, filename, status) \
1081 sg_httpres_sendfile2((res), 0, 0, 0, (filename), "inline", (status))
1082
1104SG_EXTERN int sg_httpres_sendfile2(struct sg_httpres *res, uint64_t size,
1105 uint64_t max_size, uint64_t offset,
1106 const char *filename,
1107 const char *disposition,
1108 unsigned int status);
1109
1128SG_EXTERN int sg_httpres_sendfile(struct sg_httpres *res, uint64_t size,
1129 uint64_t max_size, uint64_t offset,
1130 const char *filename, bool downloaded,
1131 unsigned int status);
1132
1147SG_EXTERN int sg_httpres_sendstream(struct sg_httpres *res, uint64_t size,
1148 sg_read_cb read_cb, void *handle,
1149 sg_free_cb free_cb, unsigned int status);
1150
1151#ifdef SG_HTTP_COMPRESSION
1152
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))
1173
1192SG_EXTERN int sg_httpres_zsendbinary2(struct sg_httpres *res, int level,
1193 void *buf, size_t size,
1194 const char *content_type,
1195 unsigned int status);
1196
1214SG_EXTERN int sg_httpres_zsendbinary(struct sg_httpres *res, void *buf,
1215 size_t size, const char *content_type,
1216 unsigned int status);
1217
1236SG_EXTERN int sg_httpres_zsendstream2(struct sg_httpres *res, int level,
1237 uint64_t size, sg_read_cb read_cb,
1238 void *handle, sg_free_cb free_cb,
1239 unsigned int status);
1240
1257SG_EXTERN int sg_httpres_zsendstream(struct sg_httpres *res, sg_read_cb read_cb,
1258 void *handle, sg_free_cb free_cb,
1259 unsigned int status);
1260
1277#define sg_httpres_zdownload(res, filename, status) \
1278 sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "attachment", (status))
1279
1296#define sg_httpres_zrender(res, filename, status) \
1297 sg_httpres_zsendfile2((res), 1, 0, 0, 0, (filename), "inline", (status))
1298
1325SG_EXTERN int sg_httpres_zsendfile2(struct sg_httpres *res, int level,
1326 uint64_t size, uint64_t max_size,
1327 uint64_t offset, const char *filename,
1328 const char *disposition,
1329 unsigned int status);
1330
1353SG_EXTERN int sg_httpres_zsendfile(struct sg_httpres *res, uint64_t size,
1354 uint64_t max_size, uint64_t offset,
1355 const char *filename, bool downloaded,
1356 unsigned int status);
1357
1358#endif /* SG_HTTP_COMPRESSION */
1359
1367SG_EXTERN int sg_httpres_reset(struct sg_httpres *res);
1368
1376SG_EXTERN int sg_httpres_clear(struct sg_httpres *res);
1377
1384SG_EXTERN bool sg_httpres_is_empty(struct sg_httpres *res);
1385
1401 sg_httpreq_cb req_cb,
1402 sg_err_cb err_cb,
1403 void *cls) __SG_MALLOC;
1404
1415 void *cls) __SG_MALLOC;
1416
1423SG_EXTERN void sg_httpsrv_free(struct sg_httpsrv *srv);
1424
1425#ifdef SG_HTTPS_SUPPORT
1426
1452SG_EXTERN bool sg_httpsrv_tls_listen4(struct sg_httpsrv *srv, const char *key,
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);
1458
1481SG_EXTERN bool sg_httpsrv_tls_listen3(struct sg_httpsrv *srv, const char *key,
1482 const char *pwd, const char *cert,
1483 const char *trust, const char *dhparams,
1484 const char *priorities, uint16_t port,
1485 bool threaded);
1486
1507SG_EXTERN bool sg_httpsrv_tls_listen2(struct sg_httpsrv *srv, const char *key,
1508 const char *pwd, const char *cert,
1509 const char *trust, const char *dhparams,
1510 uint16_t port, bool threaded);
1511
1527SG_EXTERN bool sg_httpsrv_tls_listen(struct sg_httpsrv *srv, const char *key,
1528 const char *cert, uint16_t port,
1529 bool threaded);
1530
1531#endif /* SG_HTTPS_SUPPORT */
1532
1547SG_EXTERN bool sg_httpsrv_listen2(struct sg_httpsrv *srv, const char *hostname,
1548 uint16_t port, uint32_t backlog,
1549 bool threaded);
1550
1562SG_EXTERN bool sg_httpsrv_listen(struct sg_httpsrv *srv, uint16_t port,
1563 bool threaded);
1564
1572SG_EXTERN int sg_httpsrv_shutdown(struct sg_httpsrv *srv);
1573
1580SG_EXTERN uint16_t sg_httpsrv_port(struct sg_httpsrv *srv);
1581
1588SG_EXTERN bool sg_httpsrv_is_threaded(struct sg_httpsrv *srv);
1589
1598SG_EXTERN int sg_httpsrv_set_cli_cb(struct sg_httpsrv *srv,
1599 sg_httpsrv_cli_cb cb, void *cls);
1600
1615 void *cls, sg_write_cb write_cb,
1616 sg_free_cb free_cb, sg_save_cb save_cb,
1617 sg_save_as_cb save_as_cb);
1618
1626SG_EXTERN int sg_httpsrv_set_upld_dir(struct sg_httpsrv *srv, const char *dir);
1627
1634SG_EXTERN const char *sg_httpsrv_upld_dir(struct sg_httpsrv *srv);
1635
1643SG_EXTERN int sg_httpsrv_set_post_buf_size(struct sg_httpsrv *srv, size_t size);
1644
1651SG_EXTERN size_t sg_httpsrv_post_buf_size(struct sg_httpsrv *srv);
1652
1660SG_EXTERN int sg_httpsrv_set_payld_limit(struct sg_httpsrv *srv, size_t limit);
1661
1668SG_EXTERN size_t sg_httpsrv_payld_limit(struct sg_httpsrv *srv);
1669
1677SG_EXTERN int sg_httpsrv_set_uplds_limit(struct sg_httpsrv *srv,
1678 uint64_t limit);
1679
1686SG_EXTERN uint64_t sg_httpsrv_uplds_limit(struct sg_httpsrv *srv);
1687
1697 unsigned int size);
1698
1705SG_EXTERN unsigned int sg_httpsrv_thr_pool_size(struct sg_httpsrv *srv);
1706
1714SG_EXTERN int sg_httpsrv_set_con_timeout(struct sg_httpsrv *srv,
1715 unsigned int timeout);
1716
1723SG_EXTERN unsigned int sg_httpsrv_con_timeout(struct sg_httpsrv *srv);
1724
1732SG_EXTERN int sg_httpsrv_set_con_limit(struct sg_httpsrv *srv,
1733 unsigned int limit);
1734
1741SG_EXTERN unsigned int sg_httpsrv_con_limit(struct sg_httpsrv *srv);
1742
1750SG_EXTERN void *sg_httpsrv_handle(struct sg_httpsrv *srv);
1751
1754#ifdef SG_PATH_ROUTING
1755
1769struct sg_entrypoint;
1770
1777SG_EXTERN const char *sg_entrypoint_name(struct sg_entrypoint *entrypoint);
1778
1786SG_EXTERN int sg_entrypoint_set_user_data(struct sg_entrypoint *entrypoint,
1787 void *data);
1788
1795SG_EXTERN void *sg_entrypoint_user_data(struct sg_entrypoint *entrypoint);
1796
1802struct sg_entrypoints;
1803
1812typedef int (*sg_entrypoints_iter_cb)(void *cls,
1813 struct sg_entrypoint *entrypoint);
1814
1820SG_EXTERN struct sg_entrypoints *sg_entrypoints_new(void) __SG_MALLOC;
1821
1826SG_EXTERN void sg_entrypoints_free(struct sg_entrypoints *entrypoints);
1827
1838SG_EXTERN int sg_entrypoints_add(struct sg_entrypoints *entrypoints,
1839 const char *path, void *user_data);
1840
1850SG_EXTERN int sg_entrypoints_rm(struct sg_entrypoints *entrypoints,
1851 const char *path);
1852
1862SG_EXTERN int sg_entrypoints_iter(struct sg_entrypoints *entrypoints,
1863 sg_entrypoints_iter_cb cb, void *cls);
1864
1871SG_EXTERN int sg_entrypoints_clear(struct sg_entrypoints *entrypoints);
1872
1884SG_EXTERN int sg_entrypoints_find(struct sg_entrypoints *entrypoints,
1885 struct sg_entrypoint **entrypoint,
1886 const char *path);
1887
1893struct sg_route;
1894
1904typedef int (*sg_segments_iter_cb)(void *cls, unsigned int index,
1905 const char *segment);
1906
1916typedef int (*sg_vars_iter_cb)(void *cls, const char *name, const char *val);
1917
1923typedef void (*sg_route_cb)(void *cls, struct sg_route *route);
1924
1932typedef int (*sg_routes_iter_cb)(void *cls, struct sg_route *route);
1933
1940SG_EXTERN void *sg_route_handle(struct sg_route *route);
1941
1948SG_EXTERN void *sg_route_match(struct sg_route *route);
1949
1957SG_EXTERN const char *sg_route_rawpattern(struct sg_route *route);
1958
1968SG_EXTERN char *sg_route_pattern(struct sg_route *route) __SG_MALLOC;
1969
1976SG_EXTERN const char *sg_route_path(struct sg_route *route);
1977
1987SG_EXTERN int sg_route_segments_iter(struct sg_route *route,
1988 sg_segments_iter_cb cb, void *cls);
1989
2000SG_EXTERN int sg_route_vars_iter(struct sg_route *route, sg_vars_iter_cb cb,
2001 void *cls);
2002
2009SG_EXTERN void *sg_route_user_data(struct sg_route *route);
2010
2032SG_EXTERN int sg_routes_add2(struct sg_route **routes, struct sg_route **route,
2033 const char *pattern, char *errmsg, size_t errlen,
2034 sg_route_cb cb, void *cls);
2035
2054SG_EXTERN bool sg_routes_add(struct sg_route **routes, const char *pattern,
2055 sg_route_cb cb, void *cls);
2056
2066SG_EXTERN int sg_routes_rm(struct sg_route **routes, const char *pattern);
2067
2077SG_EXTERN int sg_routes_iter(struct sg_route *routes, sg_routes_iter_cb cb,
2078 void *cls);
2079
2086SG_EXTERN int sg_routes_next(struct sg_route **route);
2087
2094SG_EXTERN unsigned int sg_routes_count(struct sg_route *routes);
2095
2100SG_EXTERN int sg_routes_cleanup(struct sg_route **routes);
2101
2107struct sg_router;
2108
2118typedef int (*sg_router_dispatch_cb)(void *cls, const char *path,
2119 struct sg_route *route);
2120
2129typedef int (*sg_router_match_cb)(void *cls, struct sg_route *route);
2130
2139SG_EXTERN struct sg_router *sg_router_new(struct sg_route *routes) __SG_MALLOC;
2140
2145SG_EXTERN void sg_router_free(struct sg_router *router);
2146
2167SG_EXTERN int sg_router_dispatch2(struct sg_router *router, const char *path,
2168 void *user_data,
2169 sg_router_dispatch_cb dispatch_cb, void *cls,
2170 sg_router_match_cb match_cb);
2171
2186SG_EXTERN int sg_router_dispatch(struct sg_router *router, const char *path,
2187 void *user_data);
2188
2191#endif /* SG_PATH_ROUTING */
2192
2193#ifdef SG_MATH_EXPR_EVAL
2194
2206struct sg_expr;
2207
2238
2244struct sg_expr_argument;
2245
2255typedef double (*sg_expr_func)(void *cls, struct sg_expr_argument *args,
2256 const char *identifier);
2257
2267 const char *identifier;
2269 void *cls;
2270};
2271
2278SG_EXTERN struct sg_expr *sg_expr_new(void) __SG_MALLOC;
2279
2285SG_EXTERN void sg_expr_free(struct sg_expr *expr);
2286
2302SG_EXTERN int sg_expr_compile(struct sg_expr *expr, const char *str, size_t len,
2303 struct sg_expr_extension *extensions);
2304
2311SG_EXTERN int sg_expr_clear(struct sg_expr *expr);
2312
2319SG_EXTERN double sg_expr_eval(struct sg_expr *expr);
2320
2331SG_EXTERN double sg_expr_var(struct sg_expr *expr, const char *name,
2332 size_t len);
2333
2344SG_EXTERN int sg_expr_set_var(struct sg_expr *expr, const char *name,
2345 size_t len, double val);
2346
2354SG_EXTERN double sg_expr_arg(struct sg_expr_argument *args, int index);
2355
2362SG_EXTERN int sg_expr_near(struct sg_expr *expr);
2363
2371SG_EXTERN enum sg_expr_err_type sg_expr_err(struct sg_expr *expr);
2372
2379SG_EXTERN const char *sg_expr_strerror(struct sg_expr *expr);
2380
2389SG_EXTERN double sg_expr_calc(const char *str, size_t len);
2390
2393#endif /* SG_MATH_EXPR_EVAL */
2394
2395#ifdef __cplusplus
2396}
2397#endif
2398
2399#endif /* SAGUI_H */
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)
ssize_t sg_eor(bool err)
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
void sg_free(void *ptr)
double(* sg_pow_func)(double x, double y)
Definition sagui.h:122
Definition sagui.h:2262
const char * identifier
Definition sagui.h:2267
sg_expr_func func
Definition sagui.h:2265
void * cls
Definition sagui.h:2269