/[cvs]/nfo/php/libs/org.netfrag.glib/DataSource/Proxy/XMLRPC.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DataSource/Proxy/XMLRPC.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Wed Mar 5 23:16:48 2003 UTC revision 1.5 by joko, Fri Mar 28 06:56:52 2003 UTC
# Line 14  Line 14 
14  ##    $Id$  ##    $Id$
15  ##    --------------------------------------------------------------------------  ##    --------------------------------------------------------------------------
16  ##    $Log$  ##    $Log$
17    ##    Revision 1.5  2003/03/28 06:56:52  joko
18    ##    updated logging/debugging code
19    ##
20    ##    Revision 1.4  2003/03/28 03:00:12  joko
21    ##    enhanced error- and exception-handling
22    ##
23    ##    Revision 1.3  2003/03/27 16:05:01  joko
24    ##    enhanced 'function _call': debugging, tracing and autodisconnect now parametrized
25    ##
26  ##    Revision 1.2  2003/03/05 23:16:48  joko  ##    Revision 1.2  2003/03/05 23:16:48  joko
27  ##    updated docu - phpDocumentor is very strict about its 'blocks'...  ##    updated docu - phpDocumentor is very strict about its 'blocks'...
28  ##  ##
# Line 92  loadModule('Class::Logger'); Line 101  loadModule('Class::Logger');
101  class DataSource_Proxy_XMLRPC extends Class_Logger {  class DataSource_Proxy_XMLRPC extends Class_Logger {
102    
103    var $configured;    var $configured;
104    var $meta;    var $meta = array();
105      var $response = null;
106      var $errors = array();
107        
108    function DataSource_Proxy_XMLRPC($args = array()) {    function DataSource_Proxy_XMLRPC($args = array()) {
109    
110      parent::constructor();      parent::constructor();
111    
112      //print Dumper($this, $args);      //print Dumper($this, $args);
113        //print Dumper($args);
114    
115      global $Data_Driver_RPC_Remote_meta;      global $Data_Driver_RPC_Remote_meta;
116      session_register_safe("Data_Driver_RPC_Remote_meta");      session_register_safe("Data_Driver_RPC_Remote_meta");
117      $this->meta = $Data_Driver_RPC_Remote_meta;      $this->meta = $Data_Driver_RPC_Remote_meta;
118    
119        // force connect?
120        
121        // V1
122        /*
123      if (!isset($this->meta[connected]) || $args[connect]) {      if (!isset($this->meta[connected]) || $args[connect]) {
124        $this->meta[connected] = 1;        $this->meta[connected] = 1;
125      }      }
126        */
127    
128        // V2
129        $this->FORCE_CONNECT = $args[connect];
130    
131      $this->_save_meta();      $this->_save_meta();
132    
133      if ($args['Host']) { $this->host = $args['Host']; }  
134      if ($args['Port']) { $this->port = $args['Port']; }      // merge args - V1
135        //if ($args['Host']) { $this->HOST = $args['Host']; }
136        //if ($args['Port']) { $this->PORT = $args['Port']; }
137    
138        // merge args - V2
139        // TODO: php::merge_to($this, $args);
140        //php::merge_to($this, $args);
141        //print Dumper($args);
142        if (is_array($args)) {
143          foreach ($args as $key => $val) {
144            //print "key: $key<br/>";
145            $key = strtoupper($key);
146            $this->$key = $val;
147          }
148        }
149    
150      // check if host is valid      // check if host is valid
151      if (!$this->host) {      if (!$this->HOST) {
152        $this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings");        $this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings");
153        return;        return;
154      }      }
155            
156      if (!$this->port) {      if (!$this->PORT) {
157        $this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings");        $this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings");
158        return;        return;
159      }      }
# Line 136  class DataSource_Proxy_XMLRPC extends Cl Line 171  class DataSource_Proxy_XMLRPC extends Cl
171    
172      $this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG);      $this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG);
173            
174        /*
175      if (!$this->isConnected()) {      if (!$this->isConnected()) {
176        $this->_raiseException( "->send: not connected!");        $this->_raiseException( "->send[ command=$command ]: not connected while trying to send command!");
177        return;        return;
178      }      }
179        */
180            
181      // do 'encode' here and ...      // do 'encode' here and ...
182      if ($options[utf8]) {      if ($options[utf8]) {
# Line 150  class DataSource_Proxy_XMLRPC extends Cl Line 187  class DataSource_Proxy_XMLRPC extends Cl
187      return $this->_call($command, $data, $options);      return $this->_call($command, $data, $options);
188    }    }
189    
190    
191    function _call($command, $data = "", $options = array() ) {    function _call($command, $data = "", $options = array() ) {
192    
193      if (!$this->configured) {      if (!$this->configured) {
# Line 166  class DataSource_Proxy_XMLRPC extends Cl Line 204  class DataSource_Proxy_XMLRPC extends Cl
204      $data_debug = $data;      $data_debug = $data;
205      if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); }      if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); }
206      $options_debug = join(", ", $options_list);      $options_debug = join(", ", $options_list);
207      $this->log(get_class($this) . ": " . $command . "(" . $data_debug . ") [" . $options_debug . "]", PEAR_LOG_DEBUG);      $this->log(get_class($this) . "->_call: " . $command . "(" . $data_debug . ") [" . $options_debug . "]", PEAR_LOG_DEBUG);
208    
209      // trace      // trace
210        //print "call: $command<hr>";        //print "call: $command<hr>";
# Line 174  class DataSource_Proxy_XMLRPC extends Cl Line 212  class DataSource_Proxy_XMLRPC extends Cl
212        //print Dumper($this);        //print Dumper($this);
213    
214      // data      // data
215        $data_enc = XML_RPC_encode($data);      $data_enc = XML_RPC_encode($data);
216    
217      // message - request      // message - request
218        $msg = new XML_RPC_Message($command);      $msg = new XML_RPC_Message($command);
219        $msg->addParam($data_enc);      $msg->addParam($data_enc);
220  //print htmlentities($msg->serialize());  
221        // ???
222        //print htmlentities($msg->serialize());
223    
224      // remote procedure call      // remote procedure call
225        $rpc = new XML_RPC_Client("/", $this->host, $this->port);      $rpc = new XML_RPC_Client("/", $this->HOST, $this->PORT);
226        $rpc->setDebug(0);      
227        if ( !$msg_response = $rpc->send($msg) ) {      // TODO: detect highlevel errors, raise proper exceptions on them (e.g. 'Unknown method', 'Method signature error(s)')
228          // TODO: redirect this error elsewhere!      // done: now possible to declare tracing at this point in configuration
229          //print "RPC-error!<br>";      //    Please look inside your {appname}/etc/hosts/{hostname}.php
230          $this->_raiseException( "->_call: no response");      $rpc->setDebug($this->TRACE);
231          return;      //$rpc->setDebug(1);
232        }      
233        if ( $this->response = $rpc->send($msg) ) {
234          // intermediate result error checking
235          $this->_checkException();
236        } else {
237          // TODO: redirect this error elsewhere!
238          //print "RPC-error!<br>";
239          $this->_raiseException( "->_call: no response");
240          return;
241        }
242        
243      // message - response      // message - response
244        $response_enc = $msg_response->value();      $response_enc = $this->response->value();
245    
246        // TODO: what's this? prematurely returning here should not be considered "stable"....
247        return $this->decodeData($response_enc, $options);
248    
       // TODO: what's this? prematurely returning here should not be considered "stable"....  
       return $this->decodeData($response_enc, $options);  
249    }    }
250        
251    
252    function &decodeData(&$payload, $options = array() ) {    function &decodeData(&$payload, $options = array() ) {
253      //if (!is_object($payload)) { return; }      //if (!is_object($payload)) { return; }
254        if ($payload) {        if ($payload) {
# Line 209  class DataSource_Proxy_XMLRPC extends Cl Line 262  class DataSource_Proxy_XMLRPC extends Cl
262            $encoder->toISO();            $encoder->toISO();
263          //}          //}
264                    
265          $this->meta[connected] = 1;          $this->_be_connected();
266          $this->_save_meta();          
   
267          return $data;          return $data;
268        } else {        } else {
269          //print "ERROR!<br>";          //print "ERROR!<br>";
# Line 219  class DataSource_Proxy_XMLRPC extends Cl Line 271  class DataSource_Proxy_XMLRPC extends Cl
271        }        }
272    }    }
273        
274    function _raiseException($message) {    function _be_connected() {
275      $this->meta[connected] = 0;      $this->meta[connected] = 1;
276      $this->_save_meta();      $this->_save_meta();
277      $this->log(get_class($this) . $message, PEAR_LOG_ERR);    }
278      
279      function _raiseException($message, $code = null) {
280        
281        $classname = get_class($this);
282        
283        // aggregate errors for this run/query
284        $this->_add_error($classname . $message, $code);
285        
286        // spout out the error message of the raised exception
287        $this->log($classname . $message, PEAR_LOG_ERR);
288    
289        // handle some stuff regarding more special behaviour (will this get rule-based sometimes?)
290        
291        // handle 'FORCE_CONNECT'
292        $connect_condition = $this->FORCE_CONNECT = ($this->isConnected() && $this->DISCONNECT_ON_ERROR);
293        if ($connect_condition) {
294          $message = '->_raiseException: [DISCONNECT_ON_ERROR] done transparently. Please reconnect manually.';
295          $this->_add_error($classname . $message, $code);
296          //$this->log($classname . $message, PEAR_LOG_WARNING);
297          $this->log($classname . $message, PEAR_LOG_ERR);
298          $this->meta[connected] = 0;
299          $this->_save_meta();
300        }
301    }    }
302        
303    function isConnected() {    function isConnected() {
# Line 233  class DataSource_Proxy_XMLRPC extends Cl Line 308  class DataSource_Proxy_XMLRPC extends Cl
308      $this->_call('ping');      $this->_call('ping');
309    }    }
310        
311    
312      function _checkException() {
313        //    Please look inside your {appname}/etc/hosts/{hostname}.php for toggling $this->DEBUG
314        if ($error_code = $this->response->faultCode()) {
315          //print $msg_response->faultString();
316          $this->_raiseException( "->_call: " . $this->response->faultString(), $error_code );
317        }
318      }
319    
320        //if ($this->DEBUG && $error_code = $msg_response->faultCode()) {
321    
322    
323      function _add_error($message, $code) {
324        array_push( $this->errors, array(code => $code, message => $message) );
325      }
326      
327      function getStatus() {
328        return array( connected => $this->isConnected(), errors => $this->errors );
329      }
330      
331  }  }
332    
333  ?>  ?>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed