Setting pz:xslt may embed local XSLT
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 27 Apr 2012 11:20:49 +0000 (13:20 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 27 Apr 2012 11:22:37 +0000 (13:22 +0200)
This is not CDATA but nodes embedded. For example:
<settings target="target="z3950.indexdata.com/marc">
 <set name="pz:xslt">
   <xsl:stylesheet
      version="1.0"
    ..
   </xsl:stylesheet>
 </set>
</settings>

src/normalize_cache.c
src/normalize_cache.h
src/normalize_record.c
src/normalize_record.h
src/session.c
src/settings.c
src/settings.h

index 2d69f33..92b71ae 100644 (file)
@@ -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));
index 4271e63..4ee9322 100644 (file)
@@ -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
index 2143d0d..90876e5 100644 (file)
@@ -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;
 
index f77a0dd..4e748f5 100644 (file)
@@ -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);
 
index 3a0fc22..b5a3d8f 100644 (file)
@@ -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;
         }
index e7d459b..cb55b5e 100644 (file)
@@ -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);
index 17756db..a746dfa 100644 (file)
@@ -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
 {