-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathldapmodule.c
More file actions
101 lines (83 loc) · 2.11 KB
/
ldapmodule.c
File metadata and controls
101 lines (83 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* See https://www.python-ldap.org/ for details. */
#include "common.h"
#include "constants.h"
#include "functions.h"
#include "ldapcontrol.h"
#include "LDAPObject.h"
#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit__ldap(void);
#else
PyMODINIT_FUNC init_ldap(void);
#endif
#define _STR(x) #x
#define STR(x) _STR(x)
static char version_str[] = STR(LDAPMODULE_VERSION);
static char author_str[] = STR(LDAPMODULE_AUTHOR);
static char license_str[] = STR(LDAPMODULE_LICENSE);
static void
init_pkginfo(PyObject *m)
{
PyModule_AddStringConstant(m, "__version__", version_str);
PyModule_AddStringConstant(m, "__author__", author_str);
PyModule_AddStringConstant(m, "__license__", license_str);
}
/* dummy module methods */
static PyMethodDef methods[] = {
{NULL, NULL}
};
/* module initialisation */
/* Common initialization code */
PyObject *
init_ldap_module(void)
{
PyObject *m, *d;
/* Create the module and add the functions */
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef ldap_moduledef = {
PyModuleDef_HEAD_INIT,
"_ldap", /* m_name */
"", /* m_doc */
-1, /* m_size */
methods, /* m_methods */
};
m = PyModule_Create(&ldap_moduledef);
#else
m = Py_InitModule("_ldap", methods);
#endif
/* Initialize LDAP class */
if (PyType_Ready(&LDAP_Type) < 0) {
Py_DECREF(m);
return NULL;
}
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
init_pkginfo(m);
if (LDAPinit_constants(m) == -1) {
return NULL;
}
LDAPinit_functions(d);
LDAPinit_control(d);
/* Marker for LDAPBytesWarning stack walking
* See _raise_byteswarning in ldapobject.py
*/
if (PyModule_AddIntConstant(m, "_LDAP_WARN_SKIP_FRAME", 1) != 0) {
return NULL;
}
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module _ldap");
return m;
}
#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC
init_ldap()
{
init_ldap_module();
}
#else
PyMODINIT_FUNC
PyInit__ldap()
{
return init_ldap_module();
}
#endif