Debian Codegraph @

samples/retrieve_roster

raw
1 #!/opt/perl/bin/perl
2 use strict;
3 use AnyEvent;
4 use AnyEvent::XMPP::IM::Connection;
5
6 my $DEBUG = 0; # set to 1 if you want to see a protocol dump
7 my $TIMEOUT = 30; # timeout the whole program after $TIMEOUT seconds
8
9 binmode STDOUT, ":utf8";
10
11 my ($jid, $pass) = @ARGV;
12
13 my $j = AnyEvent->condvar;
14 my $con =
15 AnyEvent::XMPP::IM::Connection->new (
16 jid => $jid,
17 password => $pass,
18 initial_presence => -5,
19 );
20
21 $con->reg_cb (
22 debug_recv => sub { print "< $_[1]\n" },
23 debug_send => sub { print "> $_[1]\n" },
24 ) if $DEBUG;
25
26 my $timer =
27 AnyEvent->timer (
28 after => 10, cb => sub { warn "got timeout, exiting..."; $j->broadcast }
29 );
30
31 $con->reg_cb (
32 session_ready => sub {
33 my ($con) = @_;
34 },
35 error => sub {
36 my ($con, $error) = @_;
37 warn "error: " . $error->string . "\n";
38 },
39 disconnect => sub {
40 my ($con, $host, $port, $message) = @_;
41 warn "disconnected from $host:$port: $message\n";
42 $j->broadcast;
43 },
44 roster_update => sub {
45 my ($con, $roster, $contacts) = @_;
46 for my $contact ($roster->get_contacts) {
47 print "contact: " . $contact->jid
48 . ", name: " . $contact->name
49 . ", groups: " . (join ",", $contact->groups)
50 . ", subscription: " . $contact->subscription
51 . ", ask: " . $contact->ask
52 . "\n";
53 }
54 $j->broadcast;
55 }
56 );
57
58 $con->connect;
59 $j->wait;