aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorPeter Williams <peterw@ximian.com>2001-08-16 04:05:26 +0800
committerPeter Williams <peterw@src.gnome.org>2001-08-16 04:05:26 +0800
commit5fc7eeebc0afb3b02399e047c256a54106ae1b3b (patch)
treed387ff59126dfe5915f247d7ee3e599286bef1f5 /camel
parentdfeef1979ee3fbefb287a07dafe83c21fb4487c0 (diff)
downloadgsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.tar
gsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.tar.gz
gsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.tar.bz2
gsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.tar.lz
gsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.tar.xz
gsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.tar.zst
gsoc2013-evolution-5fc7eeebc0afb3b02399e047c256a54106ae1b3b.zip
New function. Try to approximate the SSL error into errno.
2001-08-15 Peter Williams <peterw@ximian.com> * camel-tcp-stream-openssl.c (ssl_error_to_errno): New function. Try to approximate the SSL error into errno. (errlib_error_to_errno): New function, try to approximate OpenSSl's error library's error (ERR_*) into errno. (stream_read): Try to set errno using ssl_error_to_errno. (stream_write): Same. (open_ssl_connection): Same. svn path=/trunk/; revision=12065
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog8
-rw-r--r--camel/camel-tcp-stream-openssl.c51
2 files changed, 58 insertions, 1 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 394e5629d7..d06a415ac5 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,13 @@
2001-08-15 Peter Williams <peterw@ximian.com>
+ * camel-tcp-stream-openssl.c (ssl_error_to_errno): New function. Try
+ to approximate the SSL error into errno.
+ (errlib_error_to_errno): New function, try to approximate OpenSSl's
+ error library's error (ERR_*) into errno.
+ (stream_read): Try to set errno using ssl_error_to_errno.
+ (stream_write): Same.
+ (open_ssl_connection): Same.
+
* providers/imap/camel-imap-store.c (imap_connect_online): Oh crap,
huge killer typo.
diff --git a/camel/camel-tcp-stream-openssl.c b/camel/camel-tcp-stream-openssl.c
index 8066713db5..2702cd249b 100644
--- a/camel/camel-tcp-stream-openssl.c
+++ b/camel/camel-tcp-stream-openssl.c
@@ -166,6 +166,48 @@ camel_tcp_stream_openssl_new (CamelService *service, const char *expected_host)
return CAMEL_STREAM (stream);
}
+static void
+errlib_error_to_errno (int ret)
+{
+ long error;
+
+ error = ERR_get_error();
+ if (error == 0) {
+ if (ret == 0)
+ errno = EINVAL; /* unexpected EOF */
+ /* otherwise errno should be set */
+ } else
+ /* ok, we get the shaft now. */
+ errno = EIO;
+}
+
+static void
+ssl_error_to_errno (CamelTcpStreamOpenSSL *stream, int ret)
+{
+ /* hm, a CamelException might be useful right about now! */
+
+ switch (SSL_get_error (stream->priv->ssl, ret)) {
+ case SSL_ERROR_NONE:
+ errno = 0;
+ return;
+ case SSL_ERROR_ZERO_RETURN:
+ /* this one does not map well at all */
+ errno = EINVAL;
+ return;
+ case SSL_ERROR_WANT_READ: /* non-fatal; retry */
+ case SSL_ERROR_WANT_WRITE: /* non-fatal; retry */
+ case SSL_ERROR_WANT_X509_LOOKUP: /* non-fatal; retry */
+ errno = EAGAIN;
+ return;
+ case SSL_ERROR_SYSCALL:
+ errlib_error_to_errno (ret);
+ return;
+ case SSL_ERROR_SSL:
+ errlib_error_to_errno (-1);
+ return;
+ }
+}
+
static ssize_t
stream_read (CamelStream *stream, char *buffer, size_t n)
{
@@ -213,7 +255,10 @@ stream_read (CamelStream *stream, char *buffer, size_t n)
fcntl (tcp_stream_openssl->priv->sockfd, F_SETFL, flags);
}
-
+
+ if (nread == -1)
+ ssl_error_to_errno (tcp_stream_openssl, -1);
+
return nread;
}
@@ -263,6 +308,9 @@ stream_write (CamelStream *stream, const char *buffer, size_t n)
fcntl (tcp_stream_openssl->priv->sockfd, F_SETFL, flags);
}
+ if (written == -1)
+ ssl_error_to_errno (tcp_stream_openssl, -1);
+
return written;
}
@@ -450,6 +498,7 @@ open_ssl_connection (CamelService *service, int sockfd, CamelTcpStreamOpenSSL *o
n = SSL_connect (ssl);
if (n != 1) {
+ ssl_error_to_errno (openssl, n);
SSL_shutdown (ssl);