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 >
Text File  |  2000-03-23  |  14KB  |  330 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Net::PH - CCSO Nameserver Client class</TITLE>
  5. <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Net::PH - CCSO Nameserver Client class</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  23.     <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
  24.     <LI><A HREF="#description">DESCRIPTION</A></LI>
  25.     <LI><A HREF="#constructor">CONSTRUCTOR</A></LI>
  26.     <LI><A HREF="#methods">METHODS</A></LI>
  27.     <LI><A HREF="#q&a">Q&A</A></LI>
  28.     <LI><A HREF="#see also">SEE ALSO</A></LI>
  29.     <LI><A HREF="#authors">AUTHORS</A></LI>
  30.     <LI><A HREF="#acknowledgments">ACKNOWLEDGMENTS</A></LI>
  31.     <LI><A HREF="#copyright">COPYRIGHT</A></LI>
  32. </UL>
  33. <!-- INDEX END -->
  34.  
  35. <HR>
  36. <P>
  37. <H1><A NAME="name">NAME</A></H1>
  38. <P>Net::PH - CCSO Nameserver Client class</P>
  39. <P>
  40. <HR>
  41. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  42. <UL>
  43. <LI>Linux</LI>
  44. <LI>Solaris</LI>
  45. <LI>Windows</LI>
  46. </UL>
  47. <HR>
  48. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  49. <PRE>
  50.     use Net::PH;
  51. </PRE>
  52. <PRE>
  53.  
  54.     $ph = Net::PH->new("some.host.name",
  55.                        Port    => 105,
  56.                        Timeout => 120,
  57.                        Debug   => 0);</PRE>
  58. <PRE>
  59.     if($ph) {
  60.         $q = $ph->query({ field1 => "value1" },
  61.                         [qw(name address pobox)]);
  62. </PRE>
  63. <PRE>
  64.  
  65.         if($q) {
  66.         }
  67.     }</PRE>
  68. <PRE>
  69.  
  70.     # Alternative syntax</PRE>
  71. <PRE>
  72.  
  73.     if($ph) {
  74.         $q = $ph->query('field1=value1',
  75.                         'name address pobox');</PRE>
  76. <PRE>
  77.  
  78.         if($q) {
  79.         }
  80.     }</PRE>
  81. <P>
  82. <HR>
  83. <H1><A NAME="description">DESCRIPTION</A></H1>
  84. <P><CODE>Net::PH</CODE> is a class implementing a simple Nameserver/PH client in Perl
  85. as described in the CCSO Nameserver -- Server-Client Protocol. Like other
  86. modules in the Net:: family the <CODE>Net::PH</CODE> object inherits methods from
  87. <CODE>Net::Cmd</CODE>.</P>
  88. <P>
  89. <HR>
  90. <H1><A NAME="constructor">CONSTRUCTOR</A></H1>
  91. <DL>
  92. <DT><STRONG><A NAME="item_new">new ( [ HOST ] [, OPTIONS ])</A></STRONG><BR>
  93. <DD>
  94. <PRE>
  95.     $ph = Net::PH->new("some.host.name",
  96.                        Port    => 105,
  97.                        Timeout => 120,
  98.                        Debug   => 0
  99.                       );</PRE>
  100. <P>This is the constructor for a new Net::PH object. <CODE>HOST</CODE> is the
  101. name of the remote host to which a PH connection is required.</P>
  102. <P>If <CODE>HOST</CODE> is not given, then the <CODE>SNPP_Host</CODE> specified in <CODE>Net::Config</CODE>
  103. will be used.</P>
  104. <P><CODE>OPTIONS</CODE> is an optional list of named options which are passed in
  105. a hash like fashion, using key and value pairs. Possible options are:-</P>
  106. <P><STRONG>Port</STRONG> - Port number to connect to on remote host.</P>
  107. <P><STRONG>Timeout</STRONG> - Maximum time, in seconds, to wait for a response from the
  108. Nameserver, a value of zero will cause all IO operations to block.
  109. (default: 120)</P>
  110. <P><STRONG>Debug</STRONG> - Enable the printing of debugging information to STDERR</P>
  111. </DL>
  112. <P>
  113. <HR>
  114. <H1><A NAME="methods">METHODS</A></H1>
  115. <P>Unless otherwise stated all methods return either a <EM>true</EM> or <EM>false</EM>
  116. value, with <EM>true</EM> meaning that the operation was a success. When a method
  117. states that it returns a value, failure will be returned as <EM>undef</EM> or an
  118. empty list.</P>
  119. <DL>
  120. <DT><STRONG><A NAME="item_query">query( SEARCH [, RETURN ] )</A></STRONG><BR>
  121. <DD>
  122. <PRE>
  123.     $q = $ph->query({ name => $myname },
  124.                     [qw(name email schedule)]);
  125. </PRE>
  126. <PRE>
  127.  
  128.     foreach $handle (@{$q}) {
  129.         foreach $field (keys %{$handle}) {
  130.             $c = ${$handle}{$field}->code;
  131.             $v = ${$handle}{$field}->value;
  132.             $f = ${$handle}{$field}->field;
  133.             $t = ${$handle}{$field}->text;
  134.             print "field:[$field] [$c][$v][$f][$t]\n" ;
  135.         }
  136.     }</PRE>
  137. <P></P>
  138. <P>Search the database and return fields from all matching entries.</P>
  139. <P>The <CODE>SEARCH</CODE> argument is a reference to a HASH which contains field/value
  140. pairs which will be passed to the Nameserver as the search criteria.</P>
  141. <P><CODE>RETURN</CODE> is optional, but if given it should be a reference to a list which
  142. contains field names to be returned.</P>
  143. <P>The alternative syntax is to pass strings instead of references, for example</P>
  144. <PRE>
  145.     $q = $ph->query('name=myname',
  146.                     'name email schedule');</PRE>
  147. <P>The <CODE>SEARCH</CODE> argument is a string that is passed to the Nameserver as the 
  148. search criteria. The strings being passed should <STRONG>not</STRONG> contain any carriage
  149. returns, or else the query command might fail or return invalid data.</P>
  150. <P><CODE>RETURN</CODE> is optional, but if given it should be a string which will
  151. contain field names to be returned.</P>
  152. <P>Each match from the server will be returned as a HASH where the keys are the
  153. field names and the values are <CODE>Net::PH:Result</CODE> objects (<EM>code</EM>, <EM>value</EM>, 
  154. <EM>field</EM>, <EM>text</EM>).</P>
  155. <P>Returns a reference to an ARRAY which contains references to HASHs, one
  156. per match from the server.</P>
  157. <DT><STRONG><A NAME="item_change">change( SEARCH , MAKE )</A></STRONG><BR>
  158. <DD>
  159. <PRE>
  160.     $r = $ph->change({ email => "*.domain.name" },
  161.                      { schedule => "busy");</PRE>
  162. <P>Change field values for matching entries.</P>
  163. <P>The <CODE>SEARCH</CODE> argument is a reference to a HASH which contains field/value
  164. pairs which will be passed to the Nameserver as the search criteria.</P>
  165. <P>The <CODE>MAKE</CODE> argument is a reference to a HASH which contains field/value
  166. pairs which will be passed to the Nameserver that
  167. will set new values to designated fields.</P>
  168. <P>The alternative syntax is to pass strings instead of references, for example</P>
  169. <PRE>
  170.     $r = $ph->change('email="*.domain.name"',
  171.                      'schedule="busy"');</PRE>
  172. <P>The <CODE>SEARCH</CODE> argument is a string to be passed to the Nameserver as the 
  173. search criteria. The strings being passed should <STRONG>not</STRONG> contain any carriage
  174. returns, or else the query command might fail or return invalid data.</P>
  175. <P>The <CODE>MAKE</CODE> argument is a string to be passed to the Nameserver that
  176. will set new values to designated fields.</P>
  177. <P>Upon success all entries that match the search criteria will have
  178. the field values, given in the Make argument, changed.</P>
  179. <DT><STRONG><A NAME="item_login">login( USER, PASS [, ENCRYPT ])</A></STRONG><BR>
  180. <DD>
  181. <PRE>
  182.     $r = $ph->login('username','password',1);</PRE>
  183. <P>Enter login mode using <CODE>USER</CODE> and <CODE>PASS</CODE>. If <CODE>ENCRYPT</CODE> is given and
  184. is <EM>true</EM> then the password will be used to encrypt a challenge text 
  185. string provided by the server, and the encrypted string will be sent back
  186. to the server. If <CODE>ENCRYPT</CODE> is not given, or <EM>false</EM> then the password 
  187. will be sent in clear text (<EM>this is not recommended</EM>)</P>
  188. <DT><STRONG><A NAME="item_logout"><CODE>logout()</CODE></A></STRONG><BR>
  189. <DD>
  190. <PRE>
  191.     $r = $ph->logout();</PRE>
  192. <P>Exit login mode and return to anonymous mode.</P>
  193. <DT><STRONG><A NAME="item_fields">fields( [ FIELD_LIST ] )</A></STRONG><BR>
  194. <DD>
  195. <PRE>
  196.     $fields = $ph->fields();
  197.     foreach $field (keys %{$fields}) {
  198.         $c = ${$fields}{$field}->code;
  199.         $v = ${$fields}{$field}->value;
  200.         $f = ${$fields}{$field}->field;
  201.         $t = ${$fields}{$field}->text;
  202.         print "field:[$field] [$c][$v][$f][$t]\n";
  203.     }</PRE>
  204. <P>In a scalar context, returns a reference to a HASH. The keys of the HASH are
  205. the field names and the values are <CODE>Net::PH:Result</CODE> objects (<EM>code</EM>,
  206. <EM>value</EM>, <EM>field</EM>, <EM>text</EM>).</P>
  207. <P>In an array context, returns a two element array. The first element is a
  208. reference to a HASH as above, the second element is a reference to an array
  209. which contains the tag names in the order that they were returned from the
  210. server.</P>
  211. <P><CODE>FIELD_LIST</CODE> is a string that lists the fields for which info will be
  212. returned.</P>
  213. <DT><STRONG><A NAME="item_add">add( FIELD_VALUES )</A></STRONG><BR>
  214. <DD>
  215. <PRE>
  216.     $r = $ph->add( { name => $name, phone => $phone });</PRE>
  217. <P>This method is used to add new entries to the Nameserver database. You
  218. must successfully call <A HREF="#item_login">login</A> before this method can be used.</P>
  219. <P><STRONG>Note</STRONG> that this method adds new entries to the database. To modify
  220. an existing entry use <A HREF="#item_change">change</A>.</P>
  221. <P><CODE>FIELD_VALUES</CODE> is a reference to a HASH which contains field/value
  222. pairs which will be passed to the Nameserver and will be used to 
  223. initialize the new entry.</P>
  224. <P>The alternative syntax is to pass a string instead of a reference, for example</P>
  225. <PRE>
  226.     $r = $ph->add('name=myname phone=myphone');</PRE>
  227. <P><CODE>FIELD_VALUES</CODE> is a string that consists of field/value pairs which the
  228. new entry will contain. The strings being passed should <STRONG>not</STRONG> contain any
  229. carriage returns, or else the query command might fail or return invalid data.</P>
  230. <DT><STRONG><A NAME="item_delete">delete( FIELD_VALUES )</A></STRONG><BR>
  231. <DD>
  232. <PRE>
  233.     $r = $ph->delete('name=myname phone=myphone');</PRE>
  234. <P>This method is used to delete existing entries from the Nameserver database.
  235. You must successfully call <A HREF="#item_login">login</A> before this method can be used.</P>
  236. <P><STRONG>Note</STRONG> that this method deletes entries to the database. To modify
  237. an existing entry use <A HREF="#item_change">change</A>.</P>
  238. <P><CODE>FIELD_VALUES</CODE> is a string that serves as the search criteria for the
  239. records to be deleted. Any entry in the database which matches this search 
  240. criteria will be deleted.</P>
  241. <DT><STRONG><A NAME="item_id">id( [ ID ] )</A></STRONG><BR>
  242. <DD>
  243. <PRE>
  244.     $r = $ph->id('709');</PRE>
  245. <P>Sends <CODE>ID</CODE> to the Nameserver, which will enter this into its
  246. logs. If <CODE>ID</CODE> is not given then the UID of the user running the
  247. process will be sent.</P>
  248. <DT><STRONG><A NAME="item_status"><CODE>status()</CODE></A></STRONG><BR>
  249. <DD>
  250. Returns the current status of the Nameserver.
  251. <P></P>
  252. <DT><STRONG><A NAME="item_siteinfo"><CODE>siteinfo()</CODE></A></STRONG><BR>
  253. <DD>
  254. <PRE>
  255.     $siteinfo = $ph->siteinfo();
  256.     foreach $field (keys %{$siteinfo}) {
  257.         $c = ${$siteinfo}{$field}->code;
  258.         $v = ${$siteinfo}{$field}->value;
  259.         $f = ${$siteinfo}{$field}->field;
  260.         $t = ${$siteinfo}{$field}->text;
  261.         print "field:[$field] [$c][$v][$f][$t]\n";
  262.     }</PRE>
  263. <P>Returns a reference to a HASH containing information about the server's 
  264. site. The keys of the HASH are the field names and values are
  265. <CODE>Net::PH:Result</CODE> objects (<EM>code</EM>, <EM>value</EM>, <EM>field</EM>, <EM>text</EM>).</P>
  266. <DT><STRONG><A NAME="item_quit"><CODE>quit()</CODE></A></STRONG><BR>
  267. <DD>
  268. <PRE>
  269.     $r = $ph->quit();</PRE>
  270. <P>Quit the connection</P>
  271. </DL>
  272. <P>
  273. <HR>
  274. <H1><A NAME="q&a">Q&A</A></H1>
  275. <P>How do I get the values of a Net::PH::Result object?</P>
  276. <PRE>
  277.     foreach $handle (@{$q}) {
  278.         foreach $field (keys %{$handle}) {
  279.             $my_code  = ${$q}{$field}->code;
  280.             $my_value = ${$q}{$field}->value;
  281.             $my_field = ${$q}{$field}->field;
  282.             $my_text  = ${$q}{$field}->text;
  283.         }
  284.     }</PRE>
  285. <P>How do I get a count of the returned matches to my query?</P>
  286. <PRE>
  287.     $my_count = scalar(@{$query_result});</PRE>
  288. <P>How do I get the status code and message of the last <CODE>$ph</CODE> command?</P>
  289. <PRE>
  290.     $status_code    = $ph->code;
  291.     $status_message = $ph->message;</PRE>
  292. <P>
  293. <HR>
  294. <H1><A NAME="see also">SEE ALSO</A></H1>
  295. <P><A HREF="../../../site/lib/Net/Cmd.html">the Net::Cmd manpage</A></P>
  296. <P>
  297. <HR>
  298. <H1><A NAME="authors">AUTHORS</A></H1>
  299. <P>Graham Barr <<A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A>>
  300. Alex Hristov <<A HREF="mailto:hristov@slb.com">hristov@slb.com</A>></P>
  301. <P>
  302. <HR>
  303. <H1><A NAME="acknowledgments">ACKNOWLEDGMENTS</A></H1>
  304. <P>Password encryption code ported to perl by Broc Seib <<A HREF="mailto:bseib@purdue.edu">bseib@purdue.edu</A>>,
  305. Purdue University Computing Center.</P>
  306. <P>Otis Gospodnetic <<A HREF="mailto:otisg@panther.middlebury.edu">otisg@panther.middlebury.edu</A>> suggested
  307. passing parameters as string constants. Some queries cannot be 
  308. executed when passing parameters as string references.</P>
  309. <PRE>
  310.         Example: query first_name last_name email="*.domain"</PRE>
  311. <P>
  312. <HR>
  313. <H1><A NAME="copyright">COPYRIGHT</A></H1>
  314. <P>The encryption code is based upon cryptit.c, Copyright (C) 1988 by
  315. Steven Dorner, and Paul Pomes, and the University of Illinois Board
  316. of Trustees, and by CSNET.</P>
  317. <P>All other code is Copyright (c) 1996-1997 Graham Barr <<A HREF="mailto:gbarr@pobox.com">gbarr@pobox.com</A>>
  318. and Alex Hristov <<A HREF="mailto:hristov@slb.com">hristov@slb.com</A>>. All rights reserved. This program is
  319. free software; you can redistribute it and/or modify it under the same
  320. terms as Perl itself.</P>
  321. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  322. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  323. <STRONG><P CLASS=block> Net::PH - CCSO Nameserver Client class</P></STRONG>
  324. </TD></TR>
  325. </TABLE>
  326.  
  327. </BODY>
  328.  
  329. </HTML>
  330.