releasing/cbrtools/perl/Net/PH.pm
author marvin shi <marvin.shi@nokia.com>
Wed, 17 Nov 2010 16:47:55 +0800
changeset 696 30aa553e9465
parent 602 3145852acc89
permissions -rw-r--r--
features: bsym for rofsbuild and log input support for rombuild
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 1995-1997 Graham Barr <gbarr@pobox.com> and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# Alex Hristov <hristov@slb.com>. All rights reserved. This program is free
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# software; you can redistribute it and/or modify it under the same terms
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# 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::PH;
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(@ISA $VERSION);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
use Carp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
use Socket 1.3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
use IO::Socket;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
use Net::Cmd;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use Net::Config;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
$VERSION = "2.20"; # $Id: //depot/libnet/Net/PH.pm#7$
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
@ISA     = qw(Exporter Net::Cmd IO::Socket::INET);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
sub new
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
 my $pkg  = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
 my $host = shift if @_ % 2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
 my %arg  = @_; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
 my $hosts = defined $host ? [ $host ] : $NetConfig{ph_hosts};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
 my $ph;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
 my $h;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
 foreach $h (@{$hosts})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
   $ph = $pkg->SUPER::new(PeerAddr => ($host = $h), 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
			  PeerPort => $arg{Port} || 'csnet-ns(105)',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
			  Proto    => 'tcp',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
			  Timeout  => defined $arg{Timeout}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
					? $arg{Timeout}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
					: 120
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
			 ) and last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
 return undef
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
	unless defined $ph;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
 ${*$ph}{'net_ph_host'} = $host;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
 $ph->autoflush(1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
 $ph->debug(exists $arg{Debug} ? $arg{Debug} : undef);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
 $ph;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
sub status
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
 $ph->command('status')->response;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
 $ph->code;
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
sub login
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
 my($user,$pass,$encrypted) = @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
 my $resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
 $resp = $ph->command("login",$user)->response;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
 if(defined($pass) && $resp == CMD_MORE)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
   if($encrypted)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
     my $challenge_str = $ph->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
     chomp($challenge_str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
     Net::PH::crypt::crypt_start($pass);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
     my $cryptstr = Net::PH::crypt::encryptit($challenge_str);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
     $ph->command("answer", $cryptstr);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
     $ph->command("clear", $pass);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
   $resp = $ph->response;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
 $resp == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
sub logout
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
 $ph->command("logout")->response == CMD_OK;
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
sub id
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
 my $id = @_ ? shift : $<;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
 $ph->command("id",$id)->response == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
sub siteinfo
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
 $ph->command("siteinfo");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
 my $ln;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
 my %resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
 my $cur_num = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
 while(defined($ln = $ph->getline))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
   $ph->debug_print(0,$ln)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
     if ($ph->debug & 2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
   chomp($ln);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
   my($code,$num,$tag,$data);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
   if($ln =~ /^-(\d+):(\d+):(?:\s*([^:]+):)?\s*(.*)/o)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
     ($code,$num,$tag,$data) = ($1, $2, $3 || "",$4);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
     $resp{$tag} = bless [$code, $num, $tag, $data], "Net::PH::Result";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
     $ph->set_status($ph->parse_response($ln));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
     return \%resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
 return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
sub query
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
 my $search = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
 my($k,$v);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
 my @args = ('query', _arg_hash($search));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
 push(@args,'return',_arg_list( shift ))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
	if @_;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
 unless($ph->command(@args)->response == CMD_INFO)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
   return $ph->code == 501
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
	? []
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
	: undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   156
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   158
 my $ln;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
 my @resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
 my $cur_num = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
 my($last_tag);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
 while(defined($ln = $ph->getline))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
   $ph->debug_print(0,$ln)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
     if ($ph->debug & 2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
   chomp($ln);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
   my($code,$idx,$num,$tag,$data);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
   if($ln =~ /^-(\d+):(\d+):\s*([^:]*):\s*(.*)/o)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
     ($code,$idx,$tag,$data) = ($1,$2,$3,$4);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
     my $num = $idx - 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
     $resp[$num] ||= {};
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
     $tag = $last_tag
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
	unless(length($tag));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
     $last_tag = $tag;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   182
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   183
     if(exists($resp[$num]->{$tag}))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   184
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   185
       $resp[$num]->{$tag}->[3] .= "\n" . $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   186
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   187
     else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   188
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   189
       $resp[$num]->{$tag} = bless [$code, $idx, $tag, $data], "Net::PH::Result";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   190
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   191
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   192
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   193
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   194
     $ph->set_status($ph->parse_response($ln));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   195
     return \@resp;
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
 return undef;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   200
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   201
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   202
sub change
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   203
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   204
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   205
 my $search = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   206
 my $make = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   207
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   208
 $ph->command(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   209
	"change", _arg_hash($search),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   210
	"make",   _arg_hash($make)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   211
 )->response == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   212
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   213
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   214
sub _arg_hash
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   215
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   216
 my $hash = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   217
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   218
 return $hash
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   219
	unless(ref($hash));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   220
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   221
 my($k,$v);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   222
 my @r;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   223
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   224
 while(($k,$v) = each %$hash)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   225
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   226
   my $a = $v;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   227
   $a =~ s/\n/\\n/sog;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   228
   $a =~ s/\t/\\t/sog;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   229
   $a = '"' . $a . '"'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   230
	if $a =~ /\W/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   231
   $a = '""'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   232
	unless length $a;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   233
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   234
   push(@r, "$k=$a");   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   235
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   236
 join(" ", @r);
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
sub _arg_list
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   240
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   241
 my $arr = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   242
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   243
 return $arr
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   244
	unless(ref($arr));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   245
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   246
 my $v;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   247
 my @r;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   248
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   249
 foreach $v (@$arr)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   250
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   251
   my $a = $v;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   252
   $a =~ s/\n/\\n/sog;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   253
   $a =~ s/\t/\\t/sog;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   254
   $a = '"' . $a . '"'
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   255
	if $a =~ /\W/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   256
   push(@r, $a);   
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   257
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   258
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   259
 join(" ",@r);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   260
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   261
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   262
sub add
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   263
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   264
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   265
 my $arg = @_ > 1 ? { @_ } : shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   266
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   267
 $ph->command('add', _arg_hash($arg))->response == CMD_OK;
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
sub delete
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   271
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   272
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   273
 my $arg = @_ > 1 ? { @_ } : shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   274
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   275
 $ph->command('delete', _arg_hash($arg))->response == CMD_OK;
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
sub force
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   279
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   280
 my $ph = shift; 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   281
 my $search = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   282
 my $force = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   283
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   284
 $ph->command(
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   285
	"change", _arg_hash($search),
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   286
	"force",  _arg_hash($force)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   287
 )->response == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   288
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   289
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   290
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   291
sub fields
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   292
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   293
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   294
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   295
 $ph->command("fields", _arg_list(\@_));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   296
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   297
 my $ln;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   298
 my %resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   299
 my $cur_num = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   300
 my @tags = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   301
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   302
 while(defined($ln = $ph->getline))
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   303
  {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   304
   $ph->debug_print(0,$ln)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   305
     if ($ph->debug & 2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   306
   chomp($ln);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   307
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   308
   my($code,$num,$tag,$data,$last_tag);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   309
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   310
   if($ln =~ /^-(\d+):(\d+):\s*([^:]*):\s*(.*)/o)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   311
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   312
     ($code,$num,$tag,$data) = ($1,$2,$3,$4);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   313
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   314
     $tag = $last_tag
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   315
	unless(length($tag));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   316
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   317
     $last_tag = $tag;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   318
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   319
     if(exists $resp{$tag})
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   320
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   321
       $resp{$tag}->[3] .= "\n" . $data;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   322
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   323
     else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   324
      {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   325
       $resp{$tag} = bless [$code, $num, $tag, $data], "Net::PH::Result";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   326
       push @tags, $tag;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   327
      }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   328
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   329
   else
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   330
    {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   331
     $ph->set_status($ph->parse_response($ln));
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   332
     return wantarray ? (\%resp, \@tags) : \%resp;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   333
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   334
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   335
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   336
 return;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   337
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   338
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   339
sub quit
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   340
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   341
 my $ph = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   342
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   343
 $ph->close
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   344
	if $ph->command("quit")->response == CMD_OK;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   345
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   346
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   347
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   348
## Net::Cmd overrides
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   349
##
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   350
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   351
sub parse_response
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   352
{
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   353
 return ()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   354
    unless $_[1] =~ s/^(-?)(\d\d\d):?//o;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   355
 ($2, $1 eq "-");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   356
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   357
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   358
sub debug_text { $_[2] =~ /^(clear)/i ? "$1 ....\n" : $_[2]; }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   359
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   360
package Net::PH::Result;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   361
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   362
sub code  { shift->[0] }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   363
sub value { shift->[1] }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   364
sub field { shift->[2] }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   365
sub text  { shift->[3] }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   366
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   367
package Net::PH::crypt;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   368
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   369
#  The code in this package is based upon 'cryptit.c', Copyright (C) 1988 by
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   370
#  Steven Dorner, and Paul Pomes, and the University of Illinois Board
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   371
#  of Trustees, and by CSNET.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   372
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   373
use integer;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   374
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   375
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   376
sub ROTORSZ () { 256 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   377
sub MASK () { 255 }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   378
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   379
my(@t1,@t2,@t3,$n1,$n2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   380
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   381
sub crypt_start {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   382
    my $pass = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   383
    $n1 = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   384
    $n2 = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   385
    crypt_init($pass);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   386
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   387
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   388
sub crypt_init {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   389
    my $pw = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   390
    my $i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   391
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   392
    @t2 = @t3 = (0) x ROTORSZ;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   393
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   394
    my $buf = crypt($pw,$pw);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   395
    return -1 unless length($buf) > 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   396
    $buf = substr($buf . "\0" x 13,0,13);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   397
    my @buf = map { ord $_ } split(//, $buf);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   398
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   399
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   400
    my $seed = 123;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   401
    for($i = 0 ; $i < 13 ; $i++) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   402
	$seed = $seed * $buf[$i] + $i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   403
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   404
    @t1 = (0 .. ROTORSZ-1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   405
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   406
    for($i = 0 ; $i < ROTORSZ ; $i++) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   407
	$seed = 5 * $seed + $buf[$i % 13];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   408
	my $random = $seed % 65521;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   409
	my $k = ROTORSZ - 1 - $i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   410
	my $ic = ($random & MASK) % ($k + 1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   411
	$random >>= 8;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   412
	@t1[$k,$ic] = @t1[$ic,$k];
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   413
	next if $t3[$k] != 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   414
	$ic = ($random & MASK) % $k;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   415
	while($t3[$ic] != 0) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   416
	    $ic = ($ic + 1) % $k;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   417
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   418
	$t3[$k] = $ic;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   419
	$t3[$ic] = $k;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   420
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   421
    for($i = 0 ; $i < ROTORSZ ; $i++) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   422
	$t2[$t1[$i] & MASK] = $i
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   423
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   424
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   425
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   426
sub encode {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   427
    my $sp = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   428
    my $ch;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   429
    my $n = scalar(@$sp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   430
    my @out = ($n);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   431
    my $i;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   432
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   433
    for($i = 0 ; $i < $n ; ) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   434
	my($f0,$f1,$f2) = splice(@$sp,0,3);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   435
	push(@out,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   436
	    $f0 >> 2,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   437
	    ($f0 << 4) & 060 | ($f1 >> 4) & 017,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   438
	    ($f1 << 2) & 074 | ($f2 >> 6) & 03,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   439
	    $f2 & 077);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   440
	$i += 3;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   441
   }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   442
   join("", map { chr((($_ & 077) + 35) & 0xff) } @out);  # ord('#') == 35
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
sub encryptit {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   446
    my $from = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   447
    my @from = map { ord $_ } split(//, $from);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   448
    my @sp = ();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   449
    my $ch;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   450
    while(defined($ch = shift @from)) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   451
	push(@sp,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   452
	    $t2[($t3[($t1[($ch + $n1) & MASK] + $n2) & MASK] - $n2) & MASK] - $n1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   453
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   454
	$n1++;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   455
	if($n1 == ROTORSZ) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   456
	    $n1 = 0;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   457
	    $n2++;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   458
	    $n2 = 0 if $n2 == ROTORSZ;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   459
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   460
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   461
    encode(\@sp);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   462
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   463
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   464
1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   465
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   466
__END__
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   467
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   468
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   469
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   470
Net::PH - CCSO Nameserver Client class
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   471
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   472
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   473
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   474
    use Net::PH;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   475
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   476
    $ph = Net::PH->new("some.host.name",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   477
                       Port    => 105,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   478
                       Timeout => 120,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   479
                       Debug   => 0);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   480
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   481
    if($ph) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   482
        $q = $ph->query({ field1 => "value1" },
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   483
                        [qw(name address pobox)]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   484
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   485
        if($q) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   486
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   487
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   488
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   489
    # Alternative syntax
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   490
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   491
    if($ph) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   492
        $q = $ph->query('field1=value1',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   493
                        'name address pobox');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   494
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   495
        if($q) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   496
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   497
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   498
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   499
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   500
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   501
C<Net::PH> is a class implementing a simple Nameserver/PH client in Perl
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   502
as described in the CCSO Nameserver -- Server-Client Protocol. Like other
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   503
modules in the Net:: family the C<Net::PH> object inherits methods from
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   504
C<Net::Cmd>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   505
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   506
=head1 CONSTRUCTOR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   507
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   508
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   509
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   510
=item new ( [ HOST ] [, OPTIONS ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   511
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   512
    $ph = Net::PH->new("some.host.name",
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   513
                       Port    => 105,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   514
                       Timeout => 120,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   515
                       Debug   => 0
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   516
                      );
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   517
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   518
This is the constructor for a new Net::PH object. C<HOST> is the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   519
name of the remote host to which a PH connection is required.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   520
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   521
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
   522
will be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   523
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   524
C<OPTIONS> is an optional list of named options which are passed in
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   525
a hash like fashion, using key and value pairs. Possible options are:-
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   526
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   527
B<Port> - Port number to connect to on remote host.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   528
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   529
B<Timeout> - Maximum time, in seconds, to wait for a response from the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   530
Nameserver, a value of zero will cause all IO operations to block.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   531
(default: 120)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   532
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   533
B<Debug> - Enable the printing of debugging information to STDERR
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   534
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   535
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   536
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   537
=head1 METHODS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   538
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   539
Unless otherwise stated all methods return either a I<true> or I<false>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   540
value, with I<true> meaning that the operation was a success. When a method
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   541
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
   542
empty list.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   543
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   544
=over 4
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   545
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   546
=item query( SEARCH [, RETURN ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   547
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   548
    $q = $ph->query({ name => $myname },
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   549
		    [qw(name email schedule)]);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   550
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   551
    foreach $handle (@{$q}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   552
	foreach $field (keys %{$handle}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   553
            $c = ${$handle}{$field}->code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   554
            $v = ${$handle}{$field}->value;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   555
            $f = ${$handle}{$field}->field;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   556
            $t = ${$handle}{$field}->text;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   557
            print "field:[$field] [$c][$v][$f][$t]\n" ;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   558
	}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   559
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   560
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   561
    
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   562
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   563
Search the database and return fields from all matching entries.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   564
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   565
The C<SEARCH> argument is a reference to a HASH which contains field/value
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   566
pairs which will be passed to the Nameserver as the search criteria.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   567
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   568
C<RETURN> is optional, but if given it should be a reference to a list which
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   569
contains field names to be returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   570
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   571
The alternative syntax is to pass strings instead of references, for example
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   572
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   573
    $q = $ph->query('name=myname',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   574
		    'name email schedule');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   575
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   576
The C<SEARCH> argument is a string that is passed to the Nameserver as the 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   577
search criteria. The strings being passed should B<not> contain any carriage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   578
returns, or else the query command might fail or return invalid data.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   579
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   580
C<RETURN> is optional, but if given it should be a string which will
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   581
contain field names to be returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   582
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   583
Each match from the server will be returned as a HASH where the keys are the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   584
field names and the values are C<Net::PH:Result> objects (I<code>, I<value>, 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   585
I<field>, I<text>).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   586
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   587
Returns a reference to an ARRAY which contains references to HASHs, one
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   588
per match from the server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   589
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   590
=item change( SEARCH , MAKE )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   591
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   592
    $r = $ph->change({ email => "*.domain.name" },
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   593
                     { schedule => "busy");
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   594
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   595
Change field values for matching entries.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   596
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   597
The C<SEARCH> argument is a reference to a HASH which contains field/value
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   598
pairs which will be passed to the Nameserver as the search criteria.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   599
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   600
The C<MAKE> argument is a reference to a HASH which contains field/value
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   601
pairs which will be passed to the Nameserver that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   602
will set new values to designated fields.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   603
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   604
The alternative syntax is to pass strings instead of references, for example
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   605
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   606
    $r = $ph->change('email="*.domain.name"',
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   607
                     'schedule="busy"');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   608
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   609
The C<SEARCH> argument is a string to be passed to the Nameserver as the 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   610
search criteria. The strings being passed should B<not> contain any carriage
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   611
returns, or else the query command might fail or return invalid data.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   612
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   613
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   614
The C<MAKE> argument is a string to be passed to the Nameserver that
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   615
will set new values to designated fields.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   616
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   617
Upon success all entries that match the search criteria will have
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   618
the field values, given in the Make argument, changed.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   619
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   620
=item login( USER, PASS [, ENCRYPT ])
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   621
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   622
    $r = $ph->login('username','password',1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   623
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   624
Enter login mode using C<USER> and C<PASS>. If C<ENCRYPT> is given and
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   625
is I<true> then the password will be used to encrypt a challenge text 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   626
string provided by the server, and the encrypted string will be sent back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   627
to the server. If C<ENCRYPT> is not given, or I<false> then the password 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   628
will be sent in clear text (I<this is not recommended>)
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   629
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   630
=item logout()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   631
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   632
    $r = $ph->logout();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   633
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   634
Exit login mode and return to anonymous mode.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   635
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   636
=item fields( [ FIELD_LIST ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   637
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   638
    $fields = $ph->fields();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   639
    foreach $field (keys %{$fields}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   640
        $c = ${$fields}{$field}->code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   641
        $v = ${$fields}{$field}->value;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   642
        $f = ${$fields}{$field}->field;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   643
        $t = ${$fields}{$field}->text;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   644
        print "field:[$field] [$c][$v][$f][$t]\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   645
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   646
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   647
In a scalar context, returns a reference to a HASH. The keys of the HASH are
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   648
the field names and the values are C<Net::PH:Result> objects (I<code>,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   649
I<value>, I<field>, I<text>).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   650
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   651
In an array context, returns a two element array. The first element is a
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   652
reference to a HASH as above, the second element is a reference to an array
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   653
which contains the tag names in the order that they were returned from the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   654
server.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   655
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   656
C<FIELD_LIST> is a string that lists the fields for which info will be
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   657
returned.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   658
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   659
=item add( FIELD_VALUES )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   660
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   661
    $r = $ph->add( { name => $name, phone => $phone });
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   662
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   663
This method is used to add new entries to the Nameserver database. You
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   664
must successfully call L<login> before this method can be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   665
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   666
B<Note> that this method adds new entries to the database. To modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   667
an existing entry use L<change>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   668
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   669
C<FIELD_VALUES> is a reference to a HASH which contains field/value
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   670
pairs which will be passed to the Nameserver and will be used to 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   671
initialize the new entry.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   672
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   673
The alternative syntax is to pass a string instead of a reference, for example
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   674
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   675
    $r = $ph->add('name=myname phone=myphone');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   676
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   677
C<FIELD_VALUES> is a string that consists of field/value pairs which the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   678
new entry will contain. The strings being passed should B<not> contain any
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   679
carriage returns, or else the query command might fail or return invalid data.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   680
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   681
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   682
=item delete( FIELD_VALUES )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   683
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   684
    $r = $ph->delete('name=myname phone=myphone');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   685
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   686
This method is used to delete existing entries from the Nameserver database.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   687
You must successfully call L<login> before this method can be used.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   688
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   689
B<Note> that this method deletes entries to the database. To modify
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   690
an existing entry use L<change>.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   691
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   692
C<FIELD_VALUES> is a string that serves as the search criteria for the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   693
records to be deleted. Any entry in the database which matches this search 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   694
criteria will be deleted.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   695
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   696
=item id( [ ID ] )
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   697
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   698
    $r = $ph->id('709');
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   699
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   700
Sends C<ID> to the Nameserver, which will enter this into its
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   701
logs. If C<ID> is not given then the UID of the user running the
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   702
process will be sent.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   703
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   704
=item status()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   705
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   706
Returns the current status of the Nameserver.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   707
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   708
=item siteinfo()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   709
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   710
    $siteinfo = $ph->siteinfo();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   711
    foreach $field (keys %{$siteinfo}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   712
        $c = ${$siteinfo}{$field}->code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   713
        $v = ${$siteinfo}{$field}->value;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   714
        $f = ${$siteinfo}{$field}->field;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   715
        $t = ${$siteinfo}{$field}->text;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   716
        print "field:[$field] [$c][$v][$f][$t]\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   717
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   718
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   719
Returns a reference to a HASH containing information about the server's 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   720
site. The keys of the HASH are the field names and values are
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   721
C<Net::PH:Result> objects (I<code>, I<value>, I<field>, I<text>).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   722
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   723
=item quit()
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   724
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   725
    $r = $ph->quit();
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   726
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   727
Quit the connection
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   728
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   729
=back
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   730
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   731
=head1 Q&A
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   732
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   733
How do I get the values of a Net::PH::Result object?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   734
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   735
    foreach $handle (@{$q}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   736
        foreach $field (keys %{$handle}) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   737
            $my_code  = ${$q}{$field}->code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   738
            $my_value = ${$q}{$field}->value;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   739
            $my_field = ${$q}{$field}->field;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   740
            $my_text  = ${$q}{$field}->text;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   741
        }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   742
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   743
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   744
How do I get a count of the returned matches to my query?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   745
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   746
    $my_count = scalar(@{$query_result});
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   747
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   748
How do I get the status code and message of the last C<$ph> command?
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   749
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   750
    $status_code    = $ph->code;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   751
    $status_message = $ph->message;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   752
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   753
=head1 SEE ALSO
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   754
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   755
L<Net::Cmd>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   756
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   757
=head1 AUTHORS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   758
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   759
Graham Barr <gbarr@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   760
Alex Hristov <hristov@slb.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   761
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   762
=head1 ACKNOWLEDGMENTS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   763
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   764
Password encryption code ported to perl by Broc Seib <bseib@purdue.edu>,
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   765
Purdue University Computing Center.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   766
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   767
Otis Gospodnetic <otisg@panther.middlebury.edu> suggested
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   768
passing parameters as string constants. Some queries cannot be 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   769
executed when passing parameters as string references.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   770
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   771
        Example: query first_name last_name email="*.domain"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   772
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   773
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   774
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   775
The encryption code is based upon cryptit.c, Copyright (C) 1988 by
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   776
Steven Dorner, and Paul Pomes, and the University of Illinois Board
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   777
of Trustees, and by CSNET.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   778
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   779
All other code is Copyright (c) 1996-1997 Graham Barr <gbarr@pobox.com>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   780
and Alex Hristov <hristov@slb.com>. All rights reserved. This program is
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   781
free software; you can redistribute it and/or modify it under the same
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   782
terms as Perl itself.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   783
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   784
=cut