ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/test_client
Revision: 1.7
Committed: Tue Jul 3 14:00:52 2007 UTC (19 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.6: +13 -3 lines
Log Message:
implemented stanza errors

File Contents

# Content
1 #!/opt/perl/bin/perl
2 use strict;
3 use utf8;
4 use Event;
5 use AnyEvent;
6 use XML::Twig;
7 use Net::XMPP2 qw/xep-86/;
8 use Net::XMPP2::Client;
9 use Encode;
10
11 sub dumpxml {
12 my $data = shift;
13 my $t = XML::Twig->new;
14 if ($t->safe_parse ("<deb>$data</deb>")) {
15 $t->set_pretty_print ('indented');
16 $t->print;
17 print "\n";
18 } else {
19 print "[$data]\n";
20 }
21 }
22
23 binmode STDOUT, ":utf8";
24
25 my $j = AnyEvent->condvar;
26
27 my $cl = Net::XMPP2::Client->new;
28 #$cl->add_account ('elmex@jabber.org/Net::XどなPP2', 'xxxxxxxx');
29 #$cl->add_account ('elmor@jabber.org/Net::XどなPP2', 'xxxxxxxx');
30 $cl->add_account ('elmex@localhost/Net::XどなPP2', 'xxxxxxxx');
31 $cl->reg_cb (
32 connected => sub {
33 $cl->send_message ("Hello!" => 'elmex@jabbfer.org');
34
35 0
36 },
37 roster_update => sub {
38 my ($cl, $acc, $roster, $contacts) = @_;
39 $roster->debug_dump;
40 $acc->connection ()->send_presence ('probe' => undef, to => 'elmex@jabfber.org');
41 1
42 },
43 presence_update => sub {
44 my ($cl, $acc, $roster, $contact, $old, $new) = @_;
45 $roster->debug_dump;
46 1
47 },
48 sasl_error => sub {
49 my ($cl, $acc, $error) = @_;
50 print "SASL ERROR".$error->string."\n";
51 },
52 presence_error => sub {
53 my ($cl, $acc, $error) = @_;
54 print "PRESENCE ERROR: " . $error->string . "\n";
55 1;
56 },
57 message_error => sub {
58 my ($cl, $acc, $error) = @_;
59 print "MESSAGE ERROR: " . $error->string . "\n";
60 1;
61 },
62 disconnect => sub { warn "DISCON[@_]\n"; 1 },
63 debug_send => sub {
64 warn "send: @_\n";
65 1
66 },
67 debug_recv => sub {
68 warn "recv: @_\n";
69 1
70 },
71 );
72
73 $cl->reg_cb (contact_request_subscribe => sub {
74 my ($cl, $acc, $roster, $contact, $rdoit) = @_;
75 $$rdoit = 1;
76 $contact->send_subscribe;
77 1
78 });
79
80 $cl->reg_cb (contact_did_unsubscribe => sub {
81 my ($cl, $acc, $roster, $contact, $rdoit) = @_;
82 $$rdoit = 1;
83 1
84 });
85
86 $cl->reg_cb (roster_update => sub {
87 my ($cl, $acc, $roster, $contacts) = @_;
88
89 $roster->debug_dump;
90 print "ROSTER!\n";
91 # $roster->new_contact ('elmex@jabber.org', 'Der elmex', ['ABC', 'TEst'], sub {
92 # $roster->get_contact ('elmex@jabber.org')->send_subscribe;
93 # $roster->delete_contact ('elmex@jabber.org');
94 # });
95 #$cl->remove_accounts ("TEST");
96
97 0
98 });
99
100 $cl->start;
101
102 $j->wait;