00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #ifndef __VTY_H__
00037 #define __VTY_H__
00038 
00039 #include "global.h"
00040 
00041 namespace tacpp {
00042 
00043 #define TERMINAL_TIMEOUT        10000
00044 enum command {
00045   T_KEY_INSERT_CHAR=0,
00046   T_KEY_BEGINNING_OF_LINE,      
00047   T_KEY_BACKWARD_CHAR,  
00048   T_KEY_DELETE_CHAR,
00049   T_KEY_END_OF_LINE,
00050   T_KEY_FORWARD_CHAR,
00051   T_KEY_DELETE_BACKWARD_CHAR,
00052   T_KEY_CLEAR_LINE,
00053   T_KEY_NEXT_COMMAND,
00054   T_KEY_PREVIOUS_COMMAND,
00055   T_KEY_CLEAR_LINE_FROM_BEGINNING,
00056   T_KEY_KILL_WORD,
00057   T_KEY_EXECUTE_COMMAND,
00058   T_KEY_COMPLETE_COMMAND,
00059   T_KEY_GET_HELP,
00060 
00061   T_KEY_UP,
00062   T_KEY_DOWN,
00063   T_KEY_LEFT,
00064   T_KEY_RIGHT,
00065 
00066   T_KEY_EOF
00067 };
00068 
00069 enum telnetOpt {
00070   TELOPT_BINARY=0,
00071   TELOPT_ECHO=1,
00072   TELOPT_SGA=3,
00073   TELOPT_STATUS=5,
00074   TELOPT_NAOFFD=13,
00075   TELOPT_NAWS=31,
00076 };
00077 enum telnetCmd {
00078   SE=240,
00079   NOP,
00080   DMARK,
00081   BRK,
00082   IP,
00083   AO,
00084   AYT,
00085   EC,
00086   EL,
00087   GA,
00088   SB,
00089   WILL,
00090   WONT,
00091   DO,
00092   DONT,
00093   IAC
00094 };
00095 
00096 const int maxVtyInput=512;
00101 class VtyLineSplitter;
00102 class Vty {
00103  protected:
00106   char vty_line[maxVtyInput+1];
00109   int vtylinepos;
00110  public:
00116   bool isChanged;
00119   VtyLineSplitter *vtSplit;
00122   virtual string vty_get_line();
00125   virtual int vty_get_linepos();
00129   virtual void vty_cleanup();
00132   virtual void vty_set_line(const char *);
00135   virtual bool twriteErr(const char*);
00138   virtual bool twrite(const char*);
00141   virtual int treadstr()=0;
00144   virtual char * readstr()=0;
00145 };
00146 
00149 class VtyStream : public Vty {
00150  private:
00153   std::istream * cfstr;
00154  public:
00157   VtyStream(const char * fileName)throw(VtyErr);
00160   VtyStream(const  string strAsBuffer);
00163   virtual ~VtyStream();
00166   virtual int treadstr()throw(VtyErr);
00169   virtual bool twriteErr(const char*)throw(VtyErr);
00172   virtual char * readstr()throw(VtyErr) ;
00173 };
00174 
00177 class VtyTerm : public Packet,public Vty {
00178  private:
00181   int handle;
00184   struct in_addr in_address;
00187   char address[100];
00190   int vty_height;
00193   int vty_width;
00194 
00195  public:
00199   bool local_echo;
00202   void vty_clear_input();
00205   void vty_insert_char(unsigned char);
00208   void vty_del_char();
00211   void vty_del_backward_char();
00214   void vty_clear_line_from_beg();
00217   void vty_redraw_line();
00220   void vty_move_forward();
00223   void vty_move_backward();
00226   void vty_move_beginning_of_line();
00229   void vty_move_end_of_line();
00232   void vty_move_to(int pos);
00235   virtual int treadstr();
00238   char * readstr();
00241   virtual bool twriteErr(const char*);
00244   bool twrite(const char*);
00247   bool twrite(unsigned char );
00249   void twrite_marker_at(int pos,char a='^');
00252   unsigned char tsymbol(int &);
00255   void echo(bool);
00258   void linemode(bool);
00261   void toptions();
00264   void tset();
00267   void pager(const char*sourcePage,int height=0);
00270   int get_handle();
00273   VtyTerm(int,struct in_addr);
00276   virtual ~VtyTerm();
00277 };
00278 
00279 };
00280 
00281 #endif //__VTY_H__