[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Change the error semantics of tls.shutdown() to give er...



Update of /home/minion/cvsroot/src/minion/src
In directory moria.seul.org:/tmp/cvs-serv8607/src

Modified Files:
	tls.c 
Log Message:
Change the error semantics of tls.shutdown() to give errors from
SSL_shutdown except for (possibly spurious) SSL_ERROR_SYSCALL errors.

Also, change interface to tls_error.


Index: tls.c
===================================================================
RCS file: /home/minion/cvsroot/src/minion/src/tls.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- tls.c	19 Aug 2002 20:27:02 -0000	1.8
+++ tls.c	2 Dec 2002 03:18:23 -0000	1.9
@@ -43,19 +43,25 @@
 /* 
  * Checks for an outstanding error on a given SSL object that has just
  * returned the value 'r'.  Returns NO_ERROR, ERROR, or ZERO_RETURN.
- * On ERROR, a Python error is set.  On ZERO_RETURN, a Python error is
- * set if 'zeroReturnIsError'.
+ * On ERROR, a Python error is set.  
+ *
+ * On SSL_ERROR_ZERO_RETURN, a Python error is set if !(flags &
+ * IGNORE_ZERO_RETURN).  On SSL_ERROR_SYSCALL, an error condition is
+ * set if !(flags & IGNORE_SYSCALL).
  */
+#define IGNORE_ZERO_RETURN 1
+#define IGNORE_SYSCALL 2
 static int 
-tls_error(SSL *ssl, int r, int zeroReturnIsError) 
+tls_error(SSL *ssl, int r, int flags)
 {
 	int err = SSL_get_error(ssl,r);
 	switch (err) {
  	  case SSL_ERROR_NONE:
 		  return NO_ERROR;
 	  case SSL_ERROR_ZERO_RETURN:
-		  if (zeroReturnIsError)
-			  mm_SSL_ERR(0);
+		  if (flags & IGNORE_ZERO_RETURN)
+			  return ZERO_RETURN;
+                  mm_SSL_ERR(0);
 		  return ZERO_RETURN;
  	  case SSL_ERROR_WANT_READ:
 		  PyErr_SetNone(mm_TLSWantRead);
@@ -64,6 +70,8 @@
 		  PyErr_SetNone(mm_TLSWantWrite);
 		  return ERROR;
  	  case SSL_ERROR_SYSCALL:
+		  if (flags & IGNORE_SYSCALL)
+			  return NO_ERROR;
 		  PyErr_SetNone(mm_TLSClosed);
 		  return ERROR;
  	  default:
@@ -295,7 +303,7 @@
 	r = SSL_accept(ssl);
 	Py_END_ALLOW_THREADS
 	
-	if (tls_error(ssl, r, 1))
+	if (tls_error(ssl, r, 0))
 		return NULL;
 	
 	Py_INCREF(Py_None);
@@ -322,7 +330,7 @@
 	r = SSL_connect(ssl);
 	Py_END_ALLOW_THREADS
 	err = SSL_get_error(ssl,r);
-	if (tls_error(ssl, r, 1))
+	if (tls_error(ssl, r, 0))
 		return NULL;
 
 	Py_INCREF(Py_None);
@@ -383,7 +391,7 @@
 		return res;
 	}
 	Py_DECREF(res);
-	switch (tls_error(ssl, r, 0)) {
+	switch (tls_error(ssl, r, IGNORE_ZERO_RETURN)) {
 	    case NO_ERROR:
 		    Py_INCREF(Py_None);
 		    return Py_None;
@@ -423,7 +431,7 @@
 	r = SSL_write(ssl, string, stringlen);
 	Py_END_ALLOW_THREADS
 	
-	switch(tls_error(ssl, r, 0)) {
+	switch(tls_error(ssl, r, IGNORE_ZERO_RETURN)) {
 	    case NO_ERROR:	    
 		    return PyInt_FromLong(r);
 	    case ZERO_RETURN:
@@ -455,10 +463,10 @@
 	Py_BEGIN_ALLOW_THREADS
 	r = SSL_shutdown(ssl);
 	Py_END_ALLOW_THREADS
-	if (r == 0) return PyInt_FromLong(0);
 	if (r == 1) return PyInt_FromLong(1);
-	if (tls_error(ssl,r,1))
+	if (tls_error(ssl, r, IGNORE_SYSCALL))
 		return NULL;
+	if (r == 0) return PyInt_FromLong(0);
 
 	Py_INCREF(Py_None);
 	return Py_None;