* Sebastian Hammer, Adam Dickmeiss
*
* $Log: client.c,v $
- * Revision 1.101 2000-04-05 07:39:54 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
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;
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)
}
}
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;
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;
}
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)
(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;
}
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;
{
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)
}
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;
}
{"attributeset", cmd_attributeset, "<attrset>"},
{"querytype", cmd_querytype, "<type>"},
{"refid", cmd_refid, "<id>"},
- {"itemorder", cmd_itemorder, "1|2 <item>"},
+ {"itemorder", cmd_itemorder, "ill|item <itemno>"},
{"update", cmd_update, "<item>"},
#ifdef ASN_COMPILED
/* Server Admin Functions */
int netbufferlen = 0;
int i;
Z_APDU *apdu;
+#if HAVE_GETTIMEOFDAY
+ struct timeval tv_start, tv_end;
+ gettimeofday (&tv_start, 0);
+#endif
while (1)
{
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);
}
}
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;
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 <marclog>] [ -m <apdulog>] "
+ fprintf (stderr, "Usage: %s [-m <marclog>] [ -a <apdulog>] "
"[<server-addr>]\n",
prog);
exit (1);