3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdarg.h>
14 extern void * ber_pvt_err_file;
15 extern BER_LOG_FN ber_int_log_proc;
17 struct lber_options ber_int_options = {
18 LBER_UNINITIALIZED, 0, 0 };
26 const BerElement *ber;
29 ber_int_options.lbo_valid = LBER_INITIALIZED;
31 if(outvalue == NULL) {
32 /* no place to get to */
33 ber_errno = LBER_ERROR_PARAM;
34 return LBER_OPT_ERROR;
38 if(option == LBER_OPT_BER_DEBUG) {
39 * (int *) outvalue = ber_int_debug;
40 return LBER_OPT_SUCCESS;
41 } else if(option == LBER_OPT_MEMORY_INUSE) {
42 /* The memory inuse is a global variable on kernal implementations.
43 * This means that memory debug is shared by all LDAP processes
44 * so for this variable to have much meaning, only one LDAP process
45 * should be running and memory inuse should be initialized to zero
46 * using the lber_set_option() function during startup.
47 * The counter is not accurate for multithreaded ldap applications.
49 #ifdef LDAP_MEMORY_DEBUG
50 * (int *) outvalue = ber_int_options.lbo_meminuse;
51 return LBER_OPT_SUCCESS;
53 return LBER_OPT_ERROR;
55 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
56 *((FILE**)outvalue) = (FILE*)ber_pvt_err_file;
57 return LBER_OPT_SUCCESS;
60 ber_errno = LBER_ERROR_PARAM;
61 return LBER_OPT_ERROR;
68 case LBER_OPT_BER_OPTIONS:
69 assert( LBER_VALID( ber ) );
70 * (int *) outvalue = ber->ber_options;
71 return LBER_OPT_SUCCESS;
73 case LBER_OPT_BER_DEBUG:
74 assert( LBER_VALID( ber ) );
75 * (int *) outvalue = ber->ber_debug;
76 return LBER_OPT_SUCCESS;
78 case LBER_OPT_BER_REMAINING_BYTES:
79 assert( LBER_VALID( ber ) );
80 *((ber_len_t *) outvalue) = ber_pvt_ber_remaining(ber);
81 return LBER_OPT_SUCCESS;
83 case LBER_OPT_BER_TOTAL_BYTES:
84 assert( LBER_VALID( ber ) );
85 *((ber_len_t *) outvalue) = ber_pvt_ber_total(ber);
86 return LBER_OPT_SUCCESS;
88 case LBER_OPT_BER_BYTES_TO_WRITE:
89 assert( LBER_VALID( ber ) );
90 *((ber_len_t *) outvalue) = ber_pvt_ber_write(ber);
91 return LBER_OPT_SUCCESS;
95 ber_errno = LBER_ERROR_PARAM;
99 return LBER_OPT_ERROR;
106 LDAP_CONST void *invalue)
111 if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
112 && ( ber_int_memory_fns == NULL )
113 && ( option == LBER_OPT_MEMORY_FNS )
114 && ( invalue != NULL ))
116 const BerMemoryFunctions *f =
117 (const BerMemoryFunctions *) invalue;
119 /* make sure all functions are provided */
120 if(!( f->bmf_malloc && f->bmf_calloc
121 && f->bmf_realloc && f->bmf_free ))
123 ber_errno = LBER_ERROR_PARAM;
124 return LBER_OPT_ERROR;
127 ber_int_memory_fns = (BerMemoryFunctions *)
128 (*(f->bmf_malloc))(sizeof(BerMemoryFunctions));
130 if ( ber_int_memory_fns == NULL ) {
131 ber_errno = LBER_ERROR_MEMORY;
132 return LBER_OPT_ERROR;
135 AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
137 ber_int_options.lbo_valid = LBER_INITIALIZED;
138 return LBER_OPT_SUCCESS;
141 ber_int_options.lbo_valid = LBER_INITIALIZED;
143 if(invalue == NULL) {
144 /* no place to set from */
145 ber_errno = LBER_ERROR_PARAM;
146 return LBER_OPT_ERROR;
150 if(option == LBER_OPT_BER_DEBUG) {
151 ber_int_debug = * (const int *) invalue;
152 return LBER_OPT_SUCCESS;
154 } else if(option == LBER_OPT_LOG_PRINT_FN) {
155 ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
156 return LBER_OPT_SUCCESS;
157 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
158 ber_pvt_err_file = (void *) invalue;
159 return LBER_OPT_SUCCESS;
160 } else if(option == LBER_OPT_MEMORY_INUSE) {
161 /* The memory inuse is a global variable on kernal implementations.
162 * This means that memory debug is shared by all LDAP processes
163 * so for this variable to have much meaning, only one LDAP process
164 * should be running and memory inuse should be initialized to zero
165 * using the lber_set_option() function during startup.
166 * The counter is not accurate for multithreaded applications.
168 #ifdef LDAP_MEMORY_DEBUG
169 ber_int_options.lbo_meminuse = * (int *) invalue;
170 return LBER_OPT_SUCCESS;
172 return LBER_OPT_ERROR;
174 } else if(option == LBER_OPT_LOG_PROC) {
175 ber_int_log_proc = (BER_LOG_FN)invalue;
178 ber_errno = LBER_ERROR_PARAM;
179 return LBER_OPT_ERROR;
186 case LBER_OPT_BER_OPTIONS:
187 assert( LBER_VALID( ber ) );
188 ber->ber_options = * (const int *) invalue;
189 return LBER_OPT_SUCCESS;
191 case LBER_OPT_BER_DEBUG:
192 assert( LBER_VALID( ber ) );
193 ber->ber_debug = * (const int *) invalue;
194 return LBER_OPT_SUCCESS;
196 case LBER_OPT_BER_REMAINING_BYTES:
197 assert( LBER_VALID( ber ) );
198 ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
199 return LBER_OPT_SUCCESS;
201 case LBER_OPT_BER_TOTAL_BYTES:
202 assert( LBER_VALID( ber ) );
203 ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
204 return LBER_OPT_SUCCESS;
206 case LBER_OPT_BER_BYTES_TO_WRITE:
207 assert( LBER_VALID( ber ) );
208 ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
209 return LBER_OPT_SUCCESS;
213 ber_errno = LBER_ERROR_PARAM;
217 return LBER_OPT_ERROR;