1 |
joko |
1.1 |
<? |
2 |
|
|
## -------------------------------------------------------------------------- |
3 |
joko |
1.7 |
## $Id: Remote.php,v 1.6 2003/02/03 03:37:45 jonen Exp $ |
4 |
joko |
1.1 |
## -------------------------------------------------------------------------- |
5 |
joko |
1.2 |
## $Log: Remote.php,v $ |
6 |
joko |
1.7 |
## Revision 1.6 2003/02/03 03:37:45 jonen |
7 |
|
|
## - removed unused argument '$decode' at function '_call()' |
8 |
|
|
## + added argument '$options=array()' at function '_call()' |
9 |
|
|
## which will be passed to function '&decodeData()' for e.g. utf8 decoding |
10 |
|
|
## + added '$encoder->toISO()' at '&decodeData()', (re)moved from 'ProxyObject.php' |
11 |
|
|
## |
12 |
jonen |
1.6 |
## Revision 1.5 2002/12/22 13:24:09 jonen |
13 |
|
|
## + added utf8 encoding at 'send()' toggled by option |
14 |
|
|
## |
15 |
jonen |
1.5 |
## Revision 1.4 2002/12/19 02:02:25 jonen |
16 |
|
|
## + minor changes |
17 |
|
|
## |
18 |
jonen |
1.4 |
## Revision 1.3 2002/12/19 01:59:37 jonen |
19 |
|
|
## + minor changes: coment debug prints |
20 |
|
|
## |
21 |
jonen |
1.3 |
## Revision 1.2 2002/12/05 21:45:31 joko |
22 |
|
|
## + debugging |
23 |
|
|
## |
24 |
joko |
1.2 |
## Revision 1.1 2002/12/01 17:23:58 joko |
25 |
|
|
## + initial check-in |
26 |
|
|
## |
27 |
joko |
1.1 |
## Revision 1.3 2002/12/01 06:22:57 cvsjoko |
28 |
|
|
## + minor update: now can use config defaults or given args |
29 |
|
|
## |
30 |
|
|
## Revision 1.2 2002/10/29 19:14:45 cvsjoko |
31 |
|
|
## - bugfix: dont' do utf8-encoding here |
32 |
|
|
## |
33 |
|
|
## Revision 1.1 2002/10/09 00:51:39 cvsjoko |
34 |
|
|
## + new |
35 |
|
|
## |
36 |
|
|
## |
37 |
|
|
## ------------------------------------------------------------------------- |
38 |
|
|
|
39 |
|
|
class Remote { |
40 |
|
|
|
41 |
|
|
function Remote($args = array()) { |
42 |
|
|
global $cfg; |
43 |
joko |
1.2 |
//print "new Remote<br>"; |
44 |
joko |
1.1 |
$this->host = $cfg[rpcinfo][Host]; |
45 |
|
|
$this->port = $cfg[rpcinfo][Port]; |
46 |
|
|
if ($args['Host']) { $this->host = $args['Host']; } |
47 |
|
|
if ($args['Port']) { $this->port = $args['Port']; } |
48 |
|
|
} |
49 |
|
|
|
50 |
jonen |
1.5 |
function send($command, $data = "", $options = array()) { |
51 |
|
|
// do 'encode' here and ... |
52 |
|
|
if ($options[utf8]) { |
53 |
|
|
$encoder = new TextEncode($data); |
54 |
|
|
$encoder->toUTF8(); |
55 |
|
|
} |
56 |
|
|
// call '_call' with 'decode' |
57 |
jonen |
1.6 |
return $this->_call($command, $data, $options); |
58 |
joko |
1.1 |
} |
59 |
|
|
|
60 |
jonen |
1.6 |
function _call($command, $data = "", $options = array() ) { |
61 |
joko |
1.2 |
|
62 |
jonen |
1.5 |
//print "call: $command<hr>"; |
63 |
|
|
|
64 |
|
|
// print Dumper($data); |
65 |
joko |
1.1 |
|
66 |
|
|
// data |
67 |
|
|
$data_enc = XML_RPC_encode($data); |
68 |
|
|
|
69 |
|
|
// message - request |
70 |
|
|
$msg = new XML_RPC_Message($command); |
71 |
|
|
$msg->addParam($data_enc); |
72 |
jonen |
1.5 |
//print htmlentities($msg->serialize()); |
73 |
joko |
1.1 |
// remote procedure call |
74 |
|
|
$rpc = new XML_RPC_Client("/", $this->host, $this->port); |
75 |
|
|
$rpc->setDebug(0); |
76 |
|
|
if ( !$msg_response = $rpc->send($msg) ) { |
77 |
joko |
1.2 |
// TODO: redirect this error elsewhere! |
78 |
jonen |
1.3 |
print "RPC-error!<br>"; |
79 |
joko |
1.1 |
return; |
80 |
|
|
} |
81 |
|
|
// message - response |
82 |
|
|
$response_enc = $msg_response->value(); |
83 |
|
|
|
84 |
|
|
// TODO: what's this? prematurely returning here should not be considered "stable".... |
85 |
jonen |
1.6 |
return $this->decodeData($response_enc, $options); |
86 |
joko |
1.1 |
} |
87 |
|
|
|
88 |
jonen |
1.6 |
function &decodeData(&$payload, $options = array() ) { |
89 |
joko |
1.1 |
//if (!is_object($payload)) { return; } |
90 |
|
|
if ($payload) { |
91 |
|
|
// data |
92 |
|
|
$data = XML_RPC_decode($payload); |
93 |
|
|
//print "data: " . dumpVar($response); |
94 |
jonen |
1.6 |
|
95 |
|
|
// decode UTF8 to ISO if wanted |
96 |
|
|
if($options[utf8]) { |
97 |
|
|
$encoder = new TextEncode($data); |
98 |
|
|
$encoder->toISO(); |
99 |
|
|
} |
100 |
|
|
|
101 |
joko |
1.1 |
return $data; |
102 |
|
|
} else { |
103 |
|
|
//print "ERROR!<br>"; |
104 |
|
|
return 0; |
105 |
|
|
} |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
?> |