3 # Copyright (c) 1995 Graham Barr <Graham.Barr@tiuk.ti.com>. All rights
4 # reserved. This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
11 Net::SNPP - Simple Network Pager Protocol Client
18 $snpp = Net::SNPP->new('snpphost');
19 $snpp = Net::SNPP->new('snpphost', Timeout => 60);
23 This module is not complete, yet !
27 This module implements a client interface to the SNPP protocol, enabling
28 a perl5 application to talk to SNPP servers. This documentation assumes
29 that you are familiar with the SNPP protocol described in RFC1861.
31 A new Net::SNPP object must be created with the I<new> method. Once
32 this has been done, all SNPP commands are accessed through this object.
36 This example will send a pager message in one hour saying "Your lunch is ready"
38 #!/usr/local/bin/perl -w
42 $snpp = Net::SNPP->new('snpphost');
44 $snpp->send( Pager => $some_pager_number,
45 Message => "Your lunch is ready",
47 Hold => time + 3600, # lunch ready in 1 hour :-)
48 ) || die $snpp->message;
56 =item new ( HOST, [ OPTIONS ] )
58 This is the constructor for a new Net::SNPP object. C<HOST> is the
59 name of the remote host to which a SNPP connection is required.
61 C<OPTIONS> are passed in a hash like fasion, using key and value pairs.
64 B<Timeout> - Maximum time, in seconds, to wait for a response from the
65 SNPP server (default: 120)
67 B<Debug> - Enable debugging information
73 $snpp = Net::SNPP->new('snpphost',
79 Unless otherwise stated all methods return either a I<true> or I<false>
80 value, with I<true> meaning that the operation was a success. When a method
81 states that it returns a value, falure will be returned as I<undef> or an
90 Request help text from the server. Returns the text or undef upon failure
94 Send the QUIT command to the remote SNPP server and close the socket connection.
100 C<Net::SNPP> exports all that C<Net::CMD> exports, plus three more subroutines
101 that can bu used to compare against the result of C<status>. These are :-
102 C<CMD_2WAYERROR>, C<CMD_2WAYOK>, and C<CMD_2WAYQUEUED>.
111 Graham Barr <Graham.Barr@tiuk.ti.com>
116 $Date: 1996/07/26 06:49:13 $
118 The VERSION is derived from the revision by changing each number after the
119 first dot into a 2 digit number so
121 Revision 1.8 => VERSION 1.08
122 Revision 1.2.3 => VERSION 1.0203
126 Copyright (c) 1995 Graham Barr. All rights reserved. This program is free
127 software; you can redistribute it and/or modify it under the same terms
135 use vars qw($VERSION @ISA @EXPORT);
141 $VERSION = do{my @r=(q$Revision: 1.1 $=~/(\d+)/g);sprintf "%d."."%02d"x$#r,@r};
142 @ISA = qw(Net::Cmd IO::Socket::INET);
143 @EXPORT = qw(CMD_2WAYERROR CMD_2WAYOK CMD_2WAYQUEUED);
145 sub CMD_2WAYERROR { 7 }
147 sub CMD_2WAYQUEUED { 9 }
152 my $callpkg = caller;
157 @export{@_} = (1) x @_;
159 foreach $export (@EXPORT)
161 if(exists $export{$export})
163 push(@export,$export);
164 delete $export{$export};
168 Exporter::export 'Net::SNPP', $callpkg, @export
169 if(@_ == 0 || @export);
171 @export = keys %export;
172 Exporter::export 'Net::Cmd', $callpkg, @export
173 if(@_ == 0 || @export);
179 my $type = ref($self) || $self;
182 my $obj = $type->SUPER::new(PeerAddr => $host,
183 PeerPort => $arg{Port} || 'snpp(444)',
185 Timeout => defined $arg{Timeout}
192 $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
194 unless ($obj->response() == CMD_OK)
196 $obj->SUPER::close();
204 ## User interface methods
209 @_ == 2 or croak 'usage: $snpp->pager_id( PAGER_ID )';
215 @_ == 2 or croak 'usage: $snpp->content( MESSAGE )';
227 $me->_PAGE($arg{Pager}) || return 0
228 if(exists $arg{Pager});
230 $me->_MESS($arg{Message}) || return 0
231 if(exists $arg{Message});
233 $me->hold($arg{Hold}) || return 0
234 if(exists $arg{Hold});
236 $me->hold($arg{HoldLocal},1) || return 0
237 if(exists $arg{HoldLocal});
239 $me->_COVE($arg{Coverage}) || return 0
240 if(exists $arg{Coverage});
242 $me->_ALER($arg{Alert} ? 1 : 0) || return 0
243 if(exists $arg{Alert});
245 $me->service_level($arg{ServiceLevel}) || return 0
246 if(exists $arg{ServiceLevel});
256 my $ok = $me->_DATA() && $me->datasend(@_);
266 @_ == 2 || @_ == 3 or croak 'usage: $snpp->login( USER [, PASSWORD ])';
272 @_ == 1 or croak 'usage: $snpp->help()';
275 return $me->_HELP() ? $me->message
281 @_ == 2 or croak 'usage: $snpp->service_level( LEVEL )';
283 my $levl = int(shift);
286 if($level < 0 || $level > 11)
288 $me->set_status(550,"Invalid Service Level");
297 @_ == 1 || @_ == 2 or croak 'usage: $snpp->alert( VALUE )';
299 my $value = (@_ == 1 || shift) ? 1 : 0;
306 @_ == 1 or croak 'usage: $snpp->coverage( AREA )';
312 @_ == 2 || @_ == 3 or croak 'usage: $snpp->hold( TIME [, LOCAL ] )';
315 my $local = shift ? "" : " +0000";
317 my @g = reverse((gmtime($time))[0..5]);
321 $me->_HOLD( sprintf("%02d%02d%02d%02d%02d%02d%s",@g,$local));
326 @_ == 2 or croak 'usage: $snpp->caller_id( CALLER_ID )';
332 @_ == 2 or croak 'usage: $snpp->subject( SUBJECT )';
338 @_ == 1 or croak 'usage: $snpp->two_way()';
347 unless (ref($me) && defined fileno($me));
349 $me->_QUIT && $me->SUPER::close;
352 sub DESTROY { shift->close }
353 sub quit { shift->close }
356 ## Over-ride methods (Net::Cmd)
361 $_[2] =~ s/^((logi|page)\s+\S+\s+)\S*/$1 xxxx/io;
370 sub _PAGE { shift->command("PAGE", @_)->response() == CMD_OK }
371 sub _MESS { shift->command("MESS", @_)->response() == CMD_OK }
372 sub _RESE { shift->command("RESE")->response() == CMD_OK }
373 sub _SEND { shift->command("SEND")->response() == CMD_OK }
374 sub _QUIT { shift->command("QUIT")->response() == CMD_OK }
375 sub _HELP { shift->command("HELP")->response() == CMD_OK }
376 sub _DATA { shift->command("DATA")->response() == CMD_MORE }
380 sub _LOGI { shift->command("LOGI", @_)->response() == CMD_OK }
381 sub _LEVE { shift->command("LEVE", @_)->response() == CMD_OK }
382 sub _ALER { shift->command("ALER", @_)->response() == CMD_OK }
383 sub _COVE { shift->command("COVE", @_)->response() == CMD_OK }
384 sub _HOLD { shift->command("HOLD", @_)->response() == CMD_OK }
385 sub _CALL { shift->command("CALL", @_)->response() == CMD_OK }
386 sub _SUBJ { shift->command("SUBJ", @_)->response() == CMD_OK }