X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=client%2Fclient.c;h=6b82f5a581703e2099e61ac3abd7bca4fa486217;hb=4b89c0a02975f8140f079e5883692a7de30126be;hp=2dae9b337d8d54250b0e7a25c2abef194d3ecd58;hpb=a6eef2e7073a7295d1a7bf09f538946135a5ebbb;p=yaz-moved-to-github.git diff --git a/client/client.c b/client/client.c index 2dae9b3..6b82f5a 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,29 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.99 2000-03-20 19:06:25 adam + * Revision 1.106 2000-11-13 09:44:59 adam + * Work on SCAN: RPN2CCL conversion and proper "next" scan. + * + * Revision 1.105 2000/10/02 11:07:44 adam + * Added peer_name member for bend_init handler. Changed the YAZ + * client so that tcp: can be avoided in target spec. + * + * Revision 1.104 2000/09/04 08:58:15 adam + * Added prefix yaz_ for most logging utility functions. + * + * Revision 1.103 2000/08/10 08:41:26 adam + * Fixes for ILL. + * + * Revision 1.102 2000/05/18 11:57:04 adam + * Client display time elapsed. + * + * Revision 1.101 2000/04/05 07:39:54 adam + * Added shared library support (libtool). + * + * Revision 1.100 2000/03/20 19:29:59 adam + * Minor change. + * + * Revision 1.99 2000/03/20 19:06:25 adam * Added Segment request for fronend server. Work on admin for client. * * Revision 1.98 2000/03/16 13:55:49 ian @@ -381,7 +403,9 @@ static enum oid_value schema = VAL_NONE; static int sent_close = 0; 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_scan_line[512] = "0"; +static char last_scan_query[512] = "0"; + static char last_cmd[100] = "?"; static FILE *marcdump = 0; static char *refid = NULL; @@ -545,7 +569,8 @@ static int cmd_base(char *arg) int cmd_open(char *arg) { void *add; - char type[100], addr[100], base[100]; + char type_and_host[101], base[101]; + char *host = 0; CS_TYPE t; if (conn) @@ -561,37 +586,23 @@ int cmd_open(char *arg) } } base[0] = '\0'; - if (!*arg || sscanf(arg, "%[^:]:%[^/]/%s", type, addr, base) < 2) - { - fprintf(stderr, "Usage: open (osi|tcp) ':' [tsel '/']host[':'port]\n"); - return 0; - } + if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1) + return 0; + if (strncmp (type_and_host, "tcp:", 4) == 0) + host = type_and_host + 4; + else + host = type_and_host; if (*base) cmd_base (base); - if (!strcmp(type, "tcp")) - { - t = tcpip_type; - protocol = PROTO_Z3950; - } - else -#ifdef USE_XTIMOSI - if (!strcmp(type, "osi")) - { - t = mosi_type; - protocol = PROTO_SR; - } - else -#endif - { - fprintf(stderr, "Bad type: %s\n", type); - return 0; - } + t = tcpip_type; + protocol = PROTO_Z3950; + if (!(conn = cs_create(t, 1, protocol))) { perror("cs_create"); return 0; } - if (!(add = cs_straddr(conn, addr))) + if (!(add = cs_straddr(conn, host))) { perror(arg); return 0; @@ -1253,11 +1264,7 @@ void process_ESResponse(Z_ExtendedServicesResponse *res) const char *get_ill_element (void *clientData, const char *element) { - /* printf ("asking for %s\n", element); */ - if (!strcmp (element, "ill,transaction-id,transaction-group-qualifier")) - return "1"; - if (!strcmp (element, "ill,transaction-id,transaction-qualifier")) - return "1"; + printf ("%s\n", element); return 0; } @@ -1274,7 +1281,9 @@ static Z_External *create_external_itemRequest() ctl.f = get_ill_element; req = ill_get_ItemRequest(&ctl, "ill", 0); - + if (!req) + printf ("ill_get_ItemRequest failed\n"); + if (!ill_ItemRequest (out, &req, 0, 0)) { if (apdu_file) @@ -1431,21 +1440,20 @@ static Z_External *create_ItemOrderExternal(const char *type, int itemno) (int *) odr_malloc(out, sizeof(int)); *r->u.itemOrder->u.esRequest->notToKeep->resultSetItem->item = itemno; - switch (*type) + if (!strcmp (type, "item") || !strcmp(type, "2")) { - case '2': printf ("using item-request\n"); r->u.itemOrder->u.esRequest->notToKeep->itemRequest = create_external_itemRequest(); - break; - case '1': + } + else if (!strcmp(type, "ill") || !strcmp(type, "1")) + { printf ("using ILL-request\n"); r->u.itemOrder->u.esRequest->notToKeep->itemRequest = create_external_ILLRequest(); - break; - default: - r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0; } + else + r->u.itemOrder->u.esRequest->notToKeep->itemRequest = 0; return r; } @@ -1797,17 +1805,58 @@ int cmd_cancel(char *arg) return 2; } -int send_scanrequest(char *string, int pp, int num) +int send_scanrequest(const char *query, int pp, int num, const char *term) { Z_APDU *apdu = zget_APDU(out, Z_APDU_scanRequest); Z_ScanRequest *req = apdu->u.scanRequest; + int use_rpn = 1; + int oid[OID_SIZE]; - if (!(req->termListAndStartPoint = - p_query_scan(out, protocol, &req->attributeSet, string))) +#if CCL2RPN + if (queryType == QueryType_CCL2RPN) + { + oident bib1; + int error, pos; + struct ccl_rpn_node *rpn; + + rpn = ccl_find_str (bibset, query, &error, &pos); + if (error) + { + printf("CCL ERROR: %s\n", ccl_err_msg(error)); + return 0; + } + use_rpn = 0; + bib1.proto = PROTO_Z3950; + bib1.oclass = CLASS_ATTSET; + bib1.value = VAL_BIB1; + req->attributeSet = oid_ent_to_oid (&bib1, oid); + if (!(req->termListAndStartPoint = ccl_scan_query (out, rpn))) + { + printf("Couldn't convert CCL to Scan term\n"); + return 0; + } + ccl_rpn_delete (rpn); + } +#endif + if (use_rpn && !(req->termListAndStartPoint = + p_query_scan(out, protocol, &req->attributeSet, query))) { printf("Prefix query error\n"); return -1; } + if (term && *term) + { + if (req->termListAndStartPoint->term && + req->termListAndStartPoint->term->which == Z_Term_general && + req->termListAndStartPoint->term->u.general) + { + req->termListAndStartPoint->term->u.general->buf = + odr_strdup(out, term); + req->termListAndStartPoint->term->u.general->len = + req->termListAndStartPoint->term->u.general->size = + strlen(term); + } + } req->referenceId = set_refid (out); req->num_databaseNames = num_databaseNames; req->databaseNames = databaseNames; @@ -1953,13 +2002,16 @@ void display_term(Z_TermInfo *t) { if (t->term->which == Z_Term_general) { - printf("%.*s (%d)\n", t->term->u.general->len, t->term->u.general->buf, - t->globalOccurrences ? *t->globalOccurrences : -1); - sprintf(last_scan, "%.*s", t->term->u.general->len, + printf("%.*s", t->term->u.general->len, t->term->u.general->buf); + sprintf(last_scan_line, "%.*s", t->term->u.general->len, t->term->u.general->buf); } else - printf("Term type not general.\n"); + printf("Term (not general)"); + if (t->globalOccurrences) + printf (" (%d)\n", *t->globalOccurrences); + else + printf ("\n"); } void process_scanResponse(Z_ScanResponse *res) @@ -2083,12 +2135,15 @@ int cmd_scan(char *arg) } if (*arg) { - if (send_scanrequest(arg, 1, 20) < 0) + strcpy (last_scan_query, arg); + if (send_scanrequest(arg, 1, 20, 0) < 0) return 0; } else - if (send_scanrequest(last_scan, 1, 20) < 0) + { + if (send_scanrequest(last_scan_query, 1, 20, last_scan_line) < 0) return 0; + } return 2; } @@ -2269,24 +2324,30 @@ static int client(int wait) {"attributeset", cmd_attributeset, ""}, {"querytype", cmd_querytype, ""}, {"refid", cmd_refid, ""}, - {"itemorder", cmd_itemorder, "1|2 "}, + {"itemorder", cmd_itemorder, "ill|item "}, {"update", cmd_update, ""}, +#ifdef ASN_COMPILED /* Server Admin Functions */ {"adm-reindex", cmd_adm_reindex, ""}, {"adm-truncate", cmd_adm_truncate, "('database'|'index')"}, - {"adm-create", cmd_adm_create, ""}, - {"adm-delete", cmd_adm_delete, "('database'|'index')"}, - {"adm-import", cmd_adm_import, " "}, - {"adm-refresh", cmd_adm_refresh, ""}, + {"adm-create", cmd_adm_create, ""}, + {"adm-drop", cmd_adm_drop, "('database'|'index')"}, + {"adm-import", cmd_adm_import, " "}, + {"adm-refresh", cmd_adm_refresh, ""}, {"adm-commit", cmd_adm_commit, ""}, {"adm-shutdown", cmd_adm_shutdown, ""}, {"adm-startup", cmd_adm_startup, ""}, +#endif {0,0} }; char *netbuffer= 0; int netbufferlen = 0; int i; Z_APDU *apdu; +#if HAVE_GETTIMEOFDAY + struct timeval tv_start, tv_end; + gettimeofday (&tv_start, 0); +#endif while (1) { @@ -2333,6 +2394,10 @@ static int client(int wait) if ((end_p = strchr (line, '\n'))) *end_p = '\0'; #endif +#if HAVE_GETTIMEOFDAY + gettimeofday (&tv_start, 0); +#endif + if ((res = sscanf(line, "%s %[^;]", word, arg)) <= 0) { strcpy(word, last_cmd); @@ -2447,6 +2512,15 @@ static int client(int wait) } } 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 } } return 0; @@ -2485,10 +2559,10 @@ int main(int argc, char **argv) apdu_file=fopen(arg, "a"); break; case 'v': - log_init (log_mask_str(arg), "", NULL); + yaz_log_init (yaz_log_mask_str(arg), "", NULL); break; default: - fprintf (stderr, "Usage: %s [-m ] [ -m ] " + fprintf (stderr, "Usage: %s [-m ] [ -a ] " "[]\n", prog); exit (1);