xml .= '';
}
- function getLength() {
+
+ function getLength()
+ {
return strlen($this->xml);
}
- function getXml() {
+
+ function getXml()
+ {
return $this->xml;
}
}
@@ -497,26 +591,31 @@ EOD;
*
* @package IXR
* @since 1.5
+ *
*/
-class IXR_Client {
+class IXR_Client
+{
var $server;
var $port;
var $path;
var $useragent;
- var $headers;
var $response;
var $message = false;
var $debug = false;
var $timeout;
+
// Storage place for an error message
var $error = false;
- function IXR_Client($server, $path = false, $port = 80, $timeout = false) {
+
+ function IXR_Client($server, $path = false, $port = 80, $timeout = 15)
+ {
if (!$path) {
// Assume we have been given a URL instead
$bits = parse_url($server);
$this->server = $bits['host'];
$this->port = isset($bits['port']) ? $bits['port'] : 80;
$this->path = isset($bits['path']) ? $bits['path'] : '/';
+
// Make absolutely sure we have a path
if (!$this->path) {
$this->path = '/';
@@ -529,7 +628,9 @@ class IXR_Client {
$this->useragent = 'The Incutio XML-RPC PHP Library';
$this->timeout = $timeout;
}
- function query() {
+
+ function query()
+ {
$args = func_get_args();
$method = array_shift($args);
$request = new IXR_Request($method, $args);
@@ -538,33 +639,36 @@ class IXR_Client {
$r = "\r\n";
$request = "POST {$this->path} HTTP/1.0$r";
- $this->headers['Host'] = $this->server;
- $this->headers['Content-Type'] = 'text/xml';
- $this->headers['User-Agent'] = $this->useragent;
- $this->headers['Content-Length']= $length;
+ // Merged from WP #8145 - allow custom headers
+ $this->headers['Host'] = $this->server;
+ $this->headers['Content-Type'] = 'text/xml';
+ $this->headers['User-Agent'] = $this->useragent;
+ $this->headers['Content-Length']= $length;
- foreach( $this->headers as $header => $value ) {
- $request .= "{$header}: {$value}{$r}";
- }
- $request .= $r;
+ foreach( $this->headers as $header => $value ) {
+ $request .= "{$header}: {$value}{$r}";
+ }
+ $request .= $r;
$request .= $xml;
+
// Now send the request
if ($this->debug) {
echo ''.htmlspecialchars($request)."\n
\n\n";
}
+
if ($this->timeout) {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
} else {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr);
}
if (!$fp) {
- $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr");
+ $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
return false;
}
fputs($fp, $request);
$contents = '';
- $debug_contents = '';
+ $debugContents = '';
$gotFirstLine = false;
$gettingHeaders = true;
while (!feof($fp)) {
@@ -572,7 +676,7 @@ class IXR_Client {
if (!$gotFirstLine) {
// Check line for '200'
if (strstr($line, '200') === false) {
- $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200');
+ $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
return false;
}
$gotFirstLine = true;
@@ -581,16 +685,17 @@ class IXR_Client {
$gettingHeaders = false;
}
if (!$gettingHeaders) {
- // WP#12559 remove trim so as to not strip newlines from received response.
+ // merged from WP #12559 - remove trim
$contents .= $line;
}
if ($this->debug) {
- $debug_contents .= $line;
+ $debugContents .= $line;
}
}
if ($this->debug) {
- echo ''.htmlspecialchars($debug_contents)."\n
\n\n";
+ echo ''.htmlspecialchars($debugContents)."\n
\n\n";
}
+
// Now parse what we've got back
$this->message = new IXR_Message($contents);
if (!$this->message->parse()) {
@@ -598,44 +703,59 @@ class IXR_Client {
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
return false;
}
+
// Is the message a fault?
if ($this->message->messageType == 'fault') {
$this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
return false;
}
+
// Message must be OK
return true;
}
- function getResponse() {
+
+ function getResponse()
+ {
// methodResponses can only have one param - return that
return $this->message->params[0];
}
- function isError() {
+
+ function isError()
+ {
return (is_object($this->error));
}
- function getErrorCode() {
+
+ function getErrorCode()
+ {
return $this->error->code;
}
- function getErrorMessage() {
+
+ function getErrorMessage()
+ {
return $this->error->message;
}
}
+
/**
* IXR_Error
*
* @package IXR
* @since 1.5
*/
-class IXR_Error {
+class IXR_Error
+{
var $code;
var $message;
- function IXR_Error($code, $message) {
+
+ function IXR_Error($code, $message)
+ {
$this->code = $code;
- // WP adds htmlspecialchars(). See #5666
$this->message = htmlspecialchars($message);
}
- function getXml() {
+
+ function getXml()
+ {
$xml = <<
@@ -673,7 +793,9 @@ class IXR_Date {
var $minute;
var $second;
var $timezone;
- function IXR_Date($time) {
+
+ function IXR_Date($time)
+ {
// $time can be a PHP timestamp or an ISO one
if (is_numeric($time)) {
$this->parseTimestamp($time);
@@ -681,34 +803,41 @@ class IXR_Date {
$this->parseIso($time);
}
}
- function parseTimestamp($timestamp) {
+
+ function parseTimestamp($timestamp)
+ {
$this->year = date('Y', $timestamp);
$this->month = date('m', $timestamp);
$this->day = date('d', $timestamp);
$this->hour = date('H', $timestamp);
$this->minute = date('i', $timestamp);
$this->second = date('s', $timestamp);
- // WP adds timezone. See #2036
$this->timezone = '';
}
- function parseIso($iso) {
+
+ function parseIso($iso)
+ {
$this->year = substr($iso, 0, 4);
$this->month = substr($iso, 4, 2);
$this->day = substr($iso, 6, 2);
$this->hour = substr($iso, 9, 2);
$this->minute = substr($iso, 12, 2);
$this->second = substr($iso, 15, 2);
- // WP adds timezone. See #2036
$this->timezone = substr($iso, 17);
}
- function getIso() {
- // WP adds timezone. See #2036
+
+ function getIso()
+ {
return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone;
}
- function getXml() {
+
+ function getXml()
+ {
return ''.$this->getIso().'';
}
- function getTimestamp() {
+
+ function getTimestamp()
+ {
return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
}
}
@@ -719,12 +848,17 @@ class IXR_Date {
* @package IXR
* @since 1.5
*/
-class IXR_Base64 {
+class IXR_Base64
+{
var $data;
- function IXR_Base64($data) {
+
+ function IXR_Base64($data)
+ {
$this->data = $data;
}
- function getXml() {
+
+ function getXml()
+ {
return ''.base64_encode($this->data).'';
}
}
@@ -735,10 +869,13 @@ class IXR_Base64 {
* @package IXR
* @since 1.5
*/
-class IXR_IntrospectionServer extends IXR_Server {
+class IXR_IntrospectionServer extends IXR_Server
+{
var $signatures;
var $help;
- function IXR_IntrospectionServer() {
+
+ function IXR_IntrospectionServer()
+ {
$this->setCallbacks();
$this->setCapabilities();
$this->capabilities['introspection'] = array(
@@ -770,16 +907,21 @@ class IXR_IntrospectionServer extends IXR_Server {
'Returns a documentation string for the specified method'
);
}
- function addCallback($method, $callback, $args, $help) {
+
+ function addCallback($method, $callback, $args, $help)
+ {
$this->callbacks[$method] = $callback;
$this->signatures[$method] = $args;
$this->help[$method] = $help;
}
- function call($methodname, $args) {
+
+ function call($methodname, $args)
+ {
// Make sure it's in an array
if ($args && !is_array($args)) {
$args = array($args);
}
+
// Over-rides default call method, adds signature check
if (!$this->hasMethod($methodname)) {
return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
@@ -787,10 +929,12 @@ class IXR_IntrospectionServer extends IXR_Server {
$method = $this->callbacks[$methodname];
$signature = $this->signatures[$methodname];
$returnType = array_shift($signature);
+
// Check the number of arguments
if (count($args) != count($signature)) {
return new IXR_Error(-32602, 'server error. wrong number of method parameters');
}
+
// Check the argument types
$ok = true;
$argsbackup = $args;
@@ -835,7 +979,9 @@ class IXR_IntrospectionServer extends IXR_Server {
// It passed the test - run the "real" method call
return parent::call($methodname, $argsbackup);
}
- function methodSignature($method) {
+
+ function methodSignature($method)
+ {
if (!$this->hasMethod($method)) {
return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
}
@@ -873,7 +1019,9 @@ class IXR_IntrospectionServer extends IXR_Server {
}
return $return;
}
- function methodHelp($method) {
+
+ function methodHelp($method)
+ {
return $this->help[$method];
}
}
@@ -884,13 +1032,18 @@ class IXR_IntrospectionServer extends IXR_Server {
* @package IXR
* @since 1.5
*/
-class IXR_ClientMulticall extends IXR_Client {
+class IXR_ClientMulticall extends IXR_Client
+{
var $calls = array();
- function IXR_ClientMulticall($server, $path = false, $port = 80) {
+
+ function IXR_ClientMulticall($server, $path = false, $port = 80)
+ {
parent::IXR_Client($server, $path, $port);
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
}
- function addCall() {
+
+ function addCall()
+ {
$args = func_get_args();
$methodName = array_shift($args);
$struct = array(
@@ -899,7 +1052,9 @@ class IXR_ClientMulticall extends IXR_Client {
);
$this->calls[] = $struct;
}
- function query() {
+
+ function query()
+ {
// Prepare multicall, then call the parent::query() method
return parent::query('system.multicall', $this->calls);
}