-/* $Id: config.c,v 1.30 2007-04-23 12:33:00 marc Exp $
+/* $Id: config.c,v 1.37 2007-06-19 10:15:44 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: config.c,v 1.30 2007-04-23 12:33:00 marc Exp $ */
+/* $Id: config.c,v 1.37 2007-06-19 10:15:44 adam Exp $ */
#include <string.h>
#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] = ".";
return 0;
metadata->name = nmem_strdup(nmem, name);
- metadata->type = type;
- metadata->merge = merge;
+
+ // enforcing that merge_range is always type_year
+ if (merge == Metadata_merge_range)
+ metadata->type = Metadata_type_year;
+ else
+ 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->brief = brief;
metadata->termlist = termlist;
metadata->rank = rank;
metadata->sortkey_offset = sortkey_offset;
-
return metadata;
}
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 position,
+ int field_id,
const char *name,
enum conf_metadata_type type,
enum conf_metadata_merge merge,
struct conf_metadata * md = 0;
if (!service || !service->metadata || !service->num_metadata
- || position < 0 || !(position < service->num_metadata))
+ || field_id < 0 || !(field_id < service->num_metadata))
return 0;
- //md = &((service->metadata)[position]);
- md = service->metadata + position;
+ //md = &((service->metadata)[field_id]);
+ md = service->metadata + field_id;
md = conf_metadata_assign(nmem, md, name, type, merge,
brief, termlist, rank, sortkey_offset);
return md;
struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
struct conf_service *service,
- int position,
+ int field_id,
const char *name,
enum conf_sortkey_type type)
{
struct conf_sortkey * sk = 0;
if (!service || !service->sortkeys || !service->num_sortkeys
- || position < 0 || !(position < service->num_sortkeys))
+ || field_id < 0 || !(field_id < service->num_sortkeys))
return 0;
- //sk = &((service->sortkeys)[position]);
- sk = service->sortkeys + position;
+ //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 conf_service_metadata_field_id(struct conf_service *service,
+ const char * name)
{
int i = 0;
};
-int conf_service_sortkey_field_id(struct conf_service *service, const char * name)
+int conf_service_sortkey_field_id(struct conf_service *service,
+ const char * name)
{
int i = 0;
type = Metadata_type_year;
else
{
- yaz_log(YLOG_FATAL, "Unknown value for metadata/type: %s", xml_type);
+ yaz_log(YLOG_FATAL,
+ "Unknown value for metadata/type: %s", xml_type);
return 0;
}
}
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->myurl = 0;
- r->zproxy_host = 0;
- r->zproxy_port = 0;
- r->service = 0;
- r->next = 0;
- r->settings = 0;
+ 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->zproxy_host = 0;
+ //server->zproxy_port = 0;
+ server->service = 0;
+ server->next = 0;
+ server->settings = 0;
+
+#ifdef HAVE_ICU
+ server->icu_chn = 0;
+#endif // HAVE_ICU
+
for (n = node->children; n; n = n->next)
{
xmlChar *port = xmlGetProp(n, (xmlChar *) "port");
xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
if (port)
- r->port = atoi((const char *) port);
+ server->port = atoi((const char *) port);
if (host)
- r->host = nmem_strdup(nmem, (const char *) host);
+ server->host = nmem_strdup(nmem, (const char *) host);
xmlFree(port);
xmlFree(host);
}
xmlChar *host = xmlGetProp(n, (xmlChar *) "host");
xmlChar *myurl = xmlGetProp(n, (xmlChar *) "myurl");
if (port)
- r->proxy_port = atoi((const char *) port);
+ server->proxy_port = atoi((const char *) port);
if (host)
- r->proxy_host = nmem_strdup(nmem, (const char *) host);
+ server->proxy_host = nmem_strdup(nmem, (const char *) host);
if (myurl)
- r->myurl = nmem_strdup(nmem, (const char *) myurl);
+ server->myurl = nmem_strdup(nmem, (const char *) myurl);
#ifdef GAGA
else
{
xmlFree(host);
xmlFree(myurl);
}
- else if (!strcmp((const char *) n->name, "zproxy"))
- {
- xmlChar *port = 0;
- xmlChar *host = 0;
-
- port = xmlGetProp(n, (xmlChar *) "port");
- host = xmlGetProp(n, (xmlChar *) "host");
-
- if (port)
- r->zproxy_port = atoi((const char *) port);
- if (host)
- r->zproxy_host = nmem_strdup(nmem, (const char *) host);
-
- xmlFree(port);
- xmlFree(host);
- }
else if (!strcmp((const char *) n->name, "settings"))
{
- if (r->settings)
+ if (server->settings)
{
yaz_log(YLOG_FATAL, "Can't repeat 'settings'");
return 0;
}
- if (!(r->settings = parse_settings(n)))
+ if (!(server->settings = parse_settings(n)))
+ return 0;
+ }
+ else if (!strcmp((const char *) n->name, "icu_chain"))
+ {
+#ifdef HAVE_ICU
+ UErrorCode status = U_ZERO_ERROR;
+ struct icu_chain *chain = icu_chain_xml_config(n, &status);
+ if (!chain || U_FAILURE(status)){
+ //xmlDocPtr icu_doc = 0;
+ //xmlChar *xmlstr = 0;
+ //int size = 0;
+ //xmlDocDumpMemory(icu_doc, size);
+
+ yaz_log(YLOG_FATAL, "Could not parse ICU chain config:\n"
+ "<%s>\n ... \n</%s>",
+ n->name, n->name);
return 0;
+ }
+ server->icu_chn = chain;
+#else // HAVE_ICU
+ yaz_log(YLOG_FATAL, "Error: ICU support requested with element:\n"
+ "<%s>\n ... \n</%s>",
+ n->name, n->name);
+ yaz_log(YLOG_FATAL,
+ "But no ICU support compiled into pazpar2 server.");
+ yaz_log(YLOG_FATAL,
+ "Please install libicu36-dev and icu-doc or similar, "
+ "re-configure and re-compile");
+ return 0;
+#endif // HAVE_ICU
}
else if (!strcmp((const char *) n->name, "service"))
{
struct conf_service *s = parse_service(n);
if (!s)
return 0;
- r->service = s;
+ server->service = s;
}
else
{
return 0;
}
}
- return r;
+ return server;
}
xsltStylesheet *conf_load_stylesheet(const char *fname)
{
char path[256];
- sprintf(path, "%s/%s", confdir, fname);
+ if (*fname == '/')
+ yaz_snprintf(path, sizeof(path), fname);
+ else
+ yaz_snprintf(path, sizeof(path), "%s/%s", confdir, fname);
return xsltParseStylesheetFile((xmlChar *) path);
}
if ((p = strrchr(fname, '/')))
{
int len = p - fname;
+ if (len >= sizeof(confdir))
+ len = sizeof(confdir)-1;
strncpy(confdir, fname, len);
confdir[len] = '\0';
}