/*
- * Copyright (c) 1995-1998, Index Data.
+ * Copyright (c) 1995-1999, Index Data.
* See the file LICENSE for details.
* Sebastian Hammer, Adam Dickmeiss
*
* Chas Woodfield, Fretwell Downing Datasystems.
*
* $Log: ztest.c,v $
- * Revision 1.19 1998-10-20 15:16:22 adam
+ * Revision 1.26 1999-08-27 09:40:32 adam
+ * Renamed logf function to yaz_log. Removed VC++ project files.
+ *
+ * Revision 1.25 1999/06/01 14:29:12 adam
+ * Work on Extended Services.
+ *
+ * Revision 1.24 1999/05/27 13:07:54 adam
+ * Fix.
+ *
+ * Revision 1.23 1999/05/27 13:02:20 adam
+ * Assigned OID for old DB Update (VAL_DBUPDATE0).
+ *
+ * Revision 1.22 1999/05/26 13:49:12 adam
+ * DB Update implemented in client (very basic).
+ *
+ * Revision 1.21 1998/12/15 12:45:42 adam
+ * Minor change.
+ *
+ * Revision 1.20 1998/12/14 14:48:05 adam
+ * Fixed memory leak - happened when fetching MARC records.
+ *
+ * Revision 1.19 1998/10/20 15:16:22 adam
* Minor change to prevent warning.
*
* Revision 1.18 1998/10/20 15:13:45 adam
#include <assert.h>
#include <backend.h>
-#include <xmalloc.h>
#include <proto.h>
#include <log.h>
int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
{
- logf(LOG_LOG, "function: %d", *rr->esr->function);
+ yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
if (rr->esr->packageName)
- logf(LOG_LOG, "packagename: %s", rr->esr->packageName);
- logf(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
+ yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
+ yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
if (!rr->esr->taskSpecificParameters)
{
- logf (LOG_WARN, "No task specific parameters");
+ yaz_log (LOG_WARN, "No task specific parameters");
}
- else if (rr->esr->taskSpecificParameters->which != Z_External_itemOrder)
- {
- logf (LOG_WARN, "Not Item Order %d", rr->esr->taskSpecificParameters->which);
- }
- else
+ else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
{
Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder;
+ yaz_log (LOG_LOG, "Received ItemOrder");
switch (it->which)
{
#ifdef ASN_COMPILED
if (k && k->contact)
{
if (k->contact->name)
- logf(LOG_LOG, "contact name %s", k->contact->name);
+ yaz_log(LOG_LOG, "contact name %s", k->contact->name);
if (k->contact->phone)
- logf(LOG_LOG, "contact phone %s", k->contact->phone);
+ yaz_log(LOG_LOG, "contact phone %s", k->contact->phone);
if (k->contact->email)
- logf(LOG_LOG, "contact email %s", k->contact->email);
+ yaz_log(LOG_LOG, "contact email %s", k->contact->email);
}
if (k->addlBilling)
{
- logf(LOG_LOG, "Billing info (not shown)");
+ yaz_log(LOG_LOG, "Billing info (not shown)");
}
if (n->resultSetItem)
{
- logf(LOG_LOG, "resultsetItem");
- logf(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId);
- logf(LOG_LOG, "item: %d", *n->resultSetItem->item);
+ yaz_log(LOG_LOG, "resultsetItem");
+ yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId);
+ yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item);
}
}
break;
}
}
- rr->errcode = 0;
+ else if (rr->esr->taskSpecificParameters->which == Z_External_update)
+ {
+ Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
+ yaz_log (LOG_LOG, "Received DB Update");
+ if (up->which == Z_IUUpdate_esRequest)
+ {
+ Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
+ Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
+ Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
+
+ yaz_log (LOG_LOG, "action");
+ if (toKeep->action)
+ {
+ switch (*toKeep->action)
+ {
+ case Z_IUOriginPartToKeep_recordInsert:
+ yaz_log (LOG_LOG, " recordInsert");
+ break;
+ case Z_IUOriginPartToKeep_recordReplace:
+ yaz_log (LOG_LOG, " recordUpdate");
+ break;
+ case Z_IUOriginPartToKeep_recordDelete:
+ yaz_log (LOG_LOG, " recordDelete");
+ break;
+ case Z_IUOriginPartToKeep_elementUpdate:
+ yaz_log (LOG_LOG, " elementUpdate");
+ break;
+ case Z_IUOriginPartToKeep_specialUpdate:
+ yaz_log (LOG_LOG, " specialUpdate");
+ break;
+ default:
+ yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);
+ }
+ }
+ if (toKeep->databaseName)
+ {
+ yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);
+ if (!strcmp(toKeep->databaseName, "fault"))
+ {
+ rr->errcode = 109;
+ rr->errstring = toKeep->databaseName;
+ }
+ if (!strcmp(toKeep->databaseName, "accept"))
+ rr->errcode = -1;
+ }
+ if (notToKeep)
+ {
+ int i;
+ for (i = 0; i < notToKeep->num; i++)
+ {
+ Z_External *rec = notToKeep->elements[i]->record;
+
+ if (rec->direct_reference)
+ {
+ struct oident *oident;
+ oident = oid_getentbyoid(rec->direct_reference);
+ if (oident)
+ yaz_log (LOG_LOG, "record %d type %s", i,
+ oident->desc);
+ }
+ switch (rec->which)
+ {
+ case Z_External_sutrs:
+ if (rec->u.octet_aligned->len > 170)
+ yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+ rec->u.sutrs->len,
+ rec->u.sutrs->buf);
+ else
+ yaz_log (LOG_LOG, "%d bytes:\n%s",
+ rec->u.sutrs->len,
+ rec->u.sutrs->buf);
+ break;
+ case Z_External_octet :
+ if (rec->u.octet_aligned->len > 170)
+ yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+ rec->u.octet_aligned->len,
+ rec->u.octet_aligned->buf);
+ else
+ yaz_log (LOG_LOG, "%d bytes\n%s",
+ rec->u.octet_aligned->len,
+ rec->u.octet_aligned->buf);
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ yaz_log (LOG_WARN, "Unknown Extended Service(%d)",
+ rr->esr->taskSpecificParameters->which);
+
+ }
return 0;
}
return val;
}
-char *marc_read(FILE *inf)
+char *marc_read(FILE *inf, ODR odr)
{
char length_str[5];
size_t size;
size = atoin (length_str, 5);
if (size <= 6)
return NULL;
- if (!(buf = (char*) xmalloc (size+1)))
+ if (!(buf = (char*) odr_malloc (odr, size+1)))
return NULL;
if (fread (buf+5, 1, size-5, inf) != (size-5))
{
return buf;
}
-static char *dummy_database_record (int num)
+static char *dummy_database_record (int num, ODR odr)
{
FILE *inf = fopen ("dummy-records", "r");
- char *buf = 0;
+ char *buf;
if (!inf)
return NULL;
while (--num >= 0)
{
- if (buf)
- xfree(buf);
if (num == 98)
{
- buf = (char*) xmalloc(2101);
+ buf = (char*) odr_malloc(odr, 2101);
assert(buf);
memset(buf, 'A', 2100);
buf[2100] = '\0';
break;
}
else
- buf = marc_read (inf);
+ buf = marc_read (inf, odr);
if (!num || !buf)
break;
}
return r;
}
}
- else if ((cp = dummy_database_record(q->number)))
+ else if ((cp = dummy_database_record(q->number, q->stream)))
{
r->len = strlen(cp);
- r->record = (char *) odr_malloc (q->stream, 1+r->len);
- strcpy (r->record, cp);
+ r->record = cp;
r->format = VAL_USMARC;
}
else