plugins/mod_csi.lua
author Kim Alvefur <zash@zash.se>
Sat, 23 Mar 2024 20:48:19 +0100
changeset 13465 c673ff1075bd
parent 13079 82980f6890cd
permissions -rw-r--r--
mod_posix: Move everything to util.startup This allows greater control over the order of events. Notably, the internal ordering between daemonization, initialization of libunbound and setup of signal handling is sensitive. libunbound starts a separate thread for processing DNS requests. If this thread is started before signal handling has been set up, it will not inherit the signal handlers and instead behave as it would have before signal handlers were set up, i.e. cause the whole process to immediately exit. libunbound is usually initialized on the first DNS request, usually triggered by an outgoing s2s connection attempt. If daemonization happens before signals have been set up, signals may not be processed at all.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12981
74b9e05af71e plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 10433
diff changeset
     1
local st = require "prosody.util.stanza";
9076
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     2
local xmlns_csi = "urn:xmpp:csi:0";
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     3
local csi_feature = st.stanza("csi", { xmlns = xmlns_csi });
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     4
13029
b7d0c1d75a37 mod_csi: Add metrics, covering changes and totals
Kim Alvefur <zash@zash.se>
parents: 12981
diff changeset
     5
local change = module:metric("counter", "changes", "events", "CSI state changes", {"csi_state"});
b7d0c1d75a37 mod_csi: Add metrics, covering changes and totals
Kim Alvefur <zash@zash.se>
parents: 12981
diff changeset
     6
9076
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     7
module:hook("stream-features", function (event)
13079
82980f6890cd mod_csi: Always advertise feature
Kim Alvefur <zash@zash.se>
parents: 13074
diff changeset
     8
	if event.origin.username then
9076
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
     9
		event.features:add_child(csi_feature);
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
	end
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
end);
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    13
function refire_event(name)
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    14
	return function (event)
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
		if event.origin.username then
9657
91856829f18b mod_csi: Fix copypaste mistake [luacheck]
Kim Alvefur <zash@zash.se>
parents: 9655
diff changeset
    16
			event.origin.state = event.stanza.name;
13029
b7d0c1d75a37 mod_csi: Add metrics, covering changes and totals
Kim Alvefur <zash@zash.se>
parents: 12981
diff changeset
    17
			change:with_labels(event.stanza.name):add(1);
9076
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
			module:fire_event(name, event);
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
			return true;
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
		end
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
	end;
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
end
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    23
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
module:hook("stanza/"..xmlns_csi..":active", refire_event("csi-client-active"));
a5daf3f6d588 mod_csi: Imported from prosody-modules 66b3085ecc49
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
module:hook("stanza/"..xmlns_csi..":inactive", refire_event("csi-client-inactive"));