Skip to content

$Roster = $Connection->Roster(); and RosterGet does not work properly together #10

@dhyannataraj

Description

@dhyannataraj

I am trying to use Net::XMPP to get buddy list from a server and I have some
problems.

I wanted to get user list from my old jabber server, so I took an example
client.pl removed all unnecessary things and added

my $Roster = $Connection->Roster();

right after authorization. See the code at the end of thi report

Documentation says that thus Roster object will catch all incoming iq files and
I will get full roaster at the end.

But this is not what happened. I get only a few iq that came after I set my
presence. The main part of roster xml can be seen in a log but not processed
by $Roster object for some reason.

I've dug into problem and found out that if I replace RosterGet with
RosterRequest everything starts working well.

This happens because of the conflict of reply catcher. $Connection->Roster()
catches roster items via SetXPathCallBacks

But if I send roster request with RosterGet, it will send request with
specified ID, and reply catcher would be catching this reply.

And it would catch this reply before SetXPathCallBacks would be able to try to
catch it. So there would be no roster in $Roster, through we actually got
necessary data via net.

This was really confusing.

May be this is an expected behavior, I do not completely understand the
philosophy of Net::XMPP. But I doubt it.

May be something should be fixed on code or/and documentation. But I do not
understand in what direction this fix should go.

May be you have an Idea what to do with this.

#!/usr/bin/perl

use Net::XMPP;
use strict;

my $server = "irrc.ru";
my $port = 5222;
my $username = "shaplov";
my $password = "*********";
my $resource = "scrtipt2";


my $Connection = new Net::XMPP::Client(
 debuglevel=>1, debugfile=>"$0.debug.out", debuftime=>1
);

my $status = $Connection->Connect(
                                   tls =>1,
                                   hostname=>$server,
                                   port=>$port
                                  );

if ($status != 1)
{
    print "ERROR:  Jabber server is down or connection was not allowed.\n";
    print "        ($!)\n";
    print $Connection->GetErrorCode();
    exit(0);
}

my @result = $Connection->AuthSend(username=>$username,
                                   password=>$password,
                                   resource=>$resource);

if ($result[0] ne "ok")
{
    print "ERROR: Authorization failed: $result[0] - $result[1]\n";
    exit(0);
}

print "Logged in to $server:$port...\n";

my $Roster = $Connection->Roster();

###############################################
#
# FIXME if one change RosterRequest to RosterGet, script will not print compleat buddy list
#
################################################

#$Connection->RosterGet();
$Connection->RosterRequest();

$Connection->PresenceSend();

my $count = 0;
while(defined($Connection->Process(1)))
{
  print ".";
  $count ++;
  last if $count >20;
}
print "\n";

foreach my $JID ($Roster->jids())
{
  print $JID->GetJID("base"), "\n";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions