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
  
     | 
    
      #!/opt/perl/bin/perl
use strict;
use utf8;
use EV;
use AnyEvent;
use AnyEvent::XMPP::Client;
use AnyEvent::XMPP::Ext::VCard;
my $j = AnyEvent->condvar;
my $cl = AnyEvent::XMPP::Client->new (debug => 1);
$cl->add_account ($ARGV[0], $ARGV[1], undef, undef, {
   initial_presence => -1, dont_retrieve_roster => 1
});
my $ex = AnyEvent::XMPP::Ext::VCard->new;
my $av = do {
   open my $av, $ARGV[2] or die "Couldn't open avatar '$ARGV[2]': $!";
   local $/;
   binmode $av;
   <$av>
};
$cl->reg_cb (
   session_ready => sub {
      my ($cl, $acc) = @_;
      print "session ready\n";
      $ex->store ($acc->connection, { _avatar => $av }, sub {
         my ($e) = @_;
         if ($e) {
            warn "error in storing avatar: " .$e->string ."\n";
         }
         $j->broadcast;
      });
   },
   disconnect => sub {
      my ($cl, $acc, $h, $p, $reas) = @_;
      print "disconnect ($h:$p): $reas\n";
   },
   error => sub {
      my ($cl, $acc, $err) = @_;
      print "ERROR: " . $err->string . "\n";
   },
   message => sub {
      my ($cl, $acc, $msg) = @_;
      print "message from: " . $msg->from . ": " . $msg->any_body . "\n";
   }
);
$cl->start;
$j->wait;
 
     |