X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Fliblber%2Foptions.c;h=62f4fcf4175924b61167020b732c12673d5bbab8;hb=304a57740a0dbb8c95bbbdada7b7972eee521fa0;hp=c021a79031189c407b64c660464422985e52013a;hpb=21c70857f1029309d6bc5a5b6a93d7537494b742;p=openldap diff --git a/libraries/liblber/options.c b/libraries/liblber/options.c index c021a79031..62f4fcf417 100644 --- a/libraries/liblber/options.c +++ b/libraries/liblber/options.c @@ -1,3 +1,4 @@ +/* $OpenLDAP$ */ /* * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file @@ -9,12 +10,14 @@ #include "lber-int.h" +extern void * ber_pvt_err_file; /* bprint.c */ + struct lber_options ber_int_options = { LBER_UNINITIALIZED, 0, 0 }; int ber_get_option( - LDAP_CONST void *item, + void *item, int option, void *outvalue) { @@ -25,6 +28,7 @@ ber_get_option( if(outvalue == NULL) { /* no place to get to */ + ber_errno = LBER_ERROR_PARAM; return LBER_OPT_ERROR; } @@ -34,6 +38,7 @@ ber_get_option( return LBER_OPT_SUCCESS; } + ber_errno = LBER_ERROR_PARAM; return LBER_OPT_ERROR; } @@ -51,8 +56,21 @@ ber_get_option( * (int *) outvalue = ber->ber_debug; return LBER_OPT_SUCCESS; + 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; + default: /* bad param */ + ber_errno = LBER_ERROR_PARAM; break; } @@ -73,12 +91,14 @@ ber_set_option( && ( option == LBER_OPT_MEMORY_FNS ) && ( invalue != NULL )) { - BerMemoryFunctions *f = (BerMemoryFunctions *) invalue; + const BerMemoryFunctions *f = + (const BerMemoryFunctions *) invalue; /* make sure all functions are provided */ if(!( f->bmf_malloc && f->bmf_calloc && f->bmf_realloc && f->bmf_free )) { + ber_errno = LBER_ERROR_PARAM; return LBER_OPT_ERROR; } @@ -86,6 +106,7 @@ ber_set_option( (*(f->bmf_malloc))(sizeof(BerMemoryFunctions)); if ( ber_int_memory_fns == NULL ) { + ber_errno = LBER_ERROR_MEMORY; return LBER_OPT_ERROR; } @@ -99,19 +120,24 @@ ber_set_option( if(invalue == NULL) { /* no place to set from */ + ber_errno = LBER_ERROR_PARAM; return LBER_OPT_ERROR; } if(item == NULL) { if(option == LBER_OPT_BER_DEBUG) { - ber_int_debug = * (int *) invalue; + ber_int_debug = * (const int *) invalue; return LBER_OPT_SUCCESS; } else if(option == LBER_OPT_LOG_PRINT_FN) { ber_pvt_log_print = (BER_LOG_PRINT_FN) invalue; return LBER_OPT_SUCCESS; + } else if(option == LBER_OPT_LOG_PRINT_FILE) { + ber_pvt_err_file = (void *) invalue; + return LBER_OPT_SUCCESS; } + ber_errno = LBER_ERROR_PARAM; return LBER_OPT_ERROR; } @@ -121,16 +147,29 @@ ber_set_option( switch(option) { case LBER_OPT_BER_OPTIONS: assert( BER_VALID( ber ) ); - ber->ber_options = * (int *) invalue; + ber->ber_options = * (const int *) invalue; return LBER_OPT_SUCCESS; case LBER_OPT_BER_DEBUG: assert( BER_VALID( ber ) ); - ber->ber_debug = * (int *) invalue; + ber->ber_debug = * (const int *) invalue; + return LBER_OPT_SUCCESS; + + 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; default: /* bad param */ + ber_errno = LBER_ERROR_PARAM; break; }