Openfire XMPP MUC Creating Group Chat Room Error - xmpp

After connecting to the openfire server with user 'username#localhost'
I am trying to create a group chat instant room, so first
I send the Presence Stanza as specified here :
<presence from='username#localhost' to='testroom#conference.localhost' xmlns='jabber:client'>
<x xmlns='http://jabber.org/protocol/muc'></x>
</presence>
But the response is always an error:
<presence ... from='testroom#conference.localhost type='error'>
<x xmlns='http://jabber.org/protocol/muc></x>
<error code='400' type='modify'>
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanza"></bad-request>
</error>
</presence>
Are there any configurations I have to do to Openfire to get this to work? I know you can create a Group Chat Room with the Openfire Gui, and that works fine, yet when I try to join that Chat Room I get the same exact error.

You need to specify your desired nickname in the room. This is the resource of the JID you send to.
For example, to join the room as 'Joe', send your presence stanza to testroom#conference.localhost/Joe instead of just testroom#conference.localhost.
Your join stanza also should not include a 'from' attribute, this is added for you by the server. Including one doesn't break anything, but it is pointless (and yours is wrong anyway, it must be a full JID).
Therefore a correct stanza for joining the room as 'Joe':
<presence to='testroom#conference.localhost/Joe' xmlns='jabber:client'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
See XEP-0045: Entering a room for more information.

Related

Missing metadata in friend request for offline users

We are trying to customize the friend request in XMPP (Ejabberd) so that we can send additional metadata in friend request as shown below(shows the request as logged in ejabberd.log file). The issue is when the friend is offline, XMPP does not send the additional metadata (jidValue, profileImageURL etc.) when the friend request is eventually delivered to end user when they come online. But if the friend is online, when the request is sent, all the additional metadata is indeed delivered. Does anybody know why for offline users, the additional metadata is not sent and how it can possibly be resolved?
Here is the log file content:
2015-12-06 18:07:35.127 [debug]
<0.1763.0>#ejabberd_receiver:process_data:349 Received XML on stream =
<<"https://jabber.chatter.io/profiles/chatapp_profile56646b3323232.232323232.png\"
age=\"0\" gender=\"\" message=\"\">">>
packet
{xmlel,<<"presence">>,[{<<"type">>,<<"subscribe">>},{<<"to">>,<<"17032345678jinglebells#chat.chatter.io">>},{<<"jidValue">>,<<"1408123467abcd#chat.chatter.io/MCRJ">>},{<<"profileImageURL">>,<<"https://jabber.chatter.io/profiles/chatapp_profile56646b3323232.232323232.png">>},{<<"age">>,<<"0">>},{<<"gender">>,<<>>},{<<"message">>,<<>>}],[{xmlel,<<"x">>,[{<<"xmlns">>,<<"vcard-temp:x:update">>}],[{xmlel,<<"photo">>,[],[]}]}]}
When the friend is not online the friend request is not stored as is: Presence are not store for offline delivery. Instead, ejabberd looks for pending request and generate a new one when the user connects.
I created a ticket to support the feature on ejabberd Github: https://github.com/processone/ejabberd/issues/870
Note that your packet is wrong, as you seem to put your extension on attribute for convenience. They should be on custom subtag, with custom xmlns. What you do is not valid anyway. Customization should look similar the the x xmlns vcard content.
The attribute you add are not expected by XMPP in the jabber:client namespace.
I had the following XML send from my iOS client code to the other user who was offline
<presence type="subscribe" to="918054824047thj#chat.domain.io">
<profile xmlns="custom:data">
<profileImageURL>https://jabber.domain.io/profiles/slocamo_profile5667ec5aea78e2.08175827.png</profileImageURL>
<age>0</age>
<gender/>
<message/>
<jidValue>918054824047jitu#chat.domain.io/jitu</jidValue>
</profile>
<x xmlns="vcard-temp:x:update"><photo/></x>
</presence>
but when the user come's online he only receives the following XML
<presence xmlns="jabber:client" from="918054824047thj#chat.domain.io" to="918054824047jitu#chat.domain.io" type="subscribe">
<status/>
</presence>
let me know how to fix this

How to join multiple rooms by just sending one <presence> message to ejabberd server

For example, I have 20 rooms to join. The simple solution is to send 20 message to each room id. Considering the performance, this is bad.
I want to join the 20 rooms by just sending one <presence> message, how to achieve this? Writing a module to hook the custom <presence> message? But I do not know how to write this kind of module.
In XEP-0045 Multi User Chat, there is no way defined to join 20 chat rooms with a single presence packet.
However, by combining other XMPP Extension with Multi User Chat, you can definitely achieve this in pure XMPP, without the need to write custom ejabberd extensions.
You can rely on XEP-0033 Extended Stanza Addressing, you can send an XMPP packet to several recipient. It also works with presence as shown in this example.
ejabberd configuration
XEP-0033 Extending Stanza Addressing is supported as default since ejabberd 15.04. Make sure you have enable the feature by adding mod_multicast in ejabberd configuration modules section:
modules:
...
mod_multicast: {}
When the service is enabled, you should have a new service (as default named multicast.example.net) on the server supporting the feature http://jabber.org/protocol/address:
<iq type='get'
to='multicast.example.net'
id='info1'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
and response is:
<iq from="multicast.example.net" type="result" to="test#example.net/laptop" id="info1">
<query xmlns="http://jabber.org/protocol/disco#info">
<identity category="service" type="multicast" name="Multicast"/>
<feature var="http://jabber.org/protocol/disco#info"/>
<feature var="http://jabber.org/protocol/disco#items"/>
<feature var="vcard-temp"/>
<feature var="http://jabber.org/protocol/address"/>
</query>
</iq>
Usage
Once enabled, it is easy to send a presence packet targeting several MUC rooms:
<presence to='multicast.example.net'>
<addresses xmlns='http://jabber.org/protocol/address'>
<address type='bcc' jid='testroom#conference.example.net/Usernick'/>
<address type='bcc' jid='testroom2# conference.example.net/Usernick'/>
</addresses>
</presence>
You will thus see that you are joining several rooms at the same time.
Issues
XEP-0033 did not specifically mention that use case and the module had not been testing to join multiple rooms. While writing this example I found that when disconnecting, user does not properly leave the rooms he had joined.
It means you have to wait for the following Github issue to be fixed before the feature is usable in production: Broadcast presence change after multicast presence packet.

I''ve been having problems with the subscription process using my client

Im using Jabber-Net API to make a GMail client. I've been having problems with the subscription process using my client as it always returning the "subscription=none" and "ask=none". When i subscribe a new user, it works fine but, subscribing/ unsubscribing users very frquently from roster makes the users stop to send subscription request with "to/ from/ both" or etc.
I have discovered that, "CONTACT" always receives a packet like this:
<iq type="set">
<query xmlns="jabber:iq:roster">
<item
jid="jabberuser#host"
subscription="none"
ask="none"/>
</query>
</iq>
Any prompt answer will be much appreciated..
Are you sending a presence subscription?
<presence type='subscribe' to='jabberuser#host'/>

strophe.js - messages are not delivered on chrome

I'm creating custom xmpp chat application with use of Strophe.js. The communication between browser and desktop client (Adium) works perfectly. I can send messages via browser to Adium and from Adium to the browser. There is yet the problem with browser-browser communication at some point as messages are sent but not delivered. It seems it's just Google Chrome problem.
What's interesting is the fact that <presence> stanzas are sent and delivered fine. We use ejabberd as the server daemon.
This is the presence stanza I'm sending from one account:
<presence type="away" xmlns="jabber:client">
<show>away</show>
<status/>
</presence>
and what I receive on the other:
<presence xmlns="jabber:client" from="test1#domain.com/3917283126133167196759537" to="test2#domain.com/1563391996133167110798391" type="away">
<show>away</show>
<status/>
</presence>
also the message stanza I send:
<message from="test1#domain.com/267172122813316722921543" to="test2#domain.com" type="chat" id="4915" xmlns="jabber:client">
<active xmlns="http://jabber.org/protocol/chatstates" />
<body>Testing...</body>
</message>
and nothing is received on Chrome...
EDIT:
The problem was with escaping some characters. Chrome did not let them unescaped due to security issues.
The type="away" in your initial presence is not valid. Omit the 'type' attribute for available presence. Set type="unavailable" when you are going offline.
Because your presence is invalid you are not marked as available, and you will not receive any messages addressed to your bare JID.
Update: To clear any confusion about what I mean by the above (see comments)...
The 'type' attribute on this stanza is invalid:
<presence type="away" xmlns="jabber:client">
<show>away</show>
<status/>
</presence>
It is otherwise fine. There are two types of presence a client may send, available and unavailable. Standard available presence has no 'type' attribute. Unavailable presence has type="unavailable". The actual status of the user (away, etc.) is signaled via the <show/> and <status/> elements, not the 'type' attribute.
To make it the above stanza a valid available presence, just remove type="away":
<presence xmlns="jabber:client">
<show>away</show>
<status/>
</presence>

XMPP multi-user-chat get user list

get a list of all users and the status of XMPP multi-user-chat
I do so
<iq from='hag66#shakespeare.lit/pda'
id='kl2fax27'
to='coven#chat.shakespeare.lit'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#items'/>
</iq>
getting a list but without status.
I need for all users on the statuses to know?
Please read XEP-0045, which describes the multi-user chat (MUC) protocol. You need to join the room:
<presence
from='hag66#shakespeare.lit/pda'
to='coven#chat.shakespeare.lit/thirdwitch'>
<x xmlns='http://jabber.org/protocol/muc'/>
</presence>
You'll then get a presence stanza from each occupant of the room with their current status:
<presence
from='coven#chat.shakespeare.lit/firstwitch'
to='hag66#shakespeare.lit/pda'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='owner' role='moderator'/>
</x>
</presence>
<presence
from='coven#chat.shakespeare.lit/secondwitch'
to='hag66#shakespeare.lit/pda'>
<x xmlns='http://jabber.org/protocol/muc#user'>
<item affiliation='admin' role='moderator'/>
</x>
</presence>
And before you ask, no, there is no way to tell when you're "done" receiving these notifications, since users may come and go at any time. You are now subscribed to the presence changes of the occupants, and have to keep track of what is current on the receiving side.
Reading through the XMPP RFC, I see that statuses are conveyed by presence messages, and that you ask another entity to report its status now (rather than waiting for it to tell you in a broadcast) by sending a probe status request to which you'll get a directed response (§5.5 of the RFC gives some examples). It's up to you to interpret what they say back correctly, of course…