nanoserv
[ class tree: nanoserv ] [ index: nanoserv ] [ all elements ]

Source for file NS_Telnet_Line_Input_Handler.php

Documentation is available at NS_Telnet_Line_Input_Handler.php

  1. <?php
  2.  
  3. /**
  4.  *
  5.  * nanoserv handlers - Telnet with line based input protocol handler
  6.  * 
  7.  * Copyright (C) 2004-2010 Vincent Negrier aka. sIX <six@aegis-corp.org>
  8.  * 
  9.  * This library is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU Lesser General Public
  11.  * License as published by the Free Software Foundation; either
  12.  * version 2.1 of the License, or (at your option) any later version.
  13.  * 
  14.  * This library is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.  * Lesser General Public License for more details.
  18.  * 
  19.  * You should have received a copy of the GNU Lesser General Public
  20.  * License along with this library; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
  22.  *
  23.  * @package nanoserv
  24.  * @subpackage Handlers
  25.  */
  26.  
  27. /**
  28.  * Require the Telnet protocol handler
  29.  */
  30. require_once "nanoserv-compat/handlers/NS_Telnet_Handler.php";
  31.  
  32. /**
  33.  * Telnet with line input protocol handler handler class
  34.  *
  35.  * @package nanoserv
  36.  * @subpackage Handlers
  37.  */
  38.  
  39.     /**
  40.      * Maximum line length
  41.      */
  42.     const MAX_LENGTH = 16384;
  43.     
  44.     /**
  45.      * Line separator
  46.      */
  47.     const EOL_SEPARATOR = "\n";
  48.     
  49.     /**
  50.      * Line buffer
  51.      * @var string 
  52.      */
  53.     private $line_buffer "";
  54.     
  55.     /**
  56.      * Telnet read event
  57.      *
  58.      * This event is called every time there is data received
  59.      * The behavior of on_Telnet_Read() is to buffer data until a complete line in available
  60.      * and then pass it to on_Telnet_Read_Line().
  61.      *
  62.      * @param string $s 
  63.      */
  64.     public function on_Telnet_Read($data{
  65.  
  66.         $this->line_buffer .= $data;
  67.  
  68.         while (($p strrpos($this->line_bufferself::EOL_SEPARATOR)) !== false{
  69.  
  70.             $lines explode(self::EOL_SEPARATORsubstr($this->line_buffer0$p));
  71.             $this->line_buffer substr($this->line_buffer$p strlen(self::EOL_SEPARATOR));
  72.  
  73.             foreach ($lines as $line$this->on_Telnet_Read_Line(rtrim($line"\r\n").self::EOL_SEPARATOR);
  74.         
  75.         }
  76.     
  77.         if (strlen($this->line_bufferself::MAX_LENGTH{
  78.  
  79.             $this->on_Telnet_Read_Line($this->line_buffer);
  80.             $this->line_buffer "";
  81.         
  82.         }
  83.     
  84.     }
  85.  
  86.     /**
  87.      * Telnet line read event
  88.      *
  89.      * This event is called every time there is a line of data received
  90.      *
  91.      * @param string $s 
  92.      */
  93.     abstract public function on_Telnet_Read_Line($s);
  94.  
  95. }
  96.  
  97. ?>

Documentation generated on Wed, 30 Nov 2011 22:03:26 +0100 by phpDocumentor 1.4.3