leptris 1.9.340.0-arm-linux → 1.9.342.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 +31 -0
- data/Rakefile +1 -1
- data/ext/leptris/native/native.c +18 -1
- data/lib/leptris/version.rb +1 -1
- data/lib/leptris/xml/descriptor.rb +39 -3
- data/lib/leptris/xml/element.rb +18 -7
- data/lib/leptris/xml/ffi.rb +20 -0
- data/lib/leptris/xml/native.so +0 -0
- data/lib/leptris/xml/node.rb +22 -0
- data/lib/libleptris.so +0 -0
- data/vendor-src/README.md +1 -1
- data/vendor-src/libleptris/CHANGELOG.md +71 -0
- data/vendor-src/libleptris/CMakeLists.txt +1 -1
- data/vendor-src/libleptris/src/include/leptris/descriptor.h +27 -0
- data/vendor-src/libleptris/src/leptris/descriptor/plan.c +226 -12
- data/vendor-src/libleptris/src/leptris/rng/rng_regex.c +71 -3
- data/vendor-src/libleptris/src/leptris/serialize/serialize.c +38 -0
- data/vendor-src/libleptris/src/leptris/xsd/compile.c +98 -3
- data/vendor-src/libleptris/src/leptris/xsd/datatypes.c +27 -5
- data/vendor-src/libleptris/test/abi/test_descriptor.cpp +120 -0
- data/vendor-src/libleptris/test/dom/test_dom.cpp +77 -0
- data/vendor-src/libleptris/test/serializer/test_serialize.cpp +25 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/a1.xsd +5 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/a2.xsd +4 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/b1.xsd +5 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/b2.xsd +4 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/s.xsd +3 -0
- data/vendor-src/libleptris/test/xsd/libxml2-cases/import_dag/w.xsd +5 -0
- data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +93 -0
- data/vendor-src/libleptris/vcpkg.json +1 -1
- metadata +8 -2
|
@@ -1384,14 +1384,40 @@ static int dp_emit_element_open(const struct leptris_plan_result* v,
|
|
|
1384
1384
|
return 1;
|
|
1385
1385
|
}
|
|
1386
1386
|
|
|
1387
|
+
/* #425: plan-serialize formatting — depth-tracked indent for
|
|
1388
|
+
* element boundaries. NULL fmt = the compact historical form.
|
|
1389
|
+
* RAW/CONTENT runs stay verbatim inline (the byte-exact
|
|
1390
|
+
* mixed-content rule, #534 discipline): a subtree with any
|
|
1391
|
+
* non-element kid is emitted compact as a whole. */
|
|
1392
|
+
typedef struct {
|
|
1393
|
+
int indent; /* spaces per level; 0 = compact */
|
|
1394
|
+
const char* unit; /* NULL = spaces */
|
|
1395
|
+
} dp_fmt;
|
|
1396
|
+
|
|
1397
|
+
static int dp_sb_indent_newline(dp_sb* b, const dp_fmt* fmt, int depth) {
|
|
1398
|
+
if (!dp_sb_putn(b, "\n", 1)) return 0;
|
|
1399
|
+
/* One unit (or one indent-step of spaces) PER LEVEL. */
|
|
1400
|
+
if (fmt->unit) {
|
|
1401
|
+
size_t ul = strlen(fmt->unit);
|
|
1402
|
+
for (int i = 0; i < depth; i++)
|
|
1403
|
+
if (!dp_sb_putn(b, fmt->unit, ul)) return 0;
|
|
1404
|
+
return 1;
|
|
1405
|
+
}
|
|
1406
|
+
for (int i = 0; i < depth * fmt->indent; i++)
|
|
1407
|
+
if (!dp_sb_putn(b, " ", 1)) return 0;
|
|
1408
|
+
return 1;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1387
1411
|
static int dp_emit_value(const struct leptris_plan_result* v,
|
|
1388
1412
|
const dp_plan* container, const LeptrisPlan pool,
|
|
1389
|
-
dp_sb* b, const dp_decls* decls, int is_root
|
|
1413
|
+
dp_sb* b, const dp_decls* decls, int is_root,
|
|
1414
|
+
const dp_fmt* fmt, int depth);
|
|
1390
1415
|
|
|
1391
1416
|
static int dp_emit_element(const struct leptris_plan_result* v,
|
|
1392
1417
|
const char* name, const LeptrisPlan pool,
|
|
1393
1418
|
const dp_plan* kids_container, dp_sb* b,
|
|
1394
|
-
const dp_decls* decls, int is_root
|
|
1419
|
+
const dp_decls* decls, int is_root,
|
|
1420
|
+
const dp_fmt* fmt, int depth) {
|
|
1395
1421
|
if (!dp_emit_element_open(v, name, b, decls, is_root)) return 0;
|
|
1396
1422
|
const struct leptris_plan_result** kids = NULL;
|
|
1397
1423
|
size_t nk = 0, cap = 0;
|
|
@@ -1408,23 +1434,38 @@ static int dp_emit_element(const struct leptris_plan_result* v,
|
|
|
1408
1434
|
return 0;
|
|
1409
1435
|
}
|
|
1410
1436
|
qsort((void*)kids, nk, sizeof(*kids), dp_kid_pos_cmp);
|
|
1437
|
+
int indent_kids = fmt && fmt->indent > 0;
|
|
1438
|
+
for (size_t i = 0; i < nk && indent_kids; i++)
|
|
1439
|
+
if (kids[i]->kind == LEPTRIS_PLAN_VALUE_RAW)
|
|
1440
|
+
indent_kids = 0;
|
|
1411
1441
|
/* #1565: kid ROWS live in the plan that WALKED this element —
|
|
1412
1442
|
* container_plan is the plan whose row CAPTURED it (the
|
|
1413
1443
|
* parent), so a nested member resolved its kids' rows against
|
|
1414
1444
|
* the parent's rows and a CONTENT row serialized as an
|
|
1415
1445
|
* empty-named wrapper. */
|
|
1416
1446
|
int ok = 1;
|
|
1417
|
-
for (size_t i = 0; i < nk && ok; i++)
|
|
1418
|
-
|
|
1447
|
+
for (size_t i = 0; i < nk && ok; i++) {
|
|
1448
|
+
if (indent_kids && !dp_sb_indent_newline(b, fmt, depth + 1)) {
|
|
1449
|
+
ok = 0;
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
ok = dp_emit_value(kids[i], kids_container, pool, b, NULL, 0,
|
|
1453
|
+
fmt, indent_kids ? depth + 1 : depth);
|
|
1454
|
+
}
|
|
1419
1455
|
free((void*)kids);
|
|
1420
1456
|
if (!ok) return 0;
|
|
1421
|
-
|
|
1422
|
-
|
|
1457
|
+
if (indent_kids && !dp_sb_indent_newline(b, fmt, depth)) return 0;
|
|
1458
|
+
ok = dp_sb_puts(b, "</") && dp_sb_puts(b, name) &&
|
|
1459
|
+
dp_sb_putn(b, ">", 1);
|
|
1460
|
+
if (ok && is_root && fmt && fmt->indent > 0)
|
|
1461
|
+
ok = dp_sb_putn(b, "\n", 1);
|
|
1462
|
+
return ok;
|
|
1423
1463
|
}
|
|
1424
1464
|
|
|
1425
1465
|
static int dp_emit_value(const struct leptris_plan_result* v,
|
|
1426
1466
|
const dp_plan* container, const LeptrisPlan pool,
|
|
1427
|
-
dp_sb* b, const dp_decls* decls, int is_root
|
|
1467
|
+
dp_sb* b, const dp_decls* decls, int is_root,
|
|
1468
|
+
const dp_fmt* fmt, int depth) {
|
|
1428
1469
|
if (v->kind == LEPTRIS_PLAN_VALUE_RAW)
|
|
1429
1470
|
return dp_sb_puts(b, v->str ? v->str : "");
|
|
1430
1471
|
if (v->kind == LEPTRIS_PLAN_VALUE_ELEMENT) {
|
|
@@ -1475,7 +1516,7 @@ static int dp_emit_value(const struct leptris_plan_result* v,
|
|
|
1475
1516
|
&poolp->plans[cap->child_plan_index];
|
|
1476
1517
|
}
|
|
1477
1518
|
int ok = dp_emit_element(v, name, pool, kids_container, b,
|
|
1478
|
-
decls, is_root);
|
|
1519
|
+
decls, is_root, fmt, depth);
|
|
1479
1520
|
free(name);
|
|
1480
1521
|
return ok;
|
|
1481
1522
|
}
|
|
@@ -1500,9 +1541,9 @@ static int dp_emit_value(const struct leptris_plan_result* v,
|
|
|
1500
1541
|
return dp_sb_escape(b, text, 0);
|
|
1501
1542
|
}
|
|
1502
1543
|
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1544
|
+
static char* dp_serialize_impl(LeptrisPlan plan,
|
|
1545
|
+
const LeptrisPlanResult result,
|
|
1546
|
+
const dp_fmt* fmt, LeptrisStatus* status) {
|
|
1506
1547
|
if (status) *status = LEPTRIS_OK;
|
|
1507
1548
|
if (!plan || !result) {
|
|
1508
1549
|
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
@@ -1518,7 +1559,7 @@ LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
|
|
|
1518
1559
|
}
|
|
1519
1560
|
dp_sb b = {0};
|
|
1520
1561
|
int ok = dp_emit_value(rv, NULL, (const LeptrisPlan)plan, &b,
|
|
1521
|
-
&decls, 1);
|
|
1562
|
+
&decls, 1, fmt, 0);
|
|
1522
1563
|
dp_decls_free(&decls);
|
|
1523
1564
|
if (!ok) {
|
|
1524
1565
|
free(b.s);
|
|
@@ -1535,6 +1576,179 @@ LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
|
|
|
1535
1576
|
return b.s;
|
|
1536
1577
|
}
|
|
1537
1578
|
|
|
1579
|
+
LEPTRIS_API char* leptris_plan_serialize(LeptrisPlan plan,
|
|
1580
|
+
const LeptrisPlanResult result,
|
|
1581
|
+
LeptrisStatus* status) {
|
|
1582
|
+
return dp_serialize_impl(plan, result, NULL, status);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
/* #425: formatting-bearing variant — indent > 0 pretty-prints
|
|
1586
|
+
* element boundaries (RAW/CONTENT runs stay verbatim inline);
|
|
1587
|
+
* indent_unit replaces the two-space default per level. options
|
|
1588
|
+
* NULL = the compact historical form. opts_size must cover the
|
|
1589
|
+
* struct the caller compiled against (growable, #129 pattern). */
|
|
1590
|
+
LEPTRIS_API char* leptris_plan_serialize_ext(
|
|
1591
|
+
LeptrisPlan plan, const LeptrisPlanResult result,
|
|
1592
|
+
const leptris_plan_serialize_options* options, size_t options_size,
|
|
1593
|
+
LeptrisStatus* status) {
|
|
1594
|
+
if (status) *status = LEPTRIS_OK;
|
|
1595
|
+
if (options && options_size < sizeof(*options)) {
|
|
1596
|
+
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1597
|
+
return NULL;
|
|
1598
|
+
}
|
|
1599
|
+
dp_fmt fmt;
|
|
1600
|
+
memset(&fmt, 0, sizeof(fmt));
|
|
1601
|
+
if (options) {
|
|
1602
|
+
fmt.indent = options->indent;
|
|
1603
|
+
fmt.unit = options->indent_unit;
|
|
1604
|
+
}
|
|
1605
|
+
return dp_serialize_impl(plan, result, &fmt, status);
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
/* #426: materialize a built result as a native document tree —
|
|
1609
|
+
* the consumer path becomes build_result -> this -> the document
|
|
1610
|
+
* writer, with no string round trip. Attributes carry verbatim
|
|
1611
|
+
* (wire spellings); the #1626 root declarations ride as xmlns
|
|
1612
|
+
* attributes. Caller frees with leptris_document_free. */
|
|
1613
|
+
static LeptrisElement dp_mint_element(LeptrisDocument doc,
|
|
1614
|
+
const struct leptris_plan_result* v,
|
|
1615
|
+
const dp_plan* container,
|
|
1616
|
+
const LeptrisPlan pool);
|
|
1617
|
+
|
|
1618
|
+
static int dp_mint_kids(LeptrisDocument doc, LeptrisElement parent,
|
|
1619
|
+
const struct leptris_plan_result* v,
|
|
1620
|
+
const dp_plan* kids_container,
|
|
1621
|
+
const LeptrisPlan pool) {
|
|
1622
|
+
const struct leptris_plan_result** kids = NULL;
|
|
1623
|
+
size_t nk = 0, cap = 0;
|
|
1624
|
+
if (!dp_flatten_kids(v, &kids, &nk, &cap)) {
|
|
1625
|
+
free((void*)kids);
|
|
1626
|
+
return 0;
|
|
1627
|
+
}
|
|
1628
|
+
qsort((void*)kids, nk, sizeof(*kids), dp_kid_pos_cmp);
|
|
1629
|
+
int ok = 1;
|
|
1630
|
+
for (size_t i = 0; i < nk && ok; i++) {
|
|
1631
|
+
const struct leptris_plan_result* k = kids[i];
|
|
1632
|
+
if (k->kind == LEPTRIS_PLAN_VALUE_ELEMENT) {
|
|
1633
|
+
LeptrisElement el =
|
|
1634
|
+
dp_mint_element(doc, k, kids_container, pool);
|
|
1635
|
+
if (!el) {
|
|
1636
|
+
ok = 0;
|
|
1637
|
+
break;
|
|
1638
|
+
}
|
|
1639
|
+
ok = leptris_element_append_child(parent, el) == LEPTRIS_OK;
|
|
1640
|
+
} else if (k->kind == LEPTRIS_PLAN_VALUE_RAW ||
|
|
1641
|
+
(kids_container && k->row_index != UINT32_MAX &&
|
|
1642
|
+
k->row_index < kids_container->child_count &&
|
|
1643
|
+
kids_container->child_plans[k->row_index].kind ==
|
|
1644
|
+
LEPTRIS_PLAN_KIND_CONTENT)) {
|
|
1645
|
+
LeptrisNodeRef t =
|
|
1646
|
+
leptris_text_node_create(doc, k->str ? k->str : "");
|
|
1647
|
+
ok = t && leptris_element_append_child(
|
|
1648
|
+
parent, (LeptrisElement)t) == LEPTRIS_OK;
|
|
1649
|
+
} else {
|
|
1650
|
+
char* name = dp_wrapper_name(k);
|
|
1651
|
+
if (!name) {
|
|
1652
|
+
ok = 0;
|
|
1653
|
+
break;
|
|
1654
|
+
}
|
|
1655
|
+
LeptrisElement w = leptris_element_new_with_attributes(
|
|
1656
|
+
doc, name, NULL, NULL, 0);
|
|
1657
|
+
free(name);
|
|
1658
|
+
if (!w) {
|
|
1659
|
+
ok = 0;
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
ok = leptris_element_set_text(w, k->str ? k->str : "") ==
|
|
1663
|
+
LEPTRIS_OK &&
|
|
1664
|
+
leptris_element_append_child(parent, w) == LEPTRIS_OK;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
free((void*)kids);
|
|
1668
|
+
return ok;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
static LeptrisElement dp_mint_element(LeptrisDocument doc,
|
|
1672
|
+
const struct leptris_plan_result* v,
|
|
1673
|
+
const dp_plan* container,
|
|
1674
|
+
const LeptrisPlan pool) {
|
|
1675
|
+
/* Name/kids resolution mirrors dp_emit_value. */
|
|
1676
|
+
const struct leptris_plan* poolp = (const struct leptris_plan*)pool;
|
|
1677
|
+
const dp_plan* self = &poolp->plans[v->container_plan];
|
|
1678
|
+
const char* local = NULL;
|
|
1679
|
+
if (v->name) {
|
|
1680
|
+
const char* colon = strchr(v->name, ':');
|
|
1681
|
+
local = colon ? colon + 1 : v->name;
|
|
1682
|
+
} else {
|
|
1683
|
+
local = self->element_name;
|
|
1684
|
+
}
|
|
1685
|
+
char* name = v->ns_prefix
|
|
1686
|
+
? dp_join_colon(v->ns_prefix, local ? local : "")
|
|
1687
|
+
: dp_strdup(local ? local : "");
|
|
1688
|
+
if (!name) return NULL;
|
|
1689
|
+
LeptrisElement el = leptris_element_new_with_attributes(
|
|
1690
|
+
doc, name, v->attr_names, v->attr_values, v->attr_count);
|
|
1691
|
+
free(name);
|
|
1692
|
+
if (!el) return NULL;
|
|
1693
|
+
const dp_plan* kids_container = &poolp->plans[v->container_plan];
|
|
1694
|
+
if (container && v->row_index != UINT32_MAX &&
|
|
1695
|
+
v->row_index < container->child_count) {
|
|
1696
|
+
const leptris_child_plan* cap =
|
|
1697
|
+
&container->child_plans[v->row_index];
|
|
1698
|
+
if (cap->child_plan_index >= 0 &&
|
|
1699
|
+
(uint32_t)cap->child_plan_index < poolp->plan_count)
|
|
1700
|
+
kids_container = &poolp->plans[cap->child_plan_index];
|
|
1701
|
+
}
|
|
1702
|
+
if (!dp_mint_kids(doc, el, v, kids_container, pool)) return NULL;
|
|
1703
|
+
return el;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
LEPTRIS_API LeptrisDocument leptris_document_from_plan_result(
|
|
1707
|
+
LeptrisPlan plan, const LeptrisPlanResult result,
|
|
1708
|
+
LeptrisStatus* status) {
|
|
1709
|
+
if (status) *status = LEPTRIS_OK;
|
|
1710
|
+
if (!plan || !result) {
|
|
1711
|
+
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1712
|
+
return NULL;
|
|
1713
|
+
}
|
|
1714
|
+
const struct leptris_plan_result* rv =
|
|
1715
|
+
(const struct leptris_plan_result*)result;
|
|
1716
|
+
if (rv->kind != LEPTRIS_PLAN_VALUE_ELEMENT) {
|
|
1717
|
+
if (status) *status = LEPTRIS_ERROR_INVALID_ARG;
|
|
1718
|
+
return NULL;
|
|
1719
|
+
}
|
|
1720
|
+
LeptrisDocument doc = leptris_document_create();
|
|
1721
|
+
if (!doc) {
|
|
1722
|
+
if (status) *status = LEPTRIS_ERROR_MEMORY;
|
|
1723
|
+
return NULL;
|
|
1724
|
+
}
|
|
1725
|
+
dp_decls decls = {0};
|
|
1726
|
+
int ok = dp_collect_decls(rv, &decls);
|
|
1727
|
+
LeptrisElement root = NULL;
|
|
1728
|
+
if (ok) {
|
|
1729
|
+
root = dp_mint_element(doc, rv, NULL, (const LeptrisPlan)plan);
|
|
1730
|
+
ok = root != NULL;
|
|
1731
|
+
}
|
|
1732
|
+
for (size_t i = 0; ok && i < decls.n; i++) {
|
|
1733
|
+
char* dn = dp_join_colon("xmlns", decls.p[i]);
|
|
1734
|
+
if (!dn) {
|
|
1735
|
+
ok = 0;
|
|
1736
|
+
break;
|
|
1737
|
+
}
|
|
1738
|
+
ok = leptris_element_set_attribute(root, dn, decls.u[i]) ==
|
|
1739
|
+
LEPTRIS_OK;
|
|
1740
|
+
free(dn);
|
|
1741
|
+
}
|
|
1742
|
+
if (ok) ok = leptris_document_set_root(doc, root) == LEPTRIS_OK;
|
|
1743
|
+
dp_decls_free(&decls);
|
|
1744
|
+
if (!ok) {
|
|
1745
|
+
leptris_document_free(doc);
|
|
1746
|
+
if (status) *status = LEPTRIS_ERROR_MEMORY;
|
|
1747
|
+
return NULL;
|
|
1748
|
+
}
|
|
1749
|
+
return doc;
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1538
1752
|
LEPTRIS_API LeptrisPlanResult leptris_plan_result_build(
|
|
1539
1753
|
LeptrisPlan plan, const leptris_plan_row_op* ops, size_t count,
|
|
1540
1754
|
LeptrisStatus* status) {
|
|
@@ -126,6 +126,41 @@ static RreNode* parse_class(RreParser* ps) {
|
|
|
126
126
|
int first = 1;
|
|
127
127
|
while (*ps->p && (*ps->p != ']' || first)) {
|
|
128
128
|
first = 0;
|
|
129
|
+
if (*ps->p == '\\' && ps->p[1] == 'p' && ps->p[2] == '{') {
|
|
130
|
+
/* XSD property classes for the Latin-1 byte world —
|
|
131
|
+
* the byte-class matcher covers these exactly
|
|
132
|
+
* (leptris-ruby#434, ST_ContentType). Other blocks
|
|
133
|
+
* fail loudly as before. */
|
|
134
|
+
ps->p += 3;
|
|
135
|
+
const char* close = strchr(ps->p, '}');
|
|
136
|
+
if (!close) {
|
|
137
|
+
node_free(n);
|
|
138
|
+
ps->bad = 1;
|
|
139
|
+
return NULL;
|
|
140
|
+
}
|
|
141
|
+
size_t len = (size_t)(close - ps->p);
|
|
142
|
+
int hit = 0;
|
|
143
|
+
if (len == 12 && memcmp(ps->p, "IsBasicLatin", 12) == 0) {
|
|
144
|
+
for (int i = 0x00; i <= 0x7F; i++) cls_add(n, (unsigned char)i);
|
|
145
|
+
hit = 1;
|
|
146
|
+
} else if (len == 19 &&
|
|
147
|
+
memcmp(ps->p, "IsLatin-1Supplement", 19) == 0) {
|
|
148
|
+
for (int i = 0x80; i <= 0xFF; i++) cls_add(n, (unsigned char)i);
|
|
149
|
+
hit = 1;
|
|
150
|
+
} else if (len == 2 && ps->p[0] == 'C' && ps->p[1] == 'c') {
|
|
151
|
+
for (int i = 0x00; i <= 0x1F; i++) cls_add(n, (unsigned char)i);
|
|
152
|
+
cls_add(n, 0x7F);
|
|
153
|
+
for (int i = 0x80; i <= 0x9F; i++) cls_add(n, (unsigned char)i);
|
|
154
|
+
hit = 1;
|
|
155
|
+
}
|
|
156
|
+
if (!hit) {
|
|
157
|
+
node_free(n);
|
|
158
|
+
ps->bad = 1;
|
|
159
|
+
return NULL;
|
|
160
|
+
}
|
|
161
|
+
ps->p = close + 1;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
129
164
|
if (*ps->p == '\\' && ps->p[1]) {
|
|
130
165
|
ps->p++;
|
|
131
166
|
char e = *ps->p++;
|
|
@@ -155,9 +190,37 @@ static RreNode* parse_class(RreParser* ps) {
|
|
|
155
190
|
node_free(tmp);
|
|
156
191
|
continue;
|
|
157
192
|
}
|
|
193
|
+
/* XSD singleCharEsc covers the control escapes too
|
|
194
|
+
* (the OPC ST_ContentType pattern uses \t) —
|
|
195
|
+
* leptris-ruby#434. */
|
|
196
|
+
if (e == 't') { cls_add(n, '\t'); continue; }
|
|
197
|
+
if (e == 'n') { cls_add(n, '\n'); continue; }
|
|
198
|
+
if (e == 'r') { cls_add(n, '\r'); continue; }
|
|
158
199
|
cls_add(n, (unsigned char)e);
|
|
159
200
|
continue;
|
|
160
201
|
}
|
|
202
|
+
/* XSD charClassSub: `[ A - [ B ] ]` — the '-' followed by
|
|
203
|
+
* '[' subtracts the bracketed class (leptris-ruby#434, the
|
|
204
|
+
* OPC ST_ContentType shape). The subtraction is the last
|
|
205
|
+
* member of the class. */
|
|
206
|
+
if (*ps->p == '-' && ps->p[1] == '[') {
|
|
207
|
+
ps->p++;
|
|
208
|
+
RreNode* sub = parse_class(ps);
|
|
209
|
+
if (!sub) {
|
|
210
|
+
node_free(n);
|
|
211
|
+
return NULL;
|
|
212
|
+
}
|
|
213
|
+
for (int i = 0; i < 256; i++)
|
|
214
|
+
if ((sub->cls[i >> 3] >> (i & 7)) & 1)
|
|
215
|
+
n->cls[i >> 3] &= (unsigned char)~(1u << (i & 7));
|
|
216
|
+
node_free(sub);
|
|
217
|
+
if (*ps->p != ']') {
|
|
218
|
+
node_free(n);
|
|
219
|
+
ps->bad = 1;
|
|
220
|
+
return NULL;
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
161
224
|
unsigned char c = (unsigned char)*ps->p++;
|
|
162
225
|
if (*ps->p == '-' && ps->p[1] && ps->p[1] != ']') {
|
|
163
226
|
ps->p++;
|
|
@@ -228,9 +291,14 @@ static RreNode* parse_atom(RreParser* ps) {
|
|
|
228
291
|
ps->p += 2;
|
|
229
292
|
RreNode* n = node_new(RRE_CHAR);
|
|
230
293
|
if (!n) return NULL;
|
|
231
|
-
/* Only punctuation may be escaped as a literal
|
|
232
|
-
* escapes (
|
|
233
|
-
*
|
|
294
|
+
/* Only punctuation may be escaped as a literal, plus the
|
|
295
|
+
* XSD control escapes (the OPC ST_ContentType pattern uses
|
|
296
|
+
* \t) — other escapes (XSD \p{...} outside a class,
|
|
297
|
+
* backrefs) are outside the supported subset and must fail
|
|
298
|
+
* loudly at parse time (leptris-ruby#434). */
|
|
299
|
+
if (e == 't') { n->ch = '\t'; return n; }
|
|
300
|
+
if (e == 'n') { n->ch = '\n'; return n; }
|
|
301
|
+
if (e == 'r') { n->ch = '\r'; return n; }
|
|
234
302
|
if (isalnum((unsigned char)e)) {
|
|
235
303
|
free(n);
|
|
236
304
|
ps->bad = 1;
|
|
@@ -595,6 +595,39 @@ static int html_break_after_elem(LeptrisElement elem,
|
|
|
595
595
|
return 1;
|
|
596
596
|
}
|
|
597
597
|
|
|
598
|
+
/* leptris#1647 (indent_html only): a block element whose SINGLE
|
|
599
|
+
* child is itself a block keeps the line layout — the child's own
|
|
600
|
+
* block content must not glue to the parent's tag (and the parent
|
|
601
|
+
* must not poison the subtree with mixed=1). The legacy §16.2
|
|
602
|
+
* shape is untouched: its site rules stay inline for a single
|
|
603
|
+
* child. p* parents stay inline (site-rule parity). */
|
|
604
|
+
static int html_block_child_needs_lines(LeptrisElement elem,
|
|
605
|
+
const char* name, size_t len,
|
|
606
|
+
int flags) {
|
|
607
|
+
if (!html_breaks_block(name, len, flags)) return 0;
|
|
608
|
+
if (name[0] == 'p') return 0;
|
|
609
|
+
LeptrisNode* c =
|
|
610
|
+
leptris_node_first_child_internal((LeptrisNode*)elem);
|
|
611
|
+
if (!c || leptris_node_get_next_sibling(c)) return 0;
|
|
612
|
+
if (c->type != LEPTRIS_NODE_TYPE_ELEMENT) return 0;
|
|
613
|
+
/* The child must itself take the line layout: it breaks its own
|
|
614
|
+
* children (site 1), or it nests a further element. A block
|
|
615
|
+
* whose only child is text (head>title) stays inline. */
|
|
616
|
+
{
|
|
617
|
+
LeptrisElement ce = (LeptrisElement)c;
|
|
618
|
+
const char* cn = elem_name(ce);
|
|
619
|
+
size_t cnl = (ce->name_len != 0xFF) ? (size_t)ce->name_len
|
|
620
|
+
: strlen(cn);
|
|
621
|
+
if (html_break_before_children(ce, cn, cnl,
|
|
622
|
+
html_elem_sem_flags(ce)))
|
|
623
|
+
return 1;
|
|
624
|
+
for (LeptrisNode* g = leptris_node_first_child_internal(c); g;
|
|
625
|
+
g = leptris_node_get_next_sibling(g))
|
|
626
|
+
if (g->type == LEPTRIS_NODE_TYPE_ELEMENT) return 1;
|
|
627
|
+
}
|
|
628
|
+
return 0;
|
|
629
|
+
}
|
|
630
|
+
|
|
598
631
|
/* Emit the CDATA BODY, splitting "]]>" across section closes. The
|
|
599
632
|
* caller owns the surrounding <![CDATA[ / ]]> brackets (run merging).
|
|
600
633
|
* The close scan runs to len-3 INCLUSIVE — a "]]>" at the very END
|
|
@@ -1639,6 +1672,8 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1639
1672
|
* the newlines. Elements that keep their children
|
|
1640
1673
|
* inline (single-child rule) own no whitespace. */
|
|
1641
1674
|
int brk_bc = html_break_before_children(e, name, nl, hf);
|
|
1675
|
+
if (!brk_bc)
|
|
1676
|
+
brk_bc = html_block_child_needs_lines(e, name, nl, hf);
|
|
1642
1677
|
if (brk_bc) {
|
|
1643
1678
|
mixed = buf->ws_mixed
|
|
1644
1679
|
? ser_children_have_any_text(fc)
|
|
@@ -1650,6 +1685,9 @@ void serialize_element_internal(LeptrisElement root_elem, SerializeBuffer* buf,
|
|
|
1650
1685
|
if (brk_bc) buffer_append_newline(buf);
|
|
1651
1686
|
}
|
|
1652
1687
|
close_brk = html_break_before_close(e, name, nl, hf);
|
|
1688
|
+
if (!close_brk && buf->indent_html)
|
|
1689
|
+
close_brk =
|
|
1690
|
+
html_block_child_needs_lines(e, name, nl, hf);
|
|
1653
1691
|
} else {
|
|
1654
1692
|
/* #129 indent_text: the formatter owns ALL whitespace —
|
|
1655
1693
|
* no element is "mixed" for layout purposes. */
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
void xsd_capture_ics(struct leptris_xsd_schema* s,
|
|
18
18
|
LeptrisElement elem, const char* element_name);
|
|
19
|
-
extern int xsd_simple_valid(const XsdSimple* simple, const char* v
|
|
19
|
+
extern int xsd_simple_valid(const XsdSimple* simple, const char* v,
|
|
20
|
+
const char* terminal_base);
|
|
20
21
|
extern struct xsd_validator* xsd_validator_new(
|
|
21
22
|
struct leptris_xsd_schema* s);
|
|
22
23
|
extern void xsd_validator_free(struct xsd_validator* v);
|
|
@@ -46,6 +47,12 @@ struct leptris_xsd_schema {
|
|
|
46
47
|
int version_11; /* xs:schema @version = "1.1" */
|
|
47
48
|
char* base_dir; /* schemaLocation resolution (file compile) */
|
|
48
49
|
int include_depth; /* include/import recursion guard */
|
|
50
|
+
/* leptris#1644: already-captured schema units (canonical
|
|
51
|
+
* location per entry) — the include/import DAG is dense and
|
|
52
|
+
* cyclic; without this set every DAG path re-parses and
|
|
53
|
+
* re-captures the whole subtree (multi-GB / minutes). */
|
|
54
|
+
char** visited;
|
|
55
|
+
size_t visited_len, visited_cap;
|
|
49
56
|
void* validator; /* slice-4 parked error list */
|
|
50
57
|
char* error;
|
|
51
58
|
};
|
|
@@ -465,6 +472,21 @@ static int xsd_item_valid(struct leptris_xsd_schema* s,
|
|
|
465
472
|
return 1;
|
|
466
473
|
}
|
|
467
474
|
|
|
475
|
+
/* The chain's terminal builtin (NULL = none resolved): the length
|
|
476
|
+
* family needs it to count octets for the binary bases
|
|
477
|
+
* (leptris-ruby#434). */
|
|
478
|
+
static const char* xsd_chain_terminal(struct leptris_xsd_schema* s,
|
|
479
|
+
const XsdSimple* t) {
|
|
480
|
+
int depth = 0;
|
|
481
|
+
while (t && depth < 32) {
|
|
482
|
+
if (!t->base) return NULL;
|
|
483
|
+
if (strncmp(t->base, "xs:", 3) == 0) return t->base;
|
|
484
|
+
t = xsd_find_simple(s, t->base);
|
|
485
|
+
depth++;
|
|
486
|
+
}
|
|
487
|
+
return NULL;
|
|
488
|
+
}
|
|
489
|
+
|
|
468
490
|
static int xsd_deriv_valid(struct leptris_xsd_schema* s,
|
|
469
491
|
const XsdSimple* t, const char* v,
|
|
470
492
|
int depth) {
|
|
@@ -506,7 +528,7 @@ static int xsd_deriv_valid(struct leptris_xsd_schema* s,
|
|
|
506
528
|
return 1;
|
|
507
529
|
return 0;
|
|
508
530
|
}
|
|
509
|
-
return xsd_simple_valid(t, v);
|
|
531
|
+
return xsd_simple_valid(t, v, xsd_chain_terminal(s, t));
|
|
510
532
|
}
|
|
511
533
|
|
|
512
534
|
static int xsd_valid_chain(struct leptris_xsd_schema* s,
|
|
@@ -518,7 +540,7 @@ static int xsd_valid_chain(struct leptris_xsd_schema* s,
|
|
|
518
540
|
}
|
|
519
541
|
if (t->deriv != XSD_SIMPLE_RESTRICT)
|
|
520
542
|
return xsd_deriv_valid(s, t, v, depth);
|
|
521
|
-
return xsd_simple_valid(t, v);
|
|
543
|
+
return xsd_simple_valid(t, v, xsd_chain_terminal(s, t));
|
|
522
544
|
}
|
|
523
545
|
|
|
524
546
|
static void xsd_set_error(struct leptris_xsd_schema* s, const char* msg) {
|
|
@@ -688,6 +710,70 @@ fail:
|
|
|
688
710
|
* the owning schema's base_dir (string-compiled schemas have none
|
|
689
711
|
* and skip them); the referenced root's declarations merge into
|
|
690
712
|
* the same tables. */
|
|
713
|
+
/* leptris#1644: lexical path normalization — collapse "." and
|
|
714
|
+
* ".." segments (and duplicate separators) so the same file reached
|
|
715
|
+
* through different relative spellings yields one dedup key.
|
|
716
|
+
* Purely lexical: no filesystem access, portable. */
|
|
717
|
+
static void xsd_path_normalize(const char* in, char* out, size_t outsz) {
|
|
718
|
+
struct {
|
|
719
|
+
const char* p;
|
|
720
|
+
size_t len;
|
|
721
|
+
} comps[512];
|
|
722
|
+
size_t n = 0;
|
|
723
|
+
int is_abs = in[0] == '/';
|
|
724
|
+
const char* q = in;
|
|
725
|
+
while (*q) {
|
|
726
|
+
while (*q == '/') q++;
|
|
727
|
+
if (!*q) break;
|
|
728
|
+
const char* start = q;
|
|
729
|
+
while (*q && *q != '/') q++;
|
|
730
|
+
size_t len = (size_t)(q - start);
|
|
731
|
+
if (len == 1 && start[0] == '.') continue;
|
|
732
|
+
if (len == 2 && start[0] == '.' && start[1] == '.') {
|
|
733
|
+
if (n > 0)
|
|
734
|
+
n--; /* ".." pops; a leading pop on an absolute
|
|
735
|
+
path would escape the root — drop it */
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
if (n < sizeof(comps) / sizeof(comps[0])) {
|
|
739
|
+
comps[n].p = start;
|
|
740
|
+
comps[n].len = len;
|
|
741
|
+
n++;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
size_t o = 0;
|
|
745
|
+
if (is_abs && o < outsz) out[o++] = '/';
|
|
746
|
+
for (size_t i = 0; i < n; i++) {
|
|
747
|
+
if (o && o < outsz && out[o - 1] != '/') out[o++] = '/';
|
|
748
|
+
if (o + comps[i].len >= outsz) break;
|
|
749
|
+
memcpy(out + o, comps[i].p, comps[i].len);
|
|
750
|
+
o += comps[i].len;
|
|
751
|
+
}
|
|
752
|
+
if (o == 0 && outsz > 1) out[o++] = '.';
|
|
753
|
+
out[o] = 0;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
static int xsd_visited_has(struct leptris_xsd_schema* s,
|
|
757
|
+
const char* path) {
|
|
758
|
+
for (size_t i = 0; i < s->visited_len; i++)
|
|
759
|
+
if (strcmp(s->visited[i], path) == 0) return 1;
|
|
760
|
+
return 0;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
static void xsd_visited_add(struct leptris_xsd_schema* s,
|
|
764
|
+
const char* path) {
|
|
765
|
+
if (s->visited_len == s->visited_cap) {
|
|
766
|
+
size_t nc = s->visited_cap ? s->visited_cap * 2 : 8;
|
|
767
|
+
char** nv = (char**)realloc(s->visited, nc * sizeof(*nv));
|
|
768
|
+
if (!nv) return; /* dedup degrades to the old behavior */
|
|
769
|
+
s->visited = nv;
|
|
770
|
+
s->visited_cap = nc;
|
|
771
|
+
}
|
|
772
|
+
char* dup = xsd_strdup(path);
|
|
773
|
+
if (!dup) return;
|
|
774
|
+
s->visited[s->visited_len++] = dup;
|
|
775
|
+
}
|
|
776
|
+
|
|
691
777
|
static void xsd_capture_root(struct leptris_xsd_schema* s,
|
|
692
778
|
LeptrisElement root) {
|
|
693
779
|
for (LeptrisNodeRef n =
|
|
@@ -712,6 +798,13 @@ static void xsd_capture_root(struct leptris_xsd_schema* s,
|
|
|
712
798
|
char path[4096];
|
|
713
799
|
snprintf(path, sizeof(path), "%s/%s", s->base_dir,
|
|
714
800
|
loc);
|
|
801
|
+
/* leptris#1644: capture each schema unit once per
|
|
802
|
+
* compile — mark before recursing so cycles close
|
|
803
|
+
* (w.xsd includes a1.xsd includes w.xsd). */
|
|
804
|
+
char canon[4096];
|
|
805
|
+
xsd_path_normalize(path, canon, sizeof(canon));
|
|
806
|
+
if (xsd_visited_has(s, canon)) continue;
|
|
807
|
+
xsd_visited_add(s, canon);
|
|
715
808
|
size_t flen = 0;
|
|
716
809
|
char* text = xsd_read_file(path, &flen);
|
|
717
810
|
if (text) {
|
|
@@ -1000,6 +1093,8 @@ LEPTRIS_API void leptris_xsd_free(LeptrisXsdSchema schema) {
|
|
|
1000
1093
|
g = gn;
|
|
1001
1094
|
}
|
|
1002
1095
|
if (s->default_open) xsd_cm_free(s->default_open);
|
|
1096
|
+
for (size_t i = 0; i < s->visited_len; i++) free(s->visited[i]);
|
|
1097
|
+
free(s->visited);
|
|
1003
1098
|
free(s->target_ns);
|
|
1004
1099
|
free(s->base_dir);
|
|
1005
1100
|
if (s->validator)
|
|
@@ -375,7 +375,8 @@ int xsd_builtin_valid(const char* type, const char* v) {
|
|
|
375
375
|
|
|
376
376
|
/* ---- facet checking on a captured simpleType --------------------- */
|
|
377
377
|
|
|
378
|
-
int xsd_simple_valid(const XsdSimple* simple, const char* v
|
|
378
|
+
int xsd_simple_valid(const XsdSimple* simple, const char* v,
|
|
379
|
+
const char* terminal_base);
|
|
379
380
|
|
|
380
381
|
/* The base chain resolves to a built-in reference: validate the
|
|
381
382
|
* lexical against it first. */
|
|
@@ -385,7 +386,8 @@ static int base_valid(const char* base, const char* v) {
|
|
|
385
386
|
return -1; /* local base — the resolver walks the chain */
|
|
386
387
|
}
|
|
387
388
|
|
|
388
|
-
static int facet_check(const XsdSimple* s, const char* v
|
|
389
|
+
static int facet_check(const XsdSimple* s, const char* v,
|
|
390
|
+
const char* terminal_base) {
|
|
389
391
|
if (s->pattern && !rng_regex_matches(s->pattern, v)) return 0;
|
|
390
392
|
if (s->enum_values) {
|
|
391
393
|
int found = 0;
|
|
@@ -393,8 +395,27 @@ static int facet_check(const XsdSimple* s, const char* v) {
|
|
|
393
395
|
if (strcmp(e->text, v) == 0) { found = 1; break; }
|
|
394
396
|
if (!found) return 0;
|
|
395
397
|
}
|
|
396
|
-
/* Length family: character count (string-family semantics)
|
|
398
|
+
/* Length family: character count (string-family semantics) —
|
|
399
|
+
* except the binary types, where XML Schema Part 2 counts
|
|
400
|
+
* OCTETS (the wml ST_LongHexNumber shape: hexBinary + length 4
|
|
401
|
+
* accepts 8 hex digits; leptris-ruby#434). */
|
|
397
402
|
size_t n = strlen(v);
|
|
403
|
+
if (terminal_base && (strcmp(terminal_base, "xs:hexBinary") == 0 ||
|
|
404
|
+
strcmp(terminal_base, "xs:base64Binary") == 0)) {
|
|
405
|
+
if (strcmp(terminal_base, "xs:hexBinary") == 0) {
|
|
406
|
+
n = n / 2;
|
|
407
|
+
} else {
|
|
408
|
+
size_t pads = 0;
|
|
409
|
+
while (n > 0 && v[n - 1] == '=') {
|
|
410
|
+
pads++;
|
|
411
|
+
n--;
|
|
412
|
+
}
|
|
413
|
+
size_t octets = (n / 4) * 3;
|
|
414
|
+
if (n % 4 == 2) octets += 1;
|
|
415
|
+
else if (n % 4 == 3) octets += 2;
|
|
416
|
+
n = octets;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
398
419
|
if (s->length >= 0 && (long)n != s->length) return 0;
|
|
399
420
|
if (s->min_length >= 0 && (long)n < s->min_length) return 0;
|
|
400
421
|
if (s->max_length >= 0 && (long)n > s->max_length) return 0;
|
|
@@ -429,13 +450,14 @@ static int facet_check(const XsdSimple* s, const char* v) {
|
|
|
429
450
|
return 1;
|
|
430
451
|
}
|
|
431
452
|
|
|
432
|
-
int xsd_simple_valid(const XsdSimple* simple, const char* v
|
|
453
|
+
int xsd_simple_valid(const XsdSimple* simple, const char* v,
|
|
454
|
+
const char* terminal_base) {
|
|
433
455
|
if (!simple || !v) return 0;
|
|
434
456
|
int base = base_valid(simple->base, v);
|
|
435
457
|
if (base == 0) return 0;
|
|
436
458
|
/* base == -1 (local base) delegates to the resolver's chain in
|
|
437
459
|
* the caller; facets still apply here. */
|
|
438
|
-
return facet_check(simple, v);
|
|
460
|
+
return facet_check(simple, v, terminal_base);
|
|
439
461
|
}
|
|
440
462
|
|
|
441
463
|
/* Pattern/enumeration defaults for whitespace — slice 3 grows the
|