X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fconfig.c;h=3ceb42715b17e4020def9aa1ecf8200c5190cf77;hb=bec266c19b530f61fa576d2b27198ada7d7f5fe3;hp=3f02149a02e420249c9ff9ac1b631cacccee9229;hpb=dde4a5914bbb5511a91e73d8ab45210b48637596;p=pazpar2-moved-to-github.git diff --git a/src/config.c b/src/config.c index 3f02149..3ceb427 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* $Id: config.c,v 1.3 2007-01-03 06:23:44 quinn Exp $ */ +/* $Id: config.c,v 1.13 2007-01-15 16:56:51 quinn Exp $ */ #include @@ -8,6 +8,10 @@ #include #include +#if HAVE_CONFIG_H +#include +#endif + #include #include @@ -26,25 +30,148 @@ static struct conf_service *parse_service(xmlNode *node) { xmlNode *n; struct conf_service *r = nmem_malloc(nmem, sizeof(struct conf_service)); + int md_node = 0; + int sk_node = 0; - r->termlists = 0; + 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")) + { + xmlChar *sortkey = xmlGetProp(n, "sortkey"); + r->num_metadata++; + if (sortkey && strcmp(sortkey, "no")) + r->num_sortkeys++; + xmlFree(sortkey); + } + if (r->num_metadata) + r->metadata = nmem_malloc(nmem, sizeof(struct conf_metadata) * r->num_metadata); + else + r->metadata = 0; + if (r->num_sortkeys) + r->sortkeys = nmem_malloc(nmem, sizeof(struct conf_sortkey) * r->num_sortkeys); + else + r->sortkeys = 0; for (n = node->children; n; n = n->next) { if (n->type != XML_ELEMENT_NODE) continue; - if (!strcmp(n->name, "termlist")) + if (!strcmp(n->name, "metadata")) { - struct conf_termlist *tl = nmem_malloc(nmem, sizeof(struct conf_termlist)); + 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"); + if (!name) { - yaz_log(YLOG_WARN, "Missing name attribute in termlist"); - continue; + yaz_log(YLOG_FATAL, "Must specify name in metadata element"); + return 0; } - tl->name = nmem_strdup(nmem, name); - tl->next = r->termlists; - r->termlists = tl; + md->name = nmem_strdup(nmem, name); + if (brief) + { + if (!strcmp(brief, "yes")) + md->brief = 1; + else if (strcmp(brief, "no")) + { + yaz_log(YLOG_FATAL, "metadata/brief must be yes or no"); + return 0; + } + } + else + md->brief = 0; + + if (termlist) + { + if (!strcmp(termlist, "yes")) + md->termlist = 1; + else if (strcmp(termlist, "no")) + { + yaz_log(YLOG_FATAL, "metadata/termlist must be yes or no"); + return 0; + } + } + else + md->termlist = 0; + + if (rank) + md->rank = atoi(rank); + else + md->rank = 0; + + if (type) + { + if (!strcmp(type, "generic")) + md->type = Metadata_type_generic; + else if (!strcmp(type, "year")) + md->type = Metadata_type_year; + else + { + yaz_log(YLOG_FATAL, "Unknown value for metadata/type: %s", type); + return 0; + } + } + else + md->type = Metadata_type_generic; + + if (merge) + { + if (!strcmp(merge, "no")) + md->merge = Metadata_merge_no; + else if (!strcmp(merge, "unique")) + md->merge = Metadata_merge_unique; + else if (!strcmp(merge, "longest")) + md->merge = Metadata_merge_longest; + else if (!strcmp(merge, "range")) + md->merge = Metadata_merge_range; + else if (!strcmp(merge, "all")) + md->merge = Metadata_merge_all; + else + { + yaz_log(YLOG_FATAL, "Unknown value for metadata/merge: %s", merge); + return 0; + } + } + else + md->merge = Metadata_merge_no; + + if (sortkey && strcmp(sortkey, "no")) + { + struct conf_sortkey *sk = &r->sortkeys[sk_node]; + if (md->merge == Metadata_merge_no) + { + yaz_log(YLOG_FATAL, "Can't specify sortkey on a non-merged field"); + return 0; + } + if (!strcmp(sortkey, "numeric")) + sk->type = Metadata_sortkey_numeric; + else if (!strcmp(sortkey, "skiparticle")) + sk->type = Metadata_sortkey_skiparticle; + else + { + yaz_log(YLOG_FATAL, "Unknown sortkey in metadata element: %s", sortkey); + return 0; + } + sk->name = md->name; + md->sortkey_offset = sk_node; + sk_node++; + } + else + md->sortkey_offset = -1; + + xmlFree(name); + xmlFree(brief); + xmlFree(sortkey); + xmlFree(merge); + xmlFree(termlist); + xmlFree(rank); + md_node++; } else { @@ -79,6 +206,8 @@ static struct conf_server *parse_server(xmlNode *node) r->port = atoi(port); if (host) r->host = nmem_strdup(nmem, host); + xmlFree(port); + xmlFree(host); } else if (!strcmp(n->name, "proxy")) { @@ -88,6 +217,8 @@ static struct conf_server *parse_server(xmlNode *node) r->proxy_port = atoi(port); if (host) r->proxy_host = nmem_strdup(nmem, host); + xmlFree(port); + xmlFree(host); } else if (!strcmp(n->name, "service")) { @@ -160,13 +291,16 @@ static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node) 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; - r->native_encoding = "marc-8"; + if (!r->native_encoding) + r->native_encoding = "marc-8"; setup_marc(r); } else if (!strcmp(name, "xml")) @@ -186,8 +320,6 @@ static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node) return 0; } } - if (encoding) - r->native_encoding = encoding; if (mapto) { if (!strcmp(mapto, "marcxml")) @@ -200,6 +332,10 @@ static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node) return 0; } } + xmlFree(name); + xmlFree(format); + xmlFree(encoding); + xmlFree(mapto); } else if (!strcmp(n->name, "map")) { @@ -208,7 +344,7 @@ static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node) xmlChar *charset = xmlGetProp(n, "charset"); xmlChar *format = xmlGetProp(n, "format"); xmlChar *stylesheet = xmlGetProp(n, "stylesheet"); - bzero(m, sizeof(*m)); + memset(m, 0, sizeof(*m)); if (type) { if (!strcmp(type, "xslt")) @@ -230,6 +366,10 @@ static struct conf_retrievalprofile *parse_retrievalprofile(xmlNode *node) } *rm = m; rm = &m->next; + xmlFree(type); + xmlFree(charset); + xmlFree(format); + xmlFree(stylesheet); } else { @@ -283,7 +423,7 @@ static struct conf_config *parse_config(xmlNode *root) int read_config(const char *fname) { - xmlDoc *doc = xmlReadFile(fname, NULL, 0); + xmlDoc *doc = xmlParseFile(fname); const char *p; if (!nmem) // Initialize @@ -297,7 +437,7 @@ int read_config(const char *fname) yaz_log(YLOG_FATAL, "Failed to read %s", fname); exit(1); } - if ((p = rindex(fname, '/'))) + if ((p = strrchr(fname, '/'))) { int len = p - fname; strncpy(confdir, fname, len);