Software /
code /
prosody
Comparison
plugins/mod_csi_simple.lua @ 11401:228bd43fbc3d
mod_csi_simple: Add command to test importance algorithm on stream of stanzas
This won't include behavior provided by extra modules tho.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 23 Feb 2021 19:52:57 +0100 |
parent | 11380:9a1758c5aaa4 |
child | 11425:fc7706fe115d |
comparison
equal
deleted
inserted
replaced
11400:19a59cb7311e | 11401:228bd43fbc3d |
---|---|
216 disable_optimizations(session); | 216 disable_optimizations(session); |
217 end | 217 end |
218 end | 218 end |
219 end | 219 end |
220 end | 220 end |
221 | |
222 function module.command(arg) | |
223 if arg[1] ~= "test" then | |
224 print("Usage: "..module.name.." test < test-stream.xml") | |
225 print(""); | |
226 print("Provide a series of stanzas to test against importance algoritm"); | |
227 return 1; | |
228 end | |
229 -- luacheck: ignore 212/self | |
230 local xmppstream = require "util.xmppstream"; | |
231 local input_session = { notopen = true } | |
232 local stream_callbacks = { stream_ns = "jabber:client", default_ns = "jabber:client" }; | |
233 function stream_callbacks:handlestanza(stanza) | |
234 local important, because = is_important(stanza); | |
235 print("--"); | |
236 print(stanza:indent(nil, " ")); | |
237 -- :pretty_print() maybe? | |
238 if important then | |
239 print((because or "unspecified reason").. " -> important"); | |
240 else | |
241 print((because or "unspecified reason").. " -> unimportant"); | |
242 end | |
243 end | |
244 local input_stream = xmppstream.new(input_session, stream_callbacks); | |
245 input_stream:reset(); | |
246 input_stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag()); | |
247 input_session.notopen = nil; | |
248 | |
249 for line in io.lines() do | |
250 input_stream:feed(line); | |
251 end | |
252 end |