917 static PyObject *
918 l_ldap_result4( LDAPObject* self, PyObject *args )
919 {
920 int msgid = LDAP_RES_ANY;
921 int all = 1;
922 double timeout = -1.0;
923 int add_ctrls = 0;
924 int add_intermediates = 0;
925 int add_extop = 0;
926 struct timeval tv;
927 struct timeval* tvp;
928 int res_type;
929 LDAPMessage *msg = NULL;
930 PyObject *result_str, *retval, *pmsg, *pyctrls = 0;
931 int res_msgid = 0;
932 char *retoid = 0;
933 PyObject *valuestr = 0;
934
935 if (!PyArg_ParseTuple( args, "|iidiii", &msgid, &all, &timeout, &add_ctrls, &add_intermediates, &add_extop ))
when _PyArg_ParseTuple_SizeT() succeeds
taking False path
936 return NULL;
937 if (not_valid(self)) return NULL;
when considering range: -0x80000000 <= value <= -1
taking True path
938
939 if (timeout >= 0) {
940 tvp = &tv;
941 set_timeval_from_double( tvp, timeout );
942 } else {
943 tvp = NULL;
944 }
945
946 LDAP_BEGIN_ALLOW_THREADS( self );
947 res_type = ldap_result( self->ldap, msgid, all, tvp, &msg );
948 LDAP_END_ALLOW_THREADS( self );
949
950 if (res_type < 0) /* LDAP or system error */
951 return LDAPerror( self->ldap, "ldap_result4" );
952
953 if (res_type == 0) {
954 /* Polls return (None, None, None, None); timeouts raise an exception */
955 if (timeout == 0) {
956 if (add_extop) {
957 return Py_BuildValue("(OOOOOO)", Py_None, Py_None, Py_None, Py_None, Py_None, Py_None);
958 } else {
959 return Py_BuildValue("(OOOO)", Py_None, Py_None, Py_None, Py_None);
960 }
961 }
962 else
963 return LDAPerr(LDAP_TIMEOUT);
964 }
965
966 if (msg)
967 res_msgid = ldap_msgid(msg);
968
969 int result = LDAP_SUCCESS;
970 char **refs = NULL;
971 LDAPControl **serverctrls = 0;
972 LDAP_BEGIN_ALLOW_THREADS( self );
973 if (res_type == LDAP_RES_SEARCH_ENTRY) {
974 /* LDAPmessage_to_python will parse entries and read the controls for each entry */
975 } else if (res_type == LDAP_RES_SEARCH_REFERENCE) {
976 /* LDAPmessage_to_python will parse refs and read the controls for each res */
977 } else if (res_type == LDAP_RES_INTERMEDIATE) {
978 /* LDAPmessage_to_python will parse intermediates and controls */
979 } else {
980 int rc;
981 if (res_type == LDAP_RES_EXTENDED) {
982 struct berval *retdata = 0;
983 rc = ldap_parse_extended_result( self->ldap, msg, &retoid, &retdata, 0 );
984 /* handle error rc!=0 here? */
985 if (rc == LDAP_SUCCESS) {
986 valuestr = LDAPberval_to_object(retdata);
987 }
988 ber_bvfree( retdata );
989 }
990
991 rc = ldap_parse_result( self->ldap, msg, &result, NULL, NULL, &refs,
992 &serverctrls, 0 );
993 }
994 LDAP_END_ALLOW_THREADS( self );
995
996 if (result != LDAP_SUCCESS) { /* result error */
997 char *e, err[1024];
998 if (result == LDAP_REFERRAL && refs && refs[0]) {
999 snprintf(err, sizeof(err), "Referral:\n%s", refs[0]);
1000 e = err;
1001 } else
1002 e = "ldap_parse_result";
1003 ldap_msgfree(msg);
1004 return LDAPerror( self->ldap, e );
1005 }
1006
1007 if (!(pyctrls = LDAPControls_to_List(serverctrls))) {
1008 int err = LDAP_NO_MEMORY;
1009 ldap_set_option(self->ldap, LDAP_OPT_ERROR_NUMBER, &err);
1010 ldap_msgfree(msg);
1011 return LDAPerror(self->ldap, "LDAPControls_to_List");
1012 }
1013 ldap_controls_free(serverctrls);
1014
1015 pmsg = LDAPmessage_to_python( self->ldap, msg, add_ctrls, add_intermediates );
1016
1017 result_str = LDAPconstant( res_type );
1018
1019 if (pmsg == NULL) {
1020 retval = NULL;
1021 } else {
1022 /* s handles NULL, but O does not */
1023 if (add_extop) {
1024 retval = Py_BuildValue("(OOiOsO)", result_str, pmsg, res_msgid,
1025 pyctrls, retoid, valuestr ? valuestr : Py_None);
1026 } else {
1027 retval = Py_BuildValue("(OOiO)", result_str, pmsg, res_msgid, pyctrls);
1028 }
1029
1030 if (pmsg != Py_None) {
1031 Py_DECREF(pmsg);
1032 }
1033 }
1034 if (valuestr) {
1035 Py_DECREF(valuestr);
1036 }
1037 Py_XDECREF(pyctrls);
1038 Py_DECREF(result_str);
1039 return retval;
1040 }
returning (PyObject*)NULL without setting an exception