/* **********************************************************************
 * *                                                                    *
 * *      Include Definitions for IRIS Network Receive process          *
 * *                                                                    *
 * **********************************************************************
 * File: iris/sserver/sserver.h
 *
 *                COPYRIGHT (c) 2001, 2002, 2003, 2005 BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
		

#define      PORT_INUSE        1
#define SERV_PORT_INUSE       (SERV_FACILITY + PORT_INUSE )
#define      REPLY_OVERFLOW    2
#define SERV_REPLY_OVERFLOW   (SERV_FACILITY + REPLY_OVERFLOW )
#define      REPLY_CLOSE       3
#define SERV_REPLY_CLOSE      (SERV_FACILITY + REPLY_CLOSE )


#ifndef MESSAGE_ONLY

#ifdef SSERVER_ALLOCATE
#define EXTERN
#else
#define EXTERN extern
#endif

#define COMMAND_DEPTH (6)

EXTERN struct out_legend_def *pOutLegend_c;
EXTERN char  sIrisMenu_c[PATHNAME_SIZE];	/* IRIS_MENU translation */
#ifdef SIGMET_PRODUCT_H
EXTERN volatile struct one_product_file *pInuseFile_c;
#endif  /* #ifdef SIGMET_PRODUCT_H */

/* Structure used to store client state for each client.  All slots with
 * a non-zero ClientNumber are active.  When a client is deactivated, the
 * ClientNumber is zeroed, and Defunct is set TRUE.  These slots are held
 * this way for 60 seconds, to allow any references to those slots to finish
 * handshaking.  After 60 seconds, the slot is freed up for use.  This
 * prevents having to lock semaphores on every received command.
 */
struct client_state
{
  UINT4 iClientNumber;  /* Client number, high bits are index, low random, zero:unused */
  UINT4 iLastBtime;         /* Time of the last communication from this client */
  struct ymds_time ConnectTime; /* Time connection was made */
  UINT1 lDefunct;           /* Client slot is defunct, cleared in 60 seconds */
  UINT1 iLogLevel;          /* logging level for this client */
  UINT1 ipad_end[2];
};

/* Contains all shared state */
struct server_state
{
  /* Set level of logging */
#define LOG_LEVEL_NONE (0)
#define LOG_LEVEL_LOW  (1)
#define LOG_LEVEL_HIGH (2)
  UINT1 iLoggingLevel;
  char  ipad_end[3];
  SINT4 iDiagnosticSpare;
  struct client_state Clients[1];  /* Actually the array is much longer */
};

EXTERN UINT1 lSserverExitHandler_c;
EXTERN volatile struct server_state *pServerState_c;
EXTERN SINT4 iServerStateSize_c;
EXTERN SINT4 iServerStateId_c;


struct append_text
{
  char *sText;
  int   iTextSize;
  int   iTextUsed;
};

/* Function prototypes in the network receiver. */

struct client_state *ClientFromNumber  /* File: site_cmds.C */
( UINT4 iClientNumber_a );

void netchild_exit_handler     /* File: network.c */
  ( void );

void net_tcpip                 /* File: net_tcpip.C */
  (const UINT4 iport,
   volatile struct process_info *pinfo_a
   );

int AppendText                 /* File: win_cmds.C */
( const char *sText_a,   // Text to append
  char **pString_a,      // Pointer to end of string 
  int *pRemainingLength_a );

int AppendText                 /* File: pom_cmds.C */
( const char *sText_a,   // Text to append
  struct append_text *pState_a );

void ListFillFilter            /* File: pom_cmds.C */
( struct server_filter *pFilter_a,
  char *sInData_a );

void ProcessClntCommand        /* File: clnt_cmds.C */
(int iSocket_a,
 char* sCmds_a[COMMAND_DEPTH-2],
 char* sData_a,
 struct client_state *pClient_a );

void ProcessIsmCommand         /* File: ism_cmds.C */
(int iSocket_a,
 char* sCmds_a[COMMAND_DEPTH],
 char* pdata_a );

void ProcessPomCommand         /* File: pom_cmds.C */
(int iSocket_a,
 char* sCmds_a[COMMAND_DEPTH],
 char* pdata_a );

void ProcessRstCommand         /* File: rst_cmds.C */
(int iSocket_a,
 char* sCmds_a[COMMAND_DEPTH],
 char* sData_a );

void ProcessSiteCommand        /* File: site_cmds.C */
(int iSocket_a,
 char* sCmds_a[COMMAND_DEPTH],
 char* sData_a );

void ProcessWinCommand         /* File: win_cmds.C */
(int iSocket_a,
 char* sCmds_a[COMMAND_DEPTH],
 char* pdata_a );

void ReplyToClientString       /* File: net_tcpip.C */
(int iSocket_a,
 const char *sData_a );

void ReplyToClientData1        /* File: net_tcpip.C */
(int iSocket_a,
 const char *sData_a,
 SINT4 iDataSize_a);

void ReplyToClientData2        /* File: net_tcpip.C */
(int iSocket_a,
 const char *sData1_a,
 SINT4 iData1Size_a,
 const char *sData2_a,
 SINT4 iData2Size_a);

#endif  /* #ifndef MESSAGE_ONLY */

