repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
zap
github_2023
zigzap
c
mustache_on_section_test
static int32_t mustache_on_section_test(mustache_section_s *section, const char *name, uint32_t name_len, uint8_t callable) { FIOBJ o = fiobj_mustache_find_obj(section, name, name_len); if (!o || FIOBJ_TYPE_IS(o, FIOBJ_T_FALSE)) ret...
/** * Called for nested sections, must return the number of objects in the new * subsection (depending on the argument's name). * * Arrays should return the number of objects in the array. * * `true` values should return 1. * * `false` values should return 0. * * A return value of -1 will stop processing with...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L191-L201
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
mustache_on_section_start
static int mustache_on_section_start(mustache_section_s *section, char const *name, uint32_t name_len, uint32_t index) { FIOBJ o = fiobj_mustache_find_obj(section, name, name_len); if (!o) return -1; if (FIOBJ_TYPE_IS(o, FIOBJ_T_ARRAY))...
/** * Called when entering a nested section. * * `index` is a zero based index indicating the number of repetitions that * occurred so far (same as the array index for arrays). * * A return value of -1 will stop processing with an error. * * Note: this is a good time to update the subsection's `udata` with the ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L215-L226
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
mustache_on_formatting_error
static void mustache_on_formatting_error(void *udata1, void *udata2) { (void)udata1; (void)udata2; }
/** * Called for cleanup in case of error. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_mustache.c#L231-L234
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_num_new_bignum
FIOBJ fiobj_num_new_bignum(intptr_t num) { fiobj_num_s *o = fio_malloc(sizeof(*o)); if (!o) { perror("ERROR: fiobj number couldn't allocate memory"); exit(errno); } *o = (fiobj_num_s){ .head = { .type = FIOBJ_T_NUMBER, .ref = 1, }, .i = num, ...
/* ***************************************************************************** Number API ***************************************************************************** */ /** Creates a Number object. Remember to use `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_numbers.c#L106-L121
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_num_tmp
FIOBJ fiobj_num_tmp(intptr_t num) { static __thread fiobj_num_s ret; ret = (fiobj_num_s){ .head = {.type = FIOBJ_T_NUMBER, .ref = ((~(uint32_t)0) >> 4)}, .i = num, }; return (FIOBJ)&ret; }
/** Mutates a Big Number object's value. Effects every object's reference! */ // void fiobj_num_set(FIOBJ target, intptr_t num) { // assert(FIOBJ_TYPE_IS(target, FIOBJ_T_NUMBER) && // FIOBJ_IS_ALLOCATED(target)); obj2num(target)->i = num; // } /** Creates a temporary Number object. This ignores `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_numbers.c#L130-L137
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_float_new
FIOBJ fiobj_float_new(double num) { fiobj_float_s *o = fio_malloc(sizeof(*o)); if (!o) { perror("ERROR: fiobj float couldn't allocate memory"); exit(errno); } *o = (fiobj_float_s){ .head = { .type = FIOBJ_T_FLOAT, .ref = 1, }, .f = num, }; ...
/* ***************************************************************************** Float API ***************************************************************************** */ /** Creates a Float object. Remember to use `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_numbers.c#L144-L159
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_float_set
void fiobj_float_set(FIOBJ obj, double num) { assert(FIOBJ_TYPE_IS(obj, FIOBJ_T_FLOAT)); obj2float(obj)->f = num; }
/** Mutates a Float object's value. Effects every object's reference! */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_numbers.c#L162-L165
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_float_tmp
FIOBJ fiobj_float_tmp(double num) { static __thread fiobj_float_s ret; ret = (fiobj_float_s){ .head = { .type = FIOBJ_T_FLOAT, .ref = ((~(uint32_t)0) >> 4), }, .f = num, }; return (FIOBJ)&ret; }
/** Creates a temporary Number object. This ignores `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_numbers.c#L168-L179
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_str2str
static fio_str_info_s fio_str2str(const FIOBJ o) { return fiobj_str_get_cstr(o); }
/* ***************************************************************************** String VTables ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L60-L62
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_buf
FIOBJ fiobj_str_buf(size_t capa) { if (capa) capa = capa + 1; else capa = PAGE_SIZE; fiobj_str_s *s = fio_malloc(sizeof(*s)); if (!s) { perror("ERROR: fiobj string couldn't allocate memory"); exit(errno); } *s = (fiobj_str_s){ .head = { .ref = 1, ...
/* ***************************************************************************** String API ***************************************************************************** */ /** Creates a buffer String object. Remember to use `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L106-L129
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_new
FIOBJ fiobj_str_new(const char *str, size_t len) { fiobj_str_s *s = fio_malloc(sizeof(*s)); if (!s) { perror("ERROR: fiobj string couldn't allocate memory"); exit(errno); } *s = (fiobj_str_s){ .head = { .ref = 1, .type = FIOBJ_T_STRING, }, .str...
/** Creates a String object. Remember to use `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L132-L150
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_move
FIOBJ fiobj_str_move(char *str, size_t len, size_t capacity) { fiobj_str_s *s = fio_malloc(sizeof(*s)); if (!s) { perror("ERROR: fiobj string couldn't allocate memory"); exit(errno); } *s = (fiobj_str_s){ .head = { .ref = 1, .type = FIOBJ_T_STRING, }...
/** * Creates a String object. Remember to use `fiobj_free`. * * It's possible to wrap a previosly allocated memory block in a FIOBJ String * object, as long as it was allocated using `fio_malloc`. * * The ownership of the memory indicated by `str` will "move" to the object and * will be freed (using `fio_free`)...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L162-L177
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_tmp
FIOBJ fiobj_str_tmp(void) { static __thread fiobj_str_s tmp = { .head = { .ref = ((~(uint32_t)0) >> 4), .type = FIOBJ_T_STRING, }, .str = {.small = 1}, }; tmp.str.frozen = 0; fio_str_resize(&tmp.str, 0); return ((uintptr_t)&tmp | FIOBJECT_STRING_FLAG...
/** * Returns a thread-static temporary string. Avoid calling `fiobj_dup` or * `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L183-L195
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_freeze
void fiobj_str_freeze(FIOBJ str) { if (FIOBJ_TYPE_IS(str, FIOBJ_T_STRING)) fio_str_freeze(&obj2str(str)->str); }
/** Prevents the String object from being changed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L198-L201
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_capa_assert
size_t fiobj_str_capa_assert(FIOBJ str, size_t size) { assert(FIOBJ_TYPE_IS(str, FIOBJ_T_STRING)); if (obj2str(str)->str.frozen) return 0; fio_str_info_s state = fio_str_capa_assert(&obj2str(str)->str, size); return state.capa; }
/** Confirms the requested capacity is available and allocates as required. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L204-L211
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_capa
size_t fiobj_str_capa(FIOBJ str) { assert(FIOBJ_TYPE_IS(str, FIOBJ_T_STRING)); return fio_str_capa(&obj2str(str)->str); }
/** Return's a String's capacity, if any. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L214-L217
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_resize
void fiobj_str_resize(FIOBJ str, size_t size) { assert(FIOBJ_TYPE_IS(str, FIOBJ_T_STRING)); fio_str_resize(&obj2str(str)->str, size); obj2str(str)->hash = 0; return; }
/** Resizes a String object, allocating more memory if required. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L220-L225
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_compact
void fiobj_str_compact(FIOBJ str) { assert(FIOBJ_TYPE_IS(str, FIOBJ_T_STRING)); fio_str_compact(&obj2str(str)->str); return; }
/** Deallocates any unnecessary memory (if supported by OS). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L228-L232
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_clear
void fiobj_str_clear(FIOBJ str) { assert(FIOBJ_TYPE_IS(str, FIOBJ_T_STRING)); fio_str_resize(&obj2str(str)->str, 0); obj2str(str)->hash = 0; }
/** Empties a String's data. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L235-L239
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_write
size_t fiobj_str_write(FIOBJ dest, const char *data, size_t len) { assert(FIOBJ_TYPE_IS(dest, FIOBJ_T_STRING)); if (obj2str(dest)->str.frozen) return 0; obj2str(dest)->hash = 0; return fio_str_write(&obj2str(dest)->str, data, len).len; }
/** * Writes data at the end of the string, resizing the string as required. * Returns the new length of the String */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L245-L251
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_write_i
size_t fiobj_str_write_i(FIOBJ dest, int64_t num) { assert(FIOBJ_TYPE_IS(dest, FIOBJ_T_STRING)); if (obj2str(dest)->str.frozen) return 0; obj2str(dest)->hash = 0; return fio_str_write_i(&obj2str(dest)->str, num).len; }
/** * Writes a number at the end of the String using normal base 10 notation. * * Returns the new length of the String */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L258-L264
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_printf
size_t fiobj_str_printf(FIOBJ dest, const char *format, ...) { assert(FIOBJ_TYPE_IS(dest, FIOBJ_T_STRING)); if (obj2str(dest)->str.frozen) return 0; obj2str(dest)->hash = 0; va_list argv; va_start(argv, format); fio_str_info_s state = fio_str_vprintf(&obj2str(dest)->str, format, argv); va_end(argv); ...
/** * Writes data at the end of the string, resizing the string as required. * Returns the new length of the String */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L270-L280
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_readfile
size_t fiobj_str_readfile(FIOBJ dest, const char *filename, intptr_t start_at, intptr_t limit) { fio_str_info_s state = fio_str_readfile(&obj2str(dest)->str, filename, start_at, limit); return state.len; }
/** Dumps the `filename` file's contents at the end of a String. If `limit == * 0`, than the data will be read until EOF. * * If the file can't be located, opened or read, or if `start_at` is beyond * the EOF position, NULL is returned. * * Remember to use `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L299-L304
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_concat
size_t fiobj_str_concat(FIOBJ dest, FIOBJ obj) { assert(FIOBJ_TYPE_IS(dest, FIOBJ_T_STRING)); if (obj2str(dest)->str.frozen) return 0; obj2str(dest)->hash = 0; fio_str_info_s o = fiobj_obj2cstr(obj); if (o.len == 0) return fio_str_len(&obj2str(dest)->str); return fio_str_write(&obj2str(dest)->str, o...
/** * Writes data at the end of the string, resizing the string as required. * Returns the new length of the String */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L310-L319
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_str_hash
uint64_t fiobj_str_hash(FIOBJ o) { assert(FIOBJ_TYPE_IS(o, FIOBJ_T_STRING)); // if (obj2str(o)->is_small) { // return fiobj_hash_string(STR_INTENAL_STR(o), STR_INTENAL_LEN(o)); // } else if (obj2str(o)->hash) { return obj2str(o)->hash; } fio_str_info_s state = fio_str_info(&obj2str(o)->str); obj2s...
/** * Calculates a String's SipHash value for use as a HashMap key. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobj_str.c#L324-L335
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_atol
int64_t __attribute__((weak)) fio_atol(char **pstr) { return strtoll(*pstr, pstr, 0); }
/** * We include this in case the parser is used outside of facil.io. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L73-L75
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_atof
double __attribute__((weak)) fio_atof(char **pstr) { return strtod(*pstr, pstr); }
/** * We include this in case the parser is used outside of facil.io. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L81-L83
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_each2
size_t fiobj_each2(FIOBJ o, int (*task)(FIOBJ obj, void *arg), void *arg) { if (!o || !FIOBJ_IS_ALLOCATED(o) || (FIOBJECT2VTBL(o)->each == NULL)) { task(o, arg); return 1; } /* run task for root object */ if (task(o, arg) == -1) return 1; uintptr_t pos = 0; fiobj_stack_s stack = FIO_ARY_INIT; ...
/** * Single layer iteration using a callback for each nested fio object. * * Accepts any `FIOBJ ` type but only collections (Arrays and Hashes) are * processed. The container itself (the Array or the Hash) is **not** processed * (unlike `fiobj_each2`). * * The callback task function must accept an object and an...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L341-L380
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_dealloc_task
static void fiobj_dealloc_task(FIOBJ o, void *stack_) { // if (!o) // fprintf(stderr, "* WARN: freeing a NULL no-object\n"); // else // fprintf(stderr, "* freeing object %s\n", fiobj_obj2cstr(o).data); if (!o || !FIOBJ_IS_ALLOCATED(o)) return; if (OBJREF_REM(o)) return; if (!FIOBJECT2VTBL(o)->...
/* ***************************************************************************** Free complex objects (objects with nesting) ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L386-L401
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_free_complex_object
void fiobj_free_complex_object(FIOBJ o) { fiobj_stack_s stack = FIO_ARY_INIT; do { FIOBJECT2VTBL(o)->dealloc(o, fiobj_dealloc_task, &stack); } while (!fiobj_stack_pop(&stack, &o)); fiobj_stack_free(&stack); }
/** * Decreases an object's reference count, releasing memory and * resources. * * This function affects nested objects, meaning that when an Array or * a Hash object is passed along, it's children (nested objects) are * also freed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L410-L416
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobj_iseq____internal_complex__
int fiobj_iseq____internal_complex__(FIOBJ o, FIOBJ o2) { // if (FIOBJECT2VTBL(o)->each && FIOBJECT2VTBL(o)->count(o)) // return int fiobj_iseq____internal_complex__(const FIOBJ o, const FIOBJ // o2); fiobj_stack_s left = FIO_ARY_INIT, right = FIO_ARY_INIT, queue = FIO_ARY_INIT; do { fiobj_each1(o, 0,...
/** used internally for complext nested tests (Array / Hash types) */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L446-L483
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fiobject___noop_dealloc
void fiobject___noop_dealloc(FIOBJ o, void (*task)(FIOBJ, void *), void *arg) { (void)o; (void)task; (void)arg; }
/* ***************************************************************************** Defaults / NOOPs ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/fiobj/fiobject.c#L489-L493
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
fio_tls_alpn_add
void __attribute__((weak)) fio_tls_alpn_add(void *tls, const char *protocol_name, void (*callback)(intptr_t uuid, void *udata_connection, void *udata_tls), void *udata_tls, void (*on_cleanup)(void *udata_tls)) { FIO_LOG_FATAL("HTTP SSL/TLS required b...
/* ***************************************************************************** SSL/TLS patch ***************************************************************************** */ /** * Adds an ALPN protocol callback to the SSL/TLS context. * * The first protocol added will act as the default protocol to be selected. *...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L45-L57
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_set_header
int http_set_header(http_s *r, FIOBJ name, FIOBJ value) { if (HTTP_INVALID_HANDLE(r) || !name) { fiobj_free(value); return -1; } set_header_add(r->private_data.out_headers, name, value); return 0; }
/** * Sets a response header, taking ownership of the value object, but NOT the * name object (so name objects could be reused in future responses). * * Returns -1 on error and 0 on success. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L163-L170
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_set_header2
int http_set_header2(http_s *r, fio_str_info_s n, fio_str_info_s v) { if (HTTP_INVALID_HANDLE(r) || !n.data || !n.len || (v.data && !v.len)) return -1; FIOBJ tmp = fiobj_str_new(n.data, n.len); int ret = http_set_header(r, tmp, fiobj_str_new(v.data, v.len)); fiobj_free(tmp); return ret; }
/** * Sets a response header. * * Returns -1 on error and 0 on success. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L176-L183
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_send_body
int http_send_body(http_s *r, void *data, uintptr_t length) { if (HTTP_INVALID_HANDLE(r)) return -1; if (!length || !data) { http_finish(r); return 0; } add_content_length(r, length); // add_content_type(r); add_date(r); return ((http_vtable_s *)r->private_data.vtbl) ->http_send_body(r, ...
/** * Sends the response headers and body. * * Returns -1 on error and 0 on success. * * AFTER THIS FUNCTION IS CALLED, THE `http_s` OBJECT IS NO LONGER VALID. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L336-L348
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sendfile
int http_sendfile(http_s *r, int fd, uintptr_t length, uintptr_t offset) { if (HTTP_INVALID_HANDLE(r)) { close(fd); return -1; }; add_content_length(r, length); add_content_type(r); add_date(r); return ((http_vtable_s *)r->private_data.vtbl) ->http_sendfile(r, fd, length, offset); }
/** * Sends the response headers and the specified file (the response's body). * * Returns -1 on error and 0 on success. * * AFTER THIS FUNCTION IS CALLED, THE `http_s` OBJECT IS NO LONGER VALID. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L356-L366
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sendfile2
int http_sendfile2(http_s *h, const char *prefix, size_t prefix_len, const char *encoded, size_t encoded_len) { if (HTTP_INVALID_HANDLE(h)) return -1; struct stat file_data = {.st_size = 0}; static uint64_t accept_enc_hash = 0; if (!accept_enc_hash) accept_enc_hash = fiobj_hash_string...
/** * Sends the response headers and the specified file (the response's body). * * Returns -1 eton error and 0 on success. * * AFTER THIS FUNCTION IS CALLED, THE `http_s` OBJECT IS NO LONGER VALID. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L389-L616
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_send_error
int http_send_error(http_s *r, size_t error) { if (!r || !r->private_data.out_headers) { return -1; } if (error < 100 || error >= 1000) error = 500; r->status = error; char buffer[16]; buffer[0] = '/'; size_t pos = 1 + fio_ltoa(buffer + 1, error, 10); buffer[pos++] = '.'; buffer[pos++] = 'h'; ...
/** * Sends an HTTP error response. * * Returns -1 on error and 0 on success. * * AFTER THIS FUNCTION IS CALLED, THE `http_s` OBJECT IS NO LONGER VALID. * * The `uuid` argument is optional and will be used only if the `http_s` * argument is set to NULL. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L628-L653
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_finish
void http_finish(http_s *r) { if (!r || !r->private_data.vtbl) { return; } add_content_length(r, 0); add_date(r); ((http_vtable_s *)r->private_data.vtbl)->http_finish(r); }
/** * Sends the response headers for a header only response. * * AFTER THIS FUNCTION IS CALLED, THE `http_s` OBJECT IS NO LONGER VALID. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L660-L667
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_push_data
int http_push_data(http_s *r, void *data, uintptr_t length, FIOBJ mime_type) { if (!r || !(http_fio_protocol_s *)r->private_data.flag) return -1; return ((http_vtable_s *)r->private_data.vtbl) ->http_push_data(r, data, length, mime_type); }
/** * Pushes a data response when supported (HTTP/2 only). * * Returns -1 on error and 0 on success. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L673-L678
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_push_file
int http_push_file(http_s *h, FIOBJ filename, FIOBJ mime_type) { if (HTTP_INVALID_HANDLE(h)) return -1; return ((http_vtable_s *)h->private_data.vtbl) ->http_push_file(h, filename, mime_type); }
/** * Pushes a file response when supported (HTTP/2 only). * * If `mime_type` is NULL, an attempt at automatic detection using * `filename` will be made. * * Returns -1 on error and 0 on success. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L687-L692
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_pause_wrapper
static void http_pause_wrapper(void *h_, void *task_) { void (*task)(void *h) = (void (*)(void *h))((uintptr_t)task_); task(h_); }
/* perform the pause task outside of the connection's lock */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L737-L740
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_resume_wrapper
static void http_resume_wrapper(intptr_t uuid, fio_protocol_s *p_, void *arg) { http_fio_protocol_s *p = (http_fio_protocol_s *)p_; http_pause_handle_s *http = arg; http_s *h = http->h; h->udata = http->udata; http_vtable_s *vtbl = (http_vtable_s *)h->private_data.vtbl; if (http->task) http->task(h); ...
/* perform the resume task within of the connection's lock */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L743-L754
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_resume_fallback_wrapper
static void http_resume_fallback_wrapper(intptr_t uuid, void *arg) { http_pause_handle_s *http = arg; if (http->fallback) http->fallback(http->udata); fio_free(http); (void)uuid; }
/* perform the resume task fallback */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L757-L763
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_pause
void http_pause(http_s *h, void (*task)(http_pause_handle_s *http)) { if (HTTP_INVALID_HANDLE(h)) { return; } http_fio_protocol_s *p = (http_fio_protocol_s *)h->private_data.flag; http_vtable_s *vtbl = (http_vtable_s *)h->private_data.vtbl; http_pause_handle_s *http = fio_malloc(sizeof(*http)); *http = ...
/** * Defers the request / response handling for later. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L768-L782
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_resume
void http_resume(http_pause_handle_s *http, void (*task)(http_s *h), void (*fallback)(void *udata)) { if (!http) return; http->task = task; http->fallback = fallback; fio_defer_io_task(http->uuid, .udata = http, .type = FIO_PR_LOCK_TASK, .task = http_resume_wrapper, ...
/** * Defers the request / response handling for later. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L787-L796
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_hijack
intptr_t http_hijack(http_s *h, fio_str_info_s *leftover) { if (!h) return -1; return ((http_vtable_s *)h->private_data.vtbl)->http_hijack(h, leftover); }
/** * Hijacks the socket away from the HTTP protocol and away from facil.io. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L801-L805
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_on_request_fallback
static void http_on_request_fallback(http_s *h) { http_send_error(h, 404); }
/* ***************************************************************************** Setting the default settings and allocating a persistent copy ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L811-L811
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_peer_addr
fio_str_info_s http_peer_addr(http_s *h) { return fio_peer_addr(((http_fio_protocol_s *)h->private_data.flag)->uuid); }
/** * Returns the direct address of the connected peer (likely an intermediary). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L959-L961
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_on_close_client
static void http_on_close_client(intptr_t uuid, fio_protocol_s *protocol) { http_fio_protocol_s *p = (http_fio_protocol_s *)protocol; http_settings_s *set = p->settings; void (**original)(intptr_t, fio_protocol_s *) = (void (**)(intptr_t, fio_protocol_s *))(set + 1); if (set->on_finish) set->on_finish...
/* ***************************************************************************** HTTP client connections ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L967-L977
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
FIO_IGNORE_MACRO
intptr_t http_connect FIO_IGNORE_MACRO(const char *url, const char *unix_address, struct http_settings_s arg_settings) { if (!arg_settings.on_response && !arg_settings.on_upgrade) { FIO_LOG_ERROR("http_connect requires either an on_resp...
/* sublime text marker */ /** * Connects to an HTTP server as a client. * * Upon a successful connection, the `on_response` callback is called with an * empty `http_s*` handler (status == 0). Use the same API to set it's content * and send the request to the server. The next`on_response` will contain the * respon...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1036-L1163
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_copy2str
static inline void http_sse_copy2str(FIOBJ dest, char *prefix, size_t pre_len, fio_str_info_s data) { if (!data.len) return; const char *stop = data.data + data.len; while (data.len) { fiobj_str_write(dest, prefix, pre_len); char *pos = data.data; while (pos < ...
/* ***************************************************************************** EventSource Support (SSE) Note: * `http_sse_subscribe` and `http_sse_unsubscribe` are implemented in the http_internal logical unit. ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1213-L1232
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_on_message
static void http_sse_on_message(fio_msg_s *msg) { http_sse_internal_s *sse = msg->udata1; struct http_sse_subscribe_args *args = msg->udata2; /* perform a callback */ fio_protocol_s *pr = fio_protocol_try_lock(sse->uuid, FIO_PR_LOCK_TASK); if (!pr) goto postpone; args->on_message(&sse->sse, msg->channel...
/** The on message callback. the `*msg` pointer is to a temporary object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1235-L1250
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_on_unsubscribe
static void http_sse_on_unsubscribe(void *sse_, void *args_) { http_sse_internal_s *sse = sse_; struct http_sse_subscribe_args *args = args_; if (args->on_unsubscribe) args->on_unsubscribe(args->udata); fio_free(args); http_sse_try_free(sse); }
/** An optional callback for when a subscription is fully canceled. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1259-L1266
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_subscribe
uintptr_t http_sse_subscribe(http_sse_s *sse_, struct http_sse_subscribe_args args) { http_sse_internal_s *sse = FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse_); if (sse->uuid == -1) return 0; if (!args.on_message) args.on_message = http_sse_on_message__direct; struct http_s...
/** * Subscribes to a channel. See {struct http_sse_subscribe_args} for possible * arguments. * * Returns a subscription ID on success and 0 on failure. * * All subscriptions are automatically revoked once the connection is closed. * * If the connections subscribes to the same channel more than once, messages ...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1283-L1306
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_unsubscribe
void http_sse_unsubscribe(http_sse_s *sse_, uintptr_t subscription) { if (!sse_ || !subscription) return; http_sse_internal_s *sse = FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse_); subscription_s *sub = (subscription_s *)((fio_ls_s *)subscription)->obj; fio_lock(&sse->lock); fio_ls_remove((fio_ls_s *)sub...
/** * Cancels a subscription and invalidates the subscription object. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1311-L1320
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_upgrade2sse
int http_upgrade2sse(http_s *h, http_sse_s sse) { if (HTTP_INVALID_HANDLE(h)) { if (sse.on_close) sse.on_close(&sse); return -1; } return ((http_vtable_s *)h->private_data.vtbl)->http_upgrade2sse(h, &sse); }
/** * Upgrades an HTTP connection to an EventSource (SSE) connection. * * Thie `http_s` handle will be invalid after this call. * * On HTTP/1.1 connections, this will preclude future requests using the same * connection. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1331-L1338
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_set_timout
void http_sse_set_timout(http_sse_s *sse_, uint8_t timeout) { if (!sse_) return; http_sse_internal_s *sse = FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse_); fio_timeout_set(sse->uuid, timeout); }
/** * Sets the ping interval for SSE connections. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1343-L1348
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_write
int http_sse_write(http_sse_s *sse, struct http_sse_write_args args) { if (!sse || !(args.id.len + args.data.len + args.event.len) || fio_is_closed(FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse)->uuid)) return -1; FIOBJ buf; { /* best guess at data length, ignoring missing fields and multiline data ...
/** * Writes data to an EventSource (SSE) connection. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1354-L1377
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse2uuid
intptr_t http_sse2uuid(http_sse_s *sse) { if (!sse || fio_is_closed(FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse)->uuid)) return -1; return FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse)->uuid; }
/** * Get the connection's UUID (for fio_defer and similar use cases). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1382-L1387
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_close
int http_sse_close(http_sse_s *sse) { if (!sse || fio_is_closed(FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse)->uuid)) return -1; return FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse) ->vtable->http_sse_close(sse); }
/** * Closes an EventSource (SSE) connection. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1392-L1398
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_sse_free
void http_sse_free(http_sse_s *sse) { http_sse_try_free(FIO_LS_EMBD_OBJ(http_sse_internal_s, sse, sse)); }
/** * Frees an SSE handle by reference (decreases the reference count). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1413-L1415
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_urlstr2fiobj
static inline FIOBJ http_urlstr2fiobj(char *s, size_t len) { FIOBJ o = fiobj_str_buf(len); ssize_t l = http_decode_url(fiobj_obj2cstr(o).data, s, len); if (l < 0) { fiobj_free(o); return fiobj_str_new(NULL, 0); /* empty string */ } fiobj_str_resize(o, (size_t)l); return o; }
/* ***************************************************************************** HTTP GET and POST parsing helpers ***************************************************************************** */ /** URL decodes a string, returning a `FIOBJ`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1422-L1431
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_str2fiobj
static inline FIOBJ http_str2fiobj(char *s, size_t len, uint8_t encoded) { switch (len) { case 0: return fiobj_str_new(NULL, 0); /* empty string */ case 4: if (!strncasecmp(s, "true", 4)) return fiobj_true(); if (!strncasecmp(s, "null", 4)) return fiobj_null(); break; case 5: if ...
/** converts a string into a `FIOBJ`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1434-L1463
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_parse_query
void http_parse_query(http_s *h) { if (!h->query) return; if (!h->params) h->params = fiobj_hash_new(); fio_str_info_s q = fiobj_obj2cstr(h->query); do { char *cut = memchr(q.data, '&', q.len); if (!cut) cut = q.data + q.len; char *cut2 = memchr(q.data, '=', (cut - q.data)); if (cu...
/** Parses the query part of an HTTP request/response. Uses `http_add2hash`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1466-L1492
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_parse_cookies
void http_parse_cookies(http_s *h, uint8_t is_url_encoded) { if (!h->headers) return; if (h->cookies && fiobj_hash_count(h->cookies)) { FIO_LOG_WARNING("(http) attempting to parse cookies more than once."); return; } static uint64_t setcookie_header_hash; if (!setcookie_header_hash) setcookie_...
/** Parses any Cookie / Set-Cookie headers, using the `http_add2hash` scheme. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1537-L1579
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_add2hash2
int http_add2hash2(FIOBJ dest, char *name, size_t name_len, FIOBJ val, uint8_t encoded) { if (!name) goto error; FIOBJ nested_ary = FIOBJ_INVALID; char *cut1; /* we can't start with an empty object name */ while (name_len && name[0] == '[') { --name_len; ++name; } if (!name_...
/** * Adds a named parameter to the hash, resolving nesting references. * * i.e.: * * * "name[]" references a nested Array (nested in the Hash). * * "name[key]" references a nested Hash. * * "name[][key]" references a nested Hash within an array. Hash keys will be * unique (repeating a key advances the hash)....
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1597-L1770
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_add2hash
int http_add2hash(FIOBJ dest, char *name, size_t name_len, char *value, size_t value_len, uint8_t encoded) { return http_add2hash2(dest, name, name_len, http_str2fiobj(value, value_len, encoded), encoded); }
/** * Adds a named parameter to the hash, resolving nesting references. * * i.e.: * * * "name[]" references a nested Array (nested in the Hash). * * "name[key]" references a nested Hash. * * "name[][key]" references a nested Hash within an array. Hash keys will be * unique (repeating a key advances the hash)....
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1788-L1792
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mime_parser_on_data
static void http_mime_parser_on_data(http_mime_parser_s *parser, void *name, size_t name_len, void *filename, size_t filename_len, void *mimetype, size_t mimetype_len, void *value, ...
/** Called when all the data is available at once. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1812-L1840
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mime_parser_on_partial_start
static void http_mime_parser_on_partial_start( http_mime_parser_s *parser, void *name, size_t name_len, void *filename, size_t filename_len, void *mimetype, size_t mimetype_len) { http_mime_parser2fio(parser)->partial_length = 0; http_mime_parser2fio(parser)->partial_offset = 0; http_mime_parser2fio(parse...
/** Called when the data didn't fit in the buffer. Data will be streamed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1843-L1867
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mime_parser_on_partial_data
static void http_mime_parser_on_partial_data(http_mime_parser_s *parser, void *value, size_t value_len) { if (!http_mime_parser2fio(parser)->partial_offset) http_mime_parser2fio(parser)->partial_offset = http_mime_parser2fio(parser)->pos + ((uintptr_t)v...
/** Called when partial data is available. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1870-L1879
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mime_parser_on_partial_end
static void http_mime_parser_on_partial_end(http_mime_parser_s *parser) { fio_str_info_s tmp = fiobj_obj2cstr(http_mime_parser2fio(parser)->partial_name); FIOBJ o = FIOBJ_INVALID; if (!http_mime_parser2fio(parser)->partial_length) return; if (http_mime_parser2fio(parser)->partial_length < 42) { /...
/** Called when the partial data is complete. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1882-L1905
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mime_decode_url
static inline size_t http_mime_decode_url(char *dest, const char *encoded, size_t length) { return http_decode_url(dest, encoded, length); }
/** * Called when URL decoding is required. * * Should support inplace decoding (`dest == encoded`). * * Should return the length of the decoded string. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1914-L1917
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_parse_body
int http_parse_body(http_s *h) { static uint64_t content_type_hash; if (!h->body) return -1; if (!content_type_hash) content_type_hash = fiobj_hash_string("content-type", 12); FIOBJ ct = fiobj_hash_get2(h->headers, content_type_hash); fio_str_info_s content_type = fiobj_obj2cstr(ct); if (content_typ...
/** * Attempts to decode the request's body. * * Supported Types include: * * application/x-www-form-urlencoded * * application/json * * multipart/form-data */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1927-L1979
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_req2str
FIOBJ http_req2str(http_s *h) { if (HTTP_INVALID_HANDLE(h) || !fiobj_hash_count(h->headers)) return FIOBJ_INVALID; struct header_writer_s w; w.dest = fiobj_str_buf(0); if (h->status_str) { fiobj_str_join(w.dest, h->version); fiobj_str_write(w.dest, " ", 1); fiobj_str_join(w.dest, fiobj_num_tmp(...
/* ***************************************************************************** HTTP Helper functions that could be used globally ***************************************************************************** */ /** * Returns a String object representing the unparsed HTTP request (HTTP * version is capped at HTTP/1.1...
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L1990-L2032
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_date2rfc2109
size_t http_date2rfc2109(char *target, struct tm *tmbuf) { /* note: day of month is always 2 digits */ char *pos = target; uint16_t tmp; pos[0] = DAY_NAMES[tmbuf->tm_wday][0]; pos[1] = DAY_NAMES[tmbuf->tm_wday][1]; pos[2] = DAY_NAMES[tmbuf->tm_wday][2]; pos[3] = ','; pos[4] = ' '; pos += 5; tmp = tm...
/* HTTP header format for Cookie ages */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2293-L2336
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_time2str
size_t http_time2str(char *target, const time_t t) { /* pre-print time every 1 or 2 seconds or so. */ static __thread time_t cached_tick; static __thread char cached_httpdate[48]; static __thread size_t cached_len; time_t last_tick = fio_last_tick().tv_sec; if ((t | 7) < last_tick) { /* this is a custom...
/** * Prints Unix time to a HTTP time formatted string. * * This variation implements cached results for faster processing, at the * price of a less accurate string. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2344-L2364
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mimetype_register
void http_mimetype_register(char *file_ext, size_t file_ext_len, FIOBJ mime_type_str) { uintptr_t hash = FIO_HASH_FN(file_ext, file_ext_len, 0, 0); if (mime_type_str == FIOBJ_INVALID) { fio_mime_set_remove(&fio_http_mime_types, hash, FIOBJ_INVALID, NULL); } else { FIOBJ old = F...
/** Registers a Mime-Type to be associated with the file extension. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2491-L2507
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mimetype_stats
void http_mimetype_stats(void) { FIO_LOG_DEBUG("HTTP MIME hash storage count/capa: %zu / %zu", fio_mime_set_count(&fio_http_mime_types), fio_mime_set_capa(&fio_http_mime_types)); }
/** Registers a Mime-Type to be associated with the file extension. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2510-L2514
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mimetype_find
FIOBJ http_mimetype_find(char *file_ext, size_t file_ext_len) { uintptr_t hash = FIO_HASH_FN(file_ext, file_ext_len, 0, 0); return fiobj_dup( fio_mime_set_find(&fio_http_mime_types, hash, FIOBJ_INVALID)); }
/** * Finds the mime-type associated with the file extension. * Remember to call `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2520-L2524
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mimetype_find2
FIOBJ http_mimetype_find2(FIOBJ url) { static __thread char buffer[LONGEST_FILE_EXTENSION_LENGTH + 1]; fio_str_info_s ext = {.data = NULL}; FIOBJ mimetype; if (!url) goto finish; fio_str_info_s tmp = fiobj_obj2cstr(url); uint8_t steps = 1; while (tmp.len > steps || steps >= LONGEST_FILE_EXTENSION_LENG...
/** * Finds the mime-type associated with the URL. * Remember to call `fiobj_free`. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2530-L2562
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_mimetype_clear
void http_mimetype_clear(void) { fio_mime_set_free(&fio_http_mime_types); fiobj_free(current_date); current_date = FIOBJ_INVALID; last_date_added = 0; }
/** Clears the Mime-Type registry (it will be empty afterthis call). */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2565-L2570
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http_status2str
fio_str_info_s http_status2str(uintptr_t status) { static const fio_str_info_s status2str[] = { HTTP_SET_STATUS_STR(100, "Continue"), HTTP_SET_STATUS_STR(101, "Switching Protocols"), HTTP_SET_STATUS_STR(102, "Processing"), HTTP_SET_STATUS_STR(103, "Early Hints"), HTTP_SET_STATUS_STR(200,...
// clang-format on /** Returns the status as a C string struct */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http.c#L2616-L2691
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_after_finish
static inline void http1_after_finish(http_s *h) { http1pr_s *p = handle2pr(h); p->stop = p->stop & (~1UL); if (h != &p->request) { http_s_destroy(h, 0); fio_free(h); } else { http_s_clear(h, p->p.settings->log); } if (p->close) fio_close(p->p.uuid); }
/* cleanup an HTTP/1.1 handler object */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L51-L62
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_send_body
static int http1_send_body(http_s *h, void *data, uintptr_t length) { FIOBJ packet = headers2str(h, length); if (!packet) { http1_after_finish(h); return -1; } fiobj_str_write(packet, data, length); fiobj_send_free((handle2pr(h)->p.uuid), packet); http1_after_finish(h); return 0; }
/** Should send existing headers and data */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L177-L188
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_sendfile
static int http1_sendfile(http_s *h, int fd, uintptr_t length, uintptr_t offset) { FIOBJ packet = headers2str(h, 0); if (!packet) { close(fd); http1_after_finish(h); return -1; } if (length < HTTP_MAX_HEADER_LENGTH) { /* optimize away small files */ fio_str_info_s s...
/** Should send existing headers and file */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L190-L220
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
htt1p_finish
static void htt1p_finish(http_s *h) { FIOBJ packet = headers2str(h, 0); if (packet) fiobj_send_free((handle2pr(h)->p.uuid), packet); else { // fprintf(stderr, "WARNING: invalid call to `htt1p_finish`\n"); } http1_after_finish(h); }
/** Should send existing headers or complete streaming */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L223-L231
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_push_data
static int http1_push_data(http_s *h, void *data, uintptr_t length, FIOBJ mime_type) { return -1; (void)h; (void)data; (void)length; (void)mime_type; }
/** Push for data - unsupported. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L233-L240
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_push_file
static int http1_push_file(http_s *h, FIOBJ filename, FIOBJ mime_type) { return -1; (void)h; (void)filename; (void)mime_type; }
/** Push for files - unsupported. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L242-L247
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_pause
static void http1_on_pause(http_s *h, http_fio_protocol_s *pr) { ((http1pr_s *)pr)->stop = 1; fio_suspend(pr->uuid); (void)h; }
/** * Called befor a pause task, */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L252-L256
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_resume
static void http1_on_resume(http_s *h, http_fio_protocol_s *pr) { if (!((http1pr_s *)pr)->stop) { fio_force_event(pr->uuid, FIO_EVENT_ON_DATA); } (void)h; }
/** * called after the resume task had completed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L261-L266
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_websocket_client_on_upgrade
static void http1_websocket_client_on_upgrade(http_s *h, char *proto, size_t len) { http1pr_s *p = handle2pr(h); websocket_settings_s *args = h->udata; const intptr_t uuid = handle2pr(h)->p.uuid; http_settings_s *set = handle2pr(h)->p.settings; set->udata = NULL; ...
/* ***************************************************************************** Websockets Upgrading ***************************************************************************** */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L291-L305
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_upgrade2sse
static int http1_upgrade2sse(http_s *h, http_sse_s *sse) { const intptr_t uuid = handle2pr(h)->p.uuid; /* send response */ h->status = 200; http_set_header(h, HTTP_HEADER_CONTENT_TYPE, fiobj_dup(HTTP_HVALUE_SSE_MIME)); http_set_header(h, HTTP_HEADER_CACHE_CONTROL, fiobj_dup(HTTP_HVALUE_NO_CA...
/** * Upgrades an HTTP connection to an EventSource (SSE) connection. * * Thie `http_s` handle will be invalid after this call. * * On HTTP/1.1 connections, this will preclude future requests using the same * connection. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L463-L506
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_sse_write
static int http1_sse_write(http_sse_s *sse, FIOBJ str) { return fiobj_send_free(((http_sse_internal_s *)sse)->uuid, str); }
/** * Writes data to an EventSource (SSE) connection. * * See the {struct http_sse_write_args} for possible named arguments. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L514-L516
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_sse_close
static int http1_sse_close(http_sse_s *sse) { fio_close(((http_sse_internal_s *)sse)->uuid); return 0; }
/** * Closes an EventSource (SSE) connection. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L521-L524
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_request
static int http1_on_request(http1_parser_s *parser) { http1pr_s *p = parser2http(parser); http_on_request_handler______internal(&http1_pr2handle(p), p->p.settings); if (p->request.method && !p->stop) http_finish(&p->request); h1_reset(p); return fio_is_closed(p->p.uuid); }
/* ***************************************************************************** Parser Callbacks ***************************************************************************** */ /** called when a request was received. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L551-L558
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_response
static int http1_on_response(http1_parser_s *parser) { http1pr_s *p = parser2http(parser); http_on_response_handler______internal(&http1_pr2handle(p), p->p.settings); if (p->request.status_str && !p->stop) http_finish(&p->request); h1_reset(p); return fio_is_closed(p->p.uuid); }
/** called when a response was received. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L560-L567
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_method
static int http1_on_method(http1_parser_s *parser, char *method, size_t method_len) { http1_pr2handle(parser2http(parser)).method = fiobj_str_new(method, method_len); parser2http(parser)->header_size += method_len; return 0; }
/** called when a request method is parsed. */
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L569-L575
675c65b509d48c21a8d1fa4c5ec53fc407643a3b
zap
github_2023
zigzap
c
http1_on_status
static int http1_on_status(http1_parser_s *parser, size_t status, char *status_str, size_t len) { http1_pr2handle(parser2http(parser)).status_str = fiobj_str_new(status_str, len); http1_pr2handle(parser2http(parser)).status = status; parser2http(parser)->header_size += len; retu...
/** called when a response status is parsed. the status_str is the string * without the prefixed numerical status indicator.*/
https://github.com/zigzap/zap/blob/675c65b509d48c21a8d1fa4c5ec53fc407643a3b/facil.io/lib/facil/http/http1.c#L579-L586
675c65b509d48c21a8d1fa4c5ec53fc407643a3b