[Home]

Summary:ASTERISK-23510: JABBER_STATUS fails with improper code 7 for unavailable clients
Reporter:Anthony Critelli (tony2012)Labels:
Date Opened:2014-03-20 23:24:10Date Closed:2017-03-24 12:26:19
Priority:MajorRegression?
Status:Closed/CompleteComponents:Resources/res_xmpp
Versions:11.8.1 Frequency of
Occurrence
Constant
Related
Issues:
Environment:CentOS 6.5/AsteriskNOW 32-bitAttachments:( 0) 0001-xmpp-Get-Jabber-status-for-bare-JID.patch
( 1) 0001-xmpp-Get-Jabber-status-for-bare-JID.patch
( 2) get-jabberstatus.diff
( 3) get-jabberstatus.diff
Description:According to JABBER_STATUS documentation, a call to this function should return a value of 6 when a user is unavailable. Instead, it is returning 7. There are two scenarios to consider, both described in detail below. Relevant documentation is here: https://wiki.asterisk.org/wiki/display/AST/Function_JABBER_STATUS?src=search

THe first scenario is when JABBER_STATUS is called using only the bare jid (username@domain). According to documentation, this should work. However, this always fails with a return of 7.

Asterisk clearly receives presence data (debug output from xmpp set debug on):

{noformat}
<--- XMPP received from 'ejabberd' --->
<presence from='tony2012@10.1.4.13/Desktop' to='asterisk@10.1.4.13/asterisk-xmpp'><show>away</show><c xmlns='http://jabber.org/protocol/caps' node='http://pidgin.im/' hash='sha-1' ver='I22W7CegORwdbnu0ZiQwGpxr0Go='/><x xmlns='vcard-temp:x:update'><photo/></x></presence>
<------------->
{noformat}

However, a call to JABBER_STATUS fails:

{noformat}
[Mar 21 00:08:21] NOTICE[24015][C-00000000]: res_xmpp.c:1631 acf_jabberstatus_read: Resource (null) of buddy tony2012@10.1.4.13 was not found.
   -- Executing [1004@HomeSets:2] Set("SIP/TonyRoom-00000000", "JSTATUS=7") in new stack
{noformat}

The user does appear in the buddy list:

{noformat}
localhost*CLI> xmpp show buddies
XMPP buddy lists
Client: ejabberd
       Buddy:  tony2012@10.1.4.13
               Resource: Desktop
                       node: http://pidgin.im/
                       version: I22W7CegORwdbnu0ZiQwGpxr0Go=
                       Google Talk capable: no
                       Jingle capable: yes
{noformat}


Additionally, sending a message via JabberSend works fine.

Relevant extensions.conf snippet (just a test extension 1004 to send a test message and check status):

{noformat}
       exten => 1004, 1, JabberSend(ejabberd,tony2012@10.1.4.13,Test)
               same => n, Set(JSTATUS=${JABBER_STATUS(ejabberd,tony2012@10.1.4.13)})
{noformat}

xmpp.conf:

{noformat}
[root@localhost asterisk]# cat xmpp.conf
[general]
       autoregister=yes
       autoprune=no

[ejabberd]
       type=client
       serverhost=10.1.4.13
       username=asterisk@10.1.4.13
       secret=**********
       priority=2
       port=5222
       usetls=no
       usesasl=yes
       status=available
       statusmessage="It's Asterisk!"
       timeout=5
{noformat}

The behavior observed above is consistent across all jabber client states (away, available, offline, etc.)


The second scenario arises when JABBER_STATUS is called with a full jid. This will work for all values except 6 (unavailable). When a client goes unavailable, a call to JABBER_STATUS will return 7.

Asterisk clearly receives presence data (debug output from xmpp set debug on):

{noformat}
<--- XMPP received from 'ejabberd' --->
<presence from='tony2012@10.1.4.13/Desktop' to='asterisk@10.1.4.13/asterisk-xmpp'><show>dnd</show><c xmlns='http://jabber.org/protocol/caps' node='http://pidgin.im/' hash='sha-1' ver='1RsmhQD7CXz0TuytinljsuOTrVU='/><x xmlns='vcard-temp:x:update'><photo/></x></presence>
<------------->
{noformat}

And a call to JABBER_STATUS works for values other than unavailable (shown below with DND, a correct value of 5 is reported):

{noformat}
   -- Executing [1004@HomeSets:2] Set("SIP/TonyRoom-00000000", "JSTATUS=5") in new stack
{noformat}


However, this will NOT work when the client goes unavailable, as articulated below.

Asterisk clearly receives presence data (debug output from xmpp set debug on):

{noformat}
<--- XMPP received from 'ejabberd' --->
<presence from='tony2012@10.1.4.13/Desktop' to='asterisk@10.1.4.13/asterisk-xmpp' type='unavailable'/>
<------------->
{noformat}

However, a call to JABBER_STATUS fails with code 7:

{noformat}
[Mar 21 00:18:03] NOTICE[24214][C-00000001]: res_xmpp.c:1631 acf_jabberstatus_read: Resource Desktop of buddy tony2012@10.1.4.13 was not found.
   -- Executing [1004@HomeSets:2] Set("SIP/TonyRoom-00000001", "JSTATUS=7") in new stack
{noformat}

XMPP show buddies output is far less interesting, presumably because there is no longer a resource:

{noformat}
localhost*CLI> xmpp show buddies
XMPP buddy lists
Client: ejabberd
       Buddy:  tony2012@10.1.4.13
{noformat}


Relevant extensions.conf snippet:

{noformat}
       exten => 1004, 1, JabberSend(ejabberd,tony2012@10.1.4.13,Test)
               same => n, Set(JSTATUS=${JABBER_STATUS(ejabberd,tony2012@10.1.4.13/Desktop)})
{noformat}

xmpp.conf contents are THE SAME as those from the previous scenario.


Based on these data, there are two questions:

1. Why does a call to JABBER_STATUS always fail when only the bare jid is used, even though documentation explicity states that a bare jid can be used?
2. Why does a call to JABBER_STATUS fail with code 7 when a client goes unavailable, even though Asterisk clearly receives the presence data.

This has been tested across two different clients, namely Pidgin on Windows and Adium on Mac. However, this would seem to not matter, since xmpp debug shows Asterisk receiving the proper presence notifications.

Asterisk version is 11.8.1 on CentOS 6.5, originally obtained as an AsteriskNOW distro.
Comments:By: Rusty Newton (rnewton) 2014-04-03 18:53:44.896-0500

These look like bugs to me, or at least, it should be investigated so that the documentation can be adjusted.

I don't have time to reproduce this one to further narrow things down at the moment, but Im going to go ahead and open it up.

It would be extremely helpful if you could produce a step by step guide showing how to reproduce both scenarios. I think anyone could figure it out from your detailed description above, but to save time and encourage a fix it would help if you could show how you configured ejabberd for this scenario. Thanks again for the report!

By: Daniel Díaz (mrchapp) 2015-07-09 17:25:02.304-0500

Patch get-jabberstatus.diff was tested against Asterisk 11.7.0~dfsg-1ubuntu1. A similar Git patch was derived from tag 11.7.0 (0001-xmpp-Get-Jabber-status-for-bare-JID.patch), though that one is untested.

While this seems to work, I can't vouch for the correctness of it.

By: Rusty Newton (rnewton) 2015-07-11 17:29:37.248-0500

[~mrchapp] your patch is not displaying on the issue since you don't have a valid license agreement on file. You'll need to complete a license agreement and wait for it to be processed by legal. We can't accept patches or keep patches on the tracker that are not submitted under a valid submission agreement.

Here is the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Friendly Automation (friendly-automation) 2017-03-24 12:26:21.251-0500

Change 5296 merged by zuul:
res_xmpp: Correct implementation of JABBER_STATUS & JabberStatus

[https://gerrit.asterisk.org/5296|https://gerrit.asterisk.org/5296]

By: Friendly Automation (friendly-automation) 2017-03-24 17:47:04.169-0500

Change 5286 merged by Joshua Colp:
res_xmpp: Correct implementation of JABBER_STATUS & JabberStatus

[https://gerrit.asterisk.org/5286|https://gerrit.asterisk.org/5286]

By: Friendly Automation (friendly-automation) 2017-03-24 17:47:40.724-0500

Change 5295 merged by Joshua Colp:
res_xmpp: Correct implementation of JABBER_STATUS & JabberStatus

[https://gerrit.asterisk.org/5295|https://gerrit.asterisk.org/5295]