12 |
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
13 |
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
14 |
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
15 |
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
16 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
17 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
18 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
72 |
$GLOBALS['XML_RPC_defencoding']="UTF-8"; |
$GLOBALS['XML_RPC_defencoding']="UTF-8"; |
73 |
|
|
74 |
// let user errors start at 800 |
// let user errors start at 800 |
75 |
$GLOBALS['XML_RPC_erruser']=800; |
$GLOBALS['XML_RPC_erruser']=800; |
76 |
// let XML parse errors start at 100 |
// let XML parse errors start at 100 |
77 |
$GLOBALS['XML_RPC_errxml']=100; |
$GLOBALS['XML_RPC_errxml']=100; |
78 |
|
|
99 |
{ |
{ |
100 |
$top=split("&", $string); |
$top=split("&", $string); |
101 |
$op=""; |
$op=""; |
102 |
$i=0; |
$i=0; |
103 |
while($i<sizeof($top)) { |
while($i<sizeof($top)) { |
104 |
if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs)) { |
if (ereg("^([#a-zA-Z0-9]+);", $top[$i], $regs)) { |
105 |
$op.=ereg_replace("^[#a-zA-Z0-9]+;", |
$op.=ereg_replace("^[#a-zA-Z0-9]+;", |
106 |
XML_RPC_lookup_entity($regs[1]), |
XML_RPC_lookup_entity($regs[1]), |
107 |
$top[$i]); |
$top[$i]); |
108 |
} else { |
} else { |
109 |
if ($i==0) |
if ($i==0) |
110 |
$op=$top[$i]; |
$op=$top[$i]; |
111 |
else |
else |
112 |
$op.="&" . $top[$i]; |
$op.="&" . $top[$i]; |
113 |
} |
} |
114 |
|
|
115 |
$i++; |
$i++; |
116 |
} |
} |
117 |
return $op; |
return $op; |
121 |
function XML_RPC_lookup_entity($ent) |
function XML_RPC_lookup_entity($ent) |
122 |
{ |
{ |
123 |
global $XML_RPC_entities; |
global $XML_RPC_entities; |
124 |
|
|
125 |
if ($XML_RPC_entities[strtolower($ent)]) |
if ($XML_RPC_entities[strtolower($ent)]) |
126 |
return $XML_RPC_entities[strtolower($ent)]; |
return $XML_RPC_entities[strtolower($ent)]; |
127 |
|
|
128 |
if (ereg("^#([0-9]+)$", $ent, $regs)) |
if (ereg("^#([0-9]+)$", $ent, $regs)) |
129 |
return chr($regs[1]); |
return chr($regs[1]); |
130 |
|
|
131 |
return "?"; |
return "?"; |
132 |
} |
} |
133 |
|
|
135 |
function XML_RPC_se($parser, $name, $attrs) |
function XML_RPC_se($parser, $name, $attrs) |
136 |
{ |
{ |
137 |
global $XML_RPC_xh, $XML_RPC_DateTime, $XML_RPC_String; |
global $XML_RPC_xh, $XML_RPC_DateTime, $XML_RPC_String; |
138 |
|
|
139 |
switch($name) { |
switch($name) { |
140 |
case "STRUCT": |
case "STRUCT": |
141 |
case "ARRAY": |
case "ARRAY": |
142 |
$XML_RPC_xh[$parser]['st'].="array("; |
$XML_RPC_xh[$parser]['st'].="array("; |
143 |
$XML_RPC_xh[$parser]['cm']++; |
$XML_RPC_xh[$parser]['cm']++; |
144 |
// this last line turns quoting off |
// this last line turns quoting off |
145 |
// this means if we get an empty array we'll |
// this means if we get an empty array we'll |
146 |
// simply get a bit of whitespace in the eval |
// simply get a bit of whitespace in the eval |
147 |
$XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['qt']=0; |
148 |
break; |
break; |
156 |
$XML_RPC_xh[$parser]['st']=""; |
$XML_RPC_xh[$parser]['st']=""; |
157 |
break; |
break; |
158 |
case "VALUE": |
case "VALUE": |
159 |
$XML_RPC_xh[$parser]['st'].="new XML_RPC_Value("; |
$XML_RPC_xh[$parser]['st'].="new XML_RPC_Value("; |
160 |
$XML_RPC_xh[$parser]['lv']=1; |
$XML_RPC_xh[$parser]['lv']=1; |
161 |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_String; |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_String; |
162 |
$XML_RPC_xh[$parser]['ac']=""; |
$XML_RPC_xh[$parser]['ac']=""; |
165 |
// time we reach the first data segment then the type is string |
// time we reach the first data segment then the type is string |
166 |
// by implication and we need to add in a quote |
// by implication and we need to add in a quote |
167 |
break; |
break; |
168 |
|
|
169 |
case "I4": |
case "I4": |
170 |
case "INT": |
case "INT": |
171 |
case "STRING": |
case "STRING": |
174 |
case "DATETIME.ISO8601": |
case "DATETIME.ISO8601": |
175 |
case "BASE64": |
case "BASE64": |
176 |
$XML_RPC_xh[$parser]['ac']=""; // reset the accumulator |
$XML_RPC_xh[$parser]['ac']=""; // reset the accumulator |
177 |
|
|
178 |
if ($name=="DATETIME.ISO8601" || $name=="STRING") { |
if ($name=="DATETIME.ISO8601" || $name=="STRING") { |
179 |
$XML_RPC_xh[$parser]['qt']=1; |
$XML_RPC_xh[$parser]['qt']=1; |
180 |
|
|
181 |
if ($name=="DATETIME.ISO8601") |
if ($name=="DATETIME.ISO8601") |
182 |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_DateTime; |
$XML_RPC_xh[$parser]['vt']=$XML_RPC_DateTime; |
183 |
|
|
184 |
} else if ($name=="BASE64") { |
} else if ($name=="BASE64") { |
185 |
$XML_RPC_xh[$parser]['qt']=2; |
$XML_RPC_xh[$parser]['qt']=2; |
186 |
} else { |
} else { |
190 |
$XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['qt']=0; |
191 |
} |
} |
192 |
break; |
break; |
193 |
|
|
194 |
case "MEMBER": |
case "MEMBER": |
195 |
$XML_RPC_xh[$parser]['ac']=""; |
$XML_RPC_xh[$parser]['ac']=""; |
196 |
break; |
break; |
197 |
default: |
default: |
198 |
break; |
break; |
199 |
} |
} |
200 |
|
|
201 |
if ($name!="VALUE") $XML_RPC_xh[$parser]['lv']=0; |
if ($name!="VALUE") $XML_RPC_xh[$parser]['lv']=0; |
202 |
} |
} |
203 |
|
|
212 |
if ($XML_RPC_xh[$parser]['cm'] && substr($XML_RPC_xh[$parser]['st'], -1) ==',') { |
if ($XML_RPC_xh[$parser]['cm'] && substr($XML_RPC_xh[$parser]['st'], -1) ==',') { |
213 |
$XML_RPC_xh[$parser]['st']=substr($XML_RPC_xh[$parser]['st'],0,-1); |
$XML_RPC_xh[$parser]['st']=substr($XML_RPC_xh[$parser]['st'],0,-1); |
214 |
} |
} |
215 |
|
|
216 |
$XML_RPC_xh[$parser]['st'].=")"; |
$XML_RPC_xh[$parser]['st'].=")"; |
217 |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
218 |
$XML_RPC_xh[$parser]['cm']--; |
$XML_RPC_xh[$parser]['cm']--; |
219 |
break; |
break; |
220 |
|
|
221 |
case "NAME": |
case "NAME": |
222 |
$XML_RPC_xh[$parser]['st'].= $XML_RPC_xh[$parser]['ac'] . "' => "; |
$XML_RPC_xh[$parser]['st'].= $XML_RPC_xh[$parser]['ac'] . "' => "; |
223 |
break; |
break; |
224 |
|
|
225 |
case "BOOLEAN": |
case "BOOLEAN": |
226 |
// special case here: we translate boolean 1 or 0 into PHP |
// special case here: we translate boolean 1 or 0 into PHP |
227 |
// constants true or false |
// constants true or false |
228 |
if ($XML_RPC_xh[$parser]['ac']=='1') |
if ($XML_RPC_xh[$parser]['ac']=='1') |
229 |
$XML_RPC_xh[$parser]['ac']="true"; |
$XML_RPC_xh[$parser]['ac']="true"; |
230 |
else |
else |
231 |
$XML_RPC_xh[$parser]['ac']="false"; |
$XML_RPC_xh[$parser]['ac']="false"; |
232 |
|
|
233 |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
234 |
// Drop through intentionally. |
// Drop through intentionally. |
235 |
|
|
236 |
case "I4": |
case "I4": |
237 |
case "INT": |
case "INT": |
238 |
case "STRING": |
case "STRING": |
241 |
case "BASE64": |
case "BASE64": |
242 |
if ($XML_RPC_xh[$parser]['qt']==1) { |
if ($XML_RPC_xh[$parser]['qt']==1) { |
243 |
// we use double quotes rather than single so backslashification works OK |
// we use double quotes rather than single so backslashification works OK |
244 |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
245 |
} else if ($XML_RPC_xh[$parser]['qt']==2) { |
} else if ($XML_RPC_xh[$parser]['qt']==2) { |
246 |
$XML_RPC_xh[$parser]['st'].="base64_decode('". $XML_RPC_xh[$parser]['ac'] . "')"; |
$XML_RPC_xh[$parser]['st'].="base64_decode('". $XML_RPC_xh[$parser]['ac'] . "')"; |
247 |
} else if ($name=="BOOLEAN") { |
} else if ($name=="BOOLEAN") { |
248 |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
249 |
} else { |
} else { |
253 |
// TODO: find a better way of throwing an error |
// TODO: find a better way of throwing an error |
254 |
// than this! |
// than this! |
255 |
error_log("XML-RPC: non numeric value received in INT or DOUBLE"); |
error_log("XML-RPC: non numeric value received in INT or DOUBLE"); |
256 |
$XML_RPC_xh[$parser]['st'].="ERROR_NON_NUMERIC_FOUND"; |
$XML_RPC_xh[$parser]['st'].="ERROR_NON_NUMERIC_FOUND"; |
257 |
} else { |
} else { |
258 |
// it's ok, add it on |
// it's ok, add it on |
259 |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
$XML_RPC_xh[$parser]['st'].=$XML_RPC_xh[$parser]['ac']; |
260 |
} |
} |
261 |
} |
} |
262 |
|
|
263 |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
264 |
$XML_RPC_xh[$parser]['lv']=3; // indicate we've found a value |
$XML_RPC_xh[$parser]['lv']=3; // indicate we've found a value |
265 |
break; |
break; |
266 |
|
|
267 |
case "VALUE": |
case "VALUE": |
268 |
// deal with a string value |
// deal with a string value |
269 |
if (strlen($XML_RPC_xh[$parser]['ac'])>0 && |
if (strlen($XML_RPC_xh[$parser]['ac'])>0 && |
270 |
$XML_RPC_xh[$parser]['vt']==$XML_RPC_String) { |
$XML_RPC_xh[$parser]['vt']==$XML_RPC_String) { |
271 |
|
|
272 |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
$XML_RPC_xh[$parser]['st'].="\"". $XML_RPC_xh[$parser]['ac'] . "\""; |
273 |
} |
} |
274 |
|
|
275 |
// This if() detects if no scalar was inside <VALUE></VALUE> |
// This if() detects if no scalar was inside <VALUE></VALUE> |
276 |
// and pads an empty "". |
// and pads an empty "". |
277 |
if($XML_RPC_xh[$parser]['st'][strlen($XML_RPC_xh[$parser]['st'])-1] == '(') { |
if($XML_RPC_xh[$parser]['st'][strlen($XML_RPC_xh[$parser]['st'])-1] == '(') { |
280 |
$XML_RPC_xh[$parser]['st'].=", '" . $XML_RPC_xh[$parser]['vt'] . "')"; |
$XML_RPC_xh[$parser]['st'].=", '" . $XML_RPC_xh[$parser]['vt'] . "')"; |
281 |
if ($XML_RPC_xh[$parser]['cm']) $XML_RPC_xh[$parser]['st'].=","; |
if ($XML_RPC_xh[$parser]['cm']) $XML_RPC_xh[$parser]['st'].=","; |
282 |
break; |
break; |
283 |
|
|
284 |
case "MEMBER": |
case "MEMBER": |
285 |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
286 |
break; |
break; |
287 |
|
|
288 |
case "DATA": |
case "DATA": |
289 |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
$XML_RPC_xh[$parser]['ac']=""; $XML_RPC_xh[$parser]['qt']=0; |
290 |
break; |
break; |
291 |
|
|
292 |
case "PARAM": |
case "PARAM": |
293 |
$XML_RPC_xh[$parser]['params'][]=$XML_RPC_xh[$parser]['st']; |
$XML_RPC_xh[$parser]['params'][]=$XML_RPC_xh[$parser]['st']; |
294 |
break; |
break; |
295 |
|
|
296 |
case "METHODNAME": |
case "METHODNAME": |
297 |
$XML_RPC_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", "", $XML_RPC_xh[$parser]['ac']); |
$XML_RPC_xh[$parser]['method']=ereg_replace("^[\n\r\t ]+", "", $XML_RPC_xh[$parser]['ac']); |
298 |
break; |
break; |
299 |
|
|
300 |
case "BOOLEAN": |
case "BOOLEAN": |
301 |
// special case here: we translate boolean 1 or 0 into PHP |
// special case here: we translate boolean 1 or 0 into PHP |
302 |
// constants true or false |
// constants true or false |
303 |
if ($XML_RPC_xh[$parser]['ac']=='1') |
if ($XML_RPC_xh[$parser]['ac']=='1') |
304 |
$XML_RPC_xh[$parser]['ac']="true"; |
$XML_RPC_xh[$parser]['ac']="true"; |
305 |
else |
else |
306 |
$XML_RPC_xh[$parser]['ac']="false"; |
$XML_RPC_xh[$parser]['ac']="false"; |
307 |
|
|
308 |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
$XML_RPC_xh[$parser]['vt']=strtolower($name); |
309 |
break; |
break; |
310 |
|
|
311 |
default: |
default: |
312 |
break; |
break; |
313 |
} |
} |
319 |
|
|
320 |
|
|
321 |
function XML_RPC_cd($parser, $data) |
function XML_RPC_cd($parser, $data) |
322 |
{ |
{ |
323 |
global $XML_RPC_xh, $XML_RPC_backslash; |
global $XML_RPC_xh, $XML_RPC_backslash; |
324 |
|
|
325 |
//if (ereg("^[\n\r \t]+$", $data)) return; |
//if (ereg("^[\n\r \t]+$", $data)) return; |
326 |
// print "adding [${data}]\n"; |
// print "adding [${data}]\n"; |
327 |
|
|
328 |
if ($XML_RPC_xh[$parser]['lv']!=3) { |
if ($XML_RPC_xh[$parser]['lv']!=3) { |
329 |
// "lookforvalue==3" means that we've found an entire value |
// "lookforvalue==3" means that we've found an entire value |
330 |
// and should discard any further character data |
// and should discard any further character data |
331 |
|
|
332 |
if ($XML_RPC_xh[$parser]['lv']==1) { |
if ($XML_RPC_xh[$parser]['lv']==1) { |
333 |
// if we've found text and we're just in a <value> then |
// if we've found text and we're just in a <value> then |
334 |
// turn quoting on, as this will be a string |
// turn quoting on, as this will be a string |
335 |
$XML_RPC_xh[$parser]['qt']=1; |
$XML_RPC_xh[$parser]['qt']=1; |
336 |
// and say we've found a value |
// and say we've found a value |
337 |
$XML_RPC_xh[$parser]['lv']=2; |
$XML_RPC_xh[$parser]['lv']=2; |
338 |
} |
} |
339 |
|
|
340 |
// replace characters that eval would |
// replace characters that eval would |
341 |
// do special things with |
// do special things with |
342 |
@$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
@$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
350 |
{ |
{ |
351 |
global $XML_RPC_xh; |
global $XML_RPC_xh; |
352 |
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") { |
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") { |
353 |
if ($XML_RPC_xh[$parser]['lv']==1) { |
if ($XML_RPC_xh[$parser]['lv']==1) { |
354 |
$XML_RPC_xh[$parser]['qt']=1; |
$XML_RPC_xh[$parser]['qt']=1; |
355 |
$XML_RPC_xh[$parser]['lv']=2; |
$XML_RPC_xh[$parser]['lv']=2; |
356 |
} |
} |
357 |
$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
$XML_RPC_xh[$parser]['ac'].=str_replace('$', '\$', |
358 |
str_replace('"', '\"', str_replace(chr(92), |
str_replace('"', '\"', str_replace(chr(92), |
371 |
var $debug=0; |
var $debug=0; |
372 |
var $username=""; |
var $username=""; |
373 |
var $password=""; |
var $password=""; |
374 |
|
|
375 |
function XML_RPC_Client($path, $server, $port=80, $proxy="", $proxy_port=8080) |
function XML_RPC_Client($path, $server, $port = 80, |
376 |
|
$proxy = '', $proxy_port = 8080, |
377 |
|
$proxy_user = '', $proxy_pass = '') |
378 |
{ |
{ |
379 |
$this->port=$port; |
$this->port=$port; |
380 |
$this->server=$server; |
$this->server=$server; |
381 |
$this->path=$path; |
$this->path=$path; |
382 |
$this->proxy = $proxy; |
$this->proxy = $proxy; |
383 |
$this->proxy_port = $proxy_port ; |
$this->proxy_port = $proxy_port; |
384 |
|
$this->proxy_user = $proxy_user; |
385 |
|
$this->proxy_pass = $proxy_pass; |
386 |
} |
} |
387 |
|
|
388 |
function setDebug($in) |
function setDebug($in) |
389 |
{ |
{ |
390 |
if ($in) { |
if ($in) { |
391 |
$this->debug=1; |
$this->debug=1; |
392 |
} else { |
} else { |
393 |
$this->debug=0; |
$this->debug=0; |
405 |
// where msg is an xmlrpcmsg |
// where msg is an xmlrpcmsg |
406 |
$msg->debug=$this->debug; |
$msg->debug=$this->debug; |
407 |
return $this->sendPayloadHTTP10($msg, $this->server, $this->port, |
return $this->sendPayloadHTTP10($msg, $this->server, $this->port, |
408 |
$timeout, $this->username, |
$timeout, $this->username, |
409 |
$this->password); |
$this->password); |
410 |
} |
} |
411 |
|
|
418 |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr, $timeout); |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr, $timeout); |
419 |
} |
} |
420 |
else { |
else { |
421 |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr); |
$fp=fsockopen($this->proxy, $this->proxy_port, $this->errno, $this->errstr); |
422 |
} |
} |
423 |
} |
} |
424 |
else { |
else { |
425 |
if($timeout > 0) { |
if($timeout > 0) { |
426 |
$fp=fsockopen($server, $port, $this->errno, $this->errstr, $timeout); |
$fp=fsockopen($server, $port, $this->errno, $this->errstr, $timeout); |
427 |
} |
} |
428 |
else { |
else { |
429 |
$fp=fsockopen($server, $port, $this->errno, $this->errstr); |
$fp=fsockopen($server, $port, $this->errno, $this->errstr); |
430 |
} |
} |
431 |
} |
} |
432 |
|
|
433 |
if(!$fp && $this->proxy) { |
if(!$fp && $this->proxy) { |
434 |
PEAR::raiseError("Connection to proxy server ".$this->proxy.":".$this->proxy_port." failed"); |
PEAR::raiseError("Connection to proxy server ".$this->proxy.":".$this->proxy_port." failed"); |
435 |
|
$this->errstr="Connect error"; |
436 |
|
return 0; |
437 |
} |
} |
438 |
else if(!$fp) { |
else if(!$fp) { |
439 |
PEAR::raiseError("Connection to RPC server ".$this->server." failed"); |
PEAR::raiseError("Connection to RPC server ".$this->server." failed"); |
440 |
|
$this->errstr="Connect error"; |
441 |
|
return 0; |
442 |
} |
} |
443 |
|
|
|
if (!$fp) { return; } |
|
|
|
|
444 |
// Only create the payload if it was not created previously |
// Only create the payload if it was not created previously |
445 |
if(empty($msg->payload)) $msg->createPayload(); |
if(empty($msg->payload)) $msg->createPayload(); |
446 |
|
|
447 |
// thanks to Grant Rauscher <grant7@firstworld.net> |
// thanks to Grant Rauscher <grant7@firstworld.net> |
448 |
// for this |
// for this |
449 |
$credentials=""; |
$credentials=""; |
451 |
$credentials="Authorization: Basic " . |
$credentials="Authorization: Basic " . |
452 |
base64_encode($username . ":" . $password) . "\r\n"; |
base64_encode($username . ":" . $password) . "\r\n"; |
453 |
} |
} |
454 |
|
|
455 |
|
|
456 |
if($this->proxy) { |
if($this->proxy) { |
457 |
$op = "POST http://" . $this->server; |
$op = "POST http://" . $this->server; |
458 |
|
|
459 |
if($this->proxy_port) { |
if($this->proxy_port) { |
460 |
$op .= ":" . $this->port; |
$op .= ":" . $this->port; |
461 |
} |
} |
463 |
else { |
else { |
464 |
$op = "POST "; |
$op = "POST "; |
465 |
} |
} |
466 |
|
|
467 |
$op .= $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" . |
$op .= $this->path. " HTTP/1.0\r\nUser-Agent: PHP XMLRPC 1.0\r\n" . |
468 |
"Host: ". $this->server . "\r\n" . |
"Host: ". $this->server . "\r\n"; |
469 |
$credentials . |
if ($this->proxy && $this->proxy_user != '') { |
470 |
|
$op .= 'Proxy-Authorization: Basic ' . |
471 |
|
base64_encode($this->proxy_user . ':' . $this->proxy_pass) . |
472 |
|
"\r\n"; |
473 |
|
} |
474 |
|
$op .= $credentials . |
475 |
"Content-Type: text/xml\r\nContent-Length: " . |
"Content-Type: text/xml\r\nContent-Length: " . |
476 |
strlen($msg->payload) . "\r\n\r\n" . |
strlen($msg->payload) . "\r\n\r\n" . |
477 |
$msg->payload; |
$msg->payload; |
478 |
|
|
479 |
// print($op); |
// print($op); |
480 |
|
|
481 |
if (!fputs($fp, $op, strlen($op))) { |
if (!fputs($fp, $op, strlen($op))) { |
482 |
$this->errstr="Write error"; |
$this->errstr="Write error"; |
483 |
return 0; |
return 0; |
506 |
} |
} |
507 |
} |
} |
508 |
|
|
509 |
function faultCode() |
function faultCode() |
510 |
{ |
{ |
511 |
if (isset($this->fn)) |
if (isset($this->fn)) |
512 |
return $this->fn; |
return $this->fn; |
513 |
else |
else |
514 |
return 0; |
return 0; |
517 |
function faultString() { return $this->fs; } |
function faultString() { return $this->fs; } |
518 |
function value() { return $this->xv; } |
function value() { return $this->xv; } |
519 |
|
|
520 |
function serialize() { |
function serialize() { |
521 |
$rs="<methodResponse>\n"; |
$rs="<methodResponse>\n"; |
522 |
if ($this->fn) { |
if ($this->fn) { |
523 |
$rs.="<fault> |
$rs.="<fault> |
535 |
</value> |
</value> |
536 |
</fault>"; |
</fault>"; |
537 |
} else { |
} else { |
538 |
$rs.="<params>\n<param>\n" . $this->xv->serialize() . |
$rs.="<params>\n<param>\n" . $this->xv->serialize() . |
539 |
"</param>\n</params>"; |
"</param>\n</params>"; |
540 |
} |
} |
541 |
$rs.="\n</methodResponse>"; |
$rs.="\n</methodResponse>"; |
555 |
{ |
{ |
556 |
$this->methodname=$meth; |
$this->methodname=$meth; |
557 |
if (is_array($pars) && sizeof($pars)>0) { |
if (is_array($pars) && sizeof($pars)>0) { |
558 |
for($i=0; $i<sizeof($pars); $i++) |
for($i=0; $i<sizeof($pars); $i++) |
559 |
$this->addParam($pars[$i]); |
$this->addParam($pars[$i]); |
560 |
} |
} |
561 |
} |
} |
564 |
{ |
{ |
565 |
return "<?xml version=\"1.0\"?>\n<methodCall>\n"; |
return "<?xml version=\"1.0\"?>\n<methodCall>\n"; |
566 |
} |
} |
567 |
|
|
568 |
function xml_footer() |
function xml_footer() |
569 |
{ |
{ |
570 |
return "</methodCall>\n"; |
return "</methodCall>\n"; |
619 |
{ |
{ |
620 |
global $XML_RPC_xh,$XML_RPC_err,$XML_RPC_str; |
global $XML_RPC_xh,$XML_RPC_err,$XML_RPC_str; |
621 |
global $XML_RPC_defencoding; |
global $XML_RPC_defencoding; |
622 |
|
|
623 |
$parser = xml_parser_create($XML_RPC_defencoding); |
$parser = xml_parser_create($XML_RPC_defencoding); |
624 |
|
|
625 |
$XML_RPC_xh[$parser]=array(); |
$XML_RPC_xh[$parser]=array(); |
626 |
|
|
627 |
$XML_RPC_xh[$parser]['st']=""; |
$XML_RPC_xh[$parser]['st']=""; |
628 |
$XML_RPC_xh[$parser]['cm']=0; |
$XML_RPC_xh[$parser]['cm']=0; |
629 |
$XML_RPC_xh[$parser]['isf']=0; |
$XML_RPC_xh[$parser]['isf']=0; |
630 |
$XML_RPC_xh[$parser]['ac']=""; |
$XML_RPC_xh[$parser]['ac']=""; |
631 |
$XML_RPC_xh[$parser]['qt']=""; |
$XML_RPC_xh[$parser]['qt']=""; |
632 |
|
|
633 |
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); |
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true); |
634 |
xml_set_element_handler($parser, "XML_RPC_se", "XML_RPC_ee"); |
xml_set_element_handler($parser, "XML_RPC_se", "XML_RPC_ee"); |
635 |
xml_set_character_data_handler($parser, "XML_RPC_cd"); |
xml_set_character_data_handler($parser, "XML_RPC_cd"); |
637 |
$xmlrpc_value = new XML_RPC_Value; |
$xmlrpc_value = new XML_RPC_Value; |
638 |
|
|
639 |
$hdrfnd=0; |
$hdrfnd=0; |
640 |
if ($this->debug) |
if ($this->debug) { |
641 |
print "<PRE>---GOT---\n" . htmlspecialchars($data) . |
print "<PRE>---GOT---\n"; |
642 |
"\n---END---\n</PRE>"; |
print isset($_SERVER['SERVER_PROTOCOL']) ? htmlspecialchars($data) : $data; |
643 |
|
print "\n---END---\n</PRE>"; |
644 |
|
} |
645 |
// see if we got an HTTP 200 OK, else bomb |
// see if we got an HTTP 200 OK, else bomb |
646 |
// but only do this if we're using the HTTP protocol. |
// but only do this if we're using the HTTP protocol. |
647 |
if (ereg("^HTTP",$data) && |
if (ereg("^HTTP",$data) && |
648 |
!ereg("^HTTP/[0-9\.]+ 200 ", $data)) { |
!ereg("^HTTP/[0-9\.]+ 200 ", $data)) { |
649 |
$errstr= substr($data, 0, strpos($data, "\n")-1); |
$errstr= substr($data, 0, strpos($data, "\n")-1); |
650 |
error_log("HTTP error, got response: " .$errstr); |
error_log("HTTP error, got response: " .$errstr); |
655 |
return $r; |
return $r; |
656 |
} |
} |
657 |
// gotta get rid of headers here |
// gotta get rid of headers here |
658 |
if ((!$hdrfnd) && ereg("^(.*)\r\n\r\n",$data,$XML_RPC_xh[$parser]['ha'])) { |
|
659 |
$data=ereg_replace("^.*\r\n\r\n", "", $data); |
|
660 |
|
if ((!$hdrfnd) && ($brpos = strpos($data,"\r\n\r\n"))) { |
661 |
|
$XML_RPC_xh[$parser]['ha'] = substr($data,0,$brpos); |
662 |
|
$data= substr($data,$brpos+4); |
663 |
$hdrfnd=1; |
$hdrfnd=1; |
664 |
} |
} |
665 |
|
|
666 |
if (!xml_parse($parser, $data, sizeof($data))) { |
if (!xml_parse($parser, $data, sizeof($data))) { |
667 |
// thanks to Peter Kocks <peter.kocks@baygate.com> |
// thanks to Peter Kocks <peter.kocks@baygate.com> |
668 |
if((xml_get_current_line_number($parser)) == 1) |
if((xml_get_current_line_number($parser)) == 1) |
669 |
$errstr = "XML error at line 1, check URL"; |
$errstr = "XML error at line 1, check URL"; |
670 |
else |
else |
671 |
$errstr = sprintf("XML error: %s at line %d", |
$errstr = sprintf("XML error: %s at line %d", |
679 |
} |
} |
680 |
xml_parser_free($parser); |
xml_parser_free($parser); |
681 |
if ($this->debug) { |
if ($this->debug) { |
682 |
print "<PRE>---EVALING---[" . |
print "<PRE>---EVALING---[" . |
683 |
strlen($XML_RPC_xh[$parser]['st']) . " chars]---\n" . |
strlen($XML_RPC_xh[$parser]['st']) . " chars]---\n" . |
684 |
htmlspecialchars($XML_RPC_xh[$parser]['st']) . ";\n---END---</PRE>"; |
htmlspecialchars($XML_RPC_xh[$parser]['st']) . ";\n---END---</PRE>"; |
685 |
} |
} |
686 |
if (strlen($XML_RPC_xh[$parser]['st'])==0) { |
if (strlen($XML_RPC_xh[$parser]['st'])==0) { |
694 |
if ($XML_RPC_xh[$parser]['isf']) { |
if ($XML_RPC_xh[$parser]['isf']) { |
695 |
$f=$v->structmem("faultCode"); |
$f=$v->structmem("faultCode"); |
696 |
$fs=$v->structmem("faultString"); |
$fs=$v->structmem("faultString"); |
697 |
$r=new XML_RPC_Response($v, $f->scalarval(), |
$r=new XML_RPC_Response($v, $f->scalarval(), |
698 |
$fs->scalarval()); |
$fs->scalarval()); |
699 |
} else { |
} else { |
700 |
$r=new XML_RPC_Response($v); |
$r=new XML_RPC_Response($v); |
732 |
function addScalar($val, $type="string") |
function addScalar($val, $type="string") |
733 |
{ |
{ |
734 |
global $XML_RPC_Types, $XML_RPC_Boolean; |
global $XML_RPC_Types, $XML_RPC_Boolean; |
735 |
|
|
736 |
if ($this->mytype==1) { |
if ($this->mytype==1) { |
737 |
echo "<B>XML_RPC_Value</B>: scalar can have only one value<BR>"; |
echo "<B>XML_RPC_Value</B>: scalar can have only one value<BR>"; |
738 |
return 0; |
return 0; |
742 |
echo "<B>XML_RPC_Value</B>: not a scalar type (${typeof})<BR>"; |
echo "<B>XML_RPC_Value</B>: not a scalar type (${typeof})<BR>"; |
743 |
return 0; |
return 0; |
744 |
} |
} |
745 |
|
|
746 |
if ($type==$XML_RPC_Boolean) { |
if ($type==$XML_RPC_Boolean) { |
747 |
if (strcasecmp($val,"true")==0 || |
if (strcasecmp($val,"true")==0 || |
748 |
$val==1 || |
$val==1 || |
749 |
($val==true && |
($val==true && |
750 |
strcasecmp($val,"false"))) { |
strcasecmp($val,"false"))) { |
751 |
|
|
752 |
$val=1; |
$val=1; |
753 |
} else { |
} else { |
754 |
$val=0; |
$val=0; |
755 |
} |
} |
756 |
} |
} |
757 |
|
|
758 |
if ($this->mytype==2) { |
if ($this->mytype==2) { |
759 |
// we're adding to an array here |
// we're adding to an array here |
760 |
$ar=$this->me["array"]; |
$ar=$this->me["array"]; |
772 |
{ |
{ |
773 |
global $XML_RPC_Types; |
global $XML_RPC_Types; |
774 |
if ($this->mytype!=0) { |
if ($this->mytype!=0) { |
775 |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
776 |
$this->kindOf() . "]<BR>"; |
$this->kindOf() . "]<BR>"; |
777 |
return 0; |
return 0; |
778 |
} |
} |
785 |
{ |
{ |
786 |
global $XML_RPC_Types; |
global $XML_RPC_Types; |
787 |
if ($this->mytype!=0) { |
if ($this->mytype!=0) { |
788 |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
echo "<B>XML_RPC_Value</B>: already initialized as a [" . |
789 |
$this->kindOf() . "]<BR>"; |
$this->kindOf() . "]<BR>"; |
790 |
return 0; |
return 0; |
791 |
} |
} |
896 |
{ |
{ |
897 |
reset($this->me["struct"]); |
reset($this->me["struct"]); |
898 |
} |
} |
899 |
|
|
900 |
function structeach() |
function structeach() |
901 |
{ |
{ |
902 |
return each($this->me["struct"]); |
return each($this->me["struct"]); |
903 |
} |
} |
904 |
|
|
905 |
function getval() { |
function getval() { |
906 |
// UNSTABLE |
// UNSTABLE |
907 |
global $XML_RPC_BOOLEAN, $XML_RPC_Base64; |
global $XML_RPC_BOOLEAN, $XML_RPC_Base64; |
908 |
|
|
909 |
reset($this->me); |
reset($this->me); |
910 |
list($a,$b)=each($this->me); |
list($a,$b)=each($this->me); |
911 |
|
|
912 |
// contributed by I Sofer, 2001-03-24 |
// contributed by I Sofer, 2001-03-24 |
913 |
// add support for nested arrays to scalarval |
// add support for nested arrays to scalarval |
914 |
// i've created a new method here, so as to |
// i've created a new method here, so as to |
930 |
eval('$b->'.$id.' = $cont;'); |
eval('$b->'.$id.' = $cont;'); |
931 |
} |
} |
932 |
} |
} |
933 |
|
|
934 |
// end contrib |
// end contrib |
935 |
return $b; |
return $b; |
936 |
} |
} |
937 |
|
|
938 |
function scalarval() |
function scalarval() |
939 |
{ |
{ |
940 |
global $XML_RPC_Boolean, $XML_RPC_Base64; |
global $XML_RPC_Boolean, $XML_RPC_Base64; |
948 |
global $XML_RPC_I4, $XML_RPC_Int; |
global $XML_RPC_I4, $XML_RPC_Int; |
949 |
reset($this->me); |
reset($this->me); |
950 |
list($a,$b)=each($this->me); |
list($a,$b)=each($this->me); |
951 |
if ($a==$XML_RPC_I4) |
if ($a==$XML_RPC_I4) |
952 |
$a=$XML_RPC_Int; |
$a=$XML_RPC_Int; |
953 |
return $a; |
return $a; |
954 |
} |
} |
978 |
// |
// |
979 |
// "Don't assume a timezone. It should be specified by the server in its |
// "Don't assume a timezone. It should be specified by the server in its |
980 |
// documentation what assumptions it makes about timezones." |
// documentation what assumptions it makes about timezones." |
981 |
// |
// |
982 |
// these routines always assume localtime unless |
// these routines always assume localtime unless |
983 |
// $utc is set to 1, in which case UTC is assumed |
// $utc is set to 1, in which case UTC is assumed |
984 |
// and an adjustment for locale is made when encoding |
// and an adjustment for locale is made when encoding |
985 |
if (!$utc) { |
if (!$utc) { |
986 |
$t=strftime("%Y%m%dT%H:%M:%S", $timet); |
$t=strftime("%Y%m%dT%H:%M:%S", $timet); |
987 |
} else { |
} else { |
988 |
if (function_exists("gmstrftime")) |
if (function_exists("gmstrftime")) |
989 |
// gmstrftime doesn't exist in some versions |
// gmstrftime doesn't exist in some versions |
990 |
// of PHP |
// of PHP |
991 |
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet); |
$t=gmstrftime("%Y%m%dT%H:%M:%S", $timet); |
993 |
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z")); |
$t=strftime("%Y%m%dT%H:%M:%S", $timet-date("Z")); |
994 |
} |
} |
995 |
} |
} |
996 |
|
|
997 |
return $t; |
return $t; |
998 |
} |
} |
999 |
|
|
1001 |
// return a timet in the localtime, or UTC |
// return a timet in the localtime, or UTC |
1002 |
$t=0; |
$t=0; |
1003 |
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",$idate, $regs)) { |
if (ereg("([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})",$idate, $regs)) { |
1004 |
|
|
1005 |
if ($utc) { |
if ($utc) { |
1006 |
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
$t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
1007 |
} else { |
} else { |
1008 |
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
$t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
1009 |
} |
} |
1010 |
} |
} |
1011 |
|
|
1012 |
return $t; |
return $t; |
1013 |
} |
} |
1031 |
for($i = 0; $i < $size; $i++) { |
for($i = 0; $i < $size; $i++) { |
1032 |
$arr[]=XML_RPC_decode($XML_RPC_val->arraymem($i)); |
$arr[]=XML_RPC_decode($XML_RPC_val->arraymem($i)); |
1033 |
} |
} |
1034 |
return $arr; |
return $arr; |
1035 |
} |
} |
1036 |
else if($kind == "struct") { |
else if($kind == "struct") { |
1037 |
$XML_RPC_val->structreset(); |
$XML_RPC_val->structreset(); |