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
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
* key; strings byte-wise; collections structurally);
|
|
10
10
|
* - 12_JSON only: mapping keys must be string scalars; plain scalars
|
|
11
11
|
* must match a JSON production (spec 10.2.2's `*` -> Error row);
|
|
12
|
-
* explicit non-JSON tags rejected
|
|
12
|
+
* explicit non-JSON tags rejected;
|
|
13
|
+
* - 12_FULL only: the core checks plus the full family's timestamp
|
|
14
|
+
* type — explicit !!timestamp content must re-resolve through the
|
|
15
|
+
* full12 classifier (spec 2.22's four forms), and untagged plains
|
|
16
|
+
* resolve timestamps at parse time (the resolver, not this walk).
|
|
17
|
+
* !!binary/!!merge/!!value/consumer tags ride as passthrough
|
|
18
|
+
* (spec 10.4: arbitrary explicit tags never invalidate a schema).
|
|
13
19
|
*
|
|
14
20
|
* 11_COMPAT is the parse-compat resolver, not a validation family —
|
|
15
21
|
* the entry rejects it (ARG).
|
|
@@ -22,6 +28,7 @@
|
|
|
22
28
|
* the caller's buffer beyond the call.
|
|
23
29
|
*/
|
|
24
30
|
|
|
31
|
+
#include <stddef.h>
|
|
25
32
|
#include <stdio.h>
|
|
26
33
|
#include <stdlib.h>
|
|
27
34
|
#include <string.h>
|
|
@@ -168,13 +175,18 @@ void yep_validate_path_pop(yep_vctx* c, size_t mark) {
|
|
|
168
175
|
c->path_len = mark;
|
|
169
176
|
}
|
|
170
177
|
|
|
178
|
+
size_t yep_validate_doc_prefix(yep_vctx* c, int qualified, uint32_t index) {
|
|
179
|
+
size_t mark = c->path_len;
|
|
180
|
+
if (qualified && yep_validate_path_push_index(c, index) != 0) {
|
|
181
|
+
c->oom = 1; /* the path scratch failed: the walk unwinds */
|
|
182
|
+
}
|
|
183
|
+
return mark;
|
|
184
|
+
}
|
|
185
|
+
|
|
171
186
|
/* ---- the report --------------------------------------------------------- */
|
|
172
187
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
c->trial_hit = 1; /* a probe (anyOf/oneOf/not): swallow and mark */
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
188
|
+
/* The report-path writer (the cap law's one home). */
|
|
189
|
+
void yep_validate_report_put(yep_vctx* c, const yeptris_diagnostic* d) {
|
|
178
190
|
yeptris_validate_report* r = c->rep;
|
|
179
191
|
if (r->count >= YEP_VALIDATE_MAX_DIAGS) {
|
|
180
192
|
/* the cap: the LAST slot becomes the LIMIT sentinel */
|
|
@@ -186,22 +198,44 @@ void yep_validate_emit(yep_vctx* c, int code, uint32_t off, const char* detail_f
|
|
|
186
198
|
YEP_VALIDATE_MAX_DIAGS);
|
|
187
199
|
return;
|
|
188
200
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
201
|
+
r->diags[r->count++] = *d;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void yep_validate_emit(yep_vctx* c, int code, uint32_t off, const char* detail_fmt, ...) {
|
|
205
|
+
if (c->suppress > 0) {
|
|
206
|
+
c->trial_fail++; /* a probe (anyOf/oneOf/not/if): swallow, fail its own extent */
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
c->fail_mark++; /* the application that owns this extent is invalid */
|
|
210
|
+
yeptris_diagnostic d;
|
|
211
|
+
memset(&d, 0, sizeof(d));
|
|
212
|
+
d.code = (uint32_t)code;
|
|
192
213
|
if (off != UINT32_MAX && off < c->input_len) {
|
|
193
|
-
d
|
|
194
|
-
line_col_of(c, off, &d
|
|
214
|
+
d.offset = off;
|
|
215
|
+
line_col_of(c, off, &d.line, &d.col);
|
|
195
216
|
}
|
|
196
217
|
size_t plen = c->path_len < YEPTRIS_DIAG_PATH_MAX - 1 ? c->path_len : YEPTRIS_DIAG_PATH_MAX - 1;
|
|
197
218
|
if (c->path != NULL) {
|
|
198
|
-
memcpy(d
|
|
219
|
+
memcpy(d.path, c->path, plen);
|
|
199
220
|
}
|
|
200
221
|
va_list ap;
|
|
201
222
|
va_start(ap, detail_fmt);
|
|
202
|
-
vsnprintf(d
|
|
223
|
+
vsnprintf(d.detail, sizeof(d.detail), detail_fmt, ap);
|
|
203
224
|
va_end(ap);
|
|
204
|
-
|
|
225
|
+
if (c->stage_put != NULL) {
|
|
226
|
+
/* the event route's staging (#902): the diagnostic joins the
|
|
227
|
+
* OPEN mapping's stage — the flush replays [own tag][duplicates]
|
|
228
|
+
* [pair content] so the report order stays the DOM walk's.
|
|
229
|
+
* NOTHING is dropped here: the walk position is unknown until
|
|
230
|
+
* the flush order is fixed (a mapping's duplicates precede its
|
|
231
|
+
* content), so the cap law applies at the replay, through
|
|
232
|
+
* yep_validate_report_put — the staging holds O(violations),
|
|
233
|
+
* the same input-bounded class as the DOM route's tree. */
|
|
234
|
+
c->staged++;
|
|
235
|
+
c->stage_put(c->stage, &d);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
yep_validate_report_put(c, &d);
|
|
205
239
|
}
|
|
206
240
|
|
|
207
241
|
/* ---- node facts --------------------------------------------------------- */
|
|
@@ -226,27 +260,60 @@ uint32_t yep_validate_node_off(const yep_dom* d, uint32_t id) {
|
|
|
226
260
|
|
|
227
261
|
/* ---- canonical key/value facts (shared with jsonschema.c) ---------------- */
|
|
228
262
|
|
|
229
|
-
/* The
|
|
230
|
-
*
|
|
231
|
-
uint8_t
|
|
232
|
-
if (
|
|
233
|
-
return
|
|
263
|
+
/* The scalar tag law (internal.h's fact core; the DOM wrapper below
|
|
264
|
+
* and the event route's facts both land here). */
|
|
265
|
+
uint8_t yep_validate_tag_of(uint8_t tag_id, int has_tag, int plainish) {
|
|
266
|
+
if (has_tag) {
|
|
267
|
+
return tag_id;
|
|
234
268
|
}
|
|
235
269
|
/* implicit marks the resolver's verdict even at style ANY (the
|
|
236
270
|
* document-level empty scalar carries no token to style) */
|
|
237
|
-
if (
|
|
238
|
-
return
|
|
271
|
+
if (plainish) {
|
|
272
|
+
return tag_id;
|
|
239
273
|
}
|
|
240
274
|
return YEPTRIS_TAG_STR;
|
|
241
275
|
}
|
|
242
276
|
|
|
277
|
+
/* The resolved tag id of a scalar node (explicit tag wins, then the
|
|
278
|
+
* plain verdict already on the node, then str for quoted/block). */
|
|
279
|
+
uint8_t yep_validate_scalar_tag(const yep_dnode* n) {
|
|
280
|
+
return yep_validate_tag_of(n->tag_id, n->tag.len > 0,
|
|
281
|
+
n->style == YEP_STYLE_PLAIN || n->implicit);
|
|
282
|
+
}
|
|
283
|
+
|
|
243
284
|
/* Canonical hash of a node (the key-uniqueness fingerprint): tags and
|
|
244
285
|
* canonical forms, numeric values for int/float. */
|
|
245
|
-
|
|
286
|
+
uint64_t yep_validate_hash_mix(uint64_t h, uint64_t v) {
|
|
246
287
|
h ^= v + 0x9E3779B97F4A7C15ULL + (h << 6) + (h >> 2);
|
|
247
288
|
return h;
|
|
248
289
|
}
|
|
249
290
|
|
|
291
|
+
/* The scalar arm (internal.h's law): base + tag; int/float fold the
|
|
292
|
+
* numeric VALUE — one bucket for both tags (1 and 1.0 are the same
|
|
293
|
+
* canonical number) — exact for i64-representable magnitudes up to
|
|
294
|
+
* 2^53, and beyond that two distinct ints may collide (equality is
|
|
295
|
+
* the authority, a collision only costs a probe); everything else
|
|
296
|
+
* folds the raw bytes. */
|
|
297
|
+
uint64_t yep_validate_scalar_digest(uint8_t tag, yep_view v) {
|
|
298
|
+
uint64_t h = YEP_VAL_DIGEST_SCALAR + tag;
|
|
299
|
+
if (tag == YEPTRIS_TAG_INT || tag == YEPTRIS_TAG_FLOAT) {
|
|
300
|
+
double dv = 0;
|
|
301
|
+
int64_t iv = 0;
|
|
302
|
+
if (yep_num_i64(v.p, v.len, &iv) == 0) {
|
|
303
|
+
dv = (double)iv;
|
|
304
|
+
} else {
|
|
305
|
+
yep_num_f64(v.p, v.len, &dv);
|
|
306
|
+
}
|
|
307
|
+
uint64_t bits;
|
|
308
|
+
memcpy(&bits, &dv, sizeof(bits));
|
|
309
|
+
return yep_validate_hash_mix(h, bits);
|
|
310
|
+
}
|
|
311
|
+
for (uint32_t i = 0; i < v.len; i++) {
|
|
312
|
+
h = yep_validate_hash_mix(h, (unsigned char)v.p[i]);
|
|
313
|
+
}
|
|
314
|
+
return h;
|
|
315
|
+
}
|
|
316
|
+
|
|
250
317
|
uint64_t yep_validate_node_hash(const yep_dom* d, uint32_t id, int depth) {
|
|
251
318
|
if (depth > 64) {
|
|
252
319
|
return 0xDA7A;
|
|
@@ -257,55 +324,36 @@ uint64_t yep_validate_node_hash(const yep_dom* d, uint32_t id, int depth) {
|
|
|
257
324
|
}
|
|
258
325
|
if (n->kind == YEP_DOM_ALIAS) {
|
|
259
326
|
return n->target != UINT32_MAX ? yep_validate_node_hash(d, n->target, depth + 1)
|
|
260
|
-
:
|
|
327
|
+
: yep_validate_hash_mix(YEP_VAL_DIGEST_ALIAS, n->value.len);
|
|
261
328
|
}
|
|
262
329
|
if (n->kind == YEP_DOM_SEQUENCE) {
|
|
263
|
-
uint64_t h =
|
|
330
|
+
uint64_t h = YEP_VAL_DIGEST_SEQ_SEED;
|
|
264
331
|
uint32_t ch = n->first_child;
|
|
265
332
|
while (ch != UINT32_MAX) {
|
|
266
|
-
h =
|
|
333
|
+
h = yep_validate_hash_mix(h, yep_validate_node_hash(d, ch, depth + 1));
|
|
267
334
|
ch = yep_dom_node(d, ch) ? yep_dom_node(d, ch)->next_sibling : UINT32_MAX;
|
|
268
335
|
}
|
|
269
336
|
return h;
|
|
270
337
|
}
|
|
271
338
|
if (n->kind == YEP_DOM_MAPPING) {
|
|
272
|
-
|
|
339
|
+
/* mappings are UNORDERED (spec 3.2.1.3 canonical form): the
|
|
340
|
+
* fold is commutative (XOR of per-pair mixes) so key order
|
|
341
|
+
* cannot change the fingerprint */
|
|
342
|
+
uint64_t h = YEP_VAL_DIGEST_MAP_SEED;
|
|
273
343
|
uint32_t k = n->first_child;
|
|
274
344
|
while (k != UINT32_MAX) {
|
|
275
345
|
uint32_t v = yep_dom_node(d, k) ? yep_dom_node(d, k)->next_sibling : UINT32_MAX;
|
|
276
|
-
|
|
277
|
-
|
|
346
|
+
uint64_t pair = yep_validate_hash_mix(YEP_VAL_DIGEST_PAIR_SEED,
|
|
347
|
+
yep_validate_node_hash(d, k, depth + 1));
|
|
348
|
+
pair = yep_validate_hash_mix(pair, yep_validate_node_hash(d, v, depth + 1));
|
|
349
|
+
h ^= pair;
|
|
278
350
|
k = v != UINT32_MAX && yep_dom_node(d, v) ? yep_dom_node(d, v)->next_sibling
|
|
279
351
|
: UINT32_MAX;
|
|
280
352
|
}
|
|
281
353
|
return h;
|
|
282
354
|
}
|
|
283
355
|
/* scalar: tag + canonical form */
|
|
284
|
-
|
|
285
|
-
yep_view v = yep_dom_view(d, n->value);
|
|
286
|
-
uint64_t h = 0x5CA1A + tag;
|
|
287
|
-
if (tag == YEPTRIS_TAG_INT || tag == YEPTRIS_TAG_FLOAT) {
|
|
288
|
-
/* canonical: the numeric value (0o13 == 0xB == 11; 1 == 1.0
|
|
289
|
-
* rides the same number bucket only when the tags match) */
|
|
290
|
-
int64_t iv = 0;
|
|
291
|
-
double dv = 0;
|
|
292
|
-
if (yep_num_i64(v.p, v.len, &iv) == 0) {
|
|
293
|
-
int is_neg = iv < 0;
|
|
294
|
-
uint64_t mag = is_neg ? (uint64_t)(-(iv + 1)) + 1 : (uint64_t)iv;
|
|
295
|
-
h = hash_mix(h, mag ^ (is_neg ? 0x8000000000000000ULL : 0));
|
|
296
|
-
} else if (yep_num_f64(v.p, v.len, &dv) == 0) {
|
|
297
|
-
uint64_t bits;
|
|
298
|
-
memcpy(&bits, &dv, sizeof(bits));
|
|
299
|
-
h = hash_mix(h, bits);
|
|
300
|
-
} else {
|
|
301
|
-
h = hash_mix(h, v.len);
|
|
302
|
-
}
|
|
303
|
-
return h;
|
|
304
|
-
}
|
|
305
|
-
for (uint32_t i = 0; i < v.len; i++) {
|
|
306
|
-
h = hash_mix(h, (unsigned char)v.p[i]);
|
|
307
|
-
}
|
|
308
|
-
return h;
|
|
356
|
+
return yep_validate_scalar_digest(yep_validate_scalar_tag(n), yep_dom_view(d, n->value));
|
|
309
357
|
}
|
|
310
358
|
|
|
311
359
|
/* Canonical equality (spec 3.2.1.3): same tag and canonical form.
|
|
@@ -380,24 +428,31 @@ int yep_validate_node_equal(const yep_dom* da, uint32_t a, const yep_dom* db, ui
|
|
|
380
428
|
}
|
|
381
429
|
return 1;
|
|
382
430
|
}
|
|
383
|
-
/* scalars
|
|
431
|
+
/* scalars: numbers (int or float, either tag) compare by numeric
|
|
432
|
+
* value (2020-12: 0 and 0.0 are one constant); everything else
|
|
433
|
+
* requires the same tag */
|
|
384
434
|
uint8_t ta = yep_validate_scalar_tag(na), tb = yep_validate_scalar_tag(nb);
|
|
385
|
-
|
|
435
|
+
int numa = ta == YEPTRIS_TAG_INT || ta == YEPTRIS_TAG_FLOAT;
|
|
436
|
+
int numb = tb == YEPTRIS_TAG_INT || tb == YEPTRIS_TAG_FLOAT;
|
|
437
|
+
if (numa != numb) {
|
|
386
438
|
return 0;
|
|
387
439
|
}
|
|
388
440
|
yep_view va = yep_dom_view(da, na->value);
|
|
389
441
|
yep_view vb = yep_dom_view(db, nb->value);
|
|
390
|
-
if (
|
|
391
|
-
double fa, fb;
|
|
442
|
+
if (numa) {
|
|
392
443
|
int64_t ia, ib;
|
|
393
444
|
if (yep_num_i64(va.p, va.len, &ia) == 0 && yep_num_i64(vb.p, vb.len, &ib) == 0) {
|
|
394
445
|
return ia == ib;
|
|
395
446
|
}
|
|
447
|
+
double fa, fb;
|
|
396
448
|
if (yep_num_f64(va.p, va.len, &fa) == 0 && yep_num_f64(vb.p, vb.len, &fb) == 0) {
|
|
397
449
|
return fa == fb;
|
|
398
450
|
}
|
|
399
451
|
return 0;
|
|
400
452
|
}
|
|
453
|
+
if (ta != tb) {
|
|
454
|
+
return 0;
|
|
455
|
+
}
|
|
401
456
|
return va.len == vb.len && (va.len == 0 || memcmp(va.p, vb.p, va.len) == 0);
|
|
402
457
|
}
|
|
403
458
|
|
|
@@ -431,7 +486,6 @@ static void check_duplicates(yep_vctx* c, uint32_t map_id) {
|
|
|
431
486
|
}
|
|
432
487
|
memset(tbl, 0, (size_t)cap * sizeof(key_slot));
|
|
433
488
|
uint32_t k = m->first_child;
|
|
434
|
-
int reported = 0;
|
|
435
489
|
while (k != UINT32_MAX) {
|
|
436
490
|
uint32_t v = yep_dom_node(d, k) ? yep_dom_node(d, k)->next_sibling : UINT32_MAX;
|
|
437
491
|
uint64_t h64 = yep_validate_node_hash(d, k, 0);
|
|
@@ -439,19 +493,19 @@ static void check_duplicates(yep_vctx* c, uint32_t map_id) {
|
|
|
439
493
|
uint32_t i = h & (cap - 1);
|
|
440
494
|
while (tbl[i].node != 0) {
|
|
441
495
|
if (tbl[i].hash == h && yep_validate_node_equal(d, tbl[i].node - 1, d, k, 0)) {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
key[kl] = '\0';
|
|
452
|
-
yep_validate_emit(c, YEPTRIS_DIAG_DUPLICATE_KEY, off,
|
|
453
|
-
"duplicate mapping key (\"%s\")", key);
|
|
496
|
+
/* enumerate EVERY miss: each key whose canonical form
|
|
497
|
+
* already appeared is its own diagnostic (the report
|
|
498
|
+
* cap bounds a hostile mapping) */
|
|
499
|
+
uint32_t off = yep_validate_node_off(d, k);
|
|
500
|
+
yep_view kv = yep_dom_view(d, yep_dom_node(d, k)->value);
|
|
501
|
+
char key[40];
|
|
502
|
+
size_t kl = kv.len < sizeof(key) - 8 ? kv.len : sizeof(key) - 8;
|
|
503
|
+
if (kl > 0 && kv.p != NULL) {
|
|
504
|
+
memcpy(key, kv.p, kl);
|
|
454
505
|
}
|
|
506
|
+
key[kl] = '\0';
|
|
507
|
+
yep_validate_emit(c, YEPTRIS_DIAG_DUPLICATE_KEY, off,
|
|
508
|
+
"duplicate mapping key (\"%s\")", key);
|
|
455
509
|
break;
|
|
456
510
|
}
|
|
457
511
|
i = (i + 1) & (cap - 1);
|
|
@@ -496,72 +550,91 @@ static const char* tag_word(uint8_t id) {
|
|
|
496
550
|
|
|
497
551
|
/* Explicit-tag consistency (both families): the tag asserts a type the
|
|
498
552
|
* content cannot carry. seq/map check the node KIND; the five core
|
|
499
|
-
* scalar tags re-resolve the content through the family resolver.
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (
|
|
553
|
+
* scalar tags re-resolve the content through the family resolver.
|
|
554
|
+
* internal.h's fact core — the event route feeds the same five facts. */
|
|
555
|
+
void yep_check_tag_facts(yep_vctx* c, int kind, int has_tag, uint8_t tag_id, yep_view value,
|
|
556
|
+
uint32_t off, const yep_resolver* fam, int json_family) {
|
|
557
|
+
if (!has_tag) {
|
|
504
558
|
return; /* no explicit tag */
|
|
505
559
|
}
|
|
506
|
-
uint8_t want =
|
|
560
|
+
uint8_t want = tag_id;
|
|
507
561
|
const char* w = tag_word(want);
|
|
508
562
|
if (want == YEPTRIS_TAG_SEQ || want == YEPTRIS_TAG_MAP || want == YEPTRIS_TAG_STR) {
|
|
509
|
-
int ok = want == YEPTRIS_TAG_STR
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
(want == YEPTRIS_TAG_MAP && n->kind == YEP_DOM_MAPPING);
|
|
563
|
+
int ok = want == YEPTRIS_TAG_STR ? kind == YEP_DOM_SCALAR
|
|
564
|
+
: (want == YEPTRIS_TAG_SEQ && kind == YEP_DOM_SEQUENCE) ||
|
|
565
|
+
(want == YEPTRIS_TAG_MAP && kind == YEP_DOM_MAPPING);
|
|
513
566
|
if (!ok) {
|
|
514
|
-
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH,
|
|
515
|
-
|
|
516
|
-
n->kind == YEP_DOM_SCALAR
|
|
567
|
+
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH, off, "explicit %s tag on a %s", w,
|
|
568
|
+
kind == YEP_DOM_SCALAR
|
|
517
569
|
? "scalar"
|
|
518
|
-
: (
|
|
570
|
+
: (kind == YEP_DOM_SEQUENCE ? "sequence" : "mapping"));
|
|
519
571
|
}
|
|
520
572
|
return;
|
|
521
573
|
}
|
|
522
574
|
if (want >= YEPTRIS_TAG_INT && want <= YEPTRIS_TAG_NULL) {
|
|
523
|
-
if (
|
|
524
|
-
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH,
|
|
525
|
-
|
|
526
|
-
n->kind == YEP_DOM_SEQUENCE ? "sequence" : "mapping");
|
|
575
|
+
if (kind != YEP_DOM_SCALAR) {
|
|
576
|
+
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH, off, "explicit %s tag on a %s", w,
|
|
577
|
+
kind == YEP_DOM_SEQUENCE ? "sequence" : "mapping");
|
|
527
578
|
return;
|
|
528
579
|
}
|
|
529
|
-
|
|
530
|
-
uint8_t got = fam->resolve(fam->ctx, v.p != NULL ? v.p : "", v.len);
|
|
580
|
+
uint8_t got = fam->resolve(fam->ctx, value.p != NULL ? value.p : "", value.len);
|
|
531
581
|
if (got != want) {
|
|
532
582
|
if (json_family) {
|
|
533
|
-
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH,
|
|
583
|
+
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH, off,
|
|
534
584
|
"explicit %s tag; content is not a JSON %s", w, w);
|
|
535
585
|
} else {
|
|
536
|
-
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH,
|
|
586
|
+
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH, off,
|
|
537
587
|
"explicit %s tag on %s content", w, tag_word(got));
|
|
538
588
|
}
|
|
539
589
|
}
|
|
540
590
|
return;
|
|
541
591
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
592
|
+
if (want == YEPTRIS_TAG_TIMESTAMP && fam->timestamped) {
|
|
593
|
+
/* the FULL family: timestamp is a family type — the explicit
|
|
594
|
+
* tag asserts content the classifier accepts (the SAME
|
|
595
|
+
* classifier the untagged plain form rides, so the two cannot
|
|
596
|
+
* diverge). Core leaves the tag consumer-defined (spec 10.3's
|
|
597
|
+
* core schema has no timestamp); the JSON family rejects it
|
|
598
|
+
* wholesale (checked by the caller). */
|
|
599
|
+
if (kind != YEP_DOM_SCALAR) {
|
|
600
|
+
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH, off, "explicit timestamp tag on a %s",
|
|
601
|
+
kind == YEP_DOM_SEQUENCE ? "sequence" : "mapping");
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
uint8_t got = fam->resolve(fam->ctx, value.p != NULL ? value.p : "", value.len);
|
|
605
|
+
if (got != want) {
|
|
606
|
+
yep_validate_emit(c, YEPTRIS_DIAG_TAG_MISMATCH, off,
|
|
607
|
+
"explicit timestamp tag on %s content", tag_word(got));
|
|
553
608
|
}
|
|
554
609
|
return;
|
|
555
610
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
611
|
+
/* binary/merge/value/custom: consumer-defined under every family
|
|
612
|
+
* (spec 10.4: arbitrary explicit tags ride). The binary
|
|
613
|
+
* PASSTHROUGH policy: !!binary is never family-checked — PyYAML's
|
|
614
|
+
* base64 decode is a CONSTRUCTION step, so resolution and this
|
|
615
|
+
* walk keep their hands off the shaping. */
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
static void check_tag(yep_vctx* c, uint32_t id, const yep_resolver* fam, int json_family) {
|
|
619
|
+
const yep_dom* d = c->dom;
|
|
620
|
+
const yep_dnode* n = yep_dom_node(d, id);
|
|
621
|
+
if (n->tag.len == 0) {
|
|
560
622
|
return;
|
|
561
623
|
}
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
624
|
+
yep_check_tag_facts(c, (int)n->kind, 1, n->tag_id, yep_dom_view(d, n->value),
|
|
625
|
+
yep_validate_node_off(d, id), fam, json_family);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/* json12: a SCALAR mapping key's checks (internal.h's fact core —
|
|
629
|
+
* the DOM walk and the event route both land here, so the two routes
|
|
630
|
+
* cannot diverge on a verdict). A plain key matching no JSON
|
|
631
|
+
* production IS a string (spec 10.2 example 10.8's "A null"/
|
|
632
|
+
* "Booleans" are plain block keys) — the string-key demand bars only
|
|
633
|
+
* keys resolving to non-string productions. */
|
|
634
|
+
void yep_check_json_key_facts(yep_vctx* c, int has_tag, uint8_t tag_id, int plainish,
|
|
635
|
+
yep_view value, uint32_t off) {
|
|
636
|
+
if (has_tag) {
|
|
637
|
+
uint8_t want = tag_id;
|
|
565
638
|
if (want == YEPTRIS_TAG_STR) {
|
|
566
639
|
return;
|
|
567
640
|
}
|
|
@@ -577,17 +650,11 @@ static void check_json_key(yep_vctx* c, uint32_t key_id) {
|
|
|
577
650
|
}
|
|
578
651
|
return;
|
|
579
652
|
}
|
|
580
|
-
if (!
|
|
653
|
+
if (!plainish) {
|
|
581
654
|
return; /* quoted/block keys are strings */
|
|
582
655
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
if (cls == 0) {
|
|
586
|
-
yep_validate_emit(c, YEPTRIS_DIAG_NON_JSON_TYPE, off,
|
|
587
|
-
"plain scalar matches no JSON production");
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
if (cls != (int)YEPTRIS_TAG_STR) {
|
|
656
|
+
int cls = yep_json12_plain(value.p != NULL ? value.p : "", value.len);
|
|
657
|
+
if (cls != 0 && cls != (int)YEPTRIS_TAG_STR) {
|
|
591
658
|
yep_validate_emit(c, YEPTRIS_DIAG_KEY_NOT_STRING, off,
|
|
592
659
|
"mapping key is %s (expected a "
|
|
593
660
|
"string)",
|
|
@@ -595,32 +662,82 @@ static void check_json_key(yep_vctx* c, uint32_t key_id) {
|
|
|
595
662
|
}
|
|
596
663
|
}
|
|
597
664
|
|
|
598
|
-
/* json12:
|
|
599
|
-
|
|
600
|
-
static void check_json_scalar(yep_vctx* c, uint32_t id) {
|
|
665
|
+
/* json12: a mapping key must be a string scalar. */
|
|
666
|
+
static void check_json_key(yep_vctx* c, uint32_t key_id) {
|
|
601
667
|
const yep_dom* d = c->dom;
|
|
602
|
-
const yep_dnode* n = yep_dom_node(d,
|
|
603
|
-
if (n->
|
|
604
|
-
|
|
668
|
+
const yep_dnode* n = yep_dom_node(d, key_id);
|
|
669
|
+
if (n->kind == YEP_DOM_ALIAS) {
|
|
670
|
+
if (n->target != UINT32_MAX) {
|
|
671
|
+
check_json_key(c, n->target);
|
|
672
|
+
}
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
if (n->kind != YEP_DOM_SCALAR) {
|
|
676
|
+
uint32_t off = yep_validate_node_off(d, key_id);
|
|
677
|
+
yep_validate_emit(c, YEPTRIS_DIAG_KEY_NOT_STRING, off, "mapping key is a %s",
|
|
678
|
+
n->kind == YEP_DOM_SEQUENCE ? "sequence" : "mapping");
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
yep_check_json_key_facts(c, n->tag.len > 0, n->tag_id,
|
|
682
|
+
n->implicit || n->style == YEP_STYLE_PLAIN, yep_dom_view(d, n->value),
|
|
683
|
+
yep_validate_node_off(d, key_id));
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/* json12 scalar facts: only explicit non-JSON tags diagnose — example
|
|
687
|
+
* 10.8 resolves implicit no-production plains as strings (keys AND
|
|
688
|
+
* the "Invalid" list), overriding the table's error note. */
|
|
689
|
+
void yep_check_json_scalar_facts(yep_vctx* c, int has_tag, uint8_t tag_id, int plainish,
|
|
690
|
+
yep_view value, uint32_t off) {
|
|
691
|
+
(void)plainish;
|
|
692
|
+
(void)value;
|
|
693
|
+
if (has_tag) {
|
|
694
|
+
uint8_t want = tag_id;
|
|
605
695
|
if (want == YEPTRIS_TAG_TIMESTAMP || want == YEPTRIS_TAG_BINARY ||
|
|
606
696
|
want == YEPTRIS_TAG_MERGE || want == YEPTRIS_TAG_VALUE || want == YEPTRIS_TAG_CUSTOM) {
|
|
607
|
-
yep_validate_emit(c, YEPTRIS_DIAG_NON_JSON_TYPE,
|
|
697
|
+
yep_validate_emit(c, YEPTRIS_DIAG_NON_JSON_TYPE, off,
|
|
608
698
|
"explicit %s tag is not a JSON type", tag_word(want));
|
|
609
699
|
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
static void check_json_scalar(yep_vctx* c, uint32_t id) {
|
|
704
|
+
const yep_dom* d = c->dom;
|
|
705
|
+
const yep_dnode* n = yep_dom_node(d, id);
|
|
706
|
+
yep_check_json_scalar_facts(c, n->tag.len > 0, n->tag_id,
|
|
707
|
+
n->implicit || n->style == YEP_STYLE_PLAIN,
|
|
708
|
+
yep_dom_view(d, n->value), yep_validate_node_off(d, id));
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
static void walk_family(yep_vctx* c, uint32_t id, const yep_resolver* fam, int json_family);
|
|
712
|
+
|
|
713
|
+
/* The tag-driven schema hook (#906 slice 4): a node whose EXPLICIT tag
|
|
714
|
+
* matches a registry entry has its subtree validated against the bound
|
|
715
|
+
* compiled schema. The walk context carries the tag site's path — the
|
|
716
|
+
* subtree's misses extend it — and the shared report (one cap law).
|
|
717
|
+
* Unregistered tags pass untouched; tagged mapping KEYS never reach
|
|
718
|
+
* here (the walk checks keys in place, no instance path of their
|
|
719
|
+
* own). Registration is the only extension: this reads the registry,
|
|
720
|
+
* it never grows a schema branch (OCP). */
|
|
721
|
+
static void check_tag_schema(yep_vctx* c, uint32_t id, const yep_dnode* n) {
|
|
722
|
+
if (c->oom || c->reg == NULL || n->tag.len == 0) {
|
|
610
723
|
return;
|
|
611
724
|
}
|
|
612
|
-
|
|
613
|
-
|
|
725
|
+
yep_view tv = yep_dom_view(c->dom, n->tag);
|
|
726
|
+
if (tv.p == NULL) {
|
|
727
|
+
return;
|
|
614
728
|
}
|
|
615
|
-
|
|
616
|
-
if (
|
|
617
|
-
|
|
618
|
-
|
|
729
|
+
const yeptris_schema* bound = yeptris_schema_registry_lookup(c->reg, tv.p, tv.len);
|
|
730
|
+
if (bound == NULL) {
|
|
731
|
+
return; /* an unregistered tag is nobody's schema */
|
|
732
|
+
}
|
|
733
|
+
yep_schema_view v;
|
|
734
|
+
yep_schema_view_of(bound, &v);
|
|
735
|
+
if (v.dom == NULL) {
|
|
736
|
+
return;
|
|
619
737
|
}
|
|
738
|
+
yep_jsonschema_apply_subtree(v.dom, v.sroot, c, id, v.cache, v.res);
|
|
620
739
|
}
|
|
621
740
|
|
|
622
|
-
static void walk_family(yep_vctx* c, uint32_t id, const yep_resolver* fam, int json_family);
|
|
623
|
-
|
|
624
741
|
static void walk_children(yep_vctx* c, uint32_t first, const yep_resolver* fam, int json_family) {
|
|
625
742
|
uint32_t ch = first;
|
|
626
743
|
int guard = 0;
|
|
@@ -658,11 +775,13 @@ static void walk_family(yep_vctx* c, uint32_t id, const yep_resolver* fam, int j
|
|
|
658
775
|
if (json_family) {
|
|
659
776
|
check_json_scalar(c, id);
|
|
660
777
|
}
|
|
778
|
+
check_tag_schema(c, id, n);
|
|
661
779
|
break;
|
|
662
780
|
case YEP_DOM_ALIAS:
|
|
663
781
|
break; /* the target is validated at its own place */
|
|
664
782
|
case YEP_DOM_SEQUENCE: {
|
|
665
783
|
check_tag(c, id, fam, json_family);
|
|
784
|
+
check_tag_schema(c, id, n);
|
|
666
785
|
size_t mark = c->path_len;
|
|
667
786
|
uint32_t idx = 0;
|
|
668
787
|
uint32_t ch = n->first_child;
|
|
@@ -681,6 +800,7 @@ static void walk_family(yep_vctx* c, uint32_t id, const yep_resolver* fam, int j
|
|
|
681
800
|
check_tag(c, id, fam, json_family);
|
|
682
801
|
size_t mark = c->path_len;
|
|
683
802
|
check_duplicates(c, id);
|
|
803
|
+
check_tag_schema(c, id, n);
|
|
684
804
|
uint32_t k = n->first_child;
|
|
685
805
|
while (k != UINT32_MAX && !c->oom) {
|
|
686
806
|
uint32_t v =
|
|
@@ -739,21 +859,32 @@ YEPTRIS_API void yeptris_validate_report_free(yeptris_validate_report* report) {
|
|
|
739
859
|
yep_free(sys, report);
|
|
740
860
|
}
|
|
741
861
|
|
|
742
|
-
/* The
|
|
743
|
-
|
|
744
|
-
yeptris_validate_report** out) {
|
|
862
|
+
/* The report constructor (internal.h's seam — one home for the shape). */
|
|
863
|
+
yeptris_validate_report* yep_validate_report_new(void) {
|
|
745
864
|
const yep_allocator* sys = yep_system_allocator();
|
|
746
865
|
yeptris_validate_report* r = yep_alloc(sys, sizeof(*r));
|
|
747
866
|
if (r == NULL) {
|
|
748
|
-
return
|
|
867
|
+
return NULL;
|
|
749
868
|
}
|
|
750
869
|
r->diags = yep_alloc(sys, YEP_VALIDATE_MAX_DIAGS * sizeof(yeptris_diagnostic));
|
|
751
870
|
if (r->diags == NULL) {
|
|
752
871
|
yep_free(sys, r);
|
|
753
|
-
return
|
|
872
|
+
return NULL;
|
|
754
873
|
}
|
|
755
874
|
r->count = 0;
|
|
756
875
|
r->truncated = 0;
|
|
876
|
+
return r;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/* The shared tail: walk every document of the DOM into a fresh report. */
|
|
880
|
+
static YeptrisStatus validate_dom(yep_dom* dom, const yep_resolver* fam, int json_family,
|
|
881
|
+
const yeptris_schema_registry* reg,
|
|
882
|
+
yeptris_validate_report** out) {
|
|
883
|
+
const yep_allocator* sys = yep_system_allocator();
|
|
884
|
+
yeptris_validate_report* r = yep_validate_report_new();
|
|
885
|
+
if (r == NULL) {
|
|
886
|
+
return YEPTRIS_ERROR_MEMORY;
|
|
887
|
+
}
|
|
757
888
|
|
|
758
889
|
yep_vctx c;
|
|
759
890
|
memset(&c, 0, sizeof(c));
|
|
@@ -761,10 +892,15 @@ static YeptrisStatus validate_dom(yep_dom* dom, const yep_resolver* fam, int jso
|
|
|
761
892
|
c.rep = r;
|
|
762
893
|
c.input = dom->input_base;
|
|
763
894
|
c.input_len = dom->input_len;
|
|
895
|
+
c.reg = reg;
|
|
764
896
|
|
|
765
897
|
for (uint32_t i = 0; i < dom->dcount && !c.oom; i++) {
|
|
766
|
-
c.path_len = 0; /*
|
|
898
|
+
c.path_len = 0; /* root-relative per document; a multi-document
|
|
899
|
+
* stream addresses its documents as array
|
|
900
|
+
* elements: "/i" + the instance pointer */
|
|
901
|
+
size_t mark = yep_validate_doc_prefix(&c, dom->dcount > 1, i);
|
|
767
902
|
walk_family(&c, dom->docs[i], fam, json_family);
|
|
903
|
+
yep_validate_path_pop(&c, mark);
|
|
768
904
|
}
|
|
769
905
|
|
|
770
906
|
yep_free(sys, c.line_off);
|
|
@@ -782,7 +918,9 @@ static YeptrisStatus validate_dom(yep_dom* dom, const yep_resolver* fam, int jso
|
|
|
782
918
|
return st;
|
|
783
919
|
}
|
|
784
920
|
|
|
785
|
-
|
|
921
|
+
/* The family selector (internal.h's seam): 11_COMPAT is the
|
|
922
|
+
* parse-compat resolver, not a validation family. */
|
|
923
|
+
int yep_validate_schema_family(YeptrisSchema schema, const yep_resolver** fam, int* json_family) {
|
|
786
924
|
switch (schema) {
|
|
787
925
|
case YEPTRIS_SCHEMA_12_CORE:
|
|
788
926
|
*fam = yep_resolver_core12();
|
|
@@ -792,20 +930,35 @@ static int schema_is_family(YeptrisSchema schema, const yep_resolver** fam, int*
|
|
|
792
930
|
*fam = yep_resolver_json12();
|
|
793
931
|
*json_family = 1;
|
|
794
932
|
return 1;
|
|
933
|
+
case YEPTRIS_SCHEMA_12_FULL:
|
|
934
|
+
*fam = yep_resolver_full12();
|
|
935
|
+
*json_family = 0; /* full rides the core checks + timestamp */
|
|
936
|
+
return 1;
|
|
795
937
|
default:
|
|
796
938
|
return 0;
|
|
797
939
|
}
|
|
798
940
|
}
|
|
799
941
|
|
|
800
|
-
|
|
801
|
-
|
|
942
|
+
/* The options' registry field (size-versioned: an older/short struct
|
|
943
|
+
* simply carries no registry — the emit-options law). */
|
|
944
|
+
static const yeptris_schema_registry* validate_registry(const yeptris_validate_options* opts) {
|
|
945
|
+
if (opts == NULL || opts->size < (uint32_t)(offsetof(yeptris_validate_options, registry) +
|
|
946
|
+
sizeof(opts->registry))) {
|
|
947
|
+
return NULL;
|
|
948
|
+
}
|
|
949
|
+
return opts->registry;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
YEPTRIS_API YeptrisStatus yeptris_validate_document_ex(YeptrisDocument doc, YeptrisSchema schema,
|
|
953
|
+
const yeptris_validate_options* opts,
|
|
954
|
+
yeptris_validate_report** out) {
|
|
802
955
|
if (out == NULL) {
|
|
803
956
|
return YEPTRIS_ERROR_ARG;
|
|
804
957
|
}
|
|
805
958
|
*out = NULL;
|
|
806
959
|
const yep_resolver* fam;
|
|
807
960
|
int json_family;
|
|
808
|
-
if (!
|
|
961
|
+
if (!yep_validate_schema_family(schema, &fam, &json_family)) {
|
|
809
962
|
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
|
|
810
963
|
"schema %d is not a validation family", (int)schema);
|
|
811
964
|
return YEPTRIS_ERROR_ARG;
|
|
@@ -816,54 +969,57 @@ YEPTRIS_API YeptrisStatus yeptris_validate_document(YeptrisDocument doc, Yeptris
|
|
|
816
969
|
}
|
|
817
970
|
if (dom == NULL) {
|
|
818
971
|
/* an empty stream (or NULL doc): valid, empty report */
|
|
819
|
-
|
|
820
|
-
yeptris_validate_report* r = yep_alloc(sys, sizeof(*r));
|
|
972
|
+
yeptris_validate_report* r = yep_validate_report_new();
|
|
821
973
|
if (r == NULL) {
|
|
822
974
|
return YEPTRIS_ERROR_MEMORY;
|
|
823
975
|
}
|
|
824
|
-
r->diags = yep_alloc(sys, YEP_VALIDATE_MAX_DIAGS * sizeof(yeptris_diagnostic));
|
|
825
|
-
if (r->diags == NULL) {
|
|
826
|
-
yep_free(sys, r);
|
|
827
|
-
return YEPTRIS_ERROR_MEMORY;
|
|
828
|
-
}
|
|
829
|
-
r->count = 0;
|
|
830
|
-
r->truncated = 0;
|
|
831
976
|
*out = r;
|
|
832
977
|
return YEPTRIS_OK;
|
|
833
978
|
}
|
|
834
|
-
return validate_dom(dom, fam, json_family, out);
|
|
979
|
+
return validate_dom(dom, fam, json_family, validate_registry(opts), out);
|
|
835
980
|
}
|
|
836
981
|
|
|
837
|
-
YEPTRIS_API YeptrisStatus
|
|
838
|
-
|
|
982
|
+
YEPTRIS_API YeptrisStatus yeptris_validate_document(YeptrisDocument doc, YeptrisSchema schema,
|
|
983
|
+
yeptris_validate_report** out) {
|
|
984
|
+
return yeptris_validate_document_ex(doc, schema, NULL, out);
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
YEPTRIS_API YeptrisStatus yeptris_validate_ex(const char* buf, size_t len, YeptrisSchema schema,
|
|
988
|
+
const yeptris_validate_options* opts,
|
|
989
|
+
yeptris_validate_report** out) {
|
|
839
990
|
if (out == NULL || (buf == NULL && len != 0)) {
|
|
840
991
|
return YEPTRIS_ERROR_ARG;
|
|
841
992
|
}
|
|
842
993
|
*out = NULL;
|
|
843
994
|
const yep_resolver* fam;
|
|
844
995
|
int json_family;
|
|
845
|
-
if (!
|
|
996
|
+
if (!yep_validate_schema_family(schema, &fam, &json_family)) {
|
|
846
997
|
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
|
|
847
998
|
"schema %d is not a validation family", (int)schema);
|
|
848
999
|
return YEPTRIS_ERROR_ARG;
|
|
849
1000
|
}
|
|
850
|
-
YeptrisParseOptions
|
|
851
|
-
memset(&
|
|
852
|
-
|
|
1001
|
+
YeptrisParseOptions popts;
|
|
1002
|
+
memset(&popts, 0, sizeof(popts));
|
|
1003
|
+
popts.schema = schema; /* the parse resolves implicit types per family */
|
|
853
1004
|
YeptrisStatus st = YEPTRIS_OK;
|
|
854
|
-
YeptrisDocument doc = yeptris_parse_eager_ex(buf, len, &
|
|
1005
|
+
YeptrisDocument doc = yeptris_parse_eager_ex(buf, len, &popts, &st);
|
|
855
1006
|
if (doc == NULL) {
|
|
856
1007
|
if (st == YEPTRIS_OK) {
|
|
857
1008
|
/* an empty stream: valid, empty report */
|
|
858
|
-
return
|
|
1009
|
+
return yeptris_validate_document_ex(NULL, schema, opts, out);
|
|
859
1010
|
}
|
|
860
1011
|
return st; /* the parse's own error */
|
|
861
1012
|
}
|
|
862
|
-
st =
|
|
1013
|
+
st = yeptris_validate_document_ex(doc, schema, opts, out);
|
|
863
1014
|
yeptris_document_free(doc);
|
|
864
1015
|
return st;
|
|
865
1016
|
}
|
|
866
1017
|
|
|
1018
|
+
YEPTRIS_API YeptrisStatus yeptris_validate(const char* buf, size_t len, YeptrisSchema schema,
|
|
1019
|
+
yeptris_validate_report** out) {
|
|
1020
|
+
return yeptris_validate_ex(buf, len, schema, NULL, out);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
867
1023
|
YEPTRIS_API YeptrisStatus yeptris_json_schema_validate(const char* schema, size_t schema_len,
|
|
868
1024
|
const char* buf, size_t len,
|
|
869
1025
|
yeptris_validate_report** out) {
|
|
@@ -871,69 +1027,17 @@ YEPTRIS_API YeptrisStatus yeptris_json_schema_validate(const char* schema, size_
|
|
|
871
1027
|
return YEPTRIS_ERROR_ARG;
|
|
872
1028
|
}
|
|
873
1029
|
*out = NULL;
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
1030
|
+
/* the compiled-schema economy, one call deep (#885 item 3): the
|
|
1031
|
+
* schema parses ONCE here exactly as it always did, rides the SAME
|
|
1032
|
+
* walk and report paths as the retained handle, and dies at return
|
|
1033
|
+
* — the observable statuses and byte-for-byte verdicts are the
|
|
1034
|
+
* suite port's 1298 cases, unchanged */
|
|
879
1035
|
YeptrisStatus st = YEPTRIS_OK;
|
|
880
|
-
|
|
881
|
-
if (
|
|
882
|
-
|
|
883
|
-
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
|
|
884
|
-
"the schema bytes hold no document");
|
|
885
|
-
return YEPTRIS_ERROR_ARG;
|
|
886
|
-
}
|
|
887
|
-
return st; /* the schema did not parse */
|
|
888
|
-
}
|
|
889
|
-
yep_dom* sdom = yep_doc_dom((yeptris_document*)sdoc);
|
|
890
|
-
if (sdom == NULL || sdom->dcount == 0) {
|
|
891
|
-
yep_error_set(yep_error_tls(), YEP_ERR_UNEXPECTED, 0, 0, 0,
|
|
892
|
-
"the schema bytes hold no document");
|
|
893
|
-
yeptris_document_free(sdoc);
|
|
894
|
-
return YEPTRIS_ERROR_ARG;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
/* the instance stream */
|
|
898
|
-
YeptrisDocument idoc = yeptris_parse_eager_ex(buf, len, &opts, &st);
|
|
899
|
-
if (idoc == NULL) {
|
|
900
|
-
yeptris_document_free(sdoc);
|
|
901
|
-
if (st == YEPTRIS_OK) {
|
|
902
|
-
/* an empty instance stream: nothing to invalidate */
|
|
903
|
-
return yeptris_validate_document(NULL, YEPTRIS_SCHEMA_12_CORE, out);
|
|
904
|
-
}
|
|
905
|
-
return st;
|
|
906
|
-
}
|
|
907
|
-
yep_dom* idom = yep_doc_dom((yeptris_document*)idoc);
|
|
908
|
-
if (idom == NULL) {
|
|
909
|
-
yeptris_document_free(idoc);
|
|
910
|
-
yeptris_document_free(sdoc);
|
|
911
|
-
return YEPTRIS_ERROR_MEMORY;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
yeptris_validate_report* r = yep_alloc(sys, sizeof(*r));
|
|
915
|
-
if (r == NULL) {
|
|
916
|
-
yeptris_document_free(idoc);
|
|
917
|
-
yeptris_document_free(sdoc);
|
|
918
|
-
return YEPTRIS_ERROR_MEMORY;
|
|
1036
|
+
yeptris_schema* s = yep_schema_compile_st(schema, schema_len, &st);
|
|
1037
|
+
if (s == NULL) {
|
|
1038
|
+
return st; /* the schema's parse/arg failure, verbatim */
|
|
919
1039
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
yeptris_document_free(idoc);
|
|
924
|
-
yeptris_document_free(sdoc);
|
|
925
|
-
return YEPTRIS_ERROR_MEMORY;
|
|
926
|
-
}
|
|
927
|
-
r->count = 0;
|
|
928
|
-
r->truncated = 0;
|
|
929
|
-
|
|
930
|
-
int rc = yep_jsonschema_run(sdom, sdom->docs[0], idom, idom->docs, idom->dcount, r);
|
|
931
|
-
yeptris_document_free(idoc);
|
|
932
|
-
yeptris_document_free(sdoc);
|
|
933
|
-
if (rc != 0) {
|
|
934
|
-
yeptris_validate_report_free(r);
|
|
935
|
-
return YEPTRIS_ERROR_MEMORY;
|
|
936
|
-
}
|
|
937
|
-
*out = r;
|
|
938
|
-
return r->count > 0 ? YEPTRIS_ERROR_SCHEMA : YEPTRIS_OK;
|
|
1040
|
+
st = yeptris_schema_validate(s, buf, len, out);
|
|
1041
|
+
yeptris_schema_free(s);
|
|
1042
|
+
return st;
|
|
939
1043
|
}
|