From 7f39c2c107bb09afb58c55a1c3ed91cde6bcdea7 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Wed, 11 Apr 2007 18:42:25 +0000 Subject: [PATCH] Major change. Targets are now created when they are referred to in the settings system. This means that the .pz files are no longer needed. HOWEVER, for consistency & power, database name is now a setting, pz:name. The names in the .pz files are ignored. .pz-files should be converted to simple settings files. --- src/database.c | 5 +---- src/database.h | 3 ++- src/http_command.c | 9 ++++++--- src/pazpar2.c | 9 +++++---- src/pazpar2.h | 4 ++-- src/settings.c | 10 +++++++++- src/settings.h | 3 ++- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/database.c b/src/database.c index 39514d4..1e6c18d 100644 --- a/src/database.c +++ b/src/database.c @@ -1,4 +1,4 @@ -/* $Id: database.c,v 1.13 2007-04-11 16:48:09 quinn Exp $ +/* $Id: database.c,v 1.14 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -154,7 +154,6 @@ static struct database *load_database(const char *id) memset(db, 0, sizeof(*db)); db->host = host; db->url = nmem_strdup(nmem, id); - db->name = 0; db->databases = xmalloc(2 * sizeof(char *)); db->databases[0] = nmem_strdup(nmem, dbname); db->databases[1] = 0; @@ -413,8 +412,6 @@ void load_simpletargets(const char *fn) if (!(db = find_database(url, 0))) yaz_log(YLOG_WARN, "Unable to load database %s", url); - if (name && db) - db->name = nmem_strdup(nmem, name); } fclose(f); } diff --git a/src/database.h b/src/database.h index 9de98d7..08e87ae 100644 --- a/src/database.h +++ b/src/database.h @@ -1,4 +1,4 @@ -/* $Id: database.h,v 1.5 2007-04-11 02:14:15 quinn Exp $ +/* $Id: database.h,v 1.6 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -24,6 +24,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA void load_simpletargets(const char *fn); void prepare_databases(void); +struct database *find_database(const char *id, int new); int database_match_criteria(struct session_database *db, struct database_criterion *cl); int session_grep_databases(struct session *se, struct database_criterion *cl, void (*fun)(void *context, struct session_database *db)); diff --git a/src/http_command.c b/src/http_command.c index d68cce9..64f638d 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.33 2007-04-11 02:14:15 quinn Exp $ +/* $Id: http_command.c,v 1.34 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ /* - * $Id: http_command.c,v 1.33 2007-04-11 02:14:15 quinn Exp $ + * $Id: http_command.c,v 1.34 2007-04-11 18:42:25 quinn Exp $ */ #include @@ -44,6 +44,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "pazpar2.h" #include "http.h" #include "http_command.h" +#include "settings.h" extern struct parameters global_parameters; extern IOCHAN channel_list; @@ -382,9 +383,11 @@ static void write_metadata(WRBUF w, struct conf_service *service, static void write_subrecord(struct record *r, WRBUF w, struct conf_service *service) { + char *name = session_setting_oneval(r->client->database, PZ_NAME); + wrbuf_printf(w, "\n", r->client->database->database->url, - r->client->database->database->name ? r->client->database->database->name : ""); + *name ? name : "Unknown"); write_metadata(w, service, r->metadata, 1); wrbuf_puts(w, "\n"); } diff --git a/src/pazpar2.c b/src/pazpar2.c index 526e5fa..e1c992c 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.72 2007-04-11 13:27:06 quinn Exp $ +/* $Id: pazpar2.c,v 1.73 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -68,7 +68,6 @@ static void connection_destroy(struct connection *co); static int client_prep_connection(struct client *cl); static void ingest_records(struct client *cl, Z_Records *r); void session_alert_watch(struct session *s, int what); -char *session_setting_oneval(struct session_database *db, int offset); IOCHAN channel_list = 0; // Master list of connections we're handling events to @@ -793,7 +792,7 @@ static struct record *ingest_record(struct client *cl, Z_External *rec) char *session_setting_oneval(struct session_database *db, int offset) { if (!db->settings[offset]) - return 0; + return ""; return db->settings[offset]->value; } @@ -1420,8 +1419,10 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count) *count = 0; for (cl = se->clients; cl; cl = cl->next) { + char *name = session_setting_oneval(cl->database, PZ_NAME); + res[*count].id = cl->database->database->url; - res[*count].name = cl->database->database->name; + res[*count].name = *name ? name : "Unknown"; res[*count].hits = cl->hits; res[*count].records = cl->records; res[*count].diagnostic = cl->diagnostic; diff --git a/src/pazpar2.h b/src/pazpar2.h index 85360a7..eeb6bdc 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -1,4 +1,4 @@ -/* $Id: pazpar2.h,v 1.22 2007-04-11 02:14:15 quinn Exp $ +/* $Id: pazpar2.h,v 1.23 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -87,7 +87,6 @@ struct host { struct database { struct host *host; char *url; - char *name; char **databases; int errors; struct zr_explain *explain; @@ -260,6 +259,7 @@ struct termlist_score **termlist(struct session *s, const char *name, int *num); void session_set_watch(struct session *s, int what, session_watchfun fun, void *data); int session_active_clients(struct session *s); void session_apply_setting(struct session *se, char *dbname, char *setting, char *value); +char *session_setting_oneval(struct session_database *db, int offset); #endif diff --git a/src/settings.c b/src/settings.c index ba913db..e86b9d1 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,4 +1,4 @@ -/* $Id: settings.c,v 1.12 2007-04-11 11:22:35 marc Exp $ +/* $Id: settings.c,v 1.13 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -56,6 +56,7 @@ static char *hard_settings[] = { "pz:allow", "pz:maxrecs", "pz:id", + "pz:name", 0 }; @@ -252,16 +253,23 @@ static void read_settings(const char *path, // Callback. Adds a new entry to the dictionary if necessary // This is used in pass 1 to determine layout of dictionary +// and to load any databases mentioned static void prepare_dictionary(struct setting *set) { int i; char *p; + // If target address is not wildcard, add the database + if (*set->target && set->target[strlen(set->target) - 1] != '*') + find_database(set->target, 0); + + // Determine if we already have a dictionary entry if (!strncmp(set->name, "pz:", 3) && (p = strchr(set->name + 3, ':'))) *(p + 1) = '\0'; for (i = 0; i < dictionary->num; i++) if (!strcmp(dictionary->dict[i], set->name)) return; + if (!strncmp(set->name, "pz:", 3)) // Probably a typo in config fle { yaz_log(YLOG_FATAL, "Unknown pz: setting '%s'", set->name); diff --git a/src/settings.h b/src/settings.h index 5b3073a..aeae58c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,4 +1,4 @@ -/* $Id: settings.h,v 1.11 2007-04-11 02:14:15 quinn Exp $ +/* $Id: settings.h,v 1.12 2007-04-11 18:42:25 quinn Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -33,6 +33,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #define PZ_ALLOW 8 #define PZ_MAXRECS 9 #define PZ_ID 10 +#define PZ_NAME 11 struct setting { -- 1.7.10.4