1 |
<?php |
2 |
/* |
3 |
OpenIsis - an open implementation of the CDS/ISIS database |
4 |
Version 0.8.x (patchlevel see file Version) |
5 |
Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org |
6 |
|
7 |
This library is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU Lesser General Public |
9 |
License as published by the Free Software Foundation; either |
10 |
version 2.1 of the License, or (at your option) any later version. |
11 |
|
12 |
This library is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
Lesser General Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU Lesser General Public |
18 |
License along with this library; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
21 |
see README for more information |
22 |
EOH */ |
23 |
|
24 |
// $Id: Server.php,v 1.5 2003/06/30 09:54:45 kripke Exp $ |
25 |
|
26 |
|
27 |
/** |
28 |
This class represents the connection to an Isis server. |
29 |
|
30 |
In general, a server is any object having a request function, |
31 |
accepting a single Isis_Rec parameter and returning an Isis_Rec. |
32 |
|
33 |
This implementation is based on a TCP or UNIX socket. |
34 |
|
35 |
@version $Revision: 1.5 $ |
36 |
@license LGPL |
37 |
@package Isis |
38 |
*/ |
39 |
class Isis_Server { |
40 |
var $host; |
41 |
var $port; |
42 |
var $sock; |
43 |
var $pers; |
44 |
|
45 |
function Isis_Server ($host, $port = 2042, $pers = 0) |
46 |
{ |
47 |
$this->host = $host; |
48 |
$this->port = $port; |
49 |
$this->pers = $pers; |
50 |
$this->open(); |
51 |
} |
52 |
|
53 |
function open () |
54 |
{ |
55 |
// pfsockopen will reuse an existing socket on same host:port |
56 |
// should we use stream_socket_client ??? |
57 |
$this->sock = $this->pers |
58 |
? pfsockopen( $this->host, $this->port /*, $errno, $errstr*/ ) |
59 |
: fsockopen( $this->host, $this->port /*, $errno, $errstr*/ ); |
60 |
// if ( false == $this->sock ) |
61 |
// echo "could not connect to $host:$port: $errno '$errstr'"; |
62 |
// stupid PHP prints warnings itself %< |
63 |
return $this->sock; |
64 |
} |
65 |
|
66 |
|
67 |
function request ( $req ) |
68 |
{ |
69 |
if ( !$this->sock && !$this->open() ) |
70 |
return null; |
71 |
// echo "SEND\n", $req->toString(ISIS_REC_TEXT); |
72 |
fwrite($this->sock, $req->toString(ISIS_REC_TEXT) . "\n"); |
73 |
fflush($this->sock); |
74 |
$txt = ''; |
75 |
while ( ($line = fgets($this->sock)) && "\n" != $line ) { |
76 |
// error_log( "RETR ". $line ); |
77 |
$txt .= $line; |
78 |
} |
79 |
$res = new Isis_Rec; |
80 |
$res->parse($txt, ISIS_REC_TEXT); |
81 |
// error_log( "GOT ". $res->toString() ); |
82 |
return $res; |
83 |
} |
84 |
|
85 |
} // class Isis_Server |
86 |
?> |