diff --git a/Modules/options.c b/Modules/options.c index ac1eab6..f5bae42 100644 --- a/Modules/options.c +++ b/Modules/options.c @@ -180,10 +180,9 @@ LDAP_get_option(LDAPObject *self, int option) struct timeval *tv; LDAPAPIInfo apiinfo; LDAPControl **lcs; - LDAPControl *lc; char *strval; - PyObject *extensions, *v, *tup; - Py_ssize_t i, num_extensions, num_controls; + PyObject *extensions, *v; + Py_ssize_t i, num_extensions; LDAP *ld; ld = self ? self->ldap : NULL; @@ -352,27 +351,8 @@ LDAP_get_option(LDAPObject *self, int option) if (res != LDAP_OPT_SUCCESS) return option_error(res, "ldap_get_option"); - if (lcs == NULL) - return PyList_New(0); - - /* Get the number of controls */ - num_controls = 0; - while (lcs[num_controls]) - num_controls++; - - /* We'll build a list of controls, with each control a tuple */ - v = PyList_New(num_controls); - for (i = 0; i < num_controls; i++) { - lc = lcs[i]; - tup = Py_BuildValue("(sbs)", - lc->ldctl_oid, - lc->ldctl_iscritical, - lc->ldctl_value.bv_val); - PyList_SET_ITEM(v, i, tup); - } - + v = LDAPControls_to_List(lcs); ldap_controls_free(lcs); - return v; default: