mustach-cjson.h (3555B)
1 /* 2 Author: José Bollo <jobol@nonadev.net> 3 4 https://gitlab.com/jobol/mustach 5 6 SPDX-License-Identifier: ISC 7 */ 8 9 #ifndef _mustach_cJSON_h_included_ 10 #define _mustach_cJSON_h_included_ 11 12 /* 13 * mustach-cjson is intended to make integration of cJSON 14 * library by providing integrated functions. 15 */ 16 17 #include <cjson/cJSON.h> 18 #include "mustach-wrap.h" 19 20 /** 21 * Wrap interface used internally by mustach cJSON functions. 22 * Can be used for overriding behaviour. 23 */ 24 extern const struct mustach_wrap_itf mustach_cJSON_wrap_itf; 25 26 /** 27 * mustach_cJSON_file - Renders the mustache 'template' in 'file' for 'root'. 28 * 29 * @template: the template string to instantiate 30 * @length: length of the template or zero if unknown and template null terminated 31 * @root: the root json object to render 32 * @file: the file where to write the result 33 * 34 * Returns 0 in case of success, -1 with errno set in case of system error 35 * a other negative value in case of error. 36 */ 37 extern int mustach_cJSON_file(const char *template, size_t length, cJSON *root, int flags, FILE *file); 38 39 /** 40 * mustach_cJSON_fd - Renders the mustache 'template' in 'fd' for 'root'. 41 * 42 * @template: the template string to instantiate 43 * @length: length of the template or zero if unknown and template null terminated 44 * @root: the root json object to render 45 * @fd: the file descriptor number where to write the result 46 * 47 * Returns 0 in case of success, -1 with errno set in case of system error 48 * a other negative value in case of error. 49 */ 50 extern int mustach_cJSON_fd(const char *template, size_t length, cJSON *root, int flags, int fd); 51 52 53 /** 54 * mustach_cJSON_mem - Renders the mustache 'template' in 'result' for 'root'. 55 * 56 * @template: the template string to instantiate 57 * @length: length of the template or zero if unknown and template null terminated 58 * @root: the root json object to render 59 * @result: the pointer receiving the result when 0 is returned 60 * @size: the size of the returned result 61 * 62 * Returns 0 in case of success, -1 with errno set in case of system error 63 * a other negative value in case of error. 64 */ 65 extern int mustach_cJSON_mem(const char *template, size_t length, cJSON *root, int flags, char **result, size_t *size); 66 67 /** 68 * mustach_cJSON_write - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'. 69 * 70 * @template: the template string to instantiate 71 * @length: length of the template or zero if unknown and template null terminated 72 * @root: the root json object to render 73 * @writecb: the function that write values 74 * @closure: the closure for the write function 75 * 76 * Returns 0 in case of success, -1 with errno set in case of system error 77 * a other negative value in case of error. 78 */ 79 extern int mustach_cJSON_write(const char *template, size_t length, cJSON *root, int flags, mustach_write_cb_t *writecb, void *closure); 80 81 /** 82 * mustach_cJSON_emit - Renders the mustache 'template' for 'root' to custom emiter 'emitcb' with 'closure'. 83 * 84 * @template: the template string to instantiate 85 * @length: length of the template or zero if unknown and template null terminated 86 * @root: the root json object to render 87 * @emitcb: the function that emit values 88 * @closure: the closure for the write function 89 * 90 * Returns 0 in case of success, -1 with errno set in case of system error 91 * a other negative value in case of error. 92 */ 93 extern int mustach_cJSON_emit(const char *template, size_t length, cJSON *root, int flags, mustach_emit_cb_t *emitcb, void *closure); 94 95 #endif 96