aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-gpg-context.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-04-10 06:04:33 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-04-10 06:04:33 +0800
commit14517cbca46e86fdb825a2ac6df35808290df99f (patch)
treea439791d146e3088ca635fc9843748a605ea3b2e /camel/camel-gpg-context.c
parent94286866e7f748254b0f3ec70e4a52b729bc4dd0 (diff)
downloadgsoc2013-evolution-14517cbca46e86fdb825a2ac6df35808290df99f.tar.gz
gsoc2013-evolution-14517cbca46e86fdb825a2ac6df35808290df99f.tar.zst
gsoc2013-evolution-14517cbca46e86fdb825a2ac6df35808290df99f.zip
Changed my mind a bit on how I wanted this to work. Instead of aborting on
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. svn path=/trunk/; revision=20796
Diffstat (limited to 'camel/camel-gpg-context.c')
-rw-r--r--camel/camel-gpg-context.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 7a4098a3df..ad60f88fd3 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -428,39 +428,48 @@ gpg_ctx_get_utf8_diagnostics (struct _GpgCtx *gpg)
inbuf = gpg->diagnostics->data;
inleft = gpg->diagnostics->len;
- outlen = (inleft * 2) + 16;
- out = g_malloc (outlen + 1);
+ outleft = outlen = (inleft * 2) + 16;
+ outbuf = out = g_malloc (outlen + 1);
do {
- outbuf = out + converted;
- outleft = outlen - converted;
-
converted = e_iconv (cd, &inbuf, &inleft, &outbuf, &outleft);
if (converted == (size_t) -1) {
- if (errno != E2BIG && errno != EINVAL)
- goto fail;
- }
-
- /*
- * E2BIG There is not sufficient room at *outbuf.
- *
- * We just need to grow our outbuffer and try again.
- */
-
- converted = outbuf - out;
- if (errno == E2BIG) {
- outlen += inleft * 2 + 16;
- out = g_realloc (out, outlen + 1);
- outbuf = out + converted;
+ 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 (errno == E2BIG && inleft > 0);
-
- /*
- * EINVAL An incomplete multibyte sequence has been encounĀ­
- * tered in the input.
- *
- * We'll just have to ignore it...
- */
+ } while (((int) inleft) > 0);
/* flush the iconv conversion */
e_iconv (cd, NULL, NULL, &outbuf, &outleft);
@@ -471,9 +480,10 @@ gpg_ctx_get_utf8_diagnostics (struct _GpgCtx *gpg)
return out;
- fail:
+ noop:
g_free (out);
+ e_iconv_close (cd);
return gpg_ctx_get_diagnostics (gpg);
}