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 };
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;
91 ber_errno = LBER_ERROR_PARAM;
95 return LBER_OPT_ERROR;
102 LDAP_CONST void *invalue)
107 if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
108 && ( ber_int_memory_fns == NULL )
109 && ( option == LBER_OPT_MEMORY_FNS )
110 && ( invalue != NULL ))
112 const BerMemoryFunctions *f =
113 (const BerMemoryFunctions *) invalue;
115 /* make sure all functions are provided */
116 if(!( f->bmf_malloc && f->bmf_calloc
117 && f->bmf_realloc && f->bmf_free ))
119 ber_errno = LBER_ERROR_PARAM;
120 return LBER_OPT_ERROR;
123 ber_int_memory_fns = (BerMemoryFunctions *)
124 (*(f->bmf_malloc))(sizeof(BerMemoryFunctions));
126 if ( ber_int_memory_fns == NULL ) {
127 ber_errno = LBER_ERROR_MEMORY;
128 return LBER_OPT_ERROR;
131 AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
133 ber_int_options.lbo_valid = LBER_INITIALIZED;
134 return LBER_OPT_SUCCESS;
137 ber_int_options.lbo_valid = LBER_INITIALIZED;
139 if(invalue == NULL) {
140 /* no place to set from */
141 ber_errno = LBER_ERROR_PARAM;
142 return LBER_OPT_ERROR;
146 if(option == LBER_OPT_BER_DEBUG) {
147 ber_int_debug = * (const int *) invalue;
148 return LBER_OPT_SUCCESS;
150 } else if(option == LBER_OPT_LOG_PRINT_FN) {
151 ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
152 return LBER_OPT_SUCCESS;
153 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
154 ber_pvt_err_file = (void *) invalue;
155 return LBER_OPT_SUCCESS;
156 } else if(option == LBER_OPT_MEMORY_INUSE) {
157 /* The memory inuse is a global variable on kernal implementations.
158 * This means that memory debug is shared by all LDAP processes
159 * so for this variable to have much meaning, only one LDAP process
160 * should be running and memory inuse should be initialized to zero
161 * using the lber_set_option() function during startup.
162 * The counter is not accurate for multithreaded applications.
164 #ifdef LDAP_MEMORY_DEBUG
165 ber_int_options.lbo_meminuse = * (int *) invalue;
166 return LBER_OPT_SUCCESS;
168 return LBER_OPT_ERROR;
170 } else if(option == LBER_OPT_LOG_PROC) {
171 ber_int_log_proc = (BER_LOG_FN)invalue;
174 ber_errno = LBER_ERROR_PARAM;
175 return LBER_OPT_ERROR;
182 case LBER_OPT_BER_OPTIONS:
183 assert( LBER_VALID( ber ) );
184 ber->ber_options = * (const int *) invalue;
185 return LBER_OPT_SUCCESS;
187 case LBER_OPT_BER_DEBUG:
188 assert( LBER_VALID( ber ) );
189 ber->ber_debug = * (const int *) invalue;
190 return LBER_OPT_SUCCESS;
192 case LBER_OPT_BER_REMAINING_BYTES:
193 assert( LBER_VALID( ber ) );
194 ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
195 return LBER_OPT_SUCCESS;
197 case LBER_OPT_BER_TOTAL_BYTES:
198 assert( LBER_VALID( ber ) );
199 ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
200 return LBER_OPT_SUCCESS;
202 case LBER_OPT_BER_BYTES_TO_WRITE:
203 assert( LBER_VALID( ber ) );
204 ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
205 return LBER_OPT_SUCCESS;
209 ber_errno = LBER_ERROR_PARAM;
213 return LBER_OPT_ERROR;