ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/Ext/Registration.pm
Revision: 1.4
Committed: Fri Jul 20 20:41:48 2007 UTC (19 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.3: +1 -0 lines
Log Message:
lots of changes. added as_string to Net::XMPP2::Node to restore
the original xml document part of a stanza or subtree.
also implemented the jabber component protocol.

File Contents

# Content
1 package Net::XMPP2::Ext::Registration;
2 use strict;
3 use Net::XMPP2::Util;
4 use Net::XMPP2::Namespaces qw/xmpp_ns/;
5 use Net::XMPP2::Ext::RegisterForm;
6
7 =head1 NAME
8
9 Net::XMPP2::Ext::Registration - Handles all tasks of in band registration
10
11 =head1 SYNOPSIS
12
13 my $con = Net::XMPP2::Connection->new (...);
14
15 $con->reg_cb (stream_pre_authentication => sub {
16 my ($con, $rcont) = @_;
17
18 my $reg = Net::XMPP2::Ext::Registration->new;
19 $reg->send_registration_request ($con, sub {
20 my ($reg, $con, $form, $error) = @_;
21
22 if ($form) {
23 my $res = $form->try_fillout_registration ('myusername', 'mypassword');
24
25 $reg->submit_form ($con, $res, sub {
26 my ($reg, $con, $ok, $error) = @_;
27
28 if ($ok) {
29 $con->authenticate; # just make sure the connection knows your
30 # username and password :-)
31 } else {
32 print "error: " . $error->string . "\n";
33 }
34 });
35
36 } else {
37 print "error: " . $error->string . "\n";
38 }
39 });
40
41 $$rcont = 0;
42 0
43 });
44
45 =head1 DESCRIPTION
46
47 This module handles all tasks of in band registration that are
48 possible and specified by XEP-0077. (NOT IMPLEMENTED YET!)
49
50 =cut
51
52 =head1 METHODS
53
54 =over 4
55
56 =item B<new (%args)>
57
58 This is the constructor for a registration object.
59 C<%args> is a hash which can have the following keys:
60
61 NOTE: the C<connection> argument is required.
62
63 =over 4
64
65 =item connection
66
67 This must be a L<Net::XMPP2::Connection> (or some other subclass of that) object.
68
69 This argument is required.
70
71 =back
72
73 =cut
74
75 sub new {
76 my $this = shift;
77 my $class = ref($this) || $this;
78 my $self = bless { @_ }, $class;
79 $self->init;
80 $self
81 }
82
83 sub init {
84 my ($self) = @_;
85 }
86
87 =item B<send_registration_request ($con, $cb)>
88
89 This method sends a register form request.
90 C<$cb> will be called when either the form arrived or
91 an error occured.
92
93 The first argument of C<$cb> is always C<$self>.
94 If the form arrived the second argument of C<$cb> will be
95 a L<Net::XMPP2::Ext::RegisterForm> object.
96 If an error occured the second argument will be undef
97 and the third argument will be a L<Net::XMPP2::Error::Register>
98 object.
99
100 =cut
101
102 sub send_registration_request {
103 my ($self, $con, $cb) = @_;
104
105 $con->send_iq (get => {
106 defns => 'register',
107 node => { ns => 'register', name => 'query' }
108 }, sub {
109 my ($node, $error) = @_;
110
111 my $form;
112 if ($node) {
113 $form = Net::XMPP2::Ext::RegisterForm->new;
114 $form->init_from_node ($node);
115 }
116
117 $cb->($self, $con, $form, $error);
118 });
119 }
120
121 =item B<submit_form ($con, $form, $cb)>
122
123 =back
124
125 =head1 AUTHOR
126
127 Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
128
129 =head1 COPYRIGHT & LICENSE
130
131 Copyright 2007 Robin Redeker, all rights reserved.
132
133 This program is free software; you can redistribute it and/or modify it
134 under the same terms as Perl itself.
135
136 =cut
137
138 1; # End of Net::XMPP2::Ext::Registration