+#if HAVE_XML2
+static void handle_srw_response(ZOOM_connection c,
+ Z_SRW_searchRetrieveResponse *res)
+{
+ ZOOM_resultset resultset = 0;
+ int i;
+ NMEM nmem;
+
+ if (!c->tasks)
+ return;
+
+ if (c->tasks->which == ZOOM_TASK_SEARCH)
+ resultset = c->tasks->u.search.resultset;
+ else if (c->tasks->which == ZOOM_TASK_RETRIEVE)
+ resultset = c->tasks->u.retrieve.resultset;
+ else
+ return ;
+
+ resultset->size = 0;
+
+ yaz_log(LOG_DEBUG, "got SRW response OK");
+
+ if (res->numberOfRecords)
+ resultset->size = *res->numberOfRecords;
+
+ for (i = 0; i<res->num_records; i++)
+ {
+ int pos;
+
+ Z_NamePlusRecord *npr = (Z_NamePlusRecord *)
+ odr_malloc(c->odr_in, sizeof(Z_NamePlusRecord));
+
+ if (res->records[i].recordPosition &&
+ *res->records[i].recordPosition > 0)
+ pos = *res->records[i].recordPosition - 1;
+ else
+ pos = resultset->start + i;
+
+ npr->databaseName = 0;
+ npr->which = Z_NamePlusRecord_databaseRecord;
+ npr->u.databaseRecord = (Z_External *)
+ odr_malloc(c->odr_in, sizeof(Z_External));
+ npr->u.databaseRecord->descriptor = 0;
+ npr->u.databaseRecord->direct_reference =
+ yaz_oidval_to_z3950oid(c->odr_in, CLASS_RECSYN, VAL_TEXT_XML);
+ npr->u.databaseRecord->which = Z_External_octet;
+ npr->u.databaseRecord->u.octet_aligned = (Odr_oct *)
+ odr_malloc(c->odr_in, sizeof(Odr_oct));
+ npr->u.databaseRecord->u.octet_aligned->buf =
+ res->records[i].recordData_buf;
+ npr->u.databaseRecord->u.octet_aligned->len =
+ npr->u.databaseRecord->u.octet_aligned->size =
+ res->records[i].recordData_len;
+ record_cache_add (resultset, npr, pos);
+ }
+ if (res->num_diagnostics > 0)
+ {
+ set_dset_error(c, *res->diagnostics[0].code, "SRW",
+ res->diagnostics[0].details, 0);
+ }
+ nmem = odr_extract_mem(c->odr_in);
+ nmem_transfer(resultset->odr->mem, nmem);
+ nmem_destroy(nmem);
+}
+#endif
+
+#if HAVE_XML2
+static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres)
+{
+ int ret = -1;
+ const char *content_type = z_HTTP_header_lookup(hres->headers,
+ "Content-Type");
+ const char *connection_head = z_HTTP_header_lookup(hres->headers,
+ "Connection");
+ c->mask = 0;
+ yaz_log (LOG_DEBUG, "handle_http");
+
+ if (content_type && !yaz_strcmp_del("text/xml", content_type, "; "))
+ {
+ Z_SOAP *soap_package = 0;
+ ODR o = odr_createmem(ODR_DECODE);
+ Z_SOAP_Handler soap_handlers[2] = {
+ {"http://www.loc.gov/zing/srw/v1.0/", 0,
+ (Z_SOAP_fun) yaz_srw_codec},
+ {0, 0, 0}
+ };
+ ret = z_soap_codec(o, &soap_package,
+ &hres->content_buf, &hres->content_len,
+ soap_handlers);
+ if (!ret && soap_package->which == Z_SOAP_generic &&
+ soap_package->u.generic->no == 0)
+ {
+ Z_SRW_PDU *sr = soap_package->u.generic->p;
+ if (sr->which == Z_SRW_searchRetrieve_response)
+ handle_srw_response(c, sr->u.response);
+ else
+ ret = -1;
+ }
+ else if (!ret && (soap_package->which == Z_SOAP_fault
+ || soap_package->which == Z_SOAP_error))
+ {
+ set_HTTP_error(c, hres->code,
+ soap_package->u.fault->fault_code,
+ soap_package->u.fault->fault_string);
+ }
+ else
+ ret = -1;
+ odr_destroy(o);
+ }
+ if (ret)
+ {
+ if (hres->code != 200)
+ set_HTTP_error(c, hres->code, 0, 0);
+ else
+ set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
+ do_close (c);
+ }
+ ZOOM_connection_remove_task(c);
+ if (!strcmp(hres->version, "1.0"))
+ {
+ /* HTTP 1.0: only if Keep-Alive we stay alive.. */
+ if (!connection_head || strcmp(connection_head, "Keep-Alive"))
+ do_close(c);
+ }
+ else
+ {
+ /* HTTP 1.1: only if no close we stay alive .. */
+ if (connection_head && !strcmp(connection_head, "close"))
+ do_close(c);
+ }
+}
+#endif
+