yeptris 0.6.59.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/ffi.rb +19 -0
- data/lib/yeptris/yaml.rb +61 -0
- data/lib/yeptris.rb +1 -1
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +1 -1
- data/vendor/libyeptris/src/CMakeLists.txt +7 -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 +222 -21
- 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 +173 -43
- 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 +39 -3
- data/vendor/libyeptris/src/yeptris/validate/internal.h +223 -7
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +645 -115
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +623 -157
- 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 +288 -145
- metadata +8 -1
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/* output.c — the structured output face (#906 slice 5).
|
|
2
|
+
*
|
|
3
|
+
* The report -> the json-schema.org RECOMMENDED OUTPUT shape (core
|
|
4
|
+
* spec section 12; meta-schema
|
|
5
|
+
* https://json-schema.org/draft/2020-12/output/schema, fetched into
|
|
6
|
+
* test/conformance/jsonschema/output/schema.json). The published
|
|
7
|
+
* BASIC form is the truthful one for this report: one root output
|
|
8
|
+
* unit carrying "valid", "keywordLocation", "instanceLocation" and —
|
|
9
|
+
* when the report has diagnostics — "errors", each an output unit of
|
|
10
|
+
* its own. The DETAILED/VERBOSE forms are schema-structured
|
|
11
|
+
* hierarchies; the flat report (the enumerated-misses law) carries no
|
|
12
|
+
* schema-side path to build them from, so they are deliberately not
|
|
13
|
+
* faked.
|
|
14
|
+
*
|
|
15
|
+
* keywordLocation is derived from the diagnostic code: the keyword's
|
|
16
|
+
* name segment ("/type", "/required", ...). It is a JSON Pointer but
|
|
17
|
+
* NOT necessarily resolvable in the schema (no schema path in the
|
|
18
|
+
* report); family/bookkeeping codes sit at the root pointer "". $ref
|
|
19
|
+
* reports the root pointer too, so absoluteKeywordLocation — which
|
|
20
|
+
* the meta-schema demands only for /$ref/ locations — is never
|
|
21
|
+
* emitted and the output always satisfies the published meta-schema.
|
|
22
|
+
*
|
|
23
|
+
* Pure and deterministic: report in, bytes out — one measure pass
|
|
24
|
+
* (buf == NULL at the caller's choice) and one write pass compose the
|
|
25
|
+
* same bytes, no allocation on either path, no state. MECE: the
|
|
26
|
+
* diagnostic machinery stays validate.c's; this TU only serializes
|
|
27
|
+
* finished diagnostics.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#include <stdint.h>
|
|
31
|
+
#include <string.h>
|
|
32
|
+
|
|
33
|
+
#include <yeptris/validate.h>
|
|
34
|
+
|
|
35
|
+
#include "internal.h"
|
|
36
|
+
|
|
37
|
+
/* The keyword-name table (internal.h's output SSOT): index = the
|
|
38
|
+
* YeptrisDiagCode value, appending with the enum. "" = no JSON Schema
|
|
39
|
+
* keyword (the family/bookkeeping codes, and $ref sites — see the
|
|
40
|
+
* file comment). */
|
|
41
|
+
static const char* const keyword_names[] = {
|
|
42
|
+
"", /* NONE */
|
|
43
|
+
"", /* TAG_MISMATCH (family walk) */
|
|
44
|
+
"", /* KEY_NOT_STRING (family walk) */
|
|
45
|
+
"", /* NON_JSON_TYPE (family walk) */
|
|
46
|
+
"", /* DUPLICATE_KEY (family walk) */
|
|
47
|
+
"/type", /* TYPE */
|
|
48
|
+
"/required", /* REQUIRED */
|
|
49
|
+
"/enum", /* ENUM */
|
|
50
|
+
"/const", /* CONST */
|
|
51
|
+
"/pattern", /* PATTERN */
|
|
52
|
+
"/minimum", /* MINIMUM */
|
|
53
|
+
"/maximum", /* MAXIMUM */
|
|
54
|
+
"/exclusiveMinimum", /* EXCLUSIVE_MINIMUM */
|
|
55
|
+
"/exclusiveMaximum", /* EXCLUSIVE_MAXIMUM */
|
|
56
|
+
"/minLength", /* MIN_LENGTH */
|
|
57
|
+
"/maxLength", /* MAX_LENGTH */
|
|
58
|
+
"/minItems", /* MIN_ITEMS */
|
|
59
|
+
"/maxItems", /* MAX_ITEMS */
|
|
60
|
+
"/uniqueItems", /* UNIQUE_ITEMS */
|
|
61
|
+
"/additionalProperties", /* ADDITIONAL_PROPERTY */
|
|
62
|
+
"/anyOf", /* ANY_OF */
|
|
63
|
+
"/oneOf", /* ONE_OF */
|
|
64
|
+
"/not", /* NOT */
|
|
65
|
+
"", /* REF */
|
|
66
|
+
"", /* FALSE_SCHEMA */
|
|
67
|
+
"", /* DEPTH */
|
|
68
|
+
"", /* LIMIT */
|
|
69
|
+
"/multipleOf", /* MULTIPLE_OF */
|
|
70
|
+
"/minProperties", /* MIN_PROPERTIES */
|
|
71
|
+
"/maxProperties", /* MAX_PROPERTIES */
|
|
72
|
+
"/contains", /* CONTAINS */
|
|
73
|
+
"/minContains", /* MIN_CONTAINS */
|
|
74
|
+
"/maxContains", /* MAX_CONTAINS */
|
|
75
|
+
"/dependentRequired", /* DEPENDENT_REQUIRED */
|
|
76
|
+
"/unevaluatedProperties", /* UNEVALUATED_PROPERTY */
|
|
77
|
+
"/unevaluatedItems", /* UNEVALUATED_ITEM */
|
|
78
|
+
};
|
|
79
|
+
/* Appending a diag code without its keyword row is a build break (the
|
|
80
|
+
* output SSOT stays in step with the enum). */
|
|
81
|
+
YEPTRIS_CT_ASSERT(sizeof(keyword_names) / sizeof(keyword_names[0]) ==
|
|
82
|
+
(size_t)YEPTRIS_DIAG_UNEVALUATED_ITEM + 1);
|
|
83
|
+
|
|
84
|
+
const char* yep_validate_output_keyword(uint32_t code) {
|
|
85
|
+
if (code >= sizeof(keyword_names) / sizeof(keyword_names[0])) {
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
return keyword_names[code];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/* Bounded NUL-terminated length (the report's fields are fixed slots). */
|
|
92
|
+
static size_t slot_len(const char* s, size_t cap) {
|
|
93
|
+
size_t n = 0;
|
|
94
|
+
while (n < cap && s[n] != '\0') {
|
|
95
|
+
n++;
|
|
96
|
+
}
|
|
97
|
+
return n;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* RFC 8259 string escaping: quote, backslash and the C0 controls; the
|
|
101
|
+
* five named escapes where JSON has them, \u00XX otherwise. Bytes
|
|
102
|
+
* above 0x1F pass through — the report's text is UTF-8 (the parse
|
|
103
|
+
* validated it). */
|
|
104
|
+
static size_t escaped_len(const char* s, size_t n) {
|
|
105
|
+
size_t t = 0;
|
|
106
|
+
for (size_t i = 0; i < n; i++) {
|
|
107
|
+
unsigned char b = (unsigned char)s[i];
|
|
108
|
+
switch (b) {
|
|
109
|
+
case '"':
|
|
110
|
+
case '\\':
|
|
111
|
+
case '\b':
|
|
112
|
+
case '\f':
|
|
113
|
+
case '\n':
|
|
114
|
+
case '\r':
|
|
115
|
+
case '\t':
|
|
116
|
+
t += 2;
|
|
117
|
+
break;
|
|
118
|
+
default:
|
|
119
|
+
t += b < 0x20 ? 6 : 1;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return t;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
static void put_lit(char** p, const char* s, size_t n) {
|
|
127
|
+
memcpy(*p, s, n);
|
|
128
|
+
*p += n;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static void put_escaped(char** p, const char* s, size_t n) {
|
|
132
|
+
static const char hex[] = "0123456789abcdef";
|
|
133
|
+
char* o = *p;
|
|
134
|
+
for (size_t i = 0; i < n; i++) {
|
|
135
|
+
unsigned char b = (unsigned char)s[i];
|
|
136
|
+
switch (b) {
|
|
137
|
+
case '"':
|
|
138
|
+
*o++ = '\\';
|
|
139
|
+
*o++ = '"';
|
|
140
|
+
break;
|
|
141
|
+
case '\\':
|
|
142
|
+
*o++ = '\\';
|
|
143
|
+
*o++ = '\\';
|
|
144
|
+
break;
|
|
145
|
+
case '\b':
|
|
146
|
+
*o++ = '\\';
|
|
147
|
+
*o++ = 'b';
|
|
148
|
+
break;
|
|
149
|
+
case '\f':
|
|
150
|
+
*o++ = '\\';
|
|
151
|
+
*o++ = 'f';
|
|
152
|
+
break;
|
|
153
|
+
case '\n':
|
|
154
|
+
*o++ = '\\';
|
|
155
|
+
*o++ = 'n';
|
|
156
|
+
break;
|
|
157
|
+
case '\r':
|
|
158
|
+
*o++ = '\\';
|
|
159
|
+
*o++ = 'r';
|
|
160
|
+
break;
|
|
161
|
+
case '\t':
|
|
162
|
+
*o++ = '\\';
|
|
163
|
+
*o++ = 't';
|
|
164
|
+
break;
|
|
165
|
+
default:
|
|
166
|
+
if (b < 0x20) {
|
|
167
|
+
*o++ = '\\';
|
|
168
|
+
*o++ = 'u';
|
|
169
|
+
*o++ = '0';
|
|
170
|
+
*o++ = '0';
|
|
171
|
+
*o++ = hex[b >> 4];
|
|
172
|
+
*o++ = hex[b & 0xF];
|
|
173
|
+
} else {
|
|
174
|
+
*o++ = (char)b;
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
*p = o;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
#define OUT_ROOT_OPEN \
|
|
183
|
+
"{\"valid\":false,\"keywordLocation\":\"\",\"instanceLocation\":\"\",\"errors\":["
|
|
184
|
+
#define OUT_ROOT_VALID "{\"valid\":true,\"keywordLocation\":\"\",\"instanceLocation\":\"\"}"
|
|
185
|
+
#define OUT_UNIT_OPEN "{\"valid\":false,\"keywordLocation\":\""
|
|
186
|
+
#define OUT_INSTANCE "\",\"instanceLocation\":\""
|
|
187
|
+
#define OUT_ERROR "\",\"error\":\""
|
|
188
|
+
#define OUT_UNIT_CLOSE "\"}"
|
|
189
|
+
#define OUT_ROOT_CLOSE "]}"
|
|
190
|
+
|
|
191
|
+
/* One unit's exact byte cost: open + keyword + path + error + detail +
|
|
192
|
+
* close. */
|
|
193
|
+
static size_t unit_len(const yeptris_diagnostic* d) {
|
|
194
|
+
const char* kw = yep_validate_output_keyword(d->code);
|
|
195
|
+
size_t plen = slot_len(d->path, sizeof(d->path));
|
|
196
|
+
size_t dlen = slot_len(d->detail, sizeof(d->detail));
|
|
197
|
+
return (sizeof(OUT_UNIT_OPEN) - 1) + strlen(kw) + (sizeof(OUT_INSTANCE) - 1) +
|
|
198
|
+
escaped_len(d->path, plen) + (sizeof(OUT_ERROR) - 1) + escaped_len(d->detail, dlen) +
|
|
199
|
+
(sizeof(OUT_UNIT_CLOSE) - 1);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
YEPTRIS_API size_t yeptris_validate_report_write(const yeptris_validate_report* report, char* buf,
|
|
203
|
+
size_t cap) {
|
|
204
|
+
if (report == NULL) {
|
|
205
|
+
return 0;
|
|
206
|
+
}
|
|
207
|
+
size_t need;
|
|
208
|
+
if (report->count == 0) {
|
|
209
|
+
need = sizeof(OUT_ROOT_VALID) - 1;
|
|
210
|
+
} else {
|
|
211
|
+
need = (sizeof(OUT_ROOT_OPEN) - 1) + (sizeof(OUT_ROOT_CLOSE) - 1);
|
|
212
|
+
for (uint32_t i = 0; i < report->count; i++) {
|
|
213
|
+
need += unit_len(&report->diags[i]);
|
|
214
|
+
if (i > 0) {
|
|
215
|
+
need += 1; /* the comma between units */
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (buf == NULL || cap < need + 1) {
|
|
220
|
+
return need; /* the measure-only form: nothing is written */
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
char* p = buf;
|
|
224
|
+
if (report->count == 0) {
|
|
225
|
+
put_lit(&p, OUT_ROOT_VALID, sizeof(OUT_ROOT_VALID) - 1);
|
|
226
|
+
} else {
|
|
227
|
+
put_lit(&p, OUT_ROOT_OPEN, sizeof(OUT_ROOT_OPEN) - 1);
|
|
228
|
+
for (uint32_t i = 0; i < report->count; i++) {
|
|
229
|
+
const yeptris_diagnostic* d = &report->diags[i];
|
|
230
|
+
const char* kw = yep_validate_output_keyword(d->code);
|
|
231
|
+
if (i > 0) {
|
|
232
|
+
*p++ = ',';
|
|
233
|
+
}
|
|
234
|
+
put_lit(&p, OUT_UNIT_OPEN, sizeof(OUT_UNIT_OPEN) - 1);
|
|
235
|
+
put_lit(&p, kw, strlen(kw));
|
|
236
|
+
put_lit(&p, OUT_INSTANCE, sizeof(OUT_INSTANCE) - 1);
|
|
237
|
+
put_escaped(&p, d->path, slot_len(d->path, sizeof(d->path)));
|
|
238
|
+
put_lit(&p, OUT_ERROR, sizeof(OUT_ERROR) - 1);
|
|
239
|
+
put_escaped(&p, d->detail, slot_len(d->detail, sizeof(d->detail)));
|
|
240
|
+
put_lit(&p, OUT_UNIT_CLOSE, sizeof(OUT_UNIT_CLOSE) - 1);
|
|
241
|
+
}
|
|
242
|
+
put_lit(&p, OUT_ROOT_CLOSE, sizeof(OUT_ROOT_CLOSE) - 1);
|
|
243
|
+
}
|
|
244
|
+
*p = '\0';
|
|
245
|
+
return need;
|
|
246
|
+
}
|