4

By default, XMPP presence is published to all those who are subscribed to that person. Is it possible to send something like an iq call to get presence tag of an id whos not present in my roster?

sandeepzgk
  • 511
  • 2
  • 6
  • 16

4 Answers4

7

If all you want to know whether a XMPP entity is connected or not, you can use XMPP Ping (XEP-0199). Given below is an example of two xmpp users “user1” and “user2”. They are not on each others roaster list. I am using ejabberd and PSI for the below example.

  • “user2” pings “user1” (user1 is online)

IQ:

<iq from='user2@pdevdv3os18f.corp.intuit.net' 
to='user1@pdevdv3os18f.corp.intuit.net/BANL07R9AME9X' type='get' id='e2e1'>
<ping xmlns='urn:xmpp:ping'/>
</iq>

Response:

<iq from="user1@pdevdv3os18f.corp.intuit.net/BANL07R9AME9X" type="result" xml:lang="en" to="user2@pdevdv3os18f.corp.intuit.net/BANL07R9AME9X" id="e2e1" />

  • “user2” pings “user1”(user1 is offline. The response of ping results in type=error)

IQ:

<iq from='user2@pdevdv3os18f.corp.intuit.net' 
to='user1@pdevdv3os18f.corp.intuit.net/BANL07R9AME9X' type='get' id='e2e1'>
<ping xmlns='urn:xmpp:ping'/>
</iq>

Response:

<iq from="user1@pdevdv3os18f.corp.intuit.net/BANL07R9AME9X" type="error" xml:lang="en"     to="user2@pdevdv3os18f.corp.intuit.net/BANL07R9AME9X" id="e2e1" >
<ping xmlns="urn:xmpp:ping"/>
<error type="cancel" code="503" >
<service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
CPJoshi
  • 387
  • 4
  • 11
  • It is worth noting that this works only if you have the resource of user2 as well, which in some cases isn't known. – Sumit Jain Feb 29 '16 at 07:43
4

I don't think so. Have a look at the rfc, section 5.1.3. Specifically, it says:

Upon receiving a presence probe from the user, the contact's server
SHOULD reply as follows:

If the user is not in the contact's roster with a subscription state of "From", "From + Pending Out", or "Both" (as defined under Subscription States (Section 9)), the contact's server MUST return a presence stanza of type "error" in response to the presence probe.

You will probably get an error or forbidden in a response.

Maggie
  • 7,823
  • 7
  • 45
  • 66
1

The rfc says that you are not allowed to receive presence from an id that is not on your roster list.

But I believe that it is possible to query presence by modifying the server (if there is an xmpp server that allows that)

Chris
  • 33
  • 1
  • 1
  • 6
0

No.

  • Presence is subscribed to, not queried. By the time you got the answer to your query, the information would be stale.
  • Presence is personal information. You must be explicitly authorized to see it by the contact.
Joe Hildebrand
  • 10,354
  • 2
  • 38
  • 48