ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/samples/test
Revision: 1.8
Committed: Tue Apr 24 16:13:53 2007 UTC (18 years ago) by elmex
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +1 -1 lines
Log Message:
further subscription code and in-band-stuff is going to be implemented next

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 => 'admin', password => 'xxxxxx', domain => 'localhost',
35 resource => $res,
36 disable_ssl => 0,
37 );
38 $con->connect or die "Couldn't connect: $!";
39 $con->init;
40 $con->reg_cb (
41 session_ready => sub {
42 my ($con) = @_;
43 print "stream ready!\n" ;
44 # $con->{foo} = AnyEvent->timer (after => 1, cb => sub {
45 return;
46 for (qw/fippo@goodadvice.pages.de elmex@jabber.org ve.symlynx.com jabber.org/) {
47 $con->send_iq (get => sub {
48 my ($w) = @_;
49 $w->addPrefix (xmpp_ns ('disco_info'), '');
50 $w->emptyTag ([xmpp_ns ('disco_info'), 'query']);
51 }, sub {
52 }, to => $_);
53 # });
54 $con->send_iq (
55 get => sub {
56 my ($w) = @_;
57 $w->addPrefix (xmpp_ns ('version'), '');
58 $w->emptyTag ([xmpp_ns ('version'), 'query']);
59 }, sub {
60 my ($node, $errnode, $err) = @_;
61 unless (defined $node) {
62 print "ERROR: ".($errnode->attr ('from')).": $err->[0]/$err->[3]:" .($err->[1]->name)."\n";
63 return;
64 }
65 my (@name) = $node->find_all ([qw/version query/], [qw/version name/]);
66 my (@ver) = $node->find_all ([qw/version query/], [qw/version version/]);
67 print "REPL: ".($node->attr ('from')).": ".($name[0]->text). " " .($ver[0]->text)."!\n" if @name and @ver;
68 print "NO VERSION FOUND!\n" unless @name and @ver;
69 },
70 to => $_, #$con->{domain},#'localhost',
71 #from => $con->jid
72 );
73 }
74 },
75 presence_update => sub {
76 my ($con, $roster) = @_;
77 $roster->debug_dump;
78 1
79 },
80 roster_update => sub {
81 my ($con, $roster) = @_;
82 $roster->debug_dump;
83 1
84 },
85 message => sub {
86 my ($con, $msg) = @_;
87 print "Message from: ".$msg->from." to: ".$msg->to.":\n$msg\n";
88 if ($msg =~ /arsch/si) {
89 $msg->reply ("FOTZE!");
90 }
91 1
92 },
93 debug_recv => sub { print "RRRRRRRRECVVVVVV:\n"; dumpxml ($_[1]); 1},
94 debug_send => sub { print "SSSSSSSSENDDDDDD:\n"; dumpxml ($_[1]); 1 },
95 stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
96 );
97
98
99 $j->wait;