ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/test
Revision: 1.6
Committed: Tue Feb 6 22:52:45 2007 UTC (19 years, 8 months ago) by elmex
Branch: MAIN
Changes since 1.5: +13 -9 lines
Log Message:
implemented firts parts of roster handling.
added jid handling functions.

File Contents

# Content
1 #!/opt/perl/bin/perl
2 use strict;
3 use utf8;
4 use AnyEvent;
5 use XML::Twig;
6 use Net::XMPP2 qw/xep-86/;
7 use Net::XMPP2::IM::Connection;
8 use Net::XMPP2::Namespaces qw/xmpp_ns/;
9 use Net::XMPP2::Util;
10 use Net::LibIDN qw/idn_prep_resource/;
11 use Encode;
12
13 sub dumpxml {
14 my $data = shift;
15 my $t = XML::Twig->new;
16 if ($t->safe_parse ("<deb>$data</deb>")) {
17 $t->set_pretty_print ('indented');
18 $t->print;
19 print "\n";
20 } else {
21 print "[$data]\n";
22 }
23 }
24
25 binmode STDOUT, ":utf8";
26
27 my $j = AnyEvent->condvar;
28
29 my $res = "Net::XどなPP2";
30
31 #my $res = "Net::XMPP2";
32
33 my $con = Net::XMPP2::IM::Connection->new (
34 username => 'elmex', password => 'xxxxxx', domain => 'jabber.org',
35 # username => 'elmex', password => 'xxxxxx', domain => 'jabber.org',
36 # username => 'elmor', password => 'xxxxxx', domain => 'amessage.eu',
37 resource => $res,
38 disable_ssl => 1,
39 );
40 $con->connect or die "Couldn't connect: $!";
41 $con->init;
42 $con->reg_cb (
43 session_ready => sub {
44 my ($con) = @_;
45 print "stream ready!\n" ;
46 # $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 presence_update => sub {
78 my ($con, $roster) = @_;
79 $roster->debug_dump;
80 1;
81 },
82 roster_update => sub {
83 my ($con, $roster) = @_;
84 $roster->debug_dump;
85 1;
86 },
87 debug_recv => sub { print "RRRRRRRRECVVVVVV:\n"; dumpxml ($_[1]); 1},
88 debug_send => sub { print "SSSSSSSSENDDDDDD:\n"; dumpxml ($_[1]); 1 },
89 stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
90 );
91
92
93 $j->wait;