@@ -1716,6 +1716,45 @@ context_wrap_socket(PySSLContext *self, PyObject *args, PyObject *kwds)
17161716 return (PyObject * ) newPySSLSocket (self -> ctx , sock , server_side );
17171717}
17181718
1719+ static PyObject *
1720+ session_stats (PySSLContext * self , PyObject * unused )
1721+ {
1722+ int r ;
1723+ PyObject * value , * stats = PyDict_New ();
1724+ if (!stats )
1725+ return NULL ;
1726+
1727+ #define ADD_STATS (SSL_NAME , KEY_NAME ) \
1728+ value = PyLong_FromLong(SSL_CTX_sess_ ## SSL_NAME (self->ctx)); \
1729+ if (value == NULL) \
1730+ goto error; \
1731+ r = PyDict_SetItemString(stats, KEY_NAME, value); \
1732+ Py_DECREF(value); \
1733+ if (r < 0) \
1734+ goto error;
1735+
1736+ ADD_STATS (number , "number" );
1737+ ADD_STATS (connect , "connect" );
1738+ ADD_STATS (connect_good , "connect_good" );
1739+ ADD_STATS (connect_renegotiate , "connect_renegotiate" );
1740+ ADD_STATS (accept , "accept" );
1741+ ADD_STATS (accept_good , "accept_good" );
1742+ ADD_STATS (accept_renegotiate , "accept_renegotiate" );
1743+ ADD_STATS (accept , "accept" );
1744+ ADD_STATS (hits , "hits" );
1745+ ADD_STATS (misses , "misses" );
1746+ ADD_STATS (timeouts , "timeouts" );
1747+ ADD_STATS (cache_full , "cache_full" );
1748+
1749+ #undef ADD_STATS
1750+
1751+ return stats ;
1752+
1753+ error :
1754+ Py_DECREF (stats );
1755+ return NULL ;
1756+ }
1757+
17191758static PyGetSetDef context_getsetlist [] = {
17201759 {"options" , (getter ) get_options ,
17211760 (setter ) set_options , NULL },
@@ -1733,6 +1772,8 @@ static struct PyMethodDef context_methods[] = {
17331772 METH_VARARGS | METH_KEYWORDS , NULL },
17341773 {"load_verify_locations" , (PyCFunction ) load_verify_locations ,
17351774 METH_VARARGS | METH_KEYWORDS , NULL },
1775+ {"session_stats" , (PyCFunction ) session_stats ,
1776+ METH_NOARGS , NULL },
17361777 {NULL , NULL } /* sentinel */
17371778};
17381779
0 commit comments