3 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdarg.h>
13 struct lber_options ber_int_options = {
14 LBER_UNINITIALIZED, 0, 0, 0 };
22 const BerElement *ber;
25 ber_int_options.lbo_valid = LBER_INITIALIZED;
27 if(outvalue == NULL) {
28 /* no place to get to */
29 ber_errno = LBER_ERROR_PARAM;
30 return LBER_OPT_ERROR;
34 if(option == LBER_OPT_BER_DEBUG) {
35 * (int *) outvalue = ber_int_debug;
36 return LBER_OPT_SUCCESS;
37 } else if(option == LBER_OPT_MEMORY_INUSE) {
38 /* The memory inuse is a global variable on kernal implementations.
39 * This means that memory debug is shared by all LDAP processes
40 * so for this variable to have much meaning, only one LDAP process
41 * should be running and memory inuse should be initialized to zero
42 * using the lber_set_option() function during startup.
43 * The counter is not accurate for multithreaded ldap applications.
45 #ifdef LDAP_MEMORY_DEBUG
46 * (int *) outvalue = ber_int_options.lbo_meminuse;
47 return LBER_OPT_SUCCESS;
49 return LBER_OPT_ERROR;
51 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
52 *((FILE**)outvalue) = (FILE*)ber_pvt_err_file;
53 return LBER_OPT_SUCCESS;
56 ber_errno = LBER_ERROR_PARAM;
57 return LBER_OPT_ERROR;
64 case LBER_OPT_BER_OPTIONS:
65 assert( LBER_VALID( ber ) );
66 * (int *) outvalue = ber->ber_options;
67 return LBER_OPT_SUCCESS;
69 case LBER_OPT_BER_DEBUG:
70 assert( LBER_VALID( ber ) );
71 * (int *) outvalue = ber->ber_debug;
72 return LBER_OPT_SUCCESS;
74 case LBER_OPT_BER_REMAINING_BYTES:
75 assert( LBER_VALID( ber ) );
76 *((ber_len_t *) outvalue) = ber_pvt_ber_remaining(ber);
77 return LBER_OPT_SUCCESS;
79 case LBER_OPT_BER_TOTAL_BYTES:
80 assert( LBER_VALID( ber ) );
81 *((ber_len_t *) outvalue) = ber_pvt_ber_total(ber);
82 return LBER_OPT_SUCCESS;
84 case LBER_OPT_BER_BYTES_TO_WRITE:
85 assert( LBER_VALID( ber ) );
86 *((ber_len_t *) outvalue) = ber_pvt_ber_write(ber);
87 return LBER_OPT_SUCCESS;
89 case LBER_OPT_BER_MEMCTX:
90 assert( LBER_VALID( ber ) );
91 *((void **) outvalue) = ber->ber_memctx;
92 return LBER_OPT_SUCCESS;
96 ber_errno = LBER_ERROR_PARAM;
100 return LBER_OPT_ERROR;
107 LDAP_CONST void *invalue)
112 if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
113 && ( ber_int_memory_fns == NULL )
114 && ( option == LBER_OPT_MEMORY_FNS )
115 && ( invalue != NULL ))
117 const BerMemoryFunctions *f =
118 (const BerMemoryFunctions *) invalue;
120 /* make sure all functions are provided */
121 if(!( f->bmf_malloc && f->bmf_calloc
122 && f->bmf_realloc && f->bmf_free ))
124 ber_errno = LBER_ERROR_PARAM;
125 return LBER_OPT_ERROR;
128 ber_int_memory_fns = (BerMemoryFunctions *)
129 (*(f->bmf_malloc))(sizeof(BerMemoryFunctions), NULL);
131 if ( ber_int_memory_fns == NULL ) {
132 ber_errno = LBER_ERROR_MEMORY;
133 return LBER_OPT_ERROR;
136 AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
138 ber_int_options.lbo_valid = LBER_INITIALIZED;
139 return LBER_OPT_SUCCESS;
142 ber_int_options.lbo_valid = LBER_INITIALIZED;
144 if(invalue == NULL) {
145 /* no place to set from */
146 ber_errno = LBER_ERROR_PARAM;
147 return LBER_OPT_ERROR;
151 if(option == LBER_OPT_BER_DEBUG) {
152 ber_int_debug = * (const int *) invalue;
153 return LBER_OPT_SUCCESS;
155 } else if(option == LBER_OPT_LOG_PRINT_FN) {
156 ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
157 return LBER_OPT_SUCCESS;
158 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
159 ber_pvt_err_file = (void *) invalue;
160 return LBER_OPT_SUCCESS;
161 } else if(option == LBER_OPT_MEMORY_INUSE) {
162 /* The memory inuse is a global variable on kernal implementations.
163 * This means that memory debug is shared by all LDAP processes
164 * so for this variable to have much meaning, only one LDAP process
165 * should be running and memory inuse should be initialized to zero
166 * using the lber_set_option() function during startup.
167 * The counter is not accurate for multithreaded applications.
169 #ifdef LDAP_MEMORY_DEBUG
170 ber_int_options.lbo_meminuse = * (int *) invalue;
171 return LBER_OPT_SUCCESS;
173 return LBER_OPT_ERROR;
175 } else if(option == LBER_OPT_LOG_PROC) {
176 ber_int_log_proc = (BER_LOG_FN)invalue;
179 ber_errno = LBER_ERROR_PARAM;
180 return LBER_OPT_ERROR;
187 case LBER_OPT_BER_OPTIONS:
188 assert( LBER_VALID( ber ) );
189 ber->ber_options = * (const int *) invalue;
190 return LBER_OPT_SUCCESS;
192 case LBER_OPT_BER_DEBUG:
193 assert( LBER_VALID( ber ) );
194 ber->ber_debug = * (const int *) invalue;
195 return LBER_OPT_SUCCESS;
197 case LBER_OPT_BER_REMAINING_BYTES:
198 assert( LBER_VALID( ber ) );
199 ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
200 return LBER_OPT_SUCCESS;
202 case LBER_OPT_BER_TOTAL_BYTES:
203 assert( LBER_VALID( ber ) );
204 ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
205 return LBER_OPT_SUCCESS;
207 case LBER_OPT_BER_BYTES_TO_WRITE:
208 assert( LBER_VALID( ber ) );
209 ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
210 return LBER_OPT_SUCCESS;
212 case LBER_OPT_BER_MEMCTX:
213 assert( LBER_VALID( ber ) );
214 ber->ber_memctx = (void *)invalue;
215 return LBER_OPT_SUCCESS;
219 ber_errno = LBER_ERROR_PARAM;
223 return LBER_OPT_ERROR;