+ &charset) == 0
+ || yaz_sru_decode(hreq, &srw_pdu, &soap_package, odr_decode(),
+ &charset, &diagnostic, &num_diagnostic) == 0)
+ {
+ m_s2z_odr_init = odr_createmem(ODR_ENCODE);
+ m_s2z_odr_search = odr_createmem(ODR_ENCODE);
+ m_soap_ns = odr_strdup(m_s2z_odr_search, soap_package->ns);
+ m_s2z_init_apdu = 0;
+ m_s2z_search_apdu = 0;
+ m_s2z_present_apdu = 0;
+
+ m_s2z_stylesheet = 0;
+
+ Z_IdAuthentication *auth = NULL;
+ if (srw_pdu->username && srw_pdu->password)
+ {
+ yaz_log(YLOG_LOG, "username/password: %s/%s\n",
+ srw_pdu->username, srw_pdu->password);
+ auth = (Z_IdAuthentication *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdAuthentication));
+ auth->which = Z_IdAuthentication_idPass;
+ auth->u.idPass = (Z_IdPass *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdPass));
+ auth->u.idPass->groupId = NULL;
+ auth->u.idPass->password = odr_strdup(m_s2z_odr_init, srw_pdu->password);
+ auth->u.idPass->userId = odr_strdup(m_s2z_odr_init, srw_pdu->username);
+ }
+ else
+ {
+ if (*authorization_str)
+ {
+ yaz_log(YLOG_LOG, "authorization_str present: %s\n", authorization_str);
+ auth = (Z_IdAuthentication *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdAuthentication));
+ auth->which = Z_IdAuthentication_idPass;
+ auth->u.idPass = (Z_IdPass *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdPass));
+ auth->u.idPass->groupId = NULL;
+ char *p = strchr(authorization_str, ':');
+ if (p)
+ {
+ *p = '\0';
+ p++;
+ auth->u.idPass->password = odr_strdup(m_s2z_odr_init, p);
+ }
+ auth->u.idPass->userId = odr_strdup(m_s2z_odr_init, authorization_str);
+ }
+ else
+ {
+ // Use _client_ IP as shown in the log entries...!
+ auth = (Z_IdAuthentication *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdAuthentication));
+ auth->which = Z_IdAuthentication_idPass;
+ auth->u.idPass = (Z_IdPass *) odr_malloc(m_s2z_odr_init, sizeof(Z_IdPass));
+ auth->u.idPass->groupId = NULL;
+ auth->u.idPass->password = NULL;
+ auth->u.idPass->userId = odr_strdup(m_s2z_odr_init, m_peername);
+ }
+ }
+
+ 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