+static void process_http_request(association *assoc, request *req)
+{
+ Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request;
+ ODR o = assoc->encode;
+ int r = 2; /* 2=NOT TAKEN, 1=TAKEN, 0=SOAP TAKEN */
+ Z_SRW_PDU *sr = 0;
+ Z_SOAP *soap_package = 0;
+ Z_GDU *p = 0;
+ char *charset = 0;
+ Z_HTTP_Response *hres = 0;
+ int keepalive = 1;
+ const char *stylesheet = 0; /* for now .. set later */
+ Z_SRW_diagnostic *diagnostic = 0;
+ int num_diagnostic = 0;
+ const char *host = z_HTTP_header_lookup(hreq->headers, "Host");
+
+ if (!control_association(assoc, host, 0))
+ {
+ p = z_get_HTTP_Response(o, 404);
+ r = 1;
+ }
+ if (r == 2 && assoc->server && assoc->server->docpath
+ && hreq->path[0] == '/'
+ &&
+ /* check if path is a proper prefix of documentroot */
+ strncmp(hreq->path+1, assoc->server->docpath,
+ strlen(assoc->server->docpath))
+ == 0)
+ {
+ if (!check_path(hreq->path))
+ {
+ yaz_log(YLOG_LOG, "File %s access forbidden", hreq->path+1);
+ p = z_get_HTTP_Response(o, 404);
+ }
+ else
+ {
+ int content_size = 0;
+ char *content_buf = read_file(hreq->path+1, o, &content_size);
+ if (!content_buf)
+ {
+ yaz_log(YLOG_LOG, "File %s not found", hreq->path+1);
+ p = z_get_HTTP_Response(o, 404);
+ }
+ else
+ {
+ const char *ctype = 0;
+ yaz_mime_types types = yaz_mime_types_create();
+
+ yaz_mime_types_add(types, "xsl", "application/xml");
+ yaz_mime_types_add(types, "xml", "application/xml");
+ yaz_mime_types_add(types, "css", "text/css");
+ yaz_mime_types_add(types, "html", "text/html");
+ yaz_mime_types_add(types, "htm", "text/html");
+ yaz_mime_types_add(types, "txt", "text/plain");
+ yaz_mime_types_add(types, "js", "application/x-javascript");
+
+ yaz_mime_types_add(types, "gif", "image/gif");
+ yaz_mime_types_add(types, "png", "image/png");
+ yaz_mime_types_add(types, "jpg", "image/jpeg");
+ yaz_mime_types_add(types, "jpeg", "image/jpeg");
+
+ ctype = yaz_mime_lookup_fname(types, hreq->path);
+ if (!ctype)
+ {
+ yaz_log(YLOG_LOG, "No mime type for %s", hreq->path+1);
+ p = z_get_HTTP_Response(o, 404);
+ }
+ else
+ {
+ p = z_get_HTTP_Response(o, 200);
+ hres = p->u.HTTP_Response;
+ hres->content_buf = content_buf;
+ hres->content_len = content_size;
+ z_HTTP_header_add(o, &hres->headers, "Content-Type", ctype);
+ }
+ yaz_mime_types_destroy(types);
+ }
+ }
+ r = 1;
+ }
+
+ if (r == 2)
+ {
+ r = yaz_srw_decode(hreq, &sr, &soap_package, assoc->decode, &charset);
+ yaz_log(YLOG_DEBUG, "yaz_srw_decode returned %d", r);
+ }
+ if (r == 2) /* not taken */
+ {
+ r = yaz_sru_decode(hreq, &sr, &soap_package, assoc->decode, &charset,
+ &diagnostic, &num_diagnostic);
+ yaz_log(YLOG_DEBUG, "yaz_sru_decode returned %d", r);
+ }
+ if (r == 0) /* decode SRW/SRU OK .. */
+ {
+ int http_code = 200;
+ if (sr->which == Z_SRW_searchRetrieve_request)
+ {
+ Z_SRW_PDU *res =
+ yaz_srw_get_pdu(assoc->encode, Z_SRW_searchRetrieve_response,
+ sr->srw_version);
+ stylesheet = sr->u.request->stylesheet;
+ if (num_diagnostic)
+ {
+ res->u.response->diagnostics = diagnostic;
+ res->u.response->num_diagnostics = num_diagnostic;
+ }
+ else
+ {
+ srw_bend_search(assoc, req, sr, res->u.response,
+ &http_code);
+ }
+ if (http_code == 200)
+ soap_package->u.generic->p = res;
+ }
+ else if (sr->which == Z_SRW_explain_request)
+ {
+ Z_SRW_PDU *res = yaz_srw_get_pdu(o, Z_SRW_explain_response,
+ sr->srw_version);
+ stylesheet = sr->u.explain_request->stylesheet;
+ if (num_diagnostic)
+ {
+ res->u.explain_response->diagnostics = diagnostic;
+ res->u.explain_response->num_diagnostics = num_diagnostic;
+ }
+ srw_bend_explain(assoc, req, sr,
+ res->u.explain_response, &http_code);
+ if (http_code == 200)
+ soap_package->u.generic->p = res;
+ }
+ else if (sr->which == Z_SRW_scan_request)
+ {
+ Z_SRW_PDU *res = yaz_srw_get_pdu(o, Z_SRW_scan_response,
+ sr->srw_version);
+ stylesheet = sr->u.scan_request->stylesheet;
+ if (num_diagnostic)
+ {
+ res->u.scan_response->diagnostics = diagnostic;
+ res->u.scan_response->num_diagnostics = num_diagnostic;
+ }
+ srw_bend_scan(assoc, req, sr,
+ res->u.scan_response, &http_code);
+ if (http_code == 200)
+ soap_package->u.generic->p = res;
+ }
+ else if (sr->which == Z_SRW_update_request)
+ {
+ Z_SRW_PDU *res = yaz_srw_get_pdu(o, Z_SRW_update_response,
+ sr->srw_version);
+ yaz_log(YLOG_DEBUG, "handling SRW UpdateRequest");
+ if (num_diagnostic)
+ {
+ res->u.update_response->diagnostics = diagnostic;
+ res->u.update_response->num_diagnostics = num_diagnostic;
+ }
+ yaz_log(YLOG_DEBUG, "num_diag = %d", res->u.update_response->num_diagnostics );
+ srw_bend_update(assoc, req, sr,
+ res->u.update_response, &http_code);
+ if (http_code == 200)
+ soap_package->u.generic->p = res;
+ }
+ else
+ {
+ yaz_log(log_request, "SOAP ERROR");
+ /* FIXME - what error, what query */
+ http_code = 500;
+ z_soap_error(assoc->encode, soap_package,
+ "SOAP-ENV:Client", "Bad method", 0);
+ }
+ if (http_code == 200 || http_code == 500)
+ {
+ static Z_SOAP_Handler soap_handlers[4] = {
+#if YAZ_HAVE_XML2
+ {YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec},
+ {YAZ_XMLNS_SRU_v1_0, 0, (Z_SOAP_fun) yaz_srw_codec},
+ {YAZ_XMLNS_UPDATE_v0_9, 0, (Z_SOAP_fun) yaz_ucp_codec},
+#endif
+ {0, 0, 0}
+ };
+ char ctype[80];
+ int ret;
+ p = z_get_HTTP_Response(o, 200);
+ hres = p->u.HTTP_Response;