aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog3
-rw-r--r--camel/camel-gpg-context.c40
2 files changed, 20 insertions, 23 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 183f9d8989..4aed3c347a 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,7 +1,8 @@
2002-06-27 Jeffrey Stedfast <fejj@ximian.com>
* camel-gpg-context.c (gpg_ctx_op_step): Loop on our reads while
- errno is EINTR or EAGAIN.
+ errno is EINTR or EAGAIN. Also make sure to completely read stdout
+ and stderr by keeping better state.
2002-06-26 Jeffrey Stedfast <fejj@ximian.com>
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 6994337ecc..2483a10c59 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -250,8 +250,8 @@ struct _GpgCtx {
GByteArray *diagnostics;
unsigned int complete:1;
- unsigned int await_read:1;
- unsigned int reading:2;
+ unsigned int seen_eof1:1;
+ unsigned int seen_eof2:1;
unsigned int always_trust:1;
unsigned int armor:1;
unsigned int need_passwd:1;
@@ -262,7 +262,7 @@ struct _GpgCtx {
unsigned int validsig:1;
unsigned int trust:3;
- unsigned int padding:18;
+ unsigned int padding:19;
};
static struct _GpgCtx *
@@ -276,8 +276,8 @@ gpg_ctx_new (CamelSession *session, const char *path)
camel_object_ref (CAMEL_OBJECT (session));
gpg->userid_hint = g_hash_table_new (g_str_hash, g_str_equal);
gpg->complete = FALSE;
- gpg->await_read = FALSE;
- gpg->reading = 0;
+ gpg->seen_eof1 = FALSE;
+ gpg->seen_eof2 = FALSE;
gpg->pid = (pid_t) -1;
gpg->path = g_strdup (path);
@@ -787,7 +787,6 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
case GPG_CTX_MODE_SIGN:
if (!strncmp (status, "SIG_CREATED ", 12)) {
gpg->complete = TRUE;
- gpg->await_read = TRUE;
}
break;
case GPG_CTX_MODE_VERIFY:
@@ -804,21 +803,23 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
}
gpg->complete = TRUE;
+
+ /* Since verifying a signature will never produce output
+ on gpg's stdout descriptor, we use this EOF bit for
+ making sure that we get a TRUST metric. */
+ gpg->seen_eof1 = TRUE;
} else if (!strncmp (status, "VALIDSIG", 8)) {
gpg->validsig = TRUE;
- gpg->complete = TRUE;
} else if (!strncmp (status, "BADSIG", 6)) {
gpg->validsig = FALSE;
- gpg->complete = TRUE;
} else if (!strncmp (status, "ERRSIG", 6)) {
/* Note: NO_PUBKEY often comes after an ERRSIG, but do we really care? */
gpg->validsig = FALSE;
- gpg->complete = TRUE;
}
break;
case GPG_CTX_MODE_ENCRYPT:
if (!strncmp (status, "BEGIN_ENCRYPTION", 16)) {
- gpg->await_read = TRUE;
+ /* nothing to do... but we know to expect data on stdout soon */
} else if (!strncmp (status, "END_ENCRYPTION", 14)) {
gpg->complete = TRUE;
} else if (!strncmp (status, "NO_RECP", 7)) {
@@ -829,7 +830,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
break;
case GPG_CTX_MODE_DECRYPT:
if (!strncmp (status, "BEGIN_DECRYPTION", 16)) {
- gpg->await_read = TRUE;
+ /* nothing to do... but we know to expect data on stdout soon */
} else if (!strncmp (status, "END_DECRYPTION", 14)) {
gpg->complete = TRUE;
}
@@ -930,7 +931,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
can to all of them. If one fails along the way, return
-1. */
- if (FD_ISSET (gpg->status_fd, &rdset) && !gpg->complete) {
+ if (FD_ISSET (gpg->status_fd, &rdset)) {
/* read the status message and decide what to do... */
char buffer[4096];
ssize_t nread;
@@ -951,7 +952,6 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
}
}
- gpg->reading--;
if (FD_ISSET (gpg->stdout, &rdset) && gpg->ostream) {
char buffer[4096];
ssize_t nread;
@@ -967,11 +967,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
if (nread > 0) {
if (camel_stream_write (gpg->ostream, buffer, (size_t) nread) == -1)
goto exception;
-
- gpg->await_read = FALSE;
-
- /* make sure we don't exit before reading all the data... */
- gpg->reading = 3;
+ } else {
+ gpg->seen_eof1 = TRUE;
}
}
@@ -989,9 +986,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
if (nread > 0) {
g_byte_array_append (gpg->diagnostics, buffer, nread);
-
- /* make sure we don't exit before reading all the data... */
- gpg->reading = 3;
+ } else {
+ gpg->seen_eof2 = TRUE;
}
}
@@ -1094,7 +1090,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
static gboolean
gpg_ctx_op_complete (struct _GpgCtx *gpg)
{
- return gpg->complete && !gpg->await_read && !gpg->reading;
+ return gpg->complete && gpg->seen_eof1 && gpg->seen_eof2;
}
static void