/*
- * Copyright (c) 1995-2000, Index Data.
+ * Copyright (c) 1995-2001, Index Data.
* See the file LICENSE for details.
*
* NT Service interface by
* Chas Woodfield, Fretwell Downing Datasystems.
*
* $Log: ztest.c,v $
- * Revision 1.32 2000-04-05 07:39:55 adam
+ * Revision 1.45 2001-10-29 09:17:19 adam
+ * New function marc_display_exl - used by YAZ client. Server returns
+ * bad record on position 98 (for testing).
+ *
+ * Revision 1.44 2001/07/19 19:51:42 adam
+ * Added typecasts to make C++ happy.
+ *
+ * Revision 1.43 2001/06/28 09:27:25 adam
+ * Number of Extended Services Requests logged.
+ *
+ * Revision 1.42 2001/04/06 12:26:46 adam
+ * Optional CCL module. Moved atoi_n to marcdisp.h from yaz-util.h.
+ *
+ * Revision 1.41 2001/04/05 13:08:48 adam
+ * New configure options: --enable-module.
+ *
+ * Revision 1.40 2001/03/25 21:55:13 adam
+ * Added odr_intdup. Ztest server returns TaskPackage for ItemUpdate.
+ *
+ * Revision 1.39 2001/03/12 14:40:57 adam
+ * Minor change of print of item update info.
+ *
+ * Revision 1.38 2001/02/21 13:46:54 adam
+ * C++ fixes.
+ *
+ * Revision 1.37 2001/02/20 11:25:32 adam
+ * Added ill_get_APDU and ill_get_Cancel.
+ *
+ * Revision 1.36 2001/01/30 21:34:18 adam
+ * Added step-size for Scan backend interface.
+ *
+ * Revision 1.35 2000/11/23 10:58:33 adam
+ * SSL comstack support. Separate POSIX thread support library.
+ *
+ * Revision 1.34 2000/09/04 08:58:15 adam
+ * Added prefix yaz_ for most logging utility functions.
+ *
+ * Revision 1.33 2000/08/10 08:41:26 adam
+ * Fixes for ILL.
+ *
+ * Revision 1.32 2000/04/05 07:39:55 adam
* Added shared library support (libtool).
*
* Revision 1.31 2000/01/31 13:15:21 adam
#include <yaz/backend.h>
#include <yaz/log.h>
-#ifdef ASN_COMPILED
+#if YAZ_MODULE_ill
#include <yaz/ill.h>
#endif
int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
{
- yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
+ /* user-defined handle - created in bend_init */
+ int *counter = (int*) handle;
+
+ yaz_log(LOG_LOG, "ESRequest no %d", *counter);
+
+ (*counter)++;
+
if (rr->esr->packageName)
yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
+
+ yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
+
if (!rr->esr->taskSpecificParameters)
{
yaz_log (LOG_WARN, "No task specific parameters");
yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId);
yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item);
}
-#ifdef ASN_COMPILED
+#if YAZ_MODULE_ill
if (n->itemRequest)
{
Z_External *r = (Z_External*) n->itemRequest;
ILL_ItemRequest *item_req = 0;
- ILL_Request *ill_req = 0;
+ ILL_APDU *ill_apdu = 0;
if (r->direct_reference)
{
oident *ent = oid_getentbyoid(r->direct_reference);
if (ent)
yaz_log(LOG_LOG, "OID %s", ent->desc);
+ if (ent && ent->value == VAL_TEXT_XML)
+ {
+ yaz_log (LOG_LOG, "ILL XML request");
+ if (r->which == Z_External_octet)
+ yaz_log (LOG_LOG, "%.*s", r->u.octet_aligned->len,
+ r->u.octet_aligned->buf);
+ }
if (ent && ent->value == VAL_ISO_ILL_1)
{
- yaz_log (LOG_LOG, "ItemRequest");
+ yaz_log (LOG_LOG, "Decode ItemRequest begin");
if (r->which == ODR_EXTERNAL_single)
{
odr_setbuf(rr->decode,
- r->u.single_ASN1_type->buf,
+ (char *) r->u.single_ASN1_type->buf,
r->u.single_ASN1_type->len, 0);
if (!ill_ItemRequest (rr->decode, &item_req, 0, 0))
"Couldn't decode ItemRequest %s near %d",
odr_errmsg(odr_geterror(rr->decode)),
odr_offset(rr->decode));
+#if 0
yaz_log(LOG_LOG, "PDU dump:");
- odr_dumpBER(log_file(),
+ odr_dumpBER(yaz_log_file(),
r->u.single_ASN1_type->buf,
r->u.single_ASN1_type->len);
+#endif
}
+ else
+ yaz_log(LOG_LOG, "Decode ItemRequest OK");
if (rr->print)
{
ill_ItemRequest (rr->print, &item_req, 0,
}
if (!item_req && r->which == ODR_EXTERNAL_single)
{
- yaz_log (LOG_LOG, "ILLRequest");
+ yaz_log (LOG_LOG, "Decode ILL APDU begin");
odr_setbuf(rr->decode,
- r->u.single_ASN1_type->buf,
+ (char*) r->u.single_ASN1_type->buf,
r->u.single_ASN1_type->len, 0);
- if (!ill_Request (rr->decode, &ill_req, 0, 0))
+ if (!ill_APDU (rr->decode, &ill_apdu, 0, 0))
{
yaz_log (LOG_LOG,
- "Couldn't decode ILLRequest %s near %d",
+ "Couldn't decode ILL APDU %s near %d",
odr_errmsg(odr_geterror(rr->decode)),
odr_offset(rr->decode));
yaz_log(LOG_LOG, "PDU dump:");
- odr_dumpBER(log_file(),
- r->u.single_ASN1_type->buf,
+ odr_dumpBER(yaz_log_file(),
+ (char *) r->u.single_ASN1_type->buf,
r->u.single_ASN1_type->len);
}
+ else
+ yaz_log(LOG_LOG, "Decode ILL APDU OK");
if (rr->print)
{
- ill_Request (rr->print, &ill_req, 0,
- "ILLRequest");
+ ill_APDU (rr->print, &ill_apdu, 0,
+ "ILL APDU");
odr_reset (rr->print);
}
}
yaz_log (LOG_LOG, " recordInsert");
break;
case Z_IUOriginPartToKeep_recordReplace:
- yaz_log (LOG_LOG, " recordUpdate");
+ yaz_log (LOG_LOG, " recordReplace");
break;
case Z_IUOriginPartToKeep_recordDelete:
yaz_log (LOG_LOG, " recordDelete");
if (!strcmp(toKeep->databaseName, "accept"))
rr->errcode = -1;
}
+ if (toKeep)
+ {
+ Z_External *ext = (Z_External *)
+ odr_malloc (rr->stream, sizeof(*ext));
+ Z_IUOriginPartToKeep *keep = (Z_IUOriginPartToKeep *)
+ odr_malloc (rr->stream, sizeof(*keep));
+ Z_IUTargetPart *targetPart = (Z_IUTargetPart *)
+ odr_malloc (rr->stream, sizeof(*targetPart));
+ rr->taskPackage = (Z_TaskPackage *)
+ odr_malloc (rr->stream, sizeof(*rr->taskPackage));
+ rr->taskPackage->packageType =
+ odr_oiddup (rr->stream, rr->esr->packageType);
+ rr->taskPackage->packageName = 0;
+ rr->taskPackage->userId = 0;
+ rr->taskPackage->retentionTime = 0;
+ rr->taskPackage->permissions = 0;
+ rr->taskPackage->description = 0;
+ rr->taskPackage->targetReference = (Odr_oct *)
+ odr_malloc (rr->stream, sizeof(Odr_oct));
+ rr->taskPackage->targetReference->buf =
+ (unsigned char *) odr_strdup (rr->stream, "123");
+ rr->taskPackage->targetReference->len =
+ rr->taskPackage->targetReference->size =
+ strlen((char *) (rr->taskPackage->targetReference->buf));
+ rr->taskPackage->creationDateTime = 0;
+ rr->taskPackage->taskStatus = odr_intdup(rr->stream, 0);
+ rr->taskPackage->packageDiagnostics = 0;
+ rr->taskPackage->taskSpecificParameters = ext;
+
+ ext->direct_reference =
+ odr_oiddup (rr->stream, rr->esr->packageType);
+ ext->indirect_reference = 0;
+ ext->descriptor = 0;
+ ext->which = Z_External_update;
+ ext->u.update = (Z_IUUpdate *)
+ odr_malloc (rr->stream, sizeof(*ext->u.update));
+ ext->u.update->which = Z_IUUpdate_taskPackage;
+ ext->u.update->u.taskPackage = (Z_IUUpdateTaskPackage *)
+ odr_malloc (rr->stream, sizeof(Z_IUUpdateTaskPackage));
+ ext->u.update->u.taskPackage->originPart = keep;
+ ext->u.update->u.taskPackage->targetPart = targetPart;
+
+ keep->action = (int *) odr_malloc (rr->stream, sizeof(int));
+ *keep->action = *toKeep->action;
+ keep->databaseName =
+ odr_strdup (rr->stream, toKeep->databaseName);
+ keep->schema = 0;
+ keep->elementSetName = 0;
+ keep->actionQualifier = 0;
+
+ targetPart->updateStatus = odr_intdup (rr->stream, 1);
+ targetPart->num_globalDiagnostics = 0;
+ targetPart->globalDiagnostics = (Z_DiagRec **) odr_nullval();
+ targetPart->num_taskPackageRecords = 0;
+ targetPart->taskPackageRecords =
+ (Z_IUTaskPackageRecordStructure **) odr_nullval();
+ }
if (notToKeep)
{
int i;
if (!inf)
return NULL;
- while (--num >= 0)
+ if (num == 98)
+ { /* this will generate a very bad MARC record (testing only) */
+ buf = (char*) odr_malloc(odr, 2101);
+ memset(buf, '7', 2100);
+ buf[2100] = '\0';
+ }
+ else
{
- if (num == 98)
- {
- buf = (char*) odr_malloc(odr, 2101);
- memset(buf, 'A', 2100);
- buf[2100] = '\0';
- break;
- }
- else
- buf = marc_read (inf, odr);
- if (!num || !buf)
- break;
+ /* OK, try to get proper MARC records from the file */
+ while (--num >= 0)
+ {
+ buf = marc_read (inf, odr);
+ if (!buf)
+ break;
+ }
}
fclose(inf);
- if (num < 0)
- return 0;
return buf;
}
r->output_format = r->request_format;
if (r->request_format == VAL_SUTRS)
{
+#if 0
+/* this section returns a huge record (for testing non-blocking write, etc) */
+ r->len = 980000;
+ r->record = odr_malloc (r->stream, r->len);
+ memset (r->record, 'x', r->len);
+#else
+/* this section returns a small record */
char buf[100];
sprintf(buf, "This is dummy SUTRS record number %d\n", r->number);
+
r->len = strlen(buf);
r->record = (char *) odr_malloc (r->stream, r->len+1);
strcpy(r->record, buf);
+#endif
}
else if (r->request_format == VAL_GRS1)
{
q->errcode = 229; /* unsupported term type */
return 0;
}
+ if (*q->step_size != 0)
+ {
+ q->errcode = 205; /*Only zero step size supported for Scan */
+ return 0;
+ }
if (q->term->term->u.general->len >= 80)
{
q->errcode = 11; /* term too long */
bend_initresult *bend_init(bend_initrequest *q)
{
bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r));
- static char *dummy = "Hej fister";
+ int *counter = (int *) xmalloc (sizeof(int));
+ *counter = 0;
r->errcode = 0;
r->errstring = 0;
- r->handle = dummy;
+ r->handle = counter; /* user handle, in this case a simple int */
q->bend_sort = ztest_sort; /* register sort handler */
q->bend_search = ztest_search; /* register search handler */
q->bend_present = ztest_present; /* register present handle */
void bend_close(void *handle)
{
+ xfree (handle); /* release our user-defined handle */
return;
}