X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fconfig.c;h=7c4942edcc3c86f827b76edf1e5d76c3175463e7;hb=592591ac165b4e844f3968e566d52ba20dbbf26a;hp=80a32996d96b7c46dce12ff4a2c70743ec2e6e1a;hpb=a567f55ee47da94c337b232a3848d1c8bab254b2;p=pazpar2-moved-to-github.git diff --git a/src/config.c b/src/config.c index 80a3299..7c4942e 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,25 @@ -/* $Id: config.c,v 1.14 2007-02-05 16:15:41 quinn Exp $ */ +/* $Id: config.c,v 1.23 2007-04-10 08:48:56 adam Exp $ + Copyright (c) 2006-2007, Index Data. + +This file is part of Pazpar2. + +Pazpar2 is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Pazpar2; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. + */ + +/* $Id: config.c,v 1.23 2007-04-10 08:48:56 adam Exp $ */ #include @@ -36,11 +57,12 @@ static struct conf_service *parse_service(xmlNode *node) r->num_sortkeys = r->num_metadata = 0; // Allocate array of conf metadata and sortkey tructs, if necessary for (n = node->children; n; n = n->next) - if (n->type == XML_ELEMENT_NODE && !strcmp(n->name, "metadata")) + if (n->type == XML_ELEMENT_NODE && !strcmp((const char *) + n->name, "metadata")) { - xmlChar *sortkey = xmlGetProp(n, "sortkey"); + xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey"); r->num_metadata++; - if (sortkey && strcmp(sortkey, "no")) + if (sortkey && strcmp((const char *) sortkey, "no")) r->num_sortkeys++; xmlFree(sortkey); } @@ -57,28 +79,28 @@ static struct conf_service *parse_service(xmlNode *node) { if (n->type != XML_ELEMENT_NODE) continue; - if (!strcmp(n->name, "metadata")) + if (!strcmp((const char *) n->name, (const char *) "metadata")) { struct conf_metadata *md = &r->metadata[md_node]; - xmlChar *name = xmlGetProp(n, "name"); - xmlChar *brief = xmlGetProp(n, "brief"); - xmlChar *sortkey = xmlGetProp(n, "sortkey"); - xmlChar *merge = xmlGetProp(n, "merge"); - xmlChar *type = xmlGetProp(n, "type"); - xmlChar *termlist = xmlGetProp(n, "termlist"); - xmlChar *rank = xmlGetProp(n, "rank"); + xmlChar *name = xmlGetProp(n, (xmlChar *) "name"); + xmlChar *brief = xmlGetProp(n, (xmlChar *) "brief"); + xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey"); + xmlChar *merge = xmlGetProp(n, (xmlChar *) "merge"); + xmlChar *type = xmlGetProp(n, (xmlChar *) "type"); + xmlChar *termlist = xmlGetProp(n, (xmlChar *) "termlist"); + xmlChar *rank = xmlGetProp(n, (xmlChar *) "rank"); if (!name) { yaz_log(YLOG_FATAL, "Must specify name in metadata element"); return 0; } - md->name = nmem_strdup(nmem, name); + md->name = nmem_strdup(nmem, (const char *) name); if (brief) { - if (!strcmp(brief, "yes")) + if (!strcmp((const char *) brief, "yes")) md->brief = 1; - else if (strcmp(brief, "no")) + else if (strcmp((const char *) brief, "no")) { yaz_log(YLOG_FATAL, "metadata/brief must be yes or no"); return 0; @@ -89,9 +111,9 @@ static struct conf_service *parse_service(xmlNode *node) if (termlist) { - if (!strcmp(termlist, "yes")) + if (!strcmp((const char *) termlist, "yes")) md->termlist = 1; - else if (strcmp(termlist, "no")) + else if (strcmp((const char *) termlist, "no")) { yaz_log(YLOG_FATAL, "metadata/termlist must be yes or no"); return 0; @@ -101,15 +123,15 @@ static struct conf_service *parse_service(xmlNode *node) md->termlist = 0; if (rank) - md->rank = atoi(rank); + md->rank = atoi((const char *) rank); else md->rank = 0; if (type) { - if (!strcmp(type, "generic")) + if (!strcmp((const char *) type, "generic")) md->type = Metadata_type_generic; - else if (!strcmp(type, "year")) + else if (!strcmp((const char *) type, "year")) md->type = Metadata_type_year; else { @@ -122,15 +144,15 @@ static struct conf_service *parse_service(xmlNode *node) if (merge) { - if (!strcmp(merge, "no")) + if (!strcmp((const char *) merge, "no")) md->merge = Metadata_merge_no; - else if (!strcmp(merge, "unique")) + else if (!strcmp((const char *) merge, "unique")) md->merge = Metadata_merge_unique; - else if (!strcmp(merge, "longest")) + else if (!strcmp((const char *) merge, "longest")) md->merge = Metadata_merge_longest; - else if (!strcmp(merge, "range")) + else if (!strcmp((const char *) merge, "range")) md->merge = Metadata_merge_range; - else if (!strcmp(merge, "all")) + else if (!strcmp((const char *) merge, "all")) md->merge = Metadata_merge_all; else { @@ -141,7 +163,7 @@ static struct conf_service *parse_service(xmlNode *node) else md->merge = Metadata_merge_no; - if (sortkey && strcmp(sortkey, "no")) + if (sortkey && strcmp((const char *) sortkey, "no")) { struct conf_sortkey *sk = &r->sortkeys[sk_node]; if (md->merge == Metadata_merge_no) @@ -149,9 +171,9 @@ static struct conf_service *parse_service(xmlNode *node) yaz_log(YLOG_FATAL, "Can't specify sortkey on a non-merged field"); return 0; } - if (!strcmp(sortkey, "numeric")) + if (!strcmp((const char *) sortkey, "numeric")) sk->type = Metadata_sortkey_numeric; - else if (!strcmp(sortkey, "skiparticle")) + else if (!strcmp((const char *) sortkey, "skiparticle")) sk->type = Metadata_sortkey_skiparticle; else { @@ -182,6 +204,22 @@ static struct conf_service *parse_service(xmlNode *node) return r; } +static char *parse_settings(xmlNode *node) +{ + xmlChar *src = xmlGetProp(node, (xmlChar *) "src"); + char *r; + + if (src) + r = nmem_strdup(nmem, (const char *) src); + else + { + yaz_log(YLOG_FATAL, "Must specify src in targetprofile"); + return 0; + } + xmlFree(src); + return r; +} + static struct conf_server *parse_server(xmlNode *node) { xmlNode *n; @@ -192,45 +230,76 @@ static struct conf_server *parse_server(xmlNode *node) r->proxy_host = 0; r->proxy_port = 0; r->myurl = 0; + r->zproxy_host = 0; + r->zproxy_port = 0; r->service = 0; r->next = 0; + r->settings = 0; for (n = node->children; n; n = n->next) { if (n->type != XML_ELEMENT_NODE) continue; - if (!strcmp(n->name, "listen")) + if (!strcmp((const char *) n->name, "listen")) { - xmlChar *port = xmlGetProp(n, "port"); - xmlChar *host = xmlGetProp(n, "host"); + xmlChar *port = xmlGetProp(n, (xmlChar *) "port"); + xmlChar *host = xmlGetProp(n, (xmlChar *) "host"); if (port) - r->port = atoi(port); + r->port = atoi((const char *) port); if (host) - r->host = nmem_strdup(nmem, host); + r->host = nmem_strdup(nmem, (const char *) host); xmlFree(port); xmlFree(host); } - else if (!strcmp(n->name, "proxy")) + else if (!strcmp((const char *) n->name, "proxy")) { - xmlChar *port = xmlGetProp(n, "port"); - xmlChar *host = xmlGetProp(n, "host"); - xmlChar *myurl = xmlGetProp(n, "myurl"); + xmlChar *port = xmlGetProp(n, (xmlChar *) "port"); + xmlChar *host = xmlGetProp(n, (xmlChar *) "host"); + xmlChar *myurl = xmlGetProp(n, (xmlChar *) "myurl"); if (port) - r->proxy_port = atoi(port); + r->proxy_port = atoi((const char *) port); if (host) - r->proxy_host = nmem_strdup(nmem, host); + r->proxy_host = nmem_strdup(nmem, (const char *) host); if (myurl) - r->myurl = nmem_strdup(nmem, myurl); + r->myurl = nmem_strdup(nmem, (const char *) myurl); +#ifdef GAGA else { yaz_log(YLOG_FATAL, "Must specify @myurl for proxy"); return 0; } +#endif xmlFree(port); xmlFree(host); xmlFree(myurl); } - else if (!strcmp(n->name, "service")) + else if (!strcmp((const char *) n->name, "zproxy")) + { + xmlChar *port = 0; + xmlChar *host = 0; + + port = xmlGetProp(n, (xmlChar *) "port"); + host = xmlGetProp(n, (xmlChar *) "host"); + + if (port) + r->zproxy_port = atoi((const char *) port); + if (host) + r->zproxy_host = nmem_strdup(nmem, (const char *) host); + + xmlFree(port); + xmlFree(host); + } + else if (!strcmp((const char *) n->name, "settings")) + { + if (r->settings) + { + yaz_log(YLOG_FATAL, "Can't repeat 'settings'"); + return 0; + } + if (!(r->settings = parse_settings(n))) + return 0; + } + else if (!strcmp((const char *) n->name, "service")) { struct conf_service *s = parse_service(n); if (!s) @@ -246,148 +315,46 @@ static struct conf_server *parse_server(xmlNode *node) return r; } -static xsltStylesheet *load_stylesheet(const char *fname) +xsltStylesheet *conf_load_stylesheet(const char *fname) { char path[256]; sprintf(path, "%s/%s", confdir, fname); - return xsltParseStylesheetFile(path); + return xsltParseStylesheetFile((xmlChar *) path); } -static void setup_marc(struct conf_retrievalprofile *r) +static struct conf_targetprofiles *parse_targetprofiles(xmlNode *node) { - yaz_iconv_t cm; - r->yaz_marc = yaz_marc_create(); - if (!(cm = yaz_iconv_open("utf-8", r->native_encoding))) - { - yaz_log(YLOG_WARN, "Unable to support mapping from %s", r->native_encoding); - return; - } - yaz_marc_iconv(r->yaz_marc, cm); -} + struct conf_targetprofiles *r = nmem_malloc(nmem, sizeof(*r)); + xmlChar *type = xmlGetProp(node, (xmlChar *) "type"); + xmlChar *src = xmlGetProp(node, (xmlChar *) "src"); -static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node) -{ - struct conf_retrievalprofile *r = nmem_malloc(nmem, sizeof(struct conf_retrievalprofile)); - xmlNode *n; - struct conf_retrievalmap **rm = &r->maplist; - - r->requestsyntax = 0; - r->native_syntax = Nativesyn_xml; - r->native_format = Nativeform_na; - r->native_encoding = 0; - r->native_mapto = Nativemapto_na; - r->yaz_marc = 0; - r->maplist = 0; - r->next = 0; + memset(r, 0, sizeof(*r)); - for (n = node->children; n; n = n->next) + if (type) { - if (n->type != XML_ELEMENT_NODE) - continue; - if (!strcmp(n->name, "requestsyntax")) - { - xmlChar *content = xmlNodeGetContent(n); - if (content) - r->requestsyntax = nmem_strdup(nmem, content); - } - else if (!strcmp(n->name, "nativesyntax")) - { - xmlChar *name = xmlGetProp(n, "name"); - xmlChar *format = xmlGetProp(n, "format"); - xmlChar *encoding = xmlGetProp(n, "encoding"); - xmlChar *mapto = xmlGetProp(n, "mapto"); - if (!name) - { - yaz_log(YLOG_WARN, "Missing name in 'nativesyntax' element"); - return 0; - } - if (encoding) - r->native_encoding = encoding; - if (!strcmp(name, "iso2709")) - { - r->native_syntax = Nativesyn_iso2709; - // Set a few defaults, too - r->native_format = Nativeform_marc21; - r->native_mapto = Nativemapto_marcxml; - if (!r->native_encoding) - r->native_encoding = "marc-8"; - setup_marc(r); - } - else if (!strcmp(name, "xml")) - r->native_syntax = Nativesyn_xml; - else - { - yaz_log(YLOG_WARN, "Unknown native syntax name %s", name); - return 0; - } - if (format) - { - if (!strcmp(format, "marc21") || !strcmp(format, "usmarc")) - r->native_format = Nativeform_marc21; - else - { - yaz_log(YLOG_WARN, "Unknown native format name %s", format); - return 0; - } - } - if (mapto) - { - if (!strcmp(mapto, "marcxml")) - r->native_mapto = Nativemapto_marcxml; - else if (!strcmp(mapto, "marcxchange")) - r->native_mapto = Nativemapto_marcxchange; - else - { - yaz_log(YLOG_WARN, "Unknown mapto target %s", format); - return 0; - } - } - xmlFree(name); - xmlFree(format); - xmlFree(encoding); - xmlFree(mapto); - } - else if (!strcmp(n->name, "map")) - { - struct conf_retrievalmap *m = nmem_malloc(nmem, sizeof(struct conf_retrievalmap)); - xmlChar *type = xmlGetProp(n, "type"); - xmlChar *charset = xmlGetProp(n, "charset"); - xmlChar *format = xmlGetProp(n, "format"); - xmlChar *stylesheet = xmlGetProp(n, "stylesheet"); - memset(m, 0, sizeof(*m)); - if (type) - { - if (!strcmp(type, "xslt")) - m->type = Map_xslt; - else - { - yaz_log(YLOG_WARN, "Unknown map type: %s", type); - return 0; - } - } - if (charset) - m->charset = nmem_strdup(nmem, charset); - if (format) - m->format = nmem_strdup(nmem, format); - if (stylesheet) - { - if (!(m->stylesheet = load_stylesheet(stylesheet))) - return 0; - } - *rm = m; - rm = &m->next; - xmlFree(type); - xmlFree(charset); - xmlFree(format); - xmlFree(stylesheet); - } + if (!strcmp((const char *) type, "local")) + r->type = Targetprofiles_local; else { - yaz_log(YLOG_FATAL, "Bad element in retrievalprofile: %s", n->name); + yaz_log(YLOG_FATAL, "Unknown targetprofile type"); return 0; } } + else + { + yaz_log(YLOG_FATAL, "Must specify type for targetprofile"); + return 0; + } + if (src) + r->src = nmem_strdup(nmem, (const char *) src); + else + { + yaz_log(YLOG_FATAL, "Must specify src in targetprofile"); + return 0; + } + xmlFree(type); + xmlFree(src); return r; } @@ -395,17 +362,15 @@ static struct conf_config *parse_config(xmlNode *root) { xmlNode *n; struct conf_config *r = nmem_malloc(nmem, sizeof(struct conf_config)); - struct conf_retrievalprofile **rp = &r->retrievalprofiles; r->servers = 0; - r->queryprofiles = 0; - r->retrievalprofiles = 0; + r->targetprofiles = 0; for (n = root->children; n; n = n->next) { if (n->type != XML_ELEMENT_NODE) continue; - if (!strcmp(n->name, "server")) + if (!strcmp((const char *) n->name, "server")) { struct conf_server *tmp = parse_server(n); if (!tmp) @@ -413,14 +378,16 @@ static struct conf_config *parse_config(xmlNode *root) tmp->next = r->servers; r->servers = tmp; } - else if (!strcmp(n->name, "queryprofile")) + else if (!strcmp((const char *) n->name, "targetprofiles")) { - } - else if (!strcmp(n->name, "retrievalprofile")) - { - if (!(*rp = parse_retrievalprofile(n))) + // 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(n))) return 0; - rp = &(*rp)->next; } else {