1 #pragma once 2 #ifndef JBL_INTERNAL_H 3 #define JBL_INTERNAL_H 4 5 /************************************************************************************************** 6 * EJDB2 7 * 8 * MIT License 9 * 10 * Copyright (c) 2012-2021 Softmotions Ltd <info@softmotions.com> 11 * 12 * Permission is hereby granted, free of charge, to any person obtaining a copy 13 * of this software and associated documentation files (the "Software"), to deal 14 * in the Software without restriction, including without limitation the rights 15 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 16 * copies of the Software, and to permit persons to whom the Software is 17 * furnished to do so, subject to the following conditions: 18 * 19 * The above copyright notice and this permission notice shall be included in all 20 * copies or substantial portions of the Software. 21 * 22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 28 * SOFTWARE. 29 *************************************************************************************************/ 30 31 #include "jbl.h" 32 #include "binn.h" 33 #include <ejdb2/iowow/iwlog.h> 34 #include <ejdb2/iowow/iwpool.h> 35 #include <ejdb2/iowow/iwconv.h> 36 #include "ejdb2cfg.h" 37 38 #define JBL_MAX_NESTING_LEVEL 999 39 40 struct _JBL { 41 binn bn; 42 JBL_NODE node; 43 }; 44 45 /** 46 * @brief JBL visitor context 47 */ 48 typedef struct _JBL_VCTX { 49 binn *bn; /**< Root node from which started visitor */ 50 void *op; /**< Arbitrary opaque data */ 51 void *result; 52 IWPOOL *pool; /**< Pool placeholder, initialization is responsibility of `JBL_VCTX` creator */ 53 int pos; /**< Aux position, not actually used by visitor core */ 54 bool terminate; 55 bool found; /**< Used in _jbl_at() */ 56 } JBL_VCTX; 57 58 typedef jbn_visitor_cmd_t jbl_visitor_cmd_t; 59 60 typedef struct _JBL_PATCHEXT { 61 const JBL_PATCH *p; 62 JBL_PTR path; 63 JBL_PTR from; 64 } JBL_PATCHEXT; 65 66 typedef struct _JBLDRCTX { 67 IWPOOL *pool; 68 JBL_NODE root; 69 } JBLDRCTX; 70 71 iwrc jbl_from_buf_keep_onstack(JBL jbl, void *buf, size_t bufsz); 72 iwrc jbl_from_buf_keep_onstack2(JBL jbl, void *buf); 73 74 iwrc _jbl_write_double(double num, jbl_json_printer pt, void *op); 75 iwrc _jbl_write_int(int64_t num, jbl_json_printer pt, void *op); 76 iwrc _jbl_write_string(const char *str, int len, jbl_json_printer pt, void *op, jbl_print_flags_t pf); 77 iwrc _jbl_node_from_binn(const binn *bn, JBL_NODE *node, bool clone_strings, IWPOOL *pool); 78 iwrc _jbl_binn_from_node(binn *res, JBL_NODE node); 79 iwrc _jbl_from_node(JBL jbl, JBL_NODE node); 80 bool _jbl_at(JBL jbl, JBL_PTR jp, JBL res); 81 int _jbl_compare_nodes(JBL_NODE n1, JBL_NODE n2, iwrc *rcp); 82 83 typedef jbl_visitor_cmd_t (*JBL_VISITOR)(int lvl, binn *bv, const char *key, int idx, JBL_VCTX *vctx, iwrc *rc); 84 iwrc _jbl_visit(binn_iter *iter, int lvl, JBL_VCTX *vctx, JBL_VISITOR visitor); 85 86 bool _jbl_is_eq_atomic_values(JBL v1, JBL v2); 87 int _jbl_cmp_atomic_values(JBL v1, JBL v2); 88 89 BOOL binn_read_next_pair2(int expected_type, binn_iter *iter, int *klidx, char **pkey, binn *value); 90 91 #endif 92