aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2020-10-04 19:26:53 +0200
committerKim Alvefur <zash@zash.se>2020-10-04 19:26:53 +0200
commit8b68fc3c6c5e02afa8aebecadacba11b78ad5a75 (patch)
tree225e9aeb7a8564f63d6cc248d387ee51dc59e722 /tools
parentd98c136bb94210ae9074287eb0bdcbea6b956b35 (diff)
downloadprosody-8b68fc3c6c5e02afa8aebecadacba11b78ad5a75.tar.gz
prosody-8b68fc3c6c5e02afa8aebecadacba11b78ad5a75.zip
tools.dnsregistry: For converting IANA DNS registry data to Lua table
Diffstat (limited to 'tools')
-rw-r--r--tools/dnsregistry.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/dnsregistry.lua b/tools/dnsregistry.lua
new file mode 100644
index 00000000..018eadb2
--- /dev/null
+++ b/tools/dnsregistry.lua
@@ -0,0 +1,43 @@
+-- Generate util/dnsregistry.lua from IANA HTTP status code registry
+local xml = require "util.xml";
+local registries = xml.parse(io.read("*a"));
+
+print("-- Source: https://www.iana.org/assignments/dns-parameters/dns-parameters.xml");
+print(os.date("-- Generated on %Y-%m-%d"))
+
+local registry_mapping = {
+ ["dns-parameters-2"] = "classes";
+ ["dns-parameters-4"] = "types";
+ ["dns-parameters-6"] = "errors";
+};
+
+print("return {");
+for registry in registries:childtags("registry") do
+ local registry_name = registry_mapping[registry.attr.id];
+ if registry_name then
+ print("\t" .. registry_name .. " = {");
+ for record in registry:childtags("record") do
+ local record_name = record:get_child_text("name");
+ local record_type = record:get_child_text("type");
+ local record_desc = record:get_child_text("description");
+ local record_code = tonumber(record:get_child_text("value"));
+
+ if tostring(record):lower():match("reserved") or tostring(record):lower():match("reserved") then
+ record_code = nil;
+ end
+
+ if registry_name == "classes" and record_code then
+ record_type = record_desc and record_desc:match("%((%w+)%)$")
+ if record_type then
+ print(("\t\t[%q] = %d; [%d] = %q;"):format(record_type, record_code, record_code, record_type))
+ end
+ elseif registry_name == "types" and record_type and record_code then
+ print(("\t\t[%q] = %d; [%d] = %q;"):format(record_type, record_code, record_code, record_type))
+ elseif registry_name == "errors" and record_code and record_name then
+ print(("\t\t[%d] = %q; [%q] = %q;"):format(record_code, record_name, record_name, record_desc or record_name));
+ end
+ end
+ print("\t};");
+ end
+end
+print("};");