teptris 0.3.19.1-aarch64-linux → 0.3.20.0-aarch64-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,179 @@
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
+ };
32
+
33
+ typedef struct sch_node sch_node;
34
+
35
+ typedef struct {
36
+ const char *name;
37
+ sch_node *schema;
38
+ } sch_prop;
39
+
40
+ typedef struct {
41
+ struct sch_regex *re;
42
+ sch_node *schema;
43
+ } sch_pprop;
44
+
45
+ typedef struct {
46
+ const char *key;
47
+ sch_node *schema;
48
+ } sch_kschema;
49
+
50
+ struct sch_node {
51
+ bool is_false; /* the false schema: matches nothing */
52
+
53
+ unsigned types; /* ST_* mask; ST_ANY when "type" is absent */
54
+
55
+ /* applicators */
56
+ sch_node **all_of, **any_of, **one_of;
57
+ size_t n_all, n_any, n_one;
58
+ sch_node *_not, *if_s, *then_s, *else_s;
59
+ sch_node *ref; /* resolved $ref target (transparent) */
60
+
61
+ /* object keywords */
62
+ sch_prop *props;
63
+ size_t n_props;
64
+ sch_pprop *pprops;
65
+ size_t n_pprops;
66
+ sch_node *prop_names;
67
+ sch_node *additional; /* NULL = unconstrained */
68
+ bool additional_set;
69
+ char **required;
70
+ size_t n_req;
71
+ long min_props, max_props;
72
+ bool has_min_props, has_max_props;
73
+ sch_kschema *dep_req; /* key -> required keys */
74
+ size_t n_dep_req;
75
+ sch_kschema *dep_schemas; /* key -> schema */
76
+ size_t n_dep_schemas;
77
+
78
+ /* array keywords */
79
+ sch_node **prefix;
80
+ size_t n_prefix;
81
+ sch_node *items;
82
+ bool items_set;
83
+ sch_node *contains;
84
+ long min_contains, max_contains;
85
+ bool has_contains, has_min_contains, has_max_contains;
86
+ bool unique_items;
87
+ bool has_unique;
88
+ long min_items, max_items;
89
+ bool has_min_items, has_max_items;
90
+
91
+ /* string keywords */
92
+ struct sch_regex *pattern;
93
+ long min_length, max_length;
94
+ bool has_min_length, has_max_length;
95
+ int format;
96
+
97
+ /* numeric keywords: the int form is exact when the constraint was
98
+ * an exact integer token */
99
+ bool has_min, has_max, has_ex_min, has_ex_max;
100
+ double fmin, fmax, fex_min, fex_max;
101
+ int64_t imin, imax, iex_min, iex_max;
102
+ bool has_mult;
103
+ double fmult;
104
+ int64_t imult;
105
+ bool mult_is_int;
106
+
107
+ /* value constraints */
108
+ jv **enum_vals;
109
+ size_t n_enum;
110
+ jv *const_val;
111
+ bool has_const;
112
+ };
113
+
114
+ struct teptris_schema {
115
+ teptris_arena arena;
116
+ sch_node *root;
117
+ char err[256];
118
+ };
119
+
120
+ typedef struct {
121
+ teptris_arena *a;
122
+ jv *root;
123
+ /* memo: compile-once per raw subtree (handles $ref cycles) */
124
+ struct memo_entry {
125
+ const jv *src;
126
+ sch_node *node;
127
+ bool in_progress;
128
+ } *memo;
129
+ size_t n_memo, cap_memo;
130
+ /* anchors: "$anchor": name -> subtree */
131
+ struct {
132
+ const char *name;
133
+ jv *target;
134
+ } *anchors;
135
+ size_t n_anchors, cap_anchors;
136
+ char *err;
137
+ size_t err_cap;
138
+ } sctx;
139
+
140
+ /* the tagged value the validator walks: converted from a document's
141
+ * DOM once per validate call, or synthesized (schema-side enum/const
142
+ * values, propertyNames strings) */
143
+ typedef struct sch_svalue sch_svalue;
144
+ typedef struct {
145
+ const char *key;
146
+ sch_svalue *val;
147
+ } sv_member;
148
+
149
+ enum {
150
+ SV_STRING,
151
+ SV_INT,
152
+ SV_FLOAT,
153
+ SV_BOOL,
154
+ SV_NULL,
155
+ SV_ARRAY,
156
+ SV_TABLE,
157
+ SV_DATETIME, /* offset or local */
158
+ SV_DATE,
159
+ SV_TIME
160
+ };
161
+
162
+ struct sch_svalue {
163
+ int kind;
164
+ const char *str;
165
+ size_t str_len;
166
+ int64_t i;
167
+ double f;
168
+ bool b;
169
+ sv_member *members;
170
+ size_t n_members;
171
+ sch_svalue **items;
172
+ size_t n_items;
173
+ };
174
+
175
+ /* schema.c */
176
+ sch_node *sch_compile_node(sctx *c, const jv *v);
177
+ sch_node *sch_resolve_pointer(sctx *c, const char *pointer);
178
+
179
+ #endif