+Added support for retrieval of records in binary.
+
--- 1.0.4 2007/09/28
JavaScript library pzw2.js throws error if WS response (from Pazpar2 or
<!ENTITY % idcommon SYSTEM "common/common.ent">
%idcommon;
]>
-<!-- $Id: pazpar2_protocol.xml,v 1.15 2007-09-20 08:13:26 adam Exp $ -->
+<!-- $Id: pazpar2_protocol.xml,v 1.16 2007-10-08 13:19:22 adam Exp $ -->
<refentry id="pazpar2_protocol">
<refentryinfo>
<productname>Pazpar2</productname>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>binary</term>
+ <listitem>
+ <para>
+ This optional parameter enables "binary" response for retrieval
+ of a raw record (i.e. when offset is specified). For binary
+ responses the record is <emphasis>not</emphasis> converted to
+ XML and the HTTP content type is application/octet-stream.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</para>
<para>
-/* $Id: client.c,v 1.28 2007-10-02 12:11:14 adam Exp $
+/* $Id: client.c,v 1.29 2007-10-08 13:19:23 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
struct show_raw {
int active; // whether this request has been sent to the server
int position;
+ int binary;
char *syntax;
char *esn;
void (*error_handler)(void *data, const char *addinfo);
void (*error_handler)(void *data, const char *addinfo),
void (*record_handler)(void *data, const char *buf,
size_t sz),
- void **data2)
+ void **data2,
+ int binary)
{
struct show_raw *rr, **rrp;
if (!cl->connection)
rr->data = data;
rr->error_handler = error_handler;
rr->record_handler = record_handler;
+ rr->binary = binary;
if (syntax)
rr->syntax = xstrdup(syntax);
else
return;
}
+ if (cl->show_raw && cl->show_raw->binary)
+ {
+ Z_External *rec = npr->u.databaseRecord;
+ if (rec->which == Z_External_octet)
+ {
+ cl->show_raw->record_handler(cl->show_raw->data,
+ (const char *)
+ rec->u.octet_aligned->buf,
+ rec->u.octet_aligned->len);
+ client_show_raw_dequeue(cl);
+ }
+ else
+ client_show_raw_error(cl, "no records");
+ }
+
doc = record_to_xml(client_get_database(cl), npr->u.databaseRecord);
if (!doc)
{
-/* $Id: client.h,v 1.5 2007-10-02 12:11:14 adam Exp $
+/* $Id: client.h,v 1.6 2007-10-08 13:19:23 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
void (*error_handler)(void *data, const char *addinfo),
void (*record_handler)(void *data, const char *buf,
size_t sz),
- void **data2);
+ void **data2,
+ int binary);
void client_show_raw_remove(struct client *cl, void *rr);
const char *client_get_state_str(struct client *cl);
-/* $Id: http.c,v 1.41 2007-10-02 12:11:14 adam Exp $
+/* $Id: http.c,v 1.42 2007-10-08 13:19:23 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
r->channel = c;
r->headers = 0;
r->payload = 0;
+ r->content_type = "text/xml";
return r;
}
{
wrbuf_printf(c->wrbuf, "Content-Length: %d\r\n", r->payload ?
(int) strlen(r->payload) : 0);
- wrbuf_printf(c->wrbuf, "Content-Type: text/xml\r\n");
- if (1)
+ wrbuf_printf(c->wrbuf, "Content-Type: %s\r\n", r->content_type);
+ if (!strcmp(r->content_type, "text/xml"))
{
xmlDoc *doc = xmlParseMemory(r->payload, strlen(r->payload));
if (doc)
-/* $Id: http.h,v 1.12 2007-10-02 12:11:14 adam Exp $
+/* $Id: http.h,v 1.13 2007-10-08 13:19:23 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
struct http_channel *channel;
struct http_header *headers;
char *payload;
+ char *content_type;
};
void http_set_proxyaddr(char *url, char *baseurl);
-/* $Id: http_command.c,v 1.64 2007-10-02 12:11:14 adam Exp $
+/* $Id: http_command.c,v 1.65 2007-10-08 13:19:23 adam Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
*/
/*
- * $Id: http_command.c,v 1.64 2007-10-02 12:11:14 adam Exp $
+ * $Id: http_command.c,v 1.65 2007-10-08 13:19:23 adam Exp $
*/
#include <stdio.h>
http_send_response(c);
}
+
+static void show_raw_record_ok_binary(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));
+
+ rs->content_type = "application/octet-stream";
+ http_send_response(c);
+}
+
+
void show_raw_reset(void *data, struct http_channel *c, void *data2)
{
struct client *client = data;
struct conf_service *service = global_parameters.server->service;
const char *idstr = http_argbyname(rq, "id");
const char *offsetstr = http_argbyname(rq, "offset");
+ const char *binarystr = http_argbyname(rq, "binary");
if (!s)
return;
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++)
;
client_show_raw_begin(r->client, r->position, syntax, esn,
obs /* data */,
show_raw_record_error,
- show_raw_record_ok,
- &data2);
+ (binary ?
+ show_raw_record_ok_binary :
+ show_raw_record_ok),
+ &data2,
+ (binary ? 1 : 0));
if (ret == -1)
{
http_remove_observer(obs);
--- /dev/null
+00362nam 22001698a 4504001001300000003000400013005001700017008004100034010001300075040001300088050001200101100001700113245003000130260001200160263000900172300001100181\1e 11224467 \1eDLC\1e00000000000000.0\1e910710c19910701nju 00010 eng \1e \1fa11224467\1e \1faDLC\1fcDLC\1e00\1fa123-xyz\1e10\1faJack Collins\1e10\1faHow to program a computer\1e1 \1faPenguin\1e \1fa8710\1e \1fap. cm.\1e\1d
\ No newline at end of file
http://localhost:9763/search.pz2?session=2&command=bytarget
http://localhost:9763/search.pz2?session=1&command=search&query=computer
http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+program+a+computer+author+jack+collins+medium+book
+http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+program+a+computer+author+jack+collins+medium+book&offset=0&binary=1