+/* $OpenLDAP$ */
/*
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
#include <ac/socket.h>
#include <ac/string.h>
+#include <ac/time.h>
#include "ldap-int.h"
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();
}
- if(outvalue == NULL) {
- /* no place to get to */
- return LDAP_OPT_ERROR;
- }
-
if(ld == NULL) {
lo = &ldap_int_global_options;
lo = &ld->ld_options;
}
+ if(outvalue == NULL) {
+ /* no place to get to */
+ return LDAP_OPT_ERROR;
+ }
+
switch(option) {
case LDAP_OPT_API_INFO: {
struct ldapapiinfo *info = (struct ldapapiinfo *) outvalue;
* (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;
return LDAP_OPT_SUCCESS;
default:
+#ifdef HAVE_TLS
+ if ( ldap_pvt_tls_get_option(lo, option, outvalue ) == 0 )
+ return LDAP_OPT_SUCCESS;
+#endif
/* bad param */
break;
}
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 = * (int *) invalue;
- return LDAP_OPT_SUCCESS;
-
- case LDAP_OPT_SIZELIMIT:
- lo->ldo_sizelimit = * (int *) invalue;
- return LDAP_OPT_SUCCESS;
-
- case LDAP_OPT_TIMELIMIT:
- lo->ldo_timelimit = * (int *) invalue;
- return LDAP_OPT_SUCCESS;
-
- case LDAP_OPT_PROTOCOL_VERSION: {
- int vers = * (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 **controls = (LDAPControl **) invalue;
+ LDAPControl *const *controls =
+ (LDAPControl *const *) invalue;
ldap_controls_free( lo->ldo_sctrls );
return LDAP_OPT_SUCCESS;
}
- lo->ldo_sctrls =
- ldap_controls_dup( (LDAPControl **) invalue );
+ lo->ldo_sctrls = ldap_controls_dup( controls );
if(lo->ldo_sctrls == NULL) {
/* memory allocation error ? */
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_CLIENT_CONTROLS: {
- LDAPControl **controls = (LDAPControl **) invalue;
+ LDAPControl *const *controls =
+ (LDAPControl *const *) invalue;
ldap_controls_free( lo->ldo_cctrls );
return LDAP_OPT_SUCCESS;
}
- lo->ldo_cctrls =
- ldap_controls_dup( (LDAPControl **) invalue );
+ lo->ldo_cctrls = ldap_controls_dup( controls );
if(lo->ldo_cctrls == NULL) {
/* memory allocation error ? */
}
} 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: {
- char* host = (char *) invalue;
+ const char *host = (const char *) invalue;
if(lo->ldo_defhost != NULL) {
LDAP_FREE(lo->ldo_defhost);
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_NUMBER: {
- int err = * (int *) invalue;
+ int err = * (const int *) invalue;
if(ld == NULL) {
/* need a struct ldap */
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_ERROR_STRING: {
- char* err = (char *) invalue;
+ const char *err = (const char *) invalue;
if(ld == NULL) {
/* need a struct ldap */
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_MATCHED_DN: {
- char* err = (char *) invalue;
+ const char *err = (const char *) invalue;
if(ld == NULL) {
/* need a struct ldap */
break;
case LDAP_OPT_DEBUG_LEVEL:
- lo->ldo_debug = * (int *) invalue;
+ lo->ldo_debug = * (const int *) invalue;
return LDAP_OPT_SUCCESS;
default:
+#ifdef HAVE_TLS
+ if ( ldap_pvt_tls_set_option( lo, option, invalue ) == 0 )
+ return LDAP_OPT_SUCCESS;
+#endif
/* bad param */
break;
}