-/* $Id: database.c,v 1.21 2007-04-20 15:36:48 quinn Exp $
+/* $Id: database.c,v 1.22 2007-04-20 16:21:19 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
db->explain = explain;
db->settings = 0;
db->next = databases;
- db->map = 0;
databases = db;
return db;
return i;
}
-// Prepare XSLT stylesheets for record normalization
-static void prepare_map(void *ignore, struct database *db)
-{
- struct setting *s;
-
- if (!db->settings)
- return;
- for (s = db->settings[PZ_XSLT]; s; s = s->next)
- {
- char **stylesheets;
- struct database_retrievalmap **m = &db->map;
- int num, i;
-
- nmem_strsplit(nmem, ",", s->value, &stylesheets, &num);
- for (i = 0; i < num; i++)
- {
- (*m) = nmem_malloc(nmem, sizeof(**m));
- (*m)->next = 0;
- if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i])))
- {
- yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s",
- stylesheets[i]);
- exit(1);
- }
- m = &(*m)->next;
- }
- }
- if (!db->map)
- yaz_log(YLOG_WARN, "No Normalization stylesheet for target %s", db->url);
-}
-
-// Read settings for each database, and prepare support data structures
-void prepare_databases(void)
-{
- grep_databases(0, 0, prepare_map);
-}
-
// This function will most likely vanish when a proper target profile mechanism is
// introduced.
void load_simpletargets(const char *fn)
-/* $Id: logic.c,v 1.13 2007-04-20 15:36:48 quinn Exp $
+/* $Id: logic.c,v 1.14 2007-04-20 16:21:19 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
+// This file contains the primary business logic. Several parts of it should
+// Eventually be factored into separate modules.
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#endif
}
- for (m = db->map; m; m = m->next){
+ for (m = sdb->map; m; m = m->next){
xmlDoc *new = 0;
#if 1
return 0;
}
+// Prepare XSLT stylesheets for record normalization
+// Structures are allocated on the session_wide nmem to avoid having
+// to recompute this for every search. This would lead
+// to leaking if a single session was to repeatedly change the PZ_XSLT
+// setting. However, this is not a realistic use scenario.
+static int prepare_map(struct session *se, struct session_database *sdb)
+{
+ struct setting *s;
+
+ if (!sdb->settings)
+ {
+ yaz_log(YLOG_WARN, "No settings on %s", sdb->database->url);
+ return -1;
+ }
+ if ((s = sdb->settings[PZ_XSLT]))
+ {
+ char **stylesheets;
+ struct database_retrievalmap **m = &sdb->map;
+ int num, i;
+
+ nmem_strsplit(se->session_nmem, ",", s->value, &stylesheets, &num);
+ for (i = 0; i < num; i++)
+ {
+ (*m) = nmem_malloc(se->session_nmem, sizeof(**m));
+ (*m)->next = 0;
+ if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i])))
+ {
+ yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s",
+ stylesheets[i]);
+ return -1;
+ }
+ m = &(*m)->next;
+ }
+ }
+ if (!sdb->map)
+ yaz_log(YLOG_WARN, "No Normalization stylesheet for target %s",
+ sdb->database->url);
+ return 0;
+}
+
// This analyzes settings and recomputes any supporting data structures
// if necessary.
-static int prepare_session_database(struct session_database *sdb)
+static int prepare_session_database(struct session *se, struct session_database *sdb)
{
if (!sdb->settings)
{
- yaz_log(YLOG_WARN, "No settings associates with %s", sdb->database->url);
+ yaz_log(YLOG_WARN, "No settings associated with %s", sdb->database->url);
return -1;
}
if (sdb->settings[PZ_NATIVESYNTAX] && !sdb->yaz_marc)
}
if (sdb->settings[PZ_XSLT] && !sdb->map)
{
+ if (prepare_map(se, sdb) < 0)
+ return -1;
}
return 0;
}
for (cl = se->clients; cl; cl = cl->next)
{
- if (prepare_session_database(cl->database) < 0)
+ if (prepare_session_database(se, cl->database) < 0)
return "CONFIG_ERROR";
if (client_parse_query(cl, query) < 0) // Query must parse for all targets
return "QUERY";
-/* $Id: pazpar2.c,v 1.80 2007-04-19 16:07:20 adam Exp $
+/* $Id: pazpar2.c,v 1.81 2007-04-20 16:21:19 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
settings_read(global_parameters.server->settings);
else
yaz_log(YLOG_WARN, "No settings-directory specified. Problems may well ensue!");
- prepare_databases();
global_parameters.odr_in = odr_createmem(ODR_DECODE);
global_parameters.odr_out = odr_createmem(ODR_ENCODE);
-/* $Id: pazpar2.h,v 1.30 2007-04-20 15:36:48 quinn Exp $
+/* $Id: pazpar2.h,v 1.31 2007-04-20 16:21:19 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
struct zr_explain *explain;
struct setting **settings;
struct database *next;
- //yaz_marc_t yaz_marc;
- struct database_retrievalmap *map;
-};
-
-// Normalization filter. Turns incoming record into internal representation
-// Simple sequence of stylesheets run in series.
-struct database_retrievalmap {
- xsltStylesheet *stylesheet;
- struct database_retrievalmap *next;
};
struct database_criterion_value {
struct client *next;
};
-#define SESSION_WATCH_RECORDS 0
-#define SESSION_WATCH_MAX 0
-
-#define SESSION_MAX_TERMLISTS 10
-
-typedef void (*session_watchfun)(void *data);
-
-struct named_termlist
-{
- char *name;
- struct termlist *termlist;
+// Normalization filter. Turns incoming record into internal representation
+// Simple sequence of stylesheets run in series.
+struct database_retrievalmap {
+ xsltStylesheet *stylesheet;
+ struct database_retrievalmap *next;
};
// Represents a database as viewed from one session, possibly with settings overriden
struct session_database *next;
};
+#define SESSION_WATCH_RECORDS 0
+#define SESSION_WATCH_MAX 0
+
+#define SESSION_MAX_TERMLISTS 10
+
+typedef void (*session_watchfun)(void *data);
+
+struct named_termlist
+{
+ char *name;
+ struct termlist *termlist;
+};
+
// End-user session
struct session {
struct session_database *databases; // All databases, settings overriden