home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
dax1.exe
/
CP
/
CPS
/
CPCONN.C
next >
Wrap
Text File
|
1992-07-15
|
7KB
|
187 lines
// ╔════════════════════════════════════════════════════════════════════╗
// ║ ║
// ║ module: cpconn.c ║
// ║ abstract: This module contains the support APIs for handling ║
// ║ connection requests. It also houses the client ║
// ║ array and manipulation APIs. ║
// ║ ║
// ║ environment: NetWare 3.x v3.11 ║
// ║ Network C for NLMs SDK ║
// ║ CLib v3.11 ║
// ║ ║
// ║ This software is provided as is and carries no warranty ║
// ║ whatsoever. Novell disclaims and excludes any and all implied ║
// ║ warranties of merchantability, title and fitness for a particular ║
// ║ purpose. Novell does not warrant that the software will satisfy ║
// ║ your requirements or that the software is without defect or error ║
// ║ or that operation of the software will be uninterrupted. You are ║
// ║ using the software at your risk. The software is not a product ║
// ║ of Novell, Inc. or any of subsidiaries. ║
// ║ ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ maintenance history: ║
// ║ level date pi description ║
// ╟────────────────────────────────────────────────────────────────────╢
// ║ 001 02/05/92 kl initial release. ║
// ╚════════════════════════════════════════════════════════════════════╝
#include <string.h>
#include "cp/cpsys.h"
//------------------------------------------------------------------------
//
// __clients is the array that is used to maintain session data for the
// communication protocol layer of the application server.
//
STATIC CPDATA __clients[CPSDEFNUMCLNTS];
//
// This API returns a pointer to a given clients session data. It is
// used by the sending thread to get info needed to send the request.
//
CPDATA *CPGetClientInfo(LONG index)
{
if( index > CPSDEFNUMCLNTS ) return NULL;
if( __clients[index].sip != TRUE) return NULL;
return &__clients[index];
}
#define NOTFOUND -1
STATIC UINT32 CPAddressAlreadyInTable(InternetAddress *ipxaddr)
{
UINT32 i;
for(i=0; i < CPSDEFNUMCLNTS; ++i){
if( __clients[i].sip == TRUE ){
if( !memcmp(&__clients[i].ipxaddr,ipxaddr,sizeof *ipxaddr) ){
xDIAG4(CPprintf("Client %d re-sent allocate session\n",i));
return i;
}
}
}
return NOTFOUND;
}
STATIC UINT32 CPAllocateSlot()
{
UINT32 i;
for(i=0; i < CPSDEFNUMCLNTS; ++i){
if( __clients[i].sip == FALSE ){
__clients[i].sip = TRUE;
return i;
}
}
DIAG3("CPAllocateSlot() failed because table is full");
return -1;
}
STATIC T_RC CPDeAllocateSlot(UINT32 slot)
{
if( __clients[slot].sip == TRUE ){
__clients[slot].sip = FALSE;
}
else{
DIAG3("CPDeAllocateSlot() passed slot id which was not in use");
}
return CP_SUCCESS;
}
T_RC CPClearSessionID(UINT32 sessionID)
{
return CPDeAllocateSlot(sessionID);
}
//
// This API locates the session ID for a given client. It is called
// by the receive message thread, to determine which client has sent
// the request. This API will allocate a new session ID if the client
// is not found in the array.
//
UINT32 CPGetSessionID(IPX_HEADER *IPXhdr, CPMESSAGE *CPmsg)
{
CPDATA *cpd;
UINT32 serverID = CPmsg->cphdr.serverID - 1;
//
// Do authentication of signature in packet. If not valid,
// print a message and ignore this request.
//
if(CPmsg->cphdr.signature != CPPKTSIG ){
HEXDIAG1("Invalid CP packet signature on request", CPmsg);
return -1;
}
if( (cpd = CPGetClientInfo(serverID)) != NULL ){
//
// Get here if the index in the CP header is valid and
// there is a session in progress there.
//
if( !memcmp(&__clients[serverID].ipxaddr,&IPXhdr->sourceNet,sizeof(InternetAddress)) ){
//!!
// Enhance by acknowledging the duplicate underneath
//!!
//
// Get here if it came from the same address that we have
// registered in the client array
//
return serverID;
}
HEXDIAG1("Client authentication failed for session ",serverID);
}
//
// See if client is already registered on a different session ID.
// This can occur if client resends an AllocateSession DAP, since
// the serverID will still be zero.
//
//!!
// This will still be a problem if the client reboots, or tries
// a different socket number.
//
// Need to implement some sort of WATCHDOG on the engine, to
// detect these failed connections.
//!!
switch( serverID = CPAddressAlreadyInTable((InternetAddress *)&IPXhdr->sourceNet) ){
case NOTFOUND:
if( (serverID = CPAllocateSlot()) == -1 ) return -1;
break;
default:
//
// We found his serverID.
//
xDIAG4(CPprintf("Returning with serverID = %d\r\n",serverID));
return serverID;
break;
}
xDIAG4(CPprintf("Falling thru with serverID = %d\r\n",serverID));
//
// Save what we need to for communication with this client.
// We need the internet address, and put the index in there
// so he can use it on subsequent calls. Remember, the 'cphdr'
// element will be copied into the reply packet on the way out.
//
if( (cpd = CPGetClientInfo(serverID)) == NULL){
DIAG1("cpd is NULL, and it shouldn't be!\n");
return -1;
}
cpd->cphdr = CPmsg->cphdr; // xfer client header
cpd->ipxaddr = *(InternetAddress *)&IPXhdr->sourceNet;
cpd->cphdr.serverID = serverID + 1;
return serverID;
}
//------------------------------------------------------------------------
// Here are the APIs to init and deinit the connection logic
//
//
T_RC CPInitializeConnLogic(){ return 0;}
T_RC CPDeInitializeConnLogic(){return 0;}