New setting embed_xslt
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 26 Apr 2012 13:24:01 +0000 (15:24 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 26 Apr 2012 13:24:01 +0000 (15:24 +0200)
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 92b71ae..2d69f33 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)
+                                       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));
index 4ee9322..4271e63 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);
+                                       const char *spec, int embed);
 void normalize_cache_destroy(normalize_cache_t nc);
 
 #endif
index 129be2b..2143d0d 100644 (file)
@@ -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 */
 
index 4e748f5..f77a0dd 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);
+                                           const char *spec, int embed);
 
 void normalize_record_destroy(normalize_record_t nt);
 
index 54b82da..3a0fc22 100644 (file)
@@ -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;
 }
index 7b70782..e7d459b 100644 (file)
@@ -81,6 +81,7 @@ static char *hard_settings[] = {
     "pz:sortmap:",
     "pz:present_chunk",
     "pz:block_timeout",
+    "pz:embed_xslt",
     0
 };
 
index a746dfa..17756db 100644 (file)
@@ -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
 {