ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/samples/test_client
Revision: 1.6
Committed: Mon Jul 2 13:15:00 2007 UTC (19 years, 3 months ago) by elmex
Branch: MAIN
Changes since 1.5: +15 -3 lines
Log Message:
added some error handling for EOF ... err... disconnects from SSL

File Contents

# User Rev Content
1 elmex 1.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 elmex 1.3 #$cl->add_account ('elmex@jabber.org/Net::XどなPP2', 'xxxxxxxx');
29 elmex 1.6 #$cl->add_account ('elmor@jabber.org/Net::XどなPP2', 'xxxxxxxx');
30     $cl->add_account ('elmex@localhost/Net::XどなPP2', 'xxxxxxxx');
31 elmex 1.1 $cl->reg_cb (
32     connected => sub {
33 elmex 1.3 # $cl->send_message ("Hello!" => 'elmex@jabber.org');
34 elmex 1.1 0
35     },
36 elmex 1.3 roster_update => sub {
37     my ($cl, $acc, $roster, $contacts) = @_;
38     warn "ROSTER UPD\n";
39     $roster->debug_dump;
40     1
41     },
42     presence_update => sub {
43     my ($cl, $acc, $roster, $contact, $old, $new) = @_;
44     warn "PRESENCE UPD\n";
45     $roster->debug_dump;
46     1
47     },
48 elmex 1.2 sasl_error => sub {
49     my ($cl, $acc, $error) = @_;
50     print "SASL ERROR".$error->string."\n";
51 elmex 1.6 },
52     disconnect => sub { warn "DISCON[@_]\n"; 1 },
53     debug_send => sub {
54     warn "send: @_\n";
55     1
56     },
57     debug_recv => sub {
58     warn "recv: @_\n";
59     1
60     },
61 elmex 1.1 );
62    
63 elmex 1.4 $cl->reg_cb (contact_request_subscribe => sub {
64     my ($cl, $acc, $roster, $contact, $rdoit) = @_;
65     $$rdoit = 1;
66     $contact->send_subscribe;
67     1
68     });
69    
70     $cl->reg_cb (contact_did_unsubscribe => sub {
71     my ($cl, $acc, $roster, $contact, $rdoit) = @_;
72     $$rdoit = 1;
73     1
74     });
75    
76 elmex 1.3 $cl->reg_cb (roster_update => sub {
77     my ($cl, $acc, $roster, $contacts) = @_;
78    
79 elmex 1.6 $roster->debug_dump;
80     print "ROSTER!\n";
81 elmex 1.5 # $roster->new_contact ('elmex@jabber.org', 'Der elmex', ['ABC', 'TEst'], sub {
82 elmex 1.3 # $roster->get_contact ('elmex@jabber.org')->send_subscribe;
83     # $roster->delete_contact ('elmex@jabber.org');
84 elmex 1.5 # });
85 elmex 1.6 #$cl->remove_accounts ("TEST");
86 elmex 1.3
87     0
88     });
89    
90 elmex 1.1 $cl->start;
91    
92     $j->wait;