core.stanza_router
The stanza router handles basic routing of stanzas to the correct host and fires events that are then handled by modules. It also handles sending error replies for unhandled stanzas.
Description
When Prosody receives a stanza from a connected client or remote
server, called an “origin”, it enters the routing process via
prosody.core_process_stanza()
, where some authorization and
sanity checks are performed. If the origin session is not authorized to
send stanzas yet, i.e. because it has not authenticated or bound a
resource, it is rejected here.
Processing then passes to prosody.core_post_stanza()
,
where events are fired to dispatch the stanza to handling by interested
modules. If modules generate a reply of some sort, that often gets sent
directly to the origin session, bypassing most routing logic.
Stanzas created by Prosody itself, i.e. in modules, enter routing
trough prosody.core_post_stanza()
. Modules should use the
module:send()
API which in turn calls
core_post_stanza
behind the scenes.
API
TL;DR:
-- Stanza received from e.g. a connected client
.core_process_stanza(origin, stanza);
prosody
-- Fire events for stanza received from a client
.core_post_stanza(origin, stanza, true);
prosody
-- Send a stanza out from Prosody
.core_post_stanza(origin, stanza, false);
prosody
-- Similar to the above
.core_route_stanza(origin, stanza); prosody