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

# 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.8 $cl->add_account (@ARGV);
29 elmex 1.1 $cl->reg_cb (
30     connected => sub {
31 elmex 1.7 $cl->send_message ("Hello!" => 'elmex@jabbfer.org');
32 elmex 1.1 0
33     },
34 elmex 1.3 roster_update => sub {
35     my ($cl, $acc, $roster, $contacts) = @_;
36     $roster->debug_dump;
37 elmex 1.7 $acc->connection ()->send_presence ('probe' => undef, to => 'elmex@jabfber.org');
38 elmex 1.8 print "OEOFWEFIEJWFEWO\n" if not $roster->is_retrieved;
39 elmex 1.3 1
40     },
41     presence_update => sub {
42     my ($cl, $acc, $roster, $contact, $old, $new) = @_;
43     $roster->debug_dump;
44     1
45     },
46 elmex 1.2 sasl_error => sub {
47     my ($cl, $acc, $error) = @_;
48     print "SASL ERROR".$error->string."\n";
49 elmex 1.6 },
50 elmex 1.7 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 elmex 1.6 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 elmex 1.1 );
70    
71 elmex 1.4 $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 elmex 1.3 $cl->reg_cb (roster_update => sub {
85     my ($cl, $acc, $roster, $contacts) = @_;
86    
87 elmex 1.6 $roster->debug_dump;
88 elmex 1.8 # $roster->new_contact ('elmex@jabber.org', 'Der elmex', ['ABC', 'TEst'], sub {
89 elmex 1.3 # $roster->get_contact ('elmex@jabber.org')->send_subscribe;
90     # $roster->delete_contact ('elmex@jabber.org');
91 elmex 1.5 # });
92 elmex 1.6 #$cl->remove_accounts ("TEST");
93 elmex 1.3
94     0
95     });
96    
97 elmex 1.1 $cl->start;
98    
99     $j->wait;