| 1 |
elmex |
1.1 |
#!/opt/perl/bin/perl |
| 2 |
|
|
use strict; |
| 3 |
|
|
use utf8; |
| 4 |
|
|
use Event; |
| 5 |
|
|
use AnyEvent; |
| 6 |
|
|
use Net::XMPP2::Client; |
| 7 |
|
|
|
| 8 |
|
|
sub version_req { |
| 9 |
|
|
my ($con, $dest) = @_; |
| 10 |
|
|
|
| 11 |
|
|
$con->send_iq ( |
| 12 |
|
|
get => { |
| 13 |
|
|
defns => 'version', |
| 14 |
|
|
node => { name => 'query', ns => 'version' } |
| 15 |
|
|
}, |
| 16 |
|
|
sub { |
| 17 |
|
|
my ($node, $error) = @_; |
| 18 |
|
|
if ($error) { |
| 19 |
|
|
warn "*** DISCO VERSION ERROR $dest: " . $error->string . "\n"; |
| 20 |
|
|
} else { |
| 21 |
|
|
my (@name) = $node->find_all ([qw/version query/], [qw/version name/]); |
| 22 |
|
|
my (@ver) = $node->find_all ([qw/version query/], [qw/version version/]); |
| 23 |
|
|
print "$dest: ".$node->attr ('from').": name: " . $name[0]->text . " version: " . $ver[0]->text . "\n" if @name and @ver; |
| 24 |
|
|
print "$dest: no version\n" unless @name and @ver; |
| 25 |
|
|
} |
| 26 |
|
|
}, |
| 27 |
|
|
to => $dest |
| 28 |
|
|
); |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
my $j = AnyEvent->condvar; |
| 32 |
|
|
my $cl = Net::XMPP2::Client->new; |
| 33 |
|
|
$cl->add_account ('net_xmpp2@jabber.org', 'test'); |
| 34 |
|
|
$cl->reg_cb ( |
| 35 |
|
|
session_ready => sub { |
| 36 |
|
|
my ($cl, $acc) = @_; |
| 37 |
|
|
version_req ($acc->connection, $ARGV[0]); |
| 38 |
|
|
0 |
| 39 |
|
|
}, |
| 40 |
|
|
disconnect => sub { |
| 41 |
|
|
my ($cl, $acc, $h, $p, $reas) = @_; |
| 42 |
|
|
print "disconnect ($h:$p): $reas\n"; |
| 43 |
|
|
1 |
| 44 |
|
|
}, |
| 45 |
|
|
error => sub { |
| 46 |
|
|
my ($cl, $acc, $err) = @_; |
| 47 |
|
|
print "ERROR: " . $err->string . "\n"; |
| 48 |
|
|
1 |
| 49 |
|
|
}, |
| 50 |
|
|
message => sub { |
| 51 |
|
|
my ($cl, $acc, $msg) = @_; |
| 52 |
|
|
print "message from: " . $msg->from . ": " . $msg->any_body . "\n"; |
| 53 |
|
|
1 |
| 54 |
|
|
} |
| 55 |
|
|
); |
| 56 |
|
|
$cl->start; |
| 57 |
|
|
$j->wait; |