-#if HAVE_GETTIMEOFDAY
- gettimeofday (&tv_start, 0);
-#endif
-
- if ((res = sscanf(line, "%31s %1023[^;]", word, arg)) <= 0)
- {
- strcpy(word, last_cmd);
- *arg = '\0';
- }
- else if (res == 1)
- *arg = 0;
- strcpy(last_cmd, word);
- for (i = 0; cmd[i].cmd; i++)
- if (!strncmp(cmd[i].cmd, word, strlen(word)))
- {
- res = (*cmd[i].fun)(arg);
- break;
- }
- if (!cmd[i].cmd) /* dump our help-screen */
- {
- printf("Unknown command: %s.\n", word);
- printf("Currently recognized commands:\n");
- for (i = 0; cmd[i].cmd; i++)
- printf(" %s %s\n", cmd[i].cmd, cmd[i].ad);
- res = 1;
- }
- if (res < 2)
- {
- continue;
- }
- }
- wait = 0;
- if (conn
-#ifdef USE_SELECT
- && FD_ISSET(cs_fileno(conn), &input)
-#endif
- )
- {
- do
- {
- if ((res = cs_get(conn, &netbuffer, &netbufferlen)) < 0)
- {
- perror("cs_get");
- exit(1);
- }
- if (!res)
- {
- printf("Target closed connection.\n");
- exit(1);
- }
- odr_reset(in); /* release APDU from last round */
- record_last = 0;
- odr_setbuf(in, netbuffer, res, 0);
- if (!z_APDU(in, &apdu, 0, 0))
- {
- odr_perror(in, "Decoding incoming APDU");
- fprintf(stderr, "[Near %d]\n", odr_offset(in));
- fprintf(stderr, "Packet dump:\n---------\n");
- odr_dumpBER(stderr, netbuffer, res);
- fprintf(stderr, "---------\n");
- if (apdu_file)
- z_APDU(print, &apdu, 0, 0);
- exit(1);
- }
- if (apdu_file && !z_APDU(print, &apdu, 0, 0))
- {
- odr_perror(print, "Failed to print incoming APDU");
- odr_reset(print);
- continue;
- }
- switch(apdu->which)
- {
- case Z_APDU_initResponse:
- process_initResponse(apdu->u.initResponse);
- break;
- case Z_APDU_searchResponse:
- process_searchResponse(apdu->u.searchResponse);
- break;
- case Z_APDU_scanResponse:
- process_scanResponse(apdu->u.scanResponse);
- break;
- case Z_APDU_presentResponse:
- print_refid (apdu->u.presentResponse->referenceId);
- setno +=
- *apdu->u.presentResponse->numberOfRecordsReturned;
- if (apdu->u.presentResponse->records)
- display_records(apdu->u.presentResponse->records);
- else
- printf("No records.\n");
- printf ("nextResultSetPosition = %d\n",
- *apdu->u.presentResponse->nextResultSetPosition);
- break;
- case Z_APDU_sortResponse:
- process_sortResponse(apdu->u.sortResponse);
- break;
- case Z_APDU_extendedServicesResponse:
- printf("Got extended services response\n");
- process_ESResponse(apdu->u.extendedServicesResponse);
- break;
- case Z_APDU_close:
- printf("Target has closed the association.\n");
- process_close(apdu->u.close);
- break;
- case Z_APDU_resourceControlRequest:
- process_resourceControlRequest
- (apdu->u.resourceControlRequest);
- break;
- case Z_APDU_deleteResultSetResponse:
- process_deleteResultSetResponse(apdu->u.
- deleteResultSetResponse);
- break;
- default:
- printf("Received unknown APDU type (%d).\n",
- apdu->which);
- exit(1);
- }
- }
- while (conn && cs_more(conn));
-#if HAVE_GETTIMEOFDAY
- gettimeofday (&tv_end, 0);
- if (1)
- {
- printf ("Elapsed: %.6f\n", (double) tv_end.tv_usec /
- 1e6 + tv_end.tv_sec -
- ((double) tv_start.tv_usec / 1e6 + tv_start.tv_sec));
- }
-#endif
- }