]> git.sur5r.net Git - openldap/commitdiff
Clean up LDAP_BOOL_GET and fetching via ldap_get_option().
authorKurt Zeilenga <kurt@openldap.org>
Mon, 31 May 1999 17:30:22 +0000 (17:30 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 31 May 1999 17:30:22 +0000 (17:30 +0000)
Modify apitest to test for non-zero instead of LDAP_OPT_ON.

libraries/liblber/memory.c
libraries/libldap/apitest.c
libraries/libldap/ldap-int.h
libraries/libldap/options.c
libraries/libldap/request.c
libraries/libldap/result.c

index d4bbdde8bcc0cdc9e0ee860758dee806086769fb..59e2258d3c6f7f17a96495d5b518784e13651f4d 100644 (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;
index 0274f392800b7bb755c9436cf46487c51ab33c90..e27028a8d6df4e5dc7d08c28072d52c2b5aeb6a2 100644 (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]);
index bd07b0b4ab77ce9fec51ed068a97710c2b72bb7a..684f3dc0248a2456a9ac5ac5900eccfaf0bf7fac 100644 (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)
index 149c83cc30dbc0f6b2b9efd3418f06b27732446e..f03382519efc99302895c66eaaba9cd327c501f2 100644 (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;
        }
index 5c5c00952555ab9ea636a60c4e1c01703461583a..3f7970f7cc1563304769358e6414517c525c9954 100644 (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 ) {
index aaf58fde244b1fe9cc036c5e326544a90496b851..81c12f80cee89914d60fc7c0a5045732df0b6424 100644 (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,