Clean up LDAP_BOOL_GET and fetching via ldap_get_option().

Modify apitest to test for non-zero instead of LDAP_OPT_ON.
This commit is contained in:
Kurt Zeilenga 1999-05-31 17:30:22 +00:00
parent ae4c85b84f
commit 37636eabd3
6 changed files with 35 additions and 22 deletions

View File

@ -16,8 +16,14 @@ ber_memfree( void *p )
{
ber_int_options.lbo_valid = LBER_INITIALIZED;
/* catch p == NULL when debugging */
assert( p != NULL );
/* ignore p == NULL when not debugging */
if( p == NULL ) {
return;
}
if( ber_int_memory_fns == NULL ) {
free( p );
return;
@ -33,8 +39,14 @@ ber_memalloc( size_t s )
{
ber_int_options.lbo_valid = LBER_INITIALIZED;
/* catch s == 0 when debugging */
assert( s );
/* ignore s == 0 when not debugging */
if( s == 0 ) {
return NULL;
}
if( ber_int_memory_fns == NULL ) {
return malloc( s );
}
@ -49,8 +61,14 @@ ber_memcalloc( size_t n, size_t s )
{
ber_int_options.lbo_valid = LBER_INITIALIZED;
/* catch s,n == 0 when debugging */
assert( n && s );
/* ignore s,n == 0 when not debugging */
if( n == 0 || s == 0 ) {
return NULL;
}
if( ber_int_memory_fns == NULL ) {
return calloc( n, s );
}
@ -65,10 +83,12 @@ ber_memrealloc( void* p, size_t s )
{
ber_int_options.lbo_valid = LBER_INITIALIZED;
/* realloc(NULL,s) -> malloc(s) */
if( p == NULL ) {
return ber_memalloc( s );
}
/* realloc(p,0) -> free(p) */
if( s == 0 ) {
ber_memfree( p );
return NULL;

View File

@ -162,15 +162,13 @@ main(int argc, char **argv)
fprintf(stderr, "%s: ldap_get_option(referrals) failed\n", argv[0]);
return EXIT_FAILURE;
}
printf(" REFERRALS: %s\n",
ival == (int) LDAP_OPT_ON ? "on" : "off");
printf(" REFERRALS: %s\n", ival ? "on" : "off");
if(ldap_get_option(NULL, LDAP_OPT_RESTART, &ival) != LDAP_SUCCESS) {
fprintf(stderr, "%s: ldap_get_option(restart) failed\n", argv[0]);
return EXIT_FAILURE;
}
printf(" RESTART: %s\n",
ival == (int) LDAP_OPT_ON ? "on" : "off");
printf(" RESTART: %s\n", ival ? "on" : "off");
if(ldap_get_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ival) != LDAP_SUCCESS) {
fprintf(stderr, "%s: ldap_get_option(protocol version) failed\n", argv[0]);

View File

@ -56,7 +56,7 @@ LDAP_BEGIN_DECL
#define LDAP_BOOLEANS unsigned long
#define LDAP_BOOL(n) (1 << (n))
#define LDAP_BOOL_GET(lo, bool) ((lo)->ldo_booleans & LDAP_BOOL(bool) \
? LDAP_OPT_ON : LDAP_OPT_OFF)
? -1 : 0)
#define LDAP_BOOL_SET(lo, bool) ((lo)->ldo_booleans |= LDAP_BOOL(bool))
#define LDAP_BOOL_CLR(lo, bool) ((lo)->ldo_booleans &= ~LDAP_BOOL(bool))
#define LDAP_BOOL_ZERO(lo) ((lo)->ldo_booleans = 0)

View File

@ -167,18 +167,15 @@ ldap_get_option(
return LDAP_OPT_SUCCESS;
case LDAP_OPT_REFERRALS:
* (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS) ==
LDAP_OPT_ON);
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
return LDAP_OPT_SUCCESS;
case LDAP_OPT_RESTART:
* (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART) ==
LDAP_OPT_ON);
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
return LDAP_OPT_SUCCESS;
case LDAP_OPT_DNS: /* LDAPv2 */
* (int *) outvalue = (LDAP_BOOL_GET(lo, LDAP_BOOL_DNS) ==
LDAP_OPT_ON);
* (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
return LDAP_OPT_SUCCESS;
case LDAP_OPT_PROTOCOL_VERSION:
@ -320,18 +317,18 @@ ldap_set_option(
switch(option) {
case LDAP_OPT_REFERRALS:
if(invalue == LDAP_OPT_ON) {
LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
} else {
if(invalue == LDAP_OPT_OFF) {
LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
} else {
LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
}
return LDAP_OPT_SUCCESS;
case LDAP_OPT_RESTART:
if(invalue == LDAP_OPT_ON) {
LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
} else {
if(invalue == LDAP_OPT_OFF) {
LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
} else {
LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
}
return LDAP_OPT_SUCCESS;
}

View File

@ -110,7 +110,7 @@ ldap_send_initial_request(
#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
if (( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_DNS ) == LDAP_OPT_ON )
if ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_DNS ))
&& ldap_is_dns_dn( dn ) )
{
if (( servers = dn2servers( ld, dn )) == NULL ) {

View File

@ -196,8 +196,7 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
#endif
if ( rc == 0 || ( rc == -1 && (
( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
== LDAP_OPT_OFF )
!LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
|| errno != EINTR )))
{
ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
@ -341,8 +340,7 @@ try_read1msg( LDAP *ld, int msgid, int all, Sockbuf *sb,
if ( tag != LDAP_RES_SEARCH_ENTRY ) {
if ( ld->ld_version >= LDAP_VERSION2 &&
( lr->lr_parent != NULL ||
( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
!= LDAP_OPT_OFF ) ) )
LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS) ) )
{
tmpber = *ber; /* struct copy */
if ( ber_scanf( &tmpber, "{iaa}", &lderr,