source: perl/modules/Jabber/lib/Net/Jabber/Dialback/Result.pm @ 2b66c361

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 2b66c361 was c2bed55, checked in by Nelson Elhage <nelhage@mit.edu>, 18 years ago
Moving Net::Jabber into Jabber.par
  • Property mode set to 100755
File size: 6.8 KB
Line 
1##############################################################################
2#
3#  This library is free software; you can redistribute it and/or
4#  modify it under the terms of the GNU Library General Public
5#  License as published by the Free Software Foundation; either
6#  version 2 of the License, or (at your option) any later version.
7#
8#  This library is distributed in the hope that it will be useful,
9#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11#  Library General Public License for more details.
12#
13#  You should have received a copy of the GNU Library General Public
14#  License along with this library; if not, write to the
15#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16#  Boston, MA  02111-1307, USA.
17#
18#  Jabber
19#  Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
20#
21##############################################################################
22
23package Net::Jabber::Dialback::Result;
24
25=head1 NAME
26
27Net::Jabber::Dialback::Result - Jabber Dialback Result Module
28
29=head1 SYNOPSIS
30
31  Net::Jabber::Dialback::Result is a companion to the Net::Jabber::Dialback
32  module.  It provides the user a simple interface to set and retrieve all
33  parts of a Jabber Dialback Result.
34
35=head1 DESCRIPTION
36
37  To initialize the Result with a Jabber <db:*/> you must pass it
38  the XML::Stream hash.  For example:
39
40    my $dialback = Net::Jabber::Dialback::Result->new(%hash);
41
42  There has been a change from the old way of handling the callbacks.
43  You no longer have to do the above yourself, a NJ::Dialback::Result
44  object is passed to the callback function for the message.  Also,
45  the first argument to the callback functions is the session ID from
46  XML::Streams.  There are some cases where you might want this
47  information, like if you created a Client that connects to two servers
48  at once, or for writing a mini server.
49
50    use Net::Jabber qw(Server);
51
52    sub dialbackResult {
53      my ($sid,$Result) = @_;
54      .
55      .
56      .
57    }
58
59  You now have access to all of the retrieval functions available.
60
61  To create a new dialback to send to the server:
62
63    use Net::Jabber qw(Server);
64
65    $Result = Net::Jabber::Dialback::Result->new();
66
67  Now you can call the creation functions below to populate the tag before
68  sending it.
69
70  For more information about the array format being passed to the CallBack
71  please read the Net::Jabber::Client documentation.
72
73=head2 Retrieval functions
74
75    $to         = $Result->GetTo();
76    $from       = $Result->GetFrom();
77    $type       = $Result->GetType();
78
79    $data       = $Result->GetData();
80
81    $str        = $Result->GetXML();
82    @dialback   = $Result->GetTree();
83
84=head2 Creation functions
85
86    $Result->SetResult(from=>"jabber.org",
87                       to=>"jabber.com",
88                       data=>key);
89    $Result->SetTo("jabber.org");
90    $Result->SetFrom("jabber.com");
91    $Result->SetType("valid");
92    $Result->SetData(key);
93
94=head2 Test functions
95
96    $test = $Result->DefinedTo();
97    $test = $Result->DefinedFrom();
98    $test = $Result->DefinedType();
99
100=head1 METHODS
101
102=head2 Retrieval functions
103
104  GetTo() -  returns a string with server that the <db:result/> is being
105             sent to.
106
107  GetFrom() -  returns a string with server that the <db:result/> is being
108               sent from.
109
110  GetType() - returns a string with the type <db:result/> this is.
111
112  GetData() - returns a string with the cdata of the <db:result/>.
113
114  GetXML() - returns the XML string that represents the <db:result/>.
115             This is used by the Send() function in Server.pm to send
116             this object as a Jabber Dialback Result.
117
118  GetTree() - returns an array that contains the <db:result/> tag
119              in XML::Parser::Tree format.
120
121=head2 Creation functions
122
123  SetResult(to=>string,   - set multiple fields in the <db:result/>
124            from=>string,   at one time.  This is a cumulative
125            type=>string,   and over writing action.  If you set
126            data=>string)   the "from" attribute twice, the second
127                            setting is what is used.  If you set
128                            the type, and then set the data
129                            then both will be in the <db:result/>
130                            tag.  For valid settings read the
131                            specific Set functions below.
132
133  SetTo(string) - sets the to attribute.
134
135  SetFrom(string) - sets the from attribute.
136
137  SetType(string) - sets the type attribute.  Valid settings are:
138
139                    valid
140                    invalid
141
142  SetData(string) - sets the cdata of the <db:result/>.
143
144=head2 Test functions
145
146  DefinedTo() - returns 1 if the to attribute is defined in the
147                <db:result/>, 0 otherwise.
148
149  DefinedFrom() - returns 1 if the from attribute is defined in the
150                  <db:result/>, 0 otherwise.
151
152  DefinedType() - returns 1 if the type attribute is defined in the
153                  <db:result/>, 0 otherwise.
154
155=head1 AUTHOR
156
157By Ryan Eatmon in May of 2001 for http://jabber.org..
158
159=head1 COPYRIGHT
160
161This module is free software; you can redistribute it and/or modify
162it under the same terms as Perl itself.
163
164=cut
165
166require 5.003;
167use strict;
168use Carp;
169use vars qw($VERSION $AUTOLOAD %FUNCTIONS);
170
171$VERSION = "2.0";
172
173sub new
174{
175    my $proto = shift;
176    my $class = ref($proto) || $proto;
177    my $self = { };
178
179    $self->{VERSION} = $VERSION;
180
181    bless($self, $proto);
182
183    $self->{DEBUGHEADER} = "DB:Result";
184
185    $self->{DATA} = {};
186    $self->{CHILDREN} = {};
187
188    $self->{TAG} = "db:result";
189
190    if ("@_" ne (""))
191    {
192        if (ref($_[0]) eq "Net::Jabber::Dialback::Result")
193        {
194            return $_[0];
195        }
196        else
197        {
198            $self->{TREE} = shift;
199            $self->ParseTree();
200        }
201    }
202
203    return $self;
204}
205
206
207##############################################################################
208#
209# AUTOLOAD - This function calls the main AutoLoad function in Jabber.pm
210#
211##############################################################################
212sub AUTOLOAD
213{
214    my $self = shift;
215    &Net::Jabber::AutoLoad($self,$AUTOLOAD,@_);
216}
217
218$FUNCTIONS{From}->{Get}        = "from";
219$FUNCTIONS{From}->{Set}        = ["jid","from"];
220$FUNCTIONS{From}->{Defined}    = "from";
221$FUNCTIONS{From}->{Hash}       = "att";
222
223$FUNCTIONS{Data}->{Get}        = "data";
224$FUNCTIONS{Data}->{Set}        = ["scalar","data"];
225$FUNCTIONS{Data}->{Defined}    = "data";
226$FUNCTIONS{Data}->{Hash}       = "data";
227
228$FUNCTIONS{To}->{Get}        = "to";
229$FUNCTIONS{To}->{Set}        = ["jid","to"];
230$FUNCTIONS{To}->{Defined}    = "to";
231$FUNCTIONS{To}->{Hash}       = "att";
232
233$FUNCTIONS{Type}->{Get}        = "type";
234$FUNCTIONS{Type}->{Set}        = ["scalar","type"];
235$FUNCTIONS{Type}->{Defined}    = "type";
236$FUNCTIONS{Type}->{Hash}       = "att";
237
238$FUNCTIONS{Result}->{Get} = "__netjabber__:master";
239$FUNCTIONS{Result}->{Set} = ["master"];
240
2411;
242
Note: See TracBrowser for help on using the repository browser.