Exemple #1
0
 /**
  * Get request protocol based on Content-Type
  *
  * @return string default as xmlrpc
  */
 protected function init()
 {
     $ver = phpversion();
     if ($ver[0] >= 5) {
         $data = file_get_contents('php://input');
     } else {
         $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
     }
     if (count($_SERVER) == 0) {
         self::alert('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated');
     }
     if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) {
         $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
     } else {
         $content_encoding = '';
     }
     if ($content_encoding != '' && strlen($data)) {
         if ($content_encoding == 'deflate' || $content_encoding == 'gzip') {
             // if decoding works, use it. else assume data wasn't gzencoded
             if (function_exists('gzinflate')) {
                 if ($content_encoding == 'deflate' && ($degzdata = @gzuncompress($data))) {
                     $data = $degzdata;
                 } elseif ($degzdata = @gzinflate(substr($data, 10))) {
                     $data = $degzdata;
                 }
             } else {
                 self::alert('XML-RPC: ' . __METHOD__ . ': Received from client compressed HTTP request and cannot decompress');
             }
         }
     }
     $parsers = php_xmlrpc_decode_xml($data);
     $this->cmd = $parsers->methodname;
     $this->input = php_xmlrpc_decode(new xmlrpcval($parsers->params, 'array'));
 }
function get_method_name()
{
    $ver = phpversion();
    if ($ver[0] >= 5) {
        $data = file_get_contents('php://input');
    } else {
        $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
    }
    $parsers = php_xmlrpc_decode_xml($data);
    return trim($parsers->methodname);
}
function mobi_parse_requrest()
{
    global $request_method, $request_params, $params_num;
    $ver = phpversion();
    if ($ver[0] >= 5) {
        $data = file_get_contents('php://input');
    } else {
        $data = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
    }
    if (count($_SERVER) == 0) {
        $r = new xmlrpcresp('', 15, 'XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated');
        echo $r->serialize('UTF-8');
        exit;
    }
    if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) {
        $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
    } else {
        $content_encoding = '';
    }
    if ($content_encoding != '' && strlen($data)) {
        if ($content_encoding == 'deflate' || $content_encoding == 'gzip') {
            // if decoding works, use it. else assume data wasn't gzencoded
            if (function_exists('gzinflate')) {
                if ($content_encoding == 'deflate' && ($degzdata = @gzuncompress($data))) {
                    $data = $degzdata;
                } elseif ($degzdata = @gzinflate(substr($data, 10))) {
                    $data = $degzdata;
                }
            } else {
                $r = new xmlrpcresp('', 106, 'Received from client compressed HTTP request and cannot decompress');
                echo $r->serialize('UTF-8');
                exit;
            }
        }
    }
    $parsers = php_xmlrpc_decode_xml($data);
    $request_method = $parsers->methodname;
    $request_params = php_xmlrpc_decode(new xmlrpcval($parsers->params, 'array'));
    $params_num = count($request_params);
}
 function testAutoCoDec()
 {
     $data1 = array(1, 1.0, 'hello world', true, '20051021T23:43:00', -1, 11.0, '~!@#$%^&*()_+|', false, '20051021T23:43:00');
     $data2 = array('zero' => $data1, 'one' => $data1, 'two' => $data1, 'three' => $data1, 'four' => $data1, 'five' => $data1, 'six' => $data1, 'seven' => $data1, 'eight' => $data1, 'nine' => $data1);
     $data = array($data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2, $data2);
     //$keys = array('zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');
     $v1 = php_xmlrpc_encode($data, array('auto_dates'));
     $v2 = php_xmlrpc_decode_xml($v1->serialize());
     $this->assertEquals($v1, $v2);
     $r1 = new xmlrpcresp($v1);
     $r2 = php_xmlrpc_decode_xml($r1->serialize());
     $r2->serialize();
     // needed to set internal member payload
     $this->assertEquals($r1, $r2);
     $m1 = new xmlrpcmsg('hello dolly', array($v1));
     $m2 = php_xmlrpc_decode_xml($m1->serialize());
     $m2->serialize();
     // needed to set internal member payload
     $this->assertEquals($m1, $m2);
 }
    public function testLatin1Response()
    {
        $string = chr(224) . chr(252) . chr(232);
        $s = $this->newMsg('dummy');
        $f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=ISO-8859-1\r\n\r\n" . '<?xml version="1.0"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . $string . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
';
        $r = $s->parseResponse($f, false, 'phpvals');
        $v = $r->value();
        $v = $v['content'];
        $this->assertEquals($string, $v);
        $f = '<?xml version="1.0" encoding="ISO-8859-1"?><methodResponse><params><param><value><struct><member><name>userid</name><value>311127</value></member>
<member><name>dateCreated</name><value><dateTime.iso8601>20011126T09:17:52</dateTime.iso8601></value></member><member><name>content</name><value>' . $string . '</value></member><member><name>postid</name><value>7414222</value></member></struct></value></param></params></methodResponse>
';
        $r = $s->parseResponse($f, false, 'phpvals');
        $v = $r->value();
        $v = $v['content'];
        $this->assertEquals($string, $v);
        $r = php_xmlrpc_decode_xml($f);
        $v = $r->value();
        $v = $v->structmem('content')->scalarval();
        $this->assertEquals($string, $v);
    }