Christian Heimes | 7f1305e | 2021-04-17 20:06:38 +0200 | [diff] [blame] | 1 | #ifndef Py_SSL_H |
| 2 | #define Py_SSL_H |
| 3 | |
| 4 | /* |
| 5 | * ssl module state |
| 6 | */ |
| 7 | typedef struct { |
| 8 | /* Types */ |
| 9 | PyTypeObject *PySSLContext_Type; |
| 10 | PyTypeObject *PySSLSocket_Type; |
| 11 | PyTypeObject *PySSLMemoryBIO_Type; |
| 12 | PyTypeObject *PySSLSession_Type; |
| 13 | /* SSL error object */ |
| 14 | PyObject *PySSLErrorObject; |
| 15 | PyObject *PySSLCertVerificationErrorObject; |
| 16 | PyObject *PySSLZeroReturnErrorObject; |
| 17 | PyObject *PySSLWantReadErrorObject; |
| 18 | PyObject *PySSLWantWriteErrorObject; |
| 19 | PyObject *PySSLSyscallErrorObject; |
| 20 | PyObject *PySSLEOFErrorObject; |
| 21 | /* Error mappings */ |
| 22 | PyObject *err_codes_to_names; |
| 23 | PyObject *err_names_to_codes; |
| 24 | PyObject *lib_codes_to_names; |
| 25 | /* socket type from module CAPI */ |
| 26 | PyTypeObject *Sock_Type; |
| 27 | } _sslmodulestate; |
| 28 | |
| 29 | static struct PyModuleDef _sslmodule_def; |
| 30 | |
| 31 | Py_LOCAL_INLINE(_sslmodulestate*) |
| 32 | get_ssl_state(PyObject *module) |
| 33 | { |
| 34 | void *state = PyModule_GetState(module); |
| 35 | assert(state != NULL); |
| 36 | return (_sslmodulestate *)state; |
| 37 | } |
| 38 | |
| 39 | #define get_state_type(type) \ |
| 40 | (get_ssl_state(_PyType_GetModuleByDef(type, &_sslmodule_def))) |
| 41 | #define get_state_ctx(c) (((PySSLContext *)(c))->state) |
| 42 | #define get_state_sock(s) (((PySSLSocket *)(s))->ctx->state) |
| 43 | #define get_state_mbio(b) ((_sslmodulestate *)PyType_GetModuleState(Py_TYPE(b))) |
| 44 | |
| 45 | #endif /* Py_SSL_H */ |