Software /
code /
prosody
Annotate
tools/dnsregistry.lua @ 12480:7e9ebdc75ce4
net: isolate LuaSec-specifics
For this, various accessor functions are now provided directly on the
sockets, which reach down into the LuaSec implementation to obtain the
information.
While this may seem of little gain at first, it hides the implementation
detail of the LuaSec+LuaSocket combination that the actual socket and
the TLS layer are separate objects.
The net gain here is that an alternative implementation does not have to
emulate that specific implementation detail and "only" has to expose
LuaSec-compatible data structures on the new functions.
author | Jonas Schäfer <jonas@wielicki.name> |
---|---|
date | Wed, 27 Apr 2022 17:44:14 +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("};"); |