* Sebastian Hammer, Adam Dickmeiss
*
* $Log: client.c,v $
- * Revision 1.65 1998-03-31 15:13:19 adam
+ * Revision 1.73 1998-10-20 13:55:43 quinn
+ * Fixed Scan bug in asn and client
+ *
+ * Revision 1.72 1998/10/20 13:23:15 quinn
+ * changed preferred pos to 1
+ *
+ * Revision 1.71 1998/10/20 13:21:43 adam
+ * Fixed scan response handler.
+ *
+ * Revision 1.70 1998/09/22 09:40:37 adam
+ * Minor changes in sort spec.
+ *
+ * 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 <resultset>' 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
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] = "?";
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);
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 <database> <database> ...\n");
+ return 0;
+ }
+ for (i = 0; i<num_databaseNames; i++)
+ xfree (databaseNames[i]);
+ num_databaseNames = 0;
+ while (1)
+ {
+ if (!(cp = strchr(arg, ' ')))
+ cp = arg + strlen(arg);
+ if (cp - arg < 1)
+ break;
+ databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
+ memcpy (databaseNames[num_databaseNames], arg, cp - arg);
+ databaseNames[num_databaseNames++][cp - arg] = '\0';
+ if (!*cp)
+ break;
+ arg = cp+1;
+ }
+ return 1;
+}
+
+
int cmd_open(char *arg)
{
void *add;
- char type[100], addr[100];
+ char type[100], addr[100], base[100];
CS_TYPE t;
if (conn)
{
printf("Already connected.\n");
- return 0;
+
+ cs_close (conn);
+ conn = NULL;
+ if (session_mem)
+ {
+ nmem_destroy (session_mem);
+ session_mem = NULL;
+ }
}
- if (!*arg || sscanf(arg, "%[^:]:%s", type, addr) < 2)
+ 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 (*base)
+ cmd_base (base);
if (!strcmp(type, "tcp"))
{
t = tcpip_type;
}
}
+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_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);
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
#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;
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;
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;
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;
/* 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 */
fflush(stdout);
send_itemorder(arg);
- return(1);
+ return(2);
}
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)))
return 1;
}
-static int cmd_base(char *arg)
-{
- int i;
- char *cp;
-
- if (!*arg)
- {
- printf("Usage: base <database> <database> ...\n");
- return 0;
- }
- for (i = 0; i<num_databaseNames; i++)
- xfree (databaseNames[i]);
- num_databaseNames = 0;
- while (1)
- {
- if (!(cp = strchr(arg, ' ')))
- cp = arg + strlen(arg);
- if (cp - arg < 1)
- break;
- databaseNames[num_databaseNames] = (char *)xmalloc (1 + cp - arg);
- memcpy (databaseNames[num_databaseNames], arg, cp - arg);
- databaseNames[num_databaseNames++][cp - arg] = '\0';
- if (!*cp)
- break;
- arg = cp+1;
- }
- return 1;
-}
-
static int cmd_setnames(char *arg)
{
if (setnumber < 0)
req->diagnosticInformation ? 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;
apdu->u.triggerResourceControlRequest;
bool_t rfalse = 0;
- if (!session)
+ if (!conn)
{
printf("Session not initialized yet\n");
return 0;
{
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);
case 'a':
case 'A':
case '>':
- *sks->sortRelation = Z_SortRelation_ascending;
+ *sks->sortRelation = Z_SortRelation_descending;
break;
case 'd':
case 'D':
case '<':
- *sks->sortRelation = Z_SortRelation_descending;
+ *sks->sortRelation = Z_SortRelation_ascending;
break;
case 'i':
case 'I':
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)
- {
- entries = res->entries->u.entries->entries;
- num_entries = res->entries->u.entries->num_entries;
- }
-#endif
for (i = 0; i < num_entries; i++)
+ {
+ int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
if (entries[i]->which == Z_Entry_termInfo)
{
- printf("%c ", i + 1 == *res->positionOfTerm ? '*' : ' ');
+ printf("%c ", i + 1 == pos_term ? '*' : ' ');
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)
int cmd_sort_generic(char *arg, int newset)
{
- if (!session)
+ if (!conn)
{
printf("Session not initialized yet\n");
return 0;
int cmd_scan(char *arg)
{
- if (!session)
+ if (!conn)
{
printf("Session not initialized yet\n");
return 0;
}
if (*arg)
{
- if (send_scanrequest(arg, 5, 20) < 0)
+ if (send_scanrequest(arg, 1, 20) < 0)
return 0;
}
else
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");
fclose (inf);
}
#endif
+ cmd_base("Default");
}
static int client(int wait)
{"open", cmd_open, "('tcp'|'osi')':'[<tsel>'/']<host>[':'<port>]"},
{"quit", cmd_quit, ""},
{"find", cmd_find, "<query>"},
+ {"delete", cmd_delete, "<setname>"},
{"base", cmd_base, "<base-name>"},
{"show", cmd_show, "<rec#>['+'<#recs>['+'<setname>]]"},
{"scan", cmd_scan, "<term>"},
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);
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);
}
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")))
exit (1);
}
break;
+ case 'v':
+ log_init (log_mask_str(arg), "", NULL);
+ break;
default:
fprintf (stderr, "Usage: %s [-m <marclog>] [<server-addr>]\n",
prog);
}
}
if (!opened)
+ {
+ initialize ();
printf (C_PROMPT);
+ }
return client (opened);
}