ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/disco_version
Revision: 1.3
Committed: Tue Jul 24 12:31:15 2007 UTC (19 years, 2 months ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +1 -4 lines
Log Message:
documentation update

File Contents

# User Rev Content
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 elmex 1.2 sub append_outputfile {
9     open OUT, ">>disco_version.output"
10     or die "Couldn't open disco_version.output: $!\n";
11     print OUT $_[0];
12     close OUT;
13     }
14    
15 elmex 1.1 sub version_req {
16     my ($con, $dest) = @_;
17    
18     $con->send_iq (
19     get => {
20     defns => 'version',
21     node => { name => 'query', ns => 'version' }
22     },
23     sub {
24     my ($node, $error) = @_;
25     if ($error) {
26 elmex 1.2 warn "$dest: DISCO VERSION ERROR $dest: " . $error->string . "\n";
27 elmex 1.1 } else {
28     my (@name) = $node->find_all ([qw/version query/], [qw/version name/]);
29     my (@ver) = $node->find_all ([qw/version query/], [qw/version version/]);
30 elmex 1.2 if (@name and @ver) {
31     my $from = $node->attr ('from');
32     my $name = $name[0]->text;
33     my $ver = $ver[0]->text;
34     $ver =~ s/[\n\t]//g;
35     $name =~ s/[\n\t]//g;
36     print "$dest: $from: name: $name version: $ver\n";
37     append_outputfile ("$from\t$name\t$ver\n");
38     } else {
39     print "$dest: no version\n";
40     }
41 elmex 1.1 }
42     },
43     to => $dest
44     );
45     }
46    
47     my $j = AnyEvent->condvar;
48     my $cl = Net::XMPP2::Client->new;
49 elmex 1.2 my $t = undef;
50     my @jids = map { chomp; $_ } <STDIN>;
51     sub mkti {
52     my ($con) = @_;
53     $t = AnyEvent->timer (after => 1, cb => sub {
54     for (1..50) {
55     my $j = pop @jids;
56     if ($j) {
57     version_req ($con, $j);
58     } else {
59     print "no more jids to query...\n";
60     last;
61     }
62     }
63     mkti ($con);
64     });
65     }
66 elmex 1.1 $cl->add_account ('net_xmpp2@jabber.org', 'test');
67     $cl->reg_cb (
68     session_ready => sub {
69     my ($cl, $acc) = @_;
70 elmex 1.2 if (@ARGV) {
71     version_req ($acc->connection, $ARGV[0]);
72     } else {
73     mkti ($acc->connection);
74     }
75 elmex 1.3 $cl->unreg_me
76 elmex 1.1 },
77     disconnect => sub {
78     my ($cl, $acc, $h, $p, $reas) = @_;
79     print "disconnect ($h:$p): $reas\n";
80     },
81     error => sub {
82     my ($cl, $acc, $err) = @_;
83     print "ERROR: " . $err->string . "\n";
84     },
85     message => sub {
86     my ($cl, $acc, $msg) = @_;
87     print "message from: " . $msg->from . ": " . $msg->any_body . "\n";
88     }
89     );
90     $cl->start;
91     $j->wait;