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