-/* $Id: http_command.c,v 1.51 2007-06-13 08:04:03 adam Exp $
+/* $Id: http_command.c,v 1.54 2007-06-15 19:35:17 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
*/
/*
- * $Id: http_command.c,v 1.51 2007-06-13 08:04:03 adam Exp $
+ * $Id: http_command.c,v 1.54 2007-06-15 19:35:17 adam Exp $
*/
#include <stdio.h>
*p = (*p)->next;
break;
}
+ yaz_log(YLOG_LOG, "Destroying session %u", s->session_id);
iochan_destroy(s->timeout_iochan);
destroy_session(s->psession);
nmem_destroy(s->nmem);
{ PAZPAR2_RECORD_MISSING, "Record missing"},
{ PAZPAR2_NO_TARGETS, "No targets"},
{ PAZPAR2_CONFIG_TARGET, "Target cannot be configured"},
+ { PAZPAR2_RECORD_FAIL, "Record command failed"},
+ { PAZPAR2_NOT_IMPLEMENTED, "Not implemented"},
+ { PAZPAR2_LAST_ERROR, "Last error"},
{ 0, 0 }
};
int i = 0;
wrbuf_puts(w, "</location>\n");
}
+static void show_raw_record_error(void *data, const char *addinfo)
+{
+ http_channel_observer_t obs = data;
+ struct http_channel *c = http_channel_observer_chan(obs);
+ struct http_response *rs = c->response;
+
+ http_remove_observer(obs);
+
+ error(rs, PAZPAR2_NOT_IMPLEMENTED, addinfo);
+}
+
+static void show_raw_record_ok(void *data, const char *buf, size_t sz)
+{
+ http_channel_observer_t obs = data;
+ struct http_channel *c = http_channel_observer_chan(obs);
+ struct http_response *rs = c->response;
+
+ http_remove_observer(obs);
+
+ wrbuf_write(c->wrbuf, buf, sz);
+ rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
+ http_send_response(c);
+}
+
+void show_raw_reset(void *data, struct http_channel *c)
+{
+ struct client *client = data;
+ client_show_raw_reset(client);
+}
+
static void cmd_record(struct http_channel *c)
{
struct http_response *rs = c->response;
struct record_cluster *rec;
struct record *r;
struct conf_service *service = global_parameters.server->service;
- char *idstr = http_argbyname(rq, "id");
+ const char *idstr = http_argbyname(rq, "id");
+ const char *offsetstr = http_argbyname(rq, "offset");
+
int id;
if (!s)
error(rs, PAZPAR2_RECORD_MISSING, idstr);
return;
}
- wrbuf_puts(c->wrbuf, "<record>\n");
- wrbuf_printf(c->wrbuf, "<recid>%d</recid>\n", rec->recid);
- write_metadata(c->wrbuf, service, rec->metadata, 1);
- for (r = rec->records; r; r = r->next)
- write_subrecord(r, c->wrbuf, service, 1);
- wrbuf_puts(c->wrbuf, "</record>\n");
- rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
- http_send_response(c);
+ if (offsetstr)
+ {
+ int offset = atoi(offsetstr);
+ const char *syntax = http_argbyname(rq, "syntax");
+ const char *esn = http_argbyname(rq, "esn");
+ int i;
+ struct record*r = rec->records;
+
+ for (i = 0; i < offset && r; r = r->next, i++)
+ ;
+ if (!r)
+ {
+ error(rs, PAZPAR2_RECORD_FAIL, "no record at offset given");
+ return;
+ }
+ else
+ {
+ http_channel_observer_t obs =
+ http_add_observer(c, r->client, show_raw_reset);
+ if (client_show_raw_begin(r->client, r->position, syntax, esn,
+ obs /* data */,
+ show_raw_record_error,
+ show_raw_record_ok))
+ {
+ http_remove_observer(obs);
+ error(rs, PAZPAR2_RECORD_FAIL, "invalid parameters");
+ return;
+ }
+ }
+ }
+ else
+ {
+ wrbuf_puts(c->wrbuf, "<record>\n");
+ wrbuf_printf(c->wrbuf, "<recid>%d</recid>\n", rec->recid);
+ write_metadata(c->wrbuf, service, rec->metadata, 1);
+ for (r = rec->records; r; r = r->next)
+ write_subrecord(r, c->wrbuf, service, 1);
+ wrbuf_puts(c->wrbuf, "</record>\n");
+ rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
+ http_send_response(c);
+ }
}
static void show_records(struct http_channel *c, int active)
{
if (status && (!s->psession->reclist || !s->psession->reclist->num_records))
{
- session_set_watch(s->psession, SESSION_WATCH_RECORDS, show_records_ready, c);
- yaz_log(YLOG_DEBUG, "Blocking on cmd_show");
- return;
+ // if there is already a watch/block. we do not block this one
+ if (session_set_watch(s->psession,
+ SESSION_WATCH_RECORDS,
+ show_records_ready, c, c) == 0)
+ {
+ yaz_log(YLOG_DEBUG, "Blocking on cmd_show");
+ return;
+ }
}
}