ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-XMPP2/samples/test
Revision: 1.6
Committed: Tue Feb 6 22:52:45 2007 UTC (19 years, 7 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

# 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.6 username => 'elmex', password => 'xxxxxx', domain => 'jabber.org',
35     # username => 'elmex', password => 'xxxxxx', domain => 'jabber.org',
36     # username => 'elmor', password => 'xxxxxx', domain => 'amessage.eu',
37 elmex 1.1 resource => $res,
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 elmex 1.6 presence_update => sub {
78     my ($con, $roster) = @_;
79     $roster->debug_dump;
80     1;
81     },
82 elmex 1.5 roster_update => sub {
83 elmex 1.6 my ($con, $roster) = @_;
84     $roster->debug_dump;
85     1;
86 elmex 1.1 },
87 elmex 1.5 debug_recv => sub { print "RRRRRRRRECVVVVVV:\n"; dumpxml ($_[1]); 1},
88     debug_send => sub { print "SSSSSSSSENDDDDDD:\n"; dumpxml ($_[1]); 1 },
89 elmex 1.1 stream_error => sub { die "ERROR[$_[1]]{$_[2]}\n" },
90     );
91    
92    
93     $j->wait;