ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/test_client
Revision: 1.8
Committed: Wed Jul 4 16:05:22 2007 UTC (19 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.7: +3 -6 lines
Log Message:
major documentation refresh. preparing for release

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 (@ARGV);
29 $cl->reg_cb (
30 connected => sub {
31 $cl->send_message ("Hello!" => 'elmex@jabbfer.org');
32 0
33 },
34 roster_update => sub {
35 my ($cl, $acc, $roster, $contacts) = @_;
36 $roster->debug_dump;
37 $acc->connection ()->send_presence ('probe' => undef, to => 'elmex@jabfber.org');
38 print "OEOFWEFIEJWFEWO\n" if not $roster->is_retrieved;
39 1
40 },
41 presence_update => sub {
42 my ($cl, $acc, $roster, $contact, $old, $new) = @_;
43 $roster->debug_dump;
44 1
45 },
46 sasl_error => sub {
47 my ($cl, $acc, $error) = @_;
48 print "SASL ERROR".$error->string."\n";
49 },
50 presence_error => sub {
51 my ($cl, $acc, $error) = @_;
52 print "PRESENCE ERROR: " . $error->string . "\n";
53 1;
54 },
55 message_error => sub {
56 my ($cl, $acc, $error) = @_;
57 print "MESSAGE ERROR: " . $error->string . "\n";
58 1;
59 },
60 disconnect => sub { warn "DISCON[@_]\n"; 1 },
61 debug_send => sub {
62 warn "send: @_\n";
63 1
64 },
65 debug_recv => sub {
66 warn "recv: @_\n";
67 1
68 },
69 );
70
71 $cl->reg_cb (contact_request_subscribe => sub {
72 my ($cl, $acc, $roster, $contact, $rdoit) = @_;
73 $$rdoit = 1;
74 $contact->send_subscribe;
75 1
76 });
77
78 $cl->reg_cb (contact_did_unsubscribe => sub {
79 my ($cl, $acc, $roster, $contact, $rdoit) = @_;
80 $$rdoit = 1;
81 1
82 });
83
84 $cl->reg_cb (roster_update => sub {
85 my ($cl, $acc, $roster, $contacts) = @_;
86
87 $roster->debug_dump;
88 # $roster->new_contact ('elmex@jabber.org', 'Der elmex', ['ABC', 'TEst'], sub {
89 # $roster->get_contact ('elmex@jabber.org')->send_subscribe;
90 # $roster->delete_contact ('elmex@jabber.org');
91 # });
92 #$cl->remove_accounts ("TEST");
93
94 0
95 });
96
97 $cl->start;
98
99 $j->wait;