• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 #ifndef JBL_INTERNAL_H
3 #define JBL_INTERNAL_H
4 
5 /**************************************************************************************************
6  * IOWOW library
7  *
8  * MIT License
9  *
10  * Copyright (c) 2012-2022 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 "iwlog.h"
32 #include "iwjson.h"
33 #include "iwbinn.h"
34 #include "iwpool.h"
35 #include "iwconv.h"
36 
37 #define JBL_MAX_NESTING_LEVEL 999
38 
39 struct _JBL {
40   binn     bn;
41   JBL_NODE node;
42 };
43 
44 /**
45  * @brief JBL visitor context
46  */
47 typedef struct _JBL_VCTX {
48   binn   *bn;       /**< Root node from which started visitor */
49   void   *op;       /**< Arbitrary opaque data */
50   void   *result;
51   IWPOOL *pool;     /**< Pool placeholder, initialization is responsibility of `JBL_VCTX` creator */
52   int     pos;      /**< Aux position, not actually used by visitor core */
53   bool    terminate;
54   bool    found;    /**< Used in _jbl_at() */
55 } JBL_VCTX;
56 
57 typedef jbn_visitor_cmd_t jbl_visitor_cmd_t;
58 
59 typedef struct _JBL_PATCHEXT {
60   const JBL_PATCH *p;
61   JBL_PTR path;
62   JBL_PTR from;
63 } JBL_PATCHEXT;
64 
65 typedef struct _JBLDRCTX {
66   IWPOOL  *pool;
67   JBL_NODE root;
68 } JBLDRCTX;
69 
70 iwrc jbl_from_buf_keep_onstack(JBL jbl, void *buf, size_t bufsz);
71 iwrc jbl_from_buf_keep_onstack2(JBL jbl, void *buf);
72 
73 iwrc _jbl_write_double(double num, jbl_json_printer pt, void *op);
74 iwrc _jbl_write_int(int64_t num, jbl_json_printer pt, void *op);
75 iwrc _jbl_write_string(const char *str, int len, jbl_json_printer pt, void *op, jbl_print_flags_t pf);
76 iwrc _jbl_node_from_binn(const binn *bn, JBL_NODE *node, bool clone_strings, IWPOOL *pool);
77 iwrc _jbl_binn_from_node(binn *res, JBL_NODE node);
78 iwrc _jbl_from_node(JBL jbl, JBL_NODE node);
79 bool _jbl_at(JBL jbl, JBL_PTR jp, JBL res);
80 int _jbl_compare_nodes(JBL_NODE n1, JBL_NODE n2, iwrc *rcp);
81 
82 typedef jbl_visitor_cmd_t (*JBL_VISITOR)(int lvl, binn *bv, const char *key, int idx, JBL_VCTX *vctx, iwrc *rc);
83 iwrc _jbl_visit(binn_iter *iter, int lvl, JBL_VCTX *vctx, JBL_VISITOR visitor);
84 
85 bool _jbl_is_eq_atomic_values(JBL v1, JBL v2);
86 int _jbl_cmp_atomic_values(JBL v1, JBL v2);
87 
88 BOOL binn_read_next_pair2(int expected_type, binn_iter *iter, int *klidx, char **pkey, binn *value);
89 
90 #endif
91