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 (19 years, 5 months 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

# 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 elmex 1.6 use Net::XMPP2::Util;
10 elmex 1.1 use Net::LibIDN qw/idn_prep_resource/;
11     use Encode;
12    
13 elmex 1.5 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 elmex 1.1 binmode STDOUT, ":utf8";
26    
27     my $j = AnyEvent->condvar;
28    
29     my $res = "Net::XどなPP2";
30 elmex 1.6
31 elmex 1.5 #my $res = "Net::XMPP2";
32 elmex 1.1
33     my $con = Net::XMPP2::IM::Connection->new (
34 elmex 1.8 username => 'admin', password => 'xxxxxx', domain => 'localhost',
35 elmex 1.1 resource => $res,
36 elmex 1.7 disable_ssl => 0,
37 elmex 1.1 );
38 elmex 1.2 $con->connect or die "Couldn't connect: $!";
39 elmex 1.1 $con->init;
40     $con->reg_cb (
41     session_ready => sub {
42     my ($con) = @_;
43     print "stream ready!\n" ;
44 elmex 1.5 # $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 elmex 1.6 presence_update => sub {
76     my ($con, $roster) = @_;
77     $roster->debug_dump;
78 elmex 1.7 1
79 elmex 1.6 },
80 elmex 1.5 roster_update => sub {
81 elmex 1.6 my ($con, $roster) = @_;
82     $roster->debug_dump;
83 elmex 1.7 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 elmex 1.1 },
93 elmex 1.5 debug_recv => sub { print "RRRRRRRRECVVVVVV:\n"; dumpxml ($_[1]); 1},
94     debug_send => sub { print "SSSSSSSSENDDDDDD:\n"; dumpxml ($_[1]); 1 },
95 elmex 1.1 stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
96     );
97    
98    
99     $j->wait;