- wrbuf_puts(c->wrbuf, "<record>\n");
- wrbuf_printf(c->wrbuf, "<recid>%d</recid>", rec->recid);
- write_metadata(c->wrbuf, service, rec->metadata, 1);
- for (r = rec->records; r; r = r->next)
- write_subrecord(r, c->wrbuf, service);
- 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;
+ int binary = 0;
+
+ if (binarystr && *binarystr != '0')
+ binary = 1;
+
+ for (i = 0; i < offset && r; r = r->next, i++)
+ ;
+ if (!r)
+ {
+ error(rs, PAZPAR2_RECORD_FAIL, "no record at offset given");
+ return;
+ }
+ else
+ {
+ void *data2;
+ http_channel_observer_t obs =
+ http_add_observer(c, r->client, show_raw_reset);
+ int ret =
+ client_show_raw_begin(r->client, r->position, syntax, esn,
+ obs /* data */,
+ show_raw_record_error,
+ (binary ?
+ show_raw_record_ok_binary :
+ show_raw_record_ok),
+ &data2,
+ (binary ? 1 : 0));
+ if (ret == -1)
+ {
+ http_remove_observer(obs);
+ error(rs, PAZPAR2_NO_SESSION, 0);
+ return;
+ }
+ }
+ }
+ else
+ {
+ wrbuf_puts(c->wrbuf, "<record>\n");
+ wrbuf_puts(c->wrbuf, "<recid>");
+ wrbuf_xmlputs(c->wrbuf, rec->recid);
+ wrbuf_puts(c->wrbuf, "</recid>\n");
+ 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 cmd_record_ready(void *data)
+{
+ struct http_channel *c = (struct http_channel *) data;
+
+ cmd_record(c);