XMPP multi-user-chat get user list - xmpp

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…

Related

Deny messages from non-roster users in Openfire

How do I only allow contacts who are on my roster list to send me messages?
Is there any XEP responsible to do that? Or will I need to do this client-side?
Yes, OpenFire supports XEP-0016: Privacy Lists (see this question), which can be used to block stanzas according to various criteria.
You can't explicitly block stanzas for contacts not in your roster, but you can block by subscription status none, which can more or less accomplish the same goal. You could send something like this:
<iq from='romeo#example.net/orchard' type='set' id='msg3'>
<query xmlns='jabber:iq:privacy'>
<list name='message-sub-example'>
<item type='subscription'
value='none'
action='deny'
order='5'>
<message/>
</item>
</list>
</query>
</iq>
This creates a privacy list called message-sub-example, containing a rule to block any messages from contacts with subscription type none, including contacts not in the roster. For this list to take effect, you need to make it the active list:
<iq from='romeo#example.net/orchard' type='set' id='active1'>
<query xmlns='jabber:iq:privacy'>
<active name='message-sub-example'/>
</query>
</iq>

Chat process in XMPP Openfire server using Android application

I’m using Openfire XMPP server for a android chat application. I can connect and login to the server using my app.
Now I want to know how to send friend request and accept friend request in this chat application.
I can fetch all the user from server but I want to know the process of starting a chat.
Thanks in advance.
The processes are a bit more complex than it looks to add/accept friend requests you need to do some juggling with presence and and roster iq stanzas.
I'll try to give you an indication about what stanzas are sent/received using contacts operations below.
1. Add contact
To add a contact you need to send a `subscribe` stanza.
<presence xmlns="jabber:client" to="you#app.com/123" id="9VO8j-1" type="subscribe" from="me#app.com/1234" />
1.1. Request accepted
When adding a contact and the other app "accepts the request" you receive two stanzas:
1. <presence xmlns="jabber:client" from="you#app.com/123" id="9VO8j-1" type="subscribed" to="me#app.com/1234" />
2. <presence xmlns="jabber:client" from="you#app.com/123" id="9VO8j-2" type="subscribe" to="me#app.com/1234" />
3. <presence xmlns="jabber:client" from="me#app.com/1234" id="9VO8j-3" type="subscribed" to="you#app.com/123" />
1.2. Request Denied
When the request is denied you receive an "UNSUBSCRIBED" stanza.
Example: <presence xmlns="jabber:client" from="you#app.com/123" id="9VO8j-1" type="unsubscribed" to="me#app.com/1234" />
2. Accept contact request
1. <presence xmlns="jabber:client" from="me#app.com/1234" id="9VO8j-1" type="subscribed" to="you#app.com/123" />
2. <presence xmlns="jabber:client" from="me#app.com/1234" id="9VO8j-2" type="subscribe" to="you#app.com/123" />
3. Deny contact request
<presence xmlns="jabber:client" from="me#app.com/1234" id="9VO8j-1" type="unsubscribed" to="you#app.com/123" />
4. Remove contact
When you "Delete" a contact you should be in fact be "deleting" it locally in your app and from the roster.
This is done by sending two stanzas:
1. <presence xmlns="jabber:client" from="me#app.com/1234" id="9VO8j-3" type="unsubscribe" to="you#app.com/123"/>
2. <iq from='me#app.com/1234' id='ah382g67' to='you#app.com/123' type='set'>
<query xmlns='jabber:iq:roster' ver='ver34'>
<item jid='you#app.com/123' subscription='remove'/>
</query>
</iq>
Note: The use-cases described above do not include all the iq:roster stanzas associated to the presence stanzas. These are sent automatically by the server whenever a contact changes the subscription and ask types.
For a better understanding of how the these workflows work in details I suggest you read the latest RFC (implemented by your server). You can find it on the office site.
See section 3. Managing the roster.

Openfire XMPP MUC Creating Group Chat Room Error

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.

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>