1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
1998-12-29 04:38:04 +08:00
|
|
|
/*
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
*/
|
1998-12-22 09:34:01 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1999-05-31 07:00:52 +08:00
|
|
|
#include <ac/string.h>
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-06-04 02:24:22 +08:00
|
|
|
#undef LDAP_F_PRE
|
|
|
|
#define LDAP_F_PRE LDAP_F_EXPORT
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
#include "lber-int.h"
|
|
|
|
|
1999-05-29 03:33:05 +08:00
|
|
|
struct lber_options ber_int_options = {
|
|
|
|
LBER_UNINITIALIZED, 0, 0 };
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_get_option(
|
1999-10-20 08:19:47 +08:00
|
|
|
void *item,
|
1998-12-22 09:34:01 +08:00
|
|
|
int option,
|
|
|
|
void *outvalue)
|
|
|
|
{
|
1999-06-03 05:38:48 +08:00
|
|
|
LDAP_CONST BerElement *ber;
|
|
|
|
LDAP_CONST Sockbuf *sb;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
if(outvalue == NULL) {
|
|
|
|
/* no place to get to */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item == NULL) {
|
|
|
|
if(option == LBER_OPT_BER_DEBUG) {
|
1999-05-19 09:12:33 +08:00
|
|
|
* (int *) outvalue = ber_int_debug;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:38:48 +08:00
|
|
|
ber = item;
|
|
|
|
sb = item;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case LBER_OPT_BER_OPTIONS:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1998-12-22 09:34:01 +08:00
|
|
|
* (int *) outvalue = ber->ber_options;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_DEBUG:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1998-12-22 09:34:01 +08:00
|
|
|
* (int *) outvalue = ber->ber_debug;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1999-11-08 23:38:59 +08:00
|
|
|
case LBER_OPT_BER_REMAINING_BYTES:
|
|
|
|
*((ber_len_t *) outvalue) = ber->ber_end - ber->ber_ptr;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_TOTAL_BYTES:
|
|
|
|
*((ber_len_t *) outvalue) = ber->ber_end - ber->ber_buf;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_BYTES_TO_WRITE:
|
|
|
|
*((ber_len_t *) outvalue) = ber->ber_ptr - ber->ber_buf;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
default:
|
|
|
|
/* bad param */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_set_option(
|
1998-12-22 09:34:01 +08:00
|
|
|
void *item,
|
|
|
|
int option,
|
1999-05-19 09:42:29 +08:00
|
|
|
LDAP_CONST void *invalue)
|
1998-12-22 09:34:01 +08:00
|
|
|
{
|
|
|
|
BerElement *ber;
|
|
|
|
Sockbuf *sb;
|
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
if( (ber_int_options.lbo_valid == LBER_UNINITIALIZED)
|
1999-05-31 07:00:52 +08:00
|
|
|
&& ( ber_int_memory_fns == NULL )
|
|
|
|
&& ( option == LBER_OPT_MEMORY_FNS )
|
1999-05-29 13:16:31 +08:00
|
|
|
&& ( invalue != NULL ))
|
|
|
|
{
|
1999-07-13 13:17:50 +08:00
|
|
|
const BerMemoryFunctions *f =
|
|
|
|
(const BerMemoryFunctions *) invalue;
|
1999-05-31 07:00:52 +08:00
|
|
|
|
|
|
|
/* make sure all functions are provided */
|
|
|
|
if(!( f->bmf_malloc && f->bmf_calloc
|
|
|
|
&& f->bmf_realloc && f->bmf_free ))
|
|
|
|
{
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1999-05-31 07:00:52 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_int_memory_fns = (BerMemoryFunctions *)
|
|
|
|
(*(f->bmf_malloc))(sizeof(BerMemoryFunctions));
|
|
|
|
|
|
|
|
if ( ber_int_memory_fns == NULL ) {
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_MEMORY;
|
1999-05-31 07:00:52 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ber_int_memory_fns, f, sizeof(BerMemoryFunctions));
|
|
|
|
|
1999-05-29 13:16:31 +08:00
|
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_int_options.lbo_valid = LBER_INITIALIZED;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
if(invalue == NULL) {
|
|
|
|
/* no place to set from */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(item == NULL) {
|
|
|
|
if(option == LBER_OPT_BER_DEBUG) {
|
1999-07-13 13:17:50 +08:00
|
|
|
ber_int_debug = * (const int *) invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
1999-01-26 06:55:00 +08:00
|
|
|
|
|
|
|
} else if(option == LBER_OPT_LOG_PRINT_FN) {
|
1999-05-19 09:12:33 +08:00
|
|
|
ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue;
|
1999-01-26 06:55:00 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
1998-12-22 09:34:01 +08:00
|
|
|
}
|
|
|
|
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:38:48 +08:00
|
|
|
ber = item;
|
|
|
|
sb = item;
|
1998-12-22 09:34:01 +08:00
|
|
|
|
|
|
|
switch(option) {
|
|
|
|
case LBER_OPT_BER_OPTIONS:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-07-13 13:17:50 +08:00
|
|
|
ber->ber_options = * (const int *) invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_DEBUG:
|
1999-05-29 03:33:05 +08:00
|
|
|
assert( BER_VALID( ber ) );
|
1999-07-13 13:17:50 +08:00
|
|
|
ber->ber_debug = * (const int *) invalue;
|
1998-12-22 09:34:01 +08:00
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1999-11-08 23:38:59 +08:00
|
|
|
case LBER_OPT_BER_REMAINING_BYTES:
|
|
|
|
ber->ber_end = &ber->ber_ptr[* (const ber_len_t *) invalue];
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_TOTAL_BYTES:
|
|
|
|
ber->ber_end = &ber->ber_buf[* (const ber_len_t *) invalue];
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
|
|
|
case LBER_OPT_BER_BYTES_TO_WRITE:
|
|
|
|
ber->ber_ptr = &ber->ber_buf[* (const ber_len_t *) invalue];
|
|
|
|
return LBER_OPT_SUCCESS;
|
|
|
|
|
1998-12-22 09:34:01 +08:00
|
|
|
default:
|
|
|
|
/* bad param */
|
1999-12-06 14:33:26 +08:00
|
|
|
ber_errno = LBER_ERROR_PARAM;
|
1998-12-22 09:34:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LBER_OPT_ERROR;
|
|
|
|
}
|