Software /
code /
prosody
Annotate
tools/dnsregistry.lua @ 12579:ca6a43fe0231 0.12
util.jsonschema: Fix validation to not assume presence of "type" field
MattJ reported a curious issue where validation did not work as
expected. Primarily that the "type" field was expected to be mandatory,
and thus leaving it out would result in no checks being performed.
This was likely caused by misreading during initial development.
Spent some time testing against
https://github.com/json-schema-org/JSON-Schema-Test-Suite.git and
discovered a multitude of issues, far too many to bother splitting into
separate commits.
More than half of them fail. Many because of features not implemented,
which have been marked NYI. For example, some require deep comparisons
e.g. when objects or arrays are present in enums fields.
Some because of quirks with how Lua differs from JavaScript, e.g. no
distinct array or object types. Tests involving fractional floating
point numbers. We're definitely not going to follow references to remote
resources. Or deal with UTF-16 sillyness. One test asserted that 1.0 is
an integer, where Lua 5.3+ will disagree.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 08 Jul 2022 14:38:23 +0200 |
parent | 12271:f31bb79f51d7 |
child | 12855:3306807c0619 |
rev | line source |
---|---|
12237
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Generate util/dnsregistry.lua from IANA HTTP status code registry |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local xml = require "util.xml"; |
12271
f31bb79f51d7
tools: Allow processing instructions in some XML parsing tools
Kim Alvefur <zash@zash.se>
parents:
12237
diff
changeset
|
3 local registries = xml.parse(io.read("*a"), { allow_processing_instructions = true }); |
12237
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 print("-- Source: https://www.iana.org/assignments/dns-parameters/dns-parameters.xml"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 print(os.date("-- Generated on %Y-%m-%d")) |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local registry_mapping = { |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 ["dns-parameters-2"] = "classes"; |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 ["dns-parameters-4"] = "types"; |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 ["dns-parameters-6"] = "errors"; |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 }; |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 print("return {"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 for registry in registries:childtags("registry") do |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local registry_name = registry_mapping[registry.attr.id]; |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 if registry_name then |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 print("\t" .. registry_name .. " = {"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 for record in registry:childtags("record") do |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local record_name = record:get_child_text("name"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 local record_type = record:get_child_text("type"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 local record_desc = record:get_child_text("description"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local record_code = tonumber(record:get_child_text("value")); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 if tostring(record):lower():match("reserved") or tostring(record):lower():match("reserved") then |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 record_code = nil; |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 end |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 if registry_name == "classes" and record_code then |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 record_type = record_desc and record_desc:match("%((%w+)%)$") |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 if record_type then |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 print(("\t\t[%q] = %d; [%d] = %q;"):format(record_type, record_code, record_code, record_type)) |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 end |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 elseif registry_name == "types" and record_type and record_code then |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 print(("\t\t[%q] = %d; [%d] = %q;"):format(record_type, record_code, record_code, record_type)) |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 elseif registry_name == "errors" and record_code and record_name then |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 print(("\t\t[%d] = %q; [%q] = %q;"):format(record_code, record_name, record_name, record_desc or record_name)); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 end |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 print("\t};"); |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 end |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 end |
b35714c57442
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 print("};"); |