X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libraries%2Fliblber%2Foptions.c;h=42a69acb6ce3b2db7e3a7eb2945db3557cb79ea2;hb=2dd578221b3dbaf7ba2308b63c3cc46154323cae;hp=c57ce60746e38861ae1b05c3914f4e219a7b9f7b;hpb=0e2af54a3ffdeebe3901370683be56fcc53023b0;p=openldap
diff --git a/libraries/liblber/options.c b/libraries/liblber/options.c
index c57ce60746..42a69acb6c 100644
--- a/libraries/liblber/options.c
+++ b/libraries/liblber/options.c
@@ -1,8 +1,18 @@
/* $OpenLDAP$ */
-/*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2011 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
*/
+
#include "portable.h"
#include
@@ -10,9 +20,13 @@
#include
#include "lber-int.h"
+char ber_pvt_opt_on; /* used to get a non-NULL address for *_OPT_ON */
+
struct lber_options ber_int_options = {
LBER_UNINITIALIZED, 0, 0 };
+static BerMemoryFunctions ber_int_memory_fns_datum;
+
int
ber_get_option(
void *item,
@@ -22,8 +36,6 @@ ber_get_option(
const BerElement *ber;
const Sockbuf *sb;
- ber_int_options.lbo_valid = LBER_INITIALIZED;
-
if(outvalue == NULL) {
/* no place to get to */
ber_errno = LBER_ERROR_PARAM;
@@ -31,10 +43,12 @@ ber_get_option(
}
if(item == NULL) {
- if(option == LBER_OPT_BER_DEBUG) {
+ switch ( option ) {
+ case LBER_OPT_BER_DEBUG:
* (int *) outvalue = ber_int_debug;
return LBER_OPT_SUCCESS;
- } else if(option == LBER_OPT_MEMORY_INUSE) {
+
+ case LBER_OPT_MEMORY_INUSE:
/* The memory inuse is a global variable on kernal implementations.
* This means that memory debug is shared by all LDAP processes
* so for this variable to have much meaning, only one LDAP process
@@ -43,12 +57,13 @@ ber_get_option(
* The counter is not accurate for multithreaded ldap applications.
*/
#ifdef LDAP_MEMORY_DEBUG
- * (int *) outvalue = ber_int_options.lbo_meminuse;
+ * (int *) outvalue = ber_int_meminuse;
return LBER_OPT_SUCCESS;
#else
return LBER_OPT_ERROR;
#endif
- } else if(option == LBER_OPT_LOG_PRINT_FILE) {
+
+ case LBER_OPT_LOG_PRINT_FILE:
*((FILE**)outvalue) = (FILE*)ber_pvt_err_file;
return LBER_OPT_SUCCESS;
}
@@ -86,6 +101,11 @@ ber_get_option(
*((ber_len_t *) outvalue) = ber_pvt_ber_write(ber);
return LBER_OPT_SUCCESS;
+ case LBER_OPT_BER_MEMCTX:
+ assert( LBER_VALID( ber ) );
+ *((void **) outvalue) = ber->ber_memctx;
+ return LBER_OPT_SUCCESS;
+
default:
/* bad param */
ber_errno = LBER_ERROR_PARAM;
@@ -104,38 +124,6 @@ ber_set_option(
BerElement *ber;
Sockbuf *sb;
- if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
- && ( ber_int_memory_fns == NULL )
- && ( option == LBER_OPT_MEMORY_FNS )
- && ( invalue != NULL ))
- {
- const BerMemoryFunctions *f =
- (const BerMemoryFunctions *) invalue;
-
- /* make sure all functions are provided */
- if(!( f->bmf_malloc && f->bmf_calloc
- && f->bmf_realloc && f->bmf_free ))
- {
- ber_errno = LBER_ERROR_PARAM;
- return LBER_OPT_ERROR;
- }
-
- ber_int_memory_fns = (BerMemoryFunctions *)
- (*(f->bmf_malloc))(sizeof(BerMemoryFunctions));
-
- if ( ber_int_memory_fns == NULL ) {
- ber_errno = LBER_ERROR_MEMORY;
- return LBER_OPT_ERROR;
- }
-
- AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
-
- ber_int_options.lbo_valid = LBER_INITIALIZED;
- return LBER_OPT_SUCCESS;
- }
-
- ber_int_options.lbo_valid = LBER_INITIALIZED;
-
if(invalue == NULL) {
/* no place to set from */
ber_errno = LBER_ERROR_PARAM;
@@ -143,17 +131,20 @@ ber_set_option(
}
if(item == NULL) {
- if(option == LBER_OPT_BER_DEBUG) {
+ switch ( option ) {
+ case LBER_OPT_BER_DEBUG:
ber_int_debug = * (const int *) invalue;
return LBER_OPT_SUCCESS;
- } else if(option == LBER_OPT_LOG_PRINT_FN) {
+ case LBER_OPT_LOG_PRINT_FN:
ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
return LBER_OPT_SUCCESS;
- } else if(option == LBER_OPT_LOG_PRINT_FILE) {
+
+ case LBER_OPT_LOG_PRINT_FILE:
ber_pvt_err_file = (void *) invalue;
return LBER_OPT_SUCCESS;
- } else if(option == LBER_OPT_MEMORY_INUSE) {
+
+ case LBER_OPT_MEMORY_INUSE:
/* The memory inuse is a global variable on kernal implementations.
* This means that memory debug is shared by all LDAP processes
* so for this variable to have much meaning, only one LDAP process
@@ -162,13 +153,36 @@ ber_set_option(
* The counter is not accurate for multithreaded applications.
*/
#ifdef LDAP_MEMORY_DEBUG
- ber_int_options.lbo_meminuse = * (int *) invalue;
+ ber_int_meminuse = * (int *) invalue;
return LBER_OPT_SUCCESS;
#else
return LBER_OPT_ERROR;
#endif
- } else if(option == LBER_OPT_LOG_PROC) {
+ case LBER_OPT_MEMORY_FNS:
+ if ( ber_int_memory_fns == NULL )
+ {
+ const BerMemoryFunctions *f =
+ (const BerMemoryFunctions *) invalue;
+ /* make sure all functions are provided */
+ if(!( f->bmf_malloc && f->bmf_calloc
+ && f->bmf_realloc && f->bmf_free ))
+ {
+ ber_errno = LBER_ERROR_PARAM;
+ return LBER_OPT_ERROR;
+ }
+
+ ber_int_memory_fns = &ber_int_memory_fns_datum;
+
+ AC_MEMCPY(ber_int_memory_fns, f,
+ sizeof(BerMemoryFunctions));
+
+ return LBER_OPT_SUCCESS;
+ }
+ break;
+
+ case LBER_OPT_LOG_PROC:
ber_int_log_proc = (BER_LOG_FN)invalue;
+ return LBER_OPT_SUCCESS;
}
ber_errno = LBER_ERROR_PARAM;
@@ -204,6 +218,11 @@ ber_set_option(
ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
return LBER_OPT_SUCCESS;
+ case LBER_OPT_BER_MEMCTX:
+ assert( LBER_VALID( ber ) );
+ ber->ber_memctx = *(void **)invalue;
+ return LBER_OPT_SUCCESS;
+
default:
/* bad param */
ber_errno = LBER_ERROR_PARAM;