Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/pazpar2
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 14 Apr 2008 13:53:04 +0000 (15:53 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 14 Apr 2008 13:53:04 +0000 (15:53 +0200)
36 files changed:
configure.ac
src/.gitignore
src/Makefile.am
src/charsets.c
src/client.c
src/config.c [deleted file]
src/config.h [deleted file]
src/connection.c
src/database.c
src/eventl.c
src/getaddrinfo.c
src/http.c
src/http_command.c
src/icu_I18N.c
src/icu_chain_test.c
src/logic.c
src/normalize7bit.c
src/pazpar2.c
src/pazpar2.h
src/pazpar2_config.c [new file with mode: 0644]
src/pazpar2_config.h [new file with mode: 0644]
src/reclists.c
src/reclists.h
src/record.c
src/relevance.c
src/sel_thread.c
src/settings.c
src/termlists.c
src/test_config.c
src/test_icu_I18N.c
src/test_normalize.c
src/test_reclists.c
src/test_record.c
src/test_relevance.c
src/test_sel_thread.c
src/util.c

index 47a1543..9c6d987 100644 (file)
@@ -6,7 +6,7 @@
 AC_PREREQ(2.60)
 AC_INIT([pazpar2],[1.0.7],[pazpar2-help@indexdata.dk])
 
-AC_CONFIG_HEADERS(src/cconfig.h)
+AC_CONFIG_HEADERS(src/config.h)
 
 AC_CONFIG_SRCDIR([configure.ac]) 
 AC_CONFIG_AUX_DIR([config])
index b132420..2beb68d 100644 (file)
@@ -3,8 +3,8 @@ pazpar2
 icu_chain_test
 Makefile
 Makefile.in
-cconfig.h
-cconfig.h.in
+config.h
+config.h.in
 .deps
 *.log
 *.o
index 7207781..2148f6d 100644 (file)
@@ -22,7 +22,7 @@ CONFIG_CLEAN_FILES=*.log
 
 AM_CFLAGS = $(YAZINC) $(ICU_CPPFLAGS)
 
-libpazpar2_a_SOURCES = config.c config.h eventl.c eventl.h \
+libpazpar2_a_SOURCES = pazpar2_config.c pazpar2_config.h eventl.c eventl.h \
        http.c http_command.c http_command.h http.h \
         icu_I18N.h icu_I18N.c \
        logic.c pazpar2.h \
index b753c4f..80388e8 100644 (file)
@@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include <yaz/xmalloc.h>
index ad9d237..696db40 100644 (file)
@@ -47,7 +47,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/diagbib1.h>
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
diff --git a/src/config.c b/src/config.c
deleted file mode 100644 (file)
index 2b44547..0000000
+++ /dev/null
@@ -1,640 +0,0 @@
-/* This file is part of Pazpar2.
-   Copyright (C) 2006-2008 Index Data
-
-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 this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-*/
-
-/* $Id: config.c,v 1.42 2007-10-31 05:29:08 quinn Exp $ */
-
-#include <string.h>
-
-#include <libxml/parser.h>
-#include <libxml/tree.h>
-#include <libxslt/xslt.h>
-#include <libxslt/transform.h>
-#include <libxslt/xsltutils.h>
-
-#if HAVE_CONFIG_H
-#include <cconfig.h>
-#endif
-
-#include <yaz/yaz-util.h>
-#include <yaz/nmem.h>
-#include <yaz/snprintf.h>
-
-#define CONFIG_NOEXTERNS
-#include "config.h"
-
-
-static NMEM nmem = 0;
-static char confdir[256] = ".";
-
-struct conf_config *config = 0;
-
-
-struct conf_metadata * conf_metadata_assign(NMEM nmem, 
-                                            struct conf_metadata * metadata,
-                                            const char *name,
-                                            enum conf_metadata_type type,
-                                            enum conf_metadata_merge merge,
-                                            enum conf_setting_type setting,
-                                            int brief,
-                                            int termlist,
-                                            int rank,
-                                            int sortkey_offset)
-{
-    if (!nmem || !metadata || !name)
-        return 0;
-    
-    metadata->name = nmem_strdup(nmem, name);
-
-    metadata->type = type;
-
-    // enforcing that type_year is always range_merge
-    if (metadata->type == Metadata_type_year)
-        metadata->merge = Metadata_merge_range;
-    else
-        metadata->merge = merge;    
-
-    metadata->setting = setting;
-    metadata->brief = brief;   
-    metadata->termlist = termlist;
-    metadata->rank = rank;    
-    metadata->sortkey_offset = sortkey_offset;
-    return metadata;
-}
-
-
-struct conf_sortkey * conf_sortkey_assign(NMEM nmem, 
-                                          struct conf_sortkey * sortkey,
-                                          const char *name,
-                                          enum conf_sortkey_type type)
-{
-    if (!nmem || !sortkey || !name)
-        return 0;
-    
-    sortkey->name = nmem_strdup(nmem, name);
-    sortkey->type = type;
-
-    return sortkey;
-}
-
-
-struct conf_service * conf_service_create(NMEM nmem,
-                                          int num_metadata, int num_sortkeys)
-{
-    struct conf_service * service = 0;
-
-    //assert(nmem);
-    
-    service = nmem_malloc(nmem, sizeof(struct conf_service));
-
-    service->num_metadata = num_metadata;
-    service->metadata = 0;
-    if (service->num_metadata)
-      service->metadata 
-          = nmem_malloc(nmem, 
-                        sizeof(struct conf_metadata) * service->num_metadata);
-    service->num_sortkeys = num_sortkeys;
-    service->sortkeys = 0;
-    if (service->num_sortkeys)
-        service->sortkeys 
-            = nmem_malloc(nmem, 
-                          sizeof(struct conf_sortkey) * service->num_sortkeys);
-
-    return service; 
-}
-
-struct conf_metadata* conf_service_add_metadata(NMEM nmem, 
-                                                struct conf_service *service,
-                                                int field_id,
-                                                const char *name,
-                                                enum conf_metadata_type type,
-                                                enum conf_metadata_merge merge,
-                                                enum conf_setting_type setting,
-                                                int brief,
-                                                int termlist,
-                                                int rank,
-                                                int sortkey_offset)
-{
-    struct conf_metadata * md = 0;
-
-    if (!service || !service->metadata || !service->num_metadata
-        || field_id < 0  || !(field_id < service->num_metadata))
-        return 0;
-
-    //md = &((service->metadata)[field_id]);
-    md = service->metadata + field_id;
-    md = conf_metadata_assign(nmem, md, name, type, merge, setting,
-                             brief, termlist, rank, sortkey_offset);
-    return md;
-}
-
-
-struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
-                                               struct conf_service *service,
-                                               int field_id,
-                                               const char *name,
-                                               enum conf_sortkey_type type)
-{
-    struct conf_sortkey * sk = 0;
-
-    if (!service || !service->sortkeys || !service->num_sortkeys
-        || field_id < 0  || !(field_id < service->num_sortkeys))
-        return 0;
-
-    //sk = &((service->sortkeys)[field_id]);
-    sk = service->sortkeys + field_id;
-    sk = conf_sortkey_assign(nmem, sk, name, type);
-
-    return sk;
-}
-
-
-int conf_service_metadata_field_id(struct conf_service *service,
-                                   const char * name)
-{
-    int i = 0;
-
-    if (!service || !service->metadata || !service->num_metadata)
-        return -1;
-
-    for(i = 0; i < service->num_metadata; i++) {
-        if (!strcmp(name, (service->metadata[i]).name))
-            return i;
-    }
-   
-    return -1;
-};
-
-
-int conf_service_sortkey_field_id(struct conf_service *service,
-                                  const char * name)
-{
-    int i = 0;
-
-    if (!service || !service->sortkeys || !service->num_sortkeys)
-        return -1;
-
-    for(i = 0; i < service->num_sortkeys; i++) {
-        if (!strcmp(name, (service->sortkeys[i]).name))
-            return i;
-    }
-   
-    return -1;
-};
-
-
-
-/* Code to parse configuration file */
-/* ==================================================== */
-
-static struct conf_service *parse_service(xmlNode *node)
-{
-    xmlNode *n;
-    int md_node = 0;
-    int sk_node = 0;
-
-    struct conf_service *service = 0;
-    int num_metadata = 0;
-    int num_sortkeys = 0;
-    
-    // count num_metadata and num_sortkeys
-    for (n = node->children; n; n = n->next)
-        if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)
-                                                   n->name, "metadata"))
-        {
-            xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
-            num_metadata++;
-            if (sortkey && strcmp((const char *) sortkey, "no"))
-                num_sortkeys++;
-            xmlFree(sortkey);
-        }
-
-    service = conf_service_create(nmem, num_metadata, num_sortkeys);    
-
-    for (n = node->children; n; n = n->next)
-    {
-        if (n->type != XML_ELEMENT_NODE)
-            continue;
-        if (!strcmp((const char *) n->name, (const char *) "metadata"))
-        {
-            xmlChar *xml_name = xmlGetProp(n, (xmlChar *) "name");
-            xmlChar *xml_brief = xmlGetProp(n, (xmlChar *) "brief");
-            xmlChar *xml_sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
-            xmlChar *xml_merge = xmlGetProp(n, (xmlChar *) "merge");
-            xmlChar *xml_type = xmlGetProp(n, (xmlChar *) "type");
-            xmlChar *xml_termlist = xmlGetProp(n, (xmlChar *) "termlist");
-            xmlChar *xml_rank = xmlGetProp(n, (xmlChar *) "rank");
-            xmlChar *xml_setting = xmlGetProp(n, (xmlChar *) "setting");
-
-            enum conf_metadata_type type = Metadata_type_generic;
-            enum conf_metadata_merge merge = Metadata_merge_no;
-            enum conf_setting_type setting = Metadata_setting_no;
-            enum conf_sortkey_type sk_type = Metadata_sortkey_relevance;
-            int brief = 0;
-            int termlist = 0;
-            int rank = 0;
-            int sortkey_offset = 0;
-            
-            // now do the parsing logic
-            if (!xml_name)
-            {
-                yaz_log(YLOG_FATAL, "Must specify name in metadata element");
-                return 0;
-            }
-            if (xml_brief)
-            {
-                if (!strcmp((const char *) xml_brief, "yes"))
-                    brief = 1;
-                 else if (strcmp((const char *) xml_brief, "no"))
-                {
-                    yaz_log(YLOG_FATAL, "metadata/brief must be yes or no");
-                    return 0;
-                }
-            }
-            else
-                brief = 0;
-
-            if (xml_termlist)
-            {
-                if (!strcmp((const char *) xml_termlist, "yes"))
-                    termlist = 1;
-                else if (strcmp((const char *) xml_termlist, "no"))
-                {
-                    yaz_log(YLOG_FATAL, "metadata/termlist must be yes or no");
-                    return 0;
-                }
-            }
-            else
-                termlist = 0;
-
-            if (xml_rank)
-                rank = atoi((const char *) xml_rank);
-            else
-                rank = 0;
-
-            if (xml_type)
-            {
-                if (!strcmp((const char *) xml_type, "generic"))
-                    type = Metadata_type_generic;
-                else if (!strcmp((const char *) xml_type, "year"))
-                    type = Metadata_type_year;
-                else if (!strcmp((const char *) xml_type, "date"))
-                    type = Metadata_type_date;
-                else
-                {
-                    yaz_log(YLOG_FATAL, 
-                            "Unknown value for metadata/type: %s", xml_type);
-                    return 0;
-                }
-            }
-            else
-                type = Metadata_type_generic;
-
-            if (xml_merge)
-            {
-                if (!strcmp((const char *) xml_merge, "no"))
-                    merge = Metadata_merge_no;
-                else if (!strcmp((const char *) xml_merge, "unique"))
-                    merge = Metadata_merge_unique;
-                else if (!strcmp((const char *) xml_merge, "longest"))
-                    merge = Metadata_merge_longest;
-                else if (!strcmp((const char *) xml_merge, "range"))
-                    merge = Metadata_merge_range;
-                else if (!strcmp((const char *) xml_merge, "all"))
-                    merge = Metadata_merge_all;
-                else
-                {
-                    yaz_log(YLOG_FATAL, 
-                            "Unknown value for metadata/merge: %s", xml_merge);
-                    return 0;
-                }
-            }
-            else
-                merge = Metadata_merge_no;
-
-            if (xml_setting)
-            {
-                if (!strcmp((const char *) xml_setting, "no"))
-                    setting = Metadata_setting_no;
-                else if (!strcmp((const char *) xml_setting, "postproc"))
-                    setting = Metadata_setting_postproc;
-                else if (!strcmp((const char *) xml_setting, "parameter"))
-                    setting = Metadata_setting_parameter;
-                else
-                {
-                    yaz_log(YLOG_FATAL,
-                        "Unknown value for medadata/setting: %s", xml_setting);
-                    return 0;
-                }
-            }
-
-            // add a sortkey if so specified
-            if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
-            {
-                if (merge == Metadata_merge_no)
-                {
-                    yaz_log(YLOG_FATAL, 
-                            "Can't specify sortkey on a non-merged field");
-                    return 0;
-                }
-                if (!strcmp((const char *) xml_sortkey, "numeric"))
-                    sk_type = Metadata_sortkey_numeric;
-                else if (!strcmp((const char *) xml_sortkey, "skiparticle"))
-                    sk_type = Metadata_sortkey_skiparticle;
-                else
-                {
-                    yaz_log(YLOG_FATAL,
-                            "Unknown sortkey in metadata element: %s", 
-                            xml_sortkey);
-                    return 0;
-                }
-                sortkey_offset = sk_node;
-
-                conf_service_add_sortkey(nmem, service, sk_node,
-                                         (const char *) xml_name, sk_type);
-                
-                sk_node++;
-            }
-            else
-                sortkey_offset = -1;
-
-            // metadata known, assign values
-            conf_service_add_metadata(nmem, service, md_node,
-                                      (const char *) xml_name,
-                                      type, merge, setting,
-                                      brief, termlist, rank, sortkey_offset);
-
-            xmlFree(xml_name);
-            xmlFree(xml_brief);
-            xmlFree(xml_sortkey);
-            xmlFree(xml_merge);
-            xmlFree(xml_type);
-            xmlFree(xml_termlist);
-            xmlFree(xml_rank);
-            md_node++;
-        }
-        else
-        {
-            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
-            return 0;
-        }
-    }
-    return service;
-}
-
-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;
-    struct conf_server *server = nmem_malloc(nmem, sizeof(struct conf_server));
-
-    server->host = 0;
-    server->port = 0;
-    server->proxy_host = 0;
-    server->proxy_port = 0;
-    server->myurl = 0;
-    server->service = 0;
-    server->next = 0;
-    server->settings = 0;
-    server->relevance_pct = 0;
-    server->sort_pct = 0;
-    server->mergekey_pct = 0;
-
-    for (n = node->children; n; n = n->next)
-    {
-        if (n->type != XML_ELEMENT_NODE)
-            continue;
-        if (!strcmp((const char *) n->name, "listen"))
-        {
-            xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
-            xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
-            if (port)
-                server->port = atoi((const char *) port);
-            if (host)
-                server->host = nmem_strdup(nmem, (const char *) host);
-            xmlFree(port);
-            xmlFree(host);
-        }
-        else if (!strcmp((const char *) n->name, "proxy"))
-        {
-            xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
-            xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
-            xmlChar *myurl = xmlGetProp(n, (xmlChar *) "myurl");
-            if (port)
-                server->proxy_port = atoi((const char *) port);
-            if (host)
-                server->proxy_host = nmem_strdup(nmem, (const char *) host);
-            if (myurl)
-                server->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((const char *) n->name, "settings"))
-        {
-            if (server->settings)
-            {
-                yaz_log(YLOG_FATAL, "Can't repeat 'settings'");
-                return 0;
-            }
-            if (!(server->settings = parse_settings(n)))
-                return 0;
-        }
-        else if (!strcmp((const char *) n->name, "relevance"))
-        {
-            server->relevance_pct = pp2_charset_create_xml(n->children);
-        }
-        else if (!strcmp((const char *) n->name, "sort"))
-        {
-            server->sort_pct = pp2_charset_create_xml(n->children);
-        }
-        else if (!strcmp((const char *) n->name, "mergekey"))
-        {
-            server->mergekey_pct = pp2_charset_create_xml(n->children);
-        }
-        else if (!strcmp((const char *) n->name, "service"))
-        {
-            struct conf_service *s = parse_service(n);
-            if (!s)
-                return 0;
-            server->service = s;
-        }
-        else
-        {
-            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
-            return 0;
-        }
-    }
-    if (!server->relevance_pct)
-        server->relevance_pct = pp2_charset_create(0);
-    if (!server->sort_pct)
-        server->sort_pct = pp2_charset_create(0);
-    if (!server->mergekey_pct)
-        server->mergekey_pct = pp2_charset_create(0);
-    return server;
-}
-
-xsltStylesheet *conf_load_stylesheet(const char *fname)
-{
-    char path[256];
-    if (*fname == '/')
-        yaz_snprintf(path, sizeof(path), fname);
-    else
-        yaz_snprintf(path, sizeof(path), "%s/%s", confdir, fname);
-    return xsltParseStylesheetFile((xmlChar *) path);
-}
-
-static struct conf_targetprofiles *parse_targetprofiles(xmlNode *node)
-{
-    struct conf_targetprofiles *r = nmem_malloc(nmem, sizeof(*r));
-    xmlChar *type = xmlGetProp(node, (xmlChar *) "type");
-    xmlChar *src = xmlGetProp(node, (xmlChar *) "src");
-
-    memset(r, 0, sizeof(*r));
-
-    if (type)
-    {
-        if (!strcmp((const char *) type, "local"))
-            r->type = Targetprofiles_local;
-        else
-        {
-            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;
-}
-
-static struct conf_config *parse_config(xmlNode *root)
-{
-    xmlNode *n;
-    struct conf_config *r = nmem_malloc(nmem, sizeof(struct conf_config));
-
-    r->servers = 0;
-    r->targetprofiles = 0;
-
-    for (n = root->children; n; n = n->next)
-    {
-        if (n->type != XML_ELEMENT_NODE)
-            continue;
-        if (!strcmp((const char *) n->name, "server"))
-        {
-            struct conf_server *tmp = parse_server(n);
-            if (!tmp)
-                return 0;
-            tmp->next = r->servers;
-            r->servers = tmp;
-        }
-        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(n)))
-                return 0;
-        }
-        else
-        {
-            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
-            return 0;
-        }
-    }
-    return r;
-}
-
-int read_config(const char *fname)
-{
-    xmlDoc *doc = xmlParseFile(fname);
-    const char *p;
-
-    if (!nmem)  // Initialize
-    {
-        nmem = nmem_create();
-        xmlSubstituteEntitiesDefault(1);
-        xmlLoadExtDtdDefaultValue = 1;
-    }
-    if (!doc)
-    {
-        yaz_log(YLOG_FATAL, "Failed to read %s", fname);
-        exit(1);
-    }
-    if ((p = strrchr(fname, '/')))
-    {
-        int len = p - fname;
-        if (len >= sizeof(confdir))
-            len = sizeof(confdir)-1;
-        strncpy(confdir, fname, len);
-        confdir[len] = '\0';
-    }
-    config = parse_config(xmlDocGetRootElement(doc));
-    xmlFreeDoc(doc);
-
-    if (config)
-        return 1;
-    else
-        return 0;
-}
-
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
diff --git a/src/config.h b/src/config.h
deleted file mode 100644 (file)
index 6f52922..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-/* This file is part of Pazpar2.
-   Copyright (C) 2006-2008 Index Data
-
-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 this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-*/
-
-#ifndef CONFIG_H
-#define CONFIG_H
-
-#include <libxslt/xslt.h>
-#include <libxslt/transform.h>
-#include <libxslt/xsltutils.h>
-
-#include <yaz/nmem.h>
-#include "charsets.h"
-
-enum conf_metadata_type {
-    Metadata_type_generic,    // Generic text field
-    Metadata_type_number,     // A number
-    Metadata_type_year,        // A number
-    Metadata_type_date        // A number
-};
-
-enum conf_metadata_merge {
-    Metadata_merge_no,        // Don't merge
-    Metadata_merge_unique,    // Include unique elements in merged block
-    Metadata_merge_longest,   // Include the longest (strlen) value
-    Metadata_merge_range,     // Store value as a range of lowest-highest
-    Metadata_merge_all        // Just include all elements found
-};
-
-enum conf_sortkey_type {
-    Metadata_sortkey_relevance,
-    Metadata_sortkey_numeric,       // Standard numerical sorting
-    Metadata_sortkey_skiparticle,   // Skip leading article when sorting
-    Metadata_sortkey_string         // Flat string
-};
-
-// This controls the ability to insert 'static' values from settings into retrieval recs
-enum conf_setting_type {
-    Metadata_setting_no,
-    Metadata_setting_postproc,      // Insert setting value into normalized record
-    Metadata_setting_parameter      // Expose value to normalization stylesheets
-};
-
-// Describes known metadata elements and how they are to be manipulated
-// An array of these structure provides a 'map' against which
-// discovered metadata elements are matched. It also governs storage,
-// to minimize number of cycles needed at various tages of processing
-struct conf_metadata 
-{
-    char *name;  // The field name. Output by normalization stylesheet
-    int brief;   // Is this element to be returned in the brief format?
-    int termlist;// Is this field to be treated as a termlist for browsing?
-    int rank;    // Rank factor. 0 means don't use this field for ranking, 
-                 // 1 is default
-                 // values >1  give additional significance to a field
-    int sortkey_offset; // -1 if it's not a sortkey, otherwise index
-                        // into service/record_cluster->sortkey array
-    enum conf_metadata_type type;
-    enum conf_metadata_merge merge;
-    enum conf_setting_type setting; // Value is to be taken from session/db settings?
-};
-
-
-
-struct conf_metadata * conf_metadata_assign(NMEM nmem, 
-                                            struct conf_metadata * metadata,
-                                            const char *name,
-                                            enum conf_metadata_type type,
-                                            enum conf_metadata_merge merge,
-                                            enum conf_setting_type setting,
-                                            int brief,
-                                            int termlist,
-                                            int rank,
-                                            int sortkey_offset);
-
-
-
-// Controls sorting
-struct conf_sortkey
-{
-    char *name;
-    enum conf_sortkey_type type;
-};
-
-struct conf_sortkey * conf_sortkey_assign(NMEM nmem, 
-                                            struct conf_sortkey * sortkey,
-                                            const char *name,
-                                            enum conf_sortkey_type type);
-
-
-
-// It is conceivable that there will eventually be several 'services'
-// offered from one server, with separate configuration -- possibly
-// more than one services associated with the same port. For now,
-// however, only a single service is possible.
-struct conf_service
-{
-    int num_metadata;
-    struct conf_metadata *metadata;
-    int num_sortkeys;
-    struct conf_sortkey *sortkeys;
-
-};
-
-struct conf_service * conf_service_create(NMEM nmem, 
-                                          int num_metadata, int num_sortkeys);
-
-
-struct conf_metadata* conf_service_add_metadata(NMEM nmem, 
-                                                struct conf_service *service,
-                                                int field_id,
-                                                const char *name,
-                                                enum conf_metadata_type type,
-                                                enum conf_metadata_merge merge,
-                                                enum conf_setting_type setting,
-                                                int brief,
-                                                int termlist,
-                                                int rank,
-                                                int sortkey_offset);
-
-struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
-                                               struct conf_service *service,
-                                               int field_id,
-                                               const char *name,
-                                               enum conf_sortkey_type type);
-
-
-int conf_service_metadata_field_id(struct conf_service *service, const char * name);
-
-int conf_service_sortkey_field_id(struct conf_service *service, const char * name);
-
-
-struct conf_server
-{
-    char *host;
-    int port;
-    char *proxy_host;
-    int proxy_port;
-    char *myurl;
-    char *settings;
-
-    pp2_charset_t relevance_pct;
-    pp2_charset_t sort_pct;
-    pp2_charset_t mergekey_pct;
-
-    struct conf_service *service;
-    struct conf_server *next;
-};
-
-struct conf_targetprofiles
-{
-    enum {
-        Targetprofiles_local
-    } type;
-    char *src;
-};
-
-struct conf_config
-{
-    struct conf_server *servers;
-    struct conf_targetprofiles *targetprofiles;
-};
-
-#ifndef CONFIG_NOEXTERNS
-
-extern struct conf_config *config;
-
-#endif
-
-int read_config(const char *fname);
-xsltStylesheet *conf_load_stylesheet(const char *fname);
-
-#endif
-
-/*
- * Local variables:
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- * vim: shiftwidth=4 tabstop=8 expandtab
- */
index 965ebc8..067c7ac 100644 (file)
@@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <assert.h>
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include <yaz/log.h>
index 1484427..30d8a84 100644 (file)
@@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "pazpar2.h"
 #include "host.h"
-#include "config.h"
 #include "settings.h"
 #include "http.h"
 #include "zeerex.h"
index 2dfac4d..7cbd6b0 100644 (file)
@@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <assert.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #ifdef WIN32
index cce2532..0e9a96a 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include "sel_thread.h"
index c2bf0a4..f4d8d69 100644 (file)
@@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <string.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #include <netinet/in.h>
@@ -44,7 +44,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/comstack.h>
 #include <yaz/nmem.h>
 
-#include "cconfig.h"
 #include "util.h"
 #include "eventl.h"
 #include "pazpar2.h"
@@ -116,17 +115,6 @@ static void http_buf_destroy_queue(struct http_buf *b)
     }
 }
 
-#ifdef GAGA
-// Calculate length of chain
-static int http_buf_len(struct http_buf *b)
-{
-    int sum = 0;
-    for (; b; b = b->next)
-        sum += b->len;
-    return sum;
-}
-#endif
-
 static struct http_buf *http_buf_bybuf(char *b, int len)
 {
     struct http_buf *res = 0;
@@ -913,25 +901,6 @@ static void http_io(IOCHAN i, int event)
     }
 }
 
-#ifdef GAGA
-// If this hostname contains our proxy host as a prefix, replace with myurl
-static char *sub_hostname(struct http_channel *c, char *buf)
-{
-    char tmp[1024];
-    if (strlen(buf) > 1023)
-        return buf;
-    if (strncmp(buf, "http://", 7))
-        return buf;
-    if (!strncmp(buf + 7, proxy_url, strlen(proxy_url)))
-    {
-        strcpy(tmp, myurl);
-        strcat(tmp, buf + strlen(proxy_url) + 7);
-        return nmem_strdup(c->nmem, tmp);
-    }
-    return buf;
-}
-#endif
-
 // Handles I/O on a client connection to a backend web server (proxy mode)
 static void proxy_io(IOCHAN pi, int event)
 {
@@ -968,33 +937,6 @@ static void proxy_io(IOCHAN pi, int event)
                 htbuf->buf[res] = '\0';
                 htbuf->offset = 0;
                 htbuf->len = res;
-#ifdef GAGA
-                if (pc->first_response) // Check if this is a redirect
-                {
-                    int len;
-                    if ((len = package_check(htbuf->buf)))
-                    {
-                        struct http_response *res = http_parse_response_buf(hc, htbuf->buf, len);
-                        if (res)
-                        {
-                            const char *location = http_lookup_header(
-                                res->header, "Location");
-                            if (location)
-                            {
-                                // We found a location header. Rewrite it.
-                                struct http_buf *buf;
-                                h->value = sub_hostname(hc, location);
-                                buf = http_serialize_response(hc, res);
-                                yaz_log(YLOG_LOG, "Proxy rewrite");
-                                http_buf_enqueue(&hc->oqueue, buf);
-                                htbuf->offset = len;
-                                break;
-                            }
-                        }
-                    }
-                    pc->first_response = 0;
-                }
-#endif
                 // Write any remaining payload
                 if (htbuf->len - htbuf->offset > 0)
                     http_buf_enqueue(&hc->oqueue, htbuf);
index 68b56af..24928d9 100644 (file)
@@ -31,12 +31,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <sys/time.h>
 #include <yaz/snprintf.h>
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #include <yaz/yaz-util.h>
 
-#include "config.h"
 #include "util.h"
 #include "eventl.h"
 #include "pazpar2.h"
index 6786777..cfd3b18 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
index db25893..873551c 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include <string.h>
index d7fb5c0..bf1a9d1 100644 (file)
@@ -47,7 +47,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/snprintf.h>
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
@@ -63,7 +63,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "termlists.h"
 #include "reclists.h"
 #include "relevance.h"
-#include "config.h"
 #include "database.h"
 #include "client.h"
 #include "settings.h"
@@ -1308,15 +1307,6 @@ struct record *ingest_record(struct client *cl, Z_External *rec,
                     if (this_max > (*wheretoput)->data.number.max)
                         (*wheretoput)->data.number.max = this_max;
                 }
-#ifdef GAGA
-                if (ser_sk)
-                {
-                    union data_types *sdata 
-                        = cluster->sortkeys[sk_field_id];
-                    yaz_log(YLOG_LOG, "SK range: %d-%d",
-                            sdata->number.min, sdata->number.max);
-                }
-#endif
             }
 
 
index f6a6d49..7642cd7 100644 (file)
@@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <ctype.h>
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include "normalize7bit.h"
index 84c6d5e..0a32283 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 
index f27e9bb..509ad9b 100644 (file)
@@ -35,7 +35,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "relevance.h"
 #include "reclists.h"
 #include "eventl.h"
-#include "config.h"
+#include "pazpar2_config.h"
 #include "parameters.h"
 #include "http.h"
 
diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c
new file mode 100644 (file)
index 0000000..1f1423a
--- /dev/null
@@ -0,0 +1,633 @@
+/* This file is part of Pazpar2.
+   Copyright (C) 2006-2008 Index Data
+
+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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+/* $Id: config.c,v 1.42 2007-10-31 05:29:08 quinn Exp $ */
+
+#include <string.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxslt/xslt.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <yaz/yaz-util.h>
+#include <yaz/nmem.h>
+#include <yaz/snprintf.h>
+
+#define CONFIG_NOEXTERNS
+#include "pazpar2_config.h"
+
+
+static NMEM nmem = 0;
+static char confdir[256] = ".";
+
+struct conf_config *config = 0;
+
+
+struct conf_metadata * conf_metadata_assign(NMEM nmem, 
+                                            struct conf_metadata * metadata,
+                                            const char *name,
+                                            enum conf_metadata_type type,
+                                            enum conf_metadata_merge merge,
+                                            enum conf_setting_type setting,
+                                            int brief,
+                                            int termlist,
+                                            int rank,
+                                            int sortkey_offset)
+{
+    if (!nmem || !metadata || !name)
+        return 0;
+    
+    metadata->name = nmem_strdup(nmem, name);
+
+    metadata->type = type;
+
+    // enforcing that type_year is always range_merge
+    if (metadata->type == Metadata_type_year)
+        metadata->merge = Metadata_merge_range;
+    else
+        metadata->merge = merge;    
+
+    metadata->setting = setting;
+    metadata->brief = brief;   
+    metadata->termlist = termlist;
+    metadata->rank = rank;    
+    metadata->sortkey_offset = sortkey_offset;
+    return metadata;
+}
+
+
+struct conf_sortkey * conf_sortkey_assign(NMEM nmem, 
+                                          struct conf_sortkey * sortkey,
+                                          const char *name,
+                                          enum conf_sortkey_type type)
+{
+    if (!nmem || !sortkey || !name)
+        return 0;
+    
+    sortkey->name = nmem_strdup(nmem, name);
+    sortkey->type = type;
+
+    return sortkey;
+}
+
+
+struct conf_service * conf_service_create(NMEM nmem,
+                                          int num_metadata, int num_sortkeys)
+{
+    struct conf_service * service = 0;
+
+    //assert(nmem);
+    
+    service = nmem_malloc(nmem, sizeof(struct conf_service));
+
+    service->num_metadata = num_metadata;
+    service->metadata = 0;
+    if (service->num_metadata)
+      service->metadata 
+          = nmem_malloc(nmem, 
+                        sizeof(struct conf_metadata) * service->num_metadata);
+    service->num_sortkeys = num_sortkeys;
+    service->sortkeys = 0;
+    if (service->num_sortkeys)
+        service->sortkeys 
+            = nmem_malloc(nmem, 
+                          sizeof(struct conf_sortkey) * service->num_sortkeys);
+
+    return service; 
+}
+
+struct conf_metadata* conf_service_add_metadata(NMEM nmem, 
+                                                struct conf_service *service,
+                                                int field_id,
+                                                const char *name,
+                                                enum conf_metadata_type type,
+                                                enum conf_metadata_merge merge,
+                                                enum conf_setting_type setting,
+                                                int brief,
+                                                int termlist,
+                                                int rank,
+                                                int sortkey_offset)
+{
+    struct conf_metadata * md = 0;
+
+    if (!service || !service->metadata || !service->num_metadata
+        || field_id < 0  || !(field_id < service->num_metadata))
+        return 0;
+
+    //md = &((service->metadata)[field_id]);
+    md = service->metadata + field_id;
+    md = conf_metadata_assign(nmem, md, name, type, merge, setting,
+                             brief, termlist, rank, sortkey_offset);
+    return md;
+}
+
+
+struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
+                                               struct conf_service *service,
+                                               int field_id,
+                                               const char *name,
+                                               enum conf_sortkey_type type)
+{
+    struct conf_sortkey * sk = 0;
+
+    if (!service || !service->sortkeys || !service->num_sortkeys
+        || field_id < 0  || !(field_id < service->num_sortkeys))
+        return 0;
+
+    //sk = &((service->sortkeys)[field_id]);
+    sk = service->sortkeys + field_id;
+    sk = conf_sortkey_assign(nmem, sk, name, type);
+
+    return sk;
+}
+
+
+int conf_service_metadata_field_id(struct conf_service *service,
+                                   const char * name)
+{
+    int i = 0;
+
+    if (!service || !service->metadata || !service->num_metadata)
+        return -1;
+
+    for(i = 0; i < service->num_metadata; i++) {
+        if (!strcmp(name, (service->metadata[i]).name))
+            return i;
+    }
+   
+    return -1;
+};
+
+
+int conf_service_sortkey_field_id(struct conf_service *service,
+                                  const char * name)
+{
+    int i = 0;
+
+    if (!service || !service->sortkeys || !service->num_sortkeys)
+        return -1;
+
+    for(i = 0; i < service->num_sortkeys; i++) {
+        if (!strcmp(name, (service->sortkeys[i]).name))
+            return i;
+    }
+   
+    return -1;
+};
+
+
+
+/* Code to parse configuration file */
+/* ==================================================== */
+
+static struct conf_service *parse_service(xmlNode *node)
+{
+    xmlNode *n;
+    int md_node = 0;
+    int sk_node = 0;
+
+    struct conf_service *service = 0;
+    int num_metadata = 0;
+    int num_sortkeys = 0;
+    
+    // count num_metadata and num_sortkeys
+    for (n = node->children; n; n = n->next)
+        if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)
+                                                   n->name, "metadata"))
+        {
+            xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
+            num_metadata++;
+            if (sortkey && strcmp((const char *) sortkey, "no"))
+                num_sortkeys++;
+            xmlFree(sortkey);
+        }
+
+    service = conf_service_create(nmem, num_metadata, num_sortkeys);    
+
+    for (n = node->children; n; n = n->next)
+    {
+        if (n->type != XML_ELEMENT_NODE)
+            continue;
+        if (!strcmp((const char *) n->name, (const char *) "metadata"))
+        {
+            xmlChar *xml_name = xmlGetProp(n, (xmlChar *) "name");
+            xmlChar *xml_brief = xmlGetProp(n, (xmlChar *) "brief");
+            xmlChar *xml_sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
+            xmlChar *xml_merge = xmlGetProp(n, (xmlChar *) "merge");
+            xmlChar *xml_type = xmlGetProp(n, (xmlChar *) "type");
+            xmlChar *xml_termlist = xmlGetProp(n, (xmlChar *) "termlist");
+            xmlChar *xml_rank = xmlGetProp(n, (xmlChar *) "rank");
+            xmlChar *xml_setting = xmlGetProp(n, (xmlChar *) "setting");
+
+            enum conf_metadata_type type = Metadata_type_generic;
+            enum conf_metadata_merge merge = Metadata_merge_no;
+            enum conf_setting_type setting = Metadata_setting_no;
+            enum conf_sortkey_type sk_type = Metadata_sortkey_relevance;
+            int brief = 0;
+            int termlist = 0;
+            int rank = 0;
+            int sortkey_offset = 0;
+            
+            // now do the parsing logic
+            if (!xml_name)
+            {
+                yaz_log(YLOG_FATAL, "Must specify name in metadata element");
+                return 0;
+            }
+            if (xml_brief)
+            {
+                if (!strcmp((const char *) xml_brief, "yes"))
+                    brief = 1;
+                 else if (strcmp((const char *) xml_brief, "no"))
+                {
+                    yaz_log(YLOG_FATAL, "metadata/brief must be yes or no");
+                    return 0;
+                }
+            }
+            else
+                brief = 0;
+
+            if (xml_termlist)
+            {
+                if (!strcmp((const char *) xml_termlist, "yes"))
+                    termlist = 1;
+                else if (strcmp((const char *) xml_termlist, "no"))
+                {
+                    yaz_log(YLOG_FATAL, "metadata/termlist must be yes or no");
+                    return 0;
+                }
+            }
+            else
+                termlist = 0;
+
+            if (xml_rank)
+                rank = atoi((const char *) xml_rank);
+            else
+                rank = 0;
+
+            if (xml_type)
+            {
+                if (!strcmp((const char *) xml_type, "generic"))
+                    type = Metadata_type_generic;
+                else if (!strcmp((const char *) xml_type, "year"))
+                    type = Metadata_type_year;
+                else if (!strcmp((const char *) xml_type, "date"))
+                    type = Metadata_type_date;
+                else
+                {
+                    yaz_log(YLOG_FATAL, 
+                            "Unknown value for metadata/type: %s", xml_type);
+                    return 0;
+                }
+            }
+            else
+                type = Metadata_type_generic;
+
+            if (xml_merge)
+            {
+                if (!strcmp((const char *) xml_merge, "no"))
+                    merge = Metadata_merge_no;
+                else if (!strcmp((const char *) xml_merge, "unique"))
+                    merge = Metadata_merge_unique;
+                else if (!strcmp((const char *) xml_merge, "longest"))
+                    merge = Metadata_merge_longest;
+                else if (!strcmp((const char *) xml_merge, "range"))
+                    merge = Metadata_merge_range;
+                else if (!strcmp((const char *) xml_merge, "all"))
+                    merge = Metadata_merge_all;
+                else
+                {
+                    yaz_log(YLOG_FATAL, 
+                            "Unknown value for metadata/merge: %s", xml_merge);
+                    return 0;
+                }
+            }
+            else
+                merge = Metadata_merge_no;
+
+            if (xml_setting)
+            {
+                if (!strcmp((const char *) xml_setting, "no"))
+                    setting = Metadata_setting_no;
+                else if (!strcmp((const char *) xml_setting, "postproc"))
+                    setting = Metadata_setting_postproc;
+                else if (!strcmp((const char *) xml_setting, "parameter"))
+                    setting = Metadata_setting_parameter;
+                else
+                {
+                    yaz_log(YLOG_FATAL,
+                        "Unknown value for medadata/setting: %s", xml_setting);
+                    return 0;
+                }
+            }
+
+            // add a sortkey if so specified
+            if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
+            {
+                if (merge == Metadata_merge_no)
+                {
+                    yaz_log(YLOG_FATAL, 
+                            "Can't specify sortkey on a non-merged field");
+                    return 0;
+                }
+                if (!strcmp((const char *) xml_sortkey, "numeric"))
+                    sk_type = Metadata_sortkey_numeric;
+                else if (!strcmp((const char *) xml_sortkey, "skiparticle"))
+                    sk_type = Metadata_sortkey_skiparticle;
+                else
+                {
+                    yaz_log(YLOG_FATAL,
+                            "Unknown sortkey in metadata element: %s", 
+                            xml_sortkey);
+                    return 0;
+                }
+                sortkey_offset = sk_node;
+
+                conf_service_add_sortkey(nmem, service, sk_node,
+                                         (const char *) xml_name, sk_type);
+                
+                sk_node++;
+            }
+            else
+                sortkey_offset = -1;
+
+            // metadata known, assign values
+            conf_service_add_metadata(nmem, service, md_node,
+                                      (const char *) xml_name,
+                                      type, merge, setting,
+                                      brief, termlist, rank, sortkey_offset);
+
+            xmlFree(xml_name);
+            xmlFree(xml_brief);
+            xmlFree(xml_sortkey);
+            xmlFree(xml_merge);
+            xmlFree(xml_type);
+            xmlFree(xml_termlist);
+            xmlFree(xml_rank);
+            md_node++;
+        }
+        else
+        {
+            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+            return 0;
+        }
+    }
+    return service;
+}
+
+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;
+    struct conf_server *server = nmem_malloc(nmem, sizeof(struct conf_server));
+
+    server->host = 0;
+    server->port = 0;
+    server->proxy_host = 0;
+    server->proxy_port = 0;
+    server->myurl = 0;
+    server->service = 0;
+    server->next = 0;
+    server->settings = 0;
+    server->relevance_pct = 0;
+    server->sort_pct = 0;
+    server->mergekey_pct = 0;
+
+    for (n = node->children; n; n = n->next)
+    {
+        if (n->type != XML_ELEMENT_NODE)
+            continue;
+        if (!strcmp((const char *) n->name, "listen"))
+        {
+            xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
+            xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
+            if (port)
+                server->port = atoi((const char *) port);
+            if (host)
+                server->host = nmem_strdup(nmem, (const char *) host);
+            xmlFree(port);
+            xmlFree(host);
+        }
+        else if (!strcmp((const char *) n->name, "proxy"))
+        {
+            xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
+            xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
+            xmlChar *myurl = xmlGetProp(n, (xmlChar *) "myurl");
+            if (port)
+                server->proxy_port = atoi((const char *) port);
+            if (host)
+                server->proxy_host = nmem_strdup(nmem, (const char *) host);
+            if (myurl)
+                server->myurl = nmem_strdup(nmem, (const char *) myurl);
+            xmlFree(port);
+            xmlFree(host);
+            xmlFree(myurl);
+        }
+        else if (!strcmp((const char *) n->name, "settings"))
+        {
+            if (server->settings)
+            {
+                yaz_log(YLOG_FATAL, "Can't repeat 'settings'");
+                return 0;
+            }
+            if (!(server->settings = parse_settings(n)))
+                return 0;
+        }
+        else if (!strcmp((const char *) n->name, "relevance"))
+        {
+            server->relevance_pct = pp2_charset_create_xml(n->children);
+        }
+        else if (!strcmp((const char *) n->name, "sort"))
+        {
+            server->sort_pct = pp2_charset_create_xml(n->children);
+        }
+        else if (!strcmp((const char *) n->name, "mergekey"))
+        {
+            server->mergekey_pct = pp2_charset_create_xml(n->children);
+        }
+        else if (!strcmp((const char *) n->name, "service"))
+        {
+            struct conf_service *s = parse_service(n);
+            if (!s)
+                return 0;
+            server->service = s;
+        }
+        else
+        {
+            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+            return 0;
+        }
+    }
+    if (!server->relevance_pct)
+        server->relevance_pct = pp2_charset_create(0);
+    if (!server->sort_pct)
+        server->sort_pct = pp2_charset_create(0);
+    if (!server->mergekey_pct)
+        server->mergekey_pct = pp2_charset_create(0);
+    return server;
+}
+
+xsltStylesheet *conf_load_stylesheet(const char *fname)
+{
+    char path[256];
+    if (*fname == '/')
+        yaz_snprintf(path, sizeof(path), fname);
+    else
+        yaz_snprintf(path, sizeof(path), "%s/%s", confdir, fname);
+    return xsltParseStylesheetFile((xmlChar *) path);
+}
+
+static struct conf_targetprofiles *parse_targetprofiles(xmlNode *node)
+{
+    struct conf_targetprofiles *r = nmem_malloc(nmem, sizeof(*r));
+    xmlChar *type = xmlGetProp(node, (xmlChar *) "type");
+    xmlChar *src = xmlGetProp(node, (xmlChar *) "src");
+
+    memset(r, 0, sizeof(*r));
+
+    if (type)
+    {
+        if (!strcmp((const char *) type, "local"))
+            r->type = Targetprofiles_local;
+        else
+        {
+            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;
+}
+
+static struct conf_config *parse_config(xmlNode *root)
+{
+    xmlNode *n;
+    struct conf_config *r = nmem_malloc(nmem, sizeof(struct conf_config));
+
+    r->servers = 0;
+    r->targetprofiles = 0;
+
+    for (n = root->children; n; n = n->next)
+    {
+        if (n->type != XML_ELEMENT_NODE)
+            continue;
+        if (!strcmp((const char *) n->name, "server"))
+        {
+            struct conf_server *tmp = parse_server(n);
+            if (!tmp)
+                return 0;
+            tmp->next = r->servers;
+            r->servers = tmp;
+        }
+        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(n)))
+                return 0;
+        }
+        else
+        {
+            yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+            return 0;
+        }
+    }
+    return r;
+}
+
+int read_config(const char *fname)
+{
+    xmlDoc *doc = xmlParseFile(fname);
+    const char *p;
+
+    if (!nmem)  // Initialize
+    {
+        nmem = nmem_create();
+        xmlSubstituteEntitiesDefault(1);
+        xmlLoadExtDtdDefaultValue = 1;
+    }
+    if (!doc)
+    {
+        yaz_log(YLOG_FATAL, "Failed to read %s", fname);
+        exit(1);
+    }
+    if ((p = strrchr(fname, '/')))
+    {
+        int len = p - fname;
+        if (len >= sizeof(confdir))
+            len = sizeof(confdir)-1;
+        strncpy(confdir, fname, len);
+        confdir[len] = '\0';
+    }
+    config = parse_config(xmlDocGetRootElement(doc));
+    xmlFreeDoc(doc);
+
+    if (config)
+        return 1;
+    else
+        return 0;
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h
new file mode 100644 (file)
index 0000000..2a3dab9
--- /dev/null
@@ -0,0 +1,196 @@
+/* This file is part of Pazpar2.
+   Copyright (C) 2006-2008 Index Data
+
+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 this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#ifndef PAZPAR2_CONFIG_H
+#define PAZPAR2_CONFIG_H
+
+#include <libxslt/xslt.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+
+#include <yaz/nmem.h>
+#include "charsets.h"
+
+enum conf_metadata_type {
+    Metadata_type_generic,    // Generic text field
+    Metadata_type_number,     // A number
+    Metadata_type_year,        // A number
+    Metadata_type_date        // A number
+};
+
+enum conf_metadata_merge {
+    Metadata_merge_no,        // Don't merge
+    Metadata_merge_unique,    // Include unique elements in merged block
+    Metadata_merge_longest,   // Include the longest (strlen) value
+    Metadata_merge_range,     // Store value as a range of lowest-highest
+    Metadata_merge_all        // Just include all elements found
+};
+
+enum conf_sortkey_type {
+    Metadata_sortkey_relevance,
+    Metadata_sortkey_numeric,       // Standard numerical sorting
+    Metadata_sortkey_skiparticle,   // Skip leading article when sorting
+    Metadata_sortkey_string         // Flat string
+};
+
+// This controls the ability to insert 'static' values from settings into retrieval recs
+enum conf_setting_type {
+    Metadata_setting_no,
+    Metadata_setting_postproc,      // Insert setting value into normalized record
+    Metadata_setting_parameter      // Expose value to normalization stylesheets
+};
+
+// Describes known metadata elements and how they are to be manipulated
+// An array of these structure provides a 'map' against which
+// discovered metadata elements are matched. It also governs storage,
+// to minimize number of cycles needed at various tages of processing
+struct conf_metadata 
+{
+    char *name;  // The field name. Output by normalization stylesheet
+    int brief;   // Is this element to be returned in the brief format?
+    int termlist;// Is this field to be treated as a termlist for browsing?
+    int rank;    // Rank factor. 0 means don't use this field for ranking, 
+                 // 1 is default
+                 // values >1  give additional significance to a field
+    int sortkey_offset; // -1 if it's not a sortkey, otherwise index
+                        // into service/record_cluster->sortkey array
+    enum conf_metadata_type type;
+    enum conf_metadata_merge merge;
+    enum conf_setting_type setting; // Value is to be taken from session/db settings?
+};
+
+
+
+struct conf_metadata * conf_metadata_assign(NMEM nmem, 
+                                            struct conf_metadata * metadata,
+                                            const char *name,
+                                            enum conf_metadata_type type,
+                                            enum conf_metadata_merge merge,
+                                            enum conf_setting_type setting,
+                                            int brief,
+                                            int termlist,
+                                            int rank,
+                                            int sortkey_offset);
+
+
+
+// Controls sorting
+struct conf_sortkey
+{
+    char *name;
+    enum conf_sortkey_type type;
+};
+
+struct conf_sortkey * conf_sortkey_assign(NMEM nmem, 
+                                            struct conf_sortkey * sortkey,
+                                            const char *name,
+                                            enum conf_sortkey_type type);
+
+
+
+// It is conceivable that there will eventually be several 'services'
+// offered from one server, with separate configuration -- possibly
+// more than one services associated with the same port. For now,
+// however, only a single service is possible.
+struct conf_service
+{
+    int num_metadata;
+    struct conf_metadata *metadata;
+    int num_sortkeys;
+    struct conf_sortkey *sortkeys;
+
+};
+
+struct conf_service * conf_service_create(NMEM nmem, 
+                                          int num_metadata, int num_sortkeys);
+
+
+struct conf_metadata* conf_service_add_metadata(NMEM nmem, 
+                                                struct conf_service *service,
+                                                int field_id,
+                                                const char *name,
+                                                enum conf_metadata_type type,
+                                                enum conf_metadata_merge merge,
+                                                enum conf_setting_type setting,
+                                                int brief,
+                                                int termlist,
+                                                int rank,
+                                                int sortkey_offset);
+
+struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
+                                               struct conf_service *service,
+                                               int field_id,
+                                               const char *name,
+                                               enum conf_sortkey_type type);
+
+
+int conf_service_metadata_field_id(struct conf_service *service, const char * name);
+
+int conf_service_sortkey_field_id(struct conf_service *service, const char * name);
+
+
+struct conf_server
+{
+    char *host;
+    int port;
+    char *proxy_host;
+    int proxy_port;
+    char *myurl;
+    char *settings;
+
+    pp2_charset_t relevance_pct;
+    pp2_charset_t sort_pct;
+    pp2_charset_t mergekey_pct;
+
+    struct conf_service *service;
+    struct conf_server *next;
+};
+
+struct conf_targetprofiles
+{
+    enum {
+        Targetprofiles_local
+    } type;
+    char *src;
+};
+
+struct conf_config
+{
+    struct conf_server *servers;
+    struct conf_targetprofiles *targetprofiles;
+};
+
+#ifndef CONFIG_NOEXTERNS
+
+extern struct conf_config *config;
+
+#endif
+
+int read_config(const char *fname);
+xsltStylesheet *conf_load_stylesheet(const char *fname);
+
+#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
index 8dac597..663fa33 100644 (file)
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <assert.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #include <yaz/yaz-util.h>
index 4ccef8f..c75b53b 100644 (file)
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #ifndef RECLISTS_H
 #define RECLISTS_H
 
-#include "config.h"
+#include "pazpar2_config.h"
 #include "record.h"
 
 struct reclist
index 9864238..5220abf 100644 (file)
@@ -26,11 +26,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/nmem.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 //#define CONFIG_NOEXTERNS
-#include "config.h"
+#include "pazpar2_config.h"
 #include "record.h"
 
 
index 1a9f4d7..b35adce 100644 (file)
@@ -22,7 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <stdlib.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #include "relevance.h"
@@ -284,31 +284,6 @@ void relevance_donerecord(struct relevance *r, struct record_cluster *cluster)
     r->doc_frequency_vec[0]++;
 }
 
-#ifdef GAGA
-#ifdef FLOAT_REL
-static int comp(const void *p1, const void *p2)
-{
-    float res;
-    struct record **r1 = (struct record **) p1;
-    struct record **r2 = (struct record **) p2;
-    res = (*r2)->relevance - (*r1)->relevance;
-    if (res > 0)
-        return 1;
-    else if (res < 0)
-        return -1;
-    else
-        return 0;
-}
-#else
-static int comp(const void *p1, const void *p2)
-{
-    struct record_cluster **r1 = (struct record_cluster **) p1;
-    struct record_cluster **r2 = (struct record_cluster **) p2;
-    return (*r2)->relevance - (*r1)->relevance;
-}
-#endif
-#endif
-
 // Prepare for a relevance-sorted read
 void relevance_prepare_read(struct relevance *rel, struct reclist *reclist)
 {
@@ -350,9 +325,6 @@ void relevance_prepare_read(struct relevance *rel, struct reclist *reclist)
         }
         rec->relevance = (int) (relevance * 100000);
     }
-#ifdef GAGA
-    qsort(reclist->flatlist, reclist->num_records, sizeof(struct record*), comp);
-#endif
     reclist->pointer = 0;
     xfree(idfvec);
 }
index 669c0b3..0139c07 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include "sel_thread.h"
index a41f23c..5cb08c1 100644 (file)
@@ -313,22 +313,6 @@ static void update_database(void *context, struct database *db)
     if (!match_zurl(db->url, set->target))
         return;
 
-#ifdef GAGA
-    // Initialize settings array if it doesn't exist.
-    // If so, also set the 'id' automatic setting
-    if (!db->settings)
-    {
-        struct setting *id = nmem_malloc(nmem, sizeof(struct setting));
-
-        db->settings = nmem_malloc(nmem, sizeof(struct settings*) * dictionary->num);
-        memset(db->settings, 0, sizeof(struct settings*) * dictionary->num);
-        id->precedence = 0;
-        id->name = "pz:id";
-        id->target = id->value = db->url;
-        id->next = 0;
-        db->settings[PZ_ID] = id;
-    }
-#endif
     if ((offset = settings_offset_cprefix(set->name)) < 0)
         abort(); // Should never get here
 
index 52c22d2..ad0529c 100644 (file)
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/yaz-util.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #include "termlists.h"
index 68a955b..59e3d73 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
@@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <yaz/test.h>
 
-#include "config.h"
+#include "pazpar2_config.h"
 
 
 
index dbda433..bc55d7d 100644 (file)
@@ -21,7 +21,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
index 6f80f8e..c8fad2c 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include <string.h>
index eabf740..b5f29ca 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
@@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/test.h>
 
 
-#include "config.h"
+#include "pazpar2_config.h"
 //#include "record.h"
 #include "reclists.h"
 
index 06398b5..768a8c6 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
@@ -28,7 +28,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include <yaz/test.h>
 
-#include "config.h"
+#include "pazpar2_config.h"
 #include "record.h"
 
 
index a3e120b..b3707f7 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #define USE_TIMING 0
@@ -29,7 +29,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/test.h>
 
 
-#include "config.h"
+#include "pazpar2_config.h"
 #include "relevance.h"
 #include "record.h"
 #include "reclists.h"
index 0627dc1..90abdca 100644 (file)
@@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
 #if HAVE_CONFIG_H
-#include "cconfig.h"
+#include <config.h>
 #endif
 
 #include "sel_thread.h"
index 08cee14..7944d97 100644 (file)
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <stdlib.h>
 
 #if HAVE_CONFIG_H
-#include <cconfig.h>
+#include <config.h>
 #endif
 
 #include <yaz/yaz-util.h>