public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context) { $localChannel = $decoder->decodeUint32(); $encoder = new \fpoirotte\Pssht\Wire\Encoder(); $encoder->encodeUint32($localChannel); $decoder->getBuffer()->unget($encoder->getBuffer()->get(0)); if (isset($this->handlers[$localChannel][$msgType])) { $handler = $this->handlers[$localChannel][$msgType]; $logging = \Plop\Plop::getInstance(); $logging->debug('Calling %(handler)s for channel #%(channel)d ' . 'with message type #%(msgType)d', array('handler' => get_class($handler) . '::handle', 'channel' => $localChannel, 'msgType' => $msgType)); return $handler->handle($msgType, $decoder, $transport, $context); } return true; }
public function handle($msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context) { $encoder = new \fpoirotte\Pssht\Wire\Encoder(); $channel = $decoder->decodeUint32(); $type = $decoder->decodeString(); $wantsReply = $decoder->decodeBoolean(); $encoder->encodeUint32($channel); $encoder->encodeString($type); $encoder->encodeBoolean($wantsReply); $decoder->getBuffer()->unget($encoder->getBuffer()->get(0)); $remoteChannel = $this->connection->getChannel($channel); switch ($type) { case 'exec': case 'shell': case 'pty-req': // Normalize the name. // Eg. "pty-req" becomes "PtyReq". $cls = str_replace(' ', '', ucwords(str_replace('-', ' ', $type))); $cls = '\\fpoirotte\\Pssht\\Messages\\CHANNEL\\REQUEST\\' . $cls; $message = $cls::unserialize($decoder); break; default: if ($wantsReply) { $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel); $transport->writeMessage($response); } return true; } if (!$wantsReply) { return true; } if (in_array($type, array('shell', 'exec'), true)) { $response = new \fpoirotte\Pssht\Messages\CHANNEL\SUCCESS($remoteChannel); } else { $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel); } $transport->writeMessage($response); if (in_array($type, array('shell', 'exec'), true)) { $callable = $transport->getApplicationFactory(); if ($callable !== null) { call_user_func($callable, $transport, $this->connection, $message); } } return true; }
protected static function unserializeSub(\fpoirotte\Pssht\Wire\Decoder $decoder) { return array($decoder->decodeUint32()); }
public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder) { return new static($decoder->decodeUint32()); }
public static function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder) { $res = new static(new \fpoirotte\Pssht\Random\Fixed($decoder->decodeBytes(16)), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeNameList(), $decoder->decodeBoolean()); $decoder->decodeUint32(); // Reserved return $res; }
public static final function unserialize(\fpoirotte\Pssht\Wire\Decoder $decoder) { $reflector = new \ReflectionClass(get_called_class()); $args = array_merge(array($decoder->decodeUint32(), $decoder->decodeString(), $decoder->decodeBoolean()), static::unserializeSub($decoder)); return $reflector->newInstanceArgs($args); }