parseResponse() 공개 메소드

public parseResponse ( $data = "" )
예제 #1
0
 function callTamburine($method, $params)
 {
     global $config;
     if (!is_array($params)) {
         $params = array($params);
     }
     // fetch config
     $urlParts = parse_url($config['tamburineURL']);
     $port = $urlParts['port'];
     $host = $urlParts['host'];
     $path = $urlParts['path'];
     //debug("host", $host);
     //debug("port", $port);
     //debug("path", $path);
     /*
     // xmlrpc encode parameters
     for($i=0;$i<count($params);$i++){
       if(get_class($params[$i]) != 'xmlrpcval') {
         $xmlparams[$i] = xmlrpc_encoder($params[$i]);
       }
     }
     $msg = new xmlrpcmsg($method, $xmlparams);
     // this does not work because it rawurlencodes string values
     // and Tamburine does not understand it
     $rawMessage = $msg->serialize();
     */
     $rawMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<methodCall>\n<methodName>{$method}</methodName>\n<params>";
     for ($i = 0; $i < count($params); $i++) {
         $rawMessage .= "\n<param><value>";
         $value = trim($params[$i]);
         if (is_numeric($value)) {
             $rawMessage .= "<i4>{$value}</i4>";
         } else {
             $rawMessage .= "<string>{$value}</string>";
         }
         $rawMessage .= "</value></param>";
     }
     $rawMessage .= "\n</params>\n</methodCall>";
     //prepare request header
     $header = "POST {$path} HTTP/1.1\nAccept: */*\nAccept-Encoding: deflate\nTE: trailers,deflate\nHost: {$host}:{$port}\nUser-Agent: Tamburine/0.2 libwww/5.4.0\nConnection: TE,Keep-Alive\nDate: Tue, 17 Jun 2003 08:59:10 GMT\nContent-Length: " . strlen($rawMessage) . "\nContent-Type: text/xml\n\n";
     $fp = fsockopen($host, $port, $errno, $errstr, $this->timeout);
     if (!$fp) {
         raiseError("Streaming error: {$errstr} ({$errno})");
     }
     if (!socket_set_timeout($fp, $this->timeout)) {
         logError("could not set coket timeout");
     }
     if (!fputs($fp, $header, strlen($header))) {
         raiseError('Streaming error: Write error');
     }
     fflush($fp);
     debug("FLUSH", 1);
     if (!fputs($fp, $rawMessage, strlen($rawMessage))) {
         raiseError('Streaming error: Write error');
     }
     //fflush($fp);
     debug("SENT ALL", 1);
     while (!feof($fp)) {
         $rep = fread($fp, 1024);
         if ($rep === FALSE) {
             raiseError('Streaming error: Read error');
         }
         $rawReply .= $rep;
     }
     fclose($fp);
     $parts = explode("\n\n", $rawReply);
     if (count($parts) > 2) {
         raiseError("could not parse response");
     }
     $header = $parts[0];
     $content = $parts[1];
     $content = preg_replace('/<\\?.*\\?>/', '', $content);
     $msg = new xmlrpcmsg('foo', '');
     $resp = $msg->parseResponse($content);
     //dump($resp->value(), "RETVAL1");
     $retval = xmlrpc_decoder($resp->value());
     return $retval;
 }
    function testUTF8Response()
    {
        $s = new xmlrpcmsg('dummy');
        $f = "HTTP/1.1 200 OK\r\nContent-type: text/xml; charset=UTF-8\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>' . utf8_encode('àüèàüè') . '</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("àüèàüè", $v);
        $f = '<?xml version="1.0" encoding="utf-8"?><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>' . utf8_encode('àüèàüè') . '</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("àüèàüè", $v);
    }
예제 #3
0
    function testValidNumbers()
    {
        $m = new xmlrpcmsg('dummy');
        $fp = '<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value>
<struct>
<member> 
<name>integer1</name>
<value><int>01</int></value>
</member>
<member> 
<name>float1</name>
<value><double>01.10</double></value>
</member>
<member> 
<name>integer2</name>
<value><int>+1</int></value>
</member>
<member> 
<name>float2</name>
<value><double>+1.10</double></value>
</member>
<member>
<name>float3</name>
<value><double>-1.10e2</double></value>
</member>
</struct>
</value>
</param>
</params>
</methodResponse>';
        $r = $m->parseResponse($fp);
        $v = $r->value();
        $s = $v->structmem('integer1');
        $t = $v->structmem('float1');
        $u = $v->structmem('integer2');
        $w = $v->structmem('float2');
        $x = $v->structmem('float3');
        $this->assertEquals(1, $s->scalarval());
        $this->assertEquals(1.1, $t->scalarval());
        $this->assertEquals(1, $u->scalarval());
        $this->assertEquals(1.1, $w->scalarval());
        $this->assertEquals(-110.0, $x->scalarval());
    }