.ad 8
.bm 8
.fm 4
.bt $Copyright by   Software AG, 1993$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $NME$Project Distributed Database System$vos00xsc$
.tt 2 $$$
.tt 3 $R.Roedling$XSERVER include module$1997-03-27$
***********************************************************
.nf


    ========== licence begin LGPL
    Copyright (C) 2002 SAP AG

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    ========== licence end

.fo
.nf
.sp
Module  : XSERVER_include_module
=========
.sp
Purpose :
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :

.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :

.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :

.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : R.Roedling
.sp
.cp 3
Created : 1996-01-19
.sp
.cp 3
Version : 1996-01-19
.sp
.cp 3
Release :  6.2 	 Date : 1997-03-27
.br
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:

.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:

.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:

.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
/*PRETTY*/
//
// +---------------------------------------------------------------+
// |   DEFINES AND MACROS                                          |
// +---------------------------------------------------------------+
//
#define MSG1(x) {if(gxr.usDebugLevel>=1) sql60_msg_con_diag x;}
#define MSG2(x) {if(gxr.usDebugLevel>=2) sql60_msg_con_diag x;}
#define MSG3(x) {if(gxr.usDebugLevel>=3) sql60_msg_con_diag x;}
#define MSG4(x) {if(gxr.usDebugLevel>=4) sql60_msg_con_diag x;}
#define MSG5(x) {if(gxr.usDebugLevel>=5) sql60_msg_con_diag x;}
#define MSG6(x) {if(gxr.usDebugLevel>=6) sql60_msg_con_diag x;}
#define MSG7(x) {if(gxr.usDebugLevel>=7) sql60_msg_con_diag x;}
#define MSG8(x) {if(gxr.usDebugLevel>=8) sql60_msg_con_diag x;}
#define MSG9(x) {if(gxr.usDebugLevel>=9) sql60_msg_con_diag x;}

#define THRD_INITIALIZED                  1
#define THRD_RUNNING                      2
#define THRD_TERMINATED                   3
#define THRD_SLEEPING                     4
#define THRD_COMMAND_WAIT                 5
#define THRD_COMMAND_SEND                 6
#define THRD_DATA_RECEIVE                 7
#define THRD_DATA_SEND                    8
#define THRD_WAIT_FOR_ACKN                9
#define THRD_SEND_ACKN                    10

#define SERVER_STACK_SIZE                 8192
#define OLD_SERVER_STACK_SIZE             8192
#define TCPIP_COORD_STACK_SIZE            8192
#define REQUESTOR_STACK_SIZE              8192

#define XSERVER_INITIALIZE                1
#define XSERVER_STARTING                  2
#define XSERVER_RUNNING                   3
#define XSERVER_STOPPED                   4
#define XSERVER_ABORT                     5

#define READY_MESSAGE                "Ready"
#define READY_MESSAGE_LEN                 5


//
// --- exception handling
//
#if defined(_WIN32)
 #define  GUARD_EXCEPTION(_pExRec)                                            \
            try {

 #define  UNGUARD_EXCEPTION(_pExRec)                                          \
            } except(sql96c_winnt_excepthandler( GetExceptionInformation(),   \
                                                 _pExRec)){;}
#else
 #define  GUARD_EXCEPTION(_pExRec)
 #define  UNGUARD_EXCEPTION(_pExRec)
#endif


//
// +---------------------------------------------------------------+
// |   TYPEDEFS AND STRUCTS                                        |
// +---------------------------------------------------------------+
//

//
// +---------------------------------------------------------------+
// |   THREAD CONTROL HEADER                                       |
// +---------------------------------------------------------------+
//

// --- Header of the the thread control records

typedef struct thread_ctrl_header_record
  {
  TID                             Tid;
  HANDLE                          hThrd;
  LONG                            lThrdPrio;
  INT4                            ThrdState;
  ULONG                           ulStartTime;
  HANDLE                          hComm;
  HEV                             hevSem;
  } THREAD_CTRL_HEADER_REC;

//
// +---------------------------------------------------------------+
// |   OLD TCPIP COORDINATOR THREAD CONTROL                        |
// +---------------------------------------------------------------+
//

typedef struct old_tcpip_coord_ctrl_record
  {
  THREAD_CTRL_HEADER_REC          ThrdCtrlHeader;
  INT                             sd;
  USHORT                          usServicePort;
  ULONG                           ulMaxSegmentSize;
  PVOID                           pHandles;
  } OLD_TCPIP_COORD_CTRL_REC;

//
// +---------------------------------------------------------------+
// |   TCPIP COORDINATOR THREAD CONTROL                            |
// +---------------------------------------------------------------+
//

typedef struct tcpip_coord_ctrl_record
  {
  THREAD_CTRL_HEADER_REC          ThrdCtrlHeader;
  INT                             sd;
  USHORT                          usServicePort;
  ULONG                           ulMaxSegmentSize;
  PVOID                           pHandles;
  } TCPIP_COORD_CTRL_REC;

// +---------------------------------------------------------------+
// |   REQUESTOR THREAD CONTROL                                    |
// +---------------------------------------------------------------+
//

typedef struct requestor_ctrl_record
  {
  THREAD_CTRL_HEADER_REC          ThrdCtrlHeader;
  PVOID                           pHandles;
  } REQUESTOR_CTRL_REC;

//
// +---------------------------------------------------------------+
// |   TCPIP SERVER THREAD CONTROL                                 |
// +---------------------------------------------------------------+
//
typedef struct tcpip_serv_connect_info_record
  {
  THREAD_CTRL_HEADER_REC          ThrdCtrlHeader;

  ULONG                           ulConnInfoHandle;
  ULONG                           ulConnStatus;

  INT                             sd;
  SQL_NODEIDC                     szSenderNodeID;

  BOOL                            fAcknowledge;
  ULONG                           ulSwapType;
  ULONG                           ulMaxSegmentSize;
  ULONG                           ulServiceType;
  ULONG                           ulServerRef;
  ULONG                           ulSenderRef;
  SQL_DBNAMEC                     szServerDB;
  ULONG                           ulMaxCmdDataLen;
  PCOMM_PACKET_REC                pCommPacket;

  PSECURITY_ATTRIBUTES            pWorldSA;   // --- NT only
  PSECURITY_ATTRIBUTES            pLockSA;    // --- NT only

  SHM_CONNECT_INFO_REC            Shm;   // - vos33c, internal use only!
  } TCPIP_SERV_CONNECT_INFO_REC;

typedef TCPIP_SERV_CONNECT_INFO_REC *PTCPIP_SERV_CONNECT_INFO_REC;

//
// +---------------------------------------------------------------+
// |   OLD_TCPIP SERVER THREAD CONTROL                             |
// +---------------------------------------------------------------+
//
typedef struct old_tcpip_serv_connect_info_record
  {
  THREAD_CTRL_HEADER_REC          ThrdCtrlHeader;

  ULONG                           ulConnInfoHandle;
  ULONG                           ulConnStatus;

  INT                             sd;
  SQL_NODEIDC                     szSenderNodeID;

  ULONG                           ulSwapType;
  ULONG                           ulMaxSegmentSize;
  ULONG                           ulServerRef;
  ULONG                           ulSenderRef;
  SQL_DBNAMEC                     szServerDB;

  BOOL                            fNewPackets;
  PVOID                           pPacket;

  SHM_CONNECT_INFO_REC            Shm;    // - vos33c,  internal use only!
  OLD_SHM_INFO_REC                OldShm; // - vos33oc, internal use only!

  PSECURITY_ATTRIBUTES            pWorldSA;   // --- NT only
  PSECURITY_ATTRIBUTES            pLockSA;    // --- NT only

  } OLD_TCPIP_SERV_CONNECT_INFO_REC;

typedef OLD_TCPIP_SERV_CONNECT_INFO_REC *POLD_TCPIP_SERV_CONNECT_INFO_REC;

//
// +---------------------------------------------------------------+
// |   SERVER THREAD CONTROL                                       |
// +---------------------------------------------------------------+
//
typedef struct serv_connect_info_record
  {
  THREAD_CTRL_HEADER_REC          ThrdCtrlHeader;

  ULONG                           ulConnInfoHandle;
  ULONG                           ulConnStatus;
  BOOL                            fAcknowledge;

  HANDLE                          hCS;            // NT only
  struct comm_seg_header_record   *pCSHeader;
  HANDLE                          hPeerFCS;       // NT local distrib. only
  PFLAG_COMM_SEG                  pPeerFCS;       // local distrib. only
  HANDLE                          hClientProcess; // NT only
  HEV                             hevClientSem;

  PULONG                          pulPeerCommFlag;
  TCPIP_CONNECT_INFO_REC          TCPIP; // - vos23c, internal use only!
  } SERV_CONNECT_INFO_REC;

typedef SERV_CONNECT_INFO_REC *PSERV_CONNECT_INFO_REC;


//
// +---------------------------------------------------------------+
// |   GLOABAL XSERVER RECORD                                      |
// +---------------------------------------------------------------+
//
typedef struct global_xserver_record
  {
  BOOL                           fNTService;
  BOOL                           fServicePaused;
  BOOL                           fDebuggerIsDrWatson;
  USHORT                         usDebugLevel;
  BOOL                           fSuppressXserverActiveMsg;
  ULONG                          ulCrashRc;
  HEV                            hevSemXserv;
  PID                            pid;

  SECURITY_ATTRIBUTES            WorldSA;   // --- NT only
  SECURITY_ATTRIBUTES            LockSA;    // --- NT only
  SECURITY_ATTRIBUTES            AdminSA;   // --- NT only

  #if defined(_WIN32)
   SERVICE_STATUS_HANDLE         sshStatusHandle;
   SERVICE_STATUS                ssStatus;
   DWORD                         dwState;
  #endif

  TCPIP_COORD_CTRL_REC           TCPIPCoord;
  OLD_TCPIP_COORD_CTRL_REC       OldTCPIPCoord;
  REQUESTOR_CTRL_REC             Requestor;
  }  GLOBAL_XSERVER_REC;


// ========================== RTE internal PROTOTYPES =========================

#if defined(_WIN32)
 DWORD        sql96c_winnt_excepthandler( LPEXCEPTION_POINTERS lpExcPtrs,
                                          PEXCEPTION_REC       lpExcRec );
 VOID         sql96c_NewSrvState        ( DWORD                dwState,
                                          ULONG                ulExitCode );
#endif

VOID _System sql96t_TCPIP_coordinator   ( VOID );
VOID         sql96t_finish              ( VOID );
VOID _System sql96o_TCPIP_coordinator   ( VOID );
VOID         sql96o_finish              ( VOID );

ULONG   sql33o_connect     ( POLD_SHM_INFO_REC               pConnInfo,
                             ULONG                           ulApplicRef,
                             ULONG                           ulService,
                             PSZ                             pszServerDB,
                             PSECURITY_ATTRIBUTES            pWorldSA,
                             PSECURITY_ATTRIBUTES            pLockSA,
                             PULONG                          pulKernelRef,
                             PVOID                           *ppSQLPacket,
                             ERRORTEXT                       pErrText,
                             ULONG                           ulTimeOut );
ULONG  sql33o_request      ( POLD_SHM_INFO_REC               pConnInfo,
                             ERRORTEXT                       pErrText );
ULONG  sql33o_receive      ( POLD_SHM_INFO_REC               pConnInfo,
                             ERRORTEXT                       pErrText );
ULONG  sql33o_cancel       ( POLD_SHM_INFO_REC               pConnInfo,
                             ERRORTEXT                       pErrText );
ULONG  sql33o_release      ( POLD_SHM_INFO_REC               pConnInfo,
                             ERRORTEXT                       pErrText );
ULONG  sql42o_send_conpkt  ( INT                             sd,
                             ULONG                           ulMessClass,
                             ULONG                           ulMyRef,
                             ULONG                           ulPeerRef,
                             ULONG                           ulService,
                             ULONG                           ulMaxSegmentSize,
                             SQL_DBNAMEC                     szMyServerDB,
                             SQL_DBNAMEC                     szPeerServerDB,
                             USHORT                          usServicePort,
                             ULONG                           ulCommState,
                             ERRORTEXT                       pErrText );
ULONG  sql42o_recv_conpkt  ( INT                             sd,
                             PULONG                          pulMessClass,
                             PULONG                          pulMyRef,
                             PULONG                          pulPeerRef,
                             PULONG                          pulService,
                             PULONG                          pulMaxSegmentSize,
                             PULONG                          pulSwapType,
                             SQL_DBNAMEC                     szMyServerDB,
                             SQL_DBNAMEC                     szPeerServerDB,
                             PID                             *pPID,
                             PUSHORT                         pusServicePort,
                             ERRORTEXT                       pErrText );
ULONG  sql42o_send_packet  ( INT                             sd,
                             POLD_SQL_PACKET_REC             pSQLPacket,
                             ULONG                           ulMaxSegmentSize,
                             ULONG                           ulCommState,
                             ERRORTEXT                       pErrText );
ULONG  sql42o_recv_packet  ( INT                             sd,
                             POLD_SQL_PACKET_REC             pSQLPacket,
                             ULONG                           ulSwapType,
                             ULONG                           ulMaxSegmentSize,
                             ERRORTEXT                       pErrText );

ULONG  sql42c_get_dbroot (   PRTE_CONNECT_PACKET_REC         pConnectPacket,
                             PSZ                             szDBRoot );

ULONG  sql42c_get_serverpgm (PRTE_CONNECT_PACKET_REC         pConnectPacket,
                             PSZ                             szServerPgm );
                // these routines are declared here as vos00c has no
                // knowledge of PRTE_CONNECT_PACKET_REC

.CM *-END-* code ----------------------------------------
.SP 2
***********************************************************
