| 1 |
<? |
<? |
| 2 |
|
/** |
| 3 |
|
* This file contains the DataSource::Proxy::XMLRPC module. |
| 4 |
|
* |
| 5 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 6 |
|
* @package org.netfrag.glib |
| 7 |
|
* @name DataSource::Proxy::XMLRPC |
| 8 |
|
* |
| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
|
| 12 |
/* |
/* |
| 13 |
## -------------------------------------------------------------------------- |
## -------------------------------------------------------------------------- |
| 14 |
## $Id$ |
## $Id$ |
| 15 |
## -------------------------------------------------------------------------- |
## -------------------------------------------------------------------------- |
| 16 |
## $Log$ |
## $Log$ |
| 17 |
|
## Revision 1.3 2003/03/27 16:05:01 joko |
| 18 |
|
## enhanced 'function _call': debugging, tracing and autodisconnect now parametrized |
| 19 |
|
## |
| 20 |
|
## Revision 1.2 2003/03/05 23:16:48 joko |
| 21 |
|
## updated docu - phpDocumentor is very strict about its 'blocks'... |
| 22 |
|
## |
| 23 |
## Revision 1.1 2003/03/03 21:53:52 joko |
## Revision 1.1 2003/03/03 21:53:52 joko |
| 24 |
## refactored from Data::Driver::RPC::Remote |
## refactored from Data::Driver::RPC::Remote |
| 25 |
## |
## |
| 71 |
*/ |
*/ |
| 72 |
|
|
| 73 |
|
|
|
/* |
|
|
|
|
|
TODO: |
|
|
o SOAP? |
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
| 74 |
// V1: normal require |
// V1: normal require |
| 75 |
//require_once 'XML/RPC/RPC.php'; |
//require_once 'XML/RPC/RPC.php'; |
| 76 |
|
|
| 80 |
|
|
| 81 |
loadModule('Class::Logger'); |
loadModule('Class::Logger'); |
| 82 |
|
|
| 83 |
|
|
| 84 |
|
/** |
| 85 |
|
* This is the DataSource::Proxy::XMLRPC module. |
| 86 |
|
* |
| 87 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
| 88 |
|
* @package org.netfrag.glib |
| 89 |
|
* @subpackage DataSource |
| 90 |
|
* @name DataSource::Proxy::XMLRPC |
| 91 |
|
* |
| 92 |
|
* @todo SOAP? |
| 93 |
|
* |
| 94 |
|
*/ |
| 95 |
class DataSource_Proxy_XMLRPC extends Class_Logger { |
class DataSource_Proxy_XMLRPC extends Class_Logger { |
| 96 |
|
|
| 97 |
var $configured; |
var $configured; |
| 112 |
} |
} |
| 113 |
$this->_save_meta(); |
$this->_save_meta(); |
| 114 |
|
|
| 115 |
if ($args['Host']) { $this->host = $args['Host']; } |
// merge args - V1 |
| 116 |
if ($args['Port']) { $this->port = $args['Port']; } |
//if ($args['Host']) { $this->HOST = $args['Host']; } |
| 117 |
|
//if ($args['Port']) { $this->PORT = $args['Port']; } |
| 118 |
|
|
| 119 |
|
// merge args - V2 |
| 120 |
|
// TODO: php::merge_to($this, $args); |
| 121 |
|
//php::merge_to($this, $args); |
| 122 |
|
//print Dumper($args); |
| 123 |
|
if (is_array($args)) { |
| 124 |
|
foreach ($args as $key => $val) { |
| 125 |
|
$key = strtoupper($key); |
| 126 |
|
$this->$key = $val; |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
|
| 130 |
// check if host is valid |
// check if host is valid |
| 131 |
if (!$this->host) { |
if (!$this->HOST) { |
| 132 |
$this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings"); |
$this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings"); |
| 133 |
return; |
return; |
| 134 |
} |
} |
| 135 |
|
|
| 136 |
if (!$this->port) { |
if (!$this->PORT) { |
| 137 |
$this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings"); |
$this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings"); |
| 138 |
return; |
return; |
| 139 |
} |
} |
| 152 |
$this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG); |
$this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG); |
| 153 |
|
|
| 154 |
if (!$this->isConnected()) { |
if (!$this->isConnected()) { |
| 155 |
$this->_raiseException( "->send: not connected!"); |
$this->_raiseException( "->send[ command=$command ]: not connected while trying to send command!"); |
| 156 |
return; |
return; |
| 157 |
} |
} |
| 158 |
|
|
| 165 |
return $this->_call($command, $data, $options); |
return $this->_call($command, $data, $options); |
| 166 |
} |
} |
| 167 |
|
|
| 168 |
|
|
| 169 |
function _call($command, $data = "", $options = array() ) { |
function _call($command, $data = "", $options = array() ) { |
| 170 |
|
|
| 171 |
if (!$this->configured) { |
if (!$this->configured) { |
| 190 |
//print Dumper($this); |
//print Dumper($this); |
| 191 |
|
|
| 192 |
// data |
// data |
| 193 |
$data_enc = XML_RPC_encode($data); |
$data_enc = XML_RPC_encode($data); |
| 194 |
|
|
| 195 |
// message - request |
// message - request |
| 196 |
$msg = new XML_RPC_Message($command); |
$msg = new XML_RPC_Message($command); |
| 197 |
$msg->addParam($data_enc); |
$msg->addParam($data_enc); |
| 198 |
//print htmlentities($msg->serialize()); |
|
| 199 |
|
// ??? |
| 200 |
|
//print htmlentities($msg->serialize()); |
| 201 |
|
|
| 202 |
// remote procedure call |
// remote procedure call |
| 203 |
$rpc = new XML_RPC_Client("/", $this->host, $this->port); |
$rpc = new XML_RPC_Client("/", $this->HOST, $this->PORT); |
| 204 |
$rpc->setDebug(0); |
|
| 205 |
if ( !$msg_response = $rpc->send($msg) ) { |
// TODO: detect highlevel errors, raise proper exceptions on them (e.g. 'Unknown method', 'Method signature error(s)') |
| 206 |
// TODO: redirect this error elsewhere! |
// done: now possible to declare tracing at this point in configuration |
| 207 |
//print "RPC-error!<br>"; |
// Please look inside your {appname}/etc/hosts/{hostname}.php |
| 208 |
$this->_raiseException( "->_call: no response"); |
$rpc->setDebug($this->TRACE); |
| 209 |
return; |
|
| 210 |
} |
if ( !$msg_response = $rpc->send($msg) ) { |
| 211 |
|
// TODO: redirect this error elsewhere! |
| 212 |
|
//print "RPC-error!<br>"; |
| 213 |
|
$this->_raiseException( "->_call: no response"); |
| 214 |
|
return; |
| 215 |
|
} |
| 216 |
|
|
| 217 |
// message - response |
// message - response |
| 218 |
$response_enc = $msg_response->value(); |
$response_enc = $msg_response->value(); |
| 219 |
|
|
| 220 |
|
// error handling |
| 221 |
|
// Please look inside your {appname}/etc/hosts/{hostname}.php for toggling $this->DEBUG |
| 222 |
|
if ($this->DEBUG && $error_code = $msg_response->faultCode()) { |
| 223 |
|
//print $msg_response->faultString(); |
| 224 |
|
$this->_raiseException( "->_call: " . $msg_response->faultString() ); |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
// TODO: what's this? prematurely returning here should not be considered "stable".... |
| 228 |
|
return $this->decodeData($response_enc, $options); |
| 229 |
|
|
|
// TODO: what's this? prematurely returning here should not be considered "stable".... |
|
|
return $this->decodeData($response_enc, $options); |
|
| 230 |
} |
} |
| 231 |
|
|
| 232 |
|
|
| 233 |
function &decodeData(&$payload, $options = array() ) { |
function &decodeData(&$payload, $options = array() ) { |
| 234 |
//if (!is_object($payload)) { return; } |
//if (!is_object($payload)) { return; } |
| 235 |
if ($payload) { |
if ($payload) { |
| 254 |
} |
} |
| 255 |
|
|
| 256 |
function _raiseException($message) { |
function _raiseException($message) { |
| 257 |
$this->meta[connected] = 0; |
|
| 258 |
$this->_save_meta(); |
// spout out the error message of the raised exception |
| 259 |
$this->log(get_class($this) . $message, PEAR_LOG_ERR); |
$this->log(get_class($this) . $message, PEAR_LOG_ERR); |
| 260 |
|
|
| 261 |
|
// handle some stuff regarding more special behaviour (will this get a 'rule' sometimes?) |
| 262 |
|
if ($this->isConnected() && $this->DISCONNECT_ON_ERROR) { |
| 263 |
|
$message = '->_raiseException: [DISCONNECT_ON_ERROR] done transparently. Please reconnect manually.'; |
| 264 |
|
$this->log(get_class($this) . $message, PEAR_LOG_WARNING); |
| 265 |
|
$this->meta[connected] = 0; |
| 266 |
|
$this->_save_meta(); |
| 267 |
|
} |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
function isConnected() { |
function isConnected() { |