From: Adam Dickmeiss Date: Fri, 27 Apr 2012 11:20:49 +0000 (+0200) Subject: Setting pz:xslt may embed local XSLT X-Git-Tag: v1.6.13~9^2~4^2~7 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=6019a6da5031c198bae79830cc8cf6ff2f7dce7e;p=pazpar2-moved-to-github.git Setting pz:xslt may embed local XSLT This is not CDATA but nodes embedded. For example: --- diff --git a/src/normalize_cache.c b/src/normalize_cache.c index 2d69f33..92b71ae 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, int embed) + const char *spec) { 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, embed); + nt = normalize_record_create(service, spec); if (nt) { ci = nmem_malloc(nc->nmem, sizeof(*ci)); diff --git a/src/normalize_cache.h b/src/normalize_cache.h index 4271e63..4ee9322 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, int embed); + const char *spec); void normalize_cache_destroy(normalize_cache_t nc); #endif diff --git a/src/normalize_record.c b/src/normalize_record.c index 2143d0d..90876e5 100644 --- a/src/normalize_record.c +++ b/src/normalize_record.c @@ -47,12 +47,16 @@ struct normalize_record_s { }; normalize_record_t normalize_record_create(struct conf_service *service, - const char *spec, int embed) + const char *spec) { NMEM nmem = nmem_create(); normalize_record_t nt = nmem_malloc(nmem, sizeof(*nt)); struct normalize_step **m = &nt->steps; int no_errors = 0; + int embed = 0; + + if (*spec == '<') + embed = 1; nt->nmem = nmem; diff --git a/src/normalize_record.h b/src/normalize_record.h index f77a0dd..4e748f5 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, int embed); + const char *spec); void normalize_record_destroy(normalize_record_t nt); diff --git a/src/session.c b/src/session.c index 3a0fc22..b5a3d8f 100644 --- a/src/session.c +++ b/src/session.c @@ -412,16 +412,8 @@ static int prepare_map(struct session *se, struct session_database *sdb) { const char *s; - 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))) + if (sdb->settings[PZ_XSLT] && + (s = session_setting_oneval(sdb, PZ_XSLT))) { char auto_stylesheet[256]; @@ -449,7 +441,7 @@ static int prepare_map(struct session *se, struct session_database *sdb) } } sdb->map = normalize_cache_get(se->normalize_cache, - se->service, s, 0); + se->service, s); if (!sdb->map) return -1; } diff --git a/src/settings.c b/src/settings.c index e7d459b..cb55b5e 100644 --- a/src/settings.c +++ b/src/settings.c @@ -81,7 +81,6 @@ static char *hard_settings[] = { "pz:sortmap:", "pz:present_chunk", "pz:block_timeout", - "pz:embed_xslt", 0 }; @@ -199,12 +198,16 @@ int settings_read_node_x(xmlNode *n, continue; if (!strcmp((const char *) n->name, "set")) { + xmlNode *root = n->children; struct setting set; char *name = (char *) xmlGetProp(n, (xmlChar *) "name"); char *target = (char *) xmlGetProp(n, (xmlChar *) "target"); char *value = (char *) xmlGetProp(n, (xmlChar *) "value"); char *user = (char *) xmlGetProp(n, (xmlChar *) "user"); char *precedence = (char *) xmlGetProp(n, (xmlChar *) "precedence"); + xmlChar *buf_out = 0; + + set.next = 0; if (precedence) set.precedence = atoi((char *) precedence); @@ -215,8 +218,33 @@ int settings_read_node_x(xmlNode *n, set.target = target ? target : targeta; set.name = name ? name : namea; - set.value = value ? value : valuea; - set.next = 0; + + while (root && root->type != XML_ELEMENT_NODE) + root = root->next; + if (!root) + set.value = value ? value : valuea; + else + { /* xml document content for this setting */ + xmlDoc *doc = xmlNewDoc(BAD_CAST "1.0"); + if (!doc) + { + if (set.name) + yaz_log(YLOG_WARN, "bad XML content for setting " + "name=%s", set.name); + else + yaz_log(YLOG_WARN, "bad XML content for setting"); + ret_val = -1; + } + else + { + int len_out; + xmlDocSetRootElement(doc, xmlCopyNode(root, 1)); + xmlDocDumpMemory(doc, &buf_out, &len_out); + /* xmlDocDumpMemory 0-terminates */ + set.value = (char *) buf_out; + xmlFreeDoc(doc); + } + } if (set.name && set.value && set.target) (*fun)(client_data, &set); @@ -229,6 +257,7 @@ int settings_read_node_x(xmlNode *n, yaz_log(YLOG_WARN, "missing name/value/target for setting"); ret_val = -1; } + xmlFree(buf_out); xmlFree(name); xmlFree(precedence); xmlFree(value); diff --git a/src/settings.h b/src/settings.h index 17756db..a746dfa 100644 --- a/src/settings.h +++ b/src/settings.h @@ -54,8 +54,7 @@ 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_EMBED_XSLT 34 -#define PZ_MAX_EOF 35 +#define PZ_MAX_EOF 34 struct setting {