releasing/cbrtools/perl/Net/SNPP.pm
author jjkang
Wed, 30 Jun 2010 11:35:58 +0800
changeset 607 378360dbbdba
parent 602 3145852acc89
permissions -rw-r--r--
Merge missed changeset 11 (raptor v2.14 and helium 10.0)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Net::SNPP.pm
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com>. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This program is free software; you can redistribute it and/or
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# modify it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
package Net::SNPP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
require 5.001;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
use Socket 1.3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
use Carp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
use IO::Socket;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
use Net::Cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
use Net::Config;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
$VERSION = "1.11"; # $Id:$
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
@ISA     = qw(Net::Cmd IO::Socket::INET);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
@EXPORT  = (qw(CMD_2WAYERROR CMD_2WAYOK CMD_2WAYQUEUED), @Net::Cmd::EXPORT);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
sub CMD_2WAYERROR  () { 7 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
sub CMD_2WAYOK     () { 8 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
sub CMD_2WAYQUEUED () { 9 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
sub new
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
 my $self = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
 my $type = ref($self) || $self;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
 my $host = shift if @_ % 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
 my %arg  = @_; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
 my $hosts = defined $host ? [ $host ] : $NetConfig{snpp_hosts};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
 my $obj;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
 my $h;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
 foreach $h (@{$hosts})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
   $obj = $type->SUPER::new(PeerAddr => ($host = $h), 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
			    PeerPort => $arg{Port} || 'snpp(444)',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
			    Proto    => 'tcp',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
			    Timeout  => defined $arg{Timeout}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
						? $arg{Timeout}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
						: 120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
			    ) and last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
	unless defined $obj;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
 ${*$obj}{'net_snpp_host'} = $host;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
 $obj->autoflush(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
 $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
 unless ($obj->response() == CMD_OK)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
   $obj->close();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
   return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
 $obj;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
## User interface methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
sub pager_id
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
 @_ == 2 or croak 'usage: $snpp->pager_id( PAGER_ID )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
 shift->_PAGE(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
sub content
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
 @_ == 2 or croak 'usage: $snpp->content( MESSAGE )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
 shift->_MESS(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
sub send
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
 if(@_)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
   my %arg = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
   if(exists $arg{Pager})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
     my $pagers = ref($arg{Pager}) ? $arg{Pager} : [ $arg{Pager} ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
     my $pager;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
     foreach $pager (@$pagers)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
       $me->_PAGE($pager) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
   $me->_MESS($arg{Message}) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
	if(exists $arg{Message});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
   $me->hold($arg{Hold}) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
	if(exists $arg{Hold});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
   $me->hold($arg{HoldLocal},1) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
	if(exists $arg{HoldLocal});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
   $me->_COVE($arg{Coverage}) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
	if(exists $arg{Coverage});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
   $me->_ALER($arg{Alert} ? 1 : 0) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
	if(exists $arg{Alert});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
   $me->service_level($arg{ServiceLevel}) || return 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
	if(exists $arg{ServiceLevel});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
 $me->_SEND();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
sub data
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
 my $ok = $me->_DATA() && $me->datasend(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
 return $ok
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
	unless($ok && @_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
 $me->dataend;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
sub login
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
 @_ == 2 || @_ == 3 or croak 'usage: $snpp->login( USER [, PASSWORD ])';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
 shift->_LOGI(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
sub help
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
 @_ == 1 or croak 'usage: $snpp->help()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
 return $me->_HELP() ? $me->message
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
		     : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
sub xwho
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
 @_ == 1 or croak 'usage: $snpp->xwho()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
 $me->_XWHO or return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
 my(%hash,$line);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
 my @msg = $me->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
 pop @msg; # Remove command complete line
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
 foreach $line (@msg) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
   $line =~ /^\s*(\S+)\s*(.*)/ and $hash{$1} = $2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
 \%hash;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
sub service_level
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
 @_ == 2 or croak 'usage: $snpp->service_level( LEVEL )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
 my $level = int(shift);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
 if($level < 0 || $level > 11)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
   $me->set_status(550,"Invalid Service Level");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
   return 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
 $me->_LEVE($level);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
sub alert
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
 @_ == 1 || @_ == 2 or croak 'usage: $snpp->alert( VALUE )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
 my $value  = (@_ == 1 || shift) ? 1 : 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
 $me->_ALER($value);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
sub coverage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
 @_ == 1 or croak 'usage: $snpp->coverage( AREA )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
 shift->_COVE(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
sub hold
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
 @_ == 2 || @_ == 3 or croak 'usage: $snpp->hold( TIME [, LOCAL ] )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
 my $me = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
 my $time = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
 my $local = (shift) ? "" : " +0000";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
 my @g = reverse((gmtime($time))[0..5]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
 $g[1] += 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
 $g[0] %= 100;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
 $me->_HOLD( sprintf("%02d%02d%02d%02d%02d%02d%s",@g,$local));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
sub caller_id
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
 @_ == 2 or croak 'usage: $snpp->caller_id( CALLER_ID )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
 shift->_CALL(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
sub subject
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
 @_ == 2 or croak 'usage: $snpp->subject( SUBJECT )';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
 shift->_SUBJ(@_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
sub two_way
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
 @_ == 1 or croak 'usage: $snpp->two_way()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
 shift->_2WAY();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
sub quit
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
 @_ == 1 or croak 'usage: $snpp->quit()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
 my $snpp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
 $snpp->_QUIT;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
 $snpp->close;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
## IO/perl methods
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
sub DESTROY
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
 my $snpp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
 defined(fileno($snpp)) && $snpp->quit
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
## Over-ride methods (Net::Cmd)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
sub debug_text
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
 $_[2] =~ s/^((logi|page)\s+\S+\s+)\S+/$1 xxxx/io;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
 $_[2];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
sub parse_response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
 return ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
    unless $_[1] =~ s/^(\d\d\d)(.?)//o;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
 my($code,$more) = ($1, $2 eq "-");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
 $more ||= $code == 214;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
 ($code,$more);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
## RFC1861 commands
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
# Level 1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
sub _PAGE { shift->command("PAGE", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
sub _MESS { shift->command("MESS", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
sub _RESE { shift->command("RESE")->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
sub _SEND { shift->command("SEND")->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
sub _QUIT { shift->command("QUIT")->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
sub _HELP { shift->command("HELP")->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
sub _DATA { shift->command("DATA")->response()  == CMD_MORE }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
sub _SITE { shift->command("SITE",@_) }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
# Level 2
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
sub _LOGI { shift->command("LOGI", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
sub _LEVE { shift->command("LEVE", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
sub _ALER { shift->command("ALER", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
sub _COVE { shift->command("COVE", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
sub _HOLD { shift->command("HOLD", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
sub _CALL { shift->command("CALL", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
sub _SUBJ { shift->command("SUBJ", @_)->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
# NonStandard
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
sub _XWHO { shift->command("XWHO")->response()  == CMD_OK }   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
Net::SNPP - Simple Network Pager Protocol Client
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
    use Net::SNPP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
    # Constructors
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
    $snpp = Net::SNPP->new('snpphost');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
    $snpp = Net::SNPP->new('snpphost', Timeout => 60);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
=head1 NOTE
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
This module is not complete, yet !
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
This module implements a client interface to the SNPP protocol, enabling
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
a perl5 application to talk to SNPP servers. This documentation assumes
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
that you are familiar with the SNPP protocol described in RFC1861.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
A new Net::SNPP object must be created with the I<new> method. Once
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
this has been done, all SNPP commands are accessed through this object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
=head1 EXAMPLES
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
This example will send a pager message in one hour saying "Your lunch is ready"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
    #!/usr/local/bin/perl -w
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
    use Net::SNPP;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
    $snpp = Net::SNPP->new('snpphost');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
    $snpp->send( Pager   => $some_pager_number,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
	         Message => "Your lunch is ready",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
	         Alert   => 1,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
	         Hold    => time + 3600, # lunch ready in 1 hour :-)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
	       ) || die $snpp->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
    $snpp->quit;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
=head1 CONSTRUCTOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
=item new ( [ HOST, ] [ OPTIONS ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
This is the constructor for a new Net::SNPP object. C<HOST> is the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
name of the remote host to which a SNPP connection is required.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
If C<HOST> is not given, then the C<SNPP_Host> specified in C<Net::Config>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
will be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
Possible options are:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
B<Timeout> - Maximum time, in seconds, to wait for a response from the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
SNPP server (default: 120)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
B<Debug> - Enable debugging information
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
Example:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
    $snpp = Net::SNPP->new('snpphost',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
			   Debug => 1,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
			  );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
=head1 METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
Unless otherwise stated all methods return either a I<true> or I<false>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
value, with I<true> meaning that the operation was a success. When a method
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
states that it returns a value, failure will be returned as I<undef> or an
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
empty list.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
=item reset ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
=item help ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
Request help text from the server. Returns the text or undef upon failure
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
=item quit ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
Send the QUIT command to the remote SNPP server and close the socket connection.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
=head1 EXPORTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
C<Net::SNPP> exports all that C<Net::CMD> exports, plus three more subroutines
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
that can bu used to compare against the result of C<status>. These are :-
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
C<CMD_2WAYERROR>, C<CMD_2WAYOK>, and C<CMD_2WAYQUEUED>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
=head1 SEE ALSO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
L<Net::Cmd>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
RFC1861
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
=head1 AUTHOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
Graham Barr <gbarr@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
Copyright (c) 1995-1997 Graham Barr. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
This program is free software; you can redistribute it and/or modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
=cut