ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-XMPP2/lib/Net/XMPP2/Ext/Registration.pm
Revision: 1.3
Committed: Thu Jul 19 11:36:33 2007 UTC (19 years, 2 months ago) by elmex
Branch: MAIN
Changes since 1.2: +17 -3 lines
Log Message:
added initial_presence argument to the IM::Connection and the
Client. added and upgraded some examples. further work on the
registration forms.

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