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