Software / code / prosody-modules
Comparison
mod_pubsub_subscription/mod_pubsub_subscription.lua @ 6114:dc2cce03554d
mod_pubsub_subscription: Match stanzas with fixed prefix only
This should help filter out any other unrelated iq stanzas which may be
exchanged with the pubsub service.
For example, a separate module was requesting the item list from a subscribed
node, but this module was incorrectly attempting to handle the result.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 28 Dec 2024 15:23:33 +0000 |
| parent | 5674:b40750891bee |
| child | 6119:6dca425eea15 |
comparison
equal
deleted
inserted
replaced
| 6113:c0cb43817b7c | 6114:dc2cce03554d |
|---|---|
| 1 local id = require "util.id"; | |
| 1 local st = require "util.stanza"; | 2 local st = require "util.stanza"; |
| 2 local uuid = require "util.uuid"; | 3 local uuid = require "util.uuid"; |
| 3 local mt = require "util.multitable"; | 4 local mt = require "util.multitable"; |
| 4 local cache = require "util.cache"; | 5 local cache = require "util.cache"; |
| 5 | 6 |
| 35 already_subscibed = true; | 36 already_subscibed = true; |
| 36 break | 37 break |
| 37 end | 38 end |
| 38 | 39 |
| 39 item._id = uuid.generate(); | 40 item._id = uuid.generate(); |
| 40 local iq_id = uuid.generate(); | 41 local iq_id = "pubsub-sub-"..id.short(); |
| 41 pending_subscription:set(iq_id, item._id); | 42 pending_subscription:set(iq_id, item._id); |
| 42 active_subscriptions:set(item.service, item.node, item.from, item._id, item); | 43 active_subscriptions:set(item.service, item.node, item.from, item._id, item); |
| 43 | 44 |
| 44 if not already_subscibed then | 45 if not already_subscibed then |
| 45 module:send(st.iq({ type = "set", id = iq_id, from = item.from, to = item.service }) | 46 module:send(st.iq({ type = "set", id = iq_id, from = item.from, to = item.service }) |
| 65 function handle_iq(context, event) | 66 function handle_iq(context, event) |
| 66 local stanza = event.stanza; | 67 local stanza = event.stanza; |
| 67 local service = stanza.attr.from; | 68 local service = stanza.attr.from; |
| 68 | 69 |
| 69 if not stanza.attr.id then return end -- shouldn't be possible | 70 if not stanza.attr.id then return end -- shouldn't be possible |
| 71 if not stanza.attr.id:match("^pubsub%-sub%-") then return end | |
| 70 | 72 |
| 71 local subscribed_node = pending_subscription:get(stanza.attr.id); | 73 local subscribed_node = pending_subscription:get(stanza.attr.id); |
| 72 pending_subscription:set(stanza.attr.id, nil); | 74 pending_subscription:set(stanza.attr.id, nil); |
| 73 local unsubscribed_node = pending_unsubscription:get(stanza.attr.id); | 75 local unsubscribed_node = pending_unsubscription:get(stanza.attr.id); |
| 74 pending_unsubscription:set(stanza.attr.id, nil); | 76 pending_unsubscription:set(stanza.attr.id, nil); |
| 116 local item = item_event.item; | 118 local item = item_event.item; |
| 117 active_subscriptions:set(item.service, item.node, item.from, item._id, nil); | 119 active_subscriptions:set(item.service, item.node, item.from, item._id, nil); |
| 118 local node_subs = active_subscriptions:get(item.service, item.node, item.from); | 120 local node_subs = active_subscriptions:get(item.service, item.node, item.from); |
| 119 if node_subs and next(node_subs) then return end | 121 if node_subs and next(node_subs) then return end |
| 120 | 122 |
| 121 local iq_id = uuid.generate(); | 123 local iq_id = "pubsub-sub-"..id.short(); |
| 122 pending_unsubscription:set(iq_id, item._id); | 124 pending_unsubscription:set(iq_id, item._id); |
| 123 | 125 |
| 124 module:send(st.iq({ type = "set", id = iq_id, from = item.from, to = item.service }) | 126 module:send(st.iq({ type = "set", id = iq_id, from = item.from, to = item.service }) |
| 125 :tag("pubsub", { xmlns = xmlns_pubsub }) | 127 :tag("pubsub", { xmlns = xmlns_pubsub }) |
| 126 :tag("unsubscribe", { jid = item.from, node = item.node })) | 128 :tag("unsubscribe", { jid = item.from, node = item.node })) |