X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fseshigh.c;h=f47c417a34af72b40f24d473fc045c9db04472c8;hb=98128a8684aa2474140872c25e8c2f5a231710b1;hp=a786eedbe626cd6517575e6e25af3968296152e1;hpb=2cb1374ad9b888dcb3462ec15b977fbb3a97c7cf;p=yaz-moved-to-github.git diff --git a/src/seshigh.c b/src/seshigh.c index a786eed..f47c417 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.66 2006-01-20 10:34:51 adam Exp $ + * $Id: seshigh.c,v 1.74 2006-04-05 12:05:36 mike Exp $ */ /** * \file seshigh.c @@ -60,6 +60,7 @@ #include #include "eventl.h" #include "session.h" +#include "mime.h" #include #include #include @@ -516,8 +517,9 @@ static int srw_bend_init(association *assoc, Z_SRW_diagnostic **d, int *num) assoc->backend = binitres->handle; if (binitres->errcode) { + int srw_code = yaz_diag_bib1_to_srw(binitres->errcode); assoc->state = ASSOC_DEAD; - yaz_add_srw_diagnostic(assoc->encode, d, num, binitres->errcode, + yaz_add_srw_diagnostic(assoc->encode, d, num, srw_code, binitres->errstring); return 0; } @@ -640,7 +642,7 @@ static int cql2pqf(ODR odr, const char *cql, cql_transform_t ct, int r; int srw_errcode = 0; const char *add = 0; - char rpn_buf[512]; + char rpn_buf[5120]; r = cql_parser_string(cp, cql); if (r) @@ -1087,37 +1089,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, @@ -1385,6 +1385,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; @@ -1396,7 +1422,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"); @@ -1406,14 +1432,64 @@ 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, "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); @@ -1515,6 +1591,14 @@ static void process_http_request(association *assoc, request *req) int ret; p = z_get_HTTP_Response(o, 200); hres = p->u.HTTP_Response; + + if (!stylesheet) + stylesheet = assoc->stylesheet; + + /* empty stylesheet means NO stylesheet */ + if (stylesheet && *stylesheet == '\0') + stylesheet = 0; + ret = z_soap_codec_enc_xsl(assoc->encode, &soap_package, &hres->content_buf, &hres->content_len, soap_handlers, charset, stylesheet); @@ -1989,7 +2073,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.66 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.74 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, @@ -3022,6 +3106,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 +3114,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 +3124,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 +3153,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 +3168,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;