# ParaZ. Copyright (C) 2000-2004, Index Data ApS
# All rights reserved.
-# $Id: Makefile,v 1.2 2006-12-22 04:43:11 quinn Exp $
+# $Id: Makefile,v 1.3 2006-12-27 21:11:10 quinn Exp $
SHELL=/bin/sh
PROG=pazpar2
PROGO=pazpar2.o eventl.o util.o command.o http.o http_command.o termlists.o \
- reclists.o relevance.o
+ reclists.o relevance.o config.o
all: $(PROG)
command.o: command.c command.h util.h eventl.h pazpar2.h termlists.h \
relevance.h reclists.h
+config.o: config.c config.h
eventl.o: eventl.c eventl.h
http.o: http.c command.h util.h eventl.h pazpar2.h termlists.h \
relevance.h reclists.h http.h http_command.h
http_command.o: http_command.c command.h util.h eventl.h pazpar2.h \
termlists.h relevance.h reclists.h http.h http_command.h
pazpar2.o: pazpar2.c pazpar2.h termlists.h relevance.h reclists.h \
- eventl.h command.h http.h
+ eventl.h command.h http.h config.h
reclists.o: reclists.c pazpar2.h termlists.h relevance.h reclists.h \
eventl.h
relevance.o: relevance.c relevance.h pazpar2.h termlists.h eventl.h \
-/* $Id: config.c,v 1.1 2006-12-27 02:14:27 quinn Exp $ */
+/* $Id: config.c,v 1.2 2006-12-27 21:11:10 quinn Exp $ */
+
+#include <string.h>
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#include <yaz/yaz-util.h>
+#include <yaz/nmem.h>
+
+#define CONFIG_NOEXTERNS
+#include "config.h"
+
+static NMEM nmem = 0;
+
+struct conf_config *config = 0;
+
+static struct conf_service *parse_service(xmlNode *node)
+{
+ xmlNode *n;
+ struct conf_service *r = nmem_malloc(nmem, sizeof(struct conf_service));
+
+ r->termlists = 0;
+
+ for (n = node->children; n; n = n->next)
+ {
+ if (n->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp(n->name, "termlist"))
+ {
+ struct conf_termlist *tl = nmem_malloc(nmem, sizeof(struct conf_termlist));
+ xmlChar *name = xmlGetProp(n, "name");
+ if (!name)
+ {
+ yaz_log(YLOG_WARN, "Missing name attribute in termlist");
+ continue;
+ }
+ tl->name = nmem_strdup(nmem, name);
+ tl->next = r->termlists;
+ r->termlists = tl;
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+ return 0;
+ }
+ }
+ return r;
+}
+
+static struct conf_server *parse_server(xmlNode *node)
+{
+ xmlNode *n;
+ struct conf_server *r = nmem_malloc(nmem, sizeof(struct conf_server));
+
+ r->host = 0;
+ r->port = 0;
+ r->proxy_host = 0;
+ r->proxy_port = 0;
+ r->service = 0;
+ r->next = 0;
+
+ for (n = node->children; n; n = n->next)
+ {
+ if (n->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp(n->name, "listen"))
+ {
+ xmlChar *port = xmlGetProp(n, "port");
+ xmlChar *host = xmlGetProp(n, "host");
+ if (port)
+ r->port = atoi(port);
+ if (host)
+ r->host = nmem_strdup(nmem, host);
+ }
+ else if (!strcmp(n->name, "proxy"))
+ {
+ xmlChar *port = xmlGetProp(n, "port");
+ xmlChar *host = xmlGetProp(n, "host");
+ if (port)
+ r->proxy_port = atoi(port);
+ if (host)
+ r->proxy_host = nmem_strdup(nmem, host);
+ }
+ else if (!strcmp(n->name, "service"))
+ {
+ struct conf_service *s = parse_service(n);
+ if (!s)
+ return 0;
+ r->service = s;
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+ return 0;
+ }
+ }
+ 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->queryprofiles = 0;
+ r->retrievalprofiles = 0;
+
+ for (n = root->children; n; n = n->next)
+ {
+ if (n->type != XML_ELEMENT_NODE)
+ continue;
+ if (!strcmp(n->name, "server"))
+ {
+ struct conf_server *tmp = parse_server(n);
+ if (!tmp)
+ return 0;
+ tmp->next = r->servers;
+ r->servers = tmp;
+ }
+ else if (!strcmp(n->name, "queryprofile"))
+ {
+ }
+ else if (!strcmp(n->name, "retrievalprofile"))
+ {
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "Bad element: %s", n->name);
+ return 0;
+ }
+ }
+ return r;
+}
+
+int read_config(const char *fname)
+{
+ xmlDoc *doc = xmlReadFile(fname, NULL, 0);
+ if (!nmem)
+ nmem = nmem_create();
+ if (!doc)
+ {
+ yaz_log(YLOG_FATAL, "Failed to read %s", fname);
+ exit(1);
+ }
+ if ((config = parse_config(xmlDocGetRootElement(doc))))
+ return 1;
+ else
+ return 0;
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
#ifndef CONFIG_H
#define CONFIG_H
+struct conf_termlist
+{
+ char *name;
+ struct conf_termlist *next;
+};
+
+struct conf_service
+{
+ struct conf_termlist *termlists;
+};
+
+struct conf_server
+{
+ char *host;
+ int port;
+ char *proxy_host;
+ int proxy_port;
+ struct conf_service *service;
+ struct conf_server *next;
+};
+
+struct conf_queryprofile
+{
+};
+
+struct conf_retrievalprofile
+{
+};
+
+struct conf_config
+{
+ struct conf_server *servers;
+ struct conf_queryprofile *queryprofiles;
+ struct conf_retrievalprofile *retrievalprofiles;
+};
+
+#ifndef CONFIG_NOEXTERNS
+
+extern struct conf_config *config;
#endif
+
+int read_config(const char *fname);
+
+#endif
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
-/* $Id: pazpar2.c,v 1.5 2006-12-22 04:43:11 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.6 2006-12-27 21:11:10 quinn Exp $ */;
#include <stdlib.h>
#include <stdio.h>
#include "termlists.h"
#include "reclists.h"
#include "relevance.h"
+#include "config.h"
#define PAZPAR2_VERSION "0.1"
#define MAX_CHUNK 15
yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
- while ((ret = options("x:c:h:p:C:s:", argv, argc, &arg)) != -2)
+ while ((ret = options("f:x:c:h:p:C:s:", argv, argc, &arg)) != -2)
{
switch (ret) {
+ case 'f':
+ if (!read_config(arg))
+ exit(1);
+ break;
case 'c':
command_init(atoi(arg));
setport++;
break;
default:
fprintf(stderr, "Usage: pazpar2\n"
+ " -f configfile\n"
" -h [host:]port (REST protocol listener)\n"
" -c cmdport (telnet-style)\n"
" -C cclconfig\n"