/* This file is part of Pazpar2.
- Copyright (C) 2006-2011 Index Data
+ Copyright (C) 2006-2013 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
#include "ppmutex.h"
#include "incref.h"
#include "pazpar2_config.h"
+#include "service_xslt.h"
#include "settings.h"
#include "eventl.h"
#include "http.h"
{
NMEM nmem; /* for conf_config and servers memory */
struct conf_server *servers;
-
+
int no_threads;
WRBUF confdir;
iochan_man_t iochan_man;
database_hosts_t database_hosts;
};
-static void 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,
- enum conf_metadata_mergekey mt,
- const char *facetrule)
-{
- assert(nmem && metadata && name);
-
- 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;
- metadata->mergekey = mt;
- metadata->facetrule = nmem_strdup_null(nmem, facetrule);
-}
-
-
-static void conf_sortkey_assign(NMEM nmem,
- struct conf_sortkey * sortkey,
- const char *name,
- enum conf_sortkey_type type)
+struct service_xslt
{
- assert(nmem && sortkey && name);
-
- sortkey->name = nmem_strdup(nmem, name);
- sortkey->type = type;
-}
+ char *id;
+ xsltStylesheetPtr xsp;
+ struct service_xslt *next;
+};
-static struct conf_service *service_init(struct conf_server *server,
+struct conf_service *service_init(struct conf_server *server,
int num_metadata, int num_sortkeys,
const char *service_id)
{
struct conf_service * service = 0;
NMEM nmem = nmem_create();
+
service = nmem_malloc(nmem, sizeof(struct conf_service));
service->mutex = 0;
service->ref_count = 1;
service->nmem = nmem;
service->next = 0;
service->databases = 0;
+ service->xslt_list = 0;
+ service->ccl_bibset = 0;
service->server = server;
service->session_timeout = 60; /* default session timeout */
service->z3950_session_timeout = 180;
service->z3950_operation_timeout = 30;
+ service->rank_cluster = 1;
+ service->rank_debug = 0;
+ service->rank_follow = 0.0;
+ service->rank_lead = 0.0;
+ service->rank_length = 2;
service->charsets = 0;
service->id = service_id ? nmem_strdup(nmem, service_id) : 0;
+
+ // Setup a dictionary from server.
+ service->dictionary = 0;
+
+ service->settings = nmem_malloc(nmem, sizeof(*service->settings));
+ service->settings->num_settings = PZ_MAX_EOF;
+ service->settings->settings = nmem_malloc(nmem, sizeof(struct setting*) * service->settings->num_settings);
+ memset(service->settings->settings, 0, sizeof(struct setting*) * service->settings->num_settings);
+ // inherit_server_settings_values(service);
+
+ service->next = 0;
+
service->num_metadata = num_metadata;
+
service->metadata = 0;
if (service->num_metadata)
- service->metadata
- = nmem_malloc(nmem,
+ service->metadata
+ = nmem_malloc(nmem,
sizeof(struct conf_metadata) * service->num_metadata);
service->num_sortkeys = num_sortkeys;
+
+ service->default_sort = nmem_strdup(nmem, "relevance");
service->sortkeys = 0;
if (service->num_sortkeys)
- service->sortkeys
- = nmem_malloc(nmem,
+ service->sortkeys
+ = nmem_malloc(nmem,
sizeof(struct conf_sortkey) * service->num_sortkeys);
- service->dictionary = 0;
- return service;
+
+
+ return service;
}
static struct conf_metadata* conf_service_add_metadata(
enum conf_setting_type setting,
int brief,
int termlist,
- int rank,
+ const char *rank,
int sortkey_offset,
enum conf_metadata_mergekey mt,
- const char *facetrule)
+ const char *facetrule,
+ const char *limitmap,
+ const char *limitcluster
+ )
{
struct conf_metadata * md = 0;
+ NMEM nmem = service->nmem;
- if (!service || !service->metadata || !service->num_metadata
+ if (!service->metadata || !service->num_metadata
|| field_id < 0 || !(field_id < service->num_metadata))
return 0;
md = service->metadata + field_id;
- conf_metadata_assign(service->nmem, md, name, type, merge, setting,
- brief, termlist, rank, sortkey_offset,
- mt, facetrule);
+ assert(nmem && md && name);
+
+ md->name = nmem_strdup(nmem, name);
+
+ md->type = type;
+
+ // enforcing that type_year is always range_merge
+ if (md->type == Metadata_type_year)
+ md->merge = Metadata_merge_range;
+ else
+ md->merge = merge;
+
+ md->setting = setting;
+ md->brief = brief;
+ md->termlist = termlist;
+ md->rank = nmem_strdup_null(nmem, rank);
+ md->sortkey_offset = sortkey_offset;
+ md->mergekey = mt;
+ md->facetrule = nmem_strdup_null(nmem, facetrule);
+ md->limitmap = nmem_strdup_null(nmem, limitmap);
+ md->limitcluster = nmem_strdup_null(nmem, limitcluster);
return md;
}
-static struct conf_sortkey * conf_service_add_sortkey(
+static struct conf_sortkey *conf_service_add_sortkey(
struct conf_service *service,
int field_id,
const char *name,
enum conf_sortkey_type type)
{
- struct conf_sortkey * sk = 0;
+ struct conf_sortkey *sk = 0;
+ NMEM nmem = service->nmem;
- if (!service || !service->sortkeys || !service->num_sortkeys
+ if (!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;
- conf_sortkey_assign(service->nmem, sk, name, type);
+ assert(nmem && sk && name);
+
+ sk->name = nmem_strdup(nmem, name);
+ sk->type = type;
return sk;
}
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;
{
if (!pazpar2_decref(&service->ref_count, service->mutex))
{
+ service_xslt_destroy(service);
pp2_charset_fact_destroy(service->charsets);
+ ccl_qual_rm(&service->ccl_bibset);
yaz_mutex_destroy(&service->mutex);
nmem_destroy(service->nmem);
}
enum conf_metadata_mergekey mergekey_type = Metadata_mergekey_no;
int brief = 0;
int termlist = 0;
- int rank = 0;
int sortkey_offset = 0;
xmlChar *xml_name = 0;
xmlChar *xml_brief = 0;
xmlChar *xml_rank = 0;
xmlChar *xml_setting = 0;
xmlChar *xml_mergekey = 0;
+ xmlChar *xml_limitmap = 0;
+ xmlChar *xml_limitcluster = 0;
xmlChar *xml_icu_chain = 0;
+
struct _xmlAttr *attr;
+
+ assert(service);
+
for (attr = n->properties; attr; attr = attr->next)
{
if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
else if (!xmlStrcmp(attr->name, BAD_CAST "facetrule") &&
attr->children && attr->children->type == XML_TEXT_NODE)
xml_icu_chain = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "limitmap") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_limitmap = attr->children->content;
+ else if (!xmlStrcmp(attr->name, BAD_CAST "limitcluster") &&
+ attr->children && attr->children->type == XML_TEXT_NODE)
+ xml_limitcluster = attr->children->content;
else
{
yaz_log(YLOG_FATAL, "Unknown metadata attribute '%s'", attr->name);
return -1;
}
}
-
+
// now do the parsing logic
if (!xml_name)
{
return -1;
}
}
-
+
if (xml_termlist)
{
if (!strcmp((const char *) xml_termlist, "yes"))
return -1;
}
}
-
- if (xml_rank)
- rank = atoi((const char *) xml_rank);
if (xml_type)
{
type = Metadata_type_date;
else
{
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"Unknown value for metadata/type: %s", xml_type);
return -1;
}
}
-
+
if (xml_merge)
{
if (!strcmp((const char *) xml_merge, "no"))
merge = Metadata_merge_all;
else
{
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"Unknown value for metadata/merge: %s", xml_merge);
return -1;
}
}
-
+
if (xml_setting)
{
if (!strcmp((const char *) xml_setting, "no"))
return -1;
}
}
-
+
// add a sortkey if so specified
if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
{
enum conf_sortkey_type sk_type;
if (merge == Metadata_merge_no)
{
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"Can't specify sortkey on a non-merged field");
return -1;
}
else
{
yaz_log(YLOG_FATAL,
- "Unknown sortkey in metadata element: %s",
+ "Unknown sortkey in metadata element: %s",
xml_sortkey);
return -1;
}
sortkey_offset = *sk_node;
-
+
conf_service_add_sortkey(service, *sk_node,
- (const char *) xml_name, sk_type);
+ (const char *) xml_name, sk_type);
(*sk_node)++;
}
else
sortkey_offset = -1;
-
+
if (xml_mergekey)
{
if (!strcmp((const char *) xml_mergekey, "required"))
conf_service_add_metadata(service, *md_node,
(const char *) xml_name,
type, merge, setting,
- brief, termlist, rank, sortkey_offset,
- mergekey_type, (const char *) xml_icu_chain);
+ brief, termlist,
+ (const char *) xml_rank, sortkey_offset,
+ mergekey_type,
+ (const char *) xml_icu_chain,
+ (const char *) xml_limitmap,
+ (const char *) xml_limitcluster);
(*md_node)++;
return 0;
}
int num_metadata = 0;
int num_sortkeys = 0;
int got_settings = 0;
-
+
// count num_metadata and num_sortkeys
for (n = node->children; n; n = n->next)
if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)
}
}
}
+ else if (!strcmp((const char *) n->name, "ccldirective"))
+ {
+ char *name;
+ char *value;
+ if (!service->ccl_bibset)
+ service->ccl_bibset = ccl_qual_mk();
+ name = (char *) xmlGetProp(n, (xmlChar *) "name");
+ if (!name)
+ {
+ yaz_log(YLOG_FATAL, "ccldirective: missing @name");
+ return 0;
+ }
+ value = (char *) xmlGetProp(n, (xmlChar *) "value");
+ if (!value)
+ {
+ xmlFree(name);
+ yaz_log(YLOG_FATAL, "ccldirective: missing @value");
+ return 0;
+ }
+ ccl_qual_add_special(service->ccl_bibset, name, value);
+ xmlFree(value);
+ xmlFree(name);
+ }
else if (!strcmp((const char *) n->name, "settings"))
got_settings++;
else if (!strcmp((const char *) n->name, "icu_chain"))
if (parse_metadata(service, n, &md_node, &sk_node))
return 0;
}
+ else if (!strcmp((const char *) n->name, (const char *) "xslt"))
+ {
+ if (service_xslt_config(service, n))
+ return 0;
+ }
+ else if (!strcmp((const char *) n->name, (const char *) "set"))
+ {
+ xmlChar *name= xmlGetProp(n, (xmlChar *) "name");
+ xmlChar *value = xmlGetProp(n, (xmlChar *) "value");
+ if (service->dictionary && name && value) {
+ yaz_log(YLOG_DEBUG, "service set: %s=%s (Not implemented)", (char *) name, (char *) value);
+ //service_aply_setting(service, name, value);
+ }
+ }
+ else if (!strcmp((const char *) n->name, "rank"))
+ {
+ char *rank_cluster = (char *) xmlGetProp(n, (xmlChar *) "cluster");
+ char *rank_debug = (char *) xmlGetProp(n, (xmlChar *) "debug");
+ char *rank_follow = (char *) xmlGetProp(n, (xmlChar *) "follow");
+ char *rank_lead = (char *) xmlGetProp(n, (xmlChar *) "lead");
+ char *rank_length= (char *) xmlGetProp(n, (xmlChar *) "length");
+ if (rank_cluster)
+ {
+ if (!strcmp(rank_cluster, "yes"))
+ service->rank_cluster = 1;
+ else if (!strcmp(rank_cluster, "no"))
+ service->rank_cluster = 0;
+ else
+ {
+ yaz_log(YLOG_FATAL, "service: rank@cluster boolean");
+ return 0;
+ }
+ }
+ if (rank_debug)
+ {
+ if (!strcmp(rank_debug, "yes"))
+ service->rank_debug = 1;
+ else if (!strcmp(rank_debug, "no"))
+ service->rank_debug = 0;
+ else
+ {
+ yaz_log(YLOG_FATAL, "service: rank@debug boolean");
+ return 0;
+ }
+ }
+ if (rank_follow)
+ {
+ service->rank_follow = atof(rank_follow);
+ }
+ if (rank_lead)
+ {
+ service->rank_lead = atof(rank_lead);
+ }
+ if (rank_length)
+ {
+ if (!strcmp(rank_length, "linear"))
+ service->rank_length = 2;
+ else if (!strcmp(rank_length, "log"))
+ service->rank_length = 1;
+ else if (!strcmp(rank_length, "none"))
+ service->rank_length = 0;
+ else
+ {
+ yaz_log(YLOG_FATAL, "service: rank@length linear|log|none");
+ return 0;
+ }
+ }
+ xmlFree(rank_cluster);
+ xmlFree(rank_debug);
+ xmlFree(rank_follow);
+ xmlFree(rank_lead);
+ xmlFree(rank_length);
+ }
+ else if (!strcmp((const char *) n->name, "sort-default"))
+ {
+ char *default_sort = (char *) xmlGetProp(n, (xmlChar *) "field");
+
+ if (default_sort && strcmp(default_sort, "")) {
+ service->default_sort = nmem_strdup(service->nmem, default_sort);
+ yaz_log(YLOG_LOG, "service %s: default sort order configured to: %s",
+ service_id ? service_id : "unnamed", default_sort);
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "default sort order is invalid: %s", default_sort);
+ return 0;
+ }
+ xmlFree(default_sort);
+ }
else
{
yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
continue;
if (!strcmp((const char *) n->name, "settings"))
{
+ int ret;
xmlChar *src = xmlGetProp(n, (xmlChar *) "src");
if (src)
{
WRBUF w = wrbuf_alloc();
conf_dir_path(server->config, w, (const char *) src);
- settings_read_file(service, wrbuf_cstr(w), pass);
+ ret = settings_read_file(service, wrbuf_cstr(w), pass);
wrbuf_destroy(w);
xmlFree(src);
}
else
{
- settings_read_node(service, n, pass);
+ ret = settings_read_node(service, n, pass);
}
+ if (ret)
+ return 0;
}
}
}
return service;
}
-static void inherit_server_settings(struct conf_service *s)
+static int inherit_server_settings(struct conf_service *s)
{
+ int ret = 0;
struct conf_server *server = s->server;
if (!s->dictionary) /* service has no config settings ? */
{
{
/* inherit settings from server */
init_settings(s);
- settings_read_file(s, server->settings_fname, 1);
- settings_read_file(s, server->settings_fname, 2);
+ if (settings_read_file(s, server->settings_fname, 1))
+ ret = -1;
+ if (settings_read_file(s, server->settings_fname, 2))
+ ret = -1;
}
else
{
- yaz_log(YLOG_WARN, "service '%s' has no settings",
- s->id ? s->id : "unnamed");
+ yaz_log(YLOG_WARN, "server '%s' has no settings", s->id ? s->id : "unnamed");
init_settings(s);
}
}
-
+
/* use relevance/sort/mergekey/facet from server if not defined
for this service.. */
if (!s->charsets)
s->charsets = pp2_charset_fact_create();
}
}
+ return ret;
}
struct conf_service *service_create(struct conf_server *server,
xmlNode *node)
{
- struct conf_service *service = service_create_static(server,
- node, 0);
+ struct conf_service *service = service_create_static(server, node, 0);
if (service)
{
inherit_server_settings(service);
- resolve_databases(service);
assert(service->mutex == 0);
pazpar2_mutex_create(&service->mutex, "conf");
}
{
yaz_log(YLOG_FATAL, "ICU chain definition error");
return 0;
- }
- }
+ }
+ }
else if (!strcmp((const char *) n->name, "service"))
{
char *service_id = (char *)
config->database_hosts = database_hosts_create();
config->confdir = wrbuf_alloc();
- if ((p = strrchr(fname,
+ if ((p = strrchr(fname,
#ifdef WIN32
'\\'
#else
wrbuf_write(config->confdir, fname, len);
}
wrbuf_puts(config->confdir, "");
-
+
n = xmlDocGetRootElement(doc);
r = yaz_xml_include_simple(n, wrbuf_cstr(config->confdir));
if (r == 0) /* OK */
if (config)
{
struct conf_server *server = config->servers;
- iochan_man_destroy(&config->iochan_man);
+ iochan_man_destroy(&config->iochan_man);
while (server)
{
struct conf_server *s_next = server->next;
void config_process_events(struct conf_config *conf)
{
struct conf_server *ser;
-
+
for (ser = conf->servers; ser; ser = ser->next)
{
struct conf_service *s = ser->service;
for (;s ; s = s->next)
{
- resolve_databases(s);
assert(s->mutex == 0);
pazpar2_mutex_create(&s->mutex, "service");
}