- // sort unsupported
- if (srw_req->sort_type != Z_SRW_sort_type_none)
- {
- yaz_add_srw_diagnostic(odr_decode(),
- &diagnostic, &num_diagnostic,
- 80, 0);
- }
- // save stylesheet
- if (srw_req->stylesheet)
- m_s2z_stylesheet =
- odr_strdup(m_s2z_odr_init, srw_req->stylesheet);
-
- // set packing for response records ..
- if (srw_req->recordPacking &&
- !strcmp(srw_req->recordPacking, "xml"))
- m_s2z_packing = Z_SRW_recordPacking_XML;
- else
- m_s2z_packing = Z_SRW_recordPacking_string;
-
- if (num_diagnostic)
- {
- Z_SRW_PDU *srw_pdu =
- yaz_srw_get(odr_encode(),
- Z_SRW_searchRetrieve_response);
- Z_SRW_searchRetrieveResponse *srw_res = srw_pdu->u.response;
-
- srw_res->diagnostics = diagnostic;
- srw_res->num_diagnostics = num_diagnostic;
- send_srw_response(srw_pdu);
- return;
- }
-
- // prepare search PDU
- m_s2z_search_apdu = zget_APDU(m_s2z_odr_search,
- Z_APDU_searchRequest);
- Z_SearchRequest *z_searchRequest =
- m_s2z_search_apdu->u.searchRequest;
-
- z_searchRequest->num_databaseNames = 1;
- z_searchRequest->databaseNames = (char**)
- odr_malloc(m_s2z_odr_search, sizeof(char *));
- z_searchRequest->databaseNames[0] = odr_strdup(m_s2z_odr_search,
- backend_db);
-
- // query transformation
- Z_Query *query = (Z_Query *)
- odr_malloc(m_s2z_odr_search, sizeof(Z_Query));
- z_searchRequest->query = query;
-
- if (srw_req->query_type == Z_SRW_query_type_cql)
- {
- Z_External *ext = (Z_External *)
- odr_malloc(m_s2z_odr_search, sizeof(*ext));
- ext->direct_reference =
- odr_getoidbystr(m_s2z_odr_search, "1.2.840.10003.16.2");
- ext->indirect_reference = 0;
- ext->descriptor = 0;
- ext->which = Z_External_CQL;
- ext->u.cql = srw_req->query.cql;
-
- query->which = Z_Query_type_104;
- query->u.type_104 = ext;
- }
- else if (srw_req->query_type == Z_SRW_query_type_pqf)
- {
- Z_RPNQuery *RPNquery;
- YAZ_PQF_Parser pqf_parser;
-
- pqf_parser = yaz_pqf_create ();
-
- RPNquery = yaz_pqf_parse (pqf_parser, m_s2z_odr_search,
- srw_req->query.pqf);
- if (!RPNquery)
- {
- const char *pqf_msg;
- size_t off;
- int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
- yaz_log(YLOG_LOG, "%*s^\n", off+4, "");
- yaz_log(YLOG_LOG, "Bad PQF: %s (code %d)\n", pqf_msg, code);
-
- send_to_srw_client_error(10, 0);
- return;
- }
- query->which = Z_Query_type_1;
- query->u.type_1 = RPNquery;
-
- yaz_pqf_destroy (pqf_parser);
- }
- else
- {
- send_to_srw_client_error(7, "query");
- return;
- }
-
- // present
- m_s2z_present_apdu = 0;
- int max = 0;
- if (srw_req->maximumRecords)
- max = *srw_req->maximumRecords;
- int start = 1;
- if (srw_req->startRecord)
- start = *srw_req->startRecord;
- if (max > 0)
- {
+ }
+
+ if (srw_pdu->which == Z_SRW_searchRetrieve_request)
+ {
+
+ Z_SRW_searchRetrieveRequest *srw_req = srw_pdu->u.request;
+
+ const char *backend_db = srw_req->database;
+ srw_get_client(srw_req->database, &backend_db);
+
+ m_s2z_database = odr_strdup(m_s2z_odr_init, srw_req->database);
+ // recordXPath unsupported.
+ if (srw_req->recordXPath)
+ {
+ yaz_add_srw_diagnostic(odr_decode(),
+ &diagnostic, &num_diagnostic,
+ 72, 0);
+ }
+ // sort unsupported
+ if (srw_req->sort_type != Z_SRW_sort_type_none)
+ {
+ yaz_add_srw_diagnostic(odr_decode(),
+ &diagnostic, &num_diagnostic,
+ 80, 0);
+ }
+ // save stylesheet
+ if (srw_req->stylesheet)
+ m_s2z_stylesheet =
+ odr_strdup(m_s2z_odr_init, srw_req->stylesheet);
+
+ // set packing for response records ..
+ if (srw_req->recordPacking &&
+ !strcmp(srw_req->recordPacking, "xml"))
+ m_s2z_packing = Z_SRW_recordPacking_XML;
+ else
+ m_s2z_packing = Z_SRW_recordPacking_string;
+
+ if (num_diagnostic)
+ {
+ Z_SRW_PDU *srw_pdu =
+ yaz_srw_get(odr_encode(),
+ Z_SRW_searchRetrieve_response);
+ Z_SRW_searchRetrieveResponse *srw_res = srw_pdu->u.response;
+
+ srw_res->diagnostics = diagnostic;
+ srw_res->num_diagnostics = num_diagnostic;
+ send_srw_response(srw_pdu);
+ return;
+ }
+
+ // prepare search PDU
+ m_s2z_search_apdu = zget_APDU(m_s2z_odr_search,
+ Z_APDU_searchRequest);
+ Z_SearchRequest *z_searchRequest =
+ m_s2z_search_apdu->u.searchRequest;
+
+ z_searchRequest->num_databaseNames = 1;
+ z_searchRequest->databaseNames = (char**)
+ odr_malloc(m_s2z_odr_search, sizeof(char *));
+ z_searchRequest->databaseNames[0] = odr_strdup(m_s2z_odr_search,
+ backend_db);
+
+ // query transformation
+ Z_Query *query = (Z_Query *)
+ odr_malloc(m_s2z_odr_search, sizeof(Z_Query));
+ z_searchRequest->query = query;
+
+ if (srw_req->query_type == Z_SRW_query_type_cql)
+ {
+ Z_External *ext = (Z_External *)
+ odr_malloc(m_s2z_odr_search, sizeof(*ext));
+ ext->direct_reference =
+ odr_getoidbystr(m_s2z_odr_search, "1.2.840.10003.16.2");
+ ext->indirect_reference = 0;
+ ext->descriptor = 0;
+ ext->which = Z_External_CQL;
+ ext->u.cql = srw_req->query.cql;
+
+ query->which = Z_Query_type_104;
+ query->u.type_104 = ext;
+ }
+ else if (srw_req->query_type == Z_SRW_query_type_pqf)
+ {
+ Z_RPNQuery *RPNquery;
+ YAZ_PQF_Parser pqf_parser;
+
+ pqf_parser = yaz_pqf_create ();
+
+ RPNquery = yaz_pqf_parse (pqf_parser, m_s2z_odr_search,
+ srw_req->query.pqf);
+ if (!RPNquery)
+ {
+ const char *pqf_msg;
+ size_t off;
+ int code = yaz_pqf_error (pqf_parser, &pqf_msg, &off);
+ int ioff = off;
+ yaz_log(YLOG_LOG, "%*s^\n", ioff+4, "");
+ yaz_log(YLOG_LOG, "Bad PQF: %s (code %d)\n", pqf_msg, code);
+
+ send_to_srw_client_error(10, 0);
+ return;
+ }
+ query->which = Z_Query_type_1;
+ query->u.type_1 = RPNquery;
+
+ yaz_pqf_destroy (pqf_parser);
+ }
+ else
+ {
+ send_to_srw_client_error(7, "query");
+ return;
+ }
+
+ // present
+ m_s2z_present_apdu = 0;
+ int max = 0;
+ if (srw_req->maximumRecords)
+ max = *srw_req->maximumRecords;
+ int start = 1;
+ if (srw_req->startRecord)
+ start = *srw_req->startRecord;
+ if (max > 0)
+ {