From bb76bca1e2b4969ea08cf2f1f57d74cfa31dd026 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 8 Sep 2009 09:48:50 +0200 Subject: [PATCH] Targetprofiles part of service. The 'targetprofiles' element, if present, must be defined inside 'service' rather than in 'pazpar2' (global). --- src/database.c | 20 ++++++-------------- src/pazpar2_config.c | 28 +++++++++++++++++++--------- src/pazpar2_config.h | 5 ++--- src/settings.c | 2 +- test/test_http.cfg | 2 +- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/database.c b/src/database.c index 204b3ae..d5b9e75 100644 --- a/src/database.c +++ b/src/database.c @@ -47,24 +47,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA static struct host *hosts = 0; // The hosts we know about -#if 0 -static xmlDoc *get_explain_xml(const char *id) +static xmlDoc *get_explain_xml(struct conf_targetprofiles *targetprofiles, + const char *id) { struct stat st; char *dir; char path[256]; char ide[256]; - if (!config || !config->targetprofiles) - { - yaz_log(YLOG_WARN, "Config must be loaded and specify targetprofiles"); - return 0; - } - if (config->targetprofiles->type != Targetprofiles_local) + if (targetprofiles->type != Targetprofiles_local) { yaz_log(YLOG_FATAL, "Only supports local type"); return 0; } - dir = config->targetprofiles->src; + dir = targetprofiles->src; urlencode(id, ide); sprintf(path, "%s/%s", dir, ide); if (!stat(path, &st)) @@ -72,7 +67,6 @@ static xmlDoc *get_explain_xml(const char *id) else return 0; } -#endif // Create a new host structure for hostport static struct host *create_host(const char *hostport) @@ -117,15 +111,13 @@ static struct database *load_database(const char *id, yaz_log(YLOG_LOG, "New database: %s", id); -#if 0 - if (config && config->targetprofiles - && (doc = get_explain_xml(id))) + if (service->targetprofiles + && (doc = get_explain_xml(service->targetprofiles, id))) { explain = zr_read_xml(service->nmem, xmlDocGetRootElement(doc)); if (!explain) return 0; } -#endif if (strlen(id) > 255) return 0; diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index 767ea2f..05db1f6 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -41,6 +41,9 @@ static char confdir[256] = "."; static char *parse_settings(NMEM nmem, xmlNode *node); +static struct conf_targetprofiles *parse_targetprofiles(NMEM nmem, + xmlNode *node); + static struct conf_metadata * conf_metadata_assign(NMEM nmem, struct conf_metadata * metadata, @@ -106,6 +109,8 @@ struct conf_service * conf_service_create(int num_metadata, int num_sortkeys, service->next = 0; service->settings = 0; service->databases = 0; + service->targetprofiles = 0; + service->id = service_id ? nmem_strdup(nmem, service_id) : 0; service->num_metadata = num_metadata; @@ -247,6 +252,17 @@ static struct conf_service *parse_service(xmlNode *node, const char *service_id) if (!service->settings) return 0; } + else if (!strcmp((const char *) n->name, (const char *) "targetprofiles")) + { + if (service->targetprofiles) + { + yaz_log(YLOG_FATAL, "Can't repeat targetprofiles"); + return 0; + } + if (!(service->targetprofiles = + parse_targetprofiles(service->nmem, n))) + return 0; + } else if (!strcmp((const char *) n->name, (const char *) "metadata")) { xmlChar *xml_name = xmlGetProp(n, (xmlChar *) "name"); @@ -638,7 +654,6 @@ static struct conf_config *parse_config(xmlNode *root) r->nmem = nmem; r->servers = 0; - r->targetprofiles = 0; for (n = root->children; n; n = n->next) { @@ -654,14 +669,9 @@ static struct conf_config *parse_config(xmlNode *root) } else if (!strcmp((const char *) n->name, "targetprofiles")) { - // It would be fun to be able to fix this sometime - if (r->targetprofiles) - { - yaz_log(YLOG_FATAL, "Can't repeat targetprofiles"); - return 0; - } - if (!(r->targetprofiles = parse_targetprofiles(nmem, n))) - return 0; + yaz_log(YLOG_FATAL, "targetprofiles unsupported here. Must be part of service"); + return 0; + } else { diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index 3118631..61166d8 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -111,8 +111,8 @@ struct conf_service pp2_charset_t sort_pct; pp2_charset_t mergekey_pct; - struct database *databases; + struct conf_targetprofiles *targetprofiles; }; struct conf_service * conf_service_create(int num_metadata, int num_sortkeys, @@ -168,9 +168,8 @@ struct conf_targetprofiles struct conf_config { - NMEM nmem; + NMEM nmem; /* for conf_config and servers memory */ struct conf_server *servers; - struct conf_targetprofiles *targetprofiles; }; struct conf_config *read_config(const char *fname); diff --git a/src/settings.c b/src/settings.c index 44de854..74621fc 100644 --- a/src/settings.c +++ b/src/settings.c @@ -434,7 +434,7 @@ static void prepare_target_dictionary(struct conf_service *service, for (i = 0; i < dictionary->num; i++) if (!strcmp(dictionary->dict[i], set->name)) return; - yaz_log(YLOG_WARN, "setting %s not configured as metadata", set->name); + yaz_log(YLOG_WARN, "Setting '%s' not configured as metadata", set->name); } // If we ever decide we need to be able to specify multiple settings directories, diff --git a/test/test_http.cfg b/test/test_http.cfg index 2ca4acd..cc9f1f0 100644 --- a/test/test_http.cfg +++ b/test/test_http.cfg @@ -7,6 +7,7 @@ + @@ -39,7 +40,6 @@ -