#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <termios.h>
#include <fcntl.h>
#include <ctype.h>
Go to the source code of this file.
Data Structures | |
struct | server |
ISIS server application runtime system table. More... | |
struct | clients |
ISIS server client table. More... | |
struct | serial |
ISIS server serial port table. More... | |
struct | udpPreset |
ISIS preset UDP socket port table. More... | |
Defines | |
#define | ISIS_VERSION "0.0" |
Version number placeholder. | |
#define | ISIS_COMPDATE "0000-00-00" |
Compilation date placeholder. | |
#define | ISIS_COMPTIME "00:00:00" |
Compilation time placeholder. | |
#define | ISIS_CONFIG "/lhome/dts/Config/isis.ini" |
ISIS config. | |
#define | ISIS_DCONFIG "/lhome/dts/Config/isisd.ini" |
isisd daemon config file | |
#define | ISIS_LOGS "/lhome/Logs/ISIS/isis.log" |
ISIS runtime log. | |
#define | DEFAULT_LOCALHOST "IS" |
Default ISIS server host ID. | |
#define | DEFAULT_ISISPORT 0 |
default ISIS server port number | |
#define | POSIX |
#define | ISIS_MSGSIZE 4096 |
ISIS maximum message size. | |
#define | IMPv2_HOST_SIZE 9 |
maximum size of IMPv2 host names 8+1 | |
#define | LONG_STR_SIZE 4096 |
size of generic a long string | |
#define | MED_STR_SIZE 256 |
size of generic a medium-sized string | |
#define | BIG_STR_SIZE 2048 |
size of generic a big string | |
#define | SHORT_STR_SIZE 32 |
size of generic a short string | |
#define | isis_TRUE 1 |
condition is TRUE value | |
#define | isis_FALSE 0 |
condition is FALSE value | |
#define | NUL '\0' |
convenience definition for null string | |
#define | ISIS_SERVER 777 |
host table index for the server ("us") | |
#define | BROADCAST 666 |
host table index for broadcast (host AL) | |
#define | MSG_NOOP 0 |
No reply or forwarding required. | |
#define | MSG_REPLY 1 |
Send a reply back to the sender. | |
#define | MSG_FORWARD 2 |
Forward message to the destination. | |
#define | MSG_ECHO 3 |
Echo the message unprocessed. | |
#define | ERR_UNKNOWN_HOST -1 |
Recipient is an unknown host. | |
#define | ERR_UNKNOWN_FD -2 |
File descriptor is unknown to the host table. | |
#define | ERR_HOSTS_FULL -3 |
Server's client host table is full. | |
#define | NO_STARTUP 0 |
no startup tasks required | |
#define | COLD_START 1 |
cold startup | |
#define | WARM_START 2 |
warm startup | |
#define | UTCDATE 0 |
Logs use the UTC date. | |
#define | OBSDAY 1 |
Logs use the noon-to-noon local date [Default]. | |
#define | MAXCLIENTS 32 |
Maximum number of client hosts. | |
#define | UNASSIGNED 0 |
No transport method assigned to client. | |
#define | SERIAL 1 |
Client uses a serial port. | |
#define | SOCKET 2 |
Client uses a UDP network socket. | |
#define | MAXSERIAL 8 |
maximum number of serial port connections | |
#define | MAXPRESET 8 |
Maximum number of preset UDP ports. | |
Functions | |
int | openSocket (int) |
Open and setup the ISIS server UDP network socket. | |
void | closeSocket (int) |
Close the ISIS server socket. | |
int | loadConfig (char *) |
Load/parse the server runtime configuration file. | |
void | handShake (void) |
Handshake with the clients on serial ports and preset UDP ports. | |
void | initHostTable () |
Initialize the server client host table. | |
int | updateHosts (char *, int, int, long, int) |
Update the client host table with client info. | |
int | removeHost (char *) |
Remove an entry from the client host table. | |
int | isKnownHost (char *) |
Verify that client is a known host (i.e., in the client table). | |
void | printHosts (char *) |
Prints the server's client host table on stdout. | |
void | hostInfo (char *, char *) |
Report host information to a remote client. | |
int | initSerialPorts (void) |
Initialize the serial ports listed in the server's serial port table. | |
int | getSerialInfo (int) |
Map a serial port file descriptor onto a serial port table index. | |
void | portInfo (char *) |
Create a string with the server's serial port table info. | |
void | ttyHandler (char *line) |
Handle input from the command line (readline callback function). | |
void | socketHandler (int) |
Handle input from a network client socket. | |
void | serialHandler (int) |
Handle input from server serial ports. | |
void | sendMessage (int, char *) |
Send a message string to a client. | |
void | handleMessage (int, int, char *) |
Handle messages received by the ISIS server. | |
void | broadcastMessage (int, char *) |
Broadcast a message to all clients. | |
int | isisCommand (char *, char *) |
Process an ISIS server command. | |
int | serverInfo (char *) |
Report consise server status as an IMPv2-compliant message. | |
void | printInfo (void) |
Report detailed server info on server console (stdout). | |
void | printHelp (void) |
Print a quick summary of ISIS server commands to the console. | |
void | initLog (void) |
Initialize the ISIS server runtime log for this session. | |
int | logMessage (char *) |
Append an entry to the server's runtime log with date/time tagging. | |
void | getUTCTime (void) |
Read the UTC time from the system clock. | |
char * | getFineTime (void) |
Return the UTC time to microsecond precision. | |
char * | getDateTime (void) |
Return the UTC date and time to microsecond precision as a system timestamp. | |
double | sysTimeStamp (void) |
Return the elapsed time in sec since UTC 1970-01-01 with microsec precision. | |
char * | noonDateTag (void) |
Local noon-to-noon date tag in CCYYMMDD format. | |
void | getArg (char *, int, char *) |
Extract an argument from the command line. | |
void | upperCase (char *) |
Convert a string to all uppercase. | |
Variables | |
server | isis |
ISIS server application runtime system table. | |
clients | clientTab [MAXCLIENTS] |
ISIS server client table. | |
serial | ttyTab [MAXSERIAL] |
ISIS server serial port table. | |
udpPreset | udpTab [MAXPRESET] |
ISIS preset UDP socket port table. |
|
Version number placeholder.
|
|
Compilation date placeholder.
|
|
Compilation time placeholder.
|
|
ISIS config.
|
|
isisd daemon config file
|
|
ISIS runtime log.
|
|
Default ISIS server host ID.
|
|
default ISIS server port number
|
|
|
|
ISIS maximum message size.
|
|
maximum size of IMPv2 host names 8+1
|
|
size of generic a long string
|
|
size of generic a medium-sized string
|
|
size of generic a big string
|
|
size of generic a short string
|
|
condition is TRUE value
|
|
condition is FALSE value
|
|
convenience definition for null string
|
|
host table index for the server ("us")
|
|
host table index for broadcast (host AL)
|
|
No reply or forwarding required.
|
|
Send a reply back to the sender.
|
|
Forward message to the destination.
|
|
Echo the message unprocessed.
|
|
Recipient is an unknown host.
|
|
File descriptor is unknown to the host table.
|
|
Server's client host table is full.
|
|
no startup tasks required
|
|
cold startup
|
|
warm startup
|
|
Logs use the UTC date.
|
|
Logs use the noon-to-noon local date [Default].
|
|
Maximum number of client hosts.
|
|
No transport method assigned to client.
|
|
Client uses a serial port.
|
|
Client uses a UDP network socket.
|
|
maximum number of serial port connections
|
|
Maximum number of preset UDP ports.
|
|
Open and setup the ISIS server UDP network socket.
Errors are reported to stdout by this routine.
|
|
Close the ISIS server socket.
|
|
Load/parse the server runtime configuration file.
The parameters in the runtime config file take the form of keyword/value pairs. Comments are denoted by a # and skipped by the parser. Blank lines are also ignored. Unrecognized configuration parameters are ignored except to print a warning message for debugging purposes. |
|
Handshake with the clients on serial ports and preset UDP ports. Sends a ">AL PING" message to all open serial ports and all preset UDP ports. This is a blind broadcast that should lead to "PONG"s back from any ISIS clients on the serial lines or connected to the UDP socket ports. This is a placeholder that gives us minimal IMPv2 software handshaking until we can work with the system some and work out better procedures. All strings transmitted to raw ports must be in proper IMPv2-conformal format, terminated by \r (ASCII 13). |
|
Initialize the server client host table. Initializes the contents of the ISIS client table, clearing all host entries. Must be called before filling the client table either at server startup or restart. |
|
Update the client host table with client info.
See isKnownHost() for how to test to see if a recipient is known to the system. |
|
Remove an entry from the client host table.
Since the number of allowed clients is expected to remain a small number, repacking the table to remove gaps does not offer any economies at present, but someday if it is decided it is necessary, the repacking should go in this routine. |
|
Verify that client is a known host (i.e., in the client table).
|
|
Prints the server's client host table on stdout.
For output tailored for sending back to remote clients (i.e., output as an IMPv2-conformal message string), see hostInfo(). |
|
Report host information to a remote client.
For detailed output tailored for the server's command console window (i.e., printing on stdout), see printHosts(). |
|
Initialize the serial ports listed in the server's serial port table.
|
|
Map a serial port file descriptor onto a serial port table index.
testFD in the server's active serial port table, and returns the index of the port table entry if found. The serial port table is the ttyTab struct defined in the isisserver.h header file. |
|
Create a string with the server's serial port table info.
|
|
Handle input from the command line (readline callback function).
rl_callback_hander_install() function of the readline library.Once we get an error-free string we can use, we then try to interpret it. This is the main cli handler for the server. When generating IMPv2 messages for direct transmission onto the system, the strings must be terminated with return (\r = ASCII 13) not a newline (\n = ASCII 10). |
|
Handle input from a network client socket.
If the source and destination are valid, and the message is not blank or malformed, it then passes control off to handleMessage() to do the dirty work. This may permit us to enable multithreading in the future. When generating IMPv2-compliant messages, the strings must be terminated with return (\r = ASCII 13) not a newline (\n = ASCII 10). This function is designed to be invoked by a select() loop that watches particular file descriptors. See main.c for how it is implemented. |
|
Handle input from server serial ports.
If the source and destination are valid, and the message is not blank or malformed, it then passes the message off to HandleMessage() to route the message to its intended recipient. When generating IMPv2 messages for direct transmission through the server, the strings must be terminated with return (\r = ASCII 13) not a newline (\n = ASCII 10). This function is designed to be invoked by a select() loop that watches particular file descriptors. See main.c for how it is implemented. |
|
Send a message string to a client.
XX>YY message_text\r The message must be properly terminated with \r (ASCII 13) as per the IMPv2 message format specification. Designed to be lightweight and thread safe. All routines called by this (and the routine itself) must not alter global variables. this means that logging is the responsibility of calling programs upstream. |
|
Handle messages received by the ISIS server.
IMPv2 messages are terminated with return (\r = ASCII 13), not with a newline (\n = ASCII 10). Messages prepared for further routing by sendMessage() must be correctly terminated. Those printed to stdout do not require termination, as the printing routine will strip any termination and provide a \r as required. BEWARE: No terminination checking is done by sendMessage()! |
|
Broadcast a message to all clients.
XX>AL message_text\r
This is a key distinction: broadcasts are blind-sent to ports not hosts. We have to be careful not to echo a broadcast back to the sender, which risks starting infinite regressions. Designed to be lightweight and thread safe. All routines called by this (and the routine itself) must not alter global variables. this means that logging is the responsibility of calling programs upstream. |
|
Process an ISIS server command.
|
|
Report consise server status as an IMPv2-compliant message.
|
|
Report detailed server info on server console (stdout). printInfo() makes a detailed, formatted report of the current server status on stdout. For generic, concise info services, see serverInfo(). |
|
Print a quick summary of ISIS server commands to the console. Prints the current command list to the console intended as an aide-memoire, not a proper help utility. Don't expect much from it (besides, the command set is SMALL, that's the idea). |
|
Initialize the ISIS server runtime log for this session. Opens the server's runtime log. Log entries are created by the logMessage() function. |
|
Append an entry to the server's runtime log with date/time tagging.
If the date tag has changed, start a new logfile for a new observing day. Returns 0 if the logging has been disabled, making it look the same as if the log had been updated. |
|
Read the UTC time from the system clock. Reads the system's UTC time clock and puts date/time information into the system table. Time info is stored as follows:
|
|
Return the UTC time to microsecond precision.
Reads the system's UTC time clock and returns a pointer to a string with the fine-grained UTC time in Based on gf_time() from Stevens, W.R., 1998, Unix Network Programming, Vol 2, Prentice Hall, Figure 15.6, but I make a string, and restrict the output of seconds to msec rather than usec. Of course, it may return microsecond precision, microsecond accuracy is quite another thing... |
|
Return the UTC date and time to microsecond precision as a system timestamp.
Reads the system's UTC time clock and returns a pointer to a string with the fine-grained UTC time in Based on gf_time() from Stevens, W.R., 1998, Unix Network Programming, Vol 2, Prentice Hall, Figure 15.6, but I make a string, and restrict the output of seconds to msec rather than usec. Of course, it may return microsecond precision, microsecond accuracy is quite another thing... |
|
Return the elapsed time in sec since UTC 1970-01-01 with microsec precision. Reads the system's time clock and returns a double-precision value with the time in seconds and microseconds since UTC 1970-01-01. This provides us with a fine-grained numerical timestamp for the system. Of course, it may return microsecond precision, microsecond accuracy is quite another thing. The relative time should be as stable as PC system clocks ever are. |
|
Local noon-to-noon date tag in CCYYMMDD format. Convenience function for creating noon-to-noon date tags in the local time zone. If the time is after noon, it uses the current local date. If before noon, it uses *yesterday's* local date. This convention is used for "observing day", to avoid the problem with UTC that afternoon calibrations end up in the previous night's logs, or with using local midnight where logs of a night's observing are divided between two "civil day" logs. |
|
Extract an argument from the command line.
Returns a null (\0) in regarg if the argnum-th argument doesn't exist. If any stray nulls are found in the string, it replaces them with spaces. |
|
Convert a string to all uppercase.
|
|
ISIS server application runtime system table. Contains the runtime parameters of the ISIS server application. |
|
ISIS server client table. Contains the parameters of known ISIS clients. ISIS clients are added to the client table every time they pass messages through the server. This allows clients to come and go dynamically. The maximum number of allowed clients is MAXCLIENTS. |
|
ISIS server serial port table. Contains the parameters of serial ports opened by the ISIS server. The maximum number of allowed ports opened at startup is MAXSERIAL. |
|
ISIS preset UDP socket port table. Contains the parameters of up to MAXPRESET preset UDP socket hosts and ports. Preset UDP ports are pinged on startup and restart to re-establish connections on server restart with active clients. |