-/* $Id: pazpar2.c,v 1.1 2006-12-20 20:47:16 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.6 2006-12-27 21:11:10 quinn Exp $ */;
#include <stdlib.h>
#include <stdio.h>
#include <yaz/readconf.h>
#include <yaz/pquery.h>
#include <yaz/yaz-util.h>
+#include <yaz/nmem.h>
#include "pazpar2.h"
#include "eventl.h"
#include "termlists.h"
#include "reclists.h"
#include "relevance.h"
+#include "config.h"
#define PAZPAR2_VERSION "0.1"
#define MAX_CHUNK 15
0,
0,
0,
+ 0,
0
};
zquery->u.type_1 = ccl_rpn_query(global_parameters.odr_out, cn);
ccl_rpn_delete(cn);
- for (ndb = 0; *db->databases[ndb]; ndb++)
+ for (ndb = 0; db->databases[ndb]; ndb++)
;
databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
- for (ndb = 0; *db->databases[ndb]; ndb++)
+ for (ndb = 0; db->databases[ndb]; ndb++)
databaselist[ndb] = db->databases[ndb];
a->u.presentRequest->preferredRecordSyntax =
session_alert_watch(s, SESSION_WATCH_RECORDS);
}
+xsltStylesheetPtr load_stylesheet(const char *fname)
+{
+ xsltStylesheetPtr ret;
+ if (!(ret = xsltParseStylesheetFile((const xmlChar *) fname)))
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "Failed to load stylesheet %s", fname);
+ exit(1);
+ }
+ return ret;
+}
+
static void do_presentResponse(IOCHAN i, Z_APDU *a)
{
struct connection *co = iochan_getdata(i);
se = cl->session;
else
{
- yaz_log(YLOG_WARN, "Destroying orphan connection (fix me?)");
+ yaz_log(YLOG_WARN, "Destroying orphan connection");
connection_destroy(co);
return;
}
if ((res = getaddrinfo(url, port, &hints, &addrinfo)))
{
yaz_log(YLOG_WARN, "Failed to resolve %s: %s", url, gai_strerror(res));
+ xfree(host->hostport);
+ xfree(host);
continue;
}
assert(addrinfo->ai_family == PF_INET);
strcpy(database->url, url);
strcat(database->url, "/");
strcat(database->url, db);
- strcpy(database->databases[0], db);
- *database->databases[1] = '\0';
+
+ database->databases = xmalloc(2 * sizeof(char *));
+ database->databases[0] = xstrdup(db);
+ database->databases[1] = 0;
database->errors = 0;
database->next = databases;
databases = database;
return termlist_highscore(s->termlist, num);
}
-struct record **show(struct session *s, int start, int *num, int *total, int *sumhits)
+#ifdef REPORT_NMEM
+// conditional compilation by SH: This lead to a warning with currently installed
+// YAZ header files on us1
+void report_nmem_stats(void)
{
- struct record **recs = nmem_malloc(s->nmem, *num * sizeof(struct record *));
+ size_t in_use, is_free;
+
+ nmem_get_memory_in_use(&in_use);
+ nmem_get_memory_free(&is_free);
+
+ yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld",
+ (long) in_use, (long) is_free);
+}
+#endif
+
+struct record **show(struct session *s, int start, int *num, int *total,
+ int *sumhits, NMEM nmem_show)
+{
+ struct record **recs = nmem_malloc(nmem_show, *num
+ * sizeof(struct record *));
int i;
relevance_prepare_read(s->relevance, s->reclist);
yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
- while ((ret = options("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++;
case 's':
load_simpletargets(arg);
break;
+ case 'x':
+ global_parameters.xsl = load_stylesheet(arg);
+ 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"
exit(1);
}
- global_parameters.ccl_filter = load_cclfile("default.bib");
+ if (!global_parameters.xsl)
+ global_parameters.xsl = load_stylesheet("../etc/default.xsl");
+ global_parameters.ccl_filter = load_cclfile("../etc/default.bib");
global_parameters.yaz_marc = yaz_marc_create();
yaz_marc_subfield_str(global_parameters.yaz_marc, "\t");
global_parameters.odr_in = odr_createmem(ODR_DECODE);