[jdev] Net::Jabber returns empty or bogus presence from users onthe roster
Bart Smit
Bart.Smit at nexusmgmt.com
Fri Dec 9 17:02:49 CST 2005
I have created this test script:
#!/usr/bin/perl
use strict;
use Net::Jabber;
my $jb_uid = "alert";
my $jb_pw = "secret";
my $jbport = 5222;
my $jbhost = "jabber.nexusmgmt.com";
my $resource = "Daemon";
my %prs =();
my $jabcon = Net::Jabber::Client->new();
$jabcon->Connect(
"hostname" => $jbhost,
"port" => $jbport )
or die "Cannot Connect ($!)\n";
my @result = $jabcon->AuthSend (
"username" => $jb_uid,
"password" => $jb_pw,
"resource" => $resource )
or die "Cannot authenticate: ($!)\n";
$jabcon->SetCallBacks( "presence" => \&presence_handler);
die "Cannot register with the jabber roster\n"
unless (defined($jabcon->Process(10)));
$jabcon->PresenceSend();
my $roster = $jabcon->Roster();
while(defined($jabcon->Process())) { }
sub presence_handler
{
# Shift off the stream number
shift;
my $list = Net::Jabber::Presence->new($_);
my $jid = $list->GetFrom();
my $type = $list->GetType();
if ($type eq "subscribe") {
$jabcon->Send($list->Reply(type => 'subscribed'));
$jabcon->Send($list->Reply(type => 'subscribe'));
}
}
When I sign onto jabber with a user on the alert roster, the script
outputs this:
handlePresence: presence(<presence from='bsmit at jabber.nexusmgmt.com/Just
Another Jabber Client'
to='alert at jabber.nexusmgmt.com'><priority>3</priority><show>xa</show><st
atus>Ext. away</status></presence>)
handlePresence: presence(<presence from='bsmit at jabber.nexusmgmt.com/Just
Another Jabber Client'
to='alert at jabber.nexusmgmt.com'><priority>3</priority><show>xa</show><st
atus>Ext. away</status><x from='bsmit at jabber.nexusmgmt.com/Just Another
Jabber Client' stamp='20051209T22:46:58'
xmlns='jabber:x:delay'/></presence>)
But I can't capture this info in the message handler; the $jid variable
remains empty.
If I change the message handler to pass the script my $list =
Net::Jabber::Presence->new(@_); as outlined in
http://www.linux-mag.com/2001-08/jabber_01.html it dies with:
handlePresence: presence(<presence from='bsmit at jabber.nexusmgmt.com/Just
Another Jabber Client'
to='alert at jabber.nexusmgmt.com'><priority>3</priority><show>xa</show><st
atus>Ext. away</status></presence>)
Can't call method "XPath" on an undefined value at
/usr/lib/perl5/site_perl/5.8.3/Net/XMPP/Stanza.pm line 556.
Any perlmonks out there that can help me with this?
TIA
Bart...
-----Original Message-----
From: jdev-bounces at jabber.org [mailto:jdev-bounces at jabber.org] On Behalf
Of Bart Smit
Sent: 08 December 2005 14:08
To: jdev at jabber.org
Subject: [jdev] Net::Jabber returns empty or bogus presence from users
onthe roster
I am having problems with the Net::Jabber perl module getting roster
information from both a jabber 1.x and 2.x server.
My script will not show presence information from the roster. I want to
make sure that the user is online/chat before I send them a message from
the script.
After some googling I ended up on
http://www.pipetree.com/jabber/headlines.html.
To make sure the problem is not with my code, I modified the headlines
script for my server particulars and registered the headlines user
manually with Exodus. I then started the script and got this error
message as soon as I signed in:
Can't call method "isa" without a package or object reference at
/usr/lib/perl5/site_perl/5.8.6/Net/XMPP/Stanza.pm line 252
I remmed out the use strict; directive on both my script and the
Stanza.pm as suggested on some pages and it gives:
DBUG: Presence from :
<eng47d5x9gxocxoknt2hf3kiwxkj8hen5urc7xah/>
DBUG: available (online)
Did anybody get this particular script to run correctly? Are there
perhaps more recent examples of perl scripts that read the presence of
users on the roster?
Any pointers would be very much appreciated.
Thanks,
Bart...
More information about the JDev
mailing list