Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How to get online users with Net::Jabber

by shaitand (Initiate)
on Nov 02, 2012 at 00:03 UTC ( #1001891=perlquestion: print w/ replies, xml ) Need Help??
shaitand has asked for the wisdom of the Perl Monks concerning the following question:

I am using jabber presence to communicate state between systems because it pushes status updates to everyone automatically

Presence only works on systems on your Roster/Contact list.

How does one retrieve a list of all online users from a Jabber server with Net::Jabber? I've tried worming my way through browse functions and disco functions but haven't gotten anything successful enough to even bother giving the code of my attempts so a code example would be greatly appreciated!

UPDATE: I've found that manually creating and sending the request like this:

my $iq = Net::Jabber::IQ->new(); $iq->SetType('get'); $iq->SetTo("$server/admin"); my $q = $iq->NewQuery('jabber:iq:browse'); my $result = $Connection->SendAndReceiveWithID($iq); print Dumper($result);

Gives an error back with the tag 'not-allowed'. This may be because the user I'm connecting with is not an admin. Using admin credentials isn't an option for me. I welcome any input telling me that I'm mistaken! If someone stumbles upon this looking for the solution the above code may well work with an admin account.

I will use an alternative solution to work around the problem. I'm thinking about having a user with the distinct purpose of initial registration. All systems automatically subscribe to this user on first connection and that user messages back with its roster list and then system can subscribe to all those users.

Thank you to all the monks who looked and considered this issue!

Comment on How to get online users with Net::Jabber
Download Code
Re: How to get online users with Net::Jabber
by aitap (Deacon) on Nov 02, 2012 at 18:58 UTC
    Are you sure that Jabber protocol provides a way to get the full list of online users from the server? Can you do it via a regular Jabber client on your server? Some servers do provide a special search service, but I've never seen a "full online user list" service.
    Sorry if my advice was wrong.

      There are two ways mentioned in "Programming Jabber" sending an iq to jabber admin with just the server name and using the browse capability.

      The admin capability is listed as legacy in the book and indicates browse is the way to go. The documentation for Net::Jabber lists browse capability as deprecated and points to the disco functionality.

      Unfortunately I can't find any real documentation for disco. There seems to be some spec stuff but it uses terms like "node" without defining them. It seems to be some sort of tree of objects but the tree itself isn't documented under what I've read.

      I've tried using the browse functions using just a jid but that doesn't seem to work. I've tried just the server as jid as indicated in the text of the book and server/admin as indicated in the actual code listing.

      browsing entities covers using the browse function for this purpose. My expectation would be that assigning the return value of the browse function called with a jid of the server or maybe server/admin would return the online user list

      There might be more to it. For instance I discovered that you needed to initialize a local presence DB and manually use a callback to update it with presence updates before you can query it. None of that was documented. The Net::Jabber module documentation is extremely sketchy and incomplete

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001891]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2014-09-18 05:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls