-/* $Id: pazpar2.c,v 1.10 2006-12-04 03:31:24 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.17 2006-12-19 04:49:34 quinn Exp $ */;
#include <stdlib.h>
#include <stdio.h>
#include <yaz/readconf.h>
#include <yaz/pquery.h>
#include <yaz/yaz-util.h>
-#include <yaz/ccl.h>
-#include <yaz/yaz-ccl.h>
#include "pazpar2.h"
#include "eventl.h"
static void connection_destroy(struct connection *co);
static int client_prep_connection(struct client *cl);
static void ingest_records(struct client *cl, Z_Records *r);
+void session_alert_watch(struct session *s, int what);
-IOCHAN channel_list = 0; // Master list of connections we're listening to.
+IOCHAN channel_list = 0; // Master list of connections we're handling events to
static struct connection *connection_freelist = 0;
static struct client *client_freelist = 0;
"Client_Stopped"
};
-static struct parameters {
- int timeout; /* operations timeout, in seconds */
- char implementationId[128];
- char implementationName[128];
- char implementationVersion[128];
- int target_timeout; // seconds
- int toget;
- int chunk;
- CCL_bibset ccl_filter;
- yaz_marc_t yaz_marc;
- ODR odr_out;
- ODR odr_in;
-} global_parameters =
+struct parameters global_parameters =
{
30,
"81",
"Index Data PazPar2 (MasterKey)",
PAZPAR2_VERSION,
600, // 10 minutes
+ 60,
100,
MAX_CHUNK,
0,
}
}
wrbuf_putc(s->wrbuf, '\0');
- obuf = nmem_strdup(s->nmem, wrbuf_buf(s->wrbuf));
+ obuf = (unsigned char*) nmem_strdup(s->nmem, wrbuf_buf(s->wrbuf));
for (p = obuf; *p; p++)
if (*p == '&' || *p == '<' || *p > 122 || *p < ' ')
*p = ' ';
- return obuf;
+ return (char*) obuf;
}
// Extract 245 $a $b 100 $a
static void ingest_records(struct client *cl, Z_Records *r)
{
struct record *rec;
+ struct session *s = cl->session;
Z_NamePlusRecordList *rlist;
int i;
if (!rec)
continue;
}
+ if (s->watchlist[SESSION_WATCH_RECORDS].fun && rlist->num_records)
+ session_alert_watch(s, SESSION_WATCH_RECORDS);
}
static void do_presentResponse(IOCHAN i, Z_APDU *a)
if (cl)
se = cl->session;
+ else
+ {
+ yaz_log(YLOG_WARN, "Destroying orphan connection (fix me?)");
+ connection_destroy(co);
+ return;
+ }
if (co->state == Conn_Connecting && event & EVENT_OUTPUT)
{
if (len < 0)
{
- client_fatal(cl);
+ yaz_log(YLOG_WARN|YLOG_ERRNO, "Error reading from Z server");
+ connection_destroy(co);
return;
}
else if (len == 0)
{
- client_fatal(cl);
+ yaz_log(YLOG_WARN, "EOF reading from Z server");
+ connection_destroy(co);
return;
}
else if (len > 1) // We discard input if we have no connection
continue;
url = line + 7;
url[strlen(url) - 1] = '\0';
- yaz_log(LOG_DEBUG, "Target: %s", url);
+ yaz_log(YLOG_DEBUG, "Target: %s", url);
if ((db = strchr(url, '/')))
*(db++) = '\0';
else
cc->next = c->next;
}
if (c->connection)
- connection_destroy(c->connection);
+ connection_release(c->connection);
c->next = client_freelist;
client_freelist = c;
}
+void session_set_watch(struct session *s, int what, session_watchfun fun, void *data)
+{
+ s->watchlist[what].fun = fun;
+ s->watchlist[what].data = data;
+}
+
+void session_alert_watch(struct session *s, int what)
+{
+ if (!s->watchlist[what].fun)
+ return;
+ (*s->watchlist[what].fun)(s->watchlist[what].data);
+ s->watchlist[what].fun = 0;
+ s->watchlist[what].data = 0;
+}
+
// This should be extended with parameters to control selection criteria
// Associates a set of clients with a session;
int select_targets(struct session *se)
return 0;
}
+void destroy_session(struct session *s)
+{
+ yaz_log(YLOG_LOG, "Destroying session");
+ while (s->clients)
+ client_destroy(s->clients);
+ nmem_destroy(s->nmem);
+ wrbuf_free(s->wrbuf, 1);
+}
+
struct session *new_session()
{
+ int i;
struct session *session = xmalloc(sizeof(*session));
yaz_log(YLOG_DEBUG, "New pazpar2 session");
session->query[0] = '\0';
session->nmem = nmem_create();
session->wrbuf = wrbuf_alloc();
+ for (i = 0; i <= SESSION_WATCH_MAX; i++)
+ {
+ session->watchlist[i].data = 0;
+ session->watchlist[i].fun = 0;
+ }
select_targets(session);
return session;
}
-void session_destroy(struct session *s)
-{
- // FIXME do some shit here!!!!
-}
-
struct hitsbytarget *hitsbytarget(struct session *se, int *count)
{
static struct hitsbytarget res[1000]; // FIXME MM
if (signal(SIGPIPE, SIG_IGN) < 0)
yaz_log(YLOG_WARN|YLOG_ERRNO, "signal");
- yaz_log_init(YLOG_DEFAULT_LEVEL|YLOG_DEBUG, "pazpar2", 0);
+ yaz_log_init(YLOG_DEFAULT_LEVEL, "pazpar2", 0);
while ((ret = options("c:h:p:C:s:", argv, argc, &arg)) != -2)
{
setport++;
break;
case 'h':
- http_init(atoi(arg));
+ http_init(arg);
setport++;
break;
case 'C':
break;
default:
fprintf(stderr, "Usage: pazpar2\n"
- " -h httpport (REST)\n"
+ " -h [host:]port (REST protocol listener)\n"
" -c cmdport (telnet-style)\n"
" -C cclconfig\n"
" -s simpletargetfile\n"