1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2012 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <libxml/parser.h>
28 #include <libxml/tree.h>
30 #include <yaz/yaz-util.h>
32 #include <yaz/snprintf.h>
33 #include <yaz/tpath.h>
34 #include <yaz/xml_include.h>
36 #include <sys/types.h>
43 #include "pazpar2_config.h"
44 #include "service_xslt.h"
51 NMEM nmem; /* for conf_config and servers memory */
52 struct conf_server *servers;
56 iochan_man_t iochan_man;
57 database_hosts_t database_hosts;
63 xsltStylesheetPtr xsp;
64 struct service_xslt *next;
67 static void conf_metadata_assign(NMEM nmem,
68 struct conf_metadata * metadata,
70 enum conf_metadata_type type,
71 enum conf_metadata_merge merge,
72 enum conf_setting_type setting,
77 enum conf_metadata_mergekey mt,
78 const char *facetrule,
81 assert(nmem && metadata && name);
83 metadata->name = nmem_strdup(nmem, name);
85 metadata->type = type;
87 // enforcing that type_year is always range_merge
88 if (metadata->type == Metadata_type_year)
89 metadata->merge = Metadata_merge_range;
91 metadata->merge = merge;
93 metadata->setting = setting;
94 metadata->brief = brief;
95 metadata->termlist = termlist;
96 metadata->rank = nmem_strdup_null(nmem, rank);
97 metadata->sortkey_offset = sortkey_offset;
98 metadata->mergekey = mt;
99 metadata->facetrule = nmem_strdup_null(nmem, facetrule);
100 metadata->limitmap = nmem_strdup_null(nmem, limitmap);
104 static void conf_sortkey_assign(NMEM nmem,
105 struct conf_sortkey * sortkey,
107 enum conf_sortkey_type type)
109 assert(nmem && sortkey && name);
111 sortkey->name = nmem_strdup(nmem, name);
112 sortkey->type = type;
115 struct conf_service *service_init(struct conf_server *server,
116 int num_metadata, int num_sortkeys,
117 const char *service_id)
119 struct conf_service * service = 0;
120 NMEM nmem = nmem_create();
123 service = nmem_malloc(nmem, sizeof(struct conf_service));
125 service->ref_count = 1;
126 service->nmem = nmem;
128 service->databases = 0;
129 service->xslt_list = 0;
130 service->ccl_bibset = 0;
131 service->server = server;
132 service->session_timeout = 60; /* default session timeout */
133 service->z3950_session_timeout = 180;
134 service->z3950_operation_timeout = 30;
135 service->rank_cluster = 1;
137 service->charsets = 0;
139 service->id = service_id ? nmem_strdup(nmem, service_id) : 0;
140 // Setup a dictionary from server.
141 service->dictionary = 0;
143 service->settings = nmem_malloc(nmem, sizeof(*service->settings));
144 service->settings->num_settings = PZ_MAX_EOF;
145 service->settings->settings = nmem_malloc(nmem, sizeof(struct setting*) * service->settings->num_settings);
146 memset(service->settings->settings, 0, sizeof(struct setting*) * service->settings->num_settings);
147 // inherit_server_settings_values(service);
151 service->num_metadata = num_metadata;
153 service->metadata = 0;
154 if (service->num_metadata)
157 sizeof(struct conf_metadata) * service->num_metadata);
158 service->num_sortkeys = num_sortkeys;
159 service->sortkeys = 0;
160 if (service->num_sortkeys)
163 sizeof(struct conf_sortkey) * service->num_sortkeys);
169 static struct conf_metadata* conf_service_add_metadata(
170 struct conf_service *service,
173 enum conf_metadata_type type,
174 enum conf_metadata_merge merge,
175 enum conf_setting_type setting,
180 enum conf_metadata_mergekey mt,
181 const char *facetrule,
185 struct conf_metadata * md = 0;
187 if (!service || !service->metadata || !service->num_metadata
188 || field_id < 0 || !(field_id < service->num_metadata))
191 md = service->metadata + field_id;
192 conf_metadata_assign(service->nmem, md, name, type, merge, setting,
193 brief, termlist, rank, sortkey_offset,
194 mt, facetrule, limitmap);
198 static struct conf_sortkey * conf_service_add_sortkey(
199 struct conf_service *service,
202 enum conf_sortkey_type type)
204 struct conf_sortkey * sk = 0;
206 if (!service || !service->sortkeys || !service->num_sortkeys
207 || field_id < 0 || !(field_id < service->num_sortkeys))
210 //sk = &((service->sortkeys)[field_id]);
211 sk = service->sortkeys + field_id;
212 conf_sortkey_assign(service->nmem, sk, name, type);
217 int conf_service_metadata_field_id(struct conf_service *service,
222 if (!service || !service->metadata || !service->num_metadata)
225 for (i = 0; i < service->num_metadata; i++)
226 if (!strcmp(name, (service->metadata[i]).name))
231 int conf_service_sortkey_field_id(struct conf_service *service,
236 if (!service || !service->sortkeys || !service->num_sortkeys)
239 for (i = 0; i < service->num_sortkeys; i++)
240 if (!strcmp(name, (service->sortkeys[i]).name))
245 static void conf_dir_path(struct conf_config *config, WRBUF w, const char *src)
247 if (config->confdir && wrbuf_len(config->confdir) > 0 &&
248 !yaz_is_abspath(src))
250 wrbuf_printf(w, "%s/%s", wrbuf_cstr(config->confdir), src);
256 void service_destroy(struct conf_service *service)
260 if (!pazpar2_decref(&service->ref_count, service->mutex))
262 service_xslt_destroy(service);
263 pp2_charset_fact_destroy(service->charsets);
264 ccl_qual_rm(&service->ccl_bibset);
265 yaz_mutex_destroy(&service->mutex);
266 nmem_destroy(service->nmem);
271 void service_incref(struct conf_service *service)
273 yaz_log(YLOG_LOG, "service_incref. p=%p cnt=%d", service,
275 pazpar2_incref(&service->ref_count, service->mutex);
278 static int parse_metadata(struct conf_service *service, xmlNode *n,
279 int *md_node, int *sk_node)
281 enum conf_metadata_type type = Metadata_type_generic;
282 enum conf_metadata_merge merge = Metadata_merge_no;
283 enum conf_setting_type setting = Metadata_setting_no;
284 enum conf_metadata_mergekey mergekey_type = Metadata_mergekey_no;
287 int sortkey_offset = 0;
288 xmlChar *xml_name = 0;
289 xmlChar *xml_brief = 0;
290 xmlChar *xml_sortkey = 0;
291 xmlChar *xml_merge = 0;
292 xmlChar *xml_type = 0;
293 xmlChar *xml_termlist = 0;
294 xmlChar *xml_rank = 0;
295 xmlChar *xml_setting = 0;
296 xmlChar *xml_mergekey = 0;
297 xmlChar *xml_limitmap = 0;
298 xmlChar *xml_icu_chain = 0;
300 struct _xmlAttr *attr;
301 for (attr = n->properties; attr; attr = attr->next)
303 if (!xmlStrcmp(attr->name, BAD_CAST "name") &&
304 attr->children && attr->children->type == XML_TEXT_NODE)
305 xml_name = attr->children->content;
306 else if (!xmlStrcmp(attr->name, BAD_CAST "brief") &&
307 attr->children && attr->children->type == XML_TEXT_NODE)
308 xml_brief = attr->children->content;
309 else if (!xmlStrcmp(attr->name, BAD_CAST "sortkey") &&
310 attr->children && attr->children->type == XML_TEXT_NODE)
311 xml_sortkey = attr->children->content;
312 else if (!xmlStrcmp(attr->name, BAD_CAST "merge") &&
313 attr->children && attr->children->type == XML_TEXT_NODE)
314 xml_merge = attr->children->content;
315 else if (!xmlStrcmp(attr->name, BAD_CAST "type") &&
316 attr->children && attr->children->type == XML_TEXT_NODE)
317 xml_type = attr->children->content;
318 else if (!xmlStrcmp(attr->name, BAD_CAST "termlist") &&
319 attr->children && attr->children->type == XML_TEXT_NODE)
320 xml_termlist = attr->children->content;
321 else if (!xmlStrcmp(attr->name, BAD_CAST "rank") &&
322 attr->children && attr->children->type == XML_TEXT_NODE)
323 xml_rank = attr->children->content;
324 else if (!xmlStrcmp(attr->name, BAD_CAST "setting") &&
325 attr->children && attr->children->type == XML_TEXT_NODE)
326 xml_setting = attr->children->content;
327 else if (!xmlStrcmp(attr->name, BAD_CAST "mergekey") &&
328 attr->children && attr->children->type == XML_TEXT_NODE)
329 xml_mergekey = attr->children->content;
330 else if (!xmlStrcmp(attr->name, BAD_CAST "facetrule") &&
331 attr->children && attr->children->type == XML_TEXT_NODE)
332 xml_icu_chain = attr->children->content;
333 else if (!xmlStrcmp(attr->name, BAD_CAST "limitmap") &&
334 attr->children && attr->children->type == XML_TEXT_NODE)
335 xml_limitmap = attr->children->content;
338 yaz_log(YLOG_FATAL, "Unknown metadata attribute '%s'", attr->name);
343 // now do the parsing logic
346 yaz_log(YLOG_FATAL, "Must specify name in metadata element");
351 if (!strcmp((const char *) xml_brief, "yes"))
353 else if (strcmp((const char *) xml_brief, "no"))
355 yaz_log(YLOG_FATAL, "metadata/brief must be yes or no");
362 if (!strcmp((const char *) xml_termlist, "yes"))
364 else if (strcmp((const char *) xml_termlist, "no"))
366 yaz_log(YLOG_FATAL, "metadata/termlist must be yes or no");
373 if (!strcmp((const char *) xml_type, "generic"))
374 type = Metadata_type_generic;
375 else if (!strcmp((const char *) xml_type, "year"))
376 type = Metadata_type_year;
377 else if (!strcmp((const char *) xml_type, "date"))
378 type = Metadata_type_date;
382 "Unknown value for metadata/type: %s", xml_type);
389 if (!strcmp((const char *) xml_merge, "no"))
390 merge = Metadata_merge_no;
391 else if (!strcmp((const char *) xml_merge, "unique"))
392 merge = Metadata_merge_unique;
393 else if (!strcmp((const char *) xml_merge, "longest"))
394 merge = Metadata_merge_longest;
395 else if (!strcmp((const char *) xml_merge, "range"))
396 merge = Metadata_merge_range;
397 else if (!strcmp((const char *) xml_merge, "all"))
398 merge = Metadata_merge_all;
402 "Unknown value for metadata/merge: %s", xml_merge);
409 if (!strcmp((const char *) xml_setting, "no"))
410 setting = Metadata_setting_no;
411 else if (!strcmp((const char *) xml_setting, "postproc"))
412 setting = Metadata_setting_postproc;
413 else if (!strcmp((const char *) xml_setting, "parameter"))
414 setting = Metadata_setting_parameter;
418 "Unknown value for medadata/setting: %s", xml_setting);
423 // add a sortkey if so specified
424 if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
426 enum conf_sortkey_type sk_type;
427 if (merge == Metadata_merge_no)
430 "Can't specify sortkey on a non-merged field");
433 if (!strcmp((const char *) xml_sortkey, "numeric"))
434 sk_type = Metadata_sortkey_numeric;
435 else if (!strcmp((const char *) xml_sortkey, "skiparticle"))
436 sk_type = Metadata_sortkey_skiparticle;
440 "Unknown sortkey in metadata element: %s",
444 sortkey_offset = *sk_node;
446 conf_service_add_sortkey(service, *sk_node,
447 (const char *) xml_name, sk_type);
455 if (!strcmp((const char *) xml_mergekey, "required"))
456 mergekey_type = Metadata_mergekey_required;
457 else if (!strcmp((const char *) xml_mergekey, "optional"))
458 mergekey_type = Metadata_mergekey_optional;
459 else if (!strcmp((const char *) xml_mergekey, "no"))
460 mergekey_type = Metadata_mergekey_no;
463 yaz_log(YLOG_FATAL, "Unknown value for mergekey: %s", xml_mergekey);
468 // metadata known, assign values
469 conf_service_add_metadata(service, *md_node,
470 (const char *) xml_name,
471 type, merge, setting,
473 (const char *) xml_rank, sortkey_offset,
475 (const char *) xml_icu_chain,
476 (const char *) xml_limitmap);
481 static struct conf_service *service_create_static(struct conf_server *server,
483 const char *service_id)
489 struct conf_service *service = 0;
490 int num_metadata = 0;
491 int num_sortkeys = 0;
492 int got_settings = 0;
494 // count num_metadata and num_sortkeys
495 for (n = node->children; n; n = n->next)
496 if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)
497 n->name, "metadata"))
499 xmlChar *sortkey = xmlGetProp(n, (xmlChar *) "sortkey");
501 if (sortkey && strcmp((const char *) sortkey, "no"))
506 service = service_init(server, num_metadata, num_sortkeys, service_id);
508 for (n = node->children; n; n = n->next)
510 if (n->type != XML_ELEMENT_NODE)
512 if (!strcmp((const char *) n->name, "timeout"))
514 xmlChar *src = xmlGetProp(n, (xmlChar *) "session");
517 service->session_timeout = atoi((const char *) src);
519 if (service->session_timeout < 9)
521 yaz_log(YLOG_FATAL, "session timeout out of range");
525 src = xmlGetProp(n, (xmlChar *) "z3950_operation");
528 service->z3950_operation_timeout = atoi((const char *) src);
530 if (service->z3950_session_timeout < 9)
532 yaz_log(YLOG_FATAL, "Z39.50 operation timeout out of range");
536 src = xmlGetProp(n, (xmlChar *) "z3950_session");
539 service->z3950_session_timeout = atoi((const char *) src);
541 if (service->z3950_session_timeout < 9)
543 yaz_log(YLOG_FATAL, "Z39.50 session timeout out of range");
548 else if (!strcmp((const char *) n->name, "ccldirective"))
552 if (!service->ccl_bibset)
553 service->ccl_bibset = ccl_qual_mk();
554 name = (char *) xmlGetProp(n, (xmlChar *) "name");
557 yaz_log(YLOG_FATAL, "ccldirective: missing @name");
560 value = (char *) xmlGetProp(n, (xmlChar *) "value");
564 yaz_log(YLOG_FATAL, "ccldirective: missing @value");
567 ccl_qual_add_special(service->ccl_bibset, name, value);
571 else if (!strcmp((const char *) n->name, "settings"))
573 else if (!strcmp((const char *) n->name, "icu_chain"))
575 if (!service->charsets)
576 service->charsets = pp2_charset_fact_create();
577 if (pp2_charset_fact_define(service->charsets, n, 0))
579 yaz_log(YLOG_FATAL, "ICU chain definition error");
583 else if (!strcmp((const char *) n->name, "relevance")
584 || !strcmp((const char *) n->name, "sort")
585 || !strcmp((const char *) n->name, "mergekey")
586 || !strcmp((const char *) n->name, "facet"))
589 if (!service->charsets)
590 service->charsets = pp2_charset_fact_create();
591 if (pp2_charset_fact_define(service->charsets,
592 n->children, (const char *) n->name))
594 yaz_log(YLOG_FATAL, "ICU chain definition error");
598 else if (!strcmp((const char *) n->name, (const char *) "metadata"))
600 if (parse_metadata(service, n, &md_node, &sk_node))
603 else if (!strcmp((const char *) n->name, (const char *) "xslt"))
605 if (service_xslt_config(service, n))
608 else if (!strcmp((const char *) n->name, (const char *) "set"))
610 xmlChar *name= xmlGetProp(n, (xmlChar *) "name");
611 xmlChar *value = xmlGetProp(n, (xmlChar *) "value");
612 if (service->dictionary && name && value) {
613 yaz_log(YLOG_DEBUG, "service set: %s=%s (Not implemented)", (char *) name, (char *) value);
614 //service_aply_setting(service, name, value);
617 else if (!strcmp((const char *) n->name, "rank"))
619 char *rank_cluster = (char *) xmlGetProp(n, (xmlChar *) "cluster");
621 if (rank_cluster && !strcmp(rank_cluster, "yes"))
622 service->rank_cluster = 1;
623 else if (rank_cluster && !strcmp(rank_cluster, "no"))
624 service->rank_cluster = 0;
627 yaz_log(YLOG_FATAL, "service: rank@cluster boolean");
630 xmlFree(rank_cluster);
634 yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
641 /* metadata has been read.. Consider now settings */
642 init_settings(service);
643 for (pass = 1; pass <= 2; pass++)
645 for (n = node->children; n; n = n->next)
647 if (n->type != XML_ELEMENT_NODE)
649 if (!strcmp((const char *) n->name, "settings"))
652 xmlChar *src = xmlGetProp(n, (xmlChar *) "src");
655 WRBUF w = wrbuf_alloc();
656 conf_dir_path(server->config, w, (const char *) src);
657 ret = settings_read_file(service, wrbuf_cstr(w), pass);
663 ret = settings_read_node(service, n, pass);
674 static int inherit_server_settings(struct conf_service *s)
677 struct conf_server *server = s->server;
678 if (!s->dictionary) /* service has no config settings ? */
680 if (server->settings_fname)
682 /* inherit settings from server */
684 if (settings_read_file(s, server->settings_fname, 1))
686 if (settings_read_file(s, server->settings_fname, 2))
691 yaz_log(YLOG_WARN, "server '%s' has no settings", s->id ? s->id : "unnamed");
696 /* use relevance/sort/mergekey/facet from server if not defined
697 for this service.. */
700 if (server->charsets)
702 s->charsets = server->charsets;
703 pp2_charset_fact_incref(s->charsets);
707 s->charsets = pp2_charset_fact_create();
713 struct conf_service *service_create(struct conf_server *server,
716 struct conf_service *service = service_create_static(server, node, 0);
719 inherit_server_settings(service);
720 assert(service->mutex == 0);
721 pazpar2_mutex_create(&service->mutex, "conf");
726 static struct conf_server *server_create(struct conf_config *config,
727 NMEM nmem, xmlNode *node)
730 struct conf_server *server = nmem_malloc(nmem, sizeof(struct conf_server));
731 xmlChar *server_id = xmlGetProp(node, (xmlChar *) "id");
735 server->proxy_host = 0;
736 server->proxy_port = 0;
739 server->config = config;
741 server->charsets = 0;
742 server->http_server = 0;
743 server->iochan_man = 0;
744 server->database_hosts = config->database_hosts;
745 server->settings_fname = 0;
749 server->server_id = nmem_strdup(nmem, (const char *)server_id);
753 server->server_id = 0;
754 for (n = node->children; n; n = n->next)
756 if (n->type != XML_ELEMENT_NODE)
758 if (!strcmp((const char *) n->name, "listen"))
760 xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
761 xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
763 server->port = atoi((const char *) port);
765 server->host = nmem_strdup(nmem, (const char *) host);
769 else if (!strcmp((const char *) n->name, "proxy"))
771 xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
772 xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
773 xmlChar *myurl = xmlGetProp(n, (xmlChar *) "myurl");
775 server->proxy_port = atoi((const char *) port);
777 server->proxy_host = nmem_strdup(nmem, (const char *) host);
779 server->myurl = nmem_strdup(nmem, (const char *) myurl);
784 else if (!strcmp((const char *) n->name, "settings"))
786 xmlChar *src = xmlGetProp(n, (xmlChar *) "src");
790 yaz_log(YLOG_FATAL, "Missing src attribute for settings");
793 if (server->settings_fname)
796 yaz_log(YLOG_FATAL, "Can't repeat 'settings'");
800 conf_dir_path(config, w, (const char *) src);
801 server->settings_fname = nmem_strdup(nmem, wrbuf_cstr(w));
805 else if (!strcmp((const char *) n->name, "icu_chain"))
807 if (!server->charsets)
808 server->charsets = pp2_charset_fact_create();
809 if (pp2_charset_fact_define(server->charsets, n, 0))
811 yaz_log(YLOG_FATAL, "ICU chain definition error");
815 else if (!strcmp((const char *) n->name, "relevance")
816 || !strcmp((const char *) n->name, "sort")
817 || !strcmp((const char *) n->name, "mergekey")
818 || !strcmp((const char *) n->name, "facet"))
820 if (!server->charsets)
821 server->charsets = pp2_charset_fact_create();
822 if (pp2_charset_fact_define(server->charsets,
823 n->children, (const char *) n->name))
825 yaz_log(YLOG_FATAL, "ICU chain definition error");
829 else if (!strcmp((const char *) n->name, "service"))
831 char *service_id = (char *)
832 xmlGetProp(n, (xmlChar *) "id");
834 struct conf_service **sp = &server->service;
835 for (; *sp; sp = &(*sp)->next)
836 if ((*sp)->id && service_id &&
837 0 == strcmp((*sp)->id, service_id))
839 yaz_log(YLOG_FATAL, "Duplicate service: %s", service_id);
842 else if (!(*sp)->id && !service_id)
844 yaz_log(YLOG_FATAL, "Duplicate unnamed service");
848 if (*sp) /* service already exist */
855 struct conf_service *s = service_create_static(server, n,
865 yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
871 struct conf_service *s;
872 for (s = server->service; s; s = s->next)
873 inherit_server_settings(s);
878 WRBUF conf_get_fname(struct conf_config *config, const char *fname)
880 WRBUF w = wrbuf_alloc();
882 conf_dir_path(config, w, fname);
886 struct conf_service *locate_service(struct conf_server *server,
887 const char *service_id)
889 struct conf_service *s = server->service;
890 for (; s; s = s->next)
891 if (s->id && service_id && 0 == strcmp(s->id, service_id))
893 else if (!s->id && !service_id)
900 void info_services(struct conf_server *server, WRBUF w)
902 struct conf_service *s = server->service;
903 wrbuf_puts(w, " <services>\n");
904 for (; s; s = s->next)
906 wrbuf_puts(w, " <service");
909 wrbuf_puts(w, " id=\"");
910 wrbuf_xmlputs(w, s->id);
917 wrbuf_puts(w, " </services>\n");
920 static int parse_config(struct conf_config *config, xmlNode *root)
924 for (n = root->children; n; n = n->next)
926 if (n->type != XML_ELEMENT_NODE)
928 if (!strcmp((const char *) n->name, "server"))
930 struct conf_server *tmp = server_create(config, config->nmem, n);
933 tmp->next = config->servers;
934 config->servers = tmp;
936 else if (!strcmp((const char *) n->name, "threads"))
938 xmlChar *number = xmlGetProp(n, (xmlChar *) "number");
941 config->no_threads = atoi((const char *) number);
945 else if (!strcmp((const char *) n->name, "targetprofiles"))
947 yaz_log(YLOG_FATAL, "targetprofiles unsupported here. Must be part of service");
953 yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
960 struct conf_config *config_create(const char *fname, int verbose)
962 xmlDoc *doc = xmlParseFile(fname);
966 NMEM nmem = nmem_create();
967 struct conf_config *config = nmem_malloc(nmem, sizeof(struct conf_config));
969 xmlSubstituteEntitiesDefault(1);
970 xmlLoadExtDtdDefaultValue = 1;
973 yaz_log(YLOG_FATAL, "Failed to read %s", fname);
980 config->no_threads = 0;
981 config->iochan_man = 0;
982 config->database_hosts = database_hosts_create();
984 config->confdir = wrbuf_alloc();
985 if ((p = strrchr(fname,
994 wrbuf_write(config->confdir, fname, len);
996 wrbuf_puts(config->confdir, "");
998 n = xmlDocGetRootElement(doc);
999 r = yaz_xml_include_simple(n, wrbuf_cstr(config->confdir));
1000 if (r == 0) /* OK */
1004 yaz_log(YLOG_LOG, "Configuration %s after include processing",
1006 #if LIBXML_VERSION >= 20600
1007 xmlDocFormatDump(yaz_log_file(), doc, 0);
1009 xmlDocDump(yaz_log_file(), doc);
1012 r = parse_config(config, n);
1018 config_destroy(config);
1024 void server_destroy(struct conf_server *server)
1026 struct conf_service *s = server->service;
1029 struct conf_service *s_next = s->next;
1033 pp2_charset_fact_destroy(server->charsets);
1034 yaz_log(YLOG_LOG, "server_destroy server=%p", server);
1035 http_server_destroy(server->http_server);
1038 void config_destroy(struct conf_config *config)
1042 struct conf_server *server = config->servers;
1043 iochan_man_destroy(&config->iochan_man);
1046 struct conf_server *s_next = server->next;
1047 server_destroy(server);
1049 database_hosts_destroy(&config->database_hosts);
1051 wrbuf_destroy(config->confdir);
1052 nmem_destroy(config->nmem);
1056 void config_stop_listeners(struct conf_config *conf)
1058 struct conf_server *ser;
1059 for (ser = conf->servers; ser; ser = ser->next)
1060 http_close_server(ser);
1063 void config_process_events(struct conf_config *conf)
1065 struct conf_server *ser;
1067 for (ser = conf->servers; ser; ser = ser->next)
1069 struct conf_service *s = ser->service;
1071 for (;s ; s = s->next)
1073 assert(s->mutex == 0);
1074 pazpar2_mutex_create(&s->mutex, "service");
1076 http_mutex_init(ser);
1078 iochan_man_events(conf->iochan_man);
1081 int config_start_listeners(struct conf_config *conf,
1082 const char *listener_override,
1083 const char *record_fname)
1085 struct conf_server *ser;
1087 conf->iochan_man = iochan_man_create(conf->no_threads);
1088 for (ser = conf->servers; ser; ser = ser->next)
1090 WRBUF w = wrbuf_alloc();
1093 ser->iochan_man = conf->iochan_man;
1094 if (listener_override)
1096 wrbuf_puts(w, listener_override);
1097 listener_override = 0; /* only first server is overriden */
1102 wrbuf_puts(w, ser->host);
1107 wrbuf_printf(w, "%d", ser->port);
1110 r = http_init(wrbuf_cstr(w), ser, record_fname);
1116 if (ser->proxy_host || ser->proxy_port)
1118 if (ser->proxy_host)
1119 wrbuf_puts(w, ser->proxy_host);
1120 if (ser->proxy_port)
1124 wrbuf_printf(w, "%d", ser->proxy_port);
1128 http_set_proxyaddr(wrbuf_cstr(w), ser);
1137 * c-file-style: "Stroustrup"
1138 * indent-tabs-mode: nil
1140 * vim: shiftwidth=4 tabstop=8 expandtab