aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-04-10 07:21:15 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-04-10 07:21:15 +0800
commit0933b12476c210975487cd29c3e05a0f248eac04 (patch)
treee121ea2c243fd54b5c8e95589cbe2711c05200e6 /camel
parent738650c1d1326b89a8a99cddcdde1a363c55e55f (diff)
downloadgsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.tar
gsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.tar.gz
gsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.tar.bz2
gsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.tar.lz
gsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.tar.xz
gsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.tar.zst
gsoc2013-evolution-0933b12476c210975487cd29c3e05a0f248eac04.zip
Removed. I just realised that we ALWAYS want to get gpg's stderr in UTF-8,
2003-04-09 Jeffrey Stedfast <fejj@ximian.com> * camel-gpg-context.c (gpg_ctx_get_utf8_diagnostics): Removed. I just realised that we ALWAYS want to get gpg's stderr in UTF-8, so the better solution (plus less code duplication) is to just have the diagnostics buffer be a CamelStreamMem with a charset filter. (gpg_ctx_new): Setup a filter stream to convert our gpg stderr diagnostics into UTF-8 if needed. (gpg_ctx_free): Unref the diagnostcis stream. (gpg_ctx_parse_status): Flush the diagnostics stream if we are going to use the data in an exception. (gpg_ctx_op_step): Use camel_stream_write() to append to the diagnostics stream rather than appending the buffer to a GByteArray like we used to do. (gpg_ctx_op_step): Flush the diagnostics stream here too. (gpg_verify): Use a const char *diagnostics string here, forcing a slight rearrangement of calls - use the const char *dignostics before we gpg_ctx_free, otherwise we'll be passing free'd memory off to the cipher_validity. (gpg_ctx_get_diagnostics): Do the work here to flush the diagnostics stream and nul-terminate the buffer. Also return const now, instead of strdupping. No need for that. (gpg_ctx_parse_status): Convert the user hint to UTF-8. svn path=/trunk/; revision=20798
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog26
-rw-r--r--camel/camel-gpg-context.c179
2 files changed, 92 insertions, 113 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index f07d3c83f3..51046e119d 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,11 +1,37 @@
2003-04-09 Jeffrey Stedfast <fejj@ximian.com>
+ * camel-gpg-context.c (gpg_ctx_get_utf8_diagnostics): Removed. I
+ just realised that we ALWAYS want to get gpg's stderr in UTF-8, so
+ the better solution (plus less code duplication) is to just have
+ the diagnostics buffer be a CamelStreamMem with a charset filter.
+ (gpg_ctx_new): Setup a filter stream to convert our gpg stderr
+ diagnostics into UTF-8 if needed.
+ (gpg_ctx_free): Unref the diagnostcis stream.
+ (gpg_ctx_parse_status): Flush the diagnostics stream if we are
+ going to use the data in an exception.
+ (gpg_ctx_op_step): Use camel_stream_write() to append to the
+ diagnostics stream rather than appending the buffer to a
+ GByteArray like we used to do.
+ (gpg_ctx_op_step): Flush the diagnostics stream here too.
+ (gpg_verify): Use a const char *diagnostics string here, forcing a
+ slight rearrangement of calls - use the const char *dignostics
+ before we gpg_ctx_free, otherwise we'll be passing free'd memory
+ off to the cipher_validity.
+ (gpg_ctx_get_diagnostics): Do the work here to flush the
+ diagnostics stream and nul-terminate the buffer. Also return const
+ now, instead of strdupping. No need for that.
+ (gpg_ctx_parse_status): Convert the user hint to UTF-8.
+
+2003-04-09 Jeffrey Stedfast <fejj@ximian.com>
+
* camel-gpg-context.c (gpg_ctx_get_utf8_diagnostics): Changed my
mind a bit on how I wanted this to work. Instead of aborting on an
illegal sequence, do like we do with camel-mime-filter-charset and
just skip over invalid sequences. Also, in the noop failure case,
close the iconv_t so we don't leak it.
+2003-04-09 Jeffrey Stedfast <fejj@ximian.com>
+
* providers/imap/camel-imap-utils.c (imap_body_decode): Save the
content size in a temp variable until after we've successfully
parsed all of the body_type_1part expr. Also fixed a type-o in the
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index ad60f88fd3..7919056f9e 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -44,6 +44,9 @@
#include "gal/util/e-iconv.h"
#include "camel-gpg-context.h"
+#include "camel-mime-filter-charset.h"
+#include "camel-stream-filter.h"
+#include "camel-stream-mem.h"
#include "camel-stream-fs.h"
#include "camel-operation.h"
@@ -260,7 +263,8 @@ struct _GpgCtx {
CamelStream *istream;
CamelStream *ostream;
- GByteArray *diagnostics;
+ GByteArray *diagbuf;
+ CamelStream *diagnostics;
int exit_status;
@@ -285,6 +289,8 @@ static struct _GpgCtx *
gpg_ctx_new (CamelSession *session)
{
struct _GpgCtx *gpg;
+ const char *charset;
+ CamelStream *stream;
gpg = g_new (struct _GpgCtx, 1);
gpg->mode = GPG_CTX_MODE_SIGN;
@@ -326,7 +332,24 @@ gpg_ctx_new (CamelSession *session)
gpg->istream = NULL;
gpg->ostream = NULL;
- gpg->diagnostics = g_byte_array_new ();
+ stream = camel_stream_mem_new ();
+ gpg->diagbuf = CAMEL_STREAM_MEM (stream)->buffer;
+
+ if ((charset = e_iconv_locale_charset ()) && !strcasecmp (charset, "UTF-8")) {
+ CamelMimeFilterCharset *filter;
+ CamelStreamFilter *fstream;
+
+ if ((filter = camel_mime_filter_charset_new_convert (charset, "UTF-8"))) {
+ fstream = camel_stream_filter_new_with_stream (stream);
+ camel_stream_filter_add (fstream, (CamelMimeFilter *) filter);
+ camel_object_unref (filter);
+ camel_object_unref (stream);
+
+ stream = (CamelStream *) fstream;
+ }
+ }
+
+ gpg->diagnostics = stream;
return gpg;
}
@@ -400,92 +423,18 @@ gpg_ctx_set_ostream (struct _GpgCtx *gpg, CamelStream *ostream)
gpg->ostream = ostream;
}
-static char *
+static const char *
gpg_ctx_get_diagnostics (struct _GpgCtx *gpg)
{
- return g_strndup (gpg->diagnostics->data, gpg->diagnostics->len);
-}
-
-static char *
-gpg_ctx_get_utf8_diagnostics (struct _GpgCtx *gpg)
-{
- size_t inleft, outleft, converted = 0;
- const char *charset;
- char *out, *outbuf;
- const char *inbuf;
- size_t outlen;
- iconv_t cd;
-
- if (gpg->diagnostics->len == 0)
- return NULL;
-
- /* if the locale is C/POSIX/ASCII/UTF-8 - then there's nothing to do here */
- if (!(charset = e_iconv_locale_charset ()) || !strcasecmp (charset, "UTF-8"))
- return gpg_ctx_get_diagnostics (gpg);
-
- cd = e_iconv_open ("UTF-8", charset);
-
- inbuf = gpg->diagnostics->data;
- inleft = gpg->diagnostics->len;
-
- outleft = outlen = (inleft * 2) + 16;
- outbuf = out = g_malloc (outlen + 1);
-
- do {
- converted = e_iconv (cd, &inbuf, &inleft, &outbuf, &outleft);
- if (converted == (size_t) -1) {
- if (errno == E2BIG) {
- /*
- * E2BIG There is not sufficient room at *outbuf.
- *
- * We just need to grow our outbuffer and try again.
- */
-
- converted = outbuf - out;
- outlen += inleft * 2 + 16;
- out = g_realloc (out, outlen + 1);
- outbuf = out + converted;
- outleft = outlen - converted;
- } else if (errno == EILSEQ) {
- /*
- * EILSEQ An invalid multibyte sequence has been encountered
- * in the input.
- *
- * What we do here is eat the invalid bytes in the sequence and continue
- */
-
- inbuf++;
- inleft--;
- } else if (errno == EINVAL) {
- /*
- * EINVAL An incomplete multibyte sequence has been encounĀ­
- * tered in the input.
- *
- * We assume that this can only happen if we've run out of
- * bytes for a multibyte sequence, if not we're in trouble.
- */
-
- break;
- } else
- goto noop;
- }
- } while (((int) inleft) > 0);
-
- /* flush the iconv conversion */
- e_iconv (cd, NULL, NULL, &outbuf, &outleft);
- e_iconv_close (cd);
-
- /* nul-terminate the string */
- outbuf[0] = '\0';
-
- return out;
-
- noop:
-
- g_free (out);
- e_iconv_close (cd);
+ if (!gpg->diagbuf->len || gpg->diagbuf->data[gpg->diagbuf->len - 1] != '\0') {
+ camel_stream_flush (gpg->diagnostics);
+ if (gpg->diagbuf->len == 0)
+ return NULL;
+
+ g_byte_array_append (gpg->diagbuf, "", 1);
+ }
- return gpg_ctx_get_diagnostics (gpg);
+ return gpg->diagbuf->data;
}
static void
@@ -539,7 +488,7 @@ gpg_ctx_free (struct _GpgCtx *gpg)
if (gpg->ostream)
camel_object_unref (CAMEL_OBJECT (gpg->ostream));
- g_byte_array_free (gpg->diagnostics, TRUE);
+ camel_object_unref (gpg->diagnostics);
g_free (gpg);
}
@@ -813,6 +762,7 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
status += 9;
if (!strncmp (status, "USERID_HINT ", 12)) {
+ size_t nread, nwritten;
char *hint, *user;
status += 12;
@@ -829,7 +779,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
goto recycle;
}
- user = g_strdup (status);
+ if (!(user = g_locale_to_utf8 (status, -1, &nread, &nwritten, NULL)))
+ user = g_strdup (status);
+
g_strstrip (user);
g_hash_table_insert (gpg->userid_hint, hint, user);
@@ -890,9 +842,11 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
return -1;
} else if (!strncmp (status, "NODATA", 6)) {
/* this is an error */
- if (gpg->diagnostics->len)
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "%.*s",
- gpg->diagnostics->len, gpg->diagnostics->data);
+ const char *diagnostics;
+
+ diagnostics = gpg_ctx_get_diagnostics (gpg);
+ if (diagnostics && *diagnostics)
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, diagnostics);
else
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
_("No data provided"));
@@ -1003,6 +957,7 @@ static int
gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
{
fd_set rdset, wrset, *wrsetp = NULL;
+ const char *diagnostics;
struct timeval timeout;
const char *mode;
int maxfd = 0;
@@ -1108,7 +1063,9 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
goto exception;
if (nread > 0) {
- g_byte_array_append (gpg->diagnostics, buffer, nread);
+ printf ("pre-diag: %.*s\n", nread, buffer);
+ camel_stream_write (gpg->diagnostics, buffer, nread);
+ printf ("post-diag: %.*s\n", gpg->diagbuf->len, gpg->diagbuf->data);
} else {
gpg->seen_eof2 = TRUE;
}
@@ -1204,12 +1161,12 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
break;
}
- if (gpg->diagnostics->len) {
+ diagnostics = gpg_ctx_get_diagnostics (gpg);
+ if (diagnostics && *diagnostics) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- _("Failed to GPG %s: %s\n\n%.*s"),
+ _("Failed to GPG %s: %s\n\n%s"),
mode, g_strerror (errno),
- gpg->diagnostics->len,
- gpg->diagnostics->data);
+ diagnostics);
} else {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Failed to GPG %s: %s\n"),
@@ -1346,13 +1303,12 @@ gpg_sign (CamelCipherContext *context, const char *userid, CamelCipherHash hash,
}
if (gpg_ctx_op_wait (gpg) != 0) {
- char *diagnostics;
+ const char *diagnostics;
diagnostics = gpg_ctx_get_diagnostics (gpg);
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
diagnostics && *diagnostics ? diagnostics :
_("Failed to execute gpg."));
- g_free (diagnostics);
gpg_ctx_free (gpg);
@@ -1403,7 +1359,7 @@ gpg_verify (CamelCipherContext *context, CamelCipherHash hash,
CamelException *ex)
{
CamelCipherValidity *validity;
- char *diagnostics = NULL;
+ const char *diagnostics = NULL;
struct _GpgCtx *gpg;
char *sigfile = NULL;
gboolean valid;
@@ -1448,15 +1404,12 @@ gpg_verify (CamelCipherContext *context, CamelCipherHash hash,
}
}
- diagnostics = gpg_ctx_get_utf8_diagnostics (gpg);
-
valid = gpg_ctx_op_wait (gpg) == 0;
- gpg_ctx_free (gpg);
-
validity = camel_cipher_validity_new ();
+ diagnostics = gpg_ctx_get_diagnostics (gpg);
camel_cipher_validity_set_valid (validity, valid);
camel_cipher_validity_set_description (validity, diagnostics);
- g_free (diagnostics);
+ gpg_ctx_free (gpg);
if (sigfile) {
unlink (sigfile);
@@ -1526,13 +1479,12 @@ gpg_encrypt (CamelCipherContext *context, gboolean sign, const char *userid,
}
if (gpg_ctx_op_wait (gpg) != 0) {
- char *diagnostics;
+ const char *diagnostics;
diagnostics = gpg_ctx_get_diagnostics (gpg);
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
diagnostics && *diagnostics ? diagnostics :
_("Failed to execute gpg."));
- g_free (diagnostics);
gpg_ctx_free (gpg);
@@ -1583,13 +1535,12 @@ gpg_decrypt (CamelCipherContext *context, CamelStream *istream,
}
if (gpg_ctx_op_wait (gpg) != 0) {
- char *diagnostics;
+ const char *diagnostics;
diagnostics = gpg_ctx_get_diagnostics (gpg);
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
diagnostics && *diagnostics ? diagnostics :
_("Failed to execute gpg."));
- g_free (diagnostics);
gpg_ctx_free (gpg);
@@ -1629,11 +1580,12 @@ gpg_import_keys (CamelCipherContext *context, CamelStream *istream, CamelExcepti
}
if (gpg_ctx_op_wait (gpg) != 0) {
- char *diagnostics;
+ const char *diagnostics;
diagnostics = gpg_ctx_get_diagnostics (gpg);
- camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, diagnostics);
- g_free (diagnostics);
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+ diagnostics && *diagnostics ? diagnostics :
+ _("Failed to execute gpg."));
gpg_ctx_free (gpg);
@@ -1679,11 +1631,12 @@ gpg_export_keys (CamelCipherContext *context, GPtrArray *keys, CamelStream *ostr
}
if (gpg_ctx_op_wait (gpg) != 0) {
- char *diagnostics;
+ const char *diagnostics;
diagnostics = gpg_ctx_get_diagnostics (gpg);
- camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, diagnostics);
- g_free (diagnostics);
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+ diagnostics && *diagnostics ? diagnostics :
+ _("Failed to execute gpg."));
gpg_ctx_free (gpg);