yeptris 0.6.58.1-arm-linux-eabihf → 0.6.60.1-arm-linux-eabihf
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.
- checksums.yaml +4 -4
- data/ext/yeptris_native/version.h +2 -2
- data/lib/yeptris/3.4/native.so +0 -0
- data/lib/yeptris/document.rb +15 -0
- data/lib/yeptris/ffi.rb +112 -0
- data/lib/yeptris/psych/visitors.rb +16 -6
- data/lib/yeptris/psych.rb +11 -5
- data/lib/yeptris/validation.rb +320 -0
- data/lib/yeptris/yaml.rb +128 -6
- data/lib/yeptris.rb +2 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/CMakeLists.txt +8 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +30 -2
- data/vendor/libyeptris/src/include/yeptris/parse.h +52 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +8 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +259 -15
- data/vendor/libyeptris/src/include/yeptris/values.h +8 -2
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +10 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +5 -7
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +9 -9
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +1 -1
- data/vendor/libyeptris/src/yeptris/common/error.h +2 -0
- data/vendor/libyeptris/src/yeptris/doc.h +20 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +85 -13
- data/vendor/libyeptris/src/yeptris/emit/writer.c +158 -642
- data/vendor/libyeptris/src/yeptris/emit/writer.h +15 -1
- data/vendor/libyeptris/src/yeptris/events/push.c +28 -3
- data/vendor/libyeptris/src/yeptris/events/values.c +24 -0
- data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +121 -40
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +326 -0
- data/vendor/libyeptris/src/yeptris/parse.c +181 -46
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +1 -1
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +11 -3
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +12 -6
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +20 -0
- data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
- data/vendor/libyeptris/src/yeptris/validate/internal.h +255 -10
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1025 -125
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +791 -163
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +330 -226
- metadata +10 -1
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/* compile.c — the compiled-schema economy (#885 item 3).
|
|
2
|
+
*
|
|
3
|
+
* The leptris-XSD shape (~/src/leptris/leptris/src/leptris/xsd/):
|
|
4
|
+
* parse the schema ONCE, retain the DOM and the derived state, validate
|
|
5
|
+
* many instance streams against the retained model. The handle owns
|
|
6
|
+
* everything it reads — the schema bytes (copied: the DOM's scalar
|
|
7
|
+
* views borrow them), the parsed document (its DOM, pools and finish
|
|
8
|
+
* pool die with yeptris_document_free), and the compiled pattern
|
|
9
|
+
* programs (the XSD content-model analog: `(a+)+$` compiles once at
|
|
10
|
+
* compile time, not once per validated string). One free call releases
|
|
11
|
+
* it all — no refcounting, the document-ownership law.
|
|
12
|
+
*
|
|
13
|
+
* The pattern programs are populated EAGERLY by a DFS over the schema
|
|
14
|
+
* tree (`pattern` values and `patternProperties` keys — the kernel's
|
|
15
|
+
* only two consumers), so the handle is immutable after compile and
|
|
16
|
+
* `yeptris_schema_validate` is a pure reader: one schema handle per
|
|
17
|
+
* thread like documents; read-only sharing across threads is safe.
|
|
18
|
+
* An invalid pattern is simply not retained — every use then recompiles
|
|
19
|
+
* to the one-shot's -1 (ignored keyword), never a guess.
|
|
20
|
+
*
|
|
21
|
+
* The one-shot face (yeptris_json_schema_validate) routes through the
|
|
22
|
+
* same compile+validate machinery internally: identical parse, walk
|
|
23
|
+
* and report code paths, so its observable statuses and byte-for-byte
|
|
24
|
+
* verdicts are preserved (the 1298-case suite port is the referee).
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
#include <string.h>
|
|
28
|
+
|
|
29
|
+
#include <yeptris/dom.h>
|
|
30
|
+
#include <yeptris/validate.h>
|
|
31
|
+
|
|
32
|
+
#include "../common/error.h"
|
|
33
|
+
#include "../doc.h"
|
|
34
|
+
#include "../memory/allocator.h"
|
|
35
|
+
#include "../tape_in.h"
|
|
36
|
+
#include "internal.h"
|
|
37
|
+
|
|
38
|
+
/* The compiled schema. Opaque at the face (validate.h); everything it
|
|
39
|
+
* reads dies with it. */
|
|
40
|
+
struct yeptris_schema {
|
|
41
|
+
char* bytes; /* owned: the schema bytes (the DOM's input views borrow them) */
|
|
42
|
+
yeptris_document* doc; /* owned: the parsed schema document */
|
|
43
|
+
const yep_dom* dom; /* borrowed from doc (yep_doc_dom) */
|
|
44
|
+
uint32_t sroot; /* the schema document's root (docs[0]) */
|
|
45
|
+
yep_re_cache* cache; /* owned: pattern source -> compiled NFA; immutable after compile */
|
|
46
|
+
js_resources* res; /* owned: $id/$anchor/$dynamicAnchor map + ref-site bases */
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/* ---- the pattern collection (compile-time, eager) ----------------------- */
|
|
50
|
+
|
|
51
|
+
static int collect_patterns(yep_re_cache* t, const yep_dom* d, uint32_t id, int depth);
|
|
52
|
+
|
|
53
|
+
/* Collects every pattern source of one mapping pair set. 0 ok, -1 OOM. */
|
|
54
|
+
static int collect_map(yep_re_cache* t, const yep_dom* d, uint32_t map_id, int depth) {
|
|
55
|
+
const yep_dnode* m = yep_dom_node(d, map_id);
|
|
56
|
+
uint32_t k = m->first_child;
|
|
57
|
+
while (k != UINT32_MAX) {
|
|
58
|
+
uint32_t v = yep_dom_node(d, k) ? yep_dom_node(d, k)->next_sibling : UINT32_MAX;
|
|
59
|
+
const yep_dnode* kn = yep_dom_node(d, k);
|
|
60
|
+
const yep_dnode* vn = v != UINT32_MAX ? yep_dom_node(d, v) : NULL;
|
|
61
|
+
if (kn != NULL && kn->kind == YEP_DOM_SCALAR) {
|
|
62
|
+
yep_view kv = yep_dom_view(d, kn->value);
|
|
63
|
+
/* the keyword names, matched by bytes like the walk's kw_get */
|
|
64
|
+
if (kv.len == 7 && memcmp(kv.p, "pattern", 7) == 0) {
|
|
65
|
+
/* "pattern": the value is the pattern source (a string
|
|
66
|
+
* scalar, schema_word's exact read) */
|
|
67
|
+
if (vn != NULL && vn->kind == YEP_DOM_SCALAR &&
|
|
68
|
+
yep_validate_scalar_tag(vn) == YEPTRIS_TAG_STR) {
|
|
69
|
+
yep_view vv = yep_dom_view(d, vn->value);
|
|
70
|
+
if (vv.p != NULL && yep_re_cache_add(t, vv.p, vv.len) < 0) {
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else if (kv.len == 17 && memcmp(kv.p, "patternProperties", 17) == 0) {
|
|
75
|
+
/* "patternProperties": its KEYS are the pattern sources */
|
|
76
|
+
if (vn != NULL && vn->kind == YEP_DOM_MAPPING) {
|
|
77
|
+
uint32_t pk = vn->first_child;
|
|
78
|
+
while (pk != UINT32_MAX) {
|
|
79
|
+
uint32_t pv =
|
|
80
|
+
yep_dom_node(d, pk) ? yep_dom_node(d, pk)->next_sibling : UINT32_MAX;
|
|
81
|
+
const yep_dnode* pkn = yep_dom_node(d, pk);
|
|
82
|
+
if (pkn != NULL && pkn->kind == YEP_DOM_SCALAR &&
|
|
83
|
+
yep_validate_scalar_tag(pkn) == YEPTRIS_TAG_STR) {
|
|
84
|
+
yep_view pw = yep_dom_view(d, pkn->value);
|
|
85
|
+
if (pw.p != NULL && yep_re_cache_add(t, pw.p, pw.len) < 0) {
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
pk = pv;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/* the rest of the schema rides the values (keys are scalars —
|
|
95
|
+
* nothing under them; the walk reaches nodes the same way) */
|
|
96
|
+
if (v != UINT32_MAX && collect_patterns(t, d, v, depth + 1) != 0) {
|
|
97
|
+
return -1;
|
|
98
|
+
}
|
|
99
|
+
k = v != UINT32_MAX && yep_dom_node(d, v) ? yep_dom_node(d, v)->next_sibling : UINT32_MAX;
|
|
100
|
+
}
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/* Depth-bounded DFS gathering every pattern the walk can reach. 0 ok,
|
|
105
|
+
* -1 OOM. Aliases are skipped: the walk sees an alias node as opaque
|
|
106
|
+
* (never a mapping), so no reachable pattern hides behind one. */
|
|
107
|
+
static int collect_patterns(yep_re_cache* t, const yep_dom* d, uint32_t id, int depth) {
|
|
108
|
+
if (depth > YEP_DOM_MAX_DEPTH) {
|
|
109
|
+
return 0; /* the walk's own guard: deeper nodes are unreachable to it too */
|
|
110
|
+
}
|
|
111
|
+
const yep_dnode* n = yep_dom_node(d, id);
|
|
112
|
+
if (n == NULL) {
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
if (n->kind == YEP_DOM_MAPPING) {
|
|
116
|
+
return collect_map(t, d, id, depth);
|
|
117
|
+
}
|
|
118
|
+
if (n->kind == YEP_DOM_SEQUENCE) {
|
|
119
|
+
uint32_t ch = n->first_child;
|
|
120
|
+
while (ch != UINT32_MAX) {
|
|
121
|
+
uint32_t next = yep_dom_node(d, ch) ? yep_dom_node(d, ch)->next_sibling : UINT32_MAX;
|
|
122
|
+
if (collect_patterns(t, d, ch, depth + 1) != 0) {
|
|
123
|
+
return -1;
|
|
124
|
+
}
|
|
125
|
+
ch = next;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* ---- the seam with the explicit status (internal.h) --------------------- */
|
|
132
|
+
|
|
133
|
+
yeptris_schema* yep_schema_compile_st(const char* bytes, size_t n, YeptrisStatus* st) {
|
|
134
|
+
*st = YEPTRIS_OK;
|
|
135
|
+
if (bytes == NULL && n != 0) {
|
|
136
|
+
*st = YEPTRIS_ERROR_ARG;
|
|
137
|
+
return NULL;
|
|
138
|
+
}
|
|
139
|
+
const yep_allocator* sys = yep_system_allocator();
|
|
140
|
+
|
|
141
|
+
/* the schema bytes are COPIED: the DOM's scalar views borrow its
|
|
142
|
+
* input, and the handle outlives this call */
|
|
143
|
+
char* copy = NULL;
|
|
144
|
+
if (n > 0) {
|
|
145
|
+
copy = yep_alloc(sys, n);
|
|
146
|
+
if (copy == NULL) {
|
|
147
|
+
*st = YEPTRIS_ERROR_MEMORY;
|
|
148
|
+
return NULL;
|
|
149
|
+
}
|
|
150
|
+
memcpy(copy, bytes, n);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* document 0 of the stream is the schema (the one-shot's exact rule) */
|
|
154
|
+
YeptrisParseOptions opts;
|
|
155
|
+
memset(&opts, 0, sizeof(opts)); /* core12: the YAML->JSON data model */
|
|
156
|
+
YeptrisStatus ps = YEPTRIS_OK;
|
|
157
|
+
yeptris_document* doc = (yeptris_document*)yeptris_parse_eager_ex(copy, n, &opts, &ps);
|
|
158
|
+
if (doc == NULL) {
|
|
159
|
+
yep_free(sys, copy);
|
|
160
|
+
if (ps == YEPTRIS_OK) { /* empty bytes: the stream holds no document */
|
|
161
|
+
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
|
|
162
|
+
"the schema bytes hold no document");
|
|
163
|
+
*st = YEPTRIS_ERROR_ARG;
|
|
164
|
+
} else {
|
|
165
|
+
*st = ps; /* the schema did not parse — the engine's own status */
|
|
166
|
+
}
|
|
167
|
+
return NULL;
|
|
168
|
+
}
|
|
169
|
+
const yep_dom* dom = yep_doc_dom(doc);
|
|
170
|
+
if (dom == NULL || dom->dcount == 0) {
|
|
171
|
+
yeptris_document_free(doc);
|
|
172
|
+
yep_free(sys, copy);
|
|
173
|
+
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
|
|
174
|
+
"the schema bytes hold no document");
|
|
175
|
+
*st = YEPTRIS_ERROR_ARG;
|
|
176
|
+
return NULL;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* the pattern programs: compiled once, here (a failure to retain is
|
|
180
|
+
* an allocation failure — loud, like every constructor's OOM) */
|
|
181
|
+
yep_re_cache* cache = yep_re_cache_new();
|
|
182
|
+
if (cache == NULL || collect_patterns(cache, dom, dom->docs[0], 0) != 0) {
|
|
183
|
+
yep_re_cache_free(cache);
|
|
184
|
+
yeptris_document_free(doc);
|
|
185
|
+
yep_free(sys, copy);
|
|
186
|
+
yep_error_set(yep_error_tls(), YEP_ERR_MEMORY, 0, 0, 0,
|
|
187
|
+
"the schema's pattern programs failed to compile");
|
|
188
|
+
*st = YEPTRIS_ERROR_MEMORY;
|
|
189
|
+
return NULL;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* the identifier map: $id resources, anchors, ref-site bases —
|
|
193
|
+
* built once by the crawl, read-only afterwards (OOM is loud) */
|
|
194
|
+
js_resources* res = yep_js_resources_crawl(dom, dom->docs[0]);
|
|
195
|
+
if (res == NULL) {
|
|
196
|
+
yep_re_cache_free(cache);
|
|
197
|
+
yeptris_document_free(doc);
|
|
198
|
+
yep_free(sys, copy);
|
|
199
|
+
yep_error_set(yep_error_tls(), YEP_ERR_MEMORY, 0, 0, 0,
|
|
200
|
+
"the schema's identifier map failed to build");
|
|
201
|
+
*st = YEPTRIS_ERROR_MEMORY;
|
|
202
|
+
return NULL;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
yeptris_schema* s = yep_alloc(sys, sizeof(*s));
|
|
206
|
+
if (s == NULL) {
|
|
207
|
+
yep_js_resources_free(res);
|
|
208
|
+
yep_re_cache_free(cache);
|
|
209
|
+
yeptris_document_free(doc);
|
|
210
|
+
yep_free(sys, copy);
|
|
211
|
+
*st = YEPTRIS_ERROR_MEMORY;
|
|
212
|
+
return NULL;
|
|
213
|
+
}
|
|
214
|
+
s->bytes = copy;
|
|
215
|
+
s->doc = doc;
|
|
216
|
+
s->dom = dom;
|
|
217
|
+
s->sroot = dom->docs[0];
|
|
218
|
+
s->cache = cache;
|
|
219
|
+
s->res = res;
|
|
220
|
+
return s;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* ---- the public face (validate.h) --------------------------------------- */
|
|
224
|
+
|
|
225
|
+
YEPTRIS_API yeptris_schema* yeptris_schema_compile(const char* bytes, size_t n) {
|
|
226
|
+
YeptrisStatus st = YEPTRIS_OK;
|
|
227
|
+
return yep_schema_compile_st(bytes, n, &st); /* the error channel carries the why */
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* The tag-driven hook's read-only view (internal.h, #906 slice 4):
|
|
231
|
+
* everything the subtree walk reads, borrowed from the handle — the
|
|
232
|
+
* REGISTRY LAW keeps the handle alive underneath it. */
|
|
233
|
+
void yep_schema_view_of(const yeptris_schema* s, yep_schema_view* out) {
|
|
234
|
+
if (out == NULL) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (s == NULL) {
|
|
238
|
+
memset(out, 0, sizeof(*out));
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
out->dom = s->dom;
|
|
242
|
+
out->sroot = s->sroot;
|
|
243
|
+
out->cache = s->cache;
|
|
244
|
+
out->res = s->res;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
YEPTRIS_API void yeptris_schema_free(yeptris_schema* s) {
|
|
248
|
+
if (s == NULL) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const yep_allocator* sys = yep_system_allocator();
|
|
252
|
+
yep_js_resources_free(s->res);
|
|
253
|
+
yep_re_cache_free(s->cache);
|
|
254
|
+
yeptris_document_free(s->doc); /* the DOM and every pool under it */
|
|
255
|
+
yep_free(sys, s->bytes); /* the views' home: freed after its readers */
|
|
256
|
+
yep_free(sys, s);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
YEPTRIS_API YeptrisStatus yeptris_schema_validate(yeptris_schema* s, const char* buf, size_t len,
|
|
260
|
+
yeptris_validate_report** out) {
|
|
261
|
+
if (out == NULL || s == NULL || (buf == NULL && len != 0)) {
|
|
262
|
+
return YEPTRIS_ERROR_ARG;
|
|
263
|
+
}
|
|
264
|
+
*out = NULL;
|
|
265
|
+
|
|
266
|
+
/* the instance stream (core12, the one-shot's exact parse) */
|
|
267
|
+
YeptrisParseOptions opts;
|
|
268
|
+
memset(&opts, 0, sizeof(opts));
|
|
269
|
+
YeptrisStatus st = YEPTRIS_OK;
|
|
270
|
+
YeptrisDocument idoc = yeptris_parse_eager_ex(buf, len, &opts, &st);
|
|
271
|
+
if (idoc == NULL) {
|
|
272
|
+
if (st == YEPTRIS_OK) {
|
|
273
|
+
/* an empty instance stream: nothing to invalidate */
|
|
274
|
+
yeptris_validate_report* r = yep_validate_report_new();
|
|
275
|
+
if (r == NULL) {
|
|
276
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
277
|
+
}
|
|
278
|
+
*out = r;
|
|
279
|
+
return YEPTRIS_OK;
|
|
280
|
+
}
|
|
281
|
+
return st; /* the parse's own error */
|
|
282
|
+
}
|
|
283
|
+
yep_dom* idom = yep_doc_dom((yeptris_document*)idoc);
|
|
284
|
+
if (idom == NULL) {
|
|
285
|
+
yeptris_document_free(idoc);
|
|
286
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
yeptris_validate_report* r = yep_validate_report_new();
|
|
290
|
+
if (r == NULL) {
|
|
291
|
+
yeptris_document_free(idoc);
|
|
292
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
293
|
+
}
|
|
294
|
+
/* the handle is a pure reader here (its cache and identifier map
|
|
295
|
+
* are immutable): the same walk, the same report shape, the
|
|
296
|
+
* one-shot's verdicts */
|
|
297
|
+
int rc =
|
|
298
|
+
yep_jsonschema_run(s->dom, s->sroot, idom, idom->docs, idom->dcount, r, s->cache, s->res);
|
|
299
|
+
yeptris_document_free(idoc);
|
|
300
|
+
if (rc != 0) {
|
|
301
|
+
yeptris_validate_report_free(r);
|
|
302
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
303
|
+
}
|
|
304
|
+
*out = r;
|
|
305
|
+
return r->count > 0 ? YEPTRIS_ERROR_SCHEMA : YEPTRIS_OK;
|
|
306
|
+
}
|
|
@@ -45,10 +45,30 @@ typedef struct yep_vctx {
|
|
|
45
45
|
size_t path_len, path_cap;
|
|
46
46
|
int depth; /* the walk's nesting guard (never exceeds the DOM's) */
|
|
47
47
|
int oom; /* an allocation failed: stop diagnosing */
|
|
48
|
-
/* JSON Schema trial suppression (anyOf/oneOf/not probes)
|
|
48
|
+
/* JSON Schema trial suppression (anyOf/oneOf/not probes): emits
|
|
49
|
+
* inside a probe never reach the report and never touch
|
|
50
|
+
* fail_mark — the probe's own validity is ITS trial_fail delta
|
|
51
|
+
* (zero delta = held), the enclosing application's is its
|
|
52
|
+
* fail_mark delta */
|
|
49
53
|
int suppress;
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
/* the walks' invalid-application counters: every emit increments
|
|
55
|
+
* exactly one of them (suppressed -> trial_fail, otherwise
|
|
56
|
+
* fail_mark), so an application's validity is one comparison (the
|
|
57
|
+
* unevaluated* annotation model reads fail_mark) */
|
|
58
|
+
int fail_mark;
|
|
59
|
+
int trial_fail;
|
|
60
|
+
int ref_depth; /* consecutive $ref/$dynamicRef expansions */
|
|
61
|
+
/* the event route's staging hook (#902): when set, composed
|
|
62
|
+
* diagnostics join the OPEN mapping's stage (the flush replays
|
|
63
|
+
* [own tag][duplicates][pair content] so report order stays the
|
|
64
|
+
* DOM walk's); the cap counts the walk position (rep count +
|
|
65
|
+
* staged). NULL on the DOM route — the report path, unchanged. */
|
|
66
|
+
void (*stage_put)(void* stage, const yeptris_diagnostic* d);
|
|
67
|
+
void* stage;
|
|
68
|
+
size_t staged;
|
|
69
|
+
/* the tag-driven registry (#906 slice 4): NULL = no bindings —
|
|
70
|
+
* the DOM route only (the event route keeps its lanes). */
|
|
71
|
+
const yeptris_schema_registry* reg;
|
|
52
72
|
} yep_vctx;
|
|
53
73
|
|
|
54
74
|
/* Offset of a node's first positioned byte (the value span of the node
|
|
@@ -56,26 +76,109 @@ typedef struct yep_vctx {
|
|
|
56
76
|
* everything reachable lives in the arena — line/col unknown). */
|
|
57
77
|
uint32_t yep_validate_node_off(const yep_dom* d, uint32_t id);
|
|
58
78
|
|
|
79
|
+
/* ---- the fact cores (shared by the DOM walk and the event route) -------
|
|
80
|
+
*
|
|
81
|
+
* The family checks read five facts per node: kind (yep_dom_kind),
|
|
82
|
+
* explicit-tag presence, the resolved tag id, the plainness law
|
|
83
|
+
* (PLAIN style or the implicit flag), and the value bytes. The DOM
|
|
84
|
+
* walk extracts them from yep_dnode; the event route (#902) extracts
|
|
85
|
+
* the same five from the engine's events — both call THESE cores, so
|
|
86
|
+
* a verdict change lands once and both routes move together. `off` is
|
|
87
|
+
* the caller's position fact (the DOM's node_off law / the event
|
|
88
|
+
* route's borrowed-view law); UINT32_MAX = unpositioned (line/col 0).
|
|
89
|
+
* A zero-length value decodes to {NULL, 0} (the yep_dom_view law). */
|
|
90
|
+
|
|
91
|
+
/* The scalar tag law: explicit tag wins, then the resolver verdict for
|
|
92
|
+
* plain/implicit scalars, then str for quoted/block styles. */
|
|
93
|
+
uint8_t yep_validate_tag_of(uint8_t tag_id, int has_tag, int plainish);
|
|
94
|
+
|
|
95
|
+
/* Explicit-tag consistency (both families). */
|
|
96
|
+
struct yep_resolver;
|
|
97
|
+
void yep_check_tag_facts(yep_vctx* c, int kind, int has_tag, uint8_t tag_id, yep_view value,
|
|
98
|
+
uint32_t off, const struct yep_resolver* fam, int json_family);
|
|
99
|
+
|
|
100
|
+
/* json12: a plain scalar must match a JSON production; explicit
|
|
101
|
+
* non-JSON tags rejected. */
|
|
102
|
+
void yep_check_json_scalar_facts(yep_vctx* c, int has_tag, uint8_t tag_id, int plainish,
|
|
103
|
+
yep_view value, uint32_t off);
|
|
104
|
+
|
|
105
|
+
/* json12: a SCALAR mapping key's checks (the caller resolves aliases
|
|
106
|
+
* and non-scalar kinds first — the DOM wrapper keeps that recursion). */
|
|
107
|
+
void yep_check_json_key_facts(yep_vctx* c, int has_tag, uint8_t tag_id, int plainish,
|
|
108
|
+
yep_view value, uint32_t off);
|
|
109
|
+
|
|
110
|
+
/* ---- the canonical digest law (spec 3.2.1.3) --------------------------- */
|
|
111
|
+
|
|
112
|
+
/* The 64-bit fold primitive behind every canonical fingerprint. */
|
|
113
|
+
uint64_t yep_validate_hash_mix(uint64_t h, uint64_t v);
|
|
114
|
+
|
|
115
|
+
/* Seed constants of the canonical fold (validate.c's DOM hash and the
|
|
116
|
+
* event route's streaming fold must agree bit for bit). */
|
|
117
|
+
#define YEP_VAL_DIGEST_SEQ_SEED 0x5EED51ULL /* sequences: ordered fold */
|
|
118
|
+
#define YEP_VAL_DIGEST_MAP_SEED 0x5EED4A9ULL /* mappings: XOR of pairs */
|
|
119
|
+
#define YEP_VAL_DIGEST_PAIR_SEED 0x51D1ULL /* one (key, value) pair */
|
|
120
|
+
#define YEP_VAL_DIGEST_ALIAS 0xA11AULL /* unbound alias fallback */
|
|
121
|
+
#define YEP_VAL_DIGEST_SCALAR 0x5CA1AULL /* scalar base (tag added) */
|
|
122
|
+
|
|
123
|
+
/* The scalar arm of the canonical hash: base + tag, the numeric VALUE
|
|
124
|
+
* for int/float (the double bits), the raw bytes otherwise. */
|
|
125
|
+
uint64_t yep_validate_scalar_digest(uint8_t tag, yep_view v);
|
|
126
|
+
|
|
59
127
|
/* Emits one diagnostic at the current path. line/col resolve from
|
|
60
128
|
* `off` through the lazy line index; 0/0 when unknown. Detail is
|
|
61
129
|
* printf-composed into the bounded slot. Never fails the caller: the
|
|
62
130
|
* report cap turns the last slot into the LIMIT sentinel. */
|
|
63
131
|
void yep_validate_emit(yep_vctx* c, int code, uint32_t off, const char* detail_fmt, ...);
|
|
64
132
|
|
|
133
|
+
/* The report-path writer (the cap law's one home): appends a RESOLVED
|
|
134
|
+
* diagnostic, or turns the last slot into the LIMIT sentinel once the
|
|
135
|
+
* report is full. The event route's flush replays its staged
|
|
136
|
+
* diagnostics through this — the compose time (and therefore the path
|
|
137
|
+
* and position) stays the walk's. */
|
|
138
|
+
void yep_validate_report_put(yep_vctx* c, const yeptris_diagnostic* d);
|
|
139
|
+
|
|
65
140
|
/* JSON-pointer path scratch: push an escaped segment / a decimal
|
|
66
141
|
* index, pop to a mark. 0 ok, -1 OOM (ctx.oom set; the walk unwinds). */
|
|
67
142
|
int yep_validate_path_push(yep_vctx* c, const char* seg, size_t seg_len);
|
|
68
143
|
int yep_validate_path_push_index(yep_vctx* c, uint32_t idx);
|
|
69
144
|
void yep_validate_path_pop(yep_vctx* c, size_t mark);
|
|
70
145
|
|
|
146
|
+
/* The stream face's document attribution (#885 item 4): a validated
|
|
147
|
+
* stream is addressed as an array of documents — when it holds MORE
|
|
148
|
+
* THAN ONE document, every diagnostic path is prefixed with the
|
|
149
|
+
* document's index segment, so diagnostics name their document ("/1/k"
|
|
150
|
+
* is key k of document 1; the line/col stay input-absolute). Streams
|
|
151
|
+
* with a single document keep the bare instance pointers (the
|
|
152
|
+
* JSON-Schema-Test-Suite's paths and every single-doc pin are
|
|
153
|
+
* unchanged). Call before a document's walk and pop the returned mark
|
|
154
|
+
* after it; OOM sets ctx.oom and the walk unwinds. */
|
|
155
|
+
size_t yep_validate_doc_prefix(yep_vctx* c, int qualified, uint32_t index);
|
|
156
|
+
|
|
71
157
|
/* The bounded ECMA-regex subset behind `pattern` (jsonschema.c):
|
|
72
158
|
* literals, '.', classes, groups, alternation, the greedy/lazy
|
|
73
|
-
* quantifiers, anchors, \d\w\s\D\W\S\b\B
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
159
|
+
* quantifiers, anchors, \d\w\s\D\W\S\b\B, \xHH, \cX and the
|
|
160
|
+
* \p{Letter}/\p{digit} property escapes. Classes match WHOLE UTF-8
|
|
161
|
+
* code points (the named classes carry range tables: ASCII \d/\w,
|
|
162
|
+
* Unicode \s, code-point complements, generated Unicode properties);
|
|
163
|
+
* literals match byte-wise. A Thompson NFA over per-thread positions —
|
|
164
|
+
* O(len * m), no backtracking blowup, no recursion over the subject.
|
|
165
|
+
* Patterns over the program budget are invalid. 1 match, 0 no match,
|
|
166
|
+
* -1 invalid pattern. */
|
|
77
167
|
int yep_re_search(const char* pat, uint32_t pat_len, const char* s, uint32_t s_len);
|
|
78
168
|
|
|
169
|
+
/* The retained-program cache behind the compiled schema (#885 item 3):
|
|
170
|
+
* pattern source -> compiled NFA, populated at compile time, immutable
|
|
171
|
+
* afterwards (read-only sharing, the document law). A miss — a NULL
|
|
172
|
+
* cache included — compiles fresh with yep_re_search's exact verdicts;
|
|
173
|
+
* cache_add returns 1 stored, 0 not retained (invalid pattern, empty,
|
|
174
|
+
* table full — misses recompile), -1 allocation failure (loud). */
|
|
175
|
+
typedef struct yep_re_cache yep_re_cache;
|
|
176
|
+
yep_re_cache* yep_re_cache_new(void);
|
|
177
|
+
void yep_re_cache_free(yep_re_cache* t);
|
|
178
|
+
int yep_re_cache_add(yep_re_cache* t, const char* pat, uint32_t plen);
|
|
179
|
+
int yep_re_cache_search(const yep_re_cache* t, const char* pat, uint32_t plen, const char* s,
|
|
180
|
+
uint32_t s_len);
|
|
181
|
+
|
|
79
182
|
/* Canonical scalar tag of a DOM node (explicit tag, then the parse
|
|
80
183
|
* resolver's plain verdict, then str): the value model both walks
|
|
81
184
|
* compare under. */
|
|
@@ -89,11 +192,153 @@ uint64_t yep_validate_node_hash(const yep_dom* d, uint32_t id, int depth);
|
|
|
89
192
|
int yep_validate_node_equal(const yep_dom* da, uint32_t a, const yep_dom* db, uint32_t b,
|
|
90
193
|
int depth);
|
|
91
194
|
|
|
195
|
+
/* ---- the schema identifier map (resources.c) ----------------------------- */
|
|
196
|
+
|
|
197
|
+
/* Bounded identifier tables: an identifier past a cap (or a URI over
|
|
198
|
+
* the length cap) is not registered — the reference then fails to
|
|
199
|
+
* resolve at validation (DIAG_REF), exactly like any other unknown
|
|
200
|
+
* target. Nothing loops, nothing guesses. */
|
|
201
|
+
#define YEP_JS_MAX_RESOURCES 1024
|
|
202
|
+
#define YEP_JS_MAX_ANCHORS 1024
|
|
203
|
+
#define YEP_JS_MAX_REFSITES 8192
|
|
204
|
+
#define YEP_JS_URI_MAX 512
|
|
205
|
+
#define YEP_JS_MAX_SCOPE 256 /* the runtime dynamic-scope stack */
|
|
206
|
+
|
|
207
|
+
/* One schema RESOURCE: a canonical (fragment-free) URI naming the
|
|
208
|
+
* schema object that established it with "$id" — pointer fragments
|
|
209
|
+
* walk from that node. The document root is resource 0 (the empty
|
|
210
|
+
* base "" when the schema has no "$id"). */
|
|
211
|
+
typedef struct {
|
|
212
|
+
char* uri;
|
|
213
|
+
uint32_t root;
|
|
214
|
+
} js_resource;
|
|
215
|
+
|
|
216
|
+
/* A plain-name fragment: canonical URI + '#' + name -> the node.
|
|
217
|
+
* `dynamic` distinguishes "$dynamicAnchor" (the $dynamicRef
|
|
218
|
+
* extension points) from "$anchor". `res` is the owning resource
|
|
219
|
+
* index (anchors belong to the resource of their nearest "$id"). */
|
|
220
|
+
typedef struct {
|
|
221
|
+
char* key;
|
|
222
|
+
uint32_t node;
|
|
223
|
+
uint32_t res;
|
|
224
|
+
uint8_t dynamic;
|
|
225
|
+
} js_anchor;
|
|
226
|
+
|
|
227
|
+
/* A "$ref"/"$dynamicRef" site: the canonical base URI it resolves
|
|
228
|
+
* against, and that base resource's root (where fragment-only
|
|
229
|
+
* pointers start walking). */
|
|
230
|
+
typedef struct {
|
|
231
|
+
uint32_t site;
|
|
232
|
+
char* base;
|
|
233
|
+
uint32_t base_root;
|
|
234
|
+
} js_refsite;
|
|
235
|
+
|
|
236
|
+
/* The compiled schema's identifier map (built once by the crawl at
|
|
237
|
+
* compile time, read-only afterwards — the document law). Everything
|
|
238
|
+
* it owns dies with yep_js_resources_free. */
|
|
239
|
+
typedef struct {
|
|
240
|
+
js_resource* res;
|
|
241
|
+
uint32_t res_n;
|
|
242
|
+
js_anchor* anc;
|
|
243
|
+
uint32_t anc_n;
|
|
244
|
+
js_refsite* site;
|
|
245
|
+
uint32_t site_n;
|
|
246
|
+
uint32_t* rindex; /* node id -> owning resource index (UINT32_MAX unvisited) */
|
|
247
|
+
uint32_t rindex_n;
|
|
248
|
+
} js_resources;
|
|
249
|
+
|
|
250
|
+
/* The constructor: one bounded DFS over the schema DOM collecting
|
|
251
|
+
* every $id/$anchor/$dynamicAnchor and $ref/$dynamicRef site. NULL on
|
|
252
|
+
* allocation failure. */
|
|
253
|
+
js_resources* yep_js_resources_crawl(const yep_dom* d, uint32_t root);
|
|
254
|
+
void yep_js_resources_free(js_resources* r);
|
|
255
|
+
|
|
256
|
+
/* Lookups (linear over the bounded tables): resource by canonical
|
|
257
|
+
* URI; anchor by key (URI + '#' + name); a resource's DYNAMIC anchor
|
|
258
|
+
* by plain name (the dynamic-scope search's per-resource probe); a
|
|
259
|
+
* ref site's base. Each returns 1 found, 0 absent. */
|
|
260
|
+
int js_res_find(const js_resources* r, const char* uri, uint32_t* idx_out);
|
|
261
|
+
int js_anchor_find(const js_resources* r, const char* key, size_t key_len, uint32_t* node_out,
|
|
262
|
+
uint8_t* dyn_out);
|
|
263
|
+
int js_anchor_dynamic_in_res(const js_resources* r, uint32_t res_idx, const char* name,
|
|
264
|
+
size_t name_len, uint32_t* node_out);
|
|
265
|
+
int js_refsite_find(const js_resources* r, uint32_t site_node, const char** base,
|
|
266
|
+
uint32_t* base_root);
|
|
267
|
+
|
|
268
|
+
/* URI-reference resolution (RFC 3986 section 5.2, the exercised
|
|
269
|
+
* subset: schemes, authorities, path merge with dot-segment removal,
|
|
270
|
+
* query carry). Produces the canonical fragment-free form. 0 ok, -1
|
|
271
|
+
* overlong (out holds ""). */
|
|
272
|
+
int js_uri_resolve(const char* base, const char* ref, size_t ref_len, char* out, size_t cap);
|
|
273
|
+
|
|
92
274
|
/* jsonschema.c's driver: applies the schema tree (its own DOM) to
|
|
93
|
-
* every instance document root, emitting into `rep`.
|
|
94
|
-
*
|
|
275
|
+
* every instance document root, emitting into `rep`. `cache` is the
|
|
276
|
+
* compiled schema's retained pattern programs (NULL: none — the
|
|
277
|
+
* one-shot face). `res` is the compiled schema's identifier map (the
|
|
278
|
+
* resources/anchors/ref-site bases the reference machinery resolves
|
|
279
|
+
* through; NULL: none — every reference beyond a bare "#/..." pointer
|
|
280
|
+
* stays unresolvable). Returns 0, -1 on OOM. */
|
|
95
281
|
int yep_jsonschema_run(const yep_dom* schema_dom, uint32_t schema_root, const yep_dom* instance_dom,
|
|
96
|
-
const uint32_t* doc_roots, uint32_t doc_count, yeptris_validate_report* rep
|
|
282
|
+
const uint32_t* doc_roots, uint32_t doc_count, yeptris_validate_report* rep,
|
|
283
|
+
const yep_re_cache* cache, const js_resources* res);
|
|
284
|
+
|
|
285
|
+
/* The report constructor (validate.c owns the report machinery): a
|
|
286
|
+
* fresh empty report, NULL on allocation failure. */
|
|
287
|
+
yeptris_validate_report* yep_validate_report_new(void);
|
|
288
|
+
|
|
289
|
+
/* compile.c's seam (#885 item 3): the compiled-schema constructor with
|
|
290
|
+
* an explicit status — the one-shot face preserves its exact observable
|
|
291
|
+
* statuses through it. NULL on failure with *st = YEPTRIS_ERROR_ARG
|
|
292
|
+
* (NULL bytes with length, or bytes that hold no document; the thread
|
|
293
|
+
* error channel carries the message), the failed parse's status, or
|
|
294
|
+
* YEPTRIS_ERROR_MEMORY. */
|
|
295
|
+
struct yeptris_schema;
|
|
296
|
+
yeptris_schema* yep_schema_compile_st(const char* bytes, size_t n, YeptrisStatus* st);
|
|
297
|
+
|
|
298
|
+
/* The validation-family selector shared by both routes (#902): CORE_12
|
|
299
|
+
* and JSON_12 resolve to their resolvers (json_family set for the
|
|
300
|
+
* strict lane); every other schema is a parse-compat resolver, not a
|
|
301
|
+
* family — 0 with the thread error channel set, exactly like the DOM
|
|
302
|
+
* face's ARG rejection. */
|
|
303
|
+
int yep_validate_schema_family(YeptrisSchema schema, const struct yep_resolver** fam,
|
|
304
|
+
int* json_family);
|
|
305
|
+
|
|
306
|
+
/* ---- the tag-driven schema hook (#906 slice 4) --------------------------- */
|
|
307
|
+
|
|
308
|
+
/* The compiled schema's read-only evaluation view: everything the
|
|
309
|
+
* keyword walk reads, borrowed from the handle (the REGISTRY LAW
|
|
310
|
+
* applies — the handle must outlive every view taken from it). */
|
|
311
|
+
typedef struct {
|
|
312
|
+
const yep_dom* dom; /* the schema's retained tree */
|
|
313
|
+
uint32_t sroot; /* its document-0 root */
|
|
314
|
+
const yep_re_cache* cache; /* retained pattern programs */
|
|
315
|
+
const js_resources* res; /* the identifier map */
|
|
316
|
+
} yep_schema_view;
|
|
317
|
+
|
|
318
|
+
/* compile.c: fills *out from the handle. NULL handle fills zeros. */
|
|
319
|
+
void yep_schema_view_of(const yeptris_schema* s, yep_schema_view* out);
|
|
320
|
+
|
|
321
|
+
/* jsonschema.c: applies the bound schema's root to ONE instance
|
|
322
|
+
* subtree. `inst` is the CALLER'S walk context (the DOM route's
|
|
323
|
+
* yep_vctx) — its path prefix (the tag site), report, line index and
|
|
324
|
+
* guards are shared, so the subtree's misses land at the tag site's
|
|
325
|
+
* path + the schema's instance pointers with the offending node's
|
|
326
|
+
* position, and the cap law holds across the whole report. The
|
|
327
|
+
* context's scratch pointers (path buffer, line index) may have been
|
|
328
|
+
* reallocated on return — the caller frees them as before. Returns 0,
|
|
329
|
+
* -1 on OOM (ctx.oom set; the walk unwinds). */
|
|
330
|
+
int yep_jsonschema_apply_subtree(const yep_dom* schema_dom, uint32_t schema_root, yep_vctx* inst,
|
|
331
|
+
uint32_t inst_root, const yep_re_cache* cache,
|
|
332
|
+
const js_resources* res);
|
|
333
|
+
|
|
334
|
+
/* ---- the structured output face (#906 slice 5) ---------------------------
|
|
335
|
+
*
|
|
336
|
+
* output.c: the report -> JSON transform (the published BASIC shape;
|
|
337
|
+
* the byte contract lives on the public header). The keyword names
|
|
338
|
+
* behind the code-derived keywordLocation pointers — the one table
|
|
339
|
+
* (the output SSOT): a code without a keyword row writes the root
|
|
340
|
+
* pointer "". */
|
|
341
|
+
const char* yep_validate_output_keyword(uint32_t code);
|
|
97
342
|
|
|
98
343
|
#ifdef __cplusplus
|
|
99
344
|
}
|