From f79610bdec951ba2241aade917c3228e4e4a33b8 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Wed, 9 Jan 2008 20:53:39 -0500 Subject: [PATCH] When the inquire callback function returns GPG_ERR_EOF and 'result' is not NULL, finish the inquire by first sending 'result' before returning. --- libpwmd.3.in | 11 +++++++++-- libpwmd.c | 20 +++++++++++++++----- libpwmd.h | 6 +++--- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/libpwmd.3.in b/libpwmd.3.in index 6eef84a4..87ed5f88 100644 --- a/libpwmd.3.in +++ b/libpwmd.3.in @@ -213,8 +213,15 @@ this to free your own allocated memory though. Commands which use an INQUIRE to send data (i.e., STORE) should use this function and not \fBpwmd_command\fP(). \fIcmd\fP is the command to send and is also the \fIkeyword\fP argument to the specified callback function \fIfunc\fP. -\fIdata\fP is user data passed to the callback function. Returnes 0 on success -or and error code which may have been returned from the callback function. +\fIdata\fP is user data passed to the callback function. Returns 0 on success +or an error code which may have been returned from the callback function. +.RS +.P +The callback function should return \fBGPG_ERR_EOF\fP when there is no more +data to be sent or to finish sending \fIresult\fP, if not NULL, and end the +INQUIRE. Or return \fB0\fP if there is more data to be sent, or an error code +to terminate the INQUIRE. +.RE .P .TP .BI "gpg_error_t pwmd_save(pwm_t *" pwm ");" diff --git a/libpwmd.c b/libpwmd.c index 706bad6e..5a074e08 100644 --- a/libpwmd.c +++ b/libpwmd.c @@ -218,18 +218,28 @@ static int _inquire_cb(void *data, const char *keyword) for (;;) { char *result = NULL; size_t len; + gpg_error_t arc; rc = pwm->inquire_func(pwm->inquire_data, keyword, rc, &result, &len); rc = gpg_err_code(rc); - if (rc == GPG_ERR_EOF) { - rc = 0; - break; + if (rc == GPG_ERR_EOF || !rc) { + if (len <= 0 || !result || !*result) { + rc = 0; + break; + } + + arc = assuan_send_data(pwm->ctx, result, len); + + if (rc == GPG_ERR_EOF) { + rc = arc; + break; + } + + rc = arc; } else if (rc) break; - - rc = assuan_send_data(pwm->ctx, result, len); } return rc; diff --git a/libpwmd.h b/libpwmd.h index 88f781d5..e881146c 100644 --- a/libpwmd.h +++ b/libpwmd.h @@ -77,9 +77,9 @@ typedef int (*pwmd_status_fn)(void *data, const char *line); * 'result' should be set to the data to be sent which is of 'len' bytes. The * data is not modified. * - * The function should return GPG_ERR_EOF when no more data needs to be sent, - * 0 if there is more data pending or an error code which will terminate the - * INQUIRE. + * The function should return GPG_ERR_EOF when no more data needs to be sent + * or to finish sending the set 'result' and end the INQUIRE, 0 if there is + * more data pending or an error code which will terminate the INQUIRE. */ typedef gpg_error_t (*pwmd_inquire_fn)(void *data, const char *keyword, gpg_error_t rc, char **result, size_t *len); -- 2.11.4.GIT