-/* $Id: logic.c,v 1.43 2007-06-13 21:29:04 adam Exp $
+/* $Id: logic.c,v 1.48 2007-07-04 12:07:49 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
#include <yaz/nmem.h>
#include <yaz/query-charset.h>
#include <yaz/querytowrbuf.h>
-#if YAZ_VERSIONL >= 0x020163
#include <yaz/oid_db.h>
-#endif
#if HAVE_CONFIG_H
#include "cconfig.h"
termlist_insert(s->termlists[i].termlist, value);
}
-xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
+xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec)
{
- struct database_retrievalmap *m;
struct database *db = sdb->database;
xmlDoc *rdoc = 0;
const Odr_oid *oid = rec->direct_reference;
xmlDocDump(stderr, rdoc);
#endif
}
+ return rdoc;
+}
- for (m = sdb->map; m; m = m->next){
- xmlDoc *new = 0;
-
- {
- xmlNodePtr root = 0;
- new = xsltApplyStylesheet(m->stylesheet, rdoc, 0);
- root= xmlDocGetRootElement(new);
- if (!new || !root || !(root->children))
- {
- yaz_log(YLOG_WARN, "XSLT transformation failed from %s",
- sdb->database->url);
- xmlFreeDoc(new);
+xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
+{
+ struct database_retrievalmap *m;
+ xmlDoc *rdoc = record_to_xml(sdb, rec);
+ if (rdoc)
+ {
+ for (m = sdb->map; m; m = m->next){
+ xmlDoc *new = 0;
+
+ {
+ xmlNodePtr root = 0;
+ new = xsltApplyStylesheet(m->stylesheet, rdoc, 0);
+ root= xmlDocGetRootElement(new);
+ if (!new || !root || !(root->children))
+ {
+ yaz_log(YLOG_WARN, "XSLT transformation failed from %s",
+ sdb->database->url);
+ xmlFreeDoc(new);
+ xmlFreeDoc(rdoc);
+ return 0;
+ }
+ }
+
xmlFreeDoc(rdoc);
- return 0;
+ rdoc = new;
}
- }
-
- xmlFreeDoc(rdoc);
- rdoc = new;
- }
- if (global_parameters.dump_records)
- {
- fprintf(stderr, "Record from %s\n----------------\n",
- sdb->database->url);
+ if (global_parameters.dump_records)
+ {
+ fprintf(stderr, "Record from %s\n----------------\n",
+ sdb->database->url);
#if LIBXML_VERSION >= 20600
- xmlDocFormatDump(stderr, rdoc, 1);
+ xmlDocFormatDump(stderr, rdoc, 1);
#else
- xmlDocDump(stderr, rdoc);
+ xmlDocDump(stderr, rdoc);
#endif
+ }
}
return rdoc;
}
(*m)->next = 0;
if (!((*m)->stylesheet = conf_load_stylesheet(stylesheets[i])))
{
- yaz_log(YLOG_FATAL, "Unable to load stylesheet: %s",
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "Unable to load stylesheet: %s",
stylesheets[i]);
return -1;
}
return 0;
}
+// called if watch should be removed because http_channel is to be destroyed
+static void session_watch_cancel(void *data, struct http_channel *c)
+{
+ struct session_watchentry *ent = data;
+
+ ent->fun = 0;
+ ent->data = 0;
+ ent->obs = 0;
+}
-void session_set_watch(struct session *s, int what,
- session_watchfun fun, void *data)
+// set watch. Returns 0=OK, -1 if watch is already set
+int session_set_watch(struct session *s, int what,
+ session_watchfun fun, void *data,
+ struct http_channel *chan)
{
+ if (s->watchlist[what].fun)
+ return -1;
s->watchlist[what].fun = fun;
s->watchlist[what].data = data;
+ s->watchlist[what].obs = http_add_observer(chan, &s->watchlist[what],
+ session_watch_cancel);
+ return 0;
}
void session_alert_watch(struct session *s, int what)
{
if (!s->watchlist[what].fun)
return;
+ http_remove_observer(s->watchlist[what].obs);
(*s->watchlist[what].fun)(s->watchlist[what].data);
s->watchlist[what].fun = 0;
s->watchlist[what].data = 0;
+ s->watchlist[what].obs = 0;
}
//callback for grep_databases
const char **addinfo)
{
int live_channels = 0;
+ int no_working = 0;
+ int no_failed = 0;
struct client *cl;
struct database_criterion *criteria;
*addinfo = client_get_database(cl)->database->url;
return PAZPAR2_CONFIG_TARGET;
}
- // Query must parse for all targets
+ // Parse query for target
if (client_parse_query(cl, query) < 0)
+ no_failed++;
+ else
{
- *addinfo = "query";
- return PAZPAR2_MALFORMED_PARAMETER_VALUE;
+ no_working++;
+ client_prep_connection(cl);
}
}
- for (cl = se->clients; cl; cl = client_next_in_session(cl))
- client_prep_connection(cl);
-
+ // If no queries could be mapped, we signal an error
+ if (no_working == 0)
+ {
+ *addinfo = "query";
+ return PAZPAR2_MALFORMED_PARAMETER_VALUE;
+ }
return PAZPAR2_NO_ERROR;
}
void session_init_databases(struct session *se)
{
se->databases = 0;
- grep_databases(se, 0, session_init_databases_fun);
+ predef_grep_databases(se, 0, session_init_databases_fun);
}
// Probably session_init_databases_fun should be refactored instead of
session->session_nmem = nmem;
session->nmem = nmem_create();
session->wrbuf = wrbuf_alloc();
- session_init_databases(session);
+ session->databases = 0;
for (i = 0; i <= SESSION_WATCH_MAX; i++)
{
session->watchlist[i].data = 0;