X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=d813167a0984649d0e7e92285a71640b59558a81;hb=f422693382524b11066ec4129ca9213effdb893a;hp=370348ea35935ef635b8567e41266de15d0bedeb;hpb=0d9eca26da6a9369bb00efd75a9472380526f547;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 370348e..d813167 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,29 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.66 1998-05-18 13:06:53 adam + * Revision 1.73 1998-10-20 13:55:43 quinn + * Fixed Scan bug in asn and client + * + * Revision 1.72 1998/10/20 13:23:15 quinn + * changed preferred pos to 1 + * + * Revision 1.71 1998/10/20 13:21:43 adam + * Fixed scan response handler. + * + * Revision 1.70 1998/09/22 09:40:37 adam + * Minor changes in sort spec. + * + * Revision 1.69 1998/08/19 16:10:06 adam + * Changed som member names of DeleteResultSetRequest/Response. + * + * Revision 1.68 1998/07/20 12:37:06 adam + * Added 'delete ' command. Changed open command so that + * it reconnects if already connected. + * + * Revision 1.67 1998/06/09 13:55:06 adam + * Minor changes. + * + * Revision 1.66 1998/05/18 13:06:53 adam * Changed the way attribute sets are handled by the retriaval module. * Extended Explain conversion / schema. * Modified server and client to work with ASN.1 compiled protocol handlers. @@ -260,7 +282,7 @@ static int setno = 1; /* current set offset */ static enum oid_proto protocol = PROTO_Z3950; /* current app protocol */ static enum oid_value recordsyntax = VAL_USMARC; static int sent_close = 0; -static ODR_MEM session_mem; /* memory handle for init-response */ +static NMEM session_mem = NULL; /* memory handle for init-response */ static Z_InitResponse *session = 0; /* session parameters */ static char last_scan[512] = "0"; static char last_cmd[100] = "?"; @@ -332,6 +354,7 @@ static void send_initRequest() ODR_MASK_SET(req->options, Z_Options_scan); ODR_MASK_SET(req->options, Z_Options_sort); ODR_MASK_SET(req->options, Z_Options_extendedServices); + ODR_MASK_SET(req->options, Z_Options_delSet); ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(req->protocolVersion, Z_ProtocolVersion_2); @@ -375,6 +398,7 @@ static int process_initResponse(Z_InitResponse *res) printf("Guessing visiblestring:\n"); printf("'%s'\n", res->userInformationField->u. octet_aligned->buf); } + odr_reset (print); } return 0; } @@ -418,7 +442,14 @@ int cmd_open(char *arg) if (conn) { printf("Already connected.\n"); - return 0; + + cs_close (conn); + conn = NULL; + if (session_mem) + { + nmem_destroy (session_mem); + session_mem = NULL; + } } base[0] = '\0'; if (!*arg || sscanf(arg, "%[^:]:%[^/]/%s", type, addr, base) < 2) @@ -740,6 +771,26 @@ static void display_records(Z_Records *p) } } +static int send_deleteResultSetRequest(char *arg) +{ + Z_APDU *apdu = zget_APDU(out, Z_APDU_deleteResultSetRequest); + Z_DeleteResultSetRequest *req = apdu->u.deleteResultSetRequest; + + req->referenceId = set_refid (out); + + req->num_resultSetList = 1; + req->resultSetList = (char **) + odr_malloc (out, sizeof(*req->resultSetList)); + *req->resultSetList = arg; + req->deleteFunction = (int *) + odr_malloc (out, sizeof(*req->deleteFunction)); + *req->deleteFunction = Z_DeleteRequest_list; + + send_apdu(apdu); + printf("Sent deleteResultSetRequest.\n"); + return 2; +} + static int send_searchRequest(char *arg) { Z_APDU *apdu = zget_APDU(out, Z_APDU_searchRequest); @@ -747,7 +798,7 @@ static int send_searchRequest(char *arg) Z_Query query; int oid[OID_SIZE]; #if CCL2RPN - struct ccl_rpn_node *rpn; + struct ccl_rpn_node *rpn = NULL; int error, pos; oident bib1; #endif @@ -826,7 +877,8 @@ static int send_searchRequest(char *arg) #if CCL2RPN case QueryType_CCL2RPN: query.which = Z_Query_type_1; - assert((RPNquery = ccl_rpn_query(out, rpn))); + RPNquery = ccl_rpn_query(out, rpn); + assert(RPNquery); bib1.proto = protocol; bib1.oclass = CLASS_ATTSET; bib1.value = VAL_BIB1; @@ -1123,7 +1175,7 @@ static int cmd_itemorder(char *arg) fflush(stdout); send_itemorder(arg); - return(1); + return(2); } static int cmd_find(char *arg) @@ -1143,6 +1195,23 @@ static int cmd_find(char *arg) return 2; } +static int cmd_delete(char *arg) +{ + if (!*arg) + { + printf("Delete what?\n"); + return 0; + } + if (!conn) + { + printf("Not connected yet\n"); + return 0; + } + if (!send_deleteResultSetRequest(arg)) + return 0; + return 2; +} + static int cmd_ssub(char *arg) { if (!(smallSetUpperBound = atoi(arg))) @@ -1266,17 +1335,31 @@ void process_close(Z_Close *req) req->diagnosticInformation ? req->diagnosticInformation : "NULL"); if (sent_close) { - printf("Goodbye.\n"); - exit(0); + cs_close (conn); + conn = NULL; + if (session_mem) + { + nmem_destroy (session_mem); + session_mem = NULL; + } + sent_close = 0; + } + else + { + *res->closeReason = Z_Close_finished; + send_apdu(apdu); + printf("Sent response.\n"); + sent_close = 1; } - *res->closeReason = Z_Close_finished; - send_apdu(apdu); - printf("Sent response.\n"); - sent_close = 1; } static int cmd_show(char *arg) { + if (!conn) + { + printf("Not connected yet\n"); + return 0; + } if (!send_presentRequest(arg)) return 0; return 2; @@ -1296,7 +1379,7 @@ int cmd_cancel(char *arg) apdu->u.triggerResourceControlRequest; bool_t rfalse = 0; - if (!session) + if (!conn) { printf("Session not initialized yet\n"); return 0; @@ -1443,12 +1526,12 @@ int send_sortrequest(char *arg, int newset) case 'a': case 'A': case '>': - *sks->sortRelation = Z_SortRelation_ascending; + *sks->sortRelation = Z_SortRelation_descending; break; case 'd': case 'D': case '<': - *sks->sortRelation = Z_SortRelation_descending; + *sks->sortRelation = Z_SortRelation_ascending; break; case 'i': case 'I': @@ -1499,33 +1582,22 @@ void process_scanResponse(Z_ScanResponse *res) printf("Scan returned code %d\n", *res->scanStatus); if (!res->entries) return; -#ifdef ASN_COMPILED if ((entries = res->entries->entries)) num_entries = res->entries->num_entries; -#else - if (res->entries->which == Z_ListEntries_entries) - { - entries = res->entries->u.entries->entries; - num_entries = res->entries->u.entries->num_entries; - } -#endif for (i = 0; i < num_entries; i++) + { + int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1; if (entries[i]->which == Z_Entry_termInfo) { - printf("%c ", i + 1 == *res->positionOfTerm ? '*' : ' '); + printf("%c ", i + 1 == pos_term ? '*' : ' '); display_term(entries[i]->u.termInfo); } else display_diagrecs(&entries[i]->u.surrogateDiagnostic, 1); -#ifdef ASN_COMPILED + } if (res->entries->nonsurrogateDiagnostics) display_diagrecs (res->entries->nonsurrogateDiagnostics, res->entries->num_nonsurrogateDiagnostics); -#else - if (res->entries->which == Z_ListEntries_nonSurrogateDiagnostics) - display_diagrecs(&res->entries-> - u.nonSurrogateDiagnostics->diagRecs[0], 1); -#endif } void process_sortResponse(Z_SortResponse *res) @@ -1557,7 +1629,7 @@ void process_sortResponse(Z_SortResponse *res) int cmd_sort_generic(char *arg, int newset) { - if (!session) + if (!conn) { printf("Session not initialized yet\n"); return 0; @@ -1588,7 +1660,7 @@ int cmd_sort_newset (char *arg) int cmd_scan(char *arg) { - if (!session) + if (!conn) { printf("Session not initialized yet\n"); return 0; @@ -1600,7 +1672,7 @@ int cmd_scan(char *arg) } if (*arg) { - if (send_scanrequest(arg, 5, 20) < 0) + if (send_scanrequest(arg, 1, 20) < 0) return 0; } else @@ -1697,9 +1769,13 @@ int cmd_refid (char *arg) int cmd_close(char *arg) { - Z_APDU *apdu = zget_APDU(out, Z_APDU_close); - Z_Close *req = apdu->u.close; + Z_APDU *apdu; + Z_Close *req; + if (!conn) + return 0; + apdu = zget_APDU(out, Z_APDU_close); + req = apdu->u.close; *req->closeReason = Z_Close_finished; send_apdu(apdu); printf("Sent close request.\n"); @@ -1731,6 +1807,7 @@ static void initialize(void) fclose (inf); } #endif + cmd_base("Default"); } static int client(int wait) @@ -1743,6 +1820,7 @@ static int client(int wait) {"open", cmd_open, "('tcp'|'osi')':'['/'][':']"}, {"quit", cmd_quit, ""}, {"find", cmd_find, ""}, + {"delete", cmd_delete, ""}, {"base", cmd_base, ""}, {"show", cmd_show, "['+'<#recs>['+']]"}, {"scan", cmd_scan, ""}, @@ -1901,13 +1979,18 @@ static int client(int wait) process_resourceControlRequest (apdu->u.resourceControlRequest); break; + case Z_APDU_deleteResultSetResponse: + printf("Got deleteResultSetResponse status=%d\n", + *apdu->u.deleteResultSetResponse-> + deleteOperationStatus); + break; default: printf("Received unknown APDU type (%d).\n", apdu->which); exit(1); } } - while (cs_more(conn)); + while (conn && cs_more(conn)); printf(C_PROMPT); fflush(stdout); } @@ -1922,16 +2005,17 @@ int main(int argc, char **argv) int ret; int opened = 0; - initialize(); - cmd_base("Default"); - - while ((ret = options("m:", argv, argc, &arg)) != -2) + while ((ret = options("m:v:", argv, argc, &arg)) != -2) { switch (ret) { case 0: - if (cmd_open (arg) == 2) - opened = 1; + if (!opened) + { + initialize (); + if (cmd_open (arg) == 2) + opened = 1; + } break; case 'm': if (!(marcdump = fopen (arg, "a"))) @@ -1940,6 +2024,9 @@ int main(int argc, char **argv) exit (1); } break; + case 'v': + log_init (log_mask_str(arg), "", NULL); + break; default: fprintf (stderr, "Usage: %s [-m ] []\n", prog); @@ -1947,7 +2034,10 @@ int main(int argc, char **argv) } } if (!opened) + { + initialize (); printf (C_PROMPT); + } return client (opened); }