Prevent potential side effects and use local variables here
[pdns-ldap-backend/landonf.git] / src / ldaputils.cc
blob92d888b7ea0f8beceeaf6139882924b7b8d4b0bc
1 #include "ldaputils.hh"
2 #include <sys/time.h>
4 void ldapSetOption( LDAP *conn, int option, void *value )
6 if( ldap_set_option( conn, option, value ) != LDAP_OPT_SUCCESS )
8 throw( LDAPException( "Unable to set option" ) );
12 void ldapGetOption( LDAP *conn, int option, void *value )
14 if( ldap_get_option( conn, option, value ) != LDAP_OPT_SUCCESS )
16 throw( LDAPException( "Unable to get option" ) );
20 std::string ldapGetError( LDAP *conn, int code )
22 if ( code == -1 )
23 ldapGetOption( conn, LDAP_OPT_ERROR_NUMBER, &code );
24 return std::string( ldap_err2string( code ) );
27 int ldapWaitResult( LDAP *conn, int msgid, int timeout, LDAPMessage** result )
29 struct timeval tv;
30 LDAPMessage* res;
33 tv.tv_sec = timeout;
34 tv.tv_usec = 0;
36 int rc = ldap_result( conn, msgid, LDAP_MSG_ONE, &tv, &res );
38 if ( rc == -1 || rc == 0 )
39 return rc;
41 if( result == NULL )
43 ldap_msgfree( res );
44 return rc;
47 *result = res;
48 return rc;