示例#1
0
 /**
  * Dispath one message
  * @param callback if not NULL, each packet will be processed with this function;
  *                 in case that function returns TRUE, packet won't be processed
  *                 by dispather, but will be returned;
  *                 function has to accept one argument (whole packet /with 
  *                 leading packet type byte) and return boolean
  *
  * @return string|NULL string if packet was catched by return filter, NULL 
  *                     otherwise
  */
 public function dispatch($return_filter = NULL)
 {
     if ($return_filter !== NULL && !is_callable($return_filter)) {
         throw new Error('Given callback is not callable.');
     }
     $packet = $this->protocol->receive();
     if ($return_filter !== NULL) {
         if ($return_filter($packet)) {
             return $packet;
         }
     }
     list($packet_type) = parse('b', $packet);
     if (!isset($this->callbacks[$packet_type])) {
         $this->protocol->send('bu', SSH_MSG_UNIMPLEMENTED, $this->protocol->getReceiveSeq());
         return NULL;
     }
     $callback = $this->callbacks[$packet_type];
     if ($callback === NULL) {
         return NULL;
     }
     $callback($packet);
     return NULL;
 }