]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-IXR.php
WordPress 4.6.3-scripts
[autoinstalls/wordpress.git] / wp-includes / class-IXR.php
index f8fbc00b10f67b8d154c4dc9a8e8d50bf8de229a..a8e31983e880f24a0baf17d318d010ce07453086 100644 (file)
@@ -30,7 +30,7 @@
  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  *
  * @copyright  Incutio Ltd 2010 (http://www.incutio.com)
  * @version    1.7.4 7th September 2010
  * IXR_Value
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_Value {
     var $data;
     var $type;
 
-    function IXR_Value($data, $type = false)
+       /**
+        * PHP5 constructor.
+        */
+       function __construct( $data, $type = false )
     {
         $this->data = $data;
         if (!$type) {
@@ -69,6 +72,13 @@ class IXR_Value {
         }
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Value( $data, $type = false ) {
+               self::__construct( $data, $type );
+       }
+
     function calculateType()
     {
         if ($this->data === true || $this->data === false) {
@@ -151,14 +161,14 @@ class IXR_Value {
     /**
      * Checks whether or not the supplied array is a struct or not
      *
-     * @param unknown_type $array
-     * @return boolean
+     * @param array $array
+     * @return bool
      */
     function isStruct($array)
     {
         $expected = 0;
         foreach ($array as $key => $value) {
-            if ((string)$key != (string)$expected) {
+            if ((string)$key !== (string)$expected) {
                 return true;
             }
             $expected++;
@@ -171,7 +181,7 @@ class IXR_Value {
  * IXR_MESSAGE
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  *
  */
 class IXR_Message
@@ -194,20 +204,63 @@ class IXR_Message
     // The XML parser
     var $_parser;
 
-    function IXR_Message($message)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $message )
     {
         $this->message =& $message;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Message( $message ) {
+               self::__construct( $message );
+       }
+
     function parse()
     {
         // first remove the XML declaration
         // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
-        $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1);
-        $this->message = substr_replace($this->message, $header, 0, 100);
-        if (trim($this->message) == '') {
+        $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );
+        $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );
+        if ( '' == $this->message ) {
+            return false;
+        }
+
+        // Then remove the DOCTYPE
+        $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );
+        $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );
+        if ( '' == $this->message ) {
+            return false;
+        }
+
+        // Check that the root tag is valid
+        $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) );
+        if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) {
             return false;
         }
+        if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) {
+            return false;
+        }
+
+        // Bail if there are too many elements to parse
+        $element_limit = 30000;
+        if ( function_exists( 'apply_filters' ) ) {
+            /**
+             * Filters the number of elements to parse in an XML-RPC response.
+             *
+             * @since 4.0.0
+             *
+             * @param int $element_limit Default elements limit.
+             */
+            $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );
+        }
+        if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {
+            return false;
+        }
+
         $this->_parser = xml_parser_create();
         // Set XML parser to take the case of tags in to account
         xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
@@ -215,7 +268,19 @@ class IXR_Message
         xml_set_object($this->_parser, $this);
         xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
         xml_set_character_data_handler($this->_parser, 'cdata');
-        $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages
+
+        // 256Kb, parse in chunks to avoid the RAM usage on very large messages
+        $chunk_size = 262144;
+
+        /**
+         * Filters the chunk size that can be used to parse an XML-RPC reponse message.
+         *
+         * @since 4.4.0
+         *
+         * @param int $chunk_size Chunk size to parse in bytes.
+         */
+        $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size );
+
         $final = false;
         do {
             if (strlen($this->message) <= $chunk_size) {
@@ -332,7 +397,7 @@ class IXR_Message
                     $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
                 }
             } else {
-                // Just add as a paramater
+                // Just add as a parameter
                 $this->params[] = $value;
             }
         }
@@ -344,7 +409,7 @@ class IXR_Message
  * IXR_Server
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_Server
 {
@@ -353,7 +418,10 @@ class IXR_Server
     var $message;
     var $capabilities;
 
-    function IXR_Server($callbacks = false, $data = false, $wait = false)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $callbacks = false, $data = false, $wait = false )
     {
         $this->setCapabilities();
         if ($callbacks) {
@@ -365,11 +433,22 @@ class IXR_Server
         }
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Server( $callbacks = false, $data = false, $wait = false ) {
+               self::__construct( $callbacks, $data, $wait );
+       }
+
     function serve($data = false)
     {
         if (!$data) {
             if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
-               header('Content-Type: text/plain'); // merged from WP #9093
+                if ( function_exists( 'status_header' ) ) {
+                    status_header( 405 ); // WP #20986
+                    header( 'Allow: POST' );
+                }
+                header('Content-Type: text/plain'); // merged from WP #9093
                 die('XML-RPC server accepts POST requests only.');
             }
 
@@ -425,7 +504,7 @@ EOD;
 
         // Perform the callback and send the response
         if (count($args) == 1) {
-            // If only one paramater just send that instead of the whole array
+            // If only one parameter just send that instead of the whole array
             $args = $args[0];
         }
 
@@ -473,7 +552,6 @@ EOD;
             $xml = '<?xml version="1.0"?>'."\n".$xml;
         $length = strlen($xml);
         header('Connection: close');
-        header('Content-Length: '.$length);
         if ($charset)
             header('Content-Type: text/xml; charset='.$charset);
         else
@@ -555,7 +633,7 @@ EOD;
  * IXR_Request
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_Request
 {
@@ -563,7 +641,10 @@ class IXR_Request
     var $args;
     var $xml;
 
-    function IXR_Request($method, $args)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct($method, $args)
     {
         $this->method = $method;
         $this->args = $args;
@@ -583,6 +664,13 @@ EOD;
         $this->xml .= '</params></methodCall>';
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Request( $method, $args ) {
+               self::__construct( $method, $args );
+       }
+
     function getLength()
     {
         return strlen($this->xml);
@@ -598,7 +686,7 @@ EOD;
  * IXR_Client
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  *
  */
 class IXR_Client
@@ -616,7 +704,10 @@ class IXR_Client
     // Storage place for an error message
     var $error = false;
 
-    function IXR_Client($server, $path = false, $port = 80, $timeout = 15)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $server, $path = false, $port = 80, $timeout = 15 )
     {
         if (!$path) {
             // Assume we have been given a URL instead
@@ -629,6 +720,10 @@ class IXR_Client
             if (!$this->path) {
                 $this->path = '/';
             }
+
+            if ( ! empty( $bits['query'] ) ) {
+                $this->path .= '?' . $bits['query'];
+            }
         } else {
             $this->server = $server;
             $this->path = $path;
@@ -638,6 +733,13 @@ class IXR_Client
         $this->timeout = $timeout;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
+               self::__construct( $server, $path, $port, $timeout );
+       }
+
     function query()
     {
         $args = func_get_args();
@@ -750,19 +852,29 @@ class IXR_Client
  * IXR_Error
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_Error
 {
     var $code;
     var $message;
 
-    function IXR_Error($code, $message)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $code, $message )
     {
         $this->code = $code;
         $this->message = htmlspecialchars($message);
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Error( $code, $message ) {
+               self::__construct( $code, $message );
+       }
+
     function getXml()
     {
         $xml = <<<EOD
@@ -792,7 +904,7 @@ EOD;
  * IXR_Date
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_Date {
     var $year;
@@ -803,7 +915,10 @@ class IXR_Date {
     var $second;
     var $timezone;
 
-    function IXR_Date($time)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $time )
     {
         // $time can be a PHP timestamp or an ISO one
         if (is_numeric($time)) {
@@ -813,6 +928,13 @@ class IXR_Date {
         }
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Date( $time ) {
+               self::__construct( $time );
+       }
+
     function parseTimestamp($timestamp)
     {
         $this->year = date('Y', $timestamp);
@@ -855,17 +977,27 @@ class IXR_Date {
  * IXR_Base64
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_Base64
 {
     var $data;
 
-    function IXR_Base64($data)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $data )
     {
         $this->data = $data;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_Base64( $data ) {
+               self::__construct( $data );
+       }
+
     function getXml()
     {
         return '<base64>'.base64_encode($this->data).'</base64>';
@@ -876,14 +1008,17 @@ class IXR_Base64
  * IXR_IntrospectionServer
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_IntrospectionServer extends IXR_Server
 {
     var $signatures;
     var $help;
 
-    function IXR_IntrospectionServer()
+       /**
+        * PHP5 constructor.
+        */
+    function __construct()
     {
         $this->setCallbacks();
         $this->setCapabilities();
@@ -917,6 +1052,13 @@ class IXR_IntrospectionServer extends IXR_Server
         );
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_IntrospectionServer() {
+               self::__construct();
+       }
+
     function addCallback($method, $callback, $args, $help)
     {
         $this->callbacks[$method] = $callback;
@@ -1039,18 +1181,28 @@ class IXR_IntrospectionServer extends IXR_Server
  * IXR_ClientMulticall
  *
  * @package IXR
- * @since 1.5
+ * @since 1.5.0
  */
 class IXR_ClientMulticall extends IXR_Client
 {
     var $calls = array();
 
-    function IXR_ClientMulticall($server, $path = false, $port = 80)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $server, $path = false, $port = 80 )
     {
         parent::IXR_Client($server, $path, $port);
         $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) {
+               self::__construct( $server, $path, $port );
+       }
+
     function addCall()
     {
         $args = func_get_args();