X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fpazpar2_config.c;h=8b94b63df9994d8d316fca0082d3c74a8f596c9b;hb=846689d992d2183563cba6aa5f52f60dc8b14ab4;hp=8943b205337403b9acde34f66b8a73801fc7c63d;hpb=284649ed257354c2fcb2f2a6c78cf5fd7cf2283d;p=pazpar2-moved-to-github.git diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index 8943b20..8b94b63 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -1,5 +1,5 @@ /* This file is part of Pazpar2. - Copyright (C) 2006-2010 Index Data + Copyright (C) 2006-2011 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 @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if HAVE_UNISTD_H #include #endif +#include "ppmutex.h" #include "incref.h" #include "pazpar2_config.h" #include "settings.h" @@ -48,8 +49,11 @@ struct conf_config { 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; }; @@ -127,6 +131,7 @@ static struct conf_service *service_init(struct conf_server *server, service->relevance_pct = 0; service->sort_pct = 0; service->mergekey_pct = 0; + service->facet_pct = 0; service->id = service_id ? nmem_strdup(nmem, service_id) : 0; service->num_metadata = num_metadata; @@ -245,6 +250,7 @@ void service_destroy(struct conf_service *service) pp2_charset_destroy(service->relevance_pct); pp2_charset_destroy(service->sort_pct); pp2_charset_destroy(service->mergekey_pct); + pp2_charset_destroy(service->facet_pct); yaz_mutex_destroy(&service->mutex); nmem_destroy(service->nmem); } @@ -562,6 +568,20 @@ static struct conf_service *service_create_static(struct conf_server *server, return 0; } } + else if (!strcmp((const char *) n->name, "facet")) + { + if (service->mergekey_pct) + { + yaz_log(YLOG_LOG, "facety may not repeat in service"); + return 0; + } + else + { + service->facet_pct = pp2_charset_create_xml(n); + if (!service->mergekey_pct) + return 0; + } + } else if (!strcmp((const char *) n->name, (const char *) "metadata")) { if (parse_metadata(service, n, &md_node, &sk_node)) @@ -648,7 +668,7 @@ static void inherit_server_settings(struct conf_service *s) } } - /* use relevance/sort/mergekey from server if not defined + /* use relevance/sort/mergekey/facet from server if not defined for this service.. */ if (!s->relevance_pct) { @@ -658,7 +678,7 @@ static void inherit_server_settings(struct conf_service *s) pp2_charset_incref(s->relevance_pct); } else - s->relevance_pct = pp2_charset_create(0); + s->relevance_pct = pp2_charset_create_a_to_z(); } if (!s->sort_pct) @@ -669,7 +689,7 @@ static void inherit_server_settings(struct conf_service *s) pp2_charset_incref(s->sort_pct); } else - s->sort_pct = pp2_charset_create(0); + s->sort_pct = pp2_charset_create_a_to_z(); } if (!s->mergekey_pct) @@ -680,7 +700,18 @@ static void inherit_server_settings(struct conf_service *s) pp2_charset_incref(s->mergekey_pct); } else - s->mergekey_pct = pp2_charset_create(0); + s->mergekey_pct = pp2_charset_create_a_to_z(); + } + + if (!s->facet_pct) + { + if (server->facet_pct) + { + s->facet_pct = server->facet_pct; + pp2_charset_incref(s->facet_pct); + } + else + s->facet_pct = pp2_charset_create(0); } } @@ -694,7 +725,7 @@ struct conf_service *service_create(struct conf_server *server, inherit_server_settings(service); resolve_databases(service); assert(service->mutex == 0); - yaz_mutex_create(&service->mutex); + pazpar2_mutex_create(&service->mutex, "conf"); } return service; } @@ -717,8 +748,11 @@ static struct conf_server *server_create(struct conf_config *config, server->relevance_pct = 0; server->sort_pct = 0; server->mergekey_pct = 0; + server->facet_pct = 0; server->server_settings = 0; server->http_server = 0; + server->iochan_man = 0; + server->database_hosts = 0; if (server_id) { @@ -785,6 +819,12 @@ static struct conf_server *server_create(struct conf_config *config, if (!server->mergekey_pct) return 0; } + else if (!strcmp((const char *) n->name, "facet")) + { + server->facet_pct = pp2_charset_create_xml(n); + if (!server->facet_pct) + return 0; + } else if (!strcmp((const char *) n->name, "service")) { char *service_id = (char *) @@ -834,9 +874,8 @@ static struct conf_server *server_create(struct conf_config *config, return server; } -WRBUF conf_get_fname(struct conf_service *service, const char *fname) +WRBUF conf_get_fname(struct conf_config *config, const char *fname) { - struct conf_config *config = service->server->config; WRBUF w = wrbuf_alloc(); conf_dir_path(config, w, fname); @@ -894,6 +933,25 @@ struct conf_service *locate_service(struct conf_server *server, return s; } +void info_services(struct conf_server *server, WRBUF w) +{ + struct conf_service *s = server->service; + wrbuf_puts(w, " \n"); + for (; s; s = s->next) + { + wrbuf_puts(w, " id) + { + wrbuf_puts(w, " id=\""); + wrbuf_xmlputs(w, s->id); + wrbuf_puts(w, "\""); + } + wrbuf_puts(w, "/>"); + + wrbuf_puts(w, "\n"); + } + wrbuf_puts(w, " \n"); +} static int parse_config(struct conf_config *config, xmlNode *root) { @@ -956,6 +1014,7 @@ struct conf_config *config_create(const char *fname, int verbose) config->nmem = nmem; config->servers = 0; config->no_threads = 0; + config->iochan_man = 0; config->confdir = wrbuf_alloc(); if ((p = strrchr(fname, @@ -1009,6 +1068,7 @@ void server_destroy(struct conf_server *server) pp2_charset_destroy(server->relevance_pct); pp2_charset_destroy(server->sort_pct); pp2_charset_destroy(server->mergekey_pct); + pp2_charset_destroy(server->facet_pct); yaz_log(YLOG_LOG, "server_destroy server=%p", server); http_server_destroy(server->http_server); } @@ -1018,12 +1078,15 @@ void config_destroy(struct conf_config *config) if (config) { struct conf_server *server = config->servers; + iochan_man_destroy(&config->iochan_man); while (server) { struct conf_server *s_next = server->next; server_destroy(server); server = s_next; } + database_hosts_destroy(&config->database_hosts); + wrbuf_destroy(config->confdir); nmem_destroy(config->nmem); } @@ -1036,31 +1099,41 @@ void config_stop_listeners(struct conf_config *conf) http_close_server(ser); } -void config_start_databases(struct conf_config *conf) +void config_process_events(struct conf_config *conf) { struct conf_server *ser; + + conf->database_hosts = database_hosts_create(); for (ser = conf->servers; ser; ser = ser->next) { struct conf_service *s = ser->service; + + ser->database_hosts = conf->database_hosts; + for (;s ; s = s->next) { resolve_databases(s); assert(s->mutex == 0); - yaz_mutex_create(&s->mutex); + pazpar2_mutex_create(&s->mutex, "service"); } http_mutex_init(ser); } + iochan_man_events(conf->iochan_man); } int config_start_listeners(struct conf_config *conf, - const char *listener_override) + const char *listener_override, + const char *record_fname) { struct conf_server *ser; - pazpar2_chan_man_start(conf->no_threads); + + conf->iochan_man = iochan_man_create(conf->no_threads); for (ser = conf->servers; ser; ser = ser->next) { WRBUF w = wrbuf_alloc(); int r; + + ser->iochan_man = conf->iochan_man; if (listener_override) { wrbuf_puts(w, listener_override); @@ -1077,7 +1150,7 @@ int config_start_listeners(struct conf_config *conf, wrbuf_printf(w, "%d", ser->port); } } - r = http_init(wrbuf_cstr(w), ser); + r = http_init(wrbuf_cstr(w), ser, record_fname); wrbuf_destroy(w); if (r) return -1;