]> git.sur5r.net Git - openldap/commitdiff
Split out ldapoptions from struct ldap to facilate global options.
authorKurt Zeilenga <kurt@openldap.org>
Mon, 9 Nov 1998 18:40:37 +0000 (18:40 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 9 Nov 1998 18:40:37 +0000 (18:40 +0000)
Add openldap_ldap_initialize() call to ldap_init/ldap_open/ldap_get/set_options.

libraries/libldap/init.c
libraries/libldap/ldap-int.h
libraries/libldap/open.c
libraries/libldap/options.c
libraries/libldap/request.c
libraries/libldap/result.c
libraries/libldap/test.c

index 1074bf96bea81fab351001ceb4d5017305eafad0..f457511493ee7ee7ebb9aee533b1b77c3cd53aa9 100644 (file)
@@ -9,7 +9,7 @@
 
 #include "ldap-int.h"
 
-struct ldap openldap_ld_globals;
+struct ldapoptions openldap_ldap_global_options;
 
 int    openldap_ldap_initialized = 0;
 
index 5bed6b379b113e7777832924c3539ca6077697d9..89402feec154ae6d878a6a0b44ac2473505d29c3 100644 (file)
@@ -34,12 +34,13 @@ LDAP_BEGIN_DECL
 #define LDAP_BOOL_RESTART              1
 #define LDAP_BOOL_DNS                  2
 
+#define LDAP_BOOLEANS  unsigned long
 #define LDAP_BOOL(n)   (1 << (n))
-#define LDAP_BOOL_GET(ld, bool)        ((ld)->ld_booleans & LDAP_BOOL(bool) \
+#define LDAP_BOOL_GET(lo, bool)        ((lo)->ldo_booleans & LDAP_BOOL(bool) \
                                                                        ?  LDAP_OPT_ON : LDAP_OPT_OFF)
-#define LDAP_BOOL_SET(ld, bool) ((ld)->ld_booleans |= LDAP_BOOL(bool))
-#define LDAP_BOOL_CLR(ld, bool) ((ld)->ld_booleans &= ~LDAP_BOOL(bool))
-#define LDAP_BOOL_ZERO(ld) ((ld)->ld_booleans = 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)
 
 /*
  * This structure represents both ldap messages and ldap responses.
@@ -56,25 +57,50 @@ struct ldapmsg {
        unsigned int    lm_time;        /* used to maintain cache */
 };
 
+/*
+ * structure representing get/set'able options
+ * which have global defaults.
+ */
+struct ldapoptions {
+       int             ldo_version;    /* version to connect at */
+       int             ldo_deref;
+       int             ldo_timelimit;
+       int             ldo_sizelimit;
+
+       int             ldo_cldaptries; /* connectionless search retry count */
+       int             ldo_cldaptimeout;/* time between retries */
+       int             ldo_refhoplimit;        /* limit on referral nesting */
+
+       LDAP_BOOLEANS ldo_booleans;     /* boolean options */
+};
+
 /*
  * structure representing an ldap connection
  */
 
 struct ldap {
        Sockbuf         ld_sb;          /* socket descriptor & buffer */
-       char            *ld_host;
-       int             ld_version;
-       char            ld_lberoptions;
-       int             ld_deref;
-       int             ld_timelimit;
-       int             ld_sizelimit;
+
+       struct ldapoptions ld_options;
+
+#define ld_deref               ld_options.ldo_deref
+#define ld_timelimit   ld_options.ldo_timelimit
+#define ld_sizelimit   ld_options.ldo_sizelimit
+
+#define ld_cldaptries  ld_options.ldo_cldaptries
+#define ld_cldaptimeout        ld_options.ldo_cldaptimeout
+#define ld_refhoplimit ld_options.ldo_refhoplimit
+
+       int             ld_version;             /* version connected at */
+       char    *ld_host;
+       char    ld_lberoptions;
 
        LDAPFiltDesc    *ld_filtd;      /* from getfilter for ufn searches */
        char            *ld_ufnprefix;  /* for incomplete ufn's */
 
        int             ld_errno;
-       char            *ld_error;
-       char            *ld_matched;
+       char    *ld_error;
+       char    *ld_matched;
        int             ld_msgid;
 
        /* do not mess with these */
@@ -89,17 +115,12 @@ struct ldap {
        LDAPCache       *ld_cache;      /* non-null if cache is initialized */
        char            *ld_cldapdn;    /* DN used in connectionless search */
 
-       /* it is OK to change these next four values directly */
-       int             ld_cldaptries;  /* connectionless search retry count */
-       int             ld_cldaptimeout;/* time between retries */
-       int             ld_refhoplimit; /* limit on referral nesting */
-       unsigned long   ld_booleans;    /* boolean options */
-
        /* do not mess with the rest though */
        char            *ld_defhost;    /* full name of default server */
        int             ld_defport;     /* port of default server */
        BERTranslateProc ld_lber_encode_translate_proc;
        BERTranslateProc ld_lber_decode_translate_proc;
+
 #ifdef LDAP_REFERRALS
        LDAPConn        *ld_defconn;    /* default connection */
        LDAPConn        *ld_conns;      /* list of server connections */
@@ -115,7 +136,7 @@ struct ldap {
  * in init.c
  */
 extern int openldap_ldap_initialized;
-extern struct ldap openldap_ld_globals;
+extern struct ldapoptions openldap_ldap_global_options;
 void openldap_ldap_initialize LDAP_P((void));
 
 /*
index 303c3ef4f7a8c14146a71295ef148db461098049..0cbb8736071e88a02bdc97dac1eef75d7eaeea31 100644 (file)
@@ -99,6 +99,10 @@ ldap_init( char *defhost, int defport )
 {
        LDAP                    *ld;
 
+       if(!openldap_ldap_initialized) {
+               openldap_ldap_initialize();
+       }
+
        Debug( LDAP_DEBUG_TRACE, "ldap_init\n", 0, 0, 0 );
 
 #ifdef HAVE_WINSOCK2
@@ -149,10 +153,10 @@ ldap_init( char *defhost, int defport )
                return( NULL );
        }
 
-       LDAP_BOOL_ZERO(ld);
-       LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+       LDAP_BOOL_ZERO(&ld->ld_options);
+       LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
 #else
-       LDAP_BOOL_ZERO(ld);
+       LDAP_BOOL_ZERO(&ld->ld_options);
 #endif
 
        if ( defhost != NULL &&
@@ -169,10 +173,10 @@ ldap_init( char *defhost, int defport )
        ld->ld_defport = ( defport == 0 ) ? LDAP_PORT : defport;
        ld->ld_version = LDAP_VERSION;
        ld->ld_lberoptions = LBER_USE_DER;
-       ld->ld_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
+       ld->ld_options.ldo_refhoplimit = LDAP_DEFAULT_REFHOPLIMIT;
 
 #ifdef LDAP_REFERRALS
-       LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+       LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
 #endif /* LDAP_REFERRALS */
 
 #if defined( STR_TRANSLATION ) && defined( LDAP_DEFAULT_CHARSET )
index 66ccfbd523b233acdd26245d2d238d67bac789c2..b52e95cc7866cd9e9e21b39f1a82359fc757e376 100644 (file)
 
 int
 ldap_get_option(
-       LDAP    *ldp,
+       LDAP    *ld,
        int             option,
        void    *outvalue)
 {
-       LDAP *ld;
+       struct ldapoptions *lo;
 
        if(!openldap_ldap_initialized) {
                openldap_ldap_initialize();
@@ -25,10 +25,10 @@ ldap_get_option(
                return -1;
        }
 
-       if(ldp == NULL) {
-               ld = &openldap_ld_globals;
+       if(ld == NULL) {
+               lo = &openldap_ldap_global_options;
        } else {
-               ld = ldp;
+               lo = &ld->ld_options;
        }
 
        switch(option) {
@@ -57,7 +57,7 @@ ldap_get_option(
                } break;
 
        case LDAP_OPT_DESC:
-               if(ldp == NULL) {
+               if(ld == NULL) {
                        /* bad param */
                        break;
                } 
@@ -66,30 +66,35 @@ ldap_get_option(
                return 0;
 
        case LDAP_OPT_DEREF:
-               * (int *) outvalue = ld->ld_deref;
+               * (int *) outvalue = lo->ldo_deref;
                return 0;
 
        case LDAP_OPT_SIZELIMIT:
-               * (int *) outvalue = ld->ld_sizelimit;
+               * (int *) outvalue = lo->ldo_sizelimit;
                return 0;
 
        case LDAP_OPT_TIMELIMIT:
-               * (int *) outvalue = ld->ld_timelimit;
+               * (int *) outvalue = lo->ldo_timelimit;
                return 0;
 
        case LDAP_OPT_REFERRALS:
-               * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_REFERRALS);
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_REFERRALS);
                return 0;
                
        case LDAP_OPT_RESTART:
-               * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART);
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_RESTART);
                return 0;
 
        case LDAP_OPT_DNS:      /* LDAPv2 */
-               * (int *) outvalue = (int) LDAP_BOOL_GET(ld, LDAP_BOOL_DNS);
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_DNS);
                return 0;
 
        case LDAP_OPT_PROTOCOL_VERSION:
+               if(ld == NULL) {
+                       /* bad param */
+                       break;
+               } 
+
                * (int *) outvalue = ld->ld_version;
                return 0;
 
@@ -99,15 +104,27 @@ ldap_get_option(
                break;
 
        case LDAP_OPT_HOST_NAME:
+               if(ld == NULL) {
+                       /* bad param */
+                       break;
+               } 
                * (char **) outvalue = ld->ld_host;
                return 0;
 
        case LDAP_OPT_ERROR_NUMBER:
+               if(ld == NULL) {
+                       /* bad param */
+                       break;
+               } 
                * (int *) outvalue = ld->ld_errno;
                return 0;
 
        case LDAP_OPT_ERROR_STRING:
                /* not yet supported */
+               if(ld == NULL) {
+                       /* bad param */
+                       break;
+               } 
                break;
 
        default:
@@ -120,11 +137,11 @@ ldap_get_option(
 
 int
 ldap_set_option(
-       LDAP    *ldp,
+       LDAP    *ld,
        int             option,
        void    *invalue)
 {
-       LDAP *ld;
+       struct ldapoptions *lo;
 
        if(!openldap_ldap_initialized) {
                openldap_ldap_initialize();
@@ -135,10 +152,10 @@ ldap_set_option(
                return -1;
        }
 
-       if(ldp == NULL) {
-               ld = &openldap_ld_globals;
+       if(ld == NULL) {
+               lo = &openldap_ldap_global_options;
        } else {
-               ld = ldp;
+               lo = &ld->ld_options;
        }
 
        switch(option) {
@@ -148,30 +165,30 @@ ldap_set_option(
                break;
 
        case LDAP_OPT_DEREF:
-               ld->ld_deref = * (int *) invalue;
+               lo->ldo_deref = * (int *) invalue;
                return 0;
 
        case LDAP_OPT_SIZELIMIT:
-               ld->ld_sizelimit = * (int *) invalue;
+               lo->ldo_sizelimit = * (int *) invalue;
                return 0;
 
        case LDAP_OPT_TIMELIMIT:
-               ld->ld_timelimit = * (int *) invalue;
+               lo->ldo_timelimit = * (int *) invalue;
                return 0;
 
        case LDAP_OPT_REFERRALS:
                if((int) invalue == (int) LDAP_OPT_ON) {
-                       LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+                       LDAP_BOOL_SET(lo, LDAP_BOOL_REFERRALS);
                } else {
-                       LDAP_BOOL_CLR(ld, LDAP_BOOL_REFERRALS);
+                       LDAP_BOOL_CLR(lo, LDAP_BOOL_REFERRALS);
                }
                return 0;
 
        case LDAP_OPT_RESTART:
                if((int) invalue == (int) LDAP_OPT_ON) {
-                       LDAP_BOOL_SET(ld, LDAP_BOOL_RESTART);
+                       LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
                } else {
-                       LDAP_BOOL_CLR(ld, LDAP_BOOL_RESTART);
+                       LDAP_BOOL_CLR(lo, LDAP_BOOL_RESTART);
                }
                return 0;
 
index de6ed9492f37e97ad5423e9dc311181960dcba01..7de337c59eece5331a9c0aa9463a6d17b9a31da5 100644 (file)
@@ -91,7 +91,7 @@ ldap_send_initial_request( LDAP *ld, unsigned long msgtype, char *dn,
 #else /* !LDAP_REFERRALS && !LDAP_DNS */
 
 #ifdef LDAP_DNS
-       if (( LDAP_BOOL_GET(ld, LDAP_BOOL_DNS ) == LDAP_OPT_ON )
+       if (( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_DNS ) == LDAP_OPT_ON )
                && ldap_is_dns_dn( dn ) )
        {
                if (( servers = dn2servers( ld, dn )) == NULL ) {
index c022a993c393afaf8af24c4fda498cb882d6ade8..182a13ccd7d4b19c9048861ad79fe7d8dbf40143 100644 (file)
@@ -169,7 +169,8 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
                        rc = ldap_select1( ld, tvp );
 
                        if ( rc == 0 || ( rc == -1 && (
-                               (LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART) == LDAP_OPT_OFF)
+                               ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
+                                       == LDAP_OPT_OFF )
                            || errno != EINTR ))) {
                                ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
                                    LDAP_TIMEOUT);
@@ -211,8 +212,10 @@ wait4msg( LDAP *ld, int msgid, int all, struct timeval *timeout,
 #endif
 
                        if ( rc == 0 || ( rc == -1 && (
-                               (LDAP_BOOL_GET(ld, LDAP_BOOL_RESTART) == LDAP_OPT_OFF)
-                               || errno != EINTR ))) {
+                               ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART)
+                                       == LDAP_OPT_OFF )
+                               || errno != EINTR )))
+                       {
                                ld->ld_errno = (rc == -1 ? LDAP_SERVER_DOWN :
                                    LDAP_TIMEOUT);
                                return( rc );
@@ -327,8 +330,10 @@ 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, LDAP_BOOL_REFERRALS) != LDAP_OPT_OFF))) {
+                       ( lr->lr_parent != NULL ||
+                       ( LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_REFERRALS)
+                               != LDAP_OPT_OFF ) ) )
+               {
                        tmpber = ber;   /* struct copy */
                        if ( ber_scanf( &tmpber, "{iaa}", &lderr,
                            &lr->lr_res_matched, &lr->lr_res_error )
index 6abfbe2bf7e7ddec3ab95b986cac8091df491797..43c02ca8fe0b36922ea5e05cff341f80e0bac4d0 100644 (file)
@@ -750,7 +750,7 @@ main( int argc, char **argv )
                        getline( line, sizeof(line), stdin, "sizelimit?" );
                        ld->ld_sizelimit = atoi( line );
 
-                       LDAP_BOOL_ZERO(ld);
+                       LDAP_BOOL_ZERO(&ld->ld_options);
 
 #ifdef STR_TRANSLATION
                        getline( line, sizeof(line), stdin,
@@ -775,7 +775,7 @@ main( int argc, char **argv )
                        getline( line, sizeof(line), stdin,
                                "Use DN & DNS to determine where to send requests (0=no, 1=yes)?" );
                        if ( atoi( line ) != 0 ) {
-                               LDAP_BOOL_SET(ld, LDAP_BOOL_DNS);
+                               LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_DNS);
                        }
 #endif /* LDAP_DNS */
 
@@ -783,7 +783,7 @@ main( int argc, char **argv )
                        getline( line, sizeof(line), stdin,
                                "Recognize and chase referrals (0=no, 1=yes)?" );
                        if ( atoi( line ) != 0 ) {
-                               LDAP_BOOL_SET(ld, LDAP_BOOL_REFERRALS);
+                               LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
                                getline( line, sizeof(line), stdin,
                                        "Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
                                if ( atoi( line ) != 0 ) {