home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_466c2c18b2a3c0ac18383a77081e5070
< prev
next >
Wrap
Text File
|
2000-03-23
|
14KB
|
330 lines
<HTML>
<HEAD>
<TITLE>Net::PH - CCSO Nameserver Client class</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> Net::PH - CCSO Nameserver Client class</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
<LI><A HREF="#synopsis">SYNOPSIS</A></LI>
<LI><A HREF="#description">DESCRIPTION</A></LI>
<LI><A HREF="#constructor">CONSTRUCTOR</A></LI>
<LI><A HREF="#methods">METHODS</A></LI>
<LI><A HREF="#q&a">Q&A</A></LI>
<LI><A HREF="#see also">SEE ALSO</A></LI>
<LI><A HREF="#authors">AUTHORS</A></LI>
<LI><A HREF="#acknowledgments">ACKNOWLEDGMENTS</A></LI>
<LI><A HREF="#copyright">COPYRIGHT</A></LI>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="name">NAME</A></H1>
<P>Net::PH - CCSO Nameserver Client class</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use Net::PH;
</PRE>
<PRE>
$ph = Net::PH->new("some.host.name",
Port => 105,
Timeout => 120,
Debug => 0);</PRE>
<PRE>
if($ph) {
$q = $ph->query({ field1 => "value1" },
[qw(name address pobox)]);
</PRE>
<PRE>
if($q) {
}
}</PRE>
<PRE>
# Alternative syntax</PRE>
<PRE>
if($ph) {
$q = $ph->query('field1=value1',
'name address pobox');</PRE>
<PRE>
if($q) {
}
}</PRE>
<P>
<HR>
<H1><A NAME="description">DESCRIPTION</A></H1>
<P><CODE>Net::PH</CODE> is a class implementing a simple Nameserver/PH client in Perl
as described in the CCSO Nameserver -- Server-Client Protocol. Like other
modules in the Net:: family the <CODE>Net::PH</CODE> object inherits methods from
<CODE>Net::Cmd</CODE>.</P>
<P>
<HR>
<H1><A NAME="constructor">CONSTRUCTOR</A></H1>
<DL>
<DT><STRONG><A NAME="item_new">new ( [ HOST ] [, OPTIONS ])</A></STRONG><BR>
<DD>
<PRE>
$ph = Net::PH->new("some.host.name",
Port => 105,
Timeout => 120,
Debug => 0
);</PRE>
<P>This is the constructor for a new Net::PH object. <CODE>HOST</CODE> is the
name of the remote host to which a PH connection is required.</P>
<P>If <CODE>HOST</CODE> is not given, then the <CODE>SNPP_Host</CODE> specified in <CODE>Net::Config</CODE>
will be used.</P>
<P><CODE>OPTIONS</CODE> is an optional list of named options which are passed in
a hash like fashion, using key and value pairs. Possible options are:-</P>
<P><STRONG>Port</STRONG> - Port number to connect to on remote host.</P>
<P><STRONG>Timeout</STRONG> - Maximum time, in seconds, to wait for a response from the
Nameserver, a value of zero will cause all IO operations to block.
(default: 120)</P>
<P><STRONG>Debug</STRONG> - Enable the printing of debugging information to STDERR</P>
</DL>
<P>
<HR>
<H1><A NAME="methods">METHODS</A></H1>
<P>Unless otherwise stated all methods return either a <EM>true</EM> or <EM>false</EM>
value, with <EM>true</EM> meaning that the operation was a success. When a method
states that it returns a value, failure will be returned as <EM>undef</EM> or an
empty list.</P>
<DL>
<DT><STRONG><A NAME="item_query">query( SEARCH [, RETURN ] )</A></STRONG><BR>
<DD>
<PRE>
$q = $ph->query({ name => $myname },
[qw(name email schedule)]);
</PRE>
<PRE>
foreach $handle (@{$q}) {
foreach $field (keys %{$handle}) {
$c = ${$handle}{$field}->code;
$v = ${$handle}{$field}->value;
$f = ${$handle}{$field}->field;
$t = ${$handle}{$field}->text;
print "field:[$field] [$c][$v][$f][$t]\n" ;
}
}</PRE>
<P></P>
<P>Search the database and return fields from all matching entries.</P>
<P>The <CODE>SEARCH</CODE> argument is a reference to a HASH which contains field/value
pairs which will be passed to the Nameserver as the search criteria.</P>
<P><CODE>RETURN</CODE> is optional, but if given it should be a reference to a list which
contains field names to be returned.</P>
<P>The alternative syntax is to pass strings instead of references, for example</P>
<PRE>
$q = $ph->query('name=myname',
'name email schedule');</PRE>
<P>The <CODE>SEARCH</CODE> argument is a string that is passed to the Nameserver as the
search criteria. The strings being passed should <STRONG>not</STRONG> contain any carriage
returns, or else the query command might fail or return invalid data.</P>
<P><CODE>RETURN</CODE> is optional, but if given it should be a string which will
contain field names to be returned.</P>
<P>Each match from the server will be returned as a HASH where the keys are the
field names and the values are <CODE>Net::PH:Result</CODE> objects (<EM>code</EM>, <EM>value</EM>,
<EM>field</EM>, <EM>text</EM>).</P>
<P>Returns a reference to an ARRAY which contains references to HASHs, one
per match from the server.</P>
<DT><STRONG><A NAME="item_change">change( SEARCH , MAKE )</A></STRONG><BR>
<DD>
<PRE>
$r = $ph->change({ email => "*.domain.name" },
{ schedule => "busy");</PRE>
<P>Change field values for matching entries.</P>
<P>The <CODE>SEARCH</CODE> argument is a reference to a HASH which contains field/value
pairs which will be passed to the Nameserver as the search criteria.</P>
<P>The <CODE>MAKE</CODE> argument is a reference to a HASH which contains field/value
pairs which will be passed to the Nameserver that
will set new values to designated fields.</P>
<P>The alternative syntax is to pass strings instead of references, for example</P>
<PRE>
$r = $ph->change('email="*.domain.name"',
'schedule="busy"');</PRE>
<P>The <CODE>SEARCH</CODE> argument is a string to be passed to the Nameserver as the
search criteria. The strings being passed should <STRONG>not</STRONG> contain any carriage
returns, or else the query command might fail or return invalid data.</P>
<P>The <CODE>MAKE</CODE> argument is a string to be passed to the Nameserver that
will set new values to designated fields.</P>
<P>Upon success all entries that match the search criteria will have
the field values, given in the Make argument, changed.</P>
<DT><STRONG><A NAME="item_login">login( USER, PASS [, ENCRYPT ])</A></STRONG><BR>
<DD>
<PRE>
$r = $ph->login('username','password',1);</PRE>
<P>Enter login mode using <CODE>USER</CODE> and <CODE>PASS</CODE>. If <CODE>ENCRYPT</CODE> is given and
is <EM>true</EM> then the password will be used to encrypt a challenge text
string provided by the server, and the encrypted string will be sent back
to the server. If <CODE>ENCRYPT</CODE> is not given, or <EM>false</EM> then the password
will be sent in clear text (<EM>this is not recommended</EM>)</P>
<DT><STRONG><A NAME="item_logout"><CODE>logout()</CODE></A></STRONG><BR>
<DD>
<PRE>
$r = $ph->logout();</PRE>
<P>Exit login mode and return to anonymous mode.</P>
<DT><STRONG><A NAME="item_fields">fields( [ FIELD_LIST ] )</A></STRONG><BR>
<DD>
<PRE>
$fields = $ph->fields();
foreach $field (keys %{$fields}) {
$c = ${$fields}{$field}->code;
$v = ${$fields}{$field}->value;
$f = ${$fields}{$field}->field;
$t = ${$fields}{$field}->text;
print "field:[$field] [$c][$v][$f][$t]\n";
}</PRE>
<P>In a scalar context, returns a reference to a HASH. The keys of the HASH are
the field names and the values are <CODE>Net::PH:Result</CODE> objects (<EM>code</EM>,
<EM>value</EM>, <EM>field</EM>, <EM>text</EM>).</P>
<P>In an array context, returns a two element array. The first element is a
reference to a HASH as above, the second element is a reference to an array
which contains the tag names in the order that they were returned from the
server.</P>
<P><CODE>FIELD_LIST</CODE> is a string that lists the fields for which info will be
returned.</P>
<DT><STRONG><A NAME="item_add">add( FIELD_VALUES )</A></STRONG><BR>
<DD>
<PRE>
$r = $ph->add( { name => $name, phone => $phone });</PRE>
<P>This method is used to add new entries to the Nameserver database. You
must successfully call <A HREF="#item_login">login</A> before this method can be used.</P>
<P><STRONG>Note</STRONG> that this method adds new entries to the database. To modify
an existing entry use <A HREF="#item_change">change</A>.</P>
<P><CODE>FIELD_VALUES</CODE> is a reference to a HASH which contains field/value
pairs which will be passed to the Nameserver and will be used to
initialize the new entry.</P>
<P>The alternative syntax is to pass a string instead of a reference, for example</P>
<PRE>
$r = $ph->add('name=myname phone=myphone');</PRE>
<P><CODE>FIELD_VALUES</CODE> is a string that consists of field/value pairs which the
new entry will contain. The strings being passed should <STRONG>not</STRONG> contain any
carriage returns, or else the query command might fail or return invalid data.</P>
<DT><STRONG><A NAME="item_delete">delete( FIELD_VALUES )</A></STRONG><BR>
<DD>
<PRE>
$r = $ph->delete('name=myname phone=myphone');</PRE>
<P>This method is used to delete existing entries from the Nameserver database.
You must successfully call <A HREF="#item_login">login</A> before this method can be used.</P>
<P><STRONG>Note</STRONG> that this method deletes entries to the database. To modify
an existing entry use <A HREF="#item_change">change</A>.</P>
<P><CODE>FIELD_VALUES</CODE> is a string that serves as the search criteria for the
records to be deleted. Any entry in the database which matches this search
criteria will be deleted.</P>
<DT><STRONG><A NAME="item_id">id( [ ID ] )</A></STRONG><BR>
<DD>
<PRE>
$r = $ph->id('709');</PRE>
<P>Sends <CODE>ID</CODE> to the Nameserver, which will enter this into its
logs. If <CODE>ID</CODE> is not given then the UID of the user running the
process will be sent.</P>
<DT><STRONG><A NAME="item_status"><CODE>status()</CODE></A></STRONG><BR>
<DD>
Returns the current status of the Nameserver.
<P></P>
<DT><STRONG><A NAME="item_siteinfo"><CODE>siteinfo()</CODE></A></STRONG><BR>
<DD>
<PRE>
$siteinfo = $ph->siteinfo();
foreach $field (keys %{$siteinfo}) {
$c = ${$siteinfo}{$field}->code;
$v = ${$siteinfo}{$field}->value;
$f = ${$siteinfo}{$field}->field;
$t = ${$siteinfo}{$field}->text;
print "field:[$field] [$c][$v][$f][$t]\n";
}</PRE>
<P>Returns a reference to a HASH containing information about the server's
site. The keys of the HASH are the field names and values are
<CODE>Net::PH:Result</CODE> objects (<EM>code</EM>, <EM>value</EM>, <EM>field</EM>, <EM>text</EM>).</P>
<DT><STRONG><A NAME="item_quit"><CODE>quit()</CODE></A></STRONG><BR>
<DD>
<PRE>
$r = $ph->quit();</PRE>
<P>Quit the connection</P>
</DL>
<P>
<HR>
<H1><A NAME="q&a">Q&A</A></H1>
<P>How do I get the values of a Net::PH::Result object?</P>
<PRE>
foreach $handle (@{$q}) {
foreach $field (keys %{$handle}) {
$my_code = ${$q}{$field}->code;
$my_value = ${$q}{$field}->value;
$my_field = ${$q}{$field}->field;
$my_text = ${$q}{$field}->text;
}
}</PRE>
<P>How do I get a count of the returned matches to my query?</P>
<PRE>
$my_count = scalar(@{$query_result});</PRE>
<P>How do I get the status code and message of the last <CODE>$ph</CODE> command?</P>
<PRE>
$status_code = $ph->code;
$status_message = $ph->message;</PRE>
<P>
<HR>
<H1><A NAME="see also">SEE ALSO</A></H1>
<P><A HREF="../../../site/lib/Net/Cmd.html">the Net::Cmd manpage</A></P>
<P>
<HR>
<H1><A NAME="authors">AUTHORS</A></H1>
<P>Graham Barr <<A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A>>
Alex Hristov <<A HREF="mailto:hristov@slb.com">hristov@slb.com</A>></P>
<P>
<HR>
<H1><A NAME="acknowledgments">ACKNOWLEDGMENTS</A></H1>
<P>Password encryption code ported to perl by Broc Seib <<A HREF="mailto:bseib@purdue.edu">bseib@purdue.edu</A>>,
Purdue University Computing Center.</P>
<P>Otis Gospodnetic <<A HREF="mailto:otisg@panther.middlebury.edu">otisg@panther.middlebury.edu</A>> suggested
passing parameters as string constants. Some queries cannot be
executed when passing parameters as string references.</P>
<PRE>
Example: query first_name last_name email="*.domain"</PRE>
<P>
<HR>
<H1><A NAME="copyright">COPYRIGHT</A></H1>
<P>The encryption code is based upon cryptit.c, Copyright (C) 1988 by
Steven Dorner, and Paul Pomes, and the University of Illinois Board
of Trustees, and by CSNET.</P>
<P>All other code is Copyright (c) 1996-1997 Graham Barr <<A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A>>
and Alex Hristov <<A HREF="mailto:hristov@slb.com">hristov@slb.com</A>>. All rights reserved. This program is
free software; you can redistribute it and/or modify it under the same
terms as Perl itself.</P>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> Net::PH - CCSO Nameserver Client class</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>