X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;ds=sidebyside;f=src%2Fhttp_command.c;h=158bfaa94525008b83d1d6c5642ad2bc03c57001;hb=39a36357055b29eb41cfb1ef0cc82f2826d2df64;hp=447eb06026cc4cad6d9cdba17bdde79dd5994fb9;hpb=3ea2f6ca025f6888d3ef2af4fa1e342d84fe1725;p=pazpar2-moved-to-github.git diff --git a/src/http_command.c b/src/http_command.c index 447eb06..158bfaa 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.63 2007-10-02 10:11:56 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. @@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ /* - * $Id: http_command.c,v 1.63 2007-10-02 10:11:56 adam Exp $ + * $Id: http_command.c,v 1.65 2007-10-08 13:19:23 adam Exp $ */ #include @@ -513,10 +513,27 @@ static void show_raw_record_ok(void *data, const char *buf, size_t sz) http_send_response(c); } -void show_raw_reset(void *data, struct http_channel *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; - client_show_raw_reset(client); + client_show_raw_remove(client, data2); } static void cmd_record_ready(void *data); @@ -531,6 +548,7 @@ static void cmd_record(struct http_channel *c) 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; @@ -556,6 +574,10 @@ static void cmd_record(struct http_channel *c) 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++) ; @@ -566,22 +588,21 @@ static void cmd_record(struct http_channel *c) } 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, - show_raw_record_ok); + (binary ? + show_raw_record_ok_binary : + show_raw_record_ok), + &data2, + (binary ? 1 : 0)); if (ret == -1) { http_remove_observer(obs); - error(rs, PAZPAR2_RECORD_FAIL, "show already active"); - return; - } - else if (ret == -2) - { - http_remove_observer(obs); error(rs, PAZPAR2_NO_SESSION, 0); return; }