Added second half of close-handshake
authorSebastian Hammer <quinn@indexdata.com>
Tue, 29 Aug 1995 14:24:13 +0000 (14:24 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Tue, 29 Aug 1995 14:24:13 +0000 (14:24 +0000)
client/client.c
server/seshigh.c

index ef7292b..e06ad37 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.19  1995-08-29 11:17:28  quinn
+ * Revision 1.20  1995-08-29 14:24:13  quinn
+ * Added second half of close-handshake
+ *
+ * Revision 1.19  1995/08/29  11:17:28  quinn
  * Added code to receive close
  *
  * Revision 1.18  1995/08/28  12:21:27  quinn
  * Added code to receive close
  *
  * Revision 1.18  1995/08/28  12:21:27  quinn
@@ -109,6 +112,7 @@ static Z_ElementSetNames *elementSetNames = 0;
 static int setno = 1;                   /* current set offset */
 static int protocol = PROTO_Z3950;      /* current app protocol */
 static int recordsyntax = VAL_USMARC;
 static int setno = 1;                   /* current set offset */
 static int protocol = PROTO_Z3950;      /* current app protocol */
 static int recordsyntax = VAL_USMARC;
+static int sent_close = 0;
 static ODR_MEM session_mem;                /* memory handle for init-response */
 static Z_InitResponse *session = 0;        /* session parameters */
 static char last_scan[512] = "0";
 static ODR_MEM session_mem;                /* memory handle for init-response */
 static Z_InitResponse *session = 0;        /* session parameters */
 static char last_scan[512] = "0";
@@ -642,6 +646,9 @@ static int send_presentRequest(char *arg)
 
 void process_close(Z_Close *req)
 {
 
 void process_close(Z_Close *req)
 {
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
+    Z_Close *res = apdu->u.close;
+
     static char *reasons[] =
     {
        "finished",
     static char *reasons[] =
     {
        "finished",
@@ -658,6 +665,15 @@ void process_close(Z_Close *req)
 
     printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
        req->diagnosticInformation ? req->diagnosticInformation : "NULL");
 
     printf("Reason: %s, message: %s\n", reasons[*req->closeReason],
        req->diagnosticInformation ? req->diagnosticInformation : "NULL");
+    if (sent_close)
+    {
+       printf("Goodbye.\n");
+       exit(0);
+    }
+    *res->closeReason = Z_Close_finished;
+    send_apdu(apdu);
+    printf("Sent response.\n");
+    sent_close = 1;
 }
 
 static int cmd_show(char *arg)
 }
 
 static int cmd_show(char *arg)
@@ -836,6 +852,18 @@ int cmd_elements(char *arg)
     return 1;
 }
 
     return 1;
 }
 
+int cmd_close(char *arg)
+{
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_close);
+    Z_Close *req = apdu->u.close;
+
+    *req->closeReason = Z_Close_finished;
+    send_apdu(apdu);
+    printf("Sent close request.\n");
+    sent_close = 1;
+    return 2;
+}
+
 static void initialize(void)
 {
 #ifdef RPN_QUERY
 static void initialize(void)
 {
 #ifdef RPN_QUERY
@@ -888,6 +916,7 @@ static int client(void)
        {"cancel", cmd_cancel, ""},
        {"format", cmd_format, "<recordsyntax>"},
        {"elements", cmd_elements, "<elementSetName>"},
        {"cancel", cmd_cancel, ""},
        {"format", cmd_format, "<recordsyntax>"},
        {"elements", cmd_elements, "<elementSetName>"},
+       {"close", cmd_close, ""},
        {0,0}
     };
     char *netbuffer= 0;
        {0,0}
     };
     char *netbuffer= 0;
index a062b3d..a3e3807 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: seshigh.c,v $
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: seshigh.c,v $
- * Revision 1.46  1995-08-29 11:17:58  quinn
+ * Revision 1.47  1995-08-29 14:24:16  quinn
+ * Added second half of close-handshake
+ *
+ * Revision 1.46  1995/08/29  11:17:58  quinn
  * Added code to receive close
  *
  * Revision 1.45  1995/08/21  09:11:00  quinn
  * Added code to receive close
  *
  * Revision 1.45  1995/08/21  09:11:00  quinn
@@ -205,6 +208,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb,
 static Z_APDU *process_presentRequest(association *assoc, request *reqb,
     int *fd);
 static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd);
 static Z_APDU *process_presentRequest(association *assoc, request *reqb,
     int *fd);
 static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd);
+static void process_close(association *assoc, request *reqb);
 
 static FILE *apduf = 0; /* for use in static mode */
 static statserv_options_block *control_block = 0;
 
 static FILE *apduf = 0; /* for use in static mode */
 static statserv_options_block *control_block = 0;
@@ -469,6 +473,8 @@ static int process_request(association *assoc)
            res = process_presentRequest(assoc, req, &fd); break;
        case Z_APDU_scanRequest:
            res = process_scanRequest(assoc, req, &fd); break;
            res = process_presentRequest(assoc, req, &fd); break;
        case Z_APDU_scanRequest:
            res = process_scanRequest(assoc, req, &fd); break;
+       case Z_APDU_close:
+           process_close(assoc, req); return 0;
        default:
            logf(LOG_WARN, "Bad APDU received");
            return -1;
        default:
            logf(LOG_WARN, "Bad APDU received");
            return -1;
@@ -1239,3 +1245,28 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
 
     return &apdu;
 }
 
     return &apdu;
 }
+
+static void process_close(association *assoc, request *reqb)
+{
+    Z_Close *req = reqb->request->u.close;
+    static char *reasons[] =
+    {
+       "finished",
+       "shutdown",
+       "systemProblem",
+       "costLimit",
+       "resources",
+       "securityViolation",
+       "protocolError",
+       "lackOfActivity",
+       "peerAbort",
+       "unspecified"
+    };
+
+    logf(LOG_LOG, "Got close, reason %s, message %s",
+       reasons[*req->closeReason], req->diagnosticInformation ?
+       req->diagnosticInformation : "NULL");
+    if (assoc->version < 3) /* to make do_force respond with close */
+       assoc->version = 3;
+    do_close(assoc, Z_Close_finished, "Association terminated by client");
+}