[Twisted-Python] Twisted 2.0 prerelease (close!!)

James Y Knight foom at fuhm.net
Fri Mar 11 09:55:31 MST 2005


On Mar 11, 2005, at 3:59 AM, Andrea Arcangeli wrote:
> Thanks for the explanation. I've also got those messages, could you 
> post
> the patch so I can apply it to pyOpenSSL until it's merged? Thanks.

Here ya go. The last file is actually an unrelated patch that lets you 
pass None as the verify callback instead of using an empty lambda.

James

Index: src/ssl/connection.c
===================================================================
RCS file: /u/cvs/pyopenssl/pyOpenSSL/src/ssl/connection.c,v
retrieving revision 1.28
diff -u -r1.28 connection.c
--- src/ssl/connection.c        6 Aug 2004 10:21:56 -0000       1.28
+++ src/ssl/connection.c        23 Feb 2005 02:42:29 -0000
@@ -756,6 +756,43 @@
      return Py_None;
  }

+static char ssl_Connection_get_shutdown_doc[] = "\n\
+Get shutdown state\n\
+\n\
+Arguments: self - The Connection object\n\
+           args - The Python argument tuple, should be empty\n\
+Returns:   The shutdown state, a bitmask of SENT_SHUTDOWN, 
RECEIVED_SHUTDOWN.\n\
+";
+static PyObject *
+ssl_Connection_get_shutdown(ssl_ConnectionObj *self, PyObject *args)
+{
+    if (!PyArg_ParseTuple(args, ":get_shutdown"))
+        return NULL;
+
+       return PyInt_FromLong((long)SSL_get_shutdown(self->ssl));
+}
+
+static char ssl_Connection_set_shutdown_doc[] = "\n\
+Set shutdown state\n\
+\n\
+Arguments: self - The Connection object\n\
+           args - The Python argument tuple, should be\n\
+             shutdown state - bitmask of SENT_SHUTDOWN, 
RECEIVED_SHUTDOWN.\n\
+Returns:   None\n\
+";
+static PyObject *
+ssl_Connection_set_shutdown(ssl_ConnectionObj *self, PyObject *args)
+{
+    int shutdown;
+
+    if (!PyArg_ParseTuple(args, "i:set_shutdown", &shutdown))
+        return NULL;
+
+       SSL_set_shutdown(self->ssl, shutdown);
+    Py_INCREF(Py_None);
+    return Py_None;
+}
+
  static char ssl_Connection_state_string_doc[] = "\n\
  Get a verbose state description\n\
  \n\
@@ -888,6 +925,8 @@
      ADD_METHOD(makefile),
      ADD_METHOD(get_app_data),
      ADD_METHOD(set_app_data),
+    ADD_METHOD(get_shutdown),
+    ADD_METHOD(set_shutdown),
      ADD_METHOD(state_string),
      ADD_METHOD(sock_shutdown),
      ADD_METHOD(get_peer_certificate),
Index: src/ssl/ssl.c
===================================================================
RCS file: /u/cvs/pyopenssl/pyOpenSSL/src/ssl/ssl.c,v
retrieving revision 1.12
diff -u -r1.12 ssl.c
--- src/ssl/ssl.c       10 Aug 2004 21:42:51 -0000      1.12
+++ src/ssl/ssl.c       23 Feb 2005 02:42:30 -0000
@@ -180,6 +180,10 @@
      PyModule_AddIntConstant(module, "OP_NETSCAPE_CA_DN_BUG", 
SSL_OP_NETSCAPE_CA_DN_BUG);
      PyModule_AddIntConstant(module, 
"OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG", 
SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);

+       /* For SSL_set_shutdown */
+    PyModule_AddIntConstant(module, "SENT_SHUTDOWN", 
SSL_SENT_SHUTDOWN);
+    PyModule_AddIntConstant(module, "RECEIVED_SHUTDOWN", 
SSL_RECEIVED_SHUTDOWN);
+
      dict = PyModule_GetDict(module);
      if (!init_ssl_context(dict))
          goto error;
Index: src/ssl/context.c
===================================================================
RCS file: /u/cvs/pyopenssl/pyOpenSSL/src/ssl/context.c,v
retrieving revision 1.17
diff -u -r1.17 context.c
--- src/ssl/context.c   6 Aug 2004 10:21:56 -0000       1.17
+++ src/ssl/context.c   23 Feb 2005 02:42:29 -0000
@@ -562,8 +562,8 @@

      if (!PyArg_ParseTuple(args, "iO:set_verify", &mode, &callback))
          return NULL;
-
-    if (!PyCallable_Check(callback))
+
+    if (callback != Py_None && !PyCallable_Check(callback))
      {
          PyErr_SetString(PyExc_TypeError, "expected PyCallable");
          return NULL;
@@ -572,8 +572,11 @@
      Py_DECREF(self->verify_callback);
      Py_INCREF(callback);
      self->verify_callback = callback;
-    SSL_CTX_set_verify(self->ctx, mode, global_verify_callback);
-
+       if (callback == Py_None)
+               SSL_CTX_set_verify(self->ctx, mode, NULL);
+       else
+               SSL_CTX_set_verify(self->ctx, mode, 
global_verify_callback);
+
      Py_INCREF(Py_None);
      return Py_None;
  }






More information about the Twisted-Python mailing list