Mercurial > prosody-modules
comparison mod_rest/mod_rest.lua @ 4923:c83b009b5bc5
mod_rest: Add configuration of which stanzas to route to callback
Makes it simpler to build APIs that only handle a certain kind of
stanzas, letting them be handled by the unhandled stanza handler instead
of having to write code to ignore certain kinds of stanzas.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 09 Apr 2022 01:04:25 +0200 |
parents | 816b23e09c20 |
children | e7b9bc629ecc |
comparison
equal
deleted
inserted
replaced
4922:816b23e09c20 | 4923:c83b009b5bc5 |
---|---|
551 end); | 551 end); |
552 | 552 |
553 return true; | 553 return true; |
554 end | 554 end |
555 | 555 |
556 if module:get_host_type() == "component" then | 556 local send_kinds = module:get_option_set("rest_callback_stanzas", { "message", "presence", "iq" }); |
557 module:hook("iq/bare", handle_stanza, -1); | 557 |
558 module:hook("message/bare", handle_stanza, -1); | 558 local event_presets = { |
559 module:hook("presence/bare", handle_stanza, -1); | 559 -- Don't override everything on normal VirtualHosts by default |
560 module:hook("iq/full", handle_stanza, -1); | 560 ["local"] = { "host" }, |
561 module:hook("message/full", handle_stanza, -1); | 561 -- Comonents get to handle all kinds of stanzas |
562 module:hook("presence/full", handle_stanza, -1); | 562 ["component"] = { "bare", "full", "host" }, |
563 module:hook("iq/host", handle_stanza, -1); | 563 }; |
564 module:hook("message/host", handle_stanza, -1); | 564 local hook_events = module:get_option_set("rest_callback_events", event_presets[module:get_host_type()]); |
565 module:hook("presence/host", handle_stanza, -1); | 565 for kind in send_kinds do |
566 else | 566 for event in hook_events do |
567 -- Don't override everything on normal VirtualHosts | 567 module:hook(kind.."/"..event, handle_stanza, -1); |
568 module:hook("iq/host", handle_stanza, -1); | 568 end |
569 module:hook("message/host", handle_stanza, -1); | |
570 module:hook("presence/host", handle_stanza, -1); | |
571 end | 569 end |
572 end | 570 end |
573 | 571 |
574 local supported_errors = { | 572 local supported_errors = { |
575 "text/html", | 573 "text/html", |