teptris 0.3.19.1-arm-linux → 0.3.21.0-arm-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,221 @@
1
+ /* The compiled-schema internals: shared between schema.c (compile)
2
+ * and validate.c (the walk). */
3
+ #ifndef TEPTRIS_SCHEMA_INTERNAL_H
4
+ #define TEPTRIS_SCHEMA_INTERNAL_H
5
+
6
+ #include <stdbool.h>
7
+ #include <stddef.h>
8
+ #include <stdint.h>
9
+
10
+ #include "json_read.h"
11
+ #include "regex.h"
12
+ #include "teptris/memory/arena.h"
13
+
14
+ /* the JSON-view types a schema can match; datetimes map to string
15
+ * (policy 3) */
16
+ enum {
17
+ ST_STRING = 1 << 0,
18
+ ST_INTEGER = 1 << 1,
19
+ ST_NUMBER = 1 << 2, /* float or integer */
20
+ ST_BOOLEAN = 1 << 3,
21
+ ST_OBJECT = 1 << 4,
22
+ ST_ARRAY = 1 << 5
23
+ };
24
+ #define ST_ANY 0x3Fu
25
+
26
+ enum {
27
+ FMT_NONE = 0,
28
+ FMT_DATETIME,
29
+ FMT_DATE,
30
+ FMT_TIME,
31
+ /* the taplo parity set: every format the jsonschema crate (the
32
+ * engine behind taplo) asserts on; names outside this set are
33
+ * annotations on both sides */
34
+ FMT_EMAIL,
35
+ FMT_IDN_EMAIL,
36
+ FMT_HOSTNAME,
37
+ FMT_IDN_HOSTNAME,
38
+ FMT_IPV4,
39
+ FMT_IPV6,
40
+ FMT_URI,
41
+ FMT_IRI,
42
+ FMT_URI_REFERENCE,
43
+ FMT_IRI_REFERENCE,
44
+ FMT_JSON_POINTER,
45
+ FMT_RELATIVE_JSON_POINTER,
46
+ FMT_REGEX,
47
+ FMT_URI_TEMPLATE,
48
+ FMT_UUID,
49
+ FMT_DURATION,
50
+ /* taplo's own custom formats (registered by its schema cache) */
51
+ FMT_SEMVER,
52
+ FMT_SEMVER_REQUIREMENT
53
+ };
54
+
55
+ typedef struct sch_node sch_node;
56
+
57
+ typedef struct {
58
+ const char *name;
59
+ sch_node *schema;
60
+ } sch_prop;
61
+
62
+ typedef struct {
63
+ struct sch_regex *re;
64
+ sch_node *schema;
65
+ } sch_pprop;
66
+
67
+ typedef struct {
68
+ const char *key;
69
+ sch_node *schema;
70
+ } sch_kschema;
71
+
72
+ struct sch_node {
73
+ bool is_false; /* the false schema: matches nothing */
74
+
75
+ unsigned types; /* ST_* mask; ST_ANY when "type" is absent */
76
+
77
+ /* applicators */
78
+ sch_node **all_of, **any_of, **one_of;
79
+ size_t n_all, n_any, n_one;
80
+ sch_node *_not, *if_s, *then_s, *else_s;
81
+ sch_node *ref; /* resolved $ref target (transparent) */
82
+
83
+ /* object keywords */
84
+ sch_prop *props;
85
+ size_t n_props;
86
+ sch_pprop *pprops;
87
+ size_t n_pprops;
88
+ sch_node *prop_names;
89
+ sch_node *additional; /* NULL = unconstrained */
90
+ bool additional_set;
91
+ char **required;
92
+ size_t n_req;
93
+ long min_props, max_props;
94
+ bool has_min_props, has_max_props;
95
+ sch_kschema *dep_req; /* key -> required keys */
96
+ size_t n_dep_req;
97
+ sch_kschema *dep_schemas; /* key -> schema */
98
+ size_t n_dep_schemas;
99
+
100
+ /* array keywords */
101
+ sch_node **prefix;
102
+ size_t n_prefix;
103
+ sch_node *items;
104
+ bool items_set;
105
+ sch_node *add_items; /* additionalItems: applies beyond prefix */
106
+ bool add_items_set;
107
+ sch_node *contains;
108
+ long min_contains, max_contains;
109
+ bool has_contains, has_min_contains, has_max_contains;
110
+ bool unique_items;
111
+ bool has_unique;
112
+ long min_items, max_items;
113
+ bool has_min_items, has_max_items;
114
+
115
+ /* string keywords */
116
+ struct sch_regex *pattern;
117
+ long min_length, max_length;
118
+ bool has_min_length, has_max_length;
119
+ int format;
120
+ const char *content_encoding; /* enforced: "base64" */
121
+ const char *content_media_type; /* enforced: "application/json" */
122
+
123
+ /* numeric keywords: the int form is exact when the constraint was
124
+ * an exact integer token */
125
+ bool has_min, has_max, has_ex_min, has_ex_max;
126
+ double fmin, fmax, fex_min, fex_max;
127
+ int64_t imin, imax, iex_min, iex_max;
128
+ bool has_mult;
129
+ double fmult;
130
+ int64_t imult;
131
+ bool mult_is_int;
132
+ /* exact-decimal view of a non-integer multipleOf: the
133
+ * shortest-roundtrip mantissa and decimal exponent */
134
+ bool mult_exact;
135
+ int64_t mult_mant;
136
+ int mult_exp;
137
+
138
+ /* value constraints */
139
+ jv **enum_vals;
140
+ size_t n_enum;
141
+ jv *const_val;
142
+ bool has_const;
143
+ };
144
+
145
+ struct teptris_schema {
146
+ teptris_arena arena;
147
+ sch_node *root;
148
+ char err[256];
149
+ };
150
+
151
+ typedef struct {
152
+ teptris_arena *a;
153
+ jv *root;
154
+ /* memo: compile-once per raw subtree (handles $ref cycles) */
155
+ struct memo_entry {
156
+ const jv *src;
157
+ sch_node *node;
158
+ bool in_progress;
159
+ } *memo;
160
+ size_t n_memo, cap_memo;
161
+ /* dependency-list capacities (grow-in-place across keywords) */
162
+ size_t cap_dep_req, cap_dep_schemas;
163
+ /* anchors: "$anchor": name -> subtree */
164
+ struct {
165
+ const char *name;
166
+ jv *target;
167
+ } *anchors;
168
+ size_t n_anchors, cap_anchors;
169
+ char *err;
170
+ size_t err_cap;
171
+ } sctx;
172
+
173
+ /* the tagged value the validator walks: converted from a document's
174
+ * DOM once per validate call, or synthesized (schema-side enum/const
175
+ * values, propertyNames strings) */
176
+ typedef struct sch_svalue sch_svalue;
177
+ typedef struct {
178
+ const char *key;
179
+ sch_svalue *val;
180
+ } sv_member;
181
+
182
+ enum {
183
+ SV_STRING,
184
+ SV_INT,
185
+ SV_FLOAT,
186
+ SV_BOOL,
187
+ SV_NULL,
188
+ SV_ARRAY,
189
+ SV_TABLE,
190
+ SV_DATETIME, /* offset or local */
191
+ SV_DATE,
192
+ SV_TIME
193
+ };
194
+
195
+ struct sch_svalue {
196
+ int kind;
197
+ const char *str;
198
+ size_t str_len;
199
+ int64_t i;
200
+ double f;
201
+ bool b;
202
+ sv_member *members;
203
+ size_t n_members;
204
+ sch_svalue **items;
205
+ size_t n_items;
206
+ };
207
+
208
+ /* schema.c */
209
+ sch_node *sch_compile_node(sctx *c, const jv *v);
210
+ sch_node *sch_resolve_pointer(sctx *c, const char *pointer);
211
+ /* the shortest-roundtrip decimal view of a double: d = mant * 10^exp
212
+ * with |mant| < 10^18; false for non-finite d */
213
+ bool sch_decimal_of_double(double d, int64_t *mant, int *exp);
214
+
215
+ /* formats.c */
216
+ /* the string-side format battery (the taplo parity set); datetimes
217
+ * reach it through their canonical text like any other string */
218
+ bool sch_format_string_check(int format, const char *s, size_t len,
219
+ teptris_arena *scratch);
220
+
221
+ #endif