wp/wp-includes/class-IXR.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    28  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    28  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
    29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
    30  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    30  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  *
    31  *
    32  * @package IXR
    32  * @package IXR
    33  * @since 1.5
    33  * @since 1.5.0
    34  *
    34  *
    35  * @copyright  Incutio Ltd 2010 (http://www.incutio.com)
    35  * @copyright  Incutio Ltd 2010 (http://www.incutio.com)
    36  * @version    1.7.4 7th September 2010
    36  * @version    1.7.4 7th September 2010
    37  * @author     Simon Willison
    37  * @author     Simon Willison
    38  * @link       http://scripts.incutio.com/xmlrpc/ Site/manual
    38  * @link       http://scripts.incutio.com/xmlrpc/ Site/manual
    41 
    41 
    42 /**
    42 /**
    43  * IXR_Value
    43  * IXR_Value
    44  *
    44  *
    45  * @package IXR
    45  * @package IXR
    46  * @since 1.5
    46  * @since 1.5.0
    47  */
    47  */
    48 class IXR_Value {
    48 class IXR_Value {
    49     var $data;
    49     var $data;
    50     var $type;
    50     var $type;
    51 
    51 
   149     }
   149     }
   150 
   150 
   151     /**
   151     /**
   152      * Checks whether or not the supplied array is a struct or not
   152      * Checks whether or not the supplied array is a struct or not
   153      *
   153      *
   154      * @param unknown_type $array
   154      * @param array $array
   155      * @return boolean
   155      * @return boolean
   156      */
   156      */
   157     function isStruct($array)
   157     function isStruct($array)
   158     {
   158     {
   159         $expected = 0;
   159         $expected = 0;
   169 
   169 
   170 /**
   170 /**
   171  * IXR_MESSAGE
   171  * IXR_MESSAGE
   172  *
   172  *
   173  * @package IXR
   173  * @package IXR
   174  * @since 1.5
   174  * @since 1.5.0
   175  *
   175  *
   176  */
   176  */
   177 class IXR_Message
   177 class IXR_Message
   178 {
   178 {
   179     var $message;
   179     var $message;
   201 
   201 
   202     function parse()
   202     function parse()
   203     {
   203     {
   204         // first remove the XML declaration
   204         // first remove the XML declaration
   205         // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
   205         // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages
   206         $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1);
   206         $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 );
   207         $this->message = substr_replace($this->message, $header, 0, 100);
   207         $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) );
   208         if (trim($this->message) == '') {
   208         if ( '' == $this->message ) {
   209             return false;
   209             return false;
   210         }
   210         }
       
   211 
       
   212         // Then remove the DOCTYPE
       
   213         $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 );
       
   214         $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) );
       
   215         if ( '' == $this->message ) {
       
   216             return false;
       
   217         }
       
   218 
       
   219         // Check that the root tag is valid
       
   220         $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) );
       
   221         if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) {
       
   222             return false;
       
   223         }
       
   224         if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) {
       
   225             return false;
       
   226         }
       
   227 
       
   228         // Bail if there are too many elements to parse
       
   229         $element_limit = 30000;
       
   230         if ( function_exists( 'apply_filters' ) ) {
       
   231             /**
       
   232              * Filter the number of elements to parse in an XML-RPC response.
       
   233              *
       
   234              * @since 4.0.0
       
   235              *
       
   236              * @param int $element_limit Default elements limit.
       
   237              */
       
   238             $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );
       
   239         }
       
   240         if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {
       
   241             return false;
       
   242         }
       
   243 
   211         $this->_parser = xml_parser_create();
   244         $this->_parser = xml_parser_create();
   212         // Set XML parser to take the case of tags in to account
   245         // Set XML parser to take the case of tags in to account
   213         xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
   246         xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
   214         // Set XML parser callback functions
   247         // Set XML parser callback functions
   215         xml_set_object($this->_parser, $this);
   248         xml_set_object($this->_parser, $this);
   330                 } else {
   363                 } else {
   331                     // Add to array
   364                     // Add to array
   332                     $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
   365                     $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
   333                 }
   366                 }
   334             } else {
   367             } else {
   335                 // Just add as a paramater
   368                 // Just add as a parameter
   336                 $this->params[] = $value;
   369                 $this->params[] = $value;
   337             }
   370             }
   338         }
   371         }
   339         $this->_currentTagContents = '';
   372         $this->_currentTagContents = '';
   340     }
   373     }
   342 
   375 
   343 /**
   376 /**
   344  * IXR_Server
   377  * IXR_Server
   345  *
   378  *
   346  * @package IXR
   379  * @package IXR
   347  * @since 1.5
   380  * @since 1.5.0
   348  */
   381  */
   349 class IXR_Server
   382 class IXR_Server
   350 {
   383 {
   351     var $data;
   384     var $data;
   352     var $callbacks = array();
   385     var $callbacks = array();
   367 
   400 
   368     function serve($data = false)
   401     function serve($data = false)
   369     {
   402     {
   370         if (!$data) {
   403         if (!$data) {
   371             if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
   404             if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') {
   372             	header('Content-Type: text/plain'); // merged from WP #9093
   405                 if ( function_exists( 'status_header' ) ) {
       
   406                     status_header( 405 ); // WP #20986
       
   407                     header( 'Allow: POST' );
       
   408                 }
       
   409                 header('Content-Type: text/plain'); // merged from WP #9093
   373                 die('XML-RPC server accepts POST requests only.');
   410                 die('XML-RPC server accepts POST requests only.');
   374             }
   411             }
   375 
   412 
   376             global $HTTP_RAW_POST_DATA;
   413             global $HTTP_RAW_POST_DATA;
   377             if (empty($HTTP_RAW_POST_DATA)) {
   414             if (empty($HTTP_RAW_POST_DATA)) {
   423         }
   460         }
   424         $method = $this->callbacks[$methodname];
   461         $method = $this->callbacks[$methodname];
   425 
   462 
   426         // Perform the callback and send the response
   463         // Perform the callback and send the response
   427         if (count($args) == 1) {
   464         if (count($args) == 1) {
   428             // If only one paramater just send that instead of the whole array
   465             // If only one parameter just send that instead of the whole array
   429             $args = $args[0];
   466             $args = $args[0];
   430         }
   467         }
   431 
   468 
   432         // Are we dealing with a function or a method?
   469         // Are we dealing with a function or a method?
   433         if (is_string($method) && substr($method, 0, 5) == 'this:') {
   470         if (is_string($method) && substr($method, 0, 5) == 'this:') {
   553 
   590 
   554 /**
   591 /**
   555  * IXR_Request
   592  * IXR_Request
   556  *
   593  *
   557  * @package IXR
   594  * @package IXR
   558  * @since 1.5
   595  * @since 1.5.0
   559  */
   596  */
   560 class IXR_Request
   597 class IXR_Request
   561 {
   598 {
   562     var $method;
   599     var $method;
   563     var $args;
   600     var $args;
   596 
   633 
   597 /**
   634 /**
   598  * IXR_Client
   635  * IXR_Client
   599  *
   636  *
   600  * @package IXR
   637  * @package IXR
   601  * @since 1.5
   638  * @since 1.5.0
   602  *
   639  *
   603  */
   640  */
   604 class IXR_Client
   641 class IXR_Client
   605 {
   642 {
   606     var $server;
   643     var $server;
   626             $this->path = isset($bits['path']) ? $bits['path'] : '/';
   663             $this->path = isset($bits['path']) ? $bits['path'] : '/';
   627 
   664 
   628             // Make absolutely sure we have a path
   665             // Make absolutely sure we have a path
   629             if (!$this->path) {
   666             if (!$this->path) {
   630                 $this->path = '/';
   667                 $this->path = '/';
       
   668             }
       
   669 
       
   670             if ( ! empty( $bits['query'] ) ) {
       
   671                 $this->path .= '?' . $bits['query'];
   631             }
   672             }
   632         } else {
   673         } else {
   633             $this->server = $server;
   674             $this->server = $server;
   634             $this->path = $path;
   675             $this->path = $path;
   635             $this->port = $port;
   676             $this->port = $port;
   748 
   789 
   749 /**
   790 /**
   750  * IXR_Error
   791  * IXR_Error
   751  *
   792  *
   752  * @package IXR
   793  * @package IXR
   753  * @since 1.5
   794  * @since 1.5.0
   754  */
   795  */
   755 class IXR_Error
   796 class IXR_Error
   756 {
   797 {
   757     var $code;
   798     var $code;
   758     var $message;
   799     var $message;
   790 
   831 
   791 /**
   832 /**
   792  * IXR_Date
   833  * IXR_Date
   793  *
   834  *
   794  * @package IXR
   835  * @package IXR
   795  * @since 1.5
   836  * @since 1.5.0
   796  */
   837  */
   797 class IXR_Date {
   838 class IXR_Date {
   798     var $year;
   839     var $year;
   799     var $month;
   840     var $month;
   800     var $day;
   841     var $day;
   853 
   894 
   854 /**
   895 /**
   855  * IXR_Base64
   896  * IXR_Base64
   856  *
   897  *
   857  * @package IXR
   898  * @package IXR
   858  * @since 1.5
   899  * @since 1.5.0
   859  */
   900  */
   860 class IXR_Base64
   901 class IXR_Base64
   861 {
   902 {
   862     var $data;
   903     var $data;
   863 
   904 
   874 
   915 
   875 /**
   916 /**
   876  * IXR_IntrospectionServer
   917  * IXR_IntrospectionServer
   877  *
   918  *
   878  * @package IXR
   919  * @package IXR
   879  * @since 1.5
   920  * @since 1.5.0
   880  */
   921  */
   881 class IXR_IntrospectionServer extends IXR_Server
   922 class IXR_IntrospectionServer extends IXR_Server
   882 {
   923 {
   883     var $signatures;
   924     var $signatures;
   884     var $help;
   925     var $help;
  1037 
  1078 
  1038 /**
  1079 /**
  1039  * IXR_ClientMulticall
  1080  * IXR_ClientMulticall
  1040  *
  1081  *
  1041  * @package IXR
  1082  * @package IXR
  1042  * @since 1.5
  1083  * @since 1.5.0
  1043  */
  1084  */
  1044 class IXR_ClientMulticall extends IXR_Client
  1085 class IXR_ClientMulticall extends IXR_Client
  1045 {
  1086 {
  1046     var $calls = array();
  1087     var $calls = array();
  1047 
  1088