This file is indexed.

/usr/share/perl5/Net/Jabber/Server.pm is in libnet-jabber-perl 2.0-6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
##############################################################################
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Library General Public
#  License as published by the Free Software Foundation; either
#  version 2 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Library General Public License for more details.
#
#  You should have received a copy of the GNU Library General Public
#  License along with this library; if not, write to the
#  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA  02111-1307, USA.
#
#  Jabber
#  Copyright (C) 1998-1999 The Jabber Team http://jabber.org/
#
##############################################################################

package Net::Jabber::Server;

=head1 NAME

Net::Jabber::Server - Jabber Server Library

=head1 SYNOPSIS

  Net::Jabber::Server is a module that provides a developer easy access
  to developing applications that need an embedded Jabber server.

=head1 DESCRIPTION

  Server.pm seeks to provide enough high level APIs and automation of
  the low level APIs that writing and spawning a Jabber Server in Perl
  is trivial.  For those that wish to work with the low level you can
  do that too, but those functions are covered in the documentation for
  each module.

  Net::Jabber::Server provides functions to run a full Jabber server that
  accepts incoming connections and delivers packets to external Jabber
  servers.  You can use all or none of the functions, there is no requirement.

  For more information on how the details for how Net::Jabber is written
  please see the help for Net::Jabber itself.

  For a full list of high level functions available please see
  Net::Jabber::Protocol.

=head2 Basic Functions

    use Net::Jabber qw(Server);

    $Server = new Net::Jabber::Server();

    $Server->Start();
    $Server->Start(jabberxml=>"custom_jabber.xml",
	           hostname=>"foobar.net");

    %status = $Server->Process();
    %status = $Server->Process(5);
    
    $Server->Stop();

=head1 METHODS

=head2 Basic Functions

    new(debuglevel=>0|1|2, - creates the Server object.  debugfile
        debugfile=>string,   should be set to the path for the debug
        debugtime=>0|1)      log to be written.  If set to "stdout"
                             then the debug will go there.  debuglevel
                             controls the amount of debug.  For more
                             information about the valid setting for
                             debuglevel, debugfile, and debugtime see
                             Net::Jabber::Debug.

    Start(hostname=>string, - starts the server listening on the proper
	  jaberxml=>string)   ports.  hostname is a quick way of telling
                              the server the hostname to listen on.
                              jabberxml defines the path to a different
                              jabberd configuration file (default is
                              "./jabber.xml").

    Process(integer) - takes the timeout period as an argument.  If no
                       timeout is listed then the function blocks until
                       a packet is received.  Otherwise it waits that
                       number of seconds and then exits so your program
                       can continue doing useful things.  NOTE: This is
                       important for GUIs.  You need to leave time to
                       process GUI commands even if you are waiting for
                       packets.  The following are the possible return
                       values for each hash entry, and what they mean:

                           1   - Status ok, data received.
                           0   - Status ok, no data received.
                         undef - Status not ok, stop processing.
                       
                       IMPORTANT: You need to check the output of every
                       Process.  If you get an undef then the connection
                       died and you should behave accordingly.

    Stop() - stops the server from running and shuts down all sub programs.

=head1 AUTHOR

By Ryan Eatmon in January of 2001 for http://jabber.org.

=head1 COPYRIGHT

This module is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

use strict;
use Carp;
use base qw( Net::Jabber::Protocol );
use vars qw( $VERSION );

$VERSION = "2.0";

use Net::Jabber::Data;
($Net::Jabber::Data::VERSION < $VERSION) &&
  die("Net::Jabber::Data $VERSION required--this is only version $Net::Jabber::Data::VERSION");

use Net::Jabber::XDB;
($Net::Jabber::XDB::VERSION < $VERSION) &&
  die("Net::Jabber::XDB $VERSION required--this is only version $Net::Jabber::XDB::VERSION");

#use Net::Jabber::Log;
#($Net::Jabber::Log::VERSION < $VERSION) &&
#  die("Net::Jabber::Log $VERSION required--this is only version $Net::Jabber::Log::VERSION");

use Net::Jabber::Dialback;
($Net::Jabber::Dialback::VERSION < $VERSION) &&
  die("Net::Jabber::Dialback $VERSION required--this is only version $Net::Jabber::Dialback::VERSION");

use Net::Jabber::Key;
($Net::Jabber::Key::VERSION < $VERSION) &&
  die("Net::Jabber::Key $VERSION required--this is only version $Net::Jabber::Key::VERSION");

sub new
{
    srand( time() ^ ($$ + ($$ << 15)));

    my $proto = shift;
    my $self = { };

    my %args;
    while($#_ >= 0) { $args{ lc(pop(@_)) } = pop(@_); }

    bless($self, $proto);

    $self->{KEY} = new Net::Jabber::Key();

    $self->{DEBUG} =
        new Net::Jabber::Debug(level=>exists($args{debuglevel}) ? $args{debuglevel} : -1,
                               file=>exists($args{debugfile}) ? $args{debugfile} : "stdout",
                               time=>exists($args{debugtime}) ? $args{debugtime} : 0,
                               setdefault=>1,
                               header=>"NJ::Server"
                              );

    $self->{SERVER} = { hostname => "localhost",
                        port => 5269,
                        servername => ""};

    $self->{STREAM} = new XML::Stream(style=>"node",
                                      debugfh=>$self->{DEBUG}->GetHandle(),
                                      debuglevel=>$self->{DEBUG}->GetLevel(),
                                      debugtime=>$self->{DEBUG}->GetTime());

    $self->{STREAM}->SetCallBacks(node=>sub{ $self->CallBack(@_) },
                                  sid=>sub{ return $self->{KEY}->Generate()});

    $self->{VERSION} = $VERSION;

    return $self;
}


##############################################################################
#
# Start - starts the server running
#
##############################################################################
sub Start
{
    my $self = shift;
    my %args;
    while($#_ >= 0) { $args{ lc pop(@_) } = pop(@_); }

    $self->{STOP} = 0;

    $self->SetCallBacks('message'=>sub{ $self->messageHandler(@_); },
                        'presence'=>sub{ $self->presenceHandler(@_); },
                        'iq'=>sub{ $self->iqHandler(@_); },
                        'db:result'=>sub{ $self->dbresultHandler(@_); },
                        'db:verify'=>sub{ $self->dbverifyHandler(@_); },
                       );

    my $hostname = $self->{SERVER}->{hostname};
    $hostname = $args{hostname} if exists($args{hostname});

    my $status = $self->{STREAM}->Listen(hostname=>$hostname,
                         port=>$self->{SERVER}->{port},
                         namespace=>"jabber:server");

    while($self->{STOP} == 0) {
        while(($self->{STOP} == 0) && defined($self->{STREAM}->Process())) {
        }
    }
}


###############################################################################
#
#  Process - If a timeout value is specified then the function will wait
#            that long before returning.  This is useful for apps that
#            need to handle other processing while still waiting for
#            packets.  If no timeout is listed then the function waits
#            until a packet is returned.  Either way the function exits
#            as soon as a packet is returned.
#
###############################################################################
sub Process
{
    my $self = shift;
    my ($timeout) = @_;
    my %status;

    if (exists($self->{PROCESSERROR}) && ($self->{PROCESSERROR} == 1))
    {
        croak("You should always check the output of the Process call.  If it was undef\nthen there was a fatal error that you need to check.  There is an error in your\nprogram.");
    }

    $self->{DEBUG}->Log1("Process: timeout($timeout)") if defined($timeout);

    if (!defined($timeout) || ($timeout eq ""))
    {
        while(1)
        {
            %status = $self->{STREAM}->Process();
            $self->{DEBUG}->Log1("Process: status($status{$self->{SESSION}->{id}})");
            last if ($status{$self->{SESSION}->{id}} != 0);
            select(undef,undef,undef,.25);
        }
        $self->{DEBUG}->Log1("Process: return($status{$self->{SESSION}->{id}})");
        if ($status{$self->{SESSION}->{id}} == -1)
        {
            $self->{PROCESSERROR} = 1;
            return;
        }
        else
        {
            return $status{$self->{SESSION}->{id}};
        }
    }
    else
    {
        %status = $self->{STREAM}->Process($timeout);
        if ($status{$self->{SESSION}->{id}} == -1)
        {
            $self->{PROCESSERROR} = 1;
            return;
        }
        else
        {
            return $status{$self->{SESSION}->{id}};
        }
    }
}


##############################################################################
#
# Stop - shuts down the server
#
##############################################################################
sub Stop
{
    my $self = shift;
    $self->{STOP} = 1;
}


sub messageHandler
{
    my $self = shift;
    my $sid = shift;
    my ($message) = @_;

    $self->{DEBUG}->Log2("messageHandler: message(",$message->GetXML(),")");

    my $reply = $message->Reply();
    $self->Send($reply);
}


sub presenceHandler
{
    my $self = shift;
    my $sid = shift;
    my ($presence) = @_;

    $self->{DEBUG}->Log2("presenceHandler: presence(",$presence->GetXML(),")");
}


sub iqHandler
{
    my $self = shift;
    my $sid = shift;
    my ($iq) = @_;

    $self->{DEBUG}->Log2("iqHandler: iq(",$iq->GetXML(),")");
}


sub dbresultHandler
{
    my $self = shift;
    my $sid = shift;
    my ($dbresult) = @_;

    $self->{DEBUG}->Log2("dbresultHandler: dbresult(",$dbresult->GetXML(),")");

    my $dbverify = new Net::Jabber::Dialback::Verify();
    $dbverify->SetVerify(to=>$dbresult->GetFrom(),
                         from=>$dbresult->GetTo(),
                         id=>$self->{STREAM}->GetRoot($sid)->{id},
                         data=>$dbresult->GetData());
    $self->Send($dbverify);
}


sub dbverifyHandler
{
    my $self = shift;
    my $sid = shift;
    my ($dbverify) = @_;

    $self->{DEBUG}->Log2("dbverifyHandler: dbverify(",$dbverify->GetXML(),")");
}


sub Send
{
    my $self = shift;
    my $object = shift;

    if (ref($object) eq "")
    {
        my ($server) = ($object =~ /to=[\"\']([^\"\']+)[\"\']/);
        $server =~ s/^\S*\@?(\S+)\/?.*$/$1/;
        $self->SendXML($server,$object);
    }
    else
    {
        $self->SendXML($object->GetTo("jid")->GetServer(),$object->GetXML());
    }
 }


sub SendXML {
    my $self = shift;
    my $server = shift;
    my $xml = shift;
    $self->{DEBUG}->Log1("SendXML: server($server) sent($xml)");

    my $sid = $self->{STREAM}->Host2SID($server);
    if (!defined($sid)) {
        $self->{STREAM}->Connect(hostname=>$server,
                     port=>5269,
                     connectiontype=>"tcpip",
                     namespace=>"jabber:server");
        $sid = $self->{STREAM}->Host2SID($server);
    }
    $self->{DEBUG}->Log1("SendXML: sid($sid)");
    &{$self->{CB}->{send}}($sid,$xml) if exists($self->{CB}->{send});
    $self->{STREAM}->Send($sid,$xml);
}


#
# by not send xmlns:db='jabber:server:dialback' to a server, we operate in
# legacy mode, and do not have to do dialback.
#

1;