mirror of
https://github.com/sheumann/AFPBridge.git
synced 2024-06-10 21:29:30 +00:00
Updates to support opening and closing a session.
This commit is contained in:
parent
b5c3a29f37
commit
0b0a422c33
|
@ -15,7 +15,6 @@ void DoSPOpenSession(Session *sess, ASPOpenSessionRec *commandRec);
|
||||||
void DoSPCloseSession(Session *sess, ASPCloseSessionRec *commandRec);
|
void DoSPCloseSession(Session *sess, ASPCloseSessionRec *commandRec);
|
||||||
void DoSPCommand(Session *sess, ASPCommandRec *commandRec);
|
void DoSPCommand(Session *sess, ASPCommandRec *commandRec);
|
||||||
void DoSPWrite(Session *sess, ASPWriteRec *commandRec);
|
void DoSPWrite(Session *sess, ASPWriteRec *commandRec);
|
||||||
void CompleteCommand(Session *sess);
|
|
||||||
|
|
||||||
|
|
||||||
Session sessionTbl[MAX_SESSIONS];
|
Session sessionTbl[MAX_SESSIONS];
|
||||||
|
@ -59,12 +58,12 @@ void DispatchASPCommand(SPCommandRec *commandRec) {
|
||||||
// TODO properly handle all cases of getting a command while
|
// TODO properly handle all cases of getting a command while
|
||||||
// one is in progress
|
// one is in progress
|
||||||
if (commandRec->command != aspCloseSessionCommand) {
|
if (commandRec->command != aspCloseSessionCommand) {
|
||||||
if (sess->commandStatus != noCommand) {
|
if (sess->commandPending) {
|
||||||
commandRec->result = aspSessNumErr;
|
commandRec->result = aspSessNumErr;
|
||||||
CompleteCommand(sess);
|
CompleteCommand(sess);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sess->commandStatus = commandPending;
|
sess->commandPending = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (commandRec->command) {
|
switch (commandRec->command) {
|
||||||
|
@ -85,19 +84,19 @@ void DispatchASPCommand(SPCommandRec *commandRec) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandRec->async & AT_ASYNC) {
|
if ((commandRec->async & AT_ASYNC) && sess->commandPending) {
|
||||||
if (sess->commandStatus == commandDone) {
|
commandRec->result = aspBusyErr; // indicate call in process
|
||||||
CompleteCommand(sess);
|
|
||||||
} else {
|
|
||||||
commandRec->result = aspBusyErr; // indicate call in process
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're here, the call is synchronous -- we must complete it
|
// if we're here, the call is synchronous -- we must complete it
|
||||||
|
|
||||||
while (sess->commandStatus != commandDone) {
|
if (commandRec->command == aspCloseSessionCommand) {
|
||||||
PollForData(sess);
|
FinishASPCommand(sess);
|
||||||
|
} else {
|
||||||
|
while (sess->commandPending) {
|
||||||
|
PollForData(sess);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,11 +113,27 @@ void DoSPGetStatus(Session *sess, ASPGetStatusRec *commandRec) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoSPOpenSession(Session *sess, ASPOpenSessionRec *commandRec) {
|
void DoSPOpenSession(Session *sess, ASPOpenSessionRec *commandRec) {
|
||||||
// TODO
|
sess->request.flags = DSI_REQUEST;
|
||||||
|
sess->request.command = DSIOpenSession;
|
||||||
|
sess->request.requestID = htons(sess->nextRequestID++);
|
||||||
|
sess->request.writeOffset = 0;
|
||||||
|
sess->request.totalDataLength = 0;
|
||||||
|
sess->replyBuf = NULL;
|
||||||
|
sess->replyBufLen = 0;
|
||||||
|
|
||||||
|
SendDSIMessage(sess, &sess->request, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoSPCloseSession(Session *sess, ASPCloseSessionRec *commandRec) {
|
void DoSPCloseSession(Session *sess, ASPCloseSessionRec *commandRec) {
|
||||||
// TODO
|
sess->request.flags = DSI_REQUEST;
|
||||||
|
sess->request.command = DSICloseSession;
|
||||||
|
sess->request.requestID = htons(sess->nextRequestID++);
|
||||||
|
sess->request.writeOffset = 0;
|
||||||
|
sess->request.totalDataLength = 0;
|
||||||
|
sess->replyBuf = NULL;
|
||||||
|
sess->replyBufLen = 0;
|
||||||
|
|
||||||
|
SendDSIMessage(sess, &sess->request, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoSPCommand(Session *sess, ASPCommandRec *commandRec) {
|
void DoSPCommand(Session *sess, ASPCommandRec *commandRec) {
|
||||||
|
@ -146,11 +161,10 @@ void FinishASPCommand(Session *sess) {
|
||||||
((ASPGetStatusRec*)(sess->spCommandRec))->dataLength = dataLength;
|
((ASPGetStatusRec*)(sess->spCommandRec))->dataLength = dataLength;
|
||||||
break;
|
break;
|
||||||
case aspOpenSessionCommand:
|
case aspOpenSessionCommand:
|
||||||
// TODO set session ref num
|
((ASPOpenSessionRec*)(sess->spCommandRec))->refNum =
|
||||||
|
(sess - &sessionTbl[0]) + SESSION_NUM_START;
|
||||||
break;
|
break;
|
||||||
case aspCloseSessionCommand:
|
case aspCloseSessionCommand:
|
||||||
((ASPCloseSessionRec*)(sess->spCommandRec))->refNum =
|
|
||||||
(sess - &sessionTbl[0]) + SESSION_NUM_START;
|
|
||||||
break;
|
break;
|
||||||
case aspCommandCommand:
|
case aspCommandCommand:
|
||||||
((ASPCommandRec*)(sess->spCommandRec))->cmdResult =
|
((ASPCommandRec*)(sess->spCommandRec))->cmdResult =
|
||||||
|
@ -175,5 +189,11 @@ void CompleteCommand(Session *sess) {
|
||||||
|
|
||||||
// TODO call completion routine
|
// TODO call completion routine
|
||||||
|
|
||||||
memset(sess, 0, sizeof(*sess));
|
if (sess->spCommandRec->command == aspGetStatusCommand
|
||||||
|
|| sess->spCommandRec->command == aspCloseSessionCommand)
|
||||||
|
{
|
||||||
|
memset(sess, 0, sizeof(*sess));
|
||||||
|
} else {
|
||||||
|
sess->commandPending = FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
extern Session sessionTbl[MAX_SESSIONS];
|
extern Session sessionTbl[MAX_SESSIONS];
|
||||||
|
|
||||||
void FinishASPCommand(Session *sess);
|
|
||||||
void DispatchASPCommand(SPCommandRec *commandRec);
|
void DispatchASPCommand(SPCommandRec *commandRec);
|
||||||
|
void FinishASPCommand(Session *sess);
|
||||||
|
void CompleteCommand(Session *sess);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
dsi.c
14
dsi.c
|
@ -33,17 +33,14 @@ static DSIRequestHeader attentionReplyRec = {
|
||||||
void FlagFatalError(Session *sess, Word errorCode) {
|
void FlagFatalError(Session *sess, Word errorCode) {
|
||||||
sess->dsiStatus = error;
|
sess->dsiStatus = error;
|
||||||
if (errorCode) {
|
if (errorCode) {
|
||||||
if (sess->commandStatus == commandPending) {
|
if (sess->commandPending) {
|
||||||
sess->spCommandRec->result = errorCode;
|
sess->spCommandRec->result = errorCode;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO deduce error code from Marinetti errors
|
// TODO deduce error code from Marinetti errors
|
||||||
}
|
}
|
||||||
// TODO close TCP connection, anything else?
|
|
||||||
|
CompleteCommand(sess);
|
||||||
// call completion routing if needed
|
|
||||||
|
|
||||||
sess->commandStatus = commandDone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +91,7 @@ top:
|
||||||
if (sess->reply.totalDataLength != 0) {
|
if (sess->reply.totalDataLength != 0) {
|
||||||
dataLength = ntohl(sess->reply.totalDataLength);
|
dataLength = ntohl(sess->reply.totalDataLength);
|
||||||
|
|
||||||
if (sess->commandStatus == commandPending
|
if (sess->commandPending
|
||||||
&& sess->reply.flags == DSI_REPLY
|
&& sess->reply.flags == DSI_REPLY
|
||||||
&& sess->reply.requestID == sess->request.requestID
|
&& sess->reply.requestID == sess->request.requestID
|
||||||
&& sess->reply.command == sess->request.command)
|
&& sess->reply.command == sess->request.command)
|
||||||
|
@ -135,7 +132,7 @@ top:
|
||||||
// If we're here, we got a full message.
|
// If we're here, we got a full message.
|
||||||
|
|
||||||
// Handle a command that is now done, if any.
|
// Handle a command that is now done, if any.
|
||||||
if (sess->commandStatus == commandPending
|
if (sess->commandPending
|
||||||
&& sess->reply.flags == DSI_REPLY
|
&& sess->reply.flags == DSI_REPLY
|
||||||
&& sess->reply.requestID == sess->request.requestID
|
&& sess->reply.requestID == sess->request.requestID
|
||||||
&& sess->reply.command == sess->request.command)
|
&& sess->reply.command == sess->request.command)
|
||||||
|
@ -154,7 +151,6 @@ top:
|
||||||
|
|
||||||
// TODO correct logic for all cases
|
// TODO correct logic for all cases
|
||||||
FinishASPCommand(sess);
|
FinishASPCommand(sess);
|
||||||
sess->commandStatus = commandDone;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//Handle a request from the server
|
//Handle a request from the server
|
||||||
|
|
54
dsitest.c
54
dsitest.c
|
@ -6,7 +6,9 @@
|
||||||
#include "aspinterface.h"
|
#include "aspinterface.h"
|
||||||
#include "atipmapping.h"
|
#include "atipmapping.h"
|
||||||
|
|
||||||
ASPGetStatusRec commandRec;
|
ASPGetStatusRec getStatusRec;
|
||||||
|
ASPOpenSessionRec openSessionRec;
|
||||||
|
ASPCloseSessionRec closeSessionRec;
|
||||||
Byte replyBuffer[1024];
|
Byte replyBuffer[1024];
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -37,30 +39,56 @@ int main(int argc, char **argv)
|
||||||
atipMapping.port = 548;
|
atipMapping.port = 548;
|
||||||
|
|
||||||
// Do the call
|
// Do the call
|
||||||
commandRec.async = AT_SYNC;
|
getStatusRec.async = AT_SYNC;
|
||||||
commandRec.command = aspGetStatusCommand;
|
getStatusRec.command = aspGetStatusCommand;
|
||||||
commandRec.completionPtr = 0;
|
getStatusRec.completionPtr = 0;
|
||||||
commandRec.slsNet = atipMapping.networkNumber;
|
getStatusRec.slsNet = atipMapping.networkNumber;
|
||||||
commandRec.slsNode = atipMapping.node;
|
getStatusRec.slsNode = atipMapping.node;
|
||||||
commandRec.slsSocket = atipMapping.socket;
|
getStatusRec.slsSocket = atipMapping.socket;
|
||||||
commandRec.bufferLength = sizeof(replyBuffer);
|
getStatusRec.bufferLength = sizeof(replyBuffer);
|
||||||
commandRec.bufferAddr = (LongWord)&replyBuffer;
|
getStatusRec.bufferAddr = (LongWord)&replyBuffer;
|
||||||
|
|
||||||
DispatchASPCommand((SPCommandRec *)&commandRec);
|
DispatchASPCommand((SPCommandRec *)&getStatusRec);
|
||||||
|
|
||||||
for (i=0; i<commandRec.dataLength;i++) {
|
#if 0
|
||||||
|
for (i=0; i<getStatusRec.dataLength;i++) {
|
||||||
printf("%02x ", replyBuffer[i]);
|
printf("%02x ", replyBuffer[i]);
|
||||||
if ((i+1)%16 == 0) printf("\n");
|
if ((i+1)%16 == 0) printf("\n");
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
for (i=0; i<commandRec.dataLength;i++) {
|
#endif
|
||||||
|
for (i=0; i<getStatusRec.dataLength;i++) {
|
||||||
if (replyBuffer[i] >= ' ' && replyBuffer[i] <= 126)
|
if (replyBuffer[i] >= ' ' && replyBuffer[i] <= 126)
|
||||||
printf("%c", replyBuffer[i]);
|
printf("%c", replyBuffer[i]);
|
||||||
else
|
else
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
openSessionRec.async = AT_SYNC;
|
||||||
|
openSessionRec.command = aspOpenSessionCommand;
|
||||||
|
openSessionRec.completionPtr = 0;
|
||||||
|
openSessionRec.slsNet = atipMapping.networkNumber;
|
||||||
|
openSessionRec.slsNode = atipMapping.node;
|
||||||
|
openSessionRec.slsSocket = atipMapping.socket;
|
||||||
|
openSessionRec.attnRtnAddr = NULL; // not used for now
|
||||||
|
|
||||||
|
printf("Opening...\n");
|
||||||
|
DispatchASPCommand((SPCommandRec *)&openSessionRec);
|
||||||
|
|
||||||
|
printf("refnum = %i\n", openSessionRec.refNum);
|
||||||
|
printf("result code = %04x\n", openSessionRec.result);
|
||||||
|
if (openSessionRec.result)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
closeSessionRec.async = AT_SYNC;
|
||||||
|
closeSessionRec.command = aspCloseSessionCommand;
|
||||||
|
closeSessionRec.completionPtr = 0;
|
||||||
|
closeSessionRec.refNum = openSessionRec.refNum;
|
||||||
|
|
||||||
|
printf("Closing...\n");
|
||||||
|
DispatchASPCommand((SPCommandRec *)&closeSessionRec);
|
||||||
|
printf("result code = %04x\n", closeSessionRec.result);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
if (startedTCP)
|
if (startedTCP)
|
||||||
|
|
|
@ -21,12 +21,6 @@ typedef enum DSISessionStatus {
|
||||||
error
|
error
|
||||||
} DSISessionStatus;
|
} DSISessionStatus;
|
||||||
|
|
||||||
typedef enum CommandStatus {
|
|
||||||
noCommand = 0,
|
|
||||||
commandPending,
|
|
||||||
commandDone
|
|
||||||
} CommandStatus;
|
|
||||||
|
|
||||||
typedef struct Session {
|
typedef struct Session {
|
||||||
/* Marinetti TCP connection status */
|
/* Marinetti TCP connection status */
|
||||||
Word ipid;
|
Word ipid;
|
||||||
|
@ -35,7 +29,7 @@ typedef struct Session {
|
||||||
DSISessionStatus dsiStatus;
|
DSISessionStatus dsiStatus;
|
||||||
|
|
||||||
/* Information on command currently being processed, if any. */
|
/* Information on command currently being processed, if any. */
|
||||||
CommandStatus commandStatus;
|
Boolean commandPending;
|
||||||
SPCommandRec *spCommandRec;
|
SPCommandRec *spCommandRec;
|
||||||
DSIRequestHeader request;
|
DSIRequestHeader request;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,16 @@ BOOLEAN StartTCPConnection(Session *sess) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndTCPConnection(Session *sess) {
|
void EndTCPConnection(Session *sess) {
|
||||||
|
srBuff mySRBuff;
|
||||||
|
|
||||||
if (sess->tcpLoggedIn) {
|
if (sess->tcpLoggedIn) {
|
||||||
|
do {
|
||||||
|
TCPIPPoll();
|
||||||
|
} while (TCPIPStatusTCP(sess->ipid, &mySRBuff) == tcperrOK
|
||||||
|
&& !toolerror()
|
||||||
|
&& mySRBuff.srState == TCPSESTABLISHED
|
||||||
|
&& mySRBuff.srSndQueued > 0);
|
||||||
|
|
||||||
TCPIPAbortTCP(sess->ipid);
|
TCPIPAbortTCP(sess->ipid);
|
||||||
TCPIPLogout(sess->ipid);
|
TCPIPLogout(sess->ipid);
|
||||||
sess->tcpLoggedIn = FALSE;
|
sess->tcpLoggedIn = FALSE;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user