X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fconfig.c;h=7c4942edcc3c86f827b76edf1e5d76c3175463e7;hb=592591ac165b4e844f3968e566d52ba20dbbf26a;hp=ccaf13bd7fcdb7861882bfd485ae92d8793f9cb9;hpb=d716fe118643f845b127b5a12be8b6a08d735a82;p=pazpar2-moved-to-github.git diff --git a/src/config.c b/src/config.c index ccaf13b..7c4942e 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,25 @@ -/* $Id: config.c,v 1.21 2007-04-02 09:43:08 marc 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 @@ -294,152 +315,13 @@ 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((xmlChar *) path); } -static void setup_marc(struct conf_retrievalprofile *r) -{ - 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); -} - -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; - - for (n = node->children; n; n = n->next) - { - if (n->type != XML_ELEMENT_NODE) - continue; - if (!strcmp((const char *) n->name, "requestsyntax")) - { - xmlChar *content = xmlNodeGetContent(n); - if (content) - r->requestsyntax = nmem_strdup(nmem, (const char *) content); - } - else if (!strcmp((const char *) n->name, "nativesyntax")) - { - xmlChar *name = xmlGetProp(n, (xmlChar *) "name"); - xmlChar *format = xmlGetProp(n, (xmlChar *) "format"); - xmlChar *encoding = xmlGetProp(n, (xmlChar *) "encoding"); - xmlChar *mapto = xmlGetProp(n, (xmlChar *) "mapto"); - if (!name) - { - yaz_log(YLOG_WARN, "Missing name in 'nativesyntax' element"); - return 0; - } - if (encoding) - r->native_encoding = (char *) encoding; - if (!strcmp((const char *) 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((const char *) name, "xml")) - r->native_syntax = Nativesyn_xml; - else - { - yaz_log(YLOG_WARN, "Unknown native syntax name %s", name); - return 0; - } - if (format) - { - if (!strcmp((const char *) format, "marc21") - || !strcmp((const char *) format, "usmarc")) - r->native_format = Nativeform_marc21; - else - { - yaz_log(YLOG_WARN, "Unknown native format name %s", format); - return 0; - } - } - if (mapto) - { - if (!strcmp((const char *) mapto, "marcxml")) - r->native_mapto = Nativemapto_marcxml; - else if (!strcmp((const char *)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((const char *) n->name, "map")) - { - struct conf_retrievalmap *m = nmem_malloc(nmem, sizeof(struct conf_retrievalmap)); - xmlChar *type = xmlGetProp(n, (xmlChar *) "type"); - xmlChar *charset = xmlGetProp(n, (xmlChar *) "charset"); - xmlChar *format = xmlGetProp(n, (xmlChar *) "format"); - xmlChar *stylesheet = xmlGetProp(n, (xmlChar *) "stylesheet"); - memset(m, 0, sizeof(*m)); - if (type) - { - if (!strcmp((const char *) 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, (const char *) charset); - if (format) - m->format = nmem_strdup(nmem, (const char *) format); - if (stylesheet) - { - if (!(m->stylesheet = load_stylesheet((char *) stylesheet))) - return 0; - } - *rm = m; - rm = &m->next; - xmlFree(type); - xmlFree(charset); - xmlFree(format); - xmlFree(stylesheet); - } - else - { - yaz_log(YLOG_FATAL, "Bad element in retrievalprofile: %s", n->name); - return 0; - } - } - - return r; -} - static struct conf_targetprofiles *parse_targetprofiles(xmlNode *node) { struct conf_targetprofiles *r = nmem_malloc(nmem, sizeof(*r)); @@ -480,10 +362,8 @@ 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->retrievalprofiles = 0; r->targetprofiles = 0; for (n = root->children; n; n = n->next) @@ -498,12 +378,6 @@ static struct conf_config *parse_config(xmlNode *root) tmp->next = r->servers; r->servers = tmp; } - else if (!strcmp((const char *) n->name, "retrievalprofile")) - { - if (!(*rp = parse_retrievalprofile(n))) - return 0; - rp = &(*rp)->next; - } else if (!strcmp((const char *) n->name, "targetprofiles")) { // It would be fun to be able to fix this sometime