X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=client%2Fclient.c;h=6be4576c8dd16a2fa6f423598a13ee956c6f796a;hp=f85f0e1da51a660908ad6f3f68887a72f71816fb;hb=26bc83eeda2418e09c32f2ca4c9327901568fe98;hpb=fb6d99a0c7e07d9cc4a315c447deaf6564a85505 diff --git a/client/client.c b/client/client.c index f85f0e1..6be4576 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: client.c,v 1.292 2005-06-25 15:46:01 adam Exp $ + * $Id: client.c,v 1.296 2005-08-24 11:25:34 heikki Exp $ */ #include @@ -133,6 +133,7 @@ static int scan_stepSize = 0; static int scan_position = 1; static int scan_size = 20; static char cur_host[200]; +static int last_hit_count = 0; typedef enum { QueryType_Prefix, @@ -405,7 +406,7 @@ static int process_initResponse(Z_InitResponse *res) if (oid->value == VAL_OCLCUI) { Z_OCLC_UserInformation *oclc_ui; ODR decode = odr_createmem(ODR_DECODE); - odr_setbuf(decode, sat->buf, sat->len, 0); + odr_setbuf(decode, (char *) sat->buf, sat->len, 0); if (!z_OCLC_UserInformation(decode, &oclc_ui, 0, 0)) printf ("Bad OCLC UserInformation:\n"); else @@ -1668,6 +1669,7 @@ static int process_searchResponse(Z_SearchResponse *res) else printf("Search was a bloomin' failure.\n"); printf("Number of hits: %d", *res->resultCount); + last_hit_count = *res->resultCount; if (setnumber >= 0) printf (", setno %d", setnumber); printf ("\n"); @@ -2132,6 +2134,11 @@ static int send_itemorder(const char *type, int itemno) static int only_z3950() { + if (!conn) + { + printf ("Not connected yet\n"); + return 1; + } if (protocol == PROTO_HTTP) { printf ("Not supported by SRW\n"); @@ -2165,7 +2172,7 @@ static int cmd_update_common(const char *arg, int version) Z_External *record_this = 0; if (only_z3950()) - return 0; + return 1; *action = 0; *recid = 0; sscanf (arg, "%19s %19s%n", action, recid, &noread); @@ -2313,43 +2320,49 @@ static int cmd_update_common(const char *arg, int version) static int cmd_xmles(const char *arg) { - int noread = 0; - char oid_str[51]; - int oid_value_xmles = VAL_XMLES; - Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest); - Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; - - Z_External *ext = (Z_External *) odr_malloc(out, sizeof(*ext)); - req->taskSpecificParameters = ext; - ext->descriptor = 0; - ext->which = Z_External_octet; - ext->u.single_ASN1_type = (Odr_oct *) odr_malloc (out, sizeof(Odr_oct)); - - sscanf(arg, "%50s%n", oid_str, &noread); - if (noread == 0) - { - printf("Missing OID for xmles\n"); - return 0; - } - arg += noread; - oid_value_xmles = oid_getvalbyname(oid_str); - if (oid_value_xmles == VAL_NONE) + if (only_z3950()) + return 1; + else { - printf("Bad OID: %s\n", oid_str); - return 0; + int noread = 0; + char oid_str[51]; + int oid_value_xmles = VAL_XMLES; + Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest); + Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest; + + Z_External *ext = (Z_External *) odr_malloc(out, sizeof(*ext)); + + req->taskSpecificParameters = ext; + ext->indirect_reference = 0; + ext->descriptor = 0; + ext->which = Z_External_octet; + ext->u.single_ASN1_type = (Odr_oct *) odr_malloc (out, sizeof(Odr_oct)); + sscanf(arg, "%50s%n", oid_str, &noread); + if (noread == 0) + { + printf("Missing OID for xmles\n"); + return 0; + } + arg += noread; + oid_value_xmles = oid_getvalbyname(oid_str); + if (oid_value_xmles == VAL_NONE) + { + printf("Bad OID: %s\n", oid_str); + return 0; + } + + if (parse_cmd_doc(&arg, out, (char **) &ext->u.single_ASN1_type->buf, + &ext->u.single_ASN1_type->len, 0) == 0) + return 0; + req->packageType = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV, + oid_value_xmles); + + ext->direct_reference = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV, + oid_value_xmles); + send_apdu(apdu); + + return 2; } - - if (parse_cmd_doc(&arg, out, (char **) &ext->u.single_ASN1_type->buf, - &ext->u.single_ASN1_type->len, 0) == 0) - return 0; - req->packageType = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV, - oid_value_xmles); - - ext->direct_reference = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV, - oid_value_xmles); - send_apdu(apdu); - - return 2; } static int cmd_itemorder(const char *arg) @@ -2358,7 +2371,7 @@ static int cmd_itemorder(const char *arg) int itemno; if (only_z3950()) - return 0; + return 1; if (sscanf (arg, "%10s %d", type, &itemno) != 2) return 0; @@ -2431,8 +2444,8 @@ static int cmd_init(const char *arg) strncpy (cur_host, arg, sizeof(cur_host)-1); cur_host[sizeof(cur_host)-1] = 0; } - if (!conn || protocol != PROTO_Z3950) - return 0; + if (only_z3950()) + return 1; send_initRequest(cur_host); return 2; } @@ -2476,11 +2489,6 @@ static int cmd_find(const char *arg) static int cmd_delete(const char *arg) { - if (!conn) - { - printf("Not connected yet\n"); - return 0; - } if (only_z3950()) return 0; if (!send_deleteResultSetRequest(arg)) @@ -2497,8 +2505,6 @@ static int cmd_ssub(const char *arg) static int cmd_lslb(const char *arg) { - if (only_z3950()) - return 0; if (!(largeSetLowerBound = atoi(arg))) return 0; return 1; @@ -2506,8 +2512,6 @@ static int cmd_lslb(const char *arg) static int cmd_mspn(const char *arg) { - if (only_z3950()) - return 0; if (!(mediumSetPresentNumber = atoi(arg))) return 0; return 1; @@ -2556,7 +2560,15 @@ static void parse_show_args(const char *arg_c, char *setstring, *p = '\0'; } if (*arg) - *start = atoi(arg); + { + if (!strcmp(arg, "all")) + { + *number = last_hit_count; + *start = 1; + } + else + *start = atoi(arg); + } if (p && (p=strchr(p+1, '+'))) strcpy (setstring, p+1); else if (setnumber >= 0) @@ -2664,6 +2676,7 @@ static void close_session (void) odr_reset(out); odr_reset(in); odr_reset(print); + last_hit_count = 0; } void process_close(Z_Close *req) @@ -2741,11 +2754,6 @@ int cmd_cancel(const char *arg) apdu->u.triggerResourceControlRequest; bool_t rfalse = 0; - if (!conn) - { - printf("Session not initialized yet\n"); - return 0; - } if (only_z3950()) return 0; if (session_initResponse && @@ -2968,11 +2976,6 @@ void process_deleteResultSetResponse (Z_DeleteResultSetResponse *res) int cmd_sort_generic(const char *arg, int newset) { - if (!conn) - { - printf("Session not initialized yet\n"); - return 0; - } if (only_z3950()) return 0; if (session_initResponse && @@ -3178,11 +3181,8 @@ int cmd_close(const char *arg) { Z_APDU *apdu; Z_Close *req; - if (!conn) - return 0; if (only_z3950()) return 0; - apdu = zget_APDU(out, Z_APDU_close); req = apdu->u.close; *req->closeReason = Z_Close_finished; @@ -4245,6 +4245,7 @@ static struct { } cmd_array[] = { {"open", cmd_open, "('tcp'|'ssl')':[':'][/]",NULL,0,NULL}, {"quit", cmd_quit, "",NULL,0,NULL}, + {"exit", cmd_quit, "",NULL,0,NULL}, {"find", cmd_find, "",NULL,0,NULL}, {"delete", cmd_delete, "",NULL,0,NULL}, {"base", cmd_base, "",NULL,0,NULL}, @@ -4422,7 +4423,7 @@ int cmd_register_tab(const char* arg) { void process_cmd_line(char* line) { - int i,res; + int i, res; char word[32], arg[10240]; #if HAVE_GETTIMEOFDAY