views:

165

answers:

2

One of the contacts of my jabber robot,

whose 'subscription' attribute value is 'to',

which according to jabber protocol mean:

**the robot has subscribed to the other party's online status, but the other party has not subscribed to my robot's.**

But when I login to the other party account,

I can see that robot is online,

why is it like this?

Is the jabber protocol now in chaos?

+1  A: 

It has been a while since I've mucked with XMPP, but a quick re-reading of the spec has me thinking that you have the meaning of "to" mixed up. If the user is listed as "to" on the robot's roster, then that means the user is following the robots presence, not the other way around. "from" means that the robot is following -- or will receive presence stanzas from -- the user account.

Do you know what the roster for the user looks like? If things are synced up, the users's roster should have the robot listed as "from".

Joe Beda
Oh,you are right,I mixed up.But through my robot account,I can see the user account online,and I've re-subscribed to that user account multiple times,still not effect,say,the 'subscription' is still 'to'.
Shore
+1  A: 

If you say "My bot has a subscription TO shore" or "Shore has a subscription FROM my bot", "from" and "to" will make more sense.

So, if the bot's roster has:

<item jid='[email protected]' subscription='to'/>

Then the bot will see shore's presence, but shore will not see the bot's presence, assuming that shore's roster has:

<item jid='[email protected]' subscription='from'/>

It's possible for these states to get out of sync, due to network problems and the like. In those cases, the easiest way to fix the problem is to remove the item (which should end up effectively removing the item on the other side), then re-add (see RFC 3921bis, section 2.5.1 for details):

<iq from='[email protected]/background'
   id='delete_1'
   type='set'>
 <query xmlns='jabber:iq:roster'>
   <item jid='[email protected]' subscription='remove'/>
 </query>
</iq>
<presence type='subscribe' 
          from='[email protected]/background' 
          to='[email protected]'/>

The thing to keep in mind is that even if the subscription is in the direction shown, the bot MAY be sending directed presence to shore, in which case shore would see presence from the both even though he is not subscribed to the bot. Check the bot's protocol log, and you may see something like:

<presence to='[email protected]'/>
Joe Hildebrand
Great remark!You said when network problem or the like,quick fix is to remove on "both sides" then re-add.But practically,the other side is the user,so it seems a little not applicable?Is there any other solution?
Shore
If you remove from your side, it should remove from the other side enough to get things fixed. I added protocol examples for that in my answer.
Joe Hildebrand
Thank you Joe!And one more questions is:sometimes if the other sider refused to accept your subscription the first time,subsequent subscriptions will never work,how to fix that?
Shore
You can always remove and re-add, but keep in mind that if you do that a lot, the person that you're subscribing to will consider you a spammer.
Joe Hildebrand