Ccso nameserver client class
use Net::PH; $ph = Net::PH->new("some.host.name", Port => 105, Timeout => 120, Debug => 0); if($ph) { $q = $ph->query({ field1 => "value1" }, [qw(name address pobox)]); if($q) { } } # Alternative syntax if($ph) { $q = $ph->query('field1=value1', 'name address pobox'); if($q) { } }
\*(C`Net::PH\*(C' is a class implementing a simple Nameserver/PH client in Perl as described in the \s-1CCSO\s0 Nameserver \*(-- Server-Client Protocol. Like other modules in the Net:: family the \*(C`Net::PH\*(C' object inherits methods from \*(C`Net::Cmd\*(C'.
$ph = Net::PH->new("some.host.name", Port => 105, Timeout => 120, Debug => 0 ); This is the constructor for a new Net::PH object. \*(C`HOST\*(C' is the name of the remote host to which a \s-1PH\s0 connection is required. If \*(C`HOST\*(C' is not given, then the \*(C`SNPP_Host\*(C' specified in \*(C`Net::Config\*(C' will be used. \*(C`OPTIONS\*(C' is an optional list of named options which are passed in a hash like fashion, using key and value pairs. Possible options are:- Port - Port number to connect to on remote host. Timeout - Maximum time, in seconds, to wait for a response from the Nameserver, a value of zero will cause all \s-1IO\s0 operations to block. (default: 120) Debug - Enable the printing of debugging information to \s-1STDERR\s0
Unless otherwise stated all methods return either a true or false value, with true meaning that the operation was a success. When a method states that it returns a value, failure will be returned as undef or an empty list.
$q = $ph->query({ name => $myname }, [qw(name email schedule)]);
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" ; } } Search the database and return fields from all matching entries. The \*(C`SEARCH\*(C' argument is a reference to a \s-1HASH\s0 which contains field/value pairs which will be passed to the Nameserver as the search criteria. \*(C`RETURN\*(C' is optional, but if given it should be a reference to a list which contains field names to be returned. The alternative syntax is to pass strings instead of references, for example $q = $ph->query('name=myname', 'name email schedule'); The \*(C`SEARCH\*(C' argument is a string that is passed to the Nameserver as the search criteria. The strings being passed should not contain any carriage returns, or else the query command might fail or return invalid data. \*(C`RETURN\*(C' is optional, but if given it should be a string which will contain field names to be returned. Each match from the server will be returned as a \s-1HASH\s0 where the keys are the field names and the values are \*(C`Net::PH:Result\*(C' objects (code, value, field, text). Returns a reference to an \s-1ARRAY\s0 which contains references to HASHs, one per match from the server.
$r = $ph->change({ email => "*.domain.name" }, { schedule => "busy"); Change field values for matching entries. The \*(C`SEARCH\*(C' argument is a reference to a \s-1HASH\s0 which contains field/value pairs which will be passed to the Nameserver as the search criteria. The \*(C`MAKE\*(C' argument is a reference to a \s-1HASH\s0 which contains field/value pairs which will be passed to the Nameserver that will set new values to designated fields. The alternative syntax is to pass strings instead of references, for example $r = $ph->change('email="*.domain.name"', 'schedule="busy"'); The \*(C`SEARCH\*(C' argument is a string to be passed to the Nameserver as the search criteria. The strings being passed should not contain any carriage returns, or else the query command might fail or return invalid data. The \*(C`MAKE\*(C' argument is a string to be passed to the Nameserver that will set new values to designated fields. Upon success all entries that match the search criteria will have the field values, given in the Make argument, changed.
$r = $ph->login('username','password',1); Enter login mode using \*(C`USER\*(C' and \*(C`PASS\*(C'. If \*(C`ENCRYPT\*(C' is given and is true 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 \*(C`ENCRYPT\*(C' is not given, or false then the password will be sent in clear text (this is not recommended)
$r = $ph->logout(); Exit login mode and return to anonymous mode.
$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"; } In a scalar context, returns a reference to a \s-1HASH\s0. The keys of the \s-1HASH\s0 are the field names and the values are \*(C`Net::PH:Result\*(C' objects (code, value, field, text). In an array context, returns a two element array. The first element is a reference to a \s-1HASH\s0 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. \*(C`FIELD_LIST\*(C' is a string that lists the fields for which info will be returned.
$r = $ph->add( { name => $name, phone => $phone }); This method is used to add new entries to the Nameserver database. You must successfully call login before this method can be used. Note that this method adds new entries to the database. To modify an existing entry use change. \*(C`FIELD_VALUES\*(C' is a reference to a \s-1HASH\s0 which contains field/value pairs which will be passed to the Nameserver and will be used to initialize the new entry. The alternative syntax is to pass a string instead of a reference, for example $r = $ph->add('name=myname phone=myphone'); \*(C`FIELD_VALUES\*(C' is a string that consists of field/value pairs which the new entry will contain. The strings being passed should not contain any carriage returns, or else the query command might fail or return invalid data.
$r = $ph->delete('name=myname phone=myphone'); This method is used to delete existing entries from the Nameserver database. You must successfully call login before this method can be used. Note that this method deletes entries to the database. To modify an existing entry use change. \*(C`FIELD_VALUES\*(C' 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.
$r = $ph->id('709'); Sends \*(C`ID\*(C' to the Nameserver, which will enter this into its logs. If \*(C`ID\*(C' is not given then the \s-1UID\s0 of the user running the process will be sent.
Returns the current status of the Nameserver.
$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"; } Returns a reference to a \s-1HASH\s0 containing information about the server's site. The keys of the \s-1HASH\s0 are the field names and values are \*(C`Net::PH:Result\*(C' objects (code, value, field, text).
$r = $ph->quit(); Quit the connection
How do I get the values of a Net::PH::Result object?
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; } }
How do I get a count of the returned matches to my query?
$my_count = scalar(@{$query_result});
How do I get the status code and message of the last $ph command?
$status_code = $ph->code; $status_message = $ph->message;
Net::Cmd
Graham Barr <[email protected]> Alex Hristov <[email protected]>
Password encryption code ported to perl by Broc Seib <[email protected]>, Purdue University Computing Center.
Otis Gospodnetic <[email protected]> suggested passing parameters as string constants. Some queries cannot be executed when passing parameters as string references.
Example: query first_name last_name email="*.domain"
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 \s-1CSNET\s0.
All other code is Copyright (c) 1996-1997 Graham Barr <[email protected]> and Alex Hristov <[email protected]>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
$Id: //depot/ph/PH.pm#2 $