releasing/cbrtools/perl/Net/Cmd.pm
author jjkang
Fri, 25 Jun 2010 19:56:45 +0800
changeset 604 b33dd54aaa52
parent 602 3145852acc89
permissions -rw-r--r--
add cpptoolsplat
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
# Net::Cmd.pm $Id: //depot/libnet/Net/Cmd.pm#33 $
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::Cmd;
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
require Exporter;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
use vars qw(@ISA @EXPORT $VERSION);
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 Symbol 'gensym';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
BEGIN {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
  if ($^O eq 'os390') {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
    require Convert::EBCDIC;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
$VERSION = "2.24";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
@ISA     = qw(Exporter);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
@EXPORT  = qw(CMD_INFO CMD_OK CMD_MORE CMD_REJECT CMD_ERROR CMD_PENDING);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
sub CMD_INFO	{ 1 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
sub CMD_OK	{ 2 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
sub CMD_MORE	{ 3 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
sub CMD_REJECT	{ 4 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
sub CMD_ERROR	{ 5 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
sub CMD_PENDING { 0 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
my %debug = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
my $tr = $^O eq 'os390' ? Convert::EBCDIC->new() : undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
sub toebcdic
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
 unless (exists ${*$cmd}{'net_cmd_asciipeer'})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
   my $string = $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
   my $ebcdicstr = $tr->toebcdic($string);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
   ${*$cmd}{'net_cmd_asciipeer'} = $string !~ /^\d+/ && $ebcdicstr =~ /^\d+/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
  ${*$cmd}{'net_cmd_asciipeer'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
    ? $tr->toebcdic($_[0])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
    : $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
sub toascii
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
  ${*$cmd}{'net_cmd_asciipeer'}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
    ? $tr->toascii($_[0])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
    : $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
sub _print_isa
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
 no strict qw(refs);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
 my $pkg = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
 my $cmd = $pkg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
 $debug{$pkg} ||= 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
 my %done = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
 my @do   = ($pkg);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
 my %spc = ( $pkg , "");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
 while ($pkg = shift @do)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
   next if defined $done{$pkg};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
   $done{$pkg} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
   my $v = defined ${"${pkg}::VERSION"}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
                ? "(" . ${"${pkg}::VERSION"} . ")"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
                : "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
   my $spc = $spc{$pkg};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
   $cmd->debug_print(1,"${spc}${pkg}${v}\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
   if(@{"${pkg}::ISA"})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
     @spc{@{"${pkg}::ISA"}} = ("  " . $spc{$pkg}) x @{"${pkg}::ISA"};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
     unshift(@do, @{"${pkg}::ISA"});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
sub debug
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
 @_ == 1 or @_ == 2 or croak 'usage: $obj->debug([LEVEL])';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
 my($cmd,$level) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
 my $pkg = ref($cmd) || $cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
 my $oldval = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
 if(ref($cmd))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
   $oldval = ${*$cmd}{'net_cmd_debug'} || 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
 else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
   $oldval = $debug{$pkg} || 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
 return $oldval
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
    unless @_ == 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
 $level = $debug{$pkg} || 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
    unless defined $level;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
 _print_isa($pkg)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
    if($level && !exists $debug{$pkg});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
 if(ref($cmd))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
   ${*$cmd}{'net_cmd_debug'} = $level;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
 else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
   $debug{$pkg} = $level;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
 $oldval;
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 message
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
 @_ == 1 or croak 'usage: $obj->message()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
 wantarray ? @{${*$cmd}{'net_cmd_resp'}}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
    	   : join("", @{${*$cmd}{'net_cmd_resp'}});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
sub debug_text { $_[2] }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
sub debug_print
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
 my($cmd,$out,$text) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
 print STDERR $cmd,($out ? '>>> ' : '<<< '), $cmd->debug_text($out,$text);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
sub code
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
 @_ == 1 or croak 'usage: $obj->code()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
 ${*$cmd}{'net_cmd_code'} = "000"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
	unless exists ${*$cmd}{'net_cmd_code'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
 ${*$cmd}{'net_cmd_code'};
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
sub status
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
 @_ == 1 or croak 'usage: $obj->status()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
 substr(${*$cmd}{'net_cmd_code'},0,1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
sub set_status
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
 @_ == 3 or croak 'usage: $obj->set_status(CODE, MESSAGE)';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
 my($code,$resp) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
 $resp = [ $resp ]
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
	unless ref($resp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
 (${*$cmd}{'net_cmd_code'},${*$cmd}{'net_cmd_resp'}) = ($code, $resp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
sub command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
 unless (defined fileno($cmd))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
    $cmd->set_status("599", "Connection closed");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
    return $cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   196
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   197
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   198
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   199
 $cmd->dataend()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
    if(exists ${*$cmd}{'net_cmd_need_crlf'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
 if (scalar(@_))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
   local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
   my $str =  join(" ", map { /\n/ ? do { my $n = $_; $n =~ tr/\n/ /; $n } : $_; } @_);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
   $str = $cmd->toascii($str) if $tr;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
   $str .= "\015\012";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
   my $len = length $str;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
   my $swlen;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
   $cmd->close
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
	unless (defined($swlen = syswrite($cmd,$str,$len)) && $swlen == $len);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
   $cmd->debug_print(1,$str)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
	if($cmd->debug);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
   ${*$cmd}{'net_cmd_resp'} = [];      # the response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
   ${*$cmd}{'net_cmd_code'} = "000";	# Made this one up :-)
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
 $cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
sub ok
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
 @_ == 1 or croak 'usage: $obj->ok()';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
 my $code = $_[0]->code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
 0 < $code && $code < 400;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
sub unsupported
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   237
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   238
 ${*$cmd}{'net_cmd_resp'} = [ 'Unsupported command' ];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   239
 ${*$cmd}{'net_cmd_code'} = 580;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
sub getline
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
 ${*$cmd}{'net_cmd_lines'} ||= [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
 return shift @{${*$cmd}{'net_cmd_lines'}}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
    if scalar(@{${*$cmd}{'net_cmd_lines'}});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
 my $partial = defined(${*$cmd}{'net_cmd_partial'})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
		? ${*$cmd}{'net_cmd_partial'} : "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
 my $fd = fileno($cmd);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
	unless defined $fd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
 my $rin = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
 vec($rin,$fd,1) = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
 my $buf;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
 until(scalar(@{${*$cmd}{'net_cmd_lines'}}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
   my $timeout = $cmd->timeout || undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
   my $rout;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   268
   if (select($rout=$rin, undef, undef, $timeout))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   269
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   270
     unless (sysread($cmd, $buf="", 1024))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
       carp(ref($cmd) . ": Unexpected EOF on command channel")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
		if $cmd->debug;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
       $cmd->close;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
       return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   276
      } 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   277
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   278
     substr($buf,0,0) = $partial;	## prepend from last sysread
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
     my @buf = split(/\015?\012/, $buf, -1);	## break into lines
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
     $partial = pop @buf;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
     push(@{${*$cmd}{'net_cmd_lines'}}, map { "$_\n" } @buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
     carp("$cmd: Timeout") if($cmd->debug);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
 ${*$cmd}{'net_cmd_partial'} = $partial;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
 if ($tr) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
   foreach my $ln (@{${*$cmd}{'net_cmd_lines'}}) 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
     $ln = $cmd->toebcdic($ln);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
 shift @{${*$cmd}{'net_cmd_lines'}};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
sub ungetline
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
 my($cmd,$str) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
 ${*$cmd}{'net_cmd_lines'} ||= [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
 unshift(@{${*$cmd}{'net_cmd_lines'}}, $str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
sub parse_response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
 return ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
    unless $_[1] =~ s/^(\d\d\d)(.?)//o;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
 ($1, $2 eq "-");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
sub response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
 my($code,$more) = (undef) x 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
 ${*$cmd}{'net_cmd_resp'} ||= [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
 while(1)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
   my $str = $cmd->getline();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
   return CMD_ERROR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
	unless defined($str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
   $cmd->debug_print(0,$str)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
     if ($cmd->debug);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
   ($code,$more) = $cmd->parse_response($str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
   unless(defined $code)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
     $cmd->ungetline($str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
     last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
   ${*$cmd}{'net_cmd_code'} = $code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
   push(@{${*$cmd}{'net_cmd_resp'}},$str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
   last unless($more);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
  } 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
 substr($code,0,1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
sub read_until_dot
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
 my $fh  = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
 my $arr = [];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
 while(1)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
   my $str = $cmd->getline() or return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
   $cmd->debug_print(0,$str)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
     if ($cmd->debug & 4);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
   last if($str =~ /^\.\r?\n/o);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
   $str =~ s/^\.\././o;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
   if (defined $fh)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
     print $fh $str;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
     push(@$arr,$str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
 $arr;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
sub datasend
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
 my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
 my $line = join("" ,@$arr);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
 return 0 unless defined(fileno($cmd));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
 unless (length $line) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
   # Even though we are not sending anything, the fact we were
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
   # called means that dataend needs to be called before the next
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
   # command, which happens of net_cmd_need_crlf exists
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
   ${*$cmd}{'net_cmd_need_crlf'} ||= 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
   return 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
 if($cmd->debug) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
   foreach my $b (split(/\n/,$line)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
     $cmd->debug_print(1, "$b\n");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
 $line =~ s/\r?\n/\r\n/sg;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
 $line =~ tr/\r\n/\015\012/ unless "\r" eq "\015";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
 $line =~ s/(\012\.)/$1./sog;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
 $line =~ s/^\./../ unless ${*$cmd}{'net_cmd_need_crlf'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
 ${*$cmd}{'net_cmd_need_crlf'} = substr($line,-1,1) ne "\012";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
 my $len = length($line);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
 my $offset = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
 my $win = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
 vec($win,fileno($cmd),1) = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
 my $timeout = $cmd->timeout || undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
 local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
 while($len)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
   my $wout;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
   if (select(undef,$wout=$win, undef, $timeout) > 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
     my $w = syswrite($cmd, $line, $len, $offset);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
     unless (defined($w))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
       carp("$cmd: $!") if $cmd->debug;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
       return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
     $len -= $w;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
     $offset += $w;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
     carp("$cmd: Timeout") if($cmd->debug);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   443
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   444
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   445
 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
sub rawdatasend
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
 my $arr = @_ == 1 && ref($_[0]) ? $_[0] : \@_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
 my $line = join("" ,@$arr);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
 return 0 unless defined(fileno($cmd));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
 return 1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
    unless length($line);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
 if($cmd->debug)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
   my $b = "$cmd>>> ";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
   print STDERR $b,join("\n$b",split(/\n/,$line)),"\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
 my $len = length($line);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
 my $offset = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
 my $win = "";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
 vec($win,fileno($cmd),1) = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
 my $timeout = $cmd->timeout || undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
 local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
 while($len)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
   my $wout;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
   if (select(undef,$wout=$win, undef, $timeout) > 0)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
     my $w = syswrite($cmd, $line, $len, $offset);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
     unless (defined($w))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
       carp("$cmd: $!") if $cmd->debug;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
       return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
     $len -= $w;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
     $offset += $w;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
     carp("$cmd: Timeout") if($cmd->debug);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
     return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
sub dataend
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
 my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
 return 0 unless defined(fileno($cmd));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
 return 1
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
    unless(exists ${*$cmd}{'net_cmd_need_crlf'});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
 local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
 syswrite($cmd,"\015\012",2)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
    if ${*$cmd}{'net_cmd_need_crlf'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
 $cmd->debug_print(1, ".\n")
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
    if($cmd->debug);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
 syswrite($cmd,".\015\012",3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
 delete ${*$cmd}{'net_cmd_need_crlf'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
 $cmd->response() == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
# read and write to tied filehandle
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
sub tied_fh {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   522
  ${*$cmd}{'net_cmd_readbuf'} = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
  my $fh = gensym();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
  tie *$fh,ref($cmd),$cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
  return $fh;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
# tie to myself
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
sub TIEHANDLE {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
  my $class = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
  return $cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
# Tied filehandle read.  Reads requested data length, returning
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
# end-of-file when the dot is encountered.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
sub READ {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
  my ($len,$offset) = @_[1,2];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
  return unless exists ${*$cmd}{'net_cmd_readbuf'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
  my $done = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   542
  while (!$done and length(${*$cmd}{'net_cmd_readbuf'}) < $len) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
     ${*$cmd}{'net_cmd_readbuf'} .= $cmd->getline() or return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
     $done++ if ${*$cmd}{'net_cmd_readbuf'} =~ s/^\.\r?\n\Z//m;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
  $_[0] = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
  substr($_[0],$offset+0) = substr(${*$cmd}{'net_cmd_readbuf'},0,$len);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
  substr(${*$cmd}{'net_cmd_readbuf'},0,$len) = '';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
  delete ${*$cmd}{'net_cmd_readbuf'} if $done;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
  return length $_[0];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
sub READLINE {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
  # in this context, we use the presence of readbuf to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
  # indicate that we have not yet reached the eof
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
  return unless exists ${*$cmd}{'net_cmd_readbuf'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
  my $line = $cmd->getline;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
  return if $line =~ /^\.\r?\n/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
  $line;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
sub PRINT {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
  my ($buf,$len,$offset) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
  $len    ||= length ($buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
  $offset += 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
  return unless $cmd->datasend(substr($buf,$offset,$len));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
  ${*$cmd}{'net_cmd_sending'}++;  # flag that we should call dataend()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
  return $len;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
sub CLOSE {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
  my $cmd = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
  my $r = exists(${*$cmd}{'net_cmd_sending'}) ? $cmd->dataend : 1; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
  delete ${*$cmd}{'net_cmd_readbuf'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
  delete ${*$cmd}{'net_cmd_sending'};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
  $r;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
Net::Cmd - Network Command class (as used by FTP, SMTP etc)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
    use Net::Cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
    @ISA = qw(Net::Cmd);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
C<Net::Cmd> is a collection of methods that can be inherited by a sub class
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
of C<IO::Handle>. These methods implement the functionality required for a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
command based protocol, for example FTP and SMTP.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
=head1 USER METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
These methods provide a user interface to the C<Net::Cmd> object.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
=item debug ( VALUE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
Set the level of debug information for this object. If C<VALUE> is not given
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
then the current state is returned. Otherwise the state is changed to 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
C<VALUE> and the previous state returned. 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
Different packages
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
may implement different levels of debug but a non-zero value results in 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
copies of all commands and responses also being sent to STDERR.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
If C<VALUE> is C<undef> then the debug level will be set to the default
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
debug level for the class.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
This method can also be called as a I<static> method to set/get the default
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
debug level for a given class.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
=item message ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
Returns the text message returned from the last command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
=item code ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
Returns the 3-digit code from the last command. If a command is pending
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
then the value 0 is returned
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
=item ok ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
Returns non-zero if the last code value was greater than zero and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
less than 400. This holds true for most command servers. Servers
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
where this does not hold may override this method.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
=item status ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
Returns the most significant digit of the current status code. If a command
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
is pending then C<CMD_PENDING> is returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
=item datasend ( DATA )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
Send data to the remote server, converting LF to CRLF. Any line starting
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
with a '.' will be prefixed with another '.'.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
C<DATA> may be an array or a reference to an array.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
=item dataend ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
End the sending of data to the remote server. This is done by ensuring that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
the data already sent ends with CRLF then sending '.CRLF' to end the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
transmission. Once this data has been sent C<dataend> calls C<response> and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
returns true if C<response> returns CMD_OK.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
=head1 CLASS METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
These methods are not intended to be called by the user, but used or 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
over-ridden by a sub-class of C<Net::Cmd>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
=item debug_print ( DIR, TEXT )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
Print debugging information. C<DIR> denotes the direction I<true> being
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
data being sent to the server. Calls C<debug_text> before printing to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
STDERR.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
=item debug_text ( TEXT )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
This method is called to print debugging information. TEXT is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
the text being sent. The method should return the text to be printed
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
This is primarily meant for the use of modules such as FTP where passwords
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
are sent, but we do not want to display them in the debugging information.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
=item command ( CMD [, ARGS, ... ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
Send a command to the command server. All arguments a first joined with
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
a space character and CRLF is appended, this string is then sent to the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
command server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
Returns undef upon failure
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
=item unsupported ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
Sets the status code to 580 and the response text to 'Unsupported command'.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
Returns zero.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
=item response ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
Obtain a response from the server. Upon success the most significant digit
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
of the status code is returned. Upon failure, timeout etc., I<undef> is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
=item parse_response ( TEXT )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
This method is called by C<response> as a method with one argument. It should
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
return an array of 2 values, the 3-digit status code and a flag which is true
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
when this is part of a multi-line response and this line is not the list.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
=item getline ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
Retrieve one line, delimited by CRLF, from the remote server. Returns I<undef>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
upon failure.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
B<NOTE>: If you do use this method for any reason, please remember to add
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
some C<debug_print> calls into your method.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
=item ungetline ( TEXT )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
Unget a line of text from the server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
=item rawdatasend ( DATA )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
Send data to the remote server without performing any conversions. C<DATA>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
is a scalar.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
=item read_until_dot ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
Read data from the remote server until a line consisting of a single '.'.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
Any lines starting with '..' will have one of the '.'s removed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
Returns a reference to a list containing the lines, or I<undef> upon failure.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
=item tied_fh ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
Returns a filehandle tied to the Net::Cmd object.  After issuing a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
command, you may read from this filehandle using read() or <>.  The
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
filehandle will return EOF when the final dot is encountered.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
Similarly, you may write to the filehandle in order to send data to
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
the server after issuing a commmand that expects data to be written.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
See the Net::POP3 and Net::SMTP modules for examples of this.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
=head1 EXPORTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
C<Net::Cmd> exports six subroutines, five of these, C<CMD_INFO>, C<CMD_OK>,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
C<CMD_MORE>, C<CMD_REJECT> and C<CMD_ERROR>, correspond to possible results
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
of C<response> and C<status>. The sixth is C<CMD_PENDING>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
=head1 AUTHOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
Graham Barr <gbarr@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
Copyright (c) 1995-1997 Graham Barr. All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
This program is free software; you can redistribute it and/or modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
it under the same terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
=for html <hr>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
I<$Id: //depot/libnet/Net/Cmd.pm#33 $>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
=cut