X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=8d4cba53a4103fc1b674926bb7458d53988326ab;hp=25c719ce6455e66c10941ef6b23e8c71682ab473;hb=9b639eeb66d918ee531668b405a6f4c4438c64af;hpb=b436ce38e1e619d2225c7c75c1f0de841aa13bad diff --git a/client/client.c b/client/client.c index 25c719c..8d4cba5 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,22 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.64 1998-03-31 11:07:44 adam + * 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. + * + * Revision 1.65 1998/03/31 15:13:19 adam + * Development towards compiled ASN.1. + * + * Revision 1.64 1998/03/31 11:07:44 adam * Furhter work on UNIverse resource report. * Added Extended Services handling in frontend server. * @@ -249,10 +264,10 @@ static int largeSetLowerBound = 1; static int mediumSetPresentNumber = 0; 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 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] = "?"; @@ -324,6 +339,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); @@ -367,26 +383,67 @@ 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; } +static int cmd_base(char *arg) +{ + int i; + char *cp; + + if (!*arg) + { + printf("Usage: base ...\n"); + return 0; + } + for (i = 0; iu.sutrs = (Odr_oct *)rr; /* we don't actually check the type here. */ + r->u.sutrs = (Z_SUTRS *) rr; /* we don't actually check the type here. */ r->which = type->what; } } @@ -643,10 +700,22 @@ static void display_diagrecs(Z_DiagRec **pp, int num) ent->oclass != CLASS_DIAGSET || ent->value != VAL_BIB1) printf("Missing or unknown diagset\n"); printf(" [%d] %s", *r->condition, diagbib1_str(*r->condition)); +#ifdef ASN_COMPILED + switch (r->which) + { + case Z_DefaultDiagFormat_v2Addinfo: + printf (" -- v2 addinfo '%s'\n", r->u.v2Addinfo); + break; + case Z_DefaultDiagFormat_v3Addinfo: + printf (" -- v3 addinfo '%s'\n", r->u.v3Addinfo); + break; + } +#else if (r->addinfo && *r->addinfo) printf(" -- '%s'\n", r->addinfo); else printf("\n"); +#endif } } @@ -666,7 +735,16 @@ static void display_records(Z_Records *p) int i; if (p->which == Z_Records_NSD) + { +#ifdef ASN_COMPILED + Z_DiagRec dr, *dr_p = &dr; + dr.which = Z_DiagRec_defaultFormat; + dr.u.defaultFormat = p->u.nonSurrogateDiagnostic; + display_diagrecs (&dr_p, 1); +#else display_diagrecs (&p->u.nonSurrogateDiagnostic, 1); +#endif + } else if (p->which == Z_Records_multipleNSD) display_diagrecs (p->u.multipleNonSurDiagnostics->diagRecs, p->u.multipleNonSurDiagnostics->num_diagRecs); @@ -678,6 +756,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_ids = 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); @@ -685,7 +783,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 @@ -764,7 +862,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; @@ -968,7 +1067,7 @@ void process_ESResponse(Z_ExtendedServicesResponse *res) static Z_External *CreateItemOrderExternal(int itemno) { - Z_External *r = odr_malloc(out, sizeof(Z_External)); + Z_External *r = (Z_External *) odr_malloc(out, sizeof(Z_External)); oident ItemOrderRequest; ItemOrderRequest.proto = PROTO_Z3950; @@ -976,34 +1075,43 @@ static Z_External *CreateItemOrderExternal(int itemno) ItemOrderRequest.value = VAL_ITEMORDER; r->direct_reference = odr_oiddup(out,oid_getoidbyent(&ItemOrderRequest)); - r->indirect_reference = odr_malloc(out,sizeof(int)); + r->indirect_reference = (int *) odr_malloc(out,sizeof(int)); *r->indirect_reference = 0; r->descriptor = "Extended services item order"; r->which = Z_External_itemOrder; - r->u.itemOrder = odr_malloc(out,sizeof(Z_ItemOrder)); + r->u.itemOrder = (Z_ItemOrder *) odr_malloc(out,sizeof(Z_ItemOrder)); memset(r->u.itemOrder, 0, sizeof(Z_ItemOrder)); +#ifdef ASN_COMPILED + r->u.itemOrder->which=Z_IOItemOrder_esRequest; +#else r->u.itemOrder->which=Z_ItemOrder_esRequest; +#endif - r->u.itemOrder->u.esRequest = odr_malloc(out,sizeof(Z_IORequest)); + r->u.itemOrder->u.esRequest = (Z_IORequest *) + odr_malloc(out,sizeof(Z_IORequest)); memset(r->u.itemOrder->u.esRequest, 0, sizeof(Z_IORequest)); - r->u.itemOrder->u.esRequest->toKeep = odr_malloc(out,sizeof(Z_IOOriginPartToKeep)); + r->u.itemOrder->u.esRequest->toKeep = (Z_IOOriginPartToKeep *) + odr_malloc(out,sizeof(Z_IOOriginPartToKeep)); memset(r->u.itemOrder->u.esRequest->toKeep, 0, sizeof(Z_IOOriginPartToKeep)); - r->u.itemOrder->u.esRequest->notToKeep = odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep)); + r->u.itemOrder->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *) + odr_malloc(out,sizeof(Z_IOOriginPartNotToKeep)); memset(r->u.itemOrder->u.esRequest->notToKeep, 0, sizeof(Z_IOOriginPartNotToKeep)); r->u.itemOrder->u.esRequest->toKeep->supplDescription = NULL; r->u.itemOrder->u.esRequest->toKeep->contact = NULL; r->u.itemOrder->u.esRequest->toKeep->addlBilling = NULL; - r->u.itemOrder->u.esRequest->notToKeep->resultSetItem = odr_malloc(out, sizeof(Z_IOResultSetItem)); + r->u.itemOrder->u.esRequest->notToKeep->resultSetItem = + (Z_IOResultSetItem *) odr_malloc(out, sizeof(Z_IOResultSetItem)); memset(r->u.itemOrder->u.esRequest->notToKeep->resultSetItem, 0, sizeof(Z_IOResultSetItem)); r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->resultSetId = "1"; - r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = odr_malloc(out, sizeof(int)); + r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = + (int *) odr_malloc(out, sizeof(int)); *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno; r->u.itemOrder->u.esRequest->notToKeep->itemRequest = NULL; @@ -1024,7 +1132,7 @@ static int send_itemorder(char *arg) /* Set up item order request */ /* Function being performed by this extended services request */ - req->function = odr_malloc(out, sizeof(int)); + req->function = (int *) odr_malloc(out, sizeof(int)); *req->function = Z_ExtendedServicesRequest_create; /* Package type, Using protocol ILL ( But that's not in the oid.h file yet */ @@ -1072,6 +1180,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))) @@ -1101,35 +1226,6 @@ static int cmd_status(char *arg) return 1; } -static int cmd_base(char *arg) -{ - int i; - char *cp; - - if (!*arg) - { - printf("Usage: base ...\n"); - return 0; - } - for (i = 0; idiagnosticInformation ? 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; @@ -1254,7 +1364,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; @@ -1276,12 +1386,16 @@ int send_scanrequest(char *string, int pp, int num) { Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest); Z_ScanRequest *req = apdu->u.scanRequest; - + + if (!(req->termListAndStartPoint = + p_query_scan(out, protocol, &req->attributeSet, string))) + { + printf("Prefix query error\n"); + return -1; + } req->referenceId = set_refid (out); req->num_databaseNames = num_databaseNames; req->databaseNames = databaseNames; - req->termListAndStartPoint = p_query_scan(out, protocol, - &req->attributeSet, string); req->numberOfTermsRequested = # req->preferredPositionInResponse = &pp; send_apdu(apdu); @@ -1306,6 +1420,14 @@ int send_sortrequest(char *arg, int newset) req->referenceId = set_refid (out); +#ifdef ASN_COMPILED + req->num_inputResultSetNames = 1; + req->inputResultSetNames = (Z_InternationalString **) + odr_malloc (out, sizeof(*req->inputResultSetNames)); + req->inputResultSetNames[0] = (char *) + odr_malloc (out, strlen(setstring)+1); + strcpy (req->inputResultSetNames[0], setstring); +#else req->inputResultSetNames = (Z_StringList *)odr_malloc (out, sizeof(*req->inputResultSetNames)); req->inputResultSetNames->num_strings = 1; @@ -1314,6 +1436,7 @@ int send_sortrequest(char *arg, int newset) req->inputResultSetNames->strings[0] = (char *)odr_malloc (out, strlen(setstring)+1); strcpy (req->inputResultSetNames->strings[0], setstring); +#endif if (newset && setnumber >= 0) sprintf (setstring, "%d", ++setnumber); @@ -1374,7 +1497,12 @@ int send_sortrequest(char *arg, int newset) sks->caseSensitivity = (int *)odr_malloc (out, sizeof(*sks->caseSensitivity)); *sks->caseSensitivity = Z_SortCase_caseSensitive; +#ifdef ASN_COMPILED + sks->which = Z_SortKeySpec_null; + sks->u.null = odr_nullval (); +#else sks->missingValueAction = NULL; +#endif for (i = 0; sort_flags[i]; i++) { @@ -1426,6 +1554,8 @@ void display_term(Z_TermInfo *t) void process_scanResponse(Z_ScanResponse *res) { int i; + Z_Entry **entries = NULL; + int num_entries = 0; printf("Received ScanResponse\n"); print_refid (res->referenceId); @@ -1437,22 +1567,33 @@ 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) { - Z_Entries *ent = res->entries->u.entries; - - for (i = 0; i < ent->num_entries; i++) - if (ent->entries[i]->which == Z_Entry_termInfo) - { - printf("%c ", i + 1 == *res->positionOfTerm ? '*' : ' '); - display_term(ent->entries[i]->u.termInfo); - } - else - display_diagrecs(&ent->entries[i]->u.surrogateDiagnostic, 1); + entries = res->entries->u.entries->entries; + num_entries = res->entries->u.entries->num_entries; } - else +#endif + for (i = 0; i < num_entries; i++) + if (entries[i]->which == Z_Entry_termInfo) + { + printf("%c ", i + 1 == *res->positionOfTerm ? '*' : ' '); + 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) @@ -1471,14 +1612,20 @@ void process_sortResponse(Z_SortResponse *res) } printf ("\n"); print_refid (res->referenceId); +#ifdef ASN_COMPILED + if (res->diagnostics) + display_diagrecs(res->diagnostics, + res->num_diagnostics); +#else if (res->diagnostics) display_diagrecs(res->diagnostics->diagRecs, res->diagnostics->num_diagRecs); +#endif } int cmd_sort_generic(char *arg, int newset) { - if (!session) + if (!conn) { printf("Session not initialized yet\n"); return 0; @@ -1509,7 +1656,7 @@ int cmd_sort_newset (char *arg) int cmd_scan(char *arg) { - if (!session) + if (!conn) { printf("Session not initialized yet\n"); return 0; @@ -1618,9 +1765,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"); @@ -1652,6 +1803,7 @@ static void initialize(void) fclose (inf); } #endif + cmd_base("Default"); } static int client(int wait) @@ -1664,6 +1816,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, ""}, @@ -1804,6 +1957,8 @@ static int client(int wait) 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); @@ -1820,13 +1975,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); } @@ -1841,16 +2001,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"))) @@ -1859,6 +2020,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); @@ -1866,7 +2030,10 @@ int main(int argc, char **argv) } } if (!opened) + { + initialize (); printf (C_PROMPT); + } return client (opened); }