
The telnet server task creation , global , connection, sessions and application stats initialization will all be done at the initialization
time . After the initialization, telnet server will be listening to the telnet client connections.
example1.c , the telnet example application will communicate with the telnet clients through telnet library using telnet API . The
Telnet server invokes the function in telnetdata.c which in turn calls functions in example1.c . example1.c , maintains a database of
all the clients. The database is an array of structures. The structure is telApp_connstats and the global array variable is telAppstats .
Both of these are in example1.c. The maximum number of clients is based on a #define MAX_TELNET_SESS which is in
telnetdata.h
The Telnet server maintains a similar database on the heap. This is allocated at the initialization time. The maximum number of
clients for this is based on a variable, max_telnet_conn which is initialized to MAX_TELNET_SESS. This variable is in telnetdata.c. If
the application developer wants to change this value, that can be done by modifying the value MAX_TELNET_SESS which will get
assigned to the variable, max_telnet_conn.
Whenever a user telnets to the server , say for example types in telnet <ip address of iniche server> at the command prompt, telnet
server will allocate memory for the connection on the heap and give a connection id for the connection if there are no max telnet
connections already. The check will be by comparing the number of existing connections to max_telnet_conn . It then displays a
welcome banner and login prompt.
Once the user types in username and password , telnet server will invoke the function validate_telUser() in telnetdata.c. This
function has an option to check if the client ip address is valid by calling function check_telipAddr() in example1.c and then this
function will validate the typed in username and password. If the valid username and password are not typed in, then the user will
be allowed to try for the number of times based on the value in telnet_max_tries, a variable in telnetdata.c. If the login attempts,
exceed that limit then, the user will have to telnet again. Once the valid username and valid password are entered by the user,
callback functions will be registered by calling telApp_callbcks_reg() in example1.c. This telApp_callbcks_reg () function will register
two callback functions telApp_connsts() and telApp_errRecv(). Both these functions are in example1.c. While registering the
callback functions, telApp_callbcks_reg(), will use an API function tel_callbckfn_reg() from the library. Its prototype is in telnetdata.h.
When the validate_telUser() function returns success, telnet server will invoke the callback function, telApp_connsts() with
connection status as SESS_OPENED. This SESS_OPENED #define is in telnetdata.h. If the call to telApp_connsts() function is
success, telnet server will present a "Welcome <username>" message to the client.
When the connection state is SESS_OPENED, telApp_connsts() will:
1. Assign an entry to the connection in the telAppstats table if max connections are not present already by assigning
conn_state, conn_ID,username and context to the private memory of the entry. These conn_ID, conn_state, username and
private are all the members of the structure telApp_connstats in example1.c. Connection context will be assigned to the
private member by calling the API function , get_context(), whose prototype is in telnetdata.h.
2. Invoke init_telconn() , an API function for generic I/O stream operations, whose prototype is in telnetdata.h .
3. Display the cli_prompt at the client window. To display the cli_prompt onto the client it uses the API function call,
tel_send(),whose prototype is in telnetdata.h.
Now the application, example1.c will be ready to accept commands from the telnet client. When the user enters carriage return /
characters followed by carriage return, telnet server will collect the characters and invoke the same function telApp_connsts() in
example1.c but with SESS_HAS_DATA status. This SESS_HAS_DATA #define is in telnetdata.h.
When the connection state is SESS_HAS_DATA, telApp_connsts() will:
1. Invoke tel_readbuf(), an API function to copy the contents of the telnet session's command buf contents to the applications
connection buffer, member char buffer[] in the structure , telApp_connstats. Prototype for tel_readbuf() is in telnetdata.h.