+ // see if we have a records list to patch!
+ Z_NamePlusRecordList *records = 0;
+ if (gdu_res && gdu_res->which == Z_GDU_Z3950 &&
+ gdu_res->u.z3950->which == Z_APDU_presentResponse)
+ {
+ Z_PresentResponse * pr_res = gdu_res->u.z3950->u.presentResponse;
+
+ if (rc && pr_res
+ && pr_res->numberOfRecordsReturned
+ && *(pr_res->numberOfRecordsReturned) > 0
+ && pr_res->records
+ && pr_res->records->which == Z_Records_DBOSD)
+ {
+ records = pr_res->records->u.databaseOrSurDiagnostics;
+ }
+ }
+ if (gdu_res && gdu_res->which == Z_GDU_Z3950 &&
+ gdu_res->u.z3950->which == Z_APDU_searchResponse)
+ {
+ Z_SearchResponse *sr_res = gdu_res->u.z3950->u.searchResponse;
+
+ if (rc && sr_res
+ && sr_res->numberOfRecordsReturned
+ && *(sr_res->numberOfRecordsReturned) > 0
+ && sr_res->records
+ && sr_res->records->which == Z_Records_DBOSD)
+ {
+ records = sr_res->records->u.databaseOrSurDiagnostics;
+ }
+ }
+
+ if (records)
+ {
+ int i;
+ for (i = 0; i < records->num_records; i++)
+ {
+ Z_NamePlusRecord *npr = records->records[i];
+ if (npr->which == Z_NamePlusRecord_databaseRecord)
+ {
+ const char *details = 0;
+ mp::wrbuf output_record;
+ Z_External *r = npr->u.databaseRecord;
+ int ret_trans = -1;
+ if (r->which == Z_External_OPAC)
+ {
+ ret_trans =
+ yaz_record_conv_opac_record(rc, r->u.opac,
+ output_record);
+ details = yaz_record_conv_get_error(rc);
+ }
+ else if (r->which == Z_External_octet)
+ {
+ ret_trans =
+ yaz_record_conv_record(rc, (const char *)
+ r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ output_record);
+ details = yaz_record_conv_get_error(rc);
+ }
+ else
+ {
+ details = "unsupported record type for record_conv";
+ }
+ if (ret_trans)
+ {
+ records->records[i] =
+ zget_surrogateDiagRec(
+ odr_en, npr->databaseName,
+ YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
+ details);
+ }
+ else
+ {
+ if (!oid_oidcmp(match_syntax, yaz_oid_recsyn_opac))
+ {
+ yaz_marc_t mt = yaz_marc_create();
+ Z_OPACRecord *opac = 0;
+ if (yaz_xml_to_opac(mt, output_record.buf(),
+ output_record.len(),
+ &opac, 0 /* iconv */,
+ ((ODR )odr_en)->mem, 0)
+ && opac)
+ {
+ npr->u.databaseRecord =
+ z_ext_record_oid(odr_en, match_syntax,
+ (const char *) opac, -1);
+ }
+ else
+ {
+ records->records[i] =
+ zget_surrogateDiagRec(
+ odr_en, npr->databaseName,
+ YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS,
+ "XML to OPAC conversion failed");
+ }
+ yaz_marc_destroy(mt);
+ }
+ else
+ {
+ npr->u.databaseRecord =
+ z_ext_record_oid(odr_en, match_syntax,
+ output_record.buf(),
+ output_record.len());
+ }
+ }
+ }
+ }
+ package.response() = gdu_res;
+ }