Debian Codegraph @

samples/store_avatar

raw
1 #!/opt/perl/bin/perl
2 use strict;
3 use utf8;
4 use EV;
5 use AnyEvent;
6 use AnyEvent::XMPP::Client;
7 use AnyEvent::XMPP::Ext::VCard;
8
9 my $j = AnyEvent->condvar;
10 my $cl = AnyEvent::XMPP::Client->new (debug => 1);
11 $cl->add_account ($ARGV[0], $ARGV[1], undef, undef, {
12 initial_presence => -1, dont_retrieve_roster => 1
13 });
14 my $ex = AnyEvent::XMPP::Ext::VCard->new;
15
16 my $av = do {
17 open my $av, $ARGV[2] or die "Couldn't open avatar '$ARGV[2]': $!";
18 local $/;
19 binmode $av;
20 <$av>
21 };
22
23
24 $cl->reg_cb (
25 session_ready => sub {
26 my ($cl, $acc) = @_;
27 print "session ready\n";
28 $ex->store ($acc->connection, { _avatar => $av }, sub {
29 my ($e) = @_;
30 if ($e) {
31 warn "error in storing avatar: " .$e->string ."\n";
32 }
33 $j->broadcast;
34 });
35 },
36 disconnect => sub {
37 my ($cl, $acc, $h, $p, $reas) = @_;
38 print "disconnect ($h:$p): $reas\n";
39 },
40 error => sub {
41 my ($cl, $acc, $err) = @_;
42 print "ERROR: " . $err->string . "\n";
43 },
44 message => sub {
45 my ($cl, $acc, $msg) = @_;
46 print "message from: " . $msg->from . ": " . $msg->any_body . "\n";
47 }
48 );
49 $cl->start;
50 $j->wait;