From 71b5ea2d586c9a8fdc6979dfd0a51205369f7988 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 18 Apr 2009 20:25:55 -0400 Subject: [PATCH] The XFER status message is sent with the LIST, DUMP and XPATH command along with GET. --- doc/COMMANDS | 6 ++++++ src/commands.c | 60 +++++++++++++++++++++++++++++++--------------------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/doc/COMMANDS b/doc/COMMANDS index 634f61a1..a42a6af9 100644 --- a/doc/COMMANDS +++ b/doc/COMMANDS @@ -243,6 +243,12 @@ on configuration settings: GET XFER + LIST XFER + + DUMP XFER + + XPATH XFER + CLEARCACHE CACHE CACHETIMEOUT CACHE diff --git a/src/commands.c b/src/commands.c index 544a271f..14c5ecbb 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1436,14 +1436,39 @@ static int store_command(assuan_context_t ctx, char *line) return 0; } +static gpg_error_t xfer_data(assuan_context_t ctx, const gchar *line, + gint total) +{ + int to_send; + int sent = 0; + gpg_error_t rc; + + if (total < ASSUAN_LINELENGTH) + to_send = total; + else + to_send = ASSUAN_LINELENGTH; + + do { + if (sent + to_send > total) + to_send = total - sent; + + rc = assuan_send_data(ctx, line+sent, to_send); + + if (!rc) { + sent += to_send; + rc = send_status(ctx, STATUS_XFER, "%li %li", sent, total); + } + } while (!rc && sent < total); + + return rc; +} + static int get_command(assuan_context_t ctx, char *line) { struct client_s *client = assuan_get_pointer(ctx); gchar **req; gpg_error_t rc; xmlNodePtr n; - gint sent = 0, to_send; - gint total; rc = file_modified(client); @@ -1481,27 +1506,7 @@ static int get_command(assuan_context_t ctx, char *line) return send_error(ctx, EPWMD_EMPTY_ELEMENT); pth_cancel_point(); - - total = xmlStrlen(n->content); - - if (total < ASSUAN_LINELENGTH) - to_send = total; - else - to_send = ASSUAN_LINELENGTH; - - do { - if (sent + to_send > total) - to_send = total - sent; - - rc = assuan_send_data(ctx, n->content+sent, to_send); - - if (!rc) { - sent += to_send; - rc = send_status(ctx, STATUS_XFER, "%li %li", sent, total); - } - } while (!rc && sent < total); - - pth_cancel_point(); + rc = xfer_data(ctx, (gchar *)n->content, xmlStrlen(n->content)); return send_error(ctx, rc); } @@ -1678,7 +1683,7 @@ static int list_command(assuan_context_t ctx, char *line) if (rc) return send_error(ctx, rc); - rc = assuan_send_data(ctx, str->str, str->len); + rc = xfer_data(ctx, str->str, str->len); list_command_cleanup1(str); return send_error(ctx, rc); } @@ -1719,7 +1724,7 @@ static int list_command(assuan_context_t ctx, char *line) g_string_append_printf(str, "%s%s", tmp, i+1 == total ? "" : "\n"); } - rc = assuan_send_data(ctx, str->str, str->len); + rc = xfer_data(ctx, str->str, str->len); list_command_cleanup1(str); } else @@ -2396,7 +2401,7 @@ static int dump_command(assuan_context_t ctx, char *line) return send_syserror(ctx, ENOMEM); } - rc = assuan_send_data(ctx, xml, len); + rc = xfer_data(ctx, (gchar *)xml, len); xmlFree(xml); return send_error(ctx, rc); } @@ -2523,9 +2528,8 @@ static int xpath_command(assuan_context_t ctx, gchar *line) goto fail; pth_cancel_point(); - rc = assuan_send_data(ctx, xmlBufferContent(xpath.buf), + rc = xfer_data(ctx, (gchar *)xmlBufferContent(xpath.buf), xmlBufferLength(xpath.buf)); - pth_cancel_point(); fail: xpath_command_cleanup(&xpath); -- 2.11.4.GIT