* common/membuf.c (put_membuf_cb): New.
* agent/call-scd.c (membuf_data_cb): Remove. Change callers to use
put_membuf_cb.
* common/get-passphrase.c (membuf_data_cb): Ditto.
* g10/call-agent.c (membuf_data_cb): Ditto.
* sm/call-agent.c (membuf_data_cb): Ditto.
--
Signed-off-by: Werner Koch <wk@gnupg.org>
/* Local prototypes. */
-static gpg_error_t membuf_data_cb (void *opaque,
- const void *buffer, size_t length);
socket_name = NULL;
init_membuf (&data, 256);
assuan_transact (ctx, "GETINFO socket_name",
- membuf_data_cb, &data, NULL, NULL, NULL, NULL);
+ put_membuf_cb, &data, NULL, NULL, NULL, NULL);
databuf = get_membuf (&data, &datalen);
if (databuf && datalen)
\f
-static gpg_error_t
-membuf_data_cb (void *opaque, const void *buffer, size_t length)
-{
- membuf_t *data = opaque;
-
- if (buffer)
- put_membuf (data, buffer, length);
- return 0;
-}
-
/* Handle the NEEDPIN inquiry. */
static gpg_error_t
inq_needpin (void *opaque, const char *line)
snprintf (line, sizeof line, "PKSIGN %s %s",
hash_algo_option (mdalgo), keyid);
rc = assuan_transact (ctrl->scd_local->ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
inq_needpin, &inqparm,
NULL, NULL);
if (inqparm.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
snprintf (line, DIM(line)-1, "PKDECRYPT %s", keyid);
line[DIM(line)-1] = 0;
rc = assuan_transact (ctrl->scd_local->ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
inq_needpin, &inqparm,
padding_info_cb, r_padding);
if (inqparm.any_inq_seen && (gpg_err_code(rc) == GPG_ERR_CANCELED ||
snprintf (line, DIM(line)-1, "READCERT %s", id);
line[DIM(line)-1] = 0;
rc = assuan_transact (ctrl->scd_local->ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
NULL, NULL,
NULL, NULL);
if (rc)
snprintf (line, DIM(line)-1, "READKEY %s", id);
line[DIM(line)-1] = 0;
rc = assuan_transact (ctrl->scd_local->ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
NULL, NULL,
NULL, NULL);
if (rc)
}
-static gpg_error_t
-membuf_data_cb (void *opaque, const void *buffer, size_t length)
-{
- membuf_t *data = opaque;
-
- if (buffer)
- put_membuf (data, buffer, length);
- return 0;
-}
-
-
/* Ask for a passphrase via gpg-agent. On success the caller needs to
free the string stored at R_PASSPHRASE. On error NULL will be
stored at R_PASSPHRASE and an appropriate gpg error code is
else
init_membuf (&data, 64);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, NULL, NULL, NULL);
/* Older Pinentries return the old assuan error code for canceled
}
+/* A variant of put_membuf accepting a void * and returning a
+ gpg_error_t (which will always return 0) to be used as a generic
+ callback handler. This function also allows buffer to be NULL. */
+gpg_error_t
+put_membuf_cb (void *opaque, const void *buf, size_t len)
+{
+ membuf_t *data = opaque;
+
+ if (buf)
+ put_membuf (data, buf, len);
+ return 0;
+}
+
+
void
put_membuf_str (membuf_t *mb, const char *string)
{
void init_membuf_secure (membuf_t *mb, int initiallen);
void clear_membuf (membuf_t *mb, size_t amount);
void put_membuf (membuf_t *mb, const void *buf, size_t len);
+gpg_error_t put_membuf_cb (void *opaque, const void *buf, size_t len);
void put_membuf_str (membuf_t *mb, const char *string);
void put_membuf_printf (membuf_t *mb, const char *format,
...) GPGRT_ATTR_PRINTF(2,3);
}
-static gpg_error_t
-membuf_data_cb (void *opaque, const void *buffer, size_t length)
-{
- membuf_t *data = opaque;
-
- if (buffer)
- put_membuf (data, buffer, length);
- return 0;
-}
-
-
-
/* This is the default inquiry callback. It mainly handles the
Pinentry notifications. */
static gpg_error_t
/* AGENT_ID is a command implemented by gnome-keyring-daemon. It
does not return any data but an OK line with a remark. */
if (assuan_transact (ctx, "AGENT_ID",
- membuf_data_cb, &mb, NULL, NULL, NULL, NULL))
+ put_membuf_cb, &mb, NULL, NULL, NULL, NULL))
{
xfree (get_membuf (&mb, NULL));
return; /* Error - Probably not hijacked. */
snprintf (line, DIM(line)-1, "SCD APDU %s", hexapdu);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &mb, NULL, NULL, NULL, NULL);
+ put_membuf_cb, &mb, NULL, NULL, NULL, NULL);
if (!err)
{
data = get_membuf (&mb, &datalen);
snprintf (line, DIM(line)-1, "SCD READCERT %s", certidstr);
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (rc)
init_membuf_secure (&data, 64);
rc = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
init_membuf (&data, 32);
err = assuan_transact (agent_ctx, "GETINFO s2k_count",
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
NULL, NULL, NULL, NULL);
if (err)
xfree (get_membuf (&data, NULL));
cn_parm.cache_nonce_addr = cache_nonce_addr;
cn_parm.passwd_nonce_addr = NULL;
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
inq_genkey_parms, &gk_parm,
cache_nonce_status_cb, &cn_parm);
if (err)
init_membuf (&data, 1024);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (err)
cache_nonce? " -- ":"",
cache_nonce? cache_nonce:"");
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (err)
if (err)
return err;
err = assuan_transact (agent_ctx, "PKDECRYPT",
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
inq_ciphertext_cb, &parm,
padding_info_cb, r_padding);
xfree (parm.ciphertext);
init_membuf_secure (&data, 64);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, &dfltparm,
NULL, NULL);
if (err)
cn_parm.cache_nonce_addr = cache_nonce_addr;
cn_parm.passwd_nonce_addr = NULL;
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, &dfltparm,
cache_nonce_status_cb, &cn_parm);
if (err)
init_membuf (&data, 64);
err = assuan_transact (agent_ctx, "GETINFO version",
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
NULL, NULL, NULL, NULL);
if (err)
{
}
-
-static gpg_error_t
-membuf_data_cb (void *opaque, const void *buffer, size_t length)
-{
- membuf_t *data = opaque;
-
- if (buffer)
- put_membuf (data, buffer, length);
- return 0;
-}
-
-
/* This is the default inquiry callback. It mainly handles the
Pinentry notifications. */
static gpg_error_t
init_membuf (&data, 1024);
rc = assuan_transact (agent_ctx, "PKSIGN",
- membuf_data_cb, &data, default_inq_cb, ctrl,
+ put_membuf_cb, &data, default_inq_cb, ctrl,
NULL, NULL);
if (rc)
{
snprintf (line, DIM(line)-1, "SCD PKSIGN %s %s", hashopt, keyid);
line[DIM(line)-1] = 0;
rc = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data, default_inq_cb, ctrl,
+ put_membuf_cb, &data, default_inq_cb, ctrl,
NULL, NULL);
if (rc)
{
cipher_parm.ciphertext = ciphertext;
cipher_parm.ciphertextlen = ciphertextlen;
rc = assuan_transact (agent_ctx, "PKDECRYPT",
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
inq_ciphertext_cb, &cipher_parm, NULL, NULL);
if (rc)
{
if (!gk_parm.sexplen)
return gpg_error (GPG_ERR_INV_VALUE);
rc = assuan_transact (agent_ctx, "GENKEY",
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
inq_genkey_parms, &gk_parm, NULL, NULL);
if (rc)
{
init_membuf (&data, 1024);
rc = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, ctrl, NULL, NULL);
if (rc)
{
init_membuf_secure (&data, 64);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, NULL, NULL, NULL);
if (err)
init_membuf_secure (&data, 64);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, ctrl, NULL, NULL);
if (err)
{
init_membuf_secure (&data, 1024);
err = assuan_transact (agent_ctx, line,
- membuf_data_cb, &data,
+ put_membuf_cb, &data,
default_inq_cb, ctrl, NULL, NULL);
if (err)
{