X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=421cb16a473a85a4a183d2aa320ffcc220a22eb1;hp=7375649bef4afffbec769b05a97678c599392bc4;hb=b5bc2a31ad5125dc6d3ed1b6e626f0b9d22618bb;hpb=f94999cca65bd3464c1c6db8b5046e0a010b0c7f diff --git a/client/client.c b/client/client.c index 7375649..421cb16 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,22 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.65 1998-03-31 15:13:19 adam + * 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. + * + * 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 @@ -252,10 +267,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] = "?"; @@ -327,6 +342,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); @@ -370,26 +386,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.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); @@ -709,7 +786,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 @@ -788,7 +865,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; @@ -992,7 +1070,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; @@ -1000,14 +1078,14 @@ 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; @@ -1015,23 +1093,28 @@ static Z_External *CreateItemOrderExternal(int itemno) 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; @@ -1052,7 +1135,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 */ @@ -1100,6 +1183,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))) @@ -1129,35 +1229,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; @@ -1282,7 +1367,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; @@ -1304,12 +1389,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); @@ -1539,7 +1628,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; @@ -1570,7 +1659,7 @@ int cmd_sort_newset (char *arg) int cmd_scan(char *arg) { - if (!session) + if (!conn) { printf("Session not initialized yet\n"); return 0; @@ -1679,9 +1768,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"); @@ -1713,6 +1806,7 @@ static void initialize(void) fclose (inf); } #endif + cmd_base("Default"); } static int client(int wait) @@ -1725,6 +1819,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, ""}, @@ -1865,6 +1960,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); @@ -1881,13 +1978,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); } @@ -1902,16 +2004,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"))) @@ -1920,6 +2023,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); @@ -1927,7 +2033,10 @@ int main(int argc, char **argv) } } if (!opened) + { + initialize (); printf (C_PROMPT); + } return client (opened); }