From 636ea26e6f3811361226bc598d0d4d7409d07563 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Fri, 20 Apr 2007 15:36:48 +0000 Subject: [PATCH] *** empty log message *** --- src/database.c | 36 +----------------- src/logic.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++------ src/pazpar2.h | 8 ++-- src/settings.c | 3 +- src/settings.h | 19 +++++----- 5 files changed, 116 insertions(+), 62 deletions(-) diff --git a/src/database.c b/src/database.c index 2ca3af5..51713e6 100644 --- a/src/database.c +++ b/src/database.c @@ -1,4 +1,4 @@ -/* $Id: database.c,v 1.20 2007-04-20 04:32:33 quinn Exp $ +/* $Id: database.c,v 1.21 2007-04-20 15:36:48 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -165,7 +165,6 @@ static struct database *load_database(const char *id) db->explain = explain; db->settings = 0; db->next = databases; - db->yaz_marc = 0; db->map = 0; databases = db; @@ -287,38 +286,6 @@ int grep_databases(void *context, struct database_criterion *cl, return i; } -// Initialize YAZ Map structures for MARC-based targets -static void prepare_yazmarc(void *ignore, struct database *db) -{ - struct setting *s; - - if (!db->settings) - return; - for (s = db->settings[PZ_NATIVESYNTAX]; s; s = s->next) - if (!strcmp(s->value, "iso2709")) - { - char *encoding = "marc-8s"; - yaz_iconv_t cm; - - db->yaz_marc = yaz_marc_create(); - yaz_marc_subfield_str(db->yaz_marc, "\t"); - - // See if a native encoding is specified - if (db->settings[PZ_ENCODING]) - encoding = db->settings[PZ_ENCODING]->value; - - cm = yaz_iconv_open("utf-8", encoding); - if (!cm) - { - yaz_log(YLOG_FATAL, - "Unable to map from %s to UTF-8 for target %s", - encoding, db->url); - exit(1); - } - yaz_marc_iconv(db->yaz_marc, cm); - } -} - // Prepare XSLT stylesheets for record normalization static void prepare_map(void *ignore, struct database *db) { @@ -353,7 +320,6 @@ static void prepare_map(void *ignore, struct database *db) // Read settings for each database, and prepare support data structures void prepare_databases(void) { - grep_databases(0, 0, prepare_yazmarc); grep_databases(0, 0, prepare_map); } diff --git a/src/logic.c b/src/logic.c index 3cc1a23..aae6380 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.12 2007-04-20 04:32:33 quinn Exp $ +/* $Id: logic.c,v 1.13 2007-04-20 15:36:48 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -518,36 +518,36 @@ static void add_facet(struct session *s, const char *type, const char *value) static xmlDoc *normalize_record(struct client *cl, Z_External *rec) { struct database_retrievalmap *m; - struct database *db = cl->database->database; + struct session_database *sdb = cl->database; + struct database *db = sdb->database; xmlNode *res; xmlDoc *rdoc; // First normalize to XML - if (db->yaz_marc) + if (sdb->yaz_marc) { char *buf; int len; if (rec->which != Z_External_octet) { yaz_log(YLOG_WARN, "Unexpected external branch, probably BER %s", - cl->database->database->url); + db->url); return 0; } buf = (char*) rec->u.octet_aligned->buf; len = rec->u.octet_aligned->len; - if (yaz_marc_read_iso2709(db->yaz_marc, buf, len) < 0) + if (yaz_marc_read_iso2709(sdb->yaz_marc, buf, len) < 0) { - yaz_log(YLOG_WARN, "Failed to decode MARC %s", - cl->database->database->url); + yaz_log(YLOG_WARN, "Failed to decode MARC %s", db->url); return 0; } - yaz_marc_write_using_libxml2(db->yaz_marc, 1); - if (yaz_marc_write_xml(db->yaz_marc, &res, + yaz_marc_write_using_libxml2(sdb->yaz_marc, 1); + if (yaz_marc_write_xml(sdb->yaz_marc, &res, "http://www.loc.gov/MARC21/slim", 0, 0) < 0) { yaz_log(YLOG_WARN, "Failed to encode as XML %s", - cl->database->database->url); + db->url); return 0; } rdoc = xmlNewDoc((xmlChar *) "1.0"); @@ -558,14 +558,14 @@ static xmlDoc *normalize_record(struct client *cl, Z_External *rec) { yaz_log(YLOG_FATAL, "Unknown native_syntax in normalize_record from %s", - cl->database->database->url); + db->url); exit(1); } if (global_parameters.dump_records){ fprintf(stderr, "Input Record (normalized) from %s\n----------------\n", - cl->database->database->url); + db->url); #if LIBXML_VERSION >= 20600 xmlDocFormatDump(stderr, rdoc, 1); #else @@ -1248,6 +1248,61 @@ static int client_prep_connection(struct client *cl) return 0; } +// Initialize YAZ Map structures for MARC-based targets +static int prepare_yazmarc(struct session_database *sdb) +{ + struct setting *s; + + if (!sdb->settings) + { + yaz_log(YLOG_WARN, "No settings for %s", sdb->database->url); + return -1; + } + if ((s = sdb->settings[PZ_NATIVESYNTAX]) && !strncmp(s->value, "iso2709", 7)) + { + char *encoding = "marc-8s", *e; + yaz_iconv_t cm; + + // See if a native encoding is specified + if ((e = strchr(s->value, ';'))) + encoding = e + 1; + + sdb->yaz_marc = yaz_marc_create(); + yaz_marc_subfield_str(sdb->yaz_marc, "\t"); + + cm = yaz_iconv_open("utf-8", encoding); + if (!cm) + { + yaz_log(YLOG_FATAL, + "Unable to map from %s to UTF-8 for target %s", + encoding, sdb->database->url); + return -1; + } + yaz_marc_iconv(sdb->yaz_marc, cm); + } + return 0; +} + +// This analyzes settings and recomputes any supporting data structures +// if necessary. +static int prepare_session_database(struct session_database *sdb) +{ + if (!sdb->settings) + { + yaz_log(YLOG_WARN, "No settings associates with %s", sdb->database->url); + return -1; + } + if (sdb->settings[PZ_NATIVESYNTAX] && !sdb->yaz_marc) + { + if (prepare_yazmarc(sdb) < 0) + return -1; + } + if (sdb->settings[PZ_XSLT] && !sdb->map) + { + } + return 0; +} + // Initialize CCL map for a target static CCL_bibset prepare_cclmap(struct client *cl) { @@ -1471,11 +1526,19 @@ char *search(struct session *se, char *query, char *filter) return "NOTARGETS"; se->relevance = 0; + for (cl = se->clients; cl; cl = cl->next) + { + if (prepare_session_database(cl->database) < 0) + return "CONFIG_ERROR"; if (client_parse_query(cl, query) < 0) // Query must parse for all targets return "QUERY"; + } + for (cl = se->clients; cl; cl = cl->next) + { client_prep_connection(cl); + } return 0; } @@ -1502,6 +1565,29 @@ void session_apply_setting(struct session *se, char *dbname, char *setting, char new->value = value; new->next = sdb->settings[offset]; sdb->settings[offset] = new; + + // Force later recompute of settings-driven data structures + // (happens when a search starts and client connections are prepared) + switch (offset) + { + case PZ_NATIVESYNTAX: + if (sdb->yaz_marc) + { + yaz_marc_destroy(sdb->yaz_marc); + sdb->yaz_marc = 0; + } + break; + case PZ_XSLT: + if (sdb->map) + { + struct database_retrievalmap *m; + // We don't worry about the map structure -- it's in nmem + for (m = sdb->map; m; m = m->next) + xsltFreeStylesheet(m->stylesheet); + sdb->map = 0; + } + break; + } break; } if (!sdb) @@ -1516,6 +1602,8 @@ void session_init_databases_fun(void *context, struct database *db) int i; new->database = db; + new->yaz_marc = 0; + new->map = 0; new->settings = nmem_malloc(se->session_nmem, sizeof(struct settings *) * num); for (i = 0; i < num; i++) new->settings[i] = db->settings[i]; diff --git a/src/pazpar2.h b/src/pazpar2.h index 2f5a4e2..a7047c7 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -1,4 +1,4 @@ -/* $Id: pazpar2.h,v 1.29 2007-04-20 13:03:22 marc Exp $ +/* $Id: pazpar2.h,v 1.30 2007-04-20 15:36:48 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -61,7 +61,7 @@ struct database { struct zr_explain *explain; struct setting **settings; struct database *next; - yaz_marc_t yaz_marc; + //yaz_marc_t yaz_marc; struct database_retrievalmap *map; }; @@ -140,11 +140,13 @@ struct named_termlist }; // Represents a database as viewed from one session, possibly with settings overriden -// for that session (to support authorization/authentication) +// for that session struct session_database { struct database *database; struct setting **settings; + yaz_marc_t yaz_marc; + struct database_retrievalmap *map; struct session_database *next; }; diff --git a/src/settings.c b/src/settings.c index 6212162..7496dc7 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,4 +1,4 @@ -/* $Id: settings.c,v 1.16 2007-04-13 01:48:22 quinn Exp $ +/* $Id: settings.c,v 1.17 2007-04-20 15:36:48 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -50,7 +50,6 @@ static char *hard_settings[] = { "pz:elements", "pz:requestsyntax", "pz:cclmap:", - "pz:encoding", "pz:xslt", "pz:nativesyntax", "pz:authentication", diff --git a/src/settings.h b/src/settings.h index 09ec5f4..f952d57 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,4 +1,4 @@ -/* $Id: settings.h,v 1.14 2007-04-12 11:35:08 marc Exp $ +/* $Id: settings.h,v 1.15 2007-04-20 15:36:48 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -26,15 +26,14 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define PZ_ELEMENTS 1 #define PZ_REQUESTSYNTAX 2 #define PZ_CCLMAP 3 -#define PZ_ENCODING 4 -#define PZ_XSLT 5 -#define PZ_NATIVESYNTAX 6 -#define PZ_AUTHENTICATION 7 -#define PZ_ALLOW 8 -#define PZ_MAXRECS 9 -#define PZ_ID 10 -#define PZ_NAME 11 -#define PZ_QUERYENCODING 12 +#define PZ_XSLT 4 +#define PZ_NATIVESYNTAX 5 +#define PZ_AUTHENTICATION 6 +#define PZ_ALLOW 7 +#define PZ_MAXRECS 8 +#define PZ_ID 9 +#define PZ_NAME 10 +#define PZ_QUERYENCODING 11 struct setting -- 1.7.10.4