- recform.proto = a->proto;
- recform.oclass = CLASS_RECSYN;
- recform.value = fres->format;
- thisext->direct_reference = odr_oiddup(a->encode,
- oid_ent_to_oid(&recform, oid));
- thisext->indirect_reference = 0;
- thisext->descriptor = 0;
- if (fres->len < 0) /* Structured data */
- {
- switch (fres->format)
- {
- case VAL_SUTRS: thisext->which = Z_External_sutrs; break;
- case VAL_GRS1: thisext->which = Z_External_grs1; break;
- case VAL_EXPLAIN: thisext->which = Z_External_explainRecord;
- break;
- case VAL_SUMMARY: thisext->which = Z_External_summary; break;
- case VAL_OPAC: thisext->which = Z_External_OPAC; break;
-
- default:
- logf(LOG_FATAL, "Unknown structured format from backend.");
- return 0;
- }
-
- /*
- * We cheat on the pointers here. Obviously, the record field
- * of the backend-fetch structure should have been a union for
- * correctness, but we're stuck with this for backwards
- * compatibility.
- */
- thisext->u.grs1 = (Z_GenericRecord*) fres->record;
- }
- else if (fres->format == VAL_SUTRS) /* SUTRS is a single-ASN.1-type */
- {
-#if 0
- Z_SUTRS *sutrs = (Z_SUTRS *)odr_malloc(a->encode, 1+fres->len);
-
- memcpy(sutrs, fres->record, fres->len);
- sutrs[fres->len] = '\0';
-#else
- Odr_oct *sutrs = (Odr_oct *)odr_malloc(a->encode, sizeof(*sutrs));
-
- thisext->which = Z_External_sutrs;
- thisext->u.sutrs = sutrs;
- sutrs->buf = (unsigned char *)odr_malloc(a->encode, fres->len);
- sutrs->len = sutrs->size = fres->len;
- memcpy(sutrs->buf, fres->record, fres->len);
-#endif
- }
- else /* octet-aligned record. */
- {
- thisext->which = Z_External_octet;
- if (!(thisext->u.octet_aligned = (Odr_oct *)odr_malloc(a->encode,
- sizeof(Odr_oct))))
- return 0;
- if (!(thisext->u.octet_aligned->buf = (unsigned char *)odr_malloc(a->encode,
- fres->len)))
- return 0;
- memcpy(thisext->u.octet_aligned->buf, fres->record, fres->len);
- thisext->u.octet_aligned->len = thisext->u.octet_aligned->size =
- fres->len;
- }