mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
gpgsm: Print PROGRESS status lines.
* common/ksba-io-support.c (struct writer_cb_parm_s): Add field progress. (struct gnupg_ksba_io_s): Add field is_writer. (update_write_progress): New. (base64_writer_cb, plain_writer_cb): Call update_write_progress. (base64_finish_write): Ditto. (gnupg_ksba_create_writer): Set is_writer. (gnupg_ksba_set_progress_cb): New. (gnupg_ksba_set_total): New. * common/ksba-io-support.h (gnupg_ksba_progress_cb_t): New type. * sm/server.c (gpgsm_status2): Return error from statusfp writes. (gpgsm_progress_cb): New. * sm/decrypt.c (gpgsm_decrypt): Set progress handler. * sm/encrypt.c (gpgsm_encrypt): Ditto. * sm/sign.c (gpgsm_sign): Ditto. * sm/verify.c (gpgsm_verify): Ditto. -- GnuPG-bug-id: 6534 Backported-from:c58067415f
Backported-from:a88aeee129
This commit is contained in:
parent
1b60aab2c4
commit
ce0d3238f0
9 changed files with 161 additions and 10 deletions
|
@ -1116,6 +1116,8 @@ gpgsm_decrypt (ctrl_t ctrl, int in_fd, estream_t out_fp)
|
|||
goto leave;
|
||||
}
|
||||
|
||||
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
|
||||
|
||||
rc = ksba_cms_new (&cms);
|
||||
if (rc)
|
||||
goto leave;
|
||||
|
|
|
@ -672,6 +672,8 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, estream_t out_fp)
|
|||
goto leave;
|
||||
}
|
||||
|
||||
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
|
||||
|
||||
err = ksba_cms_new (&cms);
|
||||
if (err)
|
||||
{
|
||||
|
@ -847,7 +849,7 @@ gpgsm_encrypt (ctrl_t ctrl, certlist_t recplist, int data_fd, estream_t out_fp)
|
|||
err = ksba_cms_build (cms, &stopreason);
|
||||
if (err)
|
||||
{
|
||||
log_debug ("ksba_cms_build failed: %s\n", gpg_strerror (err));
|
||||
log_error ("creating CMS object failed: %s\n", gpg_strerror (err));
|
||||
rc = err;
|
||||
goto leave;
|
||||
}
|
||||
|
|
|
@ -270,6 +270,7 @@ gpg_error_t gpgsm_status_with_err_code (ctrl_t ctrl, int no, const char *text,
|
|||
gpg_err_code_t ec);
|
||||
gpg_error_t gpgsm_status_with_error (ctrl_t ctrl, int no, const char *text,
|
||||
gpg_error_t err);
|
||||
gpg_error_t gpgsm_progress_cb (ctrl_t ctrl, uint64_t current, uint64_t total);
|
||||
gpg_error_t gpgsm_proxy_pinentry_notify (ctrl_t ctrl,
|
||||
const unsigned char *line);
|
||||
|
||||
|
|
48
sm/server.c
48
sm/server.c
|
@ -1450,7 +1450,14 @@ gpgsm_status2 (ctrl_t ctrl, int no, ...)
|
|||
}
|
||||
}
|
||||
putc ('\n', statusfp);
|
||||
fflush (statusfp);
|
||||
if (ferror (statusfp))
|
||||
err = gpg_error_from_syserror ();
|
||||
else
|
||||
{
|
||||
fflush (statusfp);
|
||||
if (ferror (statusfp))
|
||||
err = gpg_error_from_syserror ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1495,6 +1502,45 @@ gpgsm_status_with_error (ctrl_t ctrl, int no, const char *text,
|
|||
}
|
||||
|
||||
|
||||
/* This callback is used to emit progress status lines. */
|
||||
gpg_error_t
|
||||
gpgsm_progress_cb (ctrl_t ctrl, uint64_t current, uint64_t total)
|
||||
{
|
||||
char buffer[60];
|
||||
char units[] = "BKMGTPEZY?";
|
||||
int unitidx = 0;
|
||||
|
||||
if (total)
|
||||
{
|
||||
if (current > total)
|
||||
current = total;
|
||||
|
||||
while (total > 1024*1024)
|
||||
{
|
||||
total /= 1024;
|
||||
current /= 1024;
|
||||
unitidx++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (current > 1024*1024)
|
||||
{
|
||||
current /= 1024;
|
||||
unitidx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (unitidx > 9)
|
||||
unitidx = 9;
|
||||
|
||||
snprintf (buffer, sizeof buffer, "? %lu %lu %c%s",
|
||||
(unsigned long)current, (unsigned long)total,
|
||||
units[unitidx], unitidx? "iB" : "");
|
||||
return gpgsm_status2 (ctrl, STATUS_PROGRESS, "?", buffer, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* Helper to notify the client about Pinentry events. Because that
|
||||
might disturb some older clients, this is only done when enabled
|
||||
via an option. Returns an gpg error code. */
|
||||
|
|
|
@ -361,6 +361,8 @@ gpgsm_sign (ctrl_t ctrl, certlist_t signerlist,
|
|||
goto leave;
|
||||
}
|
||||
|
||||
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
|
||||
|
||||
err = ksba_cms_new (&cms);
|
||||
if (err)
|
||||
{
|
||||
|
@ -684,7 +686,7 @@ gpgsm_sign (ctrl_t ctrl, certlist_t signerlist,
|
|||
err = ksba_cms_build (cms, &stopreason);
|
||||
if (err)
|
||||
{
|
||||
log_debug ("ksba_cms_build failed: %s\n", gpg_strerror (err));
|
||||
log_error ("creating CMS object failed: %s\n", gpg_strerror (err));
|
||||
rc = err;
|
||||
goto leave;
|
||||
}
|
||||
|
|
|
@ -153,6 +153,8 @@ gpgsm_verify (ctrl_t ctrl, int in_fd, int data_fd, estream_t out_fp)
|
|||
}
|
||||
}
|
||||
|
||||
gnupg_ksba_set_progress_cb (b64writer, gpgsm_progress_cb, ctrl);
|
||||
|
||||
rc = ksba_cms_new (&cms);
|
||||
if (rc)
|
||||
goto leave;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue