core: Fully implement the inquire callback for assuan_transact
* src/engine-assuan.c (inquire_cb): Implement returning data. * tests/opassuan/t-command.c (inq_cb): Send some test data. -- The old code only allowed to send an empty response which was good enough for scdaemon's KNOWNCARDP inquire but not to send actual data. A quick test using a test smartcard might be ./t-command 'scd setattr --inquire PRIVATE-DO-1' and then reading the data back using gpg-connect-agent 'scd getattr PRIVATE-DO-1' /bye Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
973c8116c8
commit
e4ee706e27
@ -445,7 +445,10 @@ llass_set_locale (void *engine, int category, const char *value)
|
||||
static gpgme_error_t
|
||||
inquire_cb (engine_llass_t llass, const char *keyword, const char *args)
|
||||
{
|
||||
gpg_error_t err;
|
||||
gpg_error_t err, err2;
|
||||
gpgme_data_t data = NULL;
|
||||
char buf[1024];
|
||||
gpgme_ssize_t n;
|
||||
|
||||
if (llass->opt.gpg_agent && !strcmp (keyword, "PINENTRY_LAUNCHED"))
|
||||
{
|
||||
@ -454,17 +457,23 @@ inquire_cb (engine_llass_t llass, const char *keyword, const char *args)
|
||||
|
||||
if (llass->user.inq_cb)
|
||||
{
|
||||
gpgme_data_t data = NULL;
|
||||
|
||||
err = llass->user.inq_cb (llass->user.inq_cb_value,
|
||||
keyword, args, &data);
|
||||
if (!err && data)
|
||||
{
|
||||
/* FIXME: Returning data is not yet implemented. However we
|
||||
need to allow the caller to cleanup his data object.
|
||||
Thus we run the callback in finish mode immediately. */
|
||||
err = llass->user.inq_cb (llass->user.inq_cb_value,
|
||||
while ((n = gpgme_data_read (data, buf, sizeof buf)) > 0)
|
||||
{
|
||||
err = assuan_send_data (llass->assuan_ctx, buf, n);
|
||||
if (err)
|
||||
break;
|
||||
}
|
||||
/* Tell the caller that we are finished with the data
|
||||
* object. The error code from assuan_send_data has
|
||||
* priority over the one from the cleanup function. */
|
||||
err2 = llass->user.inq_cb (llass->user.inq_cb_value,
|
||||
NULL, NULL, &data);
|
||||
if (!err)
|
||||
err = err2;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -70,8 +70,9 @@ inq_cb (void *opaque, const char *name, const char *args,
|
||||
/* There shall be no data object. */
|
||||
assert (!*r_data);
|
||||
|
||||
err = gpgme_data_new (&data);
|
||||
err = gpgme_data_new_from_mem (&data, "Foo bar\nbaz\n", 10, 0);
|
||||
fail_if_err (err);
|
||||
|
||||
*r_data = data;
|
||||
printf (" sending data object %p\n", data);
|
||||
}
|
||||
@ -142,4 +143,3 @@ main (int argc, char **argv)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user