Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 private function doInvoke(BytesIO $stream, stdClass $context)
 {
     $results = array();
     $reader = new Reader($stream);
     do {
         $reader->reset();
         $name = $reader->readString();
         $alias = strtolower($name);
         $cc = new stdClass();
         $cc->isMissingMethod = false;
         foreach ($context as $key => $value) {
             $cc->{$key} = $value;
         }
         if (isset($this->calls[$alias])) {
             $call = $this->calls[$alias];
         } else {
             if (isset($this->calls['*'])) {
                 $call = $this->calls['*'];
                 $cc->isMissingMethod = true;
             }
         }
         if ($call) {
             foreach ($call as $key => $value) {
                 $cc->{$key} = $value;
             }
         }
         $args = array();
         $cc->byref = false;
         $tag = $stream->getc();
         if ($tag === Tags::TagList) {
             $reader->reset();
             $args = $reader->readListWithoutTag();
             $tag = $stream->getc();
             if ($tag === Tags::TagTrue) {
                 $cc->byref = true;
                 $tag = $stream->getc();
             }
         }
         if ($tag !== Tags::TagEnd && $tag !== Tags::TagCall) {
             $data = $stream->toString();
             throw new Exception("Unknown tag: {$tag}\r\nwith following data: {$data}");
         }
         if ($call) {
             $results[] = $this->beforeInvoke($name, $args, $cc);
         } else {
             $results[] = $this->sendError(new Exception("Can\\'t find this function {$name}()."), $cc);
         }
     } while ($tag === Tags::TagCall);
     return Future\reduce($results, function ($stream, $result) {
         $stream->write($result);
         return $stream;
     }, new BytesIO())->then(function ($stream) {
         $stream->write(Tags::TagEnd);
         $data = $stream->toString();
         $stream->close();
         return $data;
     });
 }
Ejemplo n.º 4
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;
 }