- // srw'fy number of returned records
- //sru_pdu_res->u.response->num_records
- // = *(pr->numberOfRecordsReturned);
- //= (int *) odr_malloc(odr_en, sizeof(int *));
- //*(sru_pdu_res->u.response->num_records)
- // = *(pr->numberOfRecordsReturned);
-
- // srw'fy nextRecordPosition
- //if (! sru_pdu_res->u.response->nextRecordPosition)
- sru_pdu_res->u.response->nextRecordPosition
- = (int *) odr_malloc(odr_en, sizeof(int *));
- *(sru_pdu_res->u.response->nextRecordPosition)
- = *(pr->nextResultSetPosition);
+ // everything fine, continuing
+
+ Z_PresentResponse *pr = z3950_gdu->u.z3950->u.presentResponse;
+ Z_SRW_searchRetrieveResponse *sru_res = sru_pdu_res->u.response;
+
+
+ // checking non surrogate diagnostics in Z3950 present response package
+ if (!z3950_to_srw_diagnostics_ok(odr_en, sru_pdu_res->u.response,
+ pr->records))
+ return false;
+
+
+
+ // copy all records if existing
+ if (pr->records && pr->records->which == Z_Records_DBOSD)
+ {
+ // srw'fy number of returned records
+ sru_res->num_records
+ = pr->records->u.databaseOrSurDiagnostics->num_records;
+
+ sru_res->records
+ = (Z_SRW_record *) odr_malloc(odr_en,
+ sru_res->num_records
+ * sizeof(Z_SRW_record));
+
+
+ // srw'fy nextRecordPosition
+ // next position never zero or behind the last z3950 record
+ if (pr->nextResultSetPosition
+ && *(pr->nextResultSetPosition) > 0
+ && *(pr->nextResultSetPosition)
+ <= *(sru_pdu_res->u.response->numberOfRecords))
+ sru_res->nextRecordPosition
+ = odr_intdup(odr_en, *(pr->nextResultSetPosition));
+
+ // inserting all records
+ for (int i = 0; i < sru_res->num_records; i++)
+ {
+ int position = i + *apdu->u.presentRequest->resultSetStartPoint;
+ Z_NamePlusRecord *npr
+ = pr->records->u.databaseOrSurDiagnostics->records[i];
+
+ sru_res->records[i].recordPacking = record_packing;
+
+ if (npr->which == Z_NamePlusRecord_databaseRecord &&
+ npr->u.databaseRecord->direct_reference
+ && !oid_oidcmp(npr->u.databaseRecord->direct_reference,
+ yaz_oid_recsyn_xml))
+ {
+ // got XML record back
+ Z_External *r = npr->u.databaseRecord;
+ sru_res->records[i].recordPosition =
+ odr_intdup(odr_en, position);
+ sru_res->records[i].recordSchema = sr_req->recordSchema;
+ sru_res->records[i].recordData_buf
+ = odr_strdupn(odr_en,
+ (const char *)r->u.octet_aligned->buf,
+ r->u.octet_aligned->len);
+ sru_res->records[i].recordData_len
+ = r->u.octet_aligned->len;
+ }
+ else
+ {
+ // not XML or no database record at all
+ yaz_mk_sru_surrogate(
+ odr_en, sru_res->records + i, position,
+ YAZ_SRW_RECORD_NOT_AVAILABLE_IN_THIS_SCHEMA, 0);
+ }