X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fseshigh.c;h=22df1a80d83ae3ad48209115cbe74e72e6a58acb;hp=a7dbefbacce3be0f8da17d1f7dc90f5019fbf94b;hb=a6af2d19dddb0c2ef961d087d8ca0f2b3bda8f7a;hpb=9a7cdcf5ae13e63eae0259f2a620119463e64f42 diff --git a/src/seshigh.c b/src/seshigh.c index a7dbefb..22df1a8 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.65 2005-11-09 17:47:11 adam Exp $ + * $Id: seshigh.c,v 1.69 2006-03-15 13:32:05 adam Exp $ */ /** * \file seshigh.c @@ -60,10 +60,12 @@ #include #include "eventl.h" #include "session.h" +#include "mime.h" #include #include #include #include +#include #include #include #include @@ -1086,37 +1088,35 @@ static void srw_bend_scan(association *assoc, request *req, (*assoc->init->bend_scan))(assoc->backend, bsrr); } else if (srw_req->query_type == Z_SRW_query_type_cql - && assoc->init->bend_srw_scan) + && assoc->init->bend_scan && assoc->cql_transform) { - if (assoc->cql_transform) - { - int srw_error; - bsrr->scanClause = 0; - bsrr->attributeset = VAL_NONE; - bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term)); - srw_error = cql2pqf_scan(assoc->encode, - srw_req->scanClause.cql, - assoc->cql_transform, - bsrr->term); - if (srw_error) - yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, - &srw_res->num_diagnostics, - srw_error, 0); - else - { - ((int (*)(void *, bend_scan_rr *)) - (*assoc->init->bend_scan))(assoc->backend, bsrr); - } - } + int srw_error; + bsrr->scanClause = 0; + bsrr->attributeset = VAL_NONE; + bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term)); + srw_error = cql2pqf_scan(assoc->encode, + srw_req->scanClause.cql, + assoc->cql_transform, + bsrr->term); + if (srw_error) + yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, + &srw_res->num_diagnostics, + srw_error, 0); else { - bsrr->term = 0; - bsrr->attributeset = VAL_NONE; - bsrr->scanClause = srw_req->scanClause.cql; ((int (*)(void *, bend_scan_rr *)) - (*assoc->init->bend_srw_scan))(assoc->backend, bsrr); + (*assoc->init->bend_scan))(assoc->backend, bsrr); } } + else if (srw_req->query_type == Z_SRW_query_type_cql + && assoc->init->bend_srw_scan) + { + bsrr->term = 0; + bsrr->attributeset = VAL_NONE; + bsrr->scanClause = srw_req->scanClause.cql; + ((int (*)(void *, bend_scan_rr *)) + (*assoc->init->bend_srw_scan))(assoc->backend, bsrr); + } else { yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics, @@ -1384,6 +1384,32 @@ static void srw_bend_update(association *assoc, request *req, } } +/* check if path is OK (1); BAD (0) */ +static int check_path(const char *path) +{ + if (*path != '/') + return 0; + if (strstr(path, "..")) + return 0; + return 1; +} + +static char *read_file(const char *fname, ODR o, int *sz) +{ + char *buf; + FILE *inf = fopen(fname, "rb"); + if (!inf) + return 0; + + fseek(inf, 0L, SEEK_END); + *sz = ftell(inf); + rewind(inf); + buf = odr_malloc(o, *sz); + fread(buf, 1, *sz, inf); + fclose(inf); + return buf; +} + static void process_http_request(association *assoc, request *req) { Z_HTTP_Request *hreq = req->gdu_request->u.HTTP_Request; @@ -1395,7 +1421,7 @@ static void process_http_request(association *assoc, request *req) char *charset = 0; Z_HTTP_Response *hres = 0; int keepalive = 1; - char *stylesheet = 0; + 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"); @@ -1405,14 +1431,63 @@ static void process_http_request(association *assoc, request *req) p = z_get_HTTP_Response(o, 404); r = 1; } - if (r == 2 && !strcmp(hreq->path, "/test")) + if (r == 2 && assoc->docpath && hreq->path[0] == '/' + && + /* check if path is a proper prefix of documentroot */ + strncmp(hreq->path+1, assoc->docpath, strlen(assoc->docpath)) + == 0) { - p = z_get_HTTP_Response(o, 200); - hres = p->u.HTTP_Response; - hres->content_buf = "1234567890\n"; - hres->content_len = strlen(hres->content_buf); + 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, "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); @@ -1514,6 +1589,11 @@ static void process_http_request(association *assoc, request *req) int ret; p = z_get_HTTP_Response(o, 200); hres = p->u.HTTP_Response; + + yaz_log(YLOG_LOG, "assoc->stylesheet=%s", assoc->stylesheet); + if (!stylesheet) + stylesheet = assoc->stylesheet; + ret = z_soap_codec_enc_xsl(assoc->encode, &soap_package, &hres->content_buf, &hres->content_len, soap_handlers, charset, stylesheet); @@ -1988,7 +2068,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.65 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.69 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, @@ -2437,7 +2517,7 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb, wrbuf_printf(wr, "OK %d", bsrt->hits); wrbuf_printf(wr, " %s 1+%d ", req->resultSetName, returnedrecs); - wrbuf_put_zquery(wr, req->query); + yaz_query_to_wrbuf(wr, req->query); yaz_log(log_request, "Search %s", wrbuf_buf(wr)); wrbuf_free(wr, 1); @@ -2741,9 +2821,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd) *req->preferredPositionInResponse : 1), *req->numberOfTermsRequested, (res->stepSize ? *res->stepSize : 0)); - wrbuf_scan_term(wr, req->termListAndStartPoint, - bsrr->attributeset); - + yaz_scan_to_wrbuf(wr, req->termListAndStartPoint, + bsrr->attributeset); yaz_log(log_request, "Scan %s", wrbuf_buf(wr) ); wrbuf_free(wr, 1); } @@ -3022,6 +3101,7 @@ static Z_APDU *process_segmentRequest (association *assoc, request *reqb) static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) { bend_esrequest_rr esrequest; + const char *ext_name = "unknown"; Z_ExtendedServicesRequest *req = reqb->apdu_request->u.extendedServicesRequest; @@ -3029,8 +3109,6 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) Z_ExtendedServicesResponse *resp = apdu->u.extendedServicesResponse; - yaz_log(log_requestdetail,"Got EsRequest"); - esrequest.esr = reqb->apdu_request->u.extendedServicesRequest; esrequest.stream = assoc->encode; esrequest.decode = assoc->decode; @@ -3041,7 +3119,24 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) esrequest.association = assoc; esrequest.taskPackage = 0; esrequest.referenceId = req->referenceId; + + if (esrequest.esr && esrequest.esr->taskSpecificParameters) + { + switch(esrequest.esr->taskSpecificParameters->which) + { + case Z_External_itemOrder: + ext_name = "ItemOrder"; break; + case Z_External_update: + ext_name = "Update"; break; + case Z_External_update0: + ext_name = "Update0"; break; + case Z_External_ESAdmin: + ext_name = "Admin"; break; + + } + } + (*assoc->init->bend_esrequest)(assoc->backend, &esrequest); /* If the response is being delayed, return NULL */ @@ -3053,13 +3148,13 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) if (esrequest.errcode == -1) { /* Backend service indicates request will be processed */ - yaz_log(log_request,"EsRequest OK: Accepted !"); + yaz_log(log_request, "Extended Service: %s (accepted)", ext_name); *resp->operationStatus = Z_ExtendedServicesResponse_accepted; } else if (esrequest.errcode == 0) { /* Backend service indicates request will be processed */ - yaz_log(log_request,"EsRequest OK: Done !"); + yaz_log(log_request, "Extended Service: %s (done)", ext_name); *resp->operationStatus = Z_ExtendedServicesResponse_done; } else @@ -3068,7 +3163,7 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd) zget_DiagRecs(assoc->encode, esrequest.errcode, esrequest.errstring); /* Backend indicates error, request will not be processed */ - yaz_log(YLOG_DEBUG,"Request could not be processed...failure !"); + yaz_log(log_request, "Extended Service: %s (failed)", ext_name); *resp->operationStatus = Z_ExtendedServicesResponse_failure; resp->num_diagnostics = diagRecs->num_diagRecs; resp->diagnostics = diagRecs->diagRecs;