NetBurner 3.1
command.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 /*****************************************************************************
6 *****************************************************************************
7 *****************************************************************************
8 
9  This is the header file for a command processor task.
10  It reads input one line at a time from multiple sources and
11  when it gathers a whole line it sends it to a command processor
12 
13 *****************************************************************************
14 *****************************************************************************
15 *****************************************************************************/
16 
17 #ifndef _NB_COMMAND_H
18 #define _NB_COMMAND_H
19 
20 #include <basictypes.h>
21 #include <stdio.h>
22 
23 #define CMD_OK (0)
24 #define CMD_CLOSE (1)
25 #define CMD_FAIL (2)
26 #define CMD_AUTH_FAIL (3)
27 #define CMD_TO_MANY_FDS (4)
28 
29 /*****************************************************************************
30  External Authentication function CALLBACK , used to verify Username and Password
31  If this function pointer is not NULL then each new Telnet sessioon will
32  be asked to authenticate
33 The function returns:
34 CMD_OK IF the authentication was ok
35 CMD_CLOSE IF the authentication causes the session to terminate (Close)
36 *****************************************************************************/
37 extern int (*CmdAuthenticateFunc)(const char *name, const char *passwd);
38 
39 /*****************************************************************************
40  The command processing CALLBACK function
41  This function is of the form
42 int ProcessCommand(const char * command, int fd_respondeto)
43 Where
44  command is a pointer to the null terminated ASCII text of the command.
45  fRespondto is the FILE * all response should be set to. (Use fprintf)
46 The function returns:
47 CMD_OK IF the command was ok
48 CMD_CLOSE IF the command causes the session to terminate (Close)
49 *****************************************************************************/
50 extern int (*CmdCmd_func)(const char *command, FILE *fRespondto, void *pData);
51 
52 /* Same as CmdCmd func, but if defined sends single chars
53  If this is implmented does not do echo or line editing this is the responsibility of the
54  Application programmer.
55 */
56 extern int (*CmdChar_func)(char command, FILE *fRespondto, void *pData);
57 
58 /*****************************************************************************
59 Connect CALLBACK function, if this function is not NULL then the system
60 will call this function every time a new session is started
61 This function is of the form
62  void ConnectCommand(int fd_respondeto)
63 Where
64  fRespondto is the FILE * all response should be sent to. (Use fprintf)
65 Returns an arbitrary void * data item to be asociated with the session. This
66 data item is the same pData item used in other callback functions such as
67 CmdPrompt_func.
68 *****************************************************************************/
69 extern void *(*CmdConnect_func)(FILE *fRespondto);
70 
71 /*****************************************************************************
72  Prompt callback function, if this function is not NULL then the system
73  will call this function every time a new prompt line needs to be displayed
74  This function is of the form
75  void CommandPrompt(int fd_respondeto)
76  Where
77  fRespondto is the FILE * all response should be sent to. (Use fprintf)
78  The pData parameter is the value returned by CmdConnect_func.
79 *****************************************************************************/
80 extern void (*CmdPrompt_func)(FILE *fRespondto, void *pData);
81 
82 /*****************************************************************************
83  Dis-Connect callback function, if this function is not NULL then the system
84 will call this function every time a session is terminated
85 This function is of the form
86  void DisconnectCommand(int fd_respondeto, int cause)
87 Where
88  fRespondto is the FILE * all response should be sent to. (Use fprintf)
89  cause is why it is disconnected.
90 The current values of Cause are : */
91 #define CMD_DIS_CAUSE_TIMEOUT (1)
92 #define CMD_DIS_CAUSE_CLOSED (2)
93 #define CMD_DIS_SOCKET_CLOSED (3) /* Don't send a response for this case */
94 #define CMD_DIS_AUTH_FAILED (4) /* Don't send a response for this case */
95 
96 /*****************************************************************************/
97 extern void (*CmdDisConnect_func)(FILE *fRespondto, int cause, void *pData);
98 
99 /*****************************************************************************
100 The number of seconds a connection is idle before it is terminated
101 due to inactivity.
102 *****************************************************************************/
103 extern int CmdIdleTimeout;
104 
105 /* If this is not NULL then it will be sent to the socket on connection.
106 Before Authentication is tried
107 */
108 extern const char *Cmdlogin_prompt;
109 
110 /*****************************************************************************
111 Start the command processor.
112  int priority = the NBRTOS task priority to run at
113 Returns:
114  CMD_OK
115  CMD_FAIL
116 *****************************************************************************/
117 int CmdStartCommandProcessor(int priority);
118 
119 /* Stop the running process and close all open sockets/fd's */
120 void CmdStopCommandProcessor();
121 
122 /****************************************************************************
123  Add an established FD connection to the list of fd's managed
124  by the command processor.
125 
126  int fd //the file descriptor
127  int require_auth //Do we Authenticate the connection on this FD?
128  int time_out_conn //Do we time out the connection on this FD?
129  Returns:
130  CMD_OK
131  CMD_FAIL
132  CMD_TO_MANY_FDS
133 *****************************************************************************/
134 int CmdAddCommandFd(int fd, int require_auth, int time_out_conn, int local_echo = TRUE);
135 
136 /*****************************************************************************/
137 /* Remove an established FD (Either a TCP session or a serial connection
138 Returns:
139  CMD_OK
140  CMD_FAIL
141 *****************************************************************************/
142 int CmdRemoveCommandFd(int Fd);
143 
144 /*****************************************************************************
145  Start listening for connection on a TCP port.
146  uint16_t port // The port number
147  int do_telnet_processing //Should we treat the port as telnet and process telnet negotiations?
148  int max_connecitons //What are the max number of connections we should allow on this port
149 Returns:
150  CMD_OK
151  CMD_FAIL
152 *****************************************************************************/
153 int CmdListenOnTcpPort(uint16_t port, int do_telnet_processing, int max_connections);
154 /* Same as above, but not siggnon or password */
155 int CmdListenQuietOnTcpPort(uint16_t port, int do_telnet_processing, int max_connections);
156 
157 /*****************************************************************************
158  Stop Listening for connections on the specified port.
159  Also closes all open connections that were based on that port
160 Returns:
161  CMD_OK
162  CMD_FAIL
163 *****************************************************************************/
164 int CmdStopListeningOnTcpPort(uint16_t port);
165 
166 /* Send to all connected sockets, excluding "Listening sockets" */
167 void SendToAll(char *buffer, int len, BOOL include_serial_ports);
168 
169 #endif