示例#1
0
 public function outputFilter($data, stdClass $context)
 {
     if (isset($context->userdata->format) && $context->userdata->format === "xmlrpc") {
         $result = null;
         if ($data !== "") {
             $stream = new BytesIO($data);
             $reader = new Reader($stream);
             while (($tag = $stream->getc()) !== Tags::TagEnd) {
                 $reader->reset();
                 switch ($tag) {
                     case Tags::TagResult:
                         $result = $reader->unserialize();
                         break;
                     case Tags::TagError:
                         $lasterror = error_get_last();
                         $result = array("faultCode" => $lasterror["type"], "faultString" => $reader->unserialize());
                         break;
                     case Tags::TagFunctions:
                         $result = $reader->unserialize();
                         break;
                     default:
                         return xmlrpc_encode($result);
                 }
             }
         }
         $data = xmlrpc_encode($result);
     }
     return $data;
 }
示例#2
0
 public function outputFilter($data, stdClass $context)
 {
     $request = new stdClass();
     if ($this->version === "1.1") {
         $request->version = "1.1";
     } else {
         if ($this->version === "2.0") {
             $request->jsonrpc = "2.0";
         }
     }
     $stream = new BytesIO($data);
     $reader = new Reader($stream);
     $tag = $stream->getc();
     if ($tag === Tags::TagCall) {
         $request->method = $reader->readString();
         $tag = $stream->getc();
         if ($tag == Tags::TagList) {
             $reader->reset();
             $request->params = $reader->readListWithoutTag();
         }
     } else {
         throw new Exception("Error Processing Request", 1);
     }
     $request->id = self::$id++;
     return json_encode($request);
 }
示例#3
0
 public function outputFilter($data, stdClass $context)
 {
     $method = null;
     $params = array();
     $stream = new BytesIO($data);
     $reader = new Reader($stream);
     $tag = $stream->getc();
     if ($tag === Tags::TagCall) {
         $method = $reader->readString();
         $tag = $stream->getc();
         if ($tag == Tags::TagList) {
             $reader->reset();
             $params = $reader->readListWithoutTag();
         }
     } else {
         throw new Exception("Error Processing Request", 1);
     }
     return xmlrpc_encode_request($method, $params);
 }
示例#4
0
 function outputFilter($data, stdClass $context)
 {
     if (isset($context->userdata->jsonrpc)) {
         $responses = array();
         $stream = new BytesIO($data);
         $reader = new Reader($stream);
         $tag = $stream->getc();
         foreach ($context->userdata->jsonrpc as $jsonrpc) {
             $response = new stdClass();
             $response->id = $jsonrpc->id;
             $version = $jsonrpc->version;
             if ($version !== '2.0') {
                 if ($version === '1.1') {
                     $response->version = '1.1';
                 }
                 $response->result = null;
                 $response->error = null;
             } else {
                 $response->jsonrpc = '2.0';
             }
             if ($tag !== Tags::TagEnd) {
                 $reader->reset();
                 if ($tag === Tags::TagResult) {
                     $response->result = $reader->unserialize();
                 } else {
                     if ($tag === Tags::TagError) {
                         $lasterror = error_get_last();
                         $response->error = new stdClass();
                         $response->error->code = $lasterror['type'];
                         $response->error->message = $reader->unserialize();
                     }
                 }
                 $tag = $stream->getc();
             } else {
                 $response->result = null;
             }
             if ($response->id !== null) {
                 $responses[] = $response;
             }
         }
         if (count($context->userdata->jsonrpc) === 1) {
             if (count($responses) === 1) {
                 return json_encode($responses[0]);
             }
             return '';
         }
         return json_encode($responses);
     }
     return $data;
 }
示例#5
0
 function afterFilterHandler($request, stdClass $context)
 {
     $stream = new BytesIO($request);
     try {
         switch ($stream->getc()) {
             case Tags::TagCall:
                 $data = $this->doInvoke($stream, $context);
                 $stream->close();
                 return $data;
             case Tags::TagEnd:
                 $stream->close();
                 return Future\value($this->doFunctionList());
             default:
                 throw new Exception("Wrong Request: \r\n{$request}");
         }
     } catch (Exception $e) {
         $stream->close();
         return Future\error($e);
     }
 }
示例#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
 function decode($response, array &$args, stdClass $context)
 {
     if ($context->oneway) {
         return null;
     }
     if (empty($response)) {
         throw new Exception("EOF");
     }
     if ($response[strlen($response) - 1] !== Tags::TagEnd) {
         throw new Exception("Wrong Response: \r\n{$response}");
     }
     $mode = $context->mode;
     if ($mode === ResultMode::RawWithEndTag) {
         return $response;
     } elseif ($mode === ResultMode::Raw) {
         return substr($response, 0, -1);
     }
     $stream = new BytesIO($response);
     $reader = new Reader($stream);
     $result = null;
     $tag = $stream->getc();
     if ($tag === Tags::TagResult) {
         if ($mode === ResultMode::Normal) {
             $result = $reader->unserialize();
         } elseif ($mode === ResultMode::Serialized) {
             $result = $reader->readRaw()->toString();
         }
         $tag = $stream->getc();
         if ($tag === Tags::TagArgument) {
             $reader->reset();
             $arguments = $reader->readList();
             $n = min(count($arguments), count($args));
             for ($i = 0; $i < $n; $i++) {
                 $args[$i] = $arguments[$i];
             }
             $tag = $stream->getc();
         }
     } elseif ($tag === Tags::TagError) {
         $e = new Exception($reader->readString());
         $stream->close();
         throw $e;
     }
     if ($tag !== Tags::TagEnd) {
         $stream->close();
         throw new Exception("Wrong Response: \r\n{$response}");
     }
     $stream->close();
     return $result;
 }