| 1 |
joko |
1.1 |
<? |
| 2 |
|
|
## -------------------------------------------------------------------------- |
| 3 |
|
|
## $Id: Backend.class.php,v 1.3 2002/12/01 06:22:57 cvsjoko Exp $ |
| 4 |
|
|
## -------------------------------------------------------------------------- |
| 5 |
|
|
## $Log: Backend.class.php,v $ |
| 6 |
|
|
## Revision 1.3 2002/12/01 06:22:57 cvsjoko |
| 7 |
|
|
## + minor update: now can use config defaults or given args |
| 8 |
|
|
## |
| 9 |
|
|
## Revision 1.2 2002/10/29 19:14:45 cvsjoko |
| 10 |
|
|
## - bugfix: dont' do utf8-encoding here |
| 11 |
|
|
## |
| 12 |
|
|
## Revision 1.1 2002/10/09 00:51:39 cvsjoko |
| 13 |
|
|
## + new |
| 14 |
|
|
## |
| 15 |
|
|
## |
| 16 |
|
|
## ------------------------------------------------------------------------- |
| 17 |
|
|
|
| 18 |
|
|
class Remote { |
| 19 |
|
|
|
| 20 |
|
|
function Remote($args = array()) { |
| 21 |
|
|
global $cfg; |
| 22 |
|
|
$this->host = $cfg[rpcinfo][Host]; |
| 23 |
|
|
$this->port = $cfg[rpcinfo][Port]; |
| 24 |
|
|
if ($args['Host']) { $this->host = $args['Host']; } |
| 25 |
|
|
if ($args['Port']) { $this->port = $args['Port']; } |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
function &send($command, $data = "") { |
| 29 |
|
|
//$encoder = new Text_Encode($data); |
| 30 |
|
|
//$encoder->toUTF8(); |
| 31 |
|
|
return $this->call($command, $data, 1); |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
|
|
function &call($command, $data = "", $decode = 0) { |
| 35 |
|
|
|
| 36 |
|
|
// data |
| 37 |
|
|
$data_enc = XML_RPC_encode($data); |
| 38 |
|
|
|
| 39 |
|
|
// message - request |
| 40 |
|
|
$msg = new XML_RPC_Message($command); |
| 41 |
|
|
$msg->addParam($data_enc); |
| 42 |
|
|
// remote procedure call |
| 43 |
|
|
$rpc = new XML_RPC_Client("/", $this->host, $this->port); |
| 44 |
|
|
$rpc->setDebug(0); |
| 45 |
|
|
if ( !$msg_response = $rpc->send($msg) ) { |
| 46 |
|
|
return; |
| 47 |
|
|
} |
| 48 |
|
|
// message - response |
| 49 |
|
|
$response_enc = $msg_response->value(); |
| 50 |
|
|
|
| 51 |
|
|
// TODO: what's this? prematurely returning here should not be considered "stable".... |
| 52 |
|
|
return $this->decodeData($response_enc); |
| 53 |
|
|
|
| 54 |
|
|
if ($decode) { |
| 55 |
|
|
return $this->decodeData($response_enc); |
| 56 |
|
|
} else { |
| 57 |
|
|
return $response_enc; |
| 58 |
|
|
} |
| 59 |
|
|
|
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
function &decodeData(&$payload) { |
| 63 |
|
|
//if (!is_object($payload)) { return; } |
| 64 |
|
|
if ($payload) { |
| 65 |
|
|
// data |
| 66 |
|
|
$data = XML_RPC_decode($payload); |
| 67 |
|
|
//print "data: " . dumpVar($response); |
| 68 |
|
|
return $data; |
| 69 |
|
|
} else { |
| 70 |
|
|
//print "ERROR!<br>"; |
| 71 |
|
|
return 0; |
| 72 |
|
|
} |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
} |
| 76 |
|
|
|
| 77 |
|
|
?> |