Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 1 | /* |
| 2 | * ssl.h |
| 3 | * |
| 4 | * Copyright (C) AB Strakt 2001, All rights reserved |
| 5 | * |
| 6 | * Export functions and exceptions from the SSL sub module. |
| 7 | * See the file RATIONALE for a short explanation of why this module was written. |
| 8 | * |
| 9 | * Reviewed 2001-07-23 |
| 10 | * |
| 11 | * @(#) $Id: ssl.h,v 1.6 2002/04/08 19:25:43 martin Exp $ |
| 12 | */ |
| 13 | #ifndef PyOpenSSL_SSL_H_ |
| 14 | #define PyOpenSSL_SSL_H_ |
| 15 | |
| 16 | #include <Python.h> |
Jean-Paul Calderone | 00db9da | 2008-09-21 17:42:34 -0400 | [diff] [blame] | 17 | #include <pythread.h> |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 18 | #include "context.h" |
| 19 | #include "connection.h" |
| 20 | #include "../util.h" |
| 21 | #include "../crypto/crypto.h" |
| 22 | |
| 23 | extern PyObject *ssl_Error, /* Base class */ |
| 24 | *ssl_ZeroReturnError, /* Used with SSL_get_erorr */ |
| 25 | *ssl_WantReadError, /* ... */ |
| 26 | *ssl_WantWriteError, /* ... */ |
| 27 | *ssl_WantX509LookupError, /* ... */ |
| 28 | *ssl_SysCallError; /* Uses (errno,errstr) */ |
| 29 | |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 30 | #define ssl_Context_New_NUM 0 |
| 31 | #define ssl_Context_New_RETURN ssl_ContextObj * |
| 32 | #define ssl_Context_New_PROTO (int method) |
| 33 | |
| 34 | #define ssl_Connection_New_NUM 1 |
| 35 | #define ssl_Connection_New_RETURN ssl_ConnectionObj * |
| 36 | #define ssl_Connection_New_PROTO (ssl_ContextObj *ctx, PyObject *sock) |
| 37 | |
| 38 | #define ssl_API_pointers 2 |
| 39 | |
Jean-Paul Calderone | 00db9da | 2008-09-21 17:42:34 -0400 | [diff] [blame] | 40 | #ifdef WITH_THREAD |
| 41 | extern int _pyOpenSSL_tstate_key; |
| 42 | #endif /* WITH_THREAD */ |
| 43 | |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 44 | #ifdef SSL_MODULE |
| 45 | |
| 46 | extern ssl_Context_New_RETURN ssl_Context_New ssl_Context_New_PROTO; |
| 47 | extern ssl_Connection_New_RETURN ssl_Connection_New ssl_Connection_New_PROTO; |
| 48 | |
Jean-Paul Calderone | f6d0328 | 2010-11-01 17:20:32 -0400 | [diff] [blame] | 49 | extern crypto_X509Obj* (*new_x509)(X509*, int); |
| 50 | extern crypto_X509NameObj* (*new_x509name)(X509_NAME*, int); |
| 51 | extern crypto_X509StoreObj* (*new_x509store)(X509_STORE*, int); |
Jean-Paul Calderone | 305626a | 2010-10-31 20:51:17 -0400 | [diff] [blame] | 52 | |
Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame] | 53 | #else /* SSL_MODULE */ |
| 54 | |
| 55 | extern void **ssl_API; |
| 56 | |
| 57 | #define ssl_Context_New \ |
| 58 | (*(ssl_Context_New_RETURN (*)ssl_Context_New_PROTO) ssl_API[ssl_Context_New_NUM]) |
| 59 | #define ssl_Connection_New \ |
| 60 | (*(ssl_Connection_New_RETURN (*)ssl_Connection_New_PROTO) ssl_API[ssl_Connection_New_NUM]) |
| 61 | |
| 62 | #define import_SSL() \ |
| 63 | { \ |
| 64 | PyObject *module = PyImport_ImportModule("OpenSSL.SSL"); \ |
| 65 | if (module != NULL) { \ |
| 66 | PyObject *module_dict = PyModule_GetDict(module); \ |
| 67 | PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \ |
| 68 | if (PyCObject_Check(c_api_object)) { \ |
| 69 | ssl_API = (void **)PyCObject_AsVoidPtr(c_api_object); \ |
| 70 | } \ |
| 71 | } \ |
| 72 | } |
| 73 | |
| 74 | #endif /* SSL_MODULE */ |
| 75 | |
| 76 | #endif /* PyOpenSSL_SSL_H_ */ |