Refer to new project home-page

This commit is contained in:
stroeder
2009-04-17 12:19:09 +00:00
parent ee42183fd7
commit f0b197b267
12 changed files with 543 additions and 0 deletions

52
Modules/LDAPObject.h Normal file
View File

@@ -0,0 +1,52 @@
/* See http://www.python-ldap.org/ for details.
* $Id: LDAPObject.h,v 1.10 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_LDAPObject
#define __h_LDAPObject
#include "common.h"
#include "lber.h"
#include "ldap.h"
#if LDAP_API_VERSION < 2000
#error Current python-ldap requires OpenLDAP 2.x
#endif
#if PYTHON_API_VERSION < 1007
typedef PyObject* _threadstate;
#else
typedef PyThreadState* _threadstate;
#endif
typedef struct {
PyObject_HEAD
LDAP* ldap;
_threadstate _save; /* for thread saving on referrals */
int valid;
} LDAPObject;
extern PyTypeObject LDAP_Type;
#define LDAPObject_Check(v) ((v)->ob_type == &LDAP_Type)
extern LDAPObject *newLDAPObject( LDAP* );
/* macros to allow thread saving in the context of an LDAP connection */
#define LDAP_BEGIN_ALLOW_THREADS( l ) \
{ \
LDAPObject *lo = (l); \
if (lo->_save != NULL) \
Py_FatalError( "saving thread twice?" ); \
lo->_save = PyEval_SaveThread(); \
}
#define LDAP_END_ALLOW_THREADS( l ) \
{ \
LDAPObject *lo = (l); \
_threadstate _save = lo->_save; \
lo->_save = NULL; \
PyEval_RestoreThread( _save ); \
}
#endif /* __h_LDAPObject */

19
Modules/common.c Normal file
View File

@@ -0,0 +1,19 @@
/* Miscellaneous common routines
* See http://www.python-ldap.org/ for details.
* $Id: common.c,v 1.3 2009/04/17 12:19:09 stroeder Exp $ */
#include "common.h"
/* dynamically add the methods into the module dictionary d */
void
LDAPadd_methods( PyObject* d, PyMethodDef* methods )
{
PyMethodDef *meth;
for( meth = methods; meth->ml_meth; meth++ ) {
PyObject *f = PyCFunction_New( meth, NULL );
PyDict_SetItemString( d, meth->ml_name, f );
Py_DECREF(f);
}
}

39
Modules/common.h Normal file
View File

@@ -0,0 +1,39 @@
/* common utility macros
* See http://www.python-ldap.org/ for details.
* $Id: common.h,v 1.8 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_common
#define __h_common
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#if defined(MS_WINDOWS)
#include <winsock.h>
#else /* unix */
#include <netdb.h>
#include <sys/time.h>
#include <sys/types.h>
#endif
/* Backwards compability with Python prior 2.5 */
#if PY_VERSION_HEX < 0x02050000
typedef int Py_ssize_t;
#define PY_SSIZE_T_MAX INT_MAX
#define PY_SSIZE_T_MIN INT_MIN
#endif
#include <string.h>
#define streq( a, b ) \
( (*(a)==*(b)) && 0==strcmp(a,b) )
void LDAPadd_methods( PyObject*d, PyMethodDef*methods );
#define PyNone_Check(o) ((o) == Py_None)
#endif /* __h_common_ */

19
Modules/constants.h Normal file
View File

@@ -0,0 +1,19 @@
/* See http://www.python-ldap.org/ for details.
* $Id: constants.h,v 1.6 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_constants_
#define __h_constants_
#include "common.h"
extern void LDAPinit_constants( PyObject* d );
extern PyObject* LDAPconstant( int );
#ifndef LDAP_CONTROL_PAGE_OID
#define LDAP_CONTROL_PAGE_OID "1.2.840.113556.1.4.319"
#endif /* !LDAP_CONTROL_PAGE_OID */
#ifndef LDAP_CONTROL_VALUESRETURNFILTER
#define LDAP_CONTROL_VALUESRETURNFILTER "1.2.826.0.1.3344810.2.3" /* RFC 3876 */
#endif /* !LDAP_CONTROL_VALUESRETURNFILTER */
#endif /* __h_constants_ */

16
Modules/errors.h Normal file
View File

@@ -0,0 +1,16 @@
/* See http://www.python-ldap.org/ for details.
* $Id: errors.h,v 1.6 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_errors_
#define __h_errors_
#include "common.h"
#include "lber.h"
#include "ldap.h"
extern PyObject* LDAPexception_class;
extern PyObject* LDAPerror( LDAP*, char*msg );
extern void LDAPinit_errors( PyObject* );
PyObject* LDAPerr(int errnum);
#endif /* __h_errors */

12
Modules/functions.h Normal file
View File

@@ -0,0 +1,12 @@
/* See http://www.python-ldap.org/ for details.
* $Id: functions.h,v 1.4 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_functions_
#define __h_functions_
/* $Id: functions.h,v 1.4 2009/04/17 12:19:09 stroeder Exp $ */
#include "common.h"
extern void LDAPinit_functions( PyObject* );
#endif /* __h_functions_ */

49
Modules/ldapmodule.c Normal file
View File

@@ -0,0 +1,49 @@
/* See http://www.python-ldap.org/ for details.
* $Id: ldapmodule.c,v 1.9 2009/04/17 12:19:09 stroeder Exp $ */
#include "common.h"
#include "version.h"
#include "constants.h"
#include "errors.h"
#include "functions.h"
#include "schema.h"
#include "ldapcontrol.h"
#include "LDAPObject.h"
DL_EXPORT(void) init_ldap(void);
/* dummy module methods */
static PyMethodDef methods[] = {
{ NULL, NULL }
};
/* module initialisation */
DL_EXPORT(void)
init_ldap()
{
PyObject *m, *d;
#if defined(MS_WINDOWS) || defined(__CYGWIN__)
LDAP_Type.ob_type = &PyType_Type;
#endif
/* Create the module and add the functions */
m = Py_InitModule("_ldap", methods);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
LDAPinit_version(d);
LDAPinit_constants(d);
LDAPinit_errors(d);
LDAPinit_functions(d);
LDAPinit_schema(d);
LDAPinit_control(d);
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module _ldap");
}

8
Modules/options.h Normal file
View File

@@ -0,0 +1,8 @@
/* See http://www.python-ldap.org/ for details.
* $Id: options.h,v 1.4 2009/04/17 12:19:09 stroeder Exp $ */
int LDAP_optionval_by_name(const char *name);
int LDAP_set_option(LDAPObject *self, int option, PyObject *value);
PyObject *LDAP_get_option(LDAPObject *self, int option);
void set_timeval_from_double( struct timeval *tv, double d );

283
Modules/schema.c Normal file
View File

@@ -0,0 +1,283 @@
/* See http://www.python-ldap.org/ for details.
* $Id: schema.c,v 1.8 2009/04/17 12:19:09 stroeder Exp $ */
#include "common.h"
#include "schema.h"
#include "ldap_schema.h"
/*
This utility function takes a null delimited C array of (null
delimited) C strings, creates its python equivalent and returns a
new reference to it. If the array is empty or the pointer to it is
NULL, an empty python array is returned.
*/
PyObject* c_string_array_to_python(char **string_array)
{
Py_ssize_t count = 0;
char **s;
PyObject *py_list;
if (string_array) {
for (s=string_array; *s != 0; s++) count++;
py_list = PyList_New(count);
count = 0;
for (s=string_array; *s != 0; s++){
PyList_SetItem(py_list, count, PyString_FromString(*s));
count++;
}
} else py_list=PyList_New(0);
return py_list;
}
/*
This function returns a list of tuples. The first entry of each
tuple is a string (lsei_name), and the second is a lists built from
lsei_values.
Probably the C data structure is modeled along the lines of a
mapping "lsei_name -> (list of lsei_values)". However, there seems
to be no guarantee that a lsei_name is unique, so I dare not use a
python mapping for this beast...
*/
PyObject* schema_extension_to_python(LDAPSchemaExtensionItem **extensions)
{
Py_ssize_t count = 0;
LDAPSchemaExtensionItem **e;
PyObject *py_list, *item_tuple;
if (extensions) {
for (e = extensions; *e !=0; e++) count++;
py_list = PyList_New(count);
count = 0;
for (e = extensions; *e !=0; e++) {
item_tuple = PyTuple_New(2);
PyTuple_SetItem(item_tuple, 0,
PyString_FromString((*e)->lsei_name));
PyTuple_SetItem(item_tuple, 1,
c_string_array_to_python((*e)->lsei_values));
PyList_SetItem(py_list, count, item_tuple);
count++;
}
}
else py_list=PyList_New(0);
return py_list;
}
/*
The following four functions do the boring job: they take a python
string, feed it into the respective parser functions provided by
openldap, and build a python list from the data structure returned
by the C function.
*/
static char doc_ldap_str2objectclass[] =
"";
static PyObject*
l_ldap_str2objectclass(PyObject* self, PyObject *args)
{
int ret=0, flag = LDAP_SCHEMA_ALLOW_NONE;
char *oc_string;
const char *errp;
LDAPObjectClass *o;
PyObject *oc_names, *oc_sup_oids, *oc_at_oids_must,
*oc_at_oids_may, *py_ret;
if (!PyArg_ParseTuple(args, "si", &oc_string, &flag))
return NULL;
o = ldap_str2objectclass( oc_string, &ret, &errp, flag);
if (ret) {
py_ret = PyInt_FromLong(ret);
return py_ret;
}
oc_sup_oids = c_string_array_to_python(o->oc_sup_oids);
oc_names = c_string_array_to_python(o->oc_names);
oc_at_oids_must = c_string_array_to_python(o->oc_at_oids_must);
oc_at_oids_may = c_string_array_to_python(o->oc_at_oids_may);
py_ret = PyList_New(9);
PyList_SetItem(py_ret, 0, PyString_FromString(o->oc_oid));
PyList_SetItem(py_ret, 1, oc_names);
if (o->oc_desc) {
PyList_SetItem(py_ret, 2, PyString_FromString(o->oc_desc));
} else {
PyList_SetItem(py_ret, 2, PyString_FromString(""));
}
PyList_SetItem(py_ret, 3, PyInt_FromLong(o->oc_obsolete));
PyList_SetItem(py_ret, 4, oc_sup_oids);
PyList_SetItem(py_ret, 5, PyInt_FromLong(o->oc_kind));
PyList_SetItem(py_ret, 6, oc_at_oids_must);
PyList_SetItem(py_ret, 7, oc_at_oids_may);
PyList_SetItem(py_ret, 8,
schema_extension_to_python(o->oc_extensions));
ldap_objectclass_free(o);
return py_ret;
}
static char doc_ldap_str2attributetype[] =
"";
static PyObject*
l_ldap_str2attributetype(PyObject* self, PyObject *args)
{
int ret=0, flag = LDAP_SCHEMA_ALLOW_NONE;
char *at_string;
const char *errp;
LDAPAttributeType *a;
PyObject *py_ret;
PyObject *at_names;
if (!PyArg_ParseTuple(args, "si", &at_string,&flag))
return NULL;
a = ldap_str2attributetype( at_string, &ret, &errp, flag);
if (ret) {
py_ret = PyInt_FromLong(ret);
return py_ret;
}
py_ret = PyList_New(15);
PyList_SetItem(py_ret, 0, PyString_FromString(a->at_oid));
at_names = c_string_array_to_python(a->at_names);
PyList_SetItem(py_ret, 1, at_names);
if (a->at_desc) {
PyList_SetItem(py_ret, 2, PyString_FromString(a->at_desc));
} else {
PyList_SetItem(py_ret, 2, PyString_FromString(""));
}
PyList_SetItem(py_ret, 3, PyInt_FromLong(a->at_obsolete));
if (a->at_sup_oid) {
PyList_SetItem(py_ret, 4, PyString_FromString(a->at_sup_oid));
} else {
PyList_SetItem(py_ret, 4, PyString_FromString(""));
}
if (a->at_equality_oid) {
PyList_SetItem(py_ret, 5, PyString_FromString(a->at_equality_oid));
} else {
PyList_SetItem(py_ret, 5, PyString_FromString(""));
}
if (a->at_ordering_oid) {
PyList_SetItem(py_ret, 6, PyString_FromString(a->at_ordering_oid));
} else {
PyList_SetItem(py_ret, 6, PyString_FromString(""));
}
if (a->at_substr_oid) {
PyList_SetItem(py_ret, 7, PyString_FromString(a->at_substr_oid));
} else {
PyList_SetItem(py_ret, 7, PyString_FromString(""));
}
if (a->at_syntax_oid) {
PyList_SetItem(py_ret, 8, PyString_FromString(a->at_syntax_oid));
} else {
PyList_SetItem(py_ret, 8, PyString_FromString(""));
}
PyList_SetItem(py_ret, 9, PyInt_FromLong(a->at_syntax_len));
PyList_SetItem(py_ret,10, PyInt_FromLong(a->at_single_value));
PyList_SetItem(py_ret,11, PyInt_FromLong(a->at_collective));
PyList_SetItem(py_ret,12, PyInt_FromLong(a->at_no_user_mod));
PyList_SetItem(py_ret,13, PyInt_FromLong(a->at_usage));
PyList_SetItem(py_ret, 14,
schema_extension_to_python(a->at_extensions));
ldap_attributetype_free(a);
return py_ret;
}
static char doc_ldap_str2syntax[] =
"";
static PyObject*
l_ldap_str2syntax(PyObject* self, PyObject *args)
{
LDAPSyntax *s;
int ret=0, flag = LDAP_SCHEMA_ALLOW_NONE;
const char *errp;
char *syn_string;
PyObject *py_ret, *syn_names;
if (!PyArg_ParseTuple(args, "si", &syn_string,&flag))
return NULL;
s = ldap_str2syntax(syn_string, &ret, &errp, flag);
if (ret) {
py_ret = PyInt_FromLong(ret);
return py_ret;
}
py_ret = PyList_New(4);
PyList_SetItem(py_ret, 0, PyString_FromString(s->syn_oid));
syn_names = c_string_array_to_python(s->syn_names);
PyList_SetItem(py_ret, 1, syn_names);
if (s->syn_desc) {
PyList_SetItem(py_ret, 2, PyString_FromString(s->syn_desc));
} else {
PyList_SetItem(py_ret, 2, PyString_FromString(""));
}
PyList_SetItem(py_ret, 3,
schema_extension_to_python(s->syn_extensions));
ldap_syntax_free(s);
return py_ret;
}
static char doc_ldap_str2matchingrule[] =
"";
static PyObject*
l_ldap_str2matchingrule(PyObject* self, PyObject *args)
{
LDAPMatchingRule *m;
int ret=0, flag = LDAP_SCHEMA_ALLOW_NONE;
const char *errp;
char *mr_string;
PyObject *py_ret, *mr_names;
if (!PyArg_ParseTuple(args, "si", &mr_string,&flag))
return NULL;
m = ldap_str2matchingrule(mr_string, &ret, &errp, flag);
if (ret) {
py_ret = PyInt_FromLong(ret);
return py_ret;
}
py_ret = PyList_New(6);
PyList_SetItem(py_ret, 0, PyString_FromString(m->mr_oid));
mr_names = c_string_array_to_python(m->mr_names);
PyList_SetItem(py_ret, 1, mr_names);
if (m->mr_desc) {
PyList_SetItem(py_ret, 2, PyString_FromString(m->mr_desc));
} else {
PyList_SetItem(py_ret, 2, PyString_FromString(""));
}
PyList_SetItem(py_ret, 3, PyInt_FromLong(m->mr_obsolete));
if (m->mr_syntax_oid) {
PyList_SetItem(py_ret, 4, PyString_FromString(m->mr_syntax_oid));
} else {
PyList_SetItem(py_ret, 4, PyString_FromString(""));
}
PyList_SetItem(py_ret, 5,
schema_extension_to_python(m->mr_extensions));
ldap_matchingrule_free(m);
return py_ret;
}
/* methods */
static PyMethodDef methods[] = {
{ "str2objectclass", (PyCFunction)l_ldap_str2objectclass, METH_VARARGS,
doc_ldap_str2objectclass },
{ "str2attributetype", (PyCFunction)l_ldap_str2attributetype,
METH_VARARGS, doc_ldap_str2attributetype },
{ "str2syntax", (PyCFunction)l_ldap_str2syntax,
METH_VARARGS, doc_ldap_str2syntax },
{ "str2matchingrule", (PyCFunction)l_ldap_str2matchingrule,
METH_VARARGS, doc_ldap_str2matchingrule },
{ NULL, NULL }
};
void
LDAPinit_schema( PyObject* d ) {
LDAPadd_methods( d, methods );
}

14
Modules/schema.h Normal file
View File

@@ -0,0 +1,14 @@
/* See http://www.python-ldap.org/ for details.
* $Id: schema.h,v 1.5 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_schema_
#define __h_schema_
#include "common.h"
extern void LDAPinit_schema( PyObject* );
#endif /* __h_schema_ */

20
Modules/version.c Normal file
View File

@@ -0,0 +1,20 @@
/* Set release version
* See http://www.python-ldap.org/ for details.
* $Id: version.c,v 1.4 2009/04/17 12:19:09 stroeder Exp $ */
#include "common.h"
#define _STR(x) #x
#define STR(x) _STR(x)
static char version_str[] = STR(LDAPMODULE_VERSION);
void
LDAPinit_version( PyObject* d )
{
PyObject *version;
version = PyString_FromString(version_str);
PyDict_SetItemString( d, "__version__", version );
Py_DECREF(version);
}

12
Modules/version.h Normal file
View File

@@ -0,0 +1,12 @@
/* Set release version
* See http://www.python-ldap.org/ for details.
* $Id: version.h,v 1.4 2009/04/17 12:19:09 stroeder Exp $ */
#ifndef __h_version_
#define __h_version_
#include "common.h"
extern void LDAPinit_version( PyObject* d );
#endif /* __h_version_ */