From: Adam Dickmeiss Date: Thu, 26 Apr 2012 13:24:01 +0000 (+0200) Subject: New setting embed_xslt X-Git-Tag: v1.6.13~9^2~4^2~10 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=848a659ecc0b24d1881c3f091393b99259130aa7;p=pazpar2-moved-to-github.git New setting embed_xslt --- diff --git a/src/normalize_cache.c b/src/normalize_cache.c index 92b71ae..2d69f33 100644 --- a/src/normalize_cache.c +++ b/src/normalize_cache.c @@ -57,7 +57,7 @@ normalize_cache_t normalize_cache_create(void) normalize_record_t normalize_cache_get(normalize_cache_t nc, struct conf_service *service, - const char *spec) + const char *spec, int embed) { normalize_record_t nt; struct cached_item *ci; @@ -70,7 +70,7 @@ normalize_record_t normalize_cache_get(normalize_cache_t nc, nt = ci->nt; else { - nt = normalize_record_create(service, spec); + nt = normalize_record_create(service, spec, embed); if (nt) { ci = nmem_malloc(nc->nmem, sizeof(*ci)); diff --git a/src/normalize_cache.h b/src/normalize_cache.h index 4ee9322..4271e63 100644 --- a/src/normalize_cache.h +++ b/src/normalize_cache.h @@ -27,7 +27,7 @@ normalize_cache_t normalize_cache_create(void); normalize_record_t normalize_cache_get(normalize_cache_t nc, struct conf_service *service, - const char *spec); + const char *spec, int embed); void normalize_cache_destroy(normalize_cache_t nc); #endif diff --git a/src/normalize_record.c b/src/normalize_record.c index 129be2b..2143d0d 100644 --- a/src/normalize_record.c +++ b/src/normalize_record.c @@ -47,57 +47,80 @@ struct normalize_record_s { }; normalize_record_t normalize_record_create(struct conf_service *service, - const char *spec) + const char *spec, int embed) { NMEM nmem = nmem_create(); normalize_record_t nt = nmem_malloc(nmem, sizeof(*nt)); struct normalize_step **m = &nt->steps; - int i, num; int no_errors = 0; - char **stylesheets; - struct conf_config *conf = service->server->config; nt->nmem = nmem; - nmem_strsplit(nt->nmem, ",", spec, &stylesheets, &num); - for (i = 0; i < num; i++) + if (embed) { - WRBUF fname = conf_get_fname(conf, stylesheets[i]); - - *m = nmem_malloc(nt->nmem, sizeof(**m)); - (*m)->marcmap = NULL; - (*m)->stylesheet = NULL; - - (*m)->stylesheet2 = service_xslt_get(service, stylesheets[i]); - if ((*m)->stylesheet2) - ; - else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-4], ".xsl")) - { - if (!((*m)->stylesheet = - xsltParseStylesheetFile((xmlChar *) wrbuf_cstr(fname)))) - { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "Unable to load stylesheet: %s", - stylesheets[i]); + xmlDoc *xsp_doc = xmlParseMemory(spec, strlen(spec)); + + if (!xsp_doc) + no_errors++; + { + *m = nmem_malloc(nt->nmem, sizeof(**m)); + (*m)->marcmap = NULL; + (*m)->stylesheet = NULL; + (*m)->stylesheet2 = NULL; + + + (*m)->stylesheet = xsltParseStylesheetDoc(xsp_doc); + if (!(*m)->stylesheet) no_errors++; - } + m = &(*m)->next; } - else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-5], ".mmap")) + } + else + { + struct conf_config *conf = service->server->config; + int i, num; + char **stylesheets; + nmem_strsplit(nt->nmem, ",", spec, &stylesheets, &num); + + for (i = 0; i < num; i++) { - if (!((*m)->marcmap = marcmap_load(wrbuf_cstr(fname), nt->nmem))) + WRBUF fname = conf_get_fname(conf, stylesheets[i]); + + *m = nmem_malloc(nt->nmem, sizeof(**m)); + (*m)->marcmap = NULL; + (*m)->stylesheet = NULL; + + (*m)->stylesheet2 = service_xslt_get(service, stylesheets[i]); + if ((*m)->stylesheet2) + ; + else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-4], ".xsl")) + { + if (!((*m)->stylesheet = + xsltParseStylesheetFile((xmlChar *) wrbuf_cstr(fname)))) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Unable to load stylesheet: %s", + stylesheets[i]); + no_errors++; + } + } + else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-5], ".mmap")) + { + if (!((*m)->marcmap = marcmap_load(wrbuf_cstr(fname), nt->nmem))) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "Unable to load marcmap: %s", + stylesheets[i]); + no_errors++; + } + } + else { - yaz_log(YLOG_FATAL|YLOG_ERRNO, "Unable to load marcmap: %s", - stylesheets[i]); + yaz_log(YLOG_FATAL, "Cannot handle stylesheet: %s", stylesheets[i]); no_errors++; } + + wrbuf_destroy(fname); + m = &(*m)->next; } - else - { - yaz_log(YLOG_FATAL, "Cannot handle stylesheet: %s", stylesheets[i]); - no_errors++; - } - - wrbuf_destroy(fname); - m = &(*m)->next; } *m = 0; /* terminate list of steps */ diff --git a/src/normalize_record.h b/src/normalize_record.h index 4e748f5..f77a0dd 100644 --- a/src/normalize_record.h +++ b/src/normalize_record.h @@ -24,7 +24,7 @@ typedef struct normalize_record_s *normalize_record_t; struct conf_service; normalize_record_t normalize_record_create(struct conf_service *service, - const char *spec); + const char *spec, int embed); void normalize_record_destroy(normalize_record_t nt); diff --git a/src/session.c b/src/session.c index 54b82da..3a0fc22 100644 --- a/src/session.c +++ b/src/session.c @@ -408,40 +408,51 @@ const char *session_setting_oneval(struct session_database *db, int offset) // setting. However, this is not a realistic use scenario. static int prepare_map(struct session *se, struct session_database *sdb) { - const char *s; - - if (sdb->settings && sdb->settings[PZ_XSLT] && !sdb->map && - (s = session_setting_oneval(sdb, PZ_XSLT))) + if (sdb->settings && !sdb->map) { - char auto_stylesheet[256]; + const char *s; - if (!strcmp(s, "auto")) + if (sdb->settings[PZ_EMBED_XSLT] && + (s = session_setting_oneval(sdb, PZ_EMBED_XSLT))) + { + sdb->map = normalize_cache_get(se->normalize_cache, + se->service, s, 1); + if (!sdb->map) + return -1; + } + else if (sdb->settings[PZ_XSLT] && + (s = session_setting_oneval(sdb, PZ_XSLT))) { - const char *request_syntax = session_setting_oneval( - sdb, PZ_REQUESTSYNTAX); - if (request_syntax) + char auto_stylesheet[256]; + + if (!strcmp(s, "auto")) { - char *cp; - yaz_snprintf(auto_stylesheet, sizeof(auto_stylesheet), - "%s.xsl", request_syntax); - for (cp = auto_stylesheet; *cp; cp++) + const char *request_syntax = session_setting_oneval( + sdb, PZ_REQUESTSYNTAX); + if (request_syntax) + { + char *cp; + yaz_snprintf(auto_stylesheet, sizeof(auto_stylesheet), + "%s.xsl", request_syntax); + for (cp = auto_stylesheet; *cp; cp++) + { + /* deliberately only consider ASCII */ + if (*cp > 32 && *cp < 127) + *cp = tolower(*cp); + } + s = auto_stylesheet; + } + else { - /* deliberately only consider ASCII */ - if (*cp > 32 && *cp < 127) - *cp = tolower(*cp); + session_log(se, YLOG_WARN, + "No pz:requestsyntax for auto stylesheet"); } - s = auto_stylesheet; - } - else - { - session_log(se, YLOG_WARN, - "No pz:requestsyntax for auto stylesheet"); } + sdb->map = normalize_cache_get(se->normalize_cache, + se->service, s, 0); + if (!sdb->map) + return -1; } - sdb->map = normalize_cache_get(se->normalize_cache, - se->service, s); - if (!sdb->map) - return -1; } return 0; } diff --git a/src/settings.c b/src/settings.c index 7b70782..e7d459b 100644 --- a/src/settings.c +++ b/src/settings.c @@ -81,6 +81,7 @@ static char *hard_settings[] = { "pz:sortmap:", "pz:present_chunk", "pz:block_timeout", + "pz:embed_xslt", 0 }; diff --git a/src/settings.h b/src/settings.h index a746dfa..17756db 100644 --- a/src/settings.h +++ b/src/settings.h @@ -54,7 +54,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define PZ_SORTMAP 31 #define PZ_PRESENT_CHUNK 32 #define PZ_BLOCK_TIMEOUT 33 -#define PZ_MAX_EOF 34 +#define PZ_EMBED_XSLT 34 +#define PZ_MAX_EOF 35 struct setting {