- // now re-insructing the z3950 backend present request
-
- // z3950'fy record syntax
- //Odr_oid odr_oid;
- if(pr->preferredRecordSyntax){
- (pr->preferredRecordSyntax)
- = yaz_str_to_z3950oid(odr_en, CLASS_RECSYN, "xml");
-
- // = yaz_oidval_to_z3950oid (odr_en, CLASS_RECSYN, VAL_TEXT_XML);
- }
- // Odr_oid *yaz_str_to_z3950oid (ODR o, int oid_class,
- // const char *str);
- // const char *yaz_z3950oid_to_str (Odr_oid *oid, int *oid_class);
-
-
- // z3950'fy record schema
- //if ()
- // {
- // pr->recordComposition
- // = (Z_RecordComposition *)
- // odr_malloc(odr_en, sizeof(Z_RecordComposition));
- // pr->recordComposition->which
- // = Z_RecordComp_simple;
- // pr->recordComposition->u.simple
- // = build_esn_from_schema(odr_en,
- // (const char *) sr_req->recordSchema);
- // }
+ // setting up variables for conversion state
+ yaz_record_conv_t rc = 0;
+
+ const char *match_schema = 0;
+ Odr_oid *match_syntax = 0;
+
+ const char *backend_schema = 0;
+ Odr_oid *backend_syntax = 0;
+
+ int ret_code
+ = yaz_retrieval_request(m_retrieval,
+ input_schema, input_syntax,
+ &match_schema, &match_syntax,
+ &rc,
+ &backend_schema, &backend_syntax);
+ // error handling
+ if (ret_code != 0)
+ {
+ int error_code;
+ const char *details = 0;
+
+ if (ret_code == -1) /* error ? */
+ {
+ details = yaz_retrieval_get_error(m_retrieval);
+ error_code = YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
+ }
+ else if (ret_code == 1 || ret_code == 3)
+ {
+ details = input_schema;
+ error_code = YAZ_BIB1_ELEMENT_SET_NAMES_UNSUPP;
+ }
+ else if (ret_code == 2)
+ {
+ char oidbuf[OID_STR_MAX];
+ oid_oid_to_dotstring(input_syntax, oidbuf);
+ details = odr_strdup(odr_en, oidbuf);
+ error_code = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
+ }
+ else
+ {
+ char *tmp = (char*) odr_malloc(odr_en, 80);
+ sprintf(tmp,
+ "record_transform: yaz_retrieval_get_error returned %d",
+ ret_code);
+ details = tmp;
+ error_code = YAZ_BIB1_UNSPECIFIED_ERROR;
+ }
+ Z_APDU *apdu;
+ if (sr_req)
+ {
+ apdu = odr_en.create_searchResponse(
+ gdu_req->u.z3950, error_code, details);
+ }
+ else
+ {
+ apdu = odr_en.create_presentResponse(
+ gdu_req->u.z3950, error_code, details);
+ }
+ package.response() = apdu;
+ return;
+ }
+
+ if (sr_req)
+ {
+ if (backend_syntax)
+ sr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax);
+ else
+ sr_req->preferredRecordSyntax = 0;
+
+ if (backend_schema)
+ {
+ sr_req->smallSetElementSetNames
+ = (Z_ElementSetNames *)
+ odr_malloc(odr_en, sizeof(Z_ElementSetNames));
+ sr_req->smallSetElementSetNames->which = Z_ElementSetNames_generic;
+ sr_req->smallSetElementSetNames->u.generic
+ = odr_strdup(odr_en, backend_schema);
+ sr_req->mediumSetElementSetNames = sr_req->smallSetElementSetNames;
+ }
+ else
+ {
+ sr_req->smallSetElementSetNames = 0;
+ sr_req->mediumSetElementSetNames = 0;
+ }
+ }
+ else if (pr_req)
+ {
+ if (backend_syntax)
+ pr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax);
+ else
+ pr_req->preferredRecordSyntax = 0;
+
+ if (backend_schema)
+ {
+ pr_req->recordComposition
+ = (Z_RecordComposition *)
+ odr_malloc(odr_en, sizeof(Z_RecordComposition));
+ pr_req->recordComposition->which
+ = Z_RecordComp_simple;
+ pr_req->recordComposition->u.simple
+ = (Z_ElementSetNames *)
+ odr_malloc(odr_en, sizeof(Z_ElementSetNames));
+ pr_req->recordComposition->u.simple->which = Z_ElementSetNames_generic;
+ pr_req->recordComposition->u.simple->u.generic
+ = odr_strdup(odr_en, backend_schema);
+ }
+ else
+ pr_req->recordComposition = 0;
+ }