From 93e2a5a86453add0edbb66993433618a2a45281a Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 16 Apr 2017 16:19:59 -0500 Subject: [PATCH] Call attention routine when appropriate, and handle close requests from the server. --- aspinterface.c | 33 ++++++++++++++++++++++++--------- aspinterface.h | 2 ++ dsi.c | 5 +++-- session.h | 3 +++ 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/aspinterface.c b/aspinterface.c index f33ff35..03830d9 100644 --- a/aspinterface.c +++ b/aspinterface.c @@ -33,8 +33,6 @@ static Byte loginBuf[100]; static const Byte afp20VersionStr[] = "\pAFPVersion 2.0"; static const Byte afp22VersionStr[] = "\pAFP2.2"; -static void EndSession(Session *sess, Byte attentionCode); - static void DoSPGetStatus(Session *sess, ASPGetStatusRec *commandRec); static void DoSPOpenSession(Session *sess); static void DoSPCloseSession(Session *sess); @@ -65,7 +63,7 @@ LongWord DispatchASPCommand(SPCommandRec *commandRec) { for (i = 0; i < MAX_SESSIONS; i++) { if (sessionTbl[i].dsiStatus == needsReset) - EndSession(&sessionTbl[i], 0); + EndASPSession(&sessionTbl[i], 0); } for (i = 0; i < MAX_SESSIONS; i++) { if (sessionTbl[i].dsiStatus == unused) @@ -85,6 +83,11 @@ LongWord DispatchASPCommand(SPCommandRec *commandRec) { } sess->dsiStatus = awaitingHeader; InitReadTCP(sess, DSI_HEADER_SIZE, &sess->reply); + + if (commandRec->command==aspOpenSessionCommand) { + sess->attention = (ASPAttentionHeaderRec *) + ((ASPOpenSessionRec*)commandRec)->attnRtnAddr; + } } else { if (commandRec->refNum < SESSION_NUM_START) { goto callOrig; @@ -324,7 +327,7 @@ void FlagFatalError(Session *sess, Word 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 || sess->spCommandRec->command == aspCloseSessionCommand) { - EndSession(sess, 0); + EndASPSession(sess, 0); } else { sess->commandPending = FALSE; 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) { - // TODO call the attention routine to report end of session + CallAttentionRoutine(sess, attentionCode, 0); } EndTCPConnection(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) { unsigned int i; @@ -423,7 +438,7 @@ void PollAllSessions(void) { break; case needsReset: - EndSession(&sessionTbl[i], 0); + EndASPSession(&sessionTbl[i], 0); break; } } @@ -438,7 +453,7 @@ void CloseAllSessions(Byte attentionCode) { sess = &sessionTbl[i]; if (sess->dsiStatus != unused) { DoSPCloseSession(sess); - EndSession(sess, attentionCode); + EndASPSession(sess, attentionCode); } } } diff --git a/aspinterface.h b/aspinterface.h index 0d17c59..9f5a126 100644 --- a/aspinterface.h +++ b/aspinterface.h @@ -18,6 +18,8 @@ LongWord DispatchASPCommand(SPCommandRec *commandRec); void CompleteCurrentASPCommand(Session *sess, Word result); void FinishASPCommand(Session *sess); void FlagFatalError(Session *sess, Word errorCode); +void EndASPSession(Session *sess, Byte attentionCode); +void CallAttentionRoutine(Session *sess, Byte attenType, Word atten); void PollAllSessions(void); void CloseAllSessions(Byte attentionCode); void ResetAllSessions(void); diff --git a/dsi.c b/dsi.c index 18c3afa..ab535fd 100644 --- a/dsi.c +++ b/dsi.c @@ -155,9 +155,10 @@ top: if (sess->reply.command == DSIAttention) { attentionReplyRec.requestID = sess->reply.requestID; SendDSIMessage(sess, &attentionReplyRec, NULL, NULL); - //TODO call attention routine. + CallAttentionRoutine(sess, aspAttenNormal, sess->attentionCode); } else if (sess->reply.command == DSICloseSession) { - // TODO handle close + EndASPSession(sess, aspAttenClosed); + return; } else if (sess->reply.command == DSITickle) { tickleRequestRec.requestID = htons(sess->nextRequestID++); SendDSIMessage(sess, &tickleRequestRec, NULL, NULL); diff --git a/session.h b/session.h index 3d2da0d..95b240b 100644 --- a/session.h +++ b/session.h @@ -59,6 +59,9 @@ typedef struct Session { /* AppleTalk<->IP address mapping used for this session */ ATIPMapping atipMapping; + + /* Attention routine header (followed by the routine) */ + ASPAttentionHeaderRec *attention; } Session; #endif