3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
13 extern void * ber_pvt_err_file; /* bprint.c */
15 struct lber_options ber_int_options = {
16 LBER_UNINITIALIZED, 0, 0 };
24 LDAP_CONST BerElement *ber;
25 LDAP_CONST Sockbuf *sb;
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;
55 ber_errno = LBER_ERROR_PARAM;
56 return LBER_OPT_ERROR;
63 case LBER_OPT_BER_OPTIONS:
64 assert( BER_VALID( ber ) );
65 * (int *) outvalue = ber->ber_options;
66 return LBER_OPT_SUCCESS;
68 case LBER_OPT_BER_DEBUG:
69 assert( BER_VALID( ber ) );
70 * (int *) outvalue = ber->ber_debug;
71 return LBER_OPT_SUCCESS;
73 case LBER_OPT_BER_REMAINING_BYTES:
74 *((ber_len_t *) outvalue) = ber->ber_end - ber->ber_ptr;
75 return LBER_OPT_SUCCESS;
77 case LBER_OPT_BER_TOTAL_BYTES:
78 *((ber_len_t *) outvalue) = ber->ber_end - ber->ber_buf;
79 return LBER_OPT_SUCCESS;
81 case LBER_OPT_BER_BYTES_TO_WRITE:
82 *((ber_len_t *) outvalue) = ber->ber_ptr - ber->ber_buf;
83 return LBER_OPT_SUCCESS;
87 ber_errno = LBER_ERROR_PARAM;
91 return LBER_OPT_ERROR;
98 LDAP_CONST void *invalue)
103 if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
104 && ( ber_int_memory_fns == NULL )
105 && ( option == LBER_OPT_MEMORY_FNS )
106 && ( invalue != NULL ))
108 const BerMemoryFunctions *f =
109 (const BerMemoryFunctions *) invalue;
111 /* make sure all functions are provided */
112 if(!( f->bmf_malloc && f->bmf_calloc
113 && f->bmf_realloc && f->bmf_free ))
115 ber_errno = LBER_ERROR_PARAM;
116 return LBER_OPT_ERROR;
119 ber_int_memory_fns = (BerMemoryFunctions *)
120 (*(f->bmf_malloc))(sizeof(BerMemoryFunctions));
122 if ( ber_int_memory_fns == NULL ) {
123 ber_errno = LBER_ERROR_MEMORY;
124 return LBER_OPT_ERROR;
127 AC_MEMCPY(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
129 ber_int_options.lbo_valid = LBER_INITIALIZED;
130 return LBER_OPT_SUCCESS;
133 ber_int_options.lbo_valid = LBER_INITIALIZED;
135 if(invalue == NULL) {
136 /* no place to set from */
137 ber_errno = LBER_ERROR_PARAM;
138 return LBER_OPT_ERROR;
142 if(option == LBER_OPT_BER_DEBUG) {
143 ber_int_debug = * (const int *) invalue;
144 return LBER_OPT_SUCCESS;
146 } else if(option == LBER_OPT_LOG_PRINT_FN) {
147 ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
148 return LBER_OPT_SUCCESS;
149 } else if(option == LBER_OPT_LOG_PRINT_FILE) {
150 ber_pvt_err_file = (void *) invalue;
151 return LBER_OPT_SUCCESS;
152 } else if(option == LBER_OPT_MEMORY_INUSE) {
153 /* The memory inuse is a global variable on kernal implementations.
154 * This means that memory debug is shared by all LDAP processes
155 * so for this variable to have much meaning, only one LDAP process
156 * should be running and memory inuse should be initialized to zero
157 * using the lber_set_option() function during startup.
158 * The counter is not accurate for multithreaded applications.
160 #ifdef LDAP_MEMORY_DEBUG
161 ber_int_options.lbo_meminuse = * (int *) invalue;
162 return LBER_OPT_SUCCESS;
164 return LBER_OPT_ERROR;
168 ber_errno = LBER_ERROR_PARAM;
169 return LBER_OPT_ERROR;
176 case LBER_OPT_BER_OPTIONS:
177 assert( BER_VALID( ber ) );
178 ber->ber_options = * (const int *) invalue;
179 return LBER_OPT_SUCCESS;
181 case LBER_OPT_BER_DEBUG:
182 assert( BER_VALID( ber ) );
183 ber->ber_debug = * (const int *) invalue;
184 return LBER_OPT_SUCCESS;
186 case LBER_OPT_BER_REMAINING_BYTES:
187 ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
188 return LBER_OPT_SUCCESS;
190 case LBER_OPT_BER_TOTAL_BYTES:
191 ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
192 return LBER_OPT_SUCCESS;
194 case LBER_OPT_BER_BYTES_TO_WRITE:
195 ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
196 return LBER_OPT_SUCCESS;
200 ber_errno = LBER_ERROR_PARAM;
204 return LBER_OPT_ERROR;