mod_export_skeletons/skeleton_filter.lua
author Matthew Wild <mwild1@gmail.com>
Fri, 23 Sep 2022 22:41:15 +0100
changeset 5058 62480053c87b
parent 4826 b4cc6ee9fc8c
permissions -rw-r--r--
mod_cloud_notify_encrypted: Additional debug logging when enabling/skipping
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4826
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
     1
#!/usr/bin/env lua
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
     2
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
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: 4825
diff changeset
     4
package.cpath = package.cpath:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2");
4819
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
4826
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    12
local xs = require "util.xmppstream";
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    13
4819
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
4826
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    41
local stream_session = { notopen = true };
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
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: 4825
diff changeset
    43
function stream_callbacks:handlestanza(item)
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    44
	local clean = skeleton(item);
4819
9c2af2146ee2 mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    45
4826
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    46
	-- Normalize top level attributes
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    47
	clean.attr.type = item.attr.type;
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
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: 4825
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: 4825
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: 4825
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: 4825
diff changeset
    52
	print(clean);
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    53
end
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
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: 4825
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: 4825
diff changeset
    56
stream_session.notopen = nil;
4819
9c2af2146ee2 mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    57
4826
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    58
local data = io.read(4096);
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    59
while data do
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    60
	stream:feed(data);
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    61
	data = io.read(4096);
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    62
end
4819
9c2af2146ee2 mod_export_skeletons: Command to aid in analysis of archive contents
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    63
4826
b4cc6ee9fc8c mod_export_skeletons: Add a standalone filter script
Kim Alvefur <zash@zash.se>
parents: 4825
diff changeset
    64
assert(stream:feed("</stream>"));