]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/options.c
bug fixes for ldap_msgtype and ldap_msgid
[openldap] / libraries / libldap / options.c
index b3dd1b4d58f3a9b073949b0c3405d4348be815aa..27d7c2db3aaf4dbe3b7a48dee5505d9a8ac2a325 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
@@ -11,6 +12,7 @@
 
 #include <ac/socket.h>
 #include <ac/string.h>
+#include <ac/time.h>
 
 #include "ldap-int.h"
 
@@ -78,11 +80,11 @@ static const LDAPAPIFeatureInfo features[] = {
 
 int
 ldap_get_option(
-       LDAP_CONST LDAP *ld,
+       LDAP    *ld,
        int             option,
        void    *outvalue)
 {
-       LDAP_CONST struct ldapoptions *lo;
+       const struct ldapoptions *lo;
 
        if( ldap_int_global_options.ldo_valid != LDAP_INITIALIZED ) {
                ldap_int_initialize();
@@ -155,6 +157,22 @@ ldap_get_option(
                * (ber_socket_t *) outvalue = ber_pvt_sb_get_desc( &(ld->ld_sb) );
                return LDAP_OPT_SUCCESS;
 
+       case LDAP_OPT_TIMEOUT:
+               /* the caller has to free outvalue ! */
+               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 )
+               {
+                       return LDAP_OPT_ERROR;
+               }
+               return LDAP_OPT_SUCCESS;
+
        case LDAP_OPT_DEREF:
                * (int *) outvalue = lo->ldo_deref;
                return LDAP_OPT_SUCCESS;
@@ -322,38 +340,8 @@ ldap_set_option(
                return LDAP_OPT_SUCCESS;
        }
 
-       if(invalue == NULL) {
-               /* no place to set from */
-               return LDAP_OPT_ERROR;
-       }
-
-       switch(option) {
-       case LDAP_OPT_API_INFO:
-       case LDAP_OPT_DESC:
-               /* READ ONLY */
-               break;
-
-       case LDAP_OPT_DEREF:
-               lo->ldo_deref = * (const int *) invalue;
-               return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_SIZELIMIT:
-               lo->ldo_sizelimit = * (const int *) invalue;
-               return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_TIMELIMIT:
-               lo->ldo_timelimit = * (const int *) invalue;
-               return LDAP_OPT_SUCCESS;
-
-       case LDAP_OPT_PROTOCOL_VERSION: {
-                       int vers = * (const int *) invalue;
-                       if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
-                               /* not supported */
-                               break;
-                       }
-                       ld->ld_version = vers;
-               } return LDAP_OPT_SUCCESS;
-
+       /* options which can withstand invalue == NULL */
+       switch ( option ) {
        case LDAP_OPT_SERVER_CONTROLS: {
                        LDAPControl *const *controls =
                                (LDAPControl *const *) invalue;
@@ -392,6 +380,70 @@ 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;
+       }
+
+       if(invalue == NULL) {
+               /* no place to set from */
+               return LDAP_OPT_ERROR;
+       }
+
+       /* options which cannot withstand invalue == NULL */
+
+       switch(option) {
+       case LDAP_OPT_API_INFO:
+       case LDAP_OPT_DESC:
+               /* READ ONLY */
+               break;
+
+       case LDAP_OPT_DEREF:
+               lo->ldo_deref = * (const int *) invalue;
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_SIZELIMIT:
+               lo->ldo_sizelimit = * (const int *) invalue;
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_TIMELIMIT:
+               lo->ldo_timelimit = * (const int *) invalue;
+               return LDAP_OPT_SUCCESS;
+
+       case LDAP_OPT_PROTOCOL_VERSION: {
+                       int vers = * (const int *) invalue;
+                       if (vers < LDAP_VERSION_MIN || vers > LDAP_VERSION_MAX) {
+                               /* not supported */
+                               break;
+                       }
+                       ld->ld_version = vers;
+               } return LDAP_OPT_SUCCESS;
+
+
        case LDAP_OPT_HOST_NAME: {
                        const char *host = (const char *) invalue;