+ * 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)
+{
+}
+
+/*