[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: LDAP C API: ber_* error handling



George Powers wrote:
> 
> I agree with Kurt that ber_scanf() is deficient and needs to return specific
> errors.  Otherwise the Mozilla LDAP library cannot be fixed to recover from
> transient out-of-memory errors.  I think that the spec should either let it
> return additional error codes, or add an extended version that does.
> 
> Within the current API design, there is room for additional error codes in
> the form of bogus tag values such that:
> 
> (( tag & 0x00000080 ) != 0 ) && (( tag & 0xFFFFFF00 ) != 0 )

OpenLDAP actually provides a macro to validate tag values:

#define LBER_INVALID(tag) (((tag) & 0x00000080) && (((tag) & 0xFFFFFF00))

It might be useful just say that ber_scanf returns an invalid tag upon error.
An example of use would be:

	ber_tag_t tag = ber_scanf( ber, "x" );

	if( LBER_INVALID(tag) ) {
		switch(tag) {
			case LBER_ERROR:	/* generic error */
				...
			case LBER_DECODING_ERROR:
				...
			case LBER_NO_MEMORY:
				...
			default:		/* unknown error */
				...
		}
	}

However, this will break a great deal of code.

> Or, how about a version of ber_scanf() that returns an error separately than
> the tag:

If we change the semantics of the API call, yes, the call name should change.

Another approach would be to provide a routine similiar to ldap_get_option(),
say ber_get_option(), to obtain an error code which could be hidden in
the BerElement.  OpenLDAP is currently implementing this approach as it
doesn't require large amount of change to existing code.

I would not object if we ducked this issue for now (leaving it a later API
extension).  That is, I'd be happy with a simple clarification.
	ber_* routines only indicate an error has occurred.  This specification
	does not define a mechanism to obtain detail information about the error.
	Implementations of this API SHOULD provide such a mechanism.