leptris 1.9.323.0-arm-linux → 1.9.331.0-arm-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -0
- data/Rakefile +1 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/ffi.rb +5 -0
- data/lib/leptris/xml/xsd.rb +18 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +166 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/cli/commands/validate.c +5 -7
- data/vendor-src/libleptris/src/include/leptris.h +8 -0
- data/vendor-src/libleptris/src/leptris/dom/node_public.c +1 -1
- data/vendor-src/libleptris/src/leptris/dom/text.c +4 -2
- data/vendor-src/libleptris/src/leptris/dom/text.h +7 -2
- data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +32 -4
- data/vendor-src/libleptris/src/leptris/html/html_parse.c +2 -1
- data/vendor-src/libleptris/src/leptris/leptris.c +7 -2
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +957 -78
- data/vendor-src/libleptris/src/leptris/xsd/content_model.c +20 -2
- data/vendor-src/libleptris/src/leptris/xsd/validate.c +270 -19
- data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +82 -3
- data/vendor-src/libleptris/src/leptris/xslt/xslt_exec.c +1 -1
- data/vendor-src/libleptris/test/CMakeLists.txt +5 -0
- data/vendor-src/libleptris/test/parser/test_parser.cpp +116 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +518 -4
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +2 -2
|
@@ -27,6 +27,8 @@ typedef struct {
|
|
|
27
27
|
size_t count, cap;
|
|
28
28
|
int state_count; /* explicit: state ids are NOT transition ids */
|
|
29
29
|
int start, accept;
|
|
30
|
+
struct leptris_xsd_schema* s; /* group-ref resolution */
|
|
31
|
+
int depth; /* cyclic-group guard */
|
|
30
32
|
} CmNfa;
|
|
31
33
|
|
|
32
34
|
static int nfa_state(CmNfa* n) { return n->state_count++; }
|
|
@@ -80,6 +82,19 @@ static void cm_build(CmNfa* n, XsdCm* node, int from, int to) {
|
|
|
80
82
|
case XSD_CM_ALL:
|
|
81
83
|
cm_build_children(n, node, from, to);
|
|
82
84
|
return;
|
|
85
|
+
case XSD_CM_GROUP_REF: {
|
|
86
|
+
XsdGroupDef* g =
|
|
87
|
+
n->s ? xsd_find_group(n->s, node->name) : NULL;
|
|
88
|
+
if (!g || !g->model || n->depth > 64) {
|
|
89
|
+
/* unresolved (or cyclic) ref: splice nothing */
|
|
90
|
+
nfa_trans(n, from, -1, NULL, to);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
n->depth++;
|
|
94
|
+
cm_build(n, g->model, from, to);
|
|
95
|
+
n->depth--;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
83
98
|
case XSD_CM_CHOICE: {
|
|
84
99
|
XsdCm* c = node->first_child;
|
|
85
100
|
if (!c) {
|
|
@@ -181,10 +196,10 @@ static void ss_close(StateSet* ss, CmNfa* n) {
|
|
|
181
196
|
int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
182
197
|
const char* target_ns, const char* const* names,
|
|
183
198
|
const char* const* ns_uris, size_t count) {
|
|
184
|
-
(void)s;
|
|
185
199
|
if (!model) return -1;
|
|
186
200
|
CmNfa n;
|
|
187
201
|
memset(&n, 0, sizeof(n));
|
|
202
|
+
n.s = s;
|
|
188
203
|
n.start = nfa_state(&n);
|
|
189
204
|
n.accept = nfa_state(&n);
|
|
190
205
|
cm_build_occurrence(&n, model, n.start, n.accept);
|
|
@@ -205,7 +220,10 @@ int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
|
205
220
|
continue;
|
|
206
221
|
XsdCm* p = tr->particle;
|
|
207
222
|
if (p->kind == XSD_CM_ELEMENT) {
|
|
208
|
-
|
|
223
|
+
int named = (strcmp(p->name, names[c]) == 0) ||
|
|
224
|
+
(n.s && xsd_is_substitute(
|
|
225
|
+
n.s, names[c], p->name));
|
|
226
|
+
if (named &&
|
|
209
227
|
(!p->ns || (uri && strcmp(uri, p->ns) == 0)))
|
|
210
228
|
ss_add(&next, tr->to);
|
|
211
229
|
} else if (p->kind == XSD_CM_ANY) {
|
|
@@ -20,7 +20,8 @@ extern int xsd_content_valid(struct leptris_xsd_schema* s, XsdCm* model,
|
|
|
20
20
|
const char* const* names,
|
|
21
21
|
const char* const* ns_uris, size_t count);
|
|
22
22
|
extern int xsd_builtin_valid(const char* type, const char* v);
|
|
23
|
-
extern int
|
|
23
|
+
extern int xsd_simple_valid_chain(struct leptris_xsd_schema* s,
|
|
24
|
+
const XsdSimple* t, const char* v);
|
|
24
25
|
|
|
25
26
|
struct xsd_error {
|
|
26
27
|
char* text;
|
|
@@ -40,6 +41,8 @@ extern const XsdSimple* xsd_find_simple_pub(
|
|
|
40
41
|
extern const char* xsd_target_ns(struct leptris_xsd_schema* s);
|
|
41
42
|
extern const XsdTypeAttrs* xsd_find_type_attrs(
|
|
42
43
|
struct leptris_xsd_schema* s, const char* type_name);
|
|
44
|
+
extern const XsdElementIcs* xsd_find_element_ics(
|
|
45
|
+
struct leptris_xsd_schema* s, const char* element_name);
|
|
43
46
|
|
|
44
47
|
/* ---- error list ---------------------------------------------------- */
|
|
45
48
|
|
|
@@ -94,7 +97,7 @@ static int text_valid(struct xsd_validator* v,
|
|
|
94
97
|
else {
|
|
95
98
|
const XsdSimple* st = xsd_find_simple_pub(s, type);
|
|
96
99
|
if (!st) return 1; /* unresolved: accept */
|
|
97
|
-
r =
|
|
100
|
+
r = xsd_simple_valid_chain(s, st, lexical);
|
|
98
101
|
}
|
|
99
102
|
if (r == 0) {
|
|
100
103
|
verrf(v, what, name, "lexical value does not match its type");
|
|
@@ -107,6 +110,10 @@ static int text_valid(struct xsd_validator* v,
|
|
|
107
110
|
static void validate_element(struct xsd_validator* v,
|
|
108
111
|
struct leptris_xsd_schema* s,
|
|
109
112
|
LeptrisElement elem, int depth);
|
|
113
|
+
static void validate_local(struct xsd_validator* v,
|
|
114
|
+
struct leptris_xsd_schema* s,
|
|
115
|
+
LeptrisElement elem, const char* local,
|
|
116
|
+
const char* type);
|
|
110
117
|
|
|
111
118
|
static void validate_children(struct xsd_validator* v,
|
|
112
119
|
struct leptris_xsd_schema* s,
|
|
@@ -149,16 +156,25 @@ static void validate_children(struct xsd_validator* v,
|
|
|
149
156
|
leptris_element_expanded_name(elem, &local, NULL, NULL);
|
|
150
157
|
verrf(v, "element", local, "children do not match the content model");
|
|
151
158
|
}
|
|
152
|
-
/* recurse
|
|
153
|
-
*
|
|
159
|
+
/* recurse: a global declaration governs the child when one
|
|
160
|
+
* exists; otherwise the parent's particle declaration does
|
|
161
|
+
* (first-name-match DFS — position-exact particle typing
|
|
162
|
+
* arrives with the NFA trace). */
|
|
154
163
|
for (LeptrisNodeRef c =
|
|
155
164
|
leptris_node_first_child(leptris_element_as_node(elem));
|
|
156
165
|
c; c = leptris_node_next_sibling(c)) {
|
|
166
|
+
if (leptris_node_get_type(c) != LEPTRIS_NODE_TYPE_ELEMENT)
|
|
167
|
+
continue;
|
|
157
168
|
LeptrisElement ce = (LeptrisElement)c;
|
|
158
169
|
const char* cl = NULL, *cp = NULL, *cu = NULL;
|
|
159
170
|
leptris_element_expanded_name(ce, &cl, &cp, &cu);
|
|
160
|
-
if (
|
|
161
|
-
|
|
171
|
+
if (!cl) continue;
|
|
172
|
+
if (xsd_find_element(s, cl)) {
|
|
173
|
+
validate_element(v, s, ce, 0);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const char* ptype = NULL;
|
|
177
|
+
if (model) {
|
|
162
178
|
XsdCm* stack[64];
|
|
163
179
|
int sp = 0;
|
|
164
180
|
stack[sp++] = model;
|
|
@@ -170,19 +186,18 @@ static void validate_children(struct xsd_validator* v,
|
|
|
170
186
|
ptype = p->type;
|
|
171
187
|
break;
|
|
172
188
|
}
|
|
189
|
+
if (p->kind == XSD_CM_GROUP_REF) {
|
|
190
|
+
XsdGroupDef* g = xsd_find_group(s, p->name);
|
|
191
|
+
if (g && g->model && sp < 64)
|
|
192
|
+
stack[sp++] = g->model;
|
|
193
|
+
}
|
|
173
194
|
if (sp < 64 && p->first_child)
|
|
174
195
|
stack[sp++] = p->first_child;
|
|
175
196
|
}
|
|
176
197
|
}
|
|
177
|
-
if (ptype) {
|
|
178
|
-
const char* text = leptris_element_text(ce);
|
|
179
|
-
if (text && *text)
|
|
180
|
-
text_valid(v, s, ptype, text, "element", cl);
|
|
181
|
-
}
|
|
182
198
|
}
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
validate_element(v, s, ce, 0);
|
|
199
|
+
if (ptype)
|
|
200
|
+
validate_local(v, s, ce, cl, ptype);
|
|
186
201
|
}
|
|
187
202
|
}
|
|
188
203
|
|
|
@@ -217,6 +232,9 @@ static void validate_attributes(struct xsd_validator* v,
|
|
|
217
232
|
continue;
|
|
218
233
|
}
|
|
219
234
|
text_valid(v, s, a->type, val, "attribute", a->name);
|
|
235
|
+
if (a->fixed && strcmp(val, a->fixed) != 0)
|
|
236
|
+
verrf(v, "attribute", a->name,
|
|
237
|
+
"value does not match the fixed value");
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
240
|
|
|
@@ -231,20 +249,242 @@ static void validate_element(struct xsd_validator* v,
|
|
|
231
249
|
if (!d) return; /* undeclared: lax at this depth (strict later) */
|
|
232
250
|
|
|
233
251
|
if (!d->type) return; /* anyType */
|
|
252
|
+
if (d->fixed) {
|
|
253
|
+
const char* text = leptris_element_text(elem);
|
|
254
|
+
if (text && *text && strcmp(text, d->fixed) != 0)
|
|
255
|
+
verrf(v, "element", local,
|
|
256
|
+
"content does not match the fixed value");
|
|
257
|
+
}
|
|
258
|
+
validate_local(v, s, elem, local, d->type);
|
|
259
|
+
}
|
|
234
260
|
|
|
235
|
-
|
|
261
|
+
/* Validate one element against a type name that comes from a
|
|
262
|
+
* global declaration or a local particle: attributes and content
|
|
263
|
+
* model for complex types, lexical text otherwise. */
|
|
264
|
+
static void validate_local(struct xsd_validator* v,
|
|
265
|
+
struct leptris_xsd_schema* s,
|
|
266
|
+
LeptrisElement elem, const char* local,
|
|
267
|
+
const char* type) {
|
|
268
|
+
if (!type) return;
|
|
269
|
+
XsdCm* ct = xsd_find_complex(s, type);
|
|
236
270
|
if (ct) {
|
|
237
|
-
validate_attributes(v, s, elem, xsd_find_type_attrs(s,
|
|
271
|
+
validate_attributes(v, s, elem, xsd_find_type_attrs(s, type));
|
|
238
272
|
validate_children(v, s, elem, ct);
|
|
273
|
+
if (ct->text_type) {
|
|
274
|
+
const char* text = leptris_element_text(elem);
|
|
275
|
+
if (text && *text)
|
|
276
|
+
text_valid(v, s, ct->text_type, text, "element",
|
|
277
|
+
local);
|
|
278
|
+
}
|
|
239
279
|
return;
|
|
240
280
|
}
|
|
241
281
|
|
|
242
282
|
/* simple-typed element: text must be lexically valid */
|
|
243
|
-
if (strncmp(
|
|
244
|
-
xsd_find_simple_pub(s,
|
|
283
|
+
if (strncmp(type, "xs:", 3) == 0 ||
|
|
284
|
+
xsd_find_simple_pub(s, type)) {
|
|
245
285
|
const char* text = leptris_element_text(elem);
|
|
246
286
|
if (text && *text)
|
|
247
|
-
text_valid(v, s,
|
|
287
|
+
text_valid(v, s, type, text, "element", local);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* ---- slice 6: identity constraints -------------------------------- */
|
|
292
|
+
|
|
293
|
+
/* A key tuple: the field values of one selected node. */
|
|
294
|
+
typedef struct xsd_key_tuple {
|
|
295
|
+
char* values[8];
|
|
296
|
+
size_t count;
|
|
297
|
+
struct xsd_key_tuple* next;
|
|
298
|
+
} XsdKeyTuple;
|
|
299
|
+
|
|
300
|
+
/* All tuples collected for one constraint name, keyed by name. */
|
|
301
|
+
typedef struct xsd_key_table {
|
|
302
|
+
char* name;
|
|
303
|
+
XsdKeyTuple* tuples;
|
|
304
|
+
XsdKeyTuple* tail;
|
|
305
|
+
struct xsd_key_table* next;
|
|
306
|
+
} XsdKeyTable;
|
|
307
|
+
|
|
308
|
+
static XsdKeyTable* table_find(XsdKeyTable* head, const char* name) {
|
|
309
|
+
for (; head; head = head->next)
|
|
310
|
+
if (strcmp(head->name, name) == 0) return head;
|
|
311
|
+
return NULL;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static char* xsd_dup_str(const char* s) {
|
|
315
|
+
if (!s) return NULL;
|
|
316
|
+
size_t n = strlen(s) + 1;
|
|
317
|
+
char* out = (char*)malloc(n);
|
|
318
|
+
if (out) memcpy(out, s, n);
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
static void table_add(XsdKeyTable** head, const char* name,
|
|
323
|
+
char* const* values, size_t count) {
|
|
324
|
+
XsdKeyTable* t = table_find(*head, name);
|
|
325
|
+
if (!t) {
|
|
326
|
+
t = (XsdKeyTable*)calloc(1, sizeof(*t));
|
|
327
|
+
if (!t) return;
|
|
328
|
+
size_t n = strlen(name) + 1;
|
|
329
|
+
t->name = (char*)malloc(n);
|
|
330
|
+
if (!t->name) { free(t); return; }
|
|
331
|
+
memcpy(t->name, name, n);
|
|
332
|
+
t->next = *head;
|
|
333
|
+
*head = t;
|
|
334
|
+
}
|
|
335
|
+
XsdKeyTuple* tup = (XsdKeyTuple*)calloc(1, sizeof(*tup));
|
|
336
|
+
if (!tup) return;
|
|
337
|
+
for (size_t i = 0; i < count && i < 8; i++)
|
|
338
|
+
tup->values[i] = xsd_dup_str(values[i]);
|
|
339
|
+
tup->count = count < 8 ? count : 8;
|
|
340
|
+
if (t->tail)
|
|
341
|
+
t->tail->next = tup;
|
|
342
|
+
else
|
|
343
|
+
t->tuples = tup;
|
|
344
|
+
t->tail = tup;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/* Evaluate one IC against the scoping element. pass1: collect
|
|
348
|
+
* key/unique tuples and enforce uniqueness (key: also non-empty
|
|
349
|
+
* fields). pass2: keyref tuples resolve against collected tables. */
|
|
350
|
+
static void validate_ics(struct xsd_validator* v,
|
|
351
|
+
struct leptris_xsd_schema* s,
|
|
352
|
+
LeptrisElement elem, const char* elem_name,
|
|
353
|
+
XsdKeyTable** tables, int pass) {
|
|
354
|
+
(void)v;
|
|
355
|
+
const XsdElementIcs* ics = xsd_find_element_ics(s, elem_name);
|
|
356
|
+
if (!ics) return;
|
|
357
|
+
extern struct leptris_document* leptris_element_get_document(
|
|
358
|
+
LeptrisElement elem);
|
|
359
|
+
LeptrisDocument doc = leptris_element_get_document(elem);
|
|
360
|
+
for (XsdIc* ic = ics->constraints; ic; ic = ic->next) {
|
|
361
|
+
int is_ref = ic->kind == 2;
|
|
362
|
+
if (pass == 1 && is_ref) continue;
|
|
363
|
+
if (pass == 2 && !is_ref) continue;
|
|
364
|
+
if (!ic->selector || !ic->name) continue;
|
|
365
|
+
LeptrisXPathResult sel =
|
|
366
|
+
leptris_xpath_eval(doc, elem, ic->selector);
|
|
367
|
+
if (!sel) continue;
|
|
368
|
+
size_t sel_count = leptris_xpath_result_count(sel);
|
|
369
|
+
for (size_t i = 0; i < sel_count; i++) {
|
|
370
|
+
LeptrisElement node = leptris_xpath_result_get(sel, i);
|
|
371
|
+
if (!node) continue;
|
|
372
|
+
/* field values: string of each field expression */
|
|
373
|
+
char* vals[8] = {0};
|
|
374
|
+
size_t nv = 0;
|
|
375
|
+
int missing = 0;
|
|
376
|
+
for (size_t f = 0; f < ic->field_count && f < 8; f++) {
|
|
377
|
+
LeptrisXPathResult fr =
|
|
378
|
+
leptris_xpath_eval(doc, node, ic->fields[f]);
|
|
379
|
+
if (!fr || leptris_xpath_result_count(fr) == 0) {
|
|
380
|
+
missing = 1;
|
|
381
|
+
if (fr) leptris_xpath_result_free(fr);
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
/* String-value of the first node — attribute nodes
|
|
385
|
+
* included (leptris_xpath_result_string handles every
|
|
386
|
+
* node kind; #3526 contract). */
|
|
387
|
+
char* sv = leptris_xpath_result_string(fr);
|
|
388
|
+
leptris_xpath_result_free(fr);
|
|
389
|
+
vals[nv] = xsd_dup_str(sv ? sv : "");
|
|
390
|
+
leptris_free_string(sv);
|
|
391
|
+
nv++;
|
|
392
|
+
}
|
|
393
|
+
for (size_t k = 0; k < nv; k++)
|
|
394
|
+
if (!vals[k] || !vals[k][0]) missing = 1;
|
|
395
|
+
if (missing) {
|
|
396
|
+
if (ic->kind == 0)
|
|
397
|
+
verrf(v, "key", ic->name,
|
|
398
|
+
"a selected node is missing a field value");
|
|
399
|
+
for (size_t k = 0; k < nv; k++) free(vals[k]);
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
if (pass == 1) {
|
|
403
|
+
/* uniqueness within this constraint */
|
|
404
|
+
XsdKeyTable* t = table_find(*tables, ic->name);
|
|
405
|
+
int dup = 0;
|
|
406
|
+
if (t) {
|
|
407
|
+
for (XsdKeyTuple* tup = t->tuples; tup;
|
|
408
|
+
tup = tup->next) {
|
|
409
|
+
int eq = tup->count == nv;
|
|
410
|
+
for (size_t k = 0; eq && k < nv; k++)
|
|
411
|
+
if (strcmp(tup->values[k], vals[k]) != 0)
|
|
412
|
+
eq = 0;
|
|
413
|
+
if (eq) { dup = 1; break; }
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (dup) {
|
|
417
|
+
verrf(v, ic->kind == 0 ? "key" : "unique",
|
|
418
|
+
ic->name, "duplicate key tuple");
|
|
419
|
+
}
|
|
420
|
+
table_add(tables, ic->name, vals, nv);
|
|
421
|
+
} else {
|
|
422
|
+
/* keyref: resolve later (deferred to pass 2 end) —
|
|
423
|
+
* store under the REFER name */
|
|
424
|
+
table_add(tables, ic->refer ? ic->refer : "",
|
|
425
|
+
vals, nv);
|
|
426
|
+
}
|
|
427
|
+
for (size_t k = 0; k < nv; k++) free(vals[k]);
|
|
428
|
+
}
|
|
429
|
+
leptris_xpath_result_free(sel);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/* Pass 2 tail: every keyref tuple must appear in the referenced
|
|
434
|
+
* key/unique table. */
|
|
435
|
+
static void resolve_keyrefs(struct xsd_validator* v,
|
|
436
|
+
struct leptris_xsd_schema* s,
|
|
437
|
+
XsdKeyTable* all, XsdKeyTable* refs) {
|
|
438
|
+
(void)s;
|
|
439
|
+
for (XsdKeyTable* rt = refs; rt; rt = rt->next) {
|
|
440
|
+
XsdKeyTable* target = table_find(all, rt->name);
|
|
441
|
+
if (!target) continue; /* unknown refer: capture-time lax */
|
|
442
|
+
for (XsdKeyTuple* want = rt->tuples; want; want = want->next) {
|
|
443
|
+
int found = 0;
|
|
444
|
+
for (XsdKeyTuple* have = target->tuples; have;
|
|
445
|
+
have = have->next) {
|
|
446
|
+
int eq = have->count == want->count;
|
|
447
|
+
for (size_t k = 0; eq && k < want->count; k++)
|
|
448
|
+
if (strcmp(have->values[k], want->values[k]) != 0)
|
|
449
|
+
eq = 0;
|
|
450
|
+
if (eq) { found = 1; break; }
|
|
451
|
+
}
|
|
452
|
+
if (!found)
|
|
453
|
+
verrf(v, "keyref", rt->name,
|
|
454
|
+
"reference does not resolve to any key");
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
static void tables_free(XsdKeyTable* t) {
|
|
460
|
+
while (t) {
|
|
461
|
+
XsdKeyTable* n = t->next;
|
|
462
|
+
XsdKeyTuple* tup = t->tuples;
|
|
463
|
+
while (tup) {
|
|
464
|
+
XsdKeyTuple* tn = tup->next;
|
|
465
|
+
for (size_t k = 0; k < tup->count; k++) free(tup->values[k]);
|
|
466
|
+
free(tup);
|
|
467
|
+
tup = tn;
|
|
468
|
+
}
|
|
469
|
+
free(t->name);
|
|
470
|
+
free(t);
|
|
471
|
+
t = n;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/* Walk every element carrying constraints in both passes. */
|
|
476
|
+
static void ic_walk(struct xsd_validator* v, struct leptris_xsd_schema* s,
|
|
477
|
+
LeptrisElement elem, XsdKeyTable** keys,
|
|
478
|
+
XsdKeyTable** refs, int pass) {
|
|
479
|
+
const char* local = NULL;
|
|
480
|
+
leptris_element_expanded_name(elem, &local, NULL, NULL);
|
|
481
|
+
if (local) validate_ics(v, s, elem, local, pass == 1 ? keys : refs, pass);
|
|
482
|
+
for (LeptrisNodeRef c =
|
|
483
|
+
leptris_node_first_child(leptris_element_as_node(elem));
|
|
484
|
+
c; c = leptris_node_next_sibling(c)) {
|
|
485
|
+
if (leptris_node_get_type(c) != LEPTRIS_NODE_TYPE_ELEMENT)
|
|
486
|
+
continue;
|
|
487
|
+
ic_walk(v, s, (LeptrisElement)c, keys, refs, pass);
|
|
248
488
|
}
|
|
249
489
|
}
|
|
250
490
|
|
|
@@ -272,6 +512,17 @@ int xsd_validator_run(struct xsd_validator* v, LeptrisDocument doc) {
|
|
|
272
512
|
LeptrisElement root = leptris_document_root(doc);
|
|
273
513
|
if (!root) return -1;
|
|
274
514
|
validate_element(v, v->s, root, 0);
|
|
515
|
+
|
|
516
|
+
/* slice 6: identity constraints — collect (pass 1), resolve
|
|
517
|
+
* keyrefs (pass 2). */
|
|
518
|
+
XsdKeyTable* keys = NULL;
|
|
519
|
+
XsdKeyTable* refs = NULL;
|
|
520
|
+
ic_walk(v, v->s, root, &keys, &refs, 1);
|
|
521
|
+
ic_walk(v, v->s, root, &keys, &refs, 2);
|
|
522
|
+
resolve_keyrefs(v, v->s, keys, refs);
|
|
523
|
+
tables_free(keys);
|
|
524
|
+
tables_free(refs);
|
|
525
|
+
|
|
275
526
|
return v->count == 0 ? 1 : 0;
|
|
276
527
|
}
|
|
277
528
|
|
|
@@ -9,18 +9,41 @@
|
|
|
9
9
|
extern "C" {
|
|
10
10
|
#endif
|
|
11
11
|
|
|
12
|
+
/* Opaque here: compile.c owns the definition; prototypes below
|
|
13
|
+
* take it by pointer only. */
|
|
14
|
+
struct leptris_xsd_schema;
|
|
15
|
+
|
|
12
16
|
/* One xs:enumeration / facet value, schema-owned. */
|
|
13
17
|
typedef struct xsd_facet_value {
|
|
14
18
|
char* text;
|
|
15
19
|
struct xsd_facet_value* next;
|
|
16
20
|
} XsdFacetValue;
|
|
17
21
|
|
|
22
|
+
/* How a user simpleType is derived: restriction of a base (with
|
|
23
|
+
* facets), a whitespace-separated list of an item type, or a
|
|
24
|
+
* union of member types. */
|
|
25
|
+
typedef enum {
|
|
26
|
+
XSD_SIMPLE_RESTRICT = 0,
|
|
27
|
+
XSD_SIMPLE_LIST,
|
|
28
|
+
XSD_SIMPLE_UNION
|
|
29
|
+
} XsdSimpleDeriv;
|
|
30
|
+
|
|
18
31
|
/* A user simpleType captured at compile time: name, restriction
|
|
19
32
|
* base (a built-in reference like "xs:integer" or another local
|
|
20
|
-
* simpleType name), and the facets the restriction carries.
|
|
33
|
+
* simpleType name), and the facets the restriction carries.
|
|
34
|
+
* List item types and union members arrive either as NAMES
|
|
35
|
+
* (resolved through the schema at validation) or as inline
|
|
36
|
+
* anonymous captures riding this type (freed with it). */
|
|
21
37
|
typedef struct xsd_simple {
|
|
22
38
|
char* name;
|
|
23
39
|
char* base;
|
|
40
|
+
XsdSimpleDeriv deriv;
|
|
41
|
+
char* item_type; /* LIST: builtin or local type name */
|
|
42
|
+
struct xsd_simple* item_def; /* LIST: inline anonymous item type */
|
|
43
|
+
char** members; /* UNION: named member type names */
|
|
44
|
+
size_t member_count;
|
|
45
|
+
struct xsd_simple** member_defs; /* UNION: inline members */
|
|
46
|
+
size_t member_def_count;
|
|
24
47
|
char* pattern;
|
|
25
48
|
XsdFacetValue* enum_values;
|
|
26
49
|
size_t enum_count;
|
|
@@ -37,6 +60,11 @@ typedef struct xsd_simple {
|
|
|
37
60
|
struct xsd_simple* next;
|
|
38
61
|
} XsdSimple;
|
|
39
62
|
|
|
63
|
+
/* Instance-path entry to the chain walker: resolves list item
|
|
64
|
+
* types and union member names through the schema. */
|
|
65
|
+
int xsd_simple_valid_chain(struct leptris_xsd_schema* s,
|
|
66
|
+
const XsdSimple* t, const char* v);
|
|
67
|
+
|
|
40
68
|
/* Content-model node: a particle (element ref / wildcard) or a
|
|
41
69
|
* group (sequence | choice | all). Owned by the schema; freed
|
|
42
70
|
* with the schema. */
|
|
@@ -45,7 +73,8 @@ typedef enum {
|
|
|
45
73
|
XSD_CM_ANY,
|
|
46
74
|
XSD_CM_SEQ,
|
|
47
75
|
XSD_CM_CHOICE,
|
|
48
|
-
XSD_CM_ALL
|
|
76
|
+
XSD_CM_ALL,
|
|
77
|
+
XSD_CM_GROUP_REF /* name holds the ref; expanded at NFA build */
|
|
49
78
|
} XsdCmKind;
|
|
50
79
|
|
|
51
80
|
typedef struct xsd_cm {
|
|
@@ -58,24 +87,74 @@ typedef struct xsd_cm {
|
|
|
58
87
|
int min, max; /* occurrence bounds; max < 0 = unbounded */
|
|
59
88
|
struct xsd_cm* first_child; /* group children list */
|
|
60
89
|
struct xsd_cm* next; /* sibling link within the parent group */
|
|
90
|
+
char* text_type; /* simpleContent wrapper: the text's type ref */
|
|
61
91
|
} XsdCm;
|
|
62
92
|
|
|
93
|
+
/* A top-level xs:group definition: name + the model its refs
|
|
94
|
+
* splice in (the definition's single sequence/choice/all). */
|
|
95
|
+
typedef struct xsd_group_def {
|
|
96
|
+
char* name;
|
|
97
|
+
XsdCm* model;
|
|
98
|
+
struct xsd_group_def* next;
|
|
99
|
+
} XsdGroupDef;
|
|
100
|
+
|
|
101
|
+
/* Group refs resolve through the schema at NFA-build time —
|
|
102
|
+
* forward references need no capture order. */
|
|
103
|
+
XsdGroupDef* xsd_find_group(struct leptris_xsd_schema* s,
|
|
104
|
+
const char* name);
|
|
105
|
+
|
|
63
106
|
/* A top-level xs:element declaration (slice 3: name + type ref). */
|
|
64
107
|
typedef struct xsd_element_decl {
|
|
65
108
|
char* name;
|
|
66
|
-
char* type;
|
|
109
|
+
char* type; /* "xs:string"-style builtin or a local type name */
|
|
110
|
+
char* fixed; /* fixed element content: text must string-equal it */
|
|
111
|
+
char* sub_head; /* substitutionGroup head (local name after ':') */
|
|
67
112
|
struct xsd_element_decl* next;
|
|
68
113
|
} XsdElementDecl;
|
|
69
114
|
|
|
115
|
+
/* Instance element `name` may bind a particle written for `head`
|
|
116
|
+
* when its substitutionGroup chain (depth-capped) reaches head. */
|
|
117
|
+
int xsd_is_substitute(struct leptris_xsd_schema* s,
|
|
118
|
+
const char* name, const char* head);
|
|
119
|
+
|
|
70
120
|
typedef struct xsd_attr_decl {
|
|
71
121
|
char* name; /* attribute local name */
|
|
72
122
|
char* type; /* builtin ref or local simpleType name (NULL=anySimple) */
|
|
123
|
+
char* fixed; /* #FIXED value: present values must string-equal it */
|
|
73
124
|
int required;
|
|
74
125
|
struct xsd_attr_decl* next;
|
|
75
126
|
} XsdAttrDecl;
|
|
76
127
|
|
|
77
128
|
/* complexType name -> its attribute declarations (hash-free: a
|
|
78
129
|
* parallel list keyed the same way as complex model roots). */
|
|
130
|
+
/* ---- slice 6: identity constraints -------------------------------- */
|
|
131
|
+
|
|
132
|
+
/* xs:key | xs:unique | xs:keyref captured on an element decl. */
|
|
133
|
+
typedef struct xsd_ic {
|
|
134
|
+
char* name; /* constraint name */
|
|
135
|
+
int kind; /* 0 = key, 1 = unique, 2 = keyref */
|
|
136
|
+
char* selector; /* XPath relative to the scoping element */
|
|
137
|
+
char* fields[8]; /* XPaths relative to each selected node */
|
|
138
|
+
size_t field_count;
|
|
139
|
+
char* refer; /* keyref: the referenced constraint's name */
|
|
140
|
+
struct xsd_ic* next;
|
|
141
|
+
} XsdIc;
|
|
142
|
+
|
|
143
|
+
/* Per-declaration constraint list: entries keyed by element name. */
|
|
144
|
+
typedef struct xsd_element_ics {
|
|
145
|
+
char* element_name;
|
|
146
|
+
XsdIc* constraints;
|
|
147
|
+
struct xsd_element_ics* next;
|
|
148
|
+
} XsdElementIcs;
|
|
149
|
+
|
|
150
|
+
/* A top-level xs:attributeGroup definition: name + its attribute
|
|
151
|
+
* rows (deep-copied into each referencing type at capture). */
|
|
152
|
+
typedef struct xsd_attrgroup_def {
|
|
153
|
+
char* name;
|
|
154
|
+
XsdAttrDecl* attrs;
|
|
155
|
+
struct xsd_attrgroup_def* next;
|
|
156
|
+
} XsdAttrGroupDef;
|
|
157
|
+
|
|
79
158
|
typedef struct xsd_type_attrs {
|
|
80
159
|
char* type_name;
|
|
81
160
|
XsdAttrDecl* attrs;
|
|
@@ -3066,7 +3066,7 @@ static void strip_source_whitespace(XsltExec* ex) {
|
|
|
3066
3066
|
* content decodes to a NUL-terminated "" (#1285 slice
|
|
3067
3067
|
* 4b — no overflow-table entry per stripped node). */
|
|
3068
3068
|
LeptrisTextNode* tn = (LeptrisTextNode*)c;
|
|
3069
|
-
leptris_textnode_set_content_ptr_doc(tn, "", ex->result);
|
|
3069
|
+
leptris_textnode_set_content_ptr_doc(tn, "", 0, ex->result);
|
|
3070
3070
|
tn->content_len = 0;
|
|
3071
3071
|
}
|
|
3072
3072
|
}
|
|
@@ -265,4 +265,9 @@ if(LEPTRIS_ENABLE_FUZZING)
|
|
|
265
265
|
target_link_libraries(fuzz_parse PRIVATE leptris)
|
|
266
266
|
target_include_directories(fuzz_parse PRIVATE
|
|
267
267
|
${PROJECT_SOURCE_DIR}/src/include)
|
|
268
|
+
# The harness doc and the nightly workflow invoke the binary at
|
|
269
|
+
# the build root, not under build/test/ where subdirectory
|
|
270
|
+
# targets land by default.
|
|
271
|
+
set_target_properties(fuzz_parse PROPERTIES
|
|
272
|
+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
|
268
273
|
endif()
|