ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/Ext/Registration.pm
Revision: 1.5
Committed: Wed Jul 25 13:53:33 2007 UTC (19 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.4: +6 -0 lines
Log Message:
implemented OOB and fixed bugs in Disco and further developed in band registration.

File Contents

# User Rev Content
1 elmex 1.1 package Net::XMPP2::Ext::Registration;
2     use strict;
3     use Net::XMPP2::Util;
4     use Net::XMPP2::Namespaces qw/xmpp_ns/;
5 elmex 1.4 use Net::XMPP2::Ext::RegisterForm;
6 elmex 1.1
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 elmex 1.2 possible and specified by XEP-0077. (NOT IMPLEMENTED YET!)
49 elmex 1.1
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 elmex 1.3 =item B<send_registration_request ($con, $cb)>
88 elmex 1.1
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 elmex 1.3 my ($self, $con, $cb) = @_;
104 elmex 1.1
105 elmex 1.3 $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 elmex 1.1
117 elmex 1.3 $cb->($self, $con, $form, $error);
118     });
119     }
120 elmex 1.1
121 elmex 1.3 =item B<submit_form ($con, $form, $cb)>
122 elmex 1.1
123 elmex 1.5 =cut
124    
125     sub submit_form {
126     my ($self, $con, $form, $cb) = @_;
127     }
128    
129 elmex 1.2 =back
130    
131 elmex 1.1 =head1 AUTHOR
132    
133     Robin Redeker, C<< <elmex at ta-sa.org> >>, JID: C<< <elmex at jabber.org> >>
134    
135     =head1 COPYRIGHT & LICENSE
136    
137     Copyright 2007 Robin Redeker, all rights reserved.
138    
139     This program is free software; you can redistribute it and/or modify it
140     under the same terms as Perl itself.
141    
142     =cut
143    
144     1; # End of Net::XMPP2::Ext::Registration