예제 #1
0
 function inputFilter($data, stdClass $context)
 {
     if ($data !== "" && ($data[0] === '[' || $data[0] === '{')) {
         try {
             $requests = json_decode($data);
         } catch (Exception $e) {
             return $data;
         }
         if ($data[0] === '{') {
             $requests = array($requests);
         } else {
             if (count($requests) === 0) {
                 return $data;
             }
         }
         $stream = new BytesIO();
         $writer = new Writer($stream, true);
         $context->userdata->jsonrpc = array();
         foreach ($requests as $request) {
             $jsonrpc = new stdClass();
             if (isset($request->id)) {
                 $jsonrpc->id = $request->id;
             } else {
                 $jsonrpc->id = null;
             }
             if (isset($request->version)) {
                 $jsonrpc->version = $request->version;
             } else {
                 if (isset($request->jsonrpc)) {
                     $jsonrpc->version = $request->jsonrpc;
                 } else {
                     $jsonrpc->version = '1.0';
                 }
             }
             $context->userdata->jsonrpc[] = $jsonrpc;
             if (isset($request->method)) {
                 $stream->write(Tags::TagCall);
                 $writer->writeString($request->method);
                 if (isset($request->params) && count($request->params) > 0) {
                     $writer->writeArray($request->params);
                 }
             } else {
                 unset($context->userdata->jsonrpc);
                 return $data;
             }
         }
         $stream->write(Tags::TagEnd);
         $data = $stream->toString();
         unset($stream);
         unset($writer);
     }
     return $data;
 }
예제 #2
0
 public function inputFilter($data, stdClass $context)
 {
     $result = xmlrpc_decode($data, "UTF-8");
     $stream = new BytesIO();
     $writer = new Writer($stream, true);
     if (isset($result['faultString'])) {
         $stream->write(Tags::TagError);
         $writer->writeString($result['faultString']);
     } else {
         $stream->write(Tags::TagResult);
         $writer->serialize($result);
     }
     $stream->write(Tags::TagEnd);
     return $stream->toString();
 }
예제 #3
0
 public function inputFilter($data, stdClass $context)
 {
     if ($data !== "" && $data[0] === '<') {
         $context->userdata->format = "xmlrpc";
         $method = null;
         $params = xmlrpc_decode_request($data, $method, "UTF-8");
         $stream = new BytesIO();
         $writer = new Writer($stream, true);
         if (isset($method)) {
             $stream->write(Tags::TagCall);
             $writer->writeString($method);
             if (isset($params)) {
                 $writer->writeArray($params);
             }
         }
         $stream->write(Tags::TagEnd);
         $data = $stream->toString();
     }
     return $data;
 }
예제 #4
0
 public function inputFilter($data, stdClass $context)
 {
     $response = json_decode($data);
     if (!isset($response->result)) {
         $response->result = null;
     }
     if (!isset($response->error)) {
         $response->error = null;
     }
     $stream = new BytesIO();
     $writer = new Writer($stream, true);
     if ($response->error) {
         $stream->write(Tags::TagError);
         $writer->writeString($response->error->message);
     } else {
         $stream->write(Tags::TagResult);
         $writer->serialize($response->result);
     }
     $stream->write(Tags::TagEnd);
     return $stream->toString();
 }
예제 #5
0
 protected function doFunctionList()
 {
     $stream = new BytesIO();
     $writer = new Writer($stream, true);
     $stream->write(Tags::TagFunctions);
     $writer->writeArray($this->names);
     $stream->write(Tags::TagEnd);
     $data = $stream->toString();
     $stream->close();
     return $data;
 }
예제 #6
0
 private function writeRef(BytesIO $stream, $index)
 {
     $stream->write(Tags::TagRef . $index . Tags::TagSemicolon);
     return true;
 }
예제 #7
0
 private function readComplexRaw(BytesIO $ostream)
 {
     $s = $this->stream->readuntil(Tags::TagOpenbrace) . Tags::TagOpenbrace;
     $ostream->write($s);
     while (($tag = $this->stream->getc()) != Tags::TagClosebrace) {
         $this->privateReadRaw($ostream, $tag);
     }
     $ostream->write($tag);
 }
예제 #8
0
 private function encode($name, array $args, stdClass $context)
 {
     $stream = new BytesIO(Tags::TagCall);
     $writer = new Writer($stream, $context->simple);
     $writer->writeString($name);
     if (count($args) > 0 || $context->byref) {
         $writer->reset();
         $writer->writeArray($args);
         if ($context->byref) {
             $writer->writeBoolean(true);
         }
     }
     $stream->write(Tags::TagEnd);
     $request = $stream->toString();
     $stream->close();
     return $request;
 }