Call attention routine when appropriate, and handle close requests from the server.

This commit is contained in:
Stephen Heumann 2017-04-16 16:19:59 -05:00
parent 5b5295fd40
commit 93e2a5a864
4 changed files with 32 additions and 11 deletions

View File

@ -33,8 +33,6 @@ static Byte loginBuf[100];
static const Byte afp20VersionStr[] = "\pAFPVersion 2.0"; static const Byte afp20VersionStr[] = "\pAFPVersion 2.0";
static const Byte afp22VersionStr[] = "\pAFP2.2"; static const Byte afp22VersionStr[] = "\pAFP2.2";
static void EndSession(Session *sess, Byte attentionCode);
static void DoSPGetStatus(Session *sess, ASPGetStatusRec *commandRec); static void DoSPGetStatus(Session *sess, ASPGetStatusRec *commandRec);
static void DoSPOpenSession(Session *sess); static void DoSPOpenSession(Session *sess);
static void DoSPCloseSession(Session *sess); static void DoSPCloseSession(Session *sess);
@ -65,7 +63,7 @@ LongWord DispatchASPCommand(SPCommandRec *commandRec) {
for (i = 0; i < MAX_SESSIONS; i++) { for (i = 0; i < MAX_SESSIONS; i++) {
if (sessionTbl[i].dsiStatus == needsReset) if (sessionTbl[i].dsiStatus == needsReset)
EndSession(&sessionTbl[i], 0); EndASPSession(&sessionTbl[i], 0);
} }
for (i = 0; i < MAX_SESSIONS; i++) { for (i = 0; i < MAX_SESSIONS; i++) {
if (sessionTbl[i].dsiStatus == unused) if (sessionTbl[i].dsiStatus == unused)
@ -85,6 +83,11 @@ LongWord DispatchASPCommand(SPCommandRec *commandRec) {
} }
sess->dsiStatus = awaitingHeader; sess->dsiStatus = awaitingHeader;
InitReadTCP(sess, DSI_HEADER_SIZE, &sess->reply); InitReadTCP(sess, DSI_HEADER_SIZE, &sess->reply);
if (commandRec->command==aspOpenSessionCommand) {
sess->attention = (ASPAttentionHeaderRec *)
((ASPOpenSessionRec*)commandRec)->attnRtnAddr;
}
} else { } else {
if (commandRec->refNum < SESSION_NUM_START) { if (commandRec->refNum < SESSION_NUM_START) {
goto callOrig; goto callOrig;
@ -324,7 +327,7 @@ void FlagFatalError(Session *sess, Word errorCode) {
CompleteCurrentASPCommand(sess, errorCode); CompleteCurrentASPCommand(sess, errorCode);
} }
EndSession(sess, aspAttenTimeout); EndASPSession(sess, aspAttenTimeout);
} }
@ -377,7 +380,7 @@ void CompleteCurrentASPCommand(Session *sess, Word result) {
if (sess->spCommandRec->command == aspGetStatusCommand if (sess->spCommandRec->command == aspGetStatusCommand
|| sess->spCommandRec->command == aspCloseSessionCommand) || sess->spCommandRec->command == aspCloseSessionCommand)
{ {
EndSession(sess, 0); EndASPSession(sess, 0);
} else { } else {
sess->commandPending = FALSE; sess->commandPending = FALSE;
if (sess->dsiStatus != error) { if (sess->dsiStatus != error) {
@ -403,15 +406,27 @@ static void CompleteASPCommand(SPCommandRec *commandRec, Word result) {
} }
static void EndSession(Session *sess, Byte attentionCode) { void EndASPSession(Session *sess, Byte attentionCode) {
if (attentionCode != 0) { if (attentionCode != 0) {
// TODO call the attention routine to report end of session CallAttentionRoutine(sess, attentionCode, 0);
} }
EndTCPConnection(sess); EndTCPConnection(sess);
memset(sess, 0, sizeof(*sess)); memset(sess, 0, sizeof(*sess));
} }
void CallAttentionRoutine(Session *sess, Byte attenType, Word atten) {
if (sess->attention == NULL)
return;
sess->attention->sessionRefNum = (sess - sessionTbl) + SESSION_NUM_START;
sess->attention->attenType = attenType;
sess->attention->atten = atten;
/* Call attention routine like completion routine */
CallCompletionRoutine((void *)(sess->attention + 1));
}
void PollAllSessions(void) { void PollAllSessions(void) {
unsigned int i; unsigned int i;
@ -423,7 +438,7 @@ void PollAllSessions(void) {
break; break;
case needsReset: case needsReset:
EndSession(&sessionTbl[i], 0); EndASPSession(&sessionTbl[i], 0);
break; break;
} }
} }
@ -438,7 +453,7 @@ void CloseAllSessions(Byte attentionCode) {
sess = &sessionTbl[i]; sess = &sessionTbl[i];
if (sess->dsiStatus != unused) { if (sess->dsiStatus != unused) {
DoSPCloseSession(sess); DoSPCloseSession(sess);
EndSession(sess, attentionCode); EndASPSession(sess, attentionCode);
} }
} }
} }

View File

@ -18,6 +18,8 @@ LongWord DispatchASPCommand(SPCommandRec *commandRec);
void CompleteCurrentASPCommand(Session *sess, Word result); void CompleteCurrentASPCommand(Session *sess, Word result);
void FinishASPCommand(Session *sess); void FinishASPCommand(Session *sess);
void FlagFatalError(Session *sess, Word errorCode); void FlagFatalError(Session *sess, Word errorCode);
void EndASPSession(Session *sess, Byte attentionCode);
void CallAttentionRoutine(Session *sess, Byte attenType, Word atten);
void PollAllSessions(void); void PollAllSessions(void);
void CloseAllSessions(Byte attentionCode); void CloseAllSessions(Byte attentionCode);
void ResetAllSessions(void); void ResetAllSessions(void);

5
dsi.c
View File

@ -155,9 +155,10 @@ top:
if (sess->reply.command == DSIAttention) { if (sess->reply.command == DSIAttention) {
attentionReplyRec.requestID = sess->reply.requestID; attentionReplyRec.requestID = sess->reply.requestID;
SendDSIMessage(sess, &attentionReplyRec, NULL, NULL); SendDSIMessage(sess, &attentionReplyRec, NULL, NULL);
//TODO call attention routine. CallAttentionRoutine(sess, aspAttenNormal, sess->attentionCode);
} else if (sess->reply.command == DSICloseSession) { } else if (sess->reply.command == DSICloseSession) {
// TODO handle close EndASPSession(sess, aspAttenClosed);
return;
} else if (sess->reply.command == DSITickle) { } else if (sess->reply.command == DSITickle) {
tickleRequestRec.requestID = htons(sess->nextRequestID++); tickleRequestRec.requestID = htons(sess->nextRequestID++);
SendDSIMessage(sess, &tickleRequestRec, NULL, NULL); SendDSIMessage(sess, &tickleRequestRec, NULL, NULL);

View File

@ -59,6 +59,9 @@ typedef struct Session {
/* AppleTalk<->IP address mapping used for this session */ /* AppleTalk<->IP address mapping used for this session */
ATIPMapping atipMapping; ATIPMapping atipMapping;
/* Attention routine header (followed by the routine) */
ASPAttentionHeaderRec *attention;
} Session; } Session;
#endif #endif