Search code examples
ejabberdejabberd-module

ejabberd - Restrict of sending message to all resources if destination resource is not available


I have the following situation. We are using one JID to connect to the ejabberd, but with different resources to diffirentiate users. If for some reason message is sent to the resource that is not available/exist at the moment then this message is sent to all resources within JID.

We tried to find an information over the documentation and with chatbots if there is any possibility to solve it with settings, but it seems that there is no such possibility. We also tried to create custom module, but due to very limited knowledge of the language we failed with this as well.

Maybe someone had similar problem and know the solution or can share module for dealing with this?


Solution

  • What you describe is the behavior defined in the XMPP protocol. You should try, as much as possible, to follow the protocol without requiring custom changes: that way your system will work with any XMPP server, and with any version of the server.

    More concretely, the protocol text relevant for your problem is:

    https://xmpp.org/rfcs/rfc6121.html#rules-localpart-fulljid-nomatch

    You send a message stanza of type "chat" indicating as destination the full JID localpart@domainpart/resourcepart, but there isn't any session on that resourcepart .

    Section 8.5.3.2.1. Message says:

    If there is one available resource with a non-negative presence priority then the server MUST deliver the message to that resource.

    If there is more than one resource with a non-negative presence priority then the server MUST either (a) deliver the message to the "most available" resource or resources (according to the server's implementation-specific algorithm, e.g., treating the resource or resources with the highest presence priority as "most available") or (b) deliver the message to all of the non-negative resources that have opted in to receive chat messages.

    If you don't want that message to be delivered to other sessions, the clients should login with negative priority. That tip is explained in the text:

    If all of the available resources have a negative presence priority then the server SHOULD (a) store the message offline for later delivery or (b) return a stanza error to the sender, which SHOULD be .

    How to set presence priority? Most XMPP clients support setting that value, if you use some XMPP library to write your client, it should also support setting priority. If you can sniff the network traffic, check here how the initial presence stanza should look:

    https://xmpp.org/rfcs/rfc6121.html#presence-syntax-children-priority