+ // sort unsupported
+ if (sr_req->sort_type != Z_SRW_sort_type_none)
+ {
+ send_z3950_present = false;
+ yaz_add_srw_diagnostic(odr_en,
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
+ 80, 0);
+ }
+
+ // start record requested negative, or larger than number of records
+ if (sr_req->startRecord
+ &&
+ ((*(sr_req->startRecord) < 0) // negative
+ ||
+ (sru_pdu_res->u.response->numberOfRecords //out of range
+ && *(sr_req->startRecord)
+ > *(sru_pdu_res->u.response->numberOfRecords))
+ ))
+ {
+ send_z3950_present = false;
+ yaz_add_srw_diagnostic(odr_en,
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
+ 61, 0);
+ }
+
+ // maximumRecords requested negative
+ if (sr_req->maximumRecords
+ && *(sr_req->maximumRecords) < 0)
+
+ {
+ send_z3950_present = false;
+ yaz_add_srw_diagnostic(odr_en,
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
+ 6, "maximumRecords");
+ }
+
+ // exit on all these above diagnostics
+ if (!send_z3950_present)
+ return false;
+
+ // now packaging the z3950 present request
+ Package z3950_package(package.session(), package.origin());
+ z3950_package.copy_filter(package);
+ Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_presentRequest);
+
+ assert(apdu->u.presentRequest);
+
+ // z3950'fy start record position
+ if (sr_req->startRecord)
+ *(apdu->u.presentRequest->resultSetStartPoint)
+ = *(sr_req->startRecord);
+ else
+ *(apdu->u.presentRequest->resultSetStartPoint) = 1;
+
+ // z3950'fy number of records requested
+ // protect against requesting records out of range
+ if (sr_req->maximumRecords)
+ *(apdu->u.presentRequest->numberOfRecordsRequested)
+ = std::min(*(sr_req->maximumRecords),
+ *(sru_pdu_res->u.response->numberOfRecords)
+ - *(apdu->u.presentRequest->resultSetStartPoint)
+ + 1);
+
+ // z3950'fy recordPacking
+ int record_packing = Z_SRW_recordPacking_XML;
+ if (sr_req->recordPacking && 's' == *(sr_req->recordPacking))
+ record_packing = Z_SRW_recordPacking_string;
+
+ // RecordSyntax will always be XML
+ apdu->u.presentRequest->preferredRecordSyntax
+ = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN, OID_STR_XML,
+ odr_en);
+
+ // z3950'fy record schema
+ if (sr_req->recordSchema)
+ {
+ apdu->u.presentRequest->recordComposition
+ = (Z_RecordComposition *)
+ odr_malloc(odr_en, sizeof(Z_RecordComposition));
+ apdu->u.presentRequest->recordComposition->which
+ = Z_RecordComp_simple;
+ apdu->u.presentRequest->recordComposition->u.simple
+ = mp_util::build_esn_from_schema(odr_en,
+ (const char *) sr_req->recordSchema);
+ }
+
+ // z3950'fy time to live - flagged as diagnostics above
+ //if (sr_req->resultSetTTL)
+
+ // attaching Z3950 package to filter chain
+ z3950_package.request() = apdu;
+
+ // sending Z30.50 present request
+ z3950_package.move();
+
+ //check successful Z3950 present response
+ Z_GDU *z3950_gdu = z3950_package.response().get();
+ if (!z3950_gdu || z3950_gdu->which != Z_GDU_Z3950
+ || z3950_gdu->u.z3950->which != Z_APDU_presentResponse
+ || !z3950_gdu->u.z3950->u.presentResponse)
+
+ {
+ yaz_add_srw_diagnostic(odr_en,
+ &(sru_pdu_res->u.response->diagnostics),
+ &(sru_pdu_res->u.response->num_diagnostics),
+ 2, 0);
+ return false;
+ }
+