ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/samples/test
Revision: 1.5
Committed: Fri Feb 2 23:24:39 2007 UTC (19 years, 8 months ago) by elmex
Branch: MAIN
Changes since 1.4: +55 -21 lines
Log Message:
lots of changes. added roster retrival

File Contents

# User Rev Content
1 elmex 1.1 #!/opt/perl/bin/perl
2     use strict;
3     use utf8;
4     use AnyEvent;
5 elmex 1.5 use XML::Twig;
6 elmex 1.4 use Net::XMPP2 qw/xep-86/;
7 elmex 1.1 use Net::XMPP2::IM::Connection;
8     use Net::XMPP2::Namespaces qw/xmpp_ns/;
9     use Net::LibIDN qw/idn_prep_resource/;
10     use Encode;
11    
12 elmex 1.5 sub dumpxml {
13     my $data = shift;
14     my $t = XML::Twig->new;
15     if ($t->safe_parse ("<deb>$data</deb>")) {
16     $t->set_pretty_print ('indented');
17     $t->print;
18     print "\n";
19     } else {
20     print "[$data]\n";
21     }
22     }
23    
24 elmex 1.1 binmode STDOUT, ":utf8";
25    
26     my $j = AnyEvent->condvar;
27    
28     my $res = "Net::XどなPP2";
29 elmex 1.5 #my $res = "Net::XMPP2";
30 elmex 1.1
31     my $con = Net::XMPP2::IM::Connection->new (
32 elmex 1.2 username => 'elmex', #'elmor',
33 elmex 1.4 domain => 'amessage.eu',#'jabber.org',
34 elmex 1.5 # username => 'elmor', #'elmor',
35     # domain => 'jabber.org',#'jabber.org',
36 elmex 1.1 resource => $res,
37     password => 'xxxxxx',
38 elmex 1.5 disable_ssl => 1,
39 elmex 1.1 );
40 elmex 1.2 $con->connect or die "Couldn't connect: $!";
41 elmex 1.1 $con->init;
42     $con->reg_cb (
43     session_ready => sub {
44     my ($con) = @_;
45     print "stream ready!\n" ;
46 elmex 1.5 # $con->{foo} = AnyEvent->timer (after => 1, cb => sub {
47     return;
48     for (qw/fippo@goodadvice.pages.de elmex@jabber.org ve.symlynx.com jabber.org/) {
49     $con->send_iq (get => sub {
50     my ($w) = @_;
51     $w->addPrefix (xmpp_ns ('disco_info'), '');
52     $w->emptyTag ([xmpp_ns ('disco_info'), 'query']);
53     }, sub {
54     }, to => $_);
55     # });
56     $con->send_iq (
57     get => sub {
58     my ($w) = @_;
59     $w->addPrefix (xmpp_ns ('version'), '');
60     $w->emptyTag ([xmpp_ns ('version'), 'query']);
61     }, sub {
62     my ($node, $errnode, $err) = @_;
63     unless (defined $node) {
64     print "ERROR: ".($errnode->attr ('from')).": $err->[0]/$err->[3]:" .($err->[1]->name)."\n";
65     return;
66     }
67     my (@name) = $node->find_all ([qw/version query/], [qw/version name/]);
68     my (@ver) = $node->find_all ([qw/version query/], [qw/version version/]);
69     print "REPL: ".($node->attr ('from')).": ".($name[0]->text). " " .($ver[0]->text)."!\n" if @name and @ver;
70     print "NO VERSION FOUND!\n" unless @name and @ver;
71     },
72     to => $_, #$con->{domain},#'localhost',
73     #from => $con->jid
74     );
75     }
76     },
77     roster_update => sub {
78     my ($con) = @_;
79     for (keys %{$con->{roster}}) {
80     print "\tROSTER[$_]\n";
81     }
82 elmex 1.1 },
83 elmex 1.5 debug_recv => sub { print "RRRRRRRRECVVVVVV:\n"; dumpxml ($_[1]); 1},
84     debug_send => sub { print "SSSSSSSSENDDDDDD:\n"; dumpxml ($_[1]); 1 },
85 elmex 1.1 stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
86     );
87    
88    
89     $j->wait;