3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdarg.h>
13 char ber_pvt_opt_on; /* used to get a non-NULL address for *_OPT_ON */
15 struct lber_options ber_int_options = {
16 LBER_UNINITIALIZED, 0, 0, 0 };
24 const BerElement *ber;
27 ber_int_options.lbo_valid = LBER_INITIALIZED;
29 if(outvalue == NULL) {
30 /* no place to get to */
31 ber_errno = LBER_ERROR_PARAM;
32 return LBER_OPT_ERROR;
36 if(option == LBER_OPT_BER_DEBUG) {
37 * (int *) outvalue = ber_int_debug;
38 return LBER_OPT_SUCCESS;
39 } else if(option == LBER_OPT_MEMORY_INUSE) {
40 /* The memory inuse is a global variable on kernal implementations.
41 * This means that memory debug is shared by all LDAP processes
42 * so for this variable to have much meaning, only one LDAP process
43 * should be running and memory inuse should be initialized to zero
44 * using the lber_set_option() function during startup.
45 * The counter is not accurate for multithreaded ldap applications.
47 #ifdef LDAP_MEMORY_DEBUG
48 * (int *) outvalue = ber_int_options.lbo_meminuse;
49 return LBER_OPT_SUCCESS;
51 return LBER_OPT_ERROR;
53 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
54 *((FILE**)outvalue) = (FILE*)ber_pvt_err_file;
55 return LBER_OPT_SUCCESS;
58 ber_errno = LBER_ERROR_PARAM;
59 return LBER_OPT_ERROR;
66 case LBER_OPT_BER_OPTIONS:
67 assert( LBER_VALID( ber ) );
68 * (int *) outvalue = ber->ber_options;
69 return LBER_OPT_SUCCESS;
71 case LBER_OPT_BER_DEBUG:
72 assert( LBER_VALID( ber ) );
73 * (int *) outvalue = ber->ber_debug;
74 return LBER_OPT_SUCCESS;
76 case LBER_OPT_BER_REMAINING_BYTES:
77 assert( LBER_VALID( ber ) );
78 *((ber_len_t *) outvalue) = ber_pvt_ber_remaining(ber);
79 return LBER_OPT_SUCCESS;
81 case LBER_OPT_BER_TOTAL_BYTES:
82 assert( LBER_VALID( ber ) );
83 *((ber_len_t *) outvalue) = ber_pvt_ber_total(ber);
84 return LBER_OPT_SUCCESS;
86 case LBER_OPT_BER_BYTES_TO_WRITE:
87 assert( LBER_VALID( ber ) );
88 *((ber_len_t *) outvalue) = ber_pvt_ber_write(ber);
89 return LBER_OPT_SUCCESS;
91 case LBER_OPT_BER_MEMCTX:
92 assert( LBER_VALID( ber ) );
93 *((void **) outvalue) = ber->ber_memctx;
94 return LBER_OPT_SUCCESS;
98 ber_errno = LBER_ERROR_PARAM;
102 return LBER_OPT_ERROR;
109 LDAP_CONST void *invalue)
114 if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
115 && ( ber_int_memory_fns == NULL )
116 && ( option == LBER_OPT_MEMORY_FNS )
117 && ( invalue != NULL ))
119 const BerMemoryFunctions *f =
120 (const BerMemoryFunctions *) invalue;
122 /* make sure all functions are provided */
123 if(!( f->bmf_malloc && f->bmf_calloc
124 && f->bmf_realloc && f->bmf_free ))
126 ber_errno = LBER_ERROR_PARAM;
127 return LBER_OPT_ERROR;
130 ber_int_memory_fns = (BerMemoryFunctions *)
131 (*(f->bmf_malloc))(sizeof(BerMemoryFunctions), NULL);
133 if ( ber_int_memory_fns == NULL ) {
134 ber_errno = LBER_ERROR_MEMORY;
135 return LBER_OPT_ERROR;
138 AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
140 ber_int_options.lbo_valid = LBER_INITIALIZED;
141 return LBER_OPT_SUCCESS;
144 ber_int_options.lbo_valid = LBER_INITIALIZED;
146 if(invalue == NULL) {
147 /* no place to set from */
148 ber_errno = LBER_ERROR_PARAM;
149 return LBER_OPT_ERROR;
153 if(option == LBER_OPT_BER_DEBUG) {
154 ber_int_debug = * (const int *) invalue;
155 return LBER_OPT_SUCCESS;
157 } else if(option == LBER_OPT_LOG_PRINT_FN) {
158 ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
159 return LBER_OPT_SUCCESS;
160 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
161 ber_pvt_err_file = (void *) invalue;
162 return LBER_OPT_SUCCESS;
163 } else if(option == LBER_OPT_MEMORY_INUSE) {
164 /* The memory inuse is a global variable on kernal implementations.
165 * This means that memory debug is shared by all LDAP processes
166 * so for this variable to have much meaning, only one LDAP process
167 * should be running and memory inuse should be initialized to zero
168 * using the lber_set_option() function during startup.
169 * The counter is not accurate for multithreaded applications.
171 #ifdef LDAP_MEMORY_DEBUG
172 ber_int_options.lbo_meminuse = * (int *) invalue;
173 return LBER_OPT_SUCCESS;
175 return LBER_OPT_ERROR;
177 } else if(option == LBER_OPT_LOG_PROC) {
178 ber_int_log_proc = (BER_LOG_FN)invalue;
181 ber_errno = LBER_ERROR_PARAM;
182 return LBER_OPT_ERROR;
189 case LBER_OPT_BER_OPTIONS:
190 assert( LBER_VALID( ber ) );
191 ber->ber_options = * (const int *) invalue;
192 return LBER_OPT_SUCCESS;
194 case LBER_OPT_BER_DEBUG:
195 assert( LBER_VALID( ber ) );
196 ber->ber_debug = * (const int *) invalue;
197 return LBER_OPT_SUCCESS;
199 case LBER_OPT_BER_REMAINING_BYTES:
200 assert( LBER_VALID( ber ) );
201 ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
202 return LBER_OPT_SUCCESS;
204 case LBER_OPT_BER_TOTAL_BYTES:
205 assert( LBER_VALID( ber ) );
206 ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
207 return LBER_OPT_SUCCESS;
209 case LBER_OPT_BER_BYTES_TO_WRITE:
210 assert( LBER_VALID( ber ) );
211 ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
212 return LBER_OPT_SUCCESS;
214 case LBER_OPT_BER_MEMCTX:
215 assert( LBER_VALID( ber ) );
216 ber->ber_memctx = *(void **)invalue;
217 return LBER_OPT_SUCCESS;
221 ber_errno = LBER_ERROR_PARAM;
225 return LBER_OPT_ERROR;