예제 #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
 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;
     });
 }
예제 #6
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;
 }