Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying for presence in XMPP

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?

like image 847
sandeepzgk Avatar asked Dec 17 '22 10:12

sandeepzgk


2 Answers

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='[email protected]' 
to='[email protected]/BANL07R9AME9X' type='get' id='e2e1'>
<ping xmlns='urn:xmpp:ping'/>
</iq>

Response:

<iq from="[email protected]/BANL07R9AME9X" type="result" xml:lang="en" to="[email protected]/BANL07R9AME9X" id="e2e1" />

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

IQ:

<iq from='[email protected]' 
to='[email protected]/BANL07R9AME9X' type='get' id='e2e1'>
<ping xmlns='urn:xmpp:ping'/>
</iq>

Response:

<iq from="[email protected]/BANL07R9AME9X" type="error" xml:lang="en"     to="[email protected]/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>
like image 183
CPJoshi Avatar answered Jan 14 '23 12:01

CPJoshi


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.

like image 24
Maggie Avatar answered Jan 14 '23 11:01

Maggie