/*
* Europagate, 1995
*
- * $Log: zaccess.c,v $
- * Revision 1.3 1995/02/16 15:20:45 quinn
+ * zaccess.c,v
+ * Revision 1.12 1995/02/20 20:35:37 quinn
+ * Pull present status from presresp.
+ *
+ * Revision 1.11 1995/02/20 18:58:05 quinn
+ * Added hack for record in ANY
+ *
+ * Revision 1.10 1995/02/20 18:19:30 quinn
+ * More relaxed about record types.
+ *
+ * Revision 1.9 1995/02/17 15:17:51 quinn
+ * Bug fix
+ *
+ * Revision 1.8 1995/02/17 14:48:41 quinn
+ * 'nother bug in present
+ *
+ * Revision 1.7 1995/02/17 14:42:21 quinn
+ * Trivial bug in fetch-loop.
+ *
+ * Revision 1.6 1995/02/17 14:41:22 quinn
+ * Debugging.
+ *
+ * Revision 1.5 1995/02/17 13:58:01 quinn
+ * First kick at present handling
+ *
+ * Revision 1.4 1995/02/16 15:33:45 quinn
+ * Fixed bug in KWAQS generator
+ *
+ * Revision 1.3 1995/02/16 15:20:45 quinn
* Added initialization of response from search
*
* Revision 1.2 1995/02/16 15:14:53 quinn
for (i = q->u.t.attr_list; i; i = i->next)
{
sprintf(*p, "%d,%d%s", i->type, i->value, i->next ?
- " " : "");
+ "," : "");
*p += strlen(*p);
}
strcat(*p, "]");
}
/*
+ * Triple indirection - that's kinda heavy. We'll fix it later.
+ * There are worse things around, though. Like ZDist.
+ */
+void get_diagrec(zass_record ***p, DATA_DIR *rec)
+{
+ DATA_DIR *ad;
+
+ **p = malloc(sizeof(***p));
+ (**p)->next = 0;
+ (**p)->errcode = zutil_GetTaggedInt(rec, ASN1_INTEGER);
+ if ((ad = zutil_GetTaggedObject(rec, ASN1_VISIBLESTRING)))
+ {
+ char *s;
+
+ if ((s = OctetString_GetASCIIString(ad)))
+ {
+ strcpy((**p)->errstring, s);
+ FREE(s);
+ }
+ }
+ (**p)->which = ZASS_REC_DIAG;
+ *p = &(**p)->next;
+}
+
+void get_responserecords(zass_record ***p, DATA_DIR *rec)
+{
+ int num, recsyntaxlen, i;
+ DATA_DIR *record, *retrec, *align;
+ PEXTERNAL ext;
+ POBJECTIDENTIFIER oid;
+ char recsyntax[256];
+
+ num = ResponseRecords_GetCount(rec);
+ for (i = 1; i <= num; i++)
+ {
+ record = ResponseRecords_GetRecord(rec, i);
+ if (!record)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Failed to get record.");
+ return;
+ }
+ retrec = NamePlusRecord_GetRetrievalRecord(record);
+ if (!retrec)
+ {
+ /* check if it's a diagrec */
+ if (record->ptr.child->fldid == 2)
+ get_diagrec(p, record->ptr.child);
+ else
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Illegal record.");
+ return;
+ }
+ }
+ ext = RetrievalRecord_GetExternal(retrec);
+ if (!ext)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "No external in record");
+ return;
+ }
+ oid = External_GetDirectReference(ext);
+ if (!oid)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Unknown record type.");
+ return;
+ }
+ recsyntaxlen = DirectReference_GetLength(oid);
+ memcpy(recsyntax, DirectReference_GetData(oid), recsyntaxlen);
+ recsyntax[recsyntaxlen] = '\0';
+ **p = malloc(sizeof(***p));
+ (**p)->next = 0;
+ if (!strcmp(recsyntax, USMARC_OID))
+ (**p)->which = ZASS_REC_USMARC;
+ else
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "ZLAYER only knows USMARC at this point.");
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Type was '%d'", (**p)->which);
+ }
+ align = External_GetEncodingAligned(ext);
+ if (!align)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Record wasn't octet-aligned");
+ align = External_GetEncodingSingle(ext);
+ if (!align)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Record wasn't ANY");
+ return;
+ }
+ align = align->ptr.child;
+ }
+ if (!((**p)->record = malloc(align->count + 1)))
+ {
+ gw_log(GW_LOG_FATAL, ZASS_TYPE, "malloc");
+ return;
+ }
+ memcpy((**p)->record, align->ptr.data, align->count);
+ (**p)->record[align->count] = '\0';
+ gw_log(ZASS_DEBUG, ZASS_TYPE, "Got a record of %d bytes",
+ align->count);
+
+ (*p) = &(**p)->next;
+ }
+}
+
+static void zass_records_free(zass_record *p)
+{
+}
+
+/*
* Note that 1== first record.
*/
const struct zass_presentent *zass_present(ZASS a, char *resname, int start,
int num)
{
- return 0;
+ static struct zass_presentent r = {0, 0, 0, 0};
+ zass_record **rec = &r.records;
+ DATA_DIR *pdu;
+ int len;
+
+ r.num = 0;
+ if (r.records)
+ {
+ zass_records_free(r.records);
+ r.records = 0;
+ }
+ do
+ {
+ gw_log(ZASS_DEBUG, ZASS_TYPE, "Fetching %d records from # %d", num - r.num,
+ start);
+ pdu = PresentRequest_CreateInitAllASCII(0, resname, start, num - r.num, "F",
+ USMARC_OID);
+ if (!pdu)
+ {
+ gw_log(GW_LOG_FATAL, "ZASS_TYPE", "failed to create presentrequest");
+ return 0;
+ }
+ zutil_GetBEREncodedBuffer(pdu, (unsigned char*)a->buf, &len,
+ a->maxrecordsize);
+ if (len <= 0)
+ {
+ gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to encode presentrequest");
+ return 0;
+ }
+ PresentRequest_Destroy(pdu);
+ if (netbox_SendBuffer(a->ass, a->buf, len) != len)
+ {
+ gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to send presentrequest");
+ return 0;
+ }
+ gw_log(ZASS_DEBUG, ZASS_TYPE, "Sent presentrequest.");
+ if ((len = zutil_GetBERFromNet(a->ass, (unsigned char*)a->buf,
+ a->maxrecordsize)) <= 0)
+ {
+ gw_log(GW_LOG_FATAL, ZASS_TYPE, "Failed to receive presentresponse");
+ return 0;
+ }
+ pdu = zutil_CreateFromData((unsigned char*)a->buf, len);
+ if (zutil_GetTag(pdu) != PRESENTRESPONSE_TAG)
+ {
+ gw_log(GW_LOG_FATAL, ZASS_TYPE, "Expected presentresponse from target");
+ return 0;
+ }
+ gw_log(ZASS_DEBUG, ZASS_TYPE, "Got presentresponse");
+ r.num += PresentResponse_GetNumberOfRecordsReturned(pdu);
+ r.presentstatus = PresentResponse_GetPresentStatus(pdu);
+ if (r.num == 0)
+ {
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Got 0 records from target.");
+ return 0;
+ }
+ r.nextpos = PresentResponse_GetNextResultSetPosition(pdu);
+ start = r.nextpos;
+ switch(PresentResponse_GetRecordType(pdu))
+ {
+ case RESPONSERECORDS_TAG:
+ get_responserecords(&rec, PresentResponse_GetResponseRecords(pdu));
+ break;
+ case NONSURROGATEDIAGNOSTIC_TAG:
+ get_diagrec(&rec, PresentResponse_GetNonSurrogateDiagnostic(pdu));
+ break;
+ default:
+ gw_log(GW_LOG_WARN, ZASS_TYPE, "Bad tag in response rec.");
+ }
+ PresentResponse_Destroy(pdu);
+ }
+ while (num - r.num);
+ *rec = 0;
+
+ return &r;
}