Mercurial > prosody-modules
annotate mod_export_skeletons/skeleton_filter.lua @ 5354:39d59d857bfb
mod_http_oauth2: Use new mod_cron API for periodic cleanup
Less frequent but this isn't that important after all since, as the
comment states, expired codes are not usable anyway. They're also not
that large so memory usage probably doesn't matter.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Apr 2023 11:59:52 +0200 |
parents | b4cc6ee9fc8c |
children |
rev | line source |
---|---|
4822
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
1 #!/usr/bin/env lua |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
2 |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
3 package.path = package.path:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
4 package.cpath = package.cpath:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"); |
4815
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 local t_insert = table.insert; |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local t_sort = table.sort; |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local jid = require "util.jid"; |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local st = require "util.stanza"; |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 |
4822
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
12 local xs = require "util.xmppstream"; |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
13 |
4815
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local function skeleton(s) |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 local o = st.stanza(s.name, { xmlns = s.attr.xmlns }); |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local children = {}; |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 for _, child in ipairs(s.tags) do t_insert(children, skeleton(child)) end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 t_sort(children, function(a, b) |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 if a.attr.xmlns == b.attr.xmlns then return a.name < b.name; end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 return (a.attr.xmlns or "") < (b.attr.xmlns or ""); |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end); |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 for _, child in ipairs(children) do o:add_direct_child(child); end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 return o; |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 local function classify_jid(s) |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 if not s then return "" end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 local u, h, r = jid.split(s); |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 if r then |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 return "full" |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 elseif u then |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 return "bare" |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 elseif h then |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 return "host" |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 else |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 return "invalid" |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 end |
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 |
4822
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
41 local stream_session = { notopen = true }; |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
42 local stream_callbacks = { stream_ns = "jabber:client"; default_ns = "jabber:client" }; |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
43 function stream_callbacks:handlestanza(item) |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
44 local clean = skeleton(item); |
4815
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 |
4822
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
46 -- Normalize top level attributes |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
47 clean.attr.type = item.attr.type; |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
48 if clean.attr.type == nil and clean.name == "message" then clean.attr.type = "normal"; end |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
49 clean.attr.id = string.rep("x", math.floor(math.log(1 + #(item.attr.id or ""), 2))); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
50 clean.attr.from = classify_jid(item.attr.from); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
51 clean.attr.to = classify_jid(item.attr.to); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
52 print(clean); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
53 end |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
54 local stream = xs.new(stream_session, stream_callbacks); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
55 assert(stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag())); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
56 stream_session.notopen = nil; |
4815
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 |
4822
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
58 local data = io.read(4096); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
59 while data do |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
60 stream:feed(data); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
61 data = io.read(4096); |
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
62 end |
4815
9c2af2146ee2
mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 |
4822
b4cc6ee9fc8c
mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents:
4821
diff
changeset
|
64 assert(stream:feed("</stream>")); |