0
votes

I wrote an external component for Ejabberd, but when trying to send presence stanzas on behalf of a user i get a 400 error.

The component's name is bot.domain.com and the host name in Ejabberd is domain.com and I have set the "check_from" flag to false for my component.

Below is an example of a presence stanza I am trying to send from the component on behalf of a user:

<presence from="[email protected]">
    <status>Test status</status>
    <show>dnd</show>
</presence>

And this is the error message that is returned by Ejabberd:

<presence type="error" to="[email protected]">
    <status>Test status</status>
    <show>dnd</show>
    <error code="400" type="modify">
         <bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
    </error>
</presence>

If I add to="[email protected]" in the package I'm sending, the destination user actually receives the package.

If I add to="domain.com", I don't get the 400 error anymore, but the presence is not broadcast to anyone in the user's roster.

The actual problem seems to be that Ejabberd is not broadcasting the presence packet to everyone in the user's roster.

Any ideas what I might be missing or why I get the 400 error when not specifying the "to" field?

1

1 Answers

0
votes

You cannot broadcast roster presence on behalf of a user from a component. Component service does not load the user roster. Only the ejabberd_c2s is taking care of loading roster to broadcast presence. It also takes care of checking privacy list and many important features of XMPP.

As a side note, I do not know what you expect to do with that approach, but you can split presence from user session in XMPP. A user is online first because he has a session open on XMPP and only secondarily because he sent a presence. By faking presence sending from component for a users, you are not guaranteed that that user will have a session opened. In that case, the overall behaviour will certainly not the one you expect.