improved handling for list of telnet commands
This commit is contained in:
parent
676e16a477
commit
bdf36796bf
6 changed files with 36 additions and 14 deletions
5
client.c
5
client.c
|
@ -1,5 +1,8 @@
|
|||
#include "moxerver.h"
|
||||
/*
|
||||
* Handling communication with clients.
|
||||
*/
|
||||
|
||||
#include "moxerver.h"
|
||||
|
||||
/* Closes client connection. */
|
||||
int client_close(struct client_t *client) {
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
/*
|
||||
* Main server application.
|
||||
* Handles client connections on specific TCP port and allows bidirectional
|
||||
* communication with a specific TTY device.
|
||||
*/
|
||||
|
||||
#include "moxerver.h"
|
||||
#include <signal.h> /* handling quit signals */
|
||||
#include <pthread.h>
|
||||
|
@ -8,7 +14,6 @@
|
|||
#define PORT_MIN 4001 /* minimum TCP port number */
|
||||
#define PORT_MAX 4008 /* maximum TCP port number */
|
||||
|
||||
|
||||
/* Prints help message. */
|
||||
static void usage() {
|
||||
//TODO maybe some styling should be done
|
||||
|
|
|
@ -140,6 +140,8 @@ int telnet_handle_client_read(char *databuf, int *datalen);
|
|||
int telnet_handle_client_write(char *databuf, int *datalen);
|
||||
|
||||
|
||||
/* Functions handling communication with tty device. */
|
||||
|
||||
/* Opens the tty device and configures it. */
|
||||
int tty_open(struct tty_t *tty_dev);
|
||||
/* Closes the tty device. */
|
||||
|
|
5
server.c
5
server.c
|
@ -1,5 +1,8 @@
|
|||
#include "moxerver.h"
|
||||
/*
|
||||
* Handling server operation.
|
||||
*/
|
||||
|
||||
#include "moxerver.h"
|
||||
|
||||
/* Sets up the server on specific port, binds to a socket and listens for client connections. */
|
||||
int server_setup(struct server_t *server, unsigned int port) {
|
||||
|
|
27
telnet.c
27
telnet.c
|
@ -1,5 +1,8 @@
|
|||
#include "moxerver.h"
|
||||
/*
|
||||
* Handling details related to telnet protocol.
|
||||
*/
|
||||
|
||||
#include "moxerver.h"
|
||||
|
||||
/* structure for holding telnet option name and value */
|
||||
struct telnet_option_t {
|
||||
|
@ -17,25 +20,27 @@ struct telnet_option_t telnet_options[] = {
|
|||
{"ECHO", 1},
|
||||
{"SGA", 3},
|
||||
{"LINEMODE", 34},
|
||||
{NULL, 0}
|
||||
/* this list must end with {NULL, 0} */
|
||||
};
|
||||
#define TELNET_OPTIONS_COUNT 8 /* keep this up with the number of supported options */
|
||||
//TODO implement this list with last element being NULL so we don't need to keep count
|
||||
|
||||
/* Returns telnet option name based on the value. */
|
||||
static const char* telnet_option_name(int value) {
|
||||
int i;
|
||||
for (i = 0; i < TELNET_OPTIONS_COUNT; i ++)
|
||||
if (telnet_options[i].value == value)
|
||||
return telnet_options[i].name;
|
||||
int i = 0;
|
||||
while (telnet_options[i].name) {
|
||||
if (telnet_options[i].value == value) return telnet_options[i].name;
|
||||
i++;
|
||||
}
|
||||
return '\0';
|
||||
}
|
||||
|
||||
/* Returns telnet option value based on the name. */
|
||||
static char telnet_option_value(const char* name) {
|
||||
int i;
|
||||
for (i = 0; i < TELNET_OPTIONS_COUNT; i ++)
|
||||
if (!strcmp(telnet_options[i].name, name))
|
||||
return telnet_options[i].value;
|
||||
int i = 0;
|
||||
while (telnet_options[i].name) {
|
||||
if (!strcmp(telnet_options[i].name, name)) return telnet_options[i].value;
|
||||
i++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
4
tty.c
4
tty.c
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* Handling communication with tty device.
|
||||
*/
|
||||
|
||||
#include "moxerver.h"
|
||||
|
||||
#define TTY_THREAD_TIMEOUT_SEC 30
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue