mustach-json-c.h (6006B)
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_json_c_h_included_ 10 #define _mustach_json_c_h_included_ 11 12 /* 13 * mustach-json-c is intended to make integration of json-c 14 * library by providing integrated functions. 15 */ 16 17 #include <json-c/json.h> 18 #include "mustach-wrap.h" 19 20 /** 21 * Wrap interface used internally by mustach json-c functions. 22 * Can be used for overriding behaviour. 23 */ 24 extern const struct mustach_wrap_itf mustach_json_c_wrap_itf; 25 26 /** 27 * mustach_json_c_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_json_c_file(const char *template, size_t length, struct json_object *root, int flags, FILE *file); 38 39 /** 40 * mustach_json_c_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_json_c_fd(const char *template, size_t length, struct json_object *root, int flags, int fd); 51 52 /** 53 * mustach_json_c_mem - Renders the mustache 'template' in 'result' for 'root'. 54 * 55 * @template: the template string to instantiate 56 * @length: length of the template or zero if unknown and template null terminated 57 * @root: the root json object to render 58 * @result: the pointer receiving the result when 0 is returned 59 * @size: the size of the returned result 60 * 61 * Returns 0 in case of success, -1 with errno set in case of system error 62 * a other negative value in case of error. 63 */ 64 extern int mustach_json_c_mem(const char *template, size_t length, struct json_object *root, int flags, char **result, size_t *size); 65 66 /** 67 * mustach_json_c_write - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'. 68 * 69 * @template: the template string to instantiate 70 * @length: length of the template or zero if unknown and template null terminated 71 * @root: the root json object to render 72 * @writecb: the function that write values 73 * @closure: the closure for the write function 74 * 75 * Returns 0 in case of success, -1 with errno set in case of system error 76 * a other negative value in case of error. 77 */ 78 extern int mustach_json_c_write(const char *template, size_t length, struct json_object *root, int flags, mustach_write_cb_t *writecb, void *closure); 79 80 /** 81 * mustach_json_c_emit - Renders the mustache 'template' for 'root' to custom emiter 'emitcb' with 'closure'. 82 * 83 * @template: the template string to instantiate 84 * @length: length of the template or zero if unknown and template null terminated 85 * @root: the root json object to render 86 * @emitcb: the function that emit values 87 * @closure: the closure for the write function 88 * 89 * Returns 0 in case of success, -1 with errno set in case of system error 90 * a other negative value in case of error. 91 */ 92 extern int mustach_json_c_emit(const char *template, size_t length, struct json_object *root, int flags, mustach_emit_cb_t *emitcb, void *closure); 93 94 /*************************************************************************** 95 * compatibility with version before 1.0 96 */ 97 98 /** 99 * OBSOLETE use mustach_json_c_file 100 * 101 * fmustach_json_c - Renders the mustache 'template' in 'file' for 'root'. 102 * 103 * @template: the template string to instantiate 104 * @root: the root json object to render 105 * @file: the file where to write the result 106 * 107 * Returns 0 in case of success, -1 with errno set in case of system error 108 * a other negative value in case of error. 109 */ 110 111 DEPRECATED_MUSTACH(extern int fmustach_json_c(const char *template, struct json_object *root, FILE *file)); 112 113 /** 114 * OBSOLETE use mustach_json_c_fd 115 * 116 * fdmustach_json_c - Renders the mustache 'template' in 'fd' for 'root'. 117 * 118 * @template: the template string to instantiate 119 * @root: the root json object to render 120 * @fd: the file descriptor number where to write the result 121 * 122 * Returns 0 in case of success, -1 with errno set in case of system error 123 * a other negative value in case of error. 124 */ 125 126 DEPRECATED_MUSTACH(extern int fdmustach_json_c(const char *template, struct json_object *root, int fd)); 127 128 /** 129 * OBSOLETE use mustach_json_c_mem 130 * 131 * mustach_json_c - Renders the mustache 'template' in 'result' for 'root'. 132 * 133 * @template: the template string to instantiate 134 * @root: the root json object to render 135 * @result: the pointer receiving the result when 0 is returned 136 * @size: the size of the returned result 137 * 138 * Returns 0 in case of success, -1 with errno set in case of system error 139 * a other negative value in case of error. 140 */ 141 142 DEPRECATED_MUSTACH(extern int mustach_json_c(const char *template, struct json_object *root, char **result, size_t *size)); 143 144 /** 145 * OBSOLETE use mustach_json_c_write 146 * 147 * umustach_json_c - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'. 148 * 149 * @template: the template string to instantiate 150 * @root: the root json object to render 151 * @writecb: the function that write values 152 * @closure: the closure for the write function 153 * 154 * Returns 0 in case of success, -1 with errno set in case of system error 155 * a other negative value in case of error. 156 */ 157 typedef mustach_write_cb_t *mustach_json_write_cb; 158 DEPRECATED_MUSTACH(extern int umustach_json_c(const char *template, struct json_object *root, mustach_write_cb_t *writecb, void *closure)); 159 160 #endif