From dc9fddcb86754a71149d3eb8892a5da704a2cadd Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Tue, 26 Feb 2008 22:34:08 -0500 Subject: [PATCH] Added pwmd_pending_line(). This is a wrapper around assuan_pending_line() and assuan_read_line(). --- libpwmd.3.in | 9 +++++++++ libpwmd.c | 11 +++++++++++ libpwmd.h | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/libpwmd.3.in b/libpwmd.3.in index 0ea8f3df..a6525262 100644 --- a/libpwmd.3.in +++ b/libpwmd.3.in @@ -26,6 +26,7 @@ libpwmd \- pwmd client interface library .BI "gpg_error_t pwmd_init(void);" .BI "pwm_t *pwmd_connect(const char *" socket ", gpg_error_t *" error ");" .BI "gpg_error_t pwmd_assuan_ctx(pwm_t *" pwm ", assuan_context_t *" ctx ", int *" fd "); +.BI "gpg_error_t pwmd_pending_line(pwm_t *" pwm ", char **" line ", size_t *" len "); .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);" .BI "gpg_error_t pwmd_open(pwm_t *" pwm ", const char *" filename ");" .BI "int pwmd_open_nb(pwm_t *" pwm ", gpg_error_t *" error ", const char *" filename ", int " timeout ");" @@ -81,6 +82,14 @@ Sets \fIctx\fP to the assuan context associated with the handle \fIpwm\fP and code. .P .TP +.BI "gpg_error_t pwmd_pending_line(pwm_t *" pwm ", char **" line ", size_t *" len "); +This is a wrapper around \fBassuan_pending_line\fP() and +\fBassuan_read_line\fP(). Returns \fB0\fP and sets \fIline\fP to the content +and \fIlen\fP to the content length if there was a pending line. Or returns +\fBGPG_ERR_NO_DATA\fP if there was none or any error from +\fBassuan_read_line\fP(). +.P +.TP .BI "gpg_error_t pwmd_setopt(pwm_t *" pwm ", pwmd_option_t " opt ", ...);" Set the library option \fIopt\fP to the value of the next argument. Returns 0 on success or an error code. \fIopt\fP is one of the following: diff --git a/libpwmd.c b/libpwmd.c index 6bcbf7f1..64c50254 100644 --- a/libpwmd.c +++ b/libpwmd.c @@ -158,6 +158,17 @@ pwm_t *pwmd_connect(const char *path, gpg_error_t *error) return pwm; } +gpg_error_t pwmd_pending_line(pwm_t *pwm, char **line, size_t *len) +{ + if (!pwm) + return GPG_ERR_INV_ARG; + + if (assuan_pending_line(pwm->ctx)) + return assuan_read_line(pwm->ctx, line, len); + + return GPG_ERR_NO_DATA; +} + void pwmd_close(pwm_t *pwm) { if (!pwm) diff --git a/libpwmd.h b/libpwmd.h index b2f42de3..42f27274 100644 --- a/libpwmd.h +++ b/libpwmd.h @@ -220,6 +220,14 @@ typedef struct assuan_context_s *assuan_context_t; gpg_error_t pwmd_assuan_ctx(pwm_t *pwm, assuan_context_t *ctx, int *fd) __attribute__ ((warn_unused_result)); /* + * A wrapper around assuan_pending_line() and assuan_read_line(). Returns 0 if + * there was a pending line and sets 'line' to the content and 'len' to the + * length. Returns GPG_ERR_NO_DATA if there was no pending line or any error + * from assuan_read_line(). + */ +gpg_error_t pwmd_pending_line(pwm_t *pwm, char **line, size_t *len) __attribute__ ((warn_unused_result)); + +/* * Sets a libpwmd option 'opt'. The next argument should be of the data type * required for the option. Returns 0 on success or an error code. */ -- 2.11.4.GIT