Mercurial > prosody-modules
comparison mod_delegation/mod_delegation.lua @ 4709:679f1834dbdb
mod_delegation: update to XEP-0355 v0.5
- namespace bump to "urn:xmpp:delegation:2"
- disco remaining infos now uses the XEP defined "urn:xmpp:delegation:2:bare:disco#info:*"
namespace
- complemeted disco remaining infos implementation for requests made on nodes not already
managed by the server
- bare JID disco items now uses the XEP defined
"urn:xmpp:delegation:2:bare:disco#items:*'" namespace
| author | Goffi <goffi@goffi.org> |
|---|---|
| date | Fri, 15 Oct 2021 15:10:36 +0200 |
| parents | 377546ab50f9 |
| children | 7d6ae8bb95dc |
comparison
equal
deleted
inserted
replaced
| 4708:25fd5e268f90 | 4709:679f1834dbdb |
|---|---|
| 28 -- other hosts | 28 -- other hosts |
| 29 delegation_session.connected_cb = set.new() | 29 delegation_session.connected_cb = set.new() |
| 30 end | 30 end |
| 31 local connected_cb = delegation_session.connected_cb | 31 local connected_cb = delegation_session.connected_cb |
| 32 | 32 |
| 33 local _DELEGATION_NS = 'urn:xmpp:delegation:1' | 33 local _DELEGATION_NS = 'urn:xmpp:delegation:2' |
| 34 local _FORWARDED_NS = 'urn:xmpp:forward:0' | 34 local _FORWARDED_NS = 'urn:xmpp:forward:0' |
| 35 local _DISCO_INFO_NS = 'http://jabber.org/protocol/disco#info' | 35 local _DISCO_INFO_NS = 'http://jabber.org/protocol/disco#info' |
| 36 local _DISCO_ITEMS_NS = 'http://jabber.org/protocol/disco#items' | 36 local _DISCO_ITEMS_NS = 'http://jabber.org/protocol/disco#items' |
| 37 local _DATA_NS = 'jabber:x:data' | 37 local _DATA_NS = 'jabber:x:data' |
| 38 | 38 |
| 39 local _MAIN_SEP = '::' | 39 local _MAIN_SEP = '::' |
| 40 local _BARE_SEP = ':bare:' | 40 local _BARE_SEP = ':bare:' |
| 41 local _REMAINING = ':*' | 41 local _REMAINING = ':*' |
| 42 local _MAIN_PREFIX = _DELEGATION_NS.._MAIN_SEP | 42 local _MAIN_PREFIX = _DELEGATION_NS.._MAIN_SEP |
| 43 local _BARE_PREFIX = _DELEGATION_NS.._BARE_SEP | 43 local _BARE_PREFIX = _DELEGATION_NS.._BARE_SEP |
| 44 local _DISCO_REMAINING = _DISCO_ITEMS_NS.._REMAINING | 44 local _DISCO_REMAINING = _BARE_PREFIX.."disco#info".._REMAINING |
| 45 local _DISCO_ITEMS_REMAINING = _BARE_PREFIX.."disco#items".._REMAINING | |
| 45 local _PREFIXES = {_MAIN_PREFIX, _BARE_PREFIX} | 46 local _PREFIXES = {_MAIN_PREFIX, _BARE_PREFIX} |
| 46 | 47 |
| 47 local disco_nest | 48 local disco_nest |
| 48 | 49 |
| 49 module:log("debug", "Loading namespace delegation module ") | 50 module:log("debug", "Loading namespace delegation module ") |
| 103 -- if the namespace has already a connected entity, ignore the new one | 104 -- if the namespace has already a connected entity, ignore the new one |
| 104 local function set_config(jid_) | 105 local function set_config(jid_) |
| 105 for namespace, ns_data in pairs(jid2ns[jid_]) do | 106 for namespace, ns_data in pairs(jid2ns[jid_]) do |
| 106 if ns_data.connected == nil then | 107 if ns_data.connected == nil then |
| 107 ns_data.connected = entity_jid | 108 ns_data.connected = entity_jid |
| 108 -- disco remaining is a special namespace | 109 -- disco remaining and disco items remaining are special namespaces |
| 109 -- there is no disco nesting for it | 110 -- there is no disco nesting for them |
| 110 if namespace ~= _DISCO_REMAINING then | 111 if namespace ~= _DISCO_ITEMS_REMAINING and namespace ~= _DISCO_REMAINING then |
| 111 disco_nest(namespace, entity_jid) | 112 disco_nest(namespace, entity_jid) |
| 112 end | 113 end |
| 113 end | 114 end |
| 114 end | 115 end |
| 115 end | 116 end |
| 216 -- because the namespace can be lacking in case of error | 217 -- because the namespace can be lacking in case of error |
| 217 local namespace = original.tags[1].attr.xmlns | 218 local namespace = original.tags[1].attr.xmlns |
| 218 | 219 |
| 219 -- small hack for disco remaining feat | 220 -- small hack for disco remaining feat |
| 220 if namespace == _DISCO_ITEMS_NS then | 221 if namespace == _DISCO_ITEMS_NS then |
| 222 namespace = _DISCO_ITEMS_REMAINING | |
| 223 elseif namespace == _DISCO_INFO_NS then | |
| 221 namespace = _DISCO_REMAINING | 224 namespace = _DISCO_REMAINING |
| 222 end | 225 end |
| 223 | 226 |
| 224 local ns_data = ns_delegations[namespace] | 227 local ns_data = ns_delegations[namespace] |
| 225 | 228 |
| 540 end | 543 end |
| 541 | 544 |
| 542 end | 545 end |
| 543 module:hook("account-disco-info", disco_hook, -2^32) | 546 module:hook("account-disco-info", disco_hook, -2^32) |
| 544 | 547 |
| 545 -- disco#items | 548 local function disco_node_hook(event) |
| 546 | 549 -- we reach this hook if a disco node on account has not been found |
| 547 local function disco_items_node_hook(event) | 550 -- we then forward the request to managing entity |
| 548 -- check if node is not handled by server | |
| 549 -- and forward the disco request to suitable entity | |
| 550 if not event.exists then | 551 if not event.exists then |
| 551 -- this node is not handled by the server | 552 -- this node is not handled by the server |
| 552 local ns_data = ns_delegations[_DISCO_REMAINING] | 553 local ns_data = ns_delegations[_DISCO_REMAINING] |
| 553 if ns_data ~= nil then | 554 if ns_data ~= nil then |
| 554 -- remaining delegation is requested, we forward | 555 -- remaining delegation is requested, we forward |
| 556 -- and stop normal event handling | 557 -- and stop normal event handling |
| 557 return true | 558 return true |
| 558 end | 559 end |
| 559 end | 560 end |
| 560 end | 561 end |
| 562 module:hook("account-disco-info-node", disco_node_hook, -2^32) | |
| 563 | |
| 564 -- disco#items | |
| 565 | |
| 566 local function disco_items_node_hook(event) | |
| 567 -- check if node is not handled by server | |
| 568 -- and forward the disco request to suitable entity | |
| 569 if not event.exists then | |
| 570 -- this node is not handled by the server | |
| 571 local ns_data = ns_delegations[_DISCO_ITEMS_REMAINING] | |
| 572 if ns_data ~= nil then | |
| 573 -- remaining delegation is requested, we forward | |
| 574 forward_iq(event.stanza, ns_data) | |
| 575 -- and stop normal event handling | |
| 576 return true | |
| 577 end | |
| 578 end | |
| 579 end | |
| 561 module:hook("account-disco-items-node", disco_items_node_hook, -2^32) | 580 module:hook("account-disco-items-node", disco_items_node_hook, -2^32) |
| 562 | 581 |
| 563 local function disco_items_hook(event) | 582 local function disco_items_hook(event) |
| 564 -- FIXME: we forward all bare-jid disco-items requests (without node) which will replace any Prosody reply | 583 -- FIXME: we forward all bare-jid disco-items requests (without node) which will replace any Prosody reply |
| 565 -- for now it's OK because Prosody is not returning anything on request on bare jid | 584 -- for now it's OK because Prosody is not returning anything on request on bare jid |
| 566 -- but to be properly done, any Prosody reply should be kept and managing entities items should be added (merged) to it. | 585 -- but to be properly done, any Prosody reply should be kept and managing entities items should be added (merged) to it. |
| 567 -- account-disco-items can't be cancelled (return value of hooks are not checked in mod_disco), so corountine needs | 586 -- account-disco-items can't be cancelled (return value of hooks are not checked in mod_disco), so coroutine needs |
| 568 -- to be used with util.async (to get the IQ result, merge items then return from the event) | 587 -- to be used with util.async (to get the IQ result, merge items then return from the event) |
| 569 local origin, stanza = event.origin, event.stanza; | 588 local origin, stanza = event.origin, event.stanza; |
| 570 local node = stanza.tags[1].attr.node; | 589 local node = stanza.tags[1].attr.node; |
| 571 local username = jid_split(stanza.attr.to) or origin.username; | 590 local username = jid_split(stanza.attr.to) or origin.username; |
| 572 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then | 591 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
| 573 if node == nil or node == "" then | 592 if node == nil or node == "" then |
| 574 local ns_data = ns_delegations[_DISCO_REMAINING] | 593 local ns_data = ns_delegations[_DISCO_ITEMS_REMAINING] |
| 575 if ns_data ~= nil then | 594 if ns_data ~= nil then |
| 576 forward_iq(event.stanza, ns_data) | 595 forward_iq(event.stanza, ns_data) |
| 577 return true | 596 return true |
| 578 end | 597 end |
| 579 end | 598 end |
| 586 -- notably when a disco-item is done by an unsubscibed entity | 605 -- notably when a disco-item is done by an unsubscibed entity |
| 587 -- (i.e. an entity doing a disco#item on an entity without having | 606 -- (i.e. an entity doing a disco#item on an entity without having |
| 588 -- presence subscription) | 607 -- presence subscription) |
| 589 -- we forward the request to managing entity | 608 -- we forward the request to managing entity |
| 590 -- it's the responsability of the managing entity to filter the items | 609 -- it's the responsability of the managing entity to filter the items |
| 591 local ns_data = ns_delegations[_DISCO_REMAINING] | 610 local ns_data = ns_delegations[_DISCO_ITEMS_REMAINING] |
| 592 if ns_data ~= nil then | 611 if ns_data ~= nil then |
| 593 forward_iq(event.stanza, ns_data) | 612 forward_iq(event.stanza, ns_data) |
| 594 return true | 613 return true |
| 595 end | 614 end |
| 596 end | 615 end |
