xml .= '';
}
- function getLength() {
+
+ function getLength()
+ {
return strlen($this->xml);
}
- function getXml() {
+
+ function getXml()
+ {
return $this->xml;
}
}
-
-class IXR_Client {
+/**
+ * IXR_Client
+ *
+ * @package IXR
+ * @since 1.5.0
+ *
+ */
+class IXR_Client
+{
var $server;
var $port;
var $path;
@@ -457,29 +647,40 @@ class IXR_Client {
var $response;
var $message = false;
var $debug = false;
- var $timeout;
+ var $timeout;
+ var $headers = array();
+
// 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 = '/';
}
+
+ if ( ! empty( $bits['query'] ) ) {
+ $this->path .= '?' . $bits['query'];
+ }
} else {
$this->server = $server;
$this->path = $path;
$this->port = $port;
}
- $this->useragent = 'Incutio XML-RPC';
- $this->timeout = $timeout;
+ $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);
@@ -487,26 +688,37 @@ class IXR_Client {
$xml = $request->getXml();
$r = "\r\n";
$request = "POST {$this->path} HTTP/1.0$r";
- $request .= "Host: {$this->server}$r";
- $request .= "Content-Type: text/xml$r";
- $request .= "User-Agent: {$this->useragent}$r";
- $request .= "Content-length: {$length}$r$r";
+
+ // 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;
+
$request .= $xml;
+
// Now send the request
if ($this->debug) {
- echo ''.htmlspecialchars($request)."\n
\n\n";
+ 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 = '';
+ $debugContents = '';
$gotFirstLine = false;
$gettingHeaders = true;
while (!feof($fp)) {
@@ -523,12 +735,17 @@ class IXR_Client {
$gettingHeaders = false;
}
if (!$gettingHeaders) {
- $contents .= trim($line)."\n";
+ // merged from WP #12559 - remove trim
+ $contents .= $line;
+ }
+ if ($this->debug) {
+ $debugContents .= $line;
}
}
if ($this->debug) {
- echo ''.htmlspecialchars($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()) {
@@ -536,38 +753,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;
}
}
-class IXR_Error {
+/**
+ * IXR_Error
+ *
+ * @package IXR
+ * @since 1.5.0
+ */
+class IXR_Error
+{
var $code;
var $message;
- function IXR_Error($code, $message) {
+
+ function IXR_Error($code, $message)
+ {
$this->code = $code;
- $this->message = $message;
+ $this->message = htmlspecialchars($message);
}
- function getXml() {
+
+ function getXml()
+ {
$xml = <<
@@ -591,7 +829,12 @@ EOD;
}
}
-
+/**
+ * IXR_Date
+ *
+ * @package IXR
+ * @since 1.5.0
+ */
class IXR_Date {
var $year;
var $month;
@@ -599,7 +842,10 @@ class IXR_Date {
var $hour;
var $minute;
var $second;
- function IXR_Date($time) {
+ var $timezone;
+
+ function IXR_Date($time)
+ {
// $time can be a PHP timestamp or an ISO one
if (is_numeric($time)) {
$this->parseTimestamp($time);
@@ -607,15 +853,20 @@ 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);
+ $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);
@@ -624,33 +875,57 @@ class IXR_Date {
$this->second = substr($iso, 15, 2);
$this->timezone = substr($iso, 17);
}
- function getIso() {
+
+ 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);
}
}
-
-class IXR_Base64 {
+/**
+ * IXR_Base64
+ *
+ * @package IXR
+ * @since 1.5.0
+ */
+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).'';
}
}
-
-class IXR_IntrospectionServer extends IXR_Server {
+/**
+ * IXR_IntrospectionServer
+ *
+ * @package IXR
+ * @since 1.5.0
+ */
+class IXR_IntrospectionServer extends IXR_Server
+{
var $signatures;
var $help;
- function IXR_IntrospectionServer() {
+
+ function IXR_IntrospectionServer()
+ {
$this->setCallbacks();
$this->setCapabilities();
$this->capabilities['introspection'] = array(
@@ -682,16 +957,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.');
@@ -699,10 +979,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;
@@ -747,7 +1029,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.');
}
@@ -785,19 +1069,31 @@ class IXR_IntrospectionServer extends IXR_Server {
}
return $return;
}
- function methodHelp($method) {
+
+ function methodHelp($method)
+ {
return $this->help[$method];
}
}
-
-class IXR_ClientMulticall extends IXR_Client {
+/**
+ * IXR_ClientMulticall
+ *
+ * @package IXR
+ * @since 1.5.0
+ */
+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(
@@ -806,10 +1102,10 @@ 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);
}
}
-
-?>
\ No newline at end of file