]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/options.c
Fix missed rev 1.88 commit
[openldap] / libraries / libldap / options.c
index cca205a0d97b11f52dfeebc73b683fd71602b199..329047143100d217e65b86d92375d97f974727fb 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2006 The OpenLDAP Foundation.
+ * Copyright 1998-2008 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -177,14 +177,18 @@ ldap_get_option(
 
        case LDAP_OPT_TIMEOUT:
                /* the caller has to free outvalue ! */
-               if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_api) != 0 ) {
+               if ( lo->ldo_tm_api.tv_sec < 0 ) {
+                       *(void **)outvalue = NULL;
+               } else if ( ldap_int_timeval_dup( outvalue, &lo->ldo_tm_api ) != 0 ) {
                        return LDAP_OPT_ERROR;
                }
                return LDAP_OPT_SUCCESS;
                
        case LDAP_OPT_NETWORK_TIMEOUT:
                /* the caller has to free outvalue ! */
-               if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_net ) != 0 ) {
+               if ( lo->ldo_tm_net.tv_sec < 0 ) {
+                       *(void **)outvalue = NULL;
+               } else if ( ldap_int_timeval_dup( outvalue, &lo->ldo_tm_net ) != 0 ) {
                        return LDAP_OPT_ERROR;
                }
                return LDAP_OPT_SUCCESS;
@@ -242,7 +246,26 @@ ldap_get_option(
 
                return LDAP_OPT_SUCCESS;
 
-       case LDAP_OPT_ERROR_NUMBER:
+       case LDAP_OPT_CONNECT_ASYNC:
+               * (int *) outvalue = (int) LDAP_BOOL_GET(lo, LDAP_BOOL_CONNECT_ASYNC);
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_CONNECT_CB:
+               {
+                       /* Getting deletes the specified callback */
+                       ldaplist **ll = &lo->ldo_conn_cbs;
+                       for (;*ll;ll = &(*ll)->ll_next) {
+                               if ((*ll)->ll_data == outvalue) {
+                                       ldaplist *lc = *ll;
+                                       *ll = lc->ll_next;
+                                       LDAP_FREE(lc);
+                                       break;
+                               }
+                       }
+               }
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_RESULT_CODE:
                if(ld == NULL) {
                        /* bad param */
                        break;
@@ -250,7 +273,7 @@ ldap_get_option(
                * (int *) outvalue = ld->ld_errno;
                return LDAP_OPT_SUCCESS;
 
-       case LDAP_OPT_ERROR_STRING:
+       case LDAP_OPT_DIAGNOSTIC_MESSAGE:
                if(ld == NULL) {
                        /* bad param */
                        break;
@@ -330,6 +353,11 @@ ldap_get_option(
                if ( ldap_int_sasl_get_option( ld, option, outvalue ) == 0 ) {
                        return LDAP_OPT_SUCCESS;
                }
+#endif
+#ifdef HAVE_GSSAPI
+               if ( ldap_int_gssapi_get_option( ld, option, outvalue ) == 0 ) {
+                       return LDAP_OPT_SUCCESS;
+               }
 #endif
                /* bad param */
                break;
@@ -392,6 +420,14 @@ ldap_set_option(
                        LDAP_BOOL_SET(lo, LDAP_BOOL_RESTART);
                }
                return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_CONNECT_ASYNC:
+               if(invalue == LDAP_OPT_OFF) {
+                       LDAP_BOOL_CLR(lo, LDAP_BOOL_CONNECT_ASYNC);
+               } else {
+                       LDAP_BOOL_SET(lo, LDAP_BOOL_CONNECT_ASYNC);
+               }
+               return LDAP_OPT_SUCCESS;
        }
 
        /* options which can withstand invalue == NULL */
@@ -436,33 +472,6 @@ ldap_set_option(
                        }
                } return LDAP_OPT_SUCCESS;
 
-       case LDAP_OPT_TIMEOUT: {
-                       const struct timeval *tv = 
-                               (const struct timeval *) invalue;
-
-                       if ( lo->ldo_tm_api != NULL ) {
-                               LDAP_FREE( lo->ldo_tm_api );
-                               lo->ldo_tm_api = NULL;
-                       }
-
-                       if ( ldap_int_timeval_dup( &lo->ldo_tm_api, tv ) != 0 ) {
-                               return LDAP_OPT_ERROR;
-                       }
-               } return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_NETWORK_TIMEOUT: {
-                       const struct timeval *tv = 
-                               (const struct timeval *) invalue;
-
-                       if ( lo->ldo_tm_net != NULL ) {
-                               LDAP_FREE( lo->ldo_tm_net );
-                               lo->ldo_tm_net = NULL;
-                       }
-
-                       if ( ldap_int_timeval_dup( &lo->ldo_tm_net, tv ) != 0 ) {
-                               return LDAP_OPT_ERROR;
-                       }
-               } return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_HOST_NAME: {
                        const char *host = (const char *) invalue;
@@ -578,7 +587,7 @@ ldap_set_option(
                        lo->ldo_defbase = defbase;
                } return LDAP_OPT_SUCCESS;
 
-       case LDAP_OPT_ERROR_STRING: {
+       case LDAP_OPT_DIAGNOSTIC_MESSAGE: {
                        const char *err = (const char *) invalue;
 
                        if(ld == NULL) {
@@ -658,6 +667,7 @@ ldap_set_option(
        /* read-only options */
        case LDAP_OPT_API_INFO:
        case LDAP_OPT_DESC:
+       case LDAP_OPT_SOCKBUF:
        case LDAP_OPT_API_FEATURE_INFO:
                return LDAP_OPT_ERROR;
 
@@ -666,8 +676,11 @@ ldap_set_option(
        case LDAP_OPT_SIZELIMIT:
        case LDAP_OPT_TIMELIMIT:
        case LDAP_OPT_PROTOCOL_VERSION:
-       case LDAP_OPT_ERROR_NUMBER:
+       case LDAP_OPT_RESULT_CODE:
        case LDAP_OPT_DEBUG_LEVEL:
+       case LDAP_OPT_TIMEOUT:
+       case LDAP_OPT_NETWORK_TIMEOUT:
+       case LDAP_OPT_CONNECT_CB:
                if(invalue == NULL) {
                        /* no place to set from */
                        return LDAP_OPT_ERROR;
@@ -682,6 +695,10 @@ ldap_set_option(
 #ifdef HAVE_CYRUS_SASL
                if ( ldap_int_sasl_set_option( ld, option, (void *)invalue ) == 0 )
                        return LDAP_OPT_SUCCESS;
+#endif
+#ifdef HAVE_GSSAPI
+               if ( ldap_int_gssapi_set_option( ld, option, (void *)invalue ) == 0 )
+                       return LDAP_OPT_SUCCESS;
 #endif
                /* bad param */
                return LDAP_OPT_ERROR;
@@ -691,17 +708,34 @@ ldap_set_option(
 
        switch(option) {
        case LDAP_OPT_DEREF:
+               /* FIXME: check value for protocol compliance? */
                lo->ldo_deref = * (const int *) invalue;
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_SIZELIMIT:
+               /* FIXME: check value for protocol compliance? */
                lo->ldo_sizelimit = * (const int *) invalue;
                return LDAP_OPT_SUCCESS;
 
        case LDAP_OPT_TIMELIMIT:
+               /* FIXME: check value for protocol compliance? */
                lo->ldo_timelimit = * (const int *) invalue;
                return LDAP_OPT_SUCCESS;
 
+       case LDAP_OPT_TIMEOUT: {
+                       const struct timeval *tv = 
+                               (const struct timeval *) invalue;
+
+                       lo->ldo_tm_api = *tv;
+               } return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_NETWORK_TIMEOUT: {
+                       const struct timeval *tv = 
+                               (const struct timeval *) invalue;
+
+                       lo->ldo_tm_net = *tv;
+               } return LDAP_OPT_SUCCESS;
+
        case LDAP_OPT_PROTOCOL_VERSION: {
                        int vers = * (const int *) invalue;
                        if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
@@ -711,7 +745,7 @@ ldap_set_option(
                        lo->ldo_version = vers;
                } return LDAP_OPT_SUCCESS;
 
-       case LDAP_OPT_ERROR_NUMBER: {
+       case LDAP_OPT_RESULT_CODE: {
                        int err = * (const int *) invalue;
 
                        if(ld == NULL) {
@@ -725,6 +759,17 @@ ldap_set_option(
        case LDAP_OPT_DEBUG_LEVEL:
                lo->ldo_debug = * (const int *) invalue;
                return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_CONNECT_CB:
+               {
+                       /* setting pushes the callback */
+                       ldaplist *ll;
+                       ll = LDAP_MALLOC( sizeof( *ll ));
+                       ll->ll_data = (void *)invalue;
+                       ll->ll_next = lo->ldo_conn_cbs;
+                       lo->ldo_conn_cbs = ll;
+               }
+               return LDAP_OPT_SUCCESS;
        }
        return LDAP_OPT_ERROR;
 }