Skip to content

Commit

Permalink
Modules: Use LDAPControls_to_List in LDAP_get_option instead of inlin…
Browse files Browse the repository at this point in the history
…ing it
  • Loading branch information
Christian Heimes authored and Petr Viktorin committed Dec 4, 2017
1 parent c5ad802 commit 6f53205
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions Modules/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6f53205

Please sign in to comment.