embkernel
 All Classes Functions Variables Typedefs Groups Pages
NetServerTelnet.hpp
1 //------------------------------------------------------------------------------
2 //This file is part of embKernel.
3 //See license.txt for the full license governing this code.
4 //------------------------------------------------------------------------------
5 
6 #ifndef NET_SERVER_TELNET_HPP_
7 #define NET_SERVER_TELNET_HPP_
8 
9 #include "RtosInclude.hpp"
10 #include "NetInclude.hpp"
11 
12 class NetServerTelnet: public RtosRunnable {
13 protected:
14  typedef void (NetServerTelnet::*CMD_HANDLER)(int argc, char *argv[]);
15 
16  typedef struct {
17  const char* name;
18  CMD_HANDLER handler;
19  const char* descritpion;
20  } ENTRY;
21 
22  const ENTRY* mEntries;
23 
24 public:
25  NetServerTelnet(int priority, size_t stackSize);
26  ~NetServerTelnet();
27 
28 private:
29  const static int MAX_LINE_LEN = 256;
30  bool mIsLineFeedSeq;
31 
32  void iacNegotiate();
33 
34 protected:
35  RtosTask mTask;
36  NetTcpSocket mSocket;
37 
38  int getLine(char** line);
39  void freeLine(char* line);
40 
41  int getArgc(char* line);
42  void getArgV(char* line, char* argv[]);
43 
44  virtual void onConnection();
45  virtual void onDisconnection();
46  virtual void run();
47 
48  void ansiCursorUp(int value);
49  void ansiCursorDown(int value);
50  void ansiCursorForward(int value);
51  void ansiCursorBack(int value);
52  void ansiCursorPosition(int x, int y);
53  void ansiEraseData(int value);
54  void ansiEraseInLine(int value);
55  void ansiSaveCursorPosition();
56  void ansiRestoreCursorPosition();
57  void ansiHideCursor();
58  void ansiShowCursor();
59 
60  const static int RESULT_ERR_LINE_TOO_LONG = -1;
61  const static int RESULT_ERR_MEMORY = -2;
62  const static int RESULT_ERR_IO = -3;
63  const static int RESULT_EMPTY_LINE = -4;
64 
65 private:
66  typedef enum
67  :uint8_t {
68  SE = 240, //End of subnegotiation parameters
69  NOP = 241, //No operation
70  DM = 242, //Data mark Indicates the position of a Synch event within the data stream. This should always be accompanied by a TCP urgent notification.
71  BRK = 243, //Break Indicates that the "break" or "attention" key was hi.
72  IP = 244, //Suspend Interrupt or abort the process to which the NVT is connected.
73  AO = 245, //Abort output Allows the current process to run to completion but does not send its output to the user.
74  AYT = 246, //Are you there Send back to the NVT some visible evidence that the AYT was received.
75  EC = 247, //Erase character The receiver should delete the last preceding undeleted character from the data stream.
76  EL = 248, //Erase line Delete characters from the data stream back to but not including the previous CRLF.
77  GA = 249, //Go ahead Under certain circumstances used to tell the other end that it can transmit.
78  SB = 250, //Subnegotiation Subnegotiation of the indicated option follows.
79  WILL = 251, //will Indicates the desire to begin performing, or confirmation that you are now performing, the indicated option.
80  WONT = 252, //wont Indicates the refusal to perform, or continue performing, the indicated option.
81  DO = 253, //do Indicates the request that the other party perform, or confirmation that you are expecting the other party to perform, the indicated option.
82  DONT = 254, //dont Indicates the demand that the other party stop performing, or confirmation that you are no longer expecting the other party to perform, the indicated option.
83  IAC = 255 //Interpret as
84  } COMMANDS;
85 
86  typedef enum
87  :uint8_t {
88  SUPPRESS_GO_AHEAD = 3, //suppress go ahead (RFC858)
89  STATUS = 5, //status (RFC859)
90  ECHO = 1, //echo (RFC857)
91  TIMING_MARK = 6, //timing mark (RFC860)
92  TERMINAL_TYPE = 24, //terminal type (RFC1091)
93  WINDOW_SIZE = 31, //window size (RFC1073)
94  TERMINAL_SPEED = 32, //terminal speed (RFC1079)
95  REMOTE_FLOW_CONTROL = 33, //remote flow control(RFC1372)
96  LINEMODE = 34, //linemode (RFC1184)
97  ENVIRONMENT_VARIABLES = 36 //environment variables (RFC1408)
98  } OPTION;
99 
100 };
101 
102 #endif /* NET_SERVER_TELNET_HPP_ */