File: ldapmodule.c

package info (click to toggle)
python-ldap 3.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,756 kB
  • sloc: python: 9,558; ansic: 3,052; makefile: 139; sh: 79
file content (94 lines) | stat: -rw-r--r-- 1,956 bytes parent folder | download | duplicates (2)
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
/* 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);

    /* 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