+ // z3950'fy number of records requested
+ if (sr_req->maximumRecords)
+ *(apdu->u.presentRequest->numberOfRecordsRequested)
+ = *(sr_req->maximumRecords);
+
+ // 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_oidval_to_z3950oid (odr_en, CLASS_RECSYN, VAL_TEXT_XML);
+
+ // 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
+ = 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;
+
+ //std::cout << "z3950_present_request " << *apdu << "\n";
+ z3950_package.move();
+
+ //TODO: check success condition
+ 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)
+
+ {
+ //std::cout << "z3950_present_request OK\n";
+
+ Z_PresentResponse *pr = z3950_gdu->u.z3950->u.presentResponse;
+ if (pr)
+ {
+ Z_SRW_searchRetrieveResponse *sru_res = sru_pdu_res->u.response;
+
+ // srw'fy nextRecordPosition
+ if (pr->nextResultSetPosition)
+ sru_res->nextRecordPosition
+ = odr_intdup(odr_en, *(pr->nextResultSetPosition));
+
+ // = (int *) odr_malloc(odr_en, sizeof(int *));
+ //*(sru_res->nextRecordPosition)
+ //= *(Pr->nextResultSetPosition);
+
+ // 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));
+
+ for (int i = 0; i < sru_res->num_records; i++)
+ {
+ Z_NamePlusRecord *npr
+ = pr->records->u.databaseOrSurDiagnostics->records[i];
+
+ sru_res->records[i].recordPosition
+ = odr_intdup(odr_en, i + *(apdu->u.presentRequest->resultSetStartPoint));
+
+ sru_res->records[i].recordPacking = record_packing;
+
+ if (npr->which != Z_NamePlusRecord_databaseRecord)
+ {
+ sru_res->records[i].recordSchema = "diagnostic";
+ sru_res->records[i].recordData_buf = "67";
+ sru_res->records[i].recordData_len = 2;
+ }
+ else
+ {
+ Z_External *r = npr->u.databaseRecord;
+ oident *ent = oid_getentbyoid(r->direct_reference);
+ if (r->which == Z_External_octet
+ && ent->value == VAL_TEXT_XML)
+ {
+ sru_res->records[i].recordSchema = "dc";
+ 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
+ {
+ sru_res->records[i].recordSchema = "diagnostic";
+ sru_res->records[i].recordData_buf = "67";
+ sru_res->records[i].recordData_len = 2;
+ }
+ }
+
+ }
+
+
+ }
+ }
+ return true;
+ }
+
+ return false;
+}
+
+bool
+yf::SRUtoZ3950::Rep::z3950_scan_request(mp::Package &package,
+ mp::odr &odr_en,
+ Z_SRW_PDU *sru_pdu_res,
+ Z_SRW_scanRequest const *sr_req) const
+{
+ Package z3950_package(package.session(), package.origin());
+ z3950_package.copy_filter(package);
+ //mp::odr odr_en(ODR_ENCODE);
+ Z_APDU *apdu = zget_APDU(odr_en, Z_APDU_scanRequest);
+
+ //TODO: add stuff in apdu
+ Z_ScanRequest *z_scanRequest = apdu->u.scanRequest;
+
+ // database repackaging
+ z_scanRequest->num_databaseNames = 1;
+ z_scanRequest->databaseNames = (char**)
+ odr_malloc(odr_en, sizeof(char *));
+ if (sr_req->database)
+ z_scanRequest->databaseNames[0]
+ = odr_strdup(odr_en, const_cast<char *>(sr_req->database));
+ else
+ z_scanRequest->databaseNames[0]
+ = odr_strdup(odr_en, "Default");
+
+
+ // query repackaging
+ // CQL or XCQL scan is not possible in Z3950, flagging a diagnostic
+ if (sr_req->query_type != Z_SRW_query_type_pqf)
+ {
+ //send_to_srw_client_error(7, "query");
+ return false;
+ }