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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Mar 5 23:16:48 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.1: +27 -11 lines
updated docu - phpDocumentor is very strict about its 'blocks'...

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: XMLRPC.php,v 1.1 2003/03/03 21:53:52 joko Exp $
15 ## --------------------------------------------------------------------------
16 ## $Log: XMLRPC.php,v $
17 ## Revision 1.1 2003/03/03 21:53:52 joko
18 ## refactored from Data::Driver::RPC::Remote
19 ##
20 ## Revision 1.4 2003/02/20 21:42:43 joko
21 ## + fix: always converting from utf8 into latin here (for now)
22 ##
23 ## Revision 1.3 2003/02/13 21:51:29 joko
24 ## + now can remember its connection-state
25 ## + sub ping
26 ##
27 ## Revision 1.2 2003/02/13 00:42:44 joko
28 ## +- renamed modules
29 ##
30 ## Revision 1.1 2003/02/09 17:25:38 joko
31 ## + refactored from flib/Application/RPC/Remote.php
32 ##
33 ## Revision 1.6 2003/02/03 03:37:45 jonen
34 ## - removed unused argument '$decode' at function '_call()'
35 ## + added argument '$options=array()' at function '_call()'
36 ## which will be passed to function '&decodeData()' for e.g. utf8 decoding
37 ## + added '$encoder->toISO()' at '&decodeData()', (re)moved from 'ProxyObject.php'
38 ##
39 ## Revision 1.5 2002/12/22 13:24:09 jonen
40 ## + added utf8 encoding at 'send()' toggled by option
41 ##
42 ## Revision 1.4 2002/12/19 02:02:25 jonen
43 ## + minor changes
44 ##
45 ## Revision 1.3 2002/12/19 01:59:37 jonen
46 ## + minor changes: coment debug prints
47 ##
48 ## Revision 1.2 2002/12/05 21:45:31 joko
49 ## + debugging
50 ##
51 ## Revision 1.1 2002/12/01 17:23:58 joko
52 ## + initial check-in
53 ##
54 ## Revision 1.3 2002/12/01 06:22:57 cvsjoko
55 ## + minor update: now can use config defaults or given args
56 ##
57 ## Revision 1.2 2002/10/29 19:14:45 cvsjoko
58 ## - bugfix: dont' do utf8-encoding here
59 ##
60 ## Revision 1.1 2002/10/09 00:51:39 cvsjoko
61 ## + new
62 ##
63 ##
64 ## -------------------------------------------------------------------------
65 */
66
67
68 // V1: normal require
69 //require_once 'XML/RPC/RPC.php';
70
71 // V2: first time load of foreign module (PEAR::XML::RPC)
72 //require_once 'XML/RPC/RPC.php';
73 loadModule('XML::RPC::RPC');
74
75 loadModule('Class::Logger');
76
77
78 /**
79 * This is the DataSource::Proxy::XMLRPC module.
80 *
81 * @author Andreas Motl <andreas.motl@ilo.de>
82 * @package org.netfrag.glib
83 * @subpackage DataSource
84 * @name DataSource::Proxy::XMLRPC
85 *
86 * @todo SOAP?
87 *
88 */
89 class DataSource_Proxy_XMLRPC extends Class_Logger {
90
91 var $configured;
92 var $meta;
93
94 function DataSource_Proxy_XMLRPC($args = array()) {
95
96 parent::constructor();
97
98 //print Dumper($this, $args);
99
100 global $Data_Driver_RPC_Remote_meta;
101 session_register_safe("Data_Driver_RPC_Remote_meta");
102 $this->meta = $Data_Driver_RPC_Remote_meta;
103
104 if (!isset($this->meta[connected]) || $args[connect]) {
105 $this->meta[connected] = 1;
106 }
107 $this->_save_meta();
108
109 if ($args['Host']) { $this->host = $args['Host']; }
110 if ($args['Port']) { $this->port = $args['Port']; }
111
112 // check if host is valid
113 if (!$this->host) {
114 $this->_raiseException( "->constructor: attribute 'host' is empty, please check your settings");
115 return;
116 }
117
118 if (!$this->port) {
119 $this->_raiseException( "->constructor: attribute 'port' is empty, please check your settings");
120 return;
121 }
122
123 $this->configured = 1;
124
125 }
126
127 function _save_meta() {
128 global $Data_Driver_RPC_Remote_meta;
129 $Data_Driver_RPC_Remote_meta = $this->meta;
130 }
131
132 function send($command, $data = "", $options = array()) {
133
134 $this->log(get_class($this) . "->send: " . $command, PEAR_LOG_DEBUG);
135
136 if (!$this->isConnected()) {
137 $this->_raiseException( "->send: not connected!");
138 return;
139 }
140
141 // do 'encode' here and ...
142 if ($options[utf8]) {
143 $encoder = new Data_Encode($data);
144 $encoder->toUTF8();
145 }
146 // call '_call' with 'decode'
147 return $this->_call($command, $data, $options);
148 }
149
150 function _call($command, $data = "", $options = array() ) {
151
152 if (!$this->configured) {
153 $this->_raiseException( "->_call: class not configured properly");
154 return;
155 }
156
157 // populate options list - mostly for debugging purposes
158 $options_list = array();
159 foreach ($options as $key => $value) {
160 array_push($options_list, "$key=$value");
161 }
162
163 $data_debug = $data;
164 if (is_array($data_debug)) { $data_debug = join(", ", $data_debug); }
165 $options_debug = join(", ", $options_list);
166 $this->log(get_class($this) . ": " . $command . "(" . $data_debug . ") [" . $options_debug . "]", PEAR_LOG_DEBUG);
167
168 // trace
169 //print "call: $command<hr>";
170 //print Dumper($data);
171 //print Dumper($this);
172
173 // data
174 $data_enc = XML_RPC_encode($data);
175
176 // message - request
177 $msg = new XML_RPC_Message($command);
178 $msg->addParam($data_enc);
179 //print htmlentities($msg->serialize());
180 // remote procedure call
181 $rpc = new XML_RPC_Client("/", $this->host, $this->port);
182 $rpc->setDebug(0);
183 if ( !$msg_response = $rpc->send($msg) ) {
184 // TODO: redirect this error elsewhere!
185 //print "RPC-error!<br>";
186 $this->_raiseException( "->_call: no response");
187 return;
188 }
189 // message - response
190 $response_enc = $msg_response->value();
191
192 // TODO: what's this? prematurely returning here should not be considered "stable"....
193 return $this->decodeData($response_enc, $options);
194 }
195
196 function &decodeData(&$payload, $options = array() ) {
197 //if (!is_object($payload)) { return; }
198 if ($payload) {
199 // data
200 $data = XML_RPC_decode($payload);
201 //print "data: " . dumpVar($response);
202
203 // decode UTF8 to ISO if wanted
204 //if ($options[to_latin]) {
205 $encoder = new Data_Encode($data);
206 $encoder->toISO();
207 //}
208
209 $this->meta[connected] = 1;
210 $this->_save_meta();
211
212 return $data;
213 } else {
214 //print "ERROR!<br>";
215 return 0;
216 }
217 }
218
219 function _raiseException($message) {
220 $this->meta[connected] = 0;
221 $this->_save_meta();
222 $this->log(get_class($this) . $message, PEAR_LOG_ERR);
223 }
224
225 function isConnected() {
226 return $this->meta[connected];
227 }
228
229 function ping() {
230 $this->_call('ping');
231 }
232
233 }
234
235 ?>

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