int		berrc, err, errcode; long		along;
int		berrc, err, errcode = 0; long		along = 0;
nsldapi_parse_result( LDAP *ld, int msgtype, BerElement *rber, int *errcodep,    char **matchednp, char **errmsgp, char ***referralsp,    LDAPControl ***serverctrlsp ){	BerElement	ber;	unsigned long	len;	int		berrc, err, errcode;	long		along;	char		*m, *e;	/*	 * Parse the result message.  LDAPv3 result messages look like this:	 *	 *	LDAPResult ::= SEQUENCE {	 *		resultCode	ENUMERATED { ... },	 *		matchedDN	LDAPDN,	 *		errorMessage	LDAPString,	 *		referral	[3] Referral OPTIONAL	 *		opSpecificStuff	OPTIONAL	 *	}	 *	 * all wrapped up in an LDAPMessage sequence which looks like this:	 *	LDAPMessage ::= SEQUENCE {	 *		messageID	MessageID,	 *		LDAPResult	CHOICE { ... },	// message type	 *		controls	[0] Controls OPTIONAL	 *	}	 *	 * LDAPv2 messages don't include referrals or controls.	 * LDAPv1 messages don't include matchedDN, referrals, or controls.	 *	 * ldap_result() pulls out the message id, so by the time a result	 * message gets here we are sitting at the start of the LDAPResult.	 */	err = LDAP_SUCCESS;	/* optimistic */	m = e = NULL;	if ( matchednp != NULL ) {		*matchednp = NULL;	}	if ( errmsgp != NULL ) {		*errmsgp = NULL;	}	if ( referralsp != NULL ) {		*referralsp = NULL;	}	if ( serverctrlsp != NULL ) {		*serverctrlsp = NULL;	}	ber = *rber;		/* struct copy */	if ( NSLDAPI_LDAP_VERSION( ld ) < LDAP_VERSION2 ) {		berrc = ber_scanf( &ber, "{ia}", &along, &e );		errcode = (int)along;	/* XXX lossy cast */	} else {		if (( berrc = ber_scanf( &ber, "{iaa", &along, &m, &e ))		    != LBER_ERROR ) {			errcode = (int)along;	/* XXX lossy cast */			/* check for optional referrals */			if ( ber_peek_tag( &ber, &len ) == LDAP_TAG_REFERRAL ) {				if ( referralsp == NULL ) {					/* skip referrals */					berrc = ber_scanf( &ber, "x" );				} else {					/* suck out referrals */					berrc = ber_scanf( &ber, "v",					    referralsp );				}			} else if ( referralsp != NULL ) {				*referralsp = NULL;			}		}		if ( berrc != LBER_ERROR ) {			/*			 * skip past optional operation-specific elements:			 *   bind results - serverSASLcreds			 *   extendedop results -  OID plus value			 */			if ( msgtype == LDAP_RES_BIND ) {				if ( ber_peek_tag( &ber, &len ) == 				    LDAP_TAG_SASL_RES_CREDS ) {					berrc = ber_scanf( &ber, "x" );				}			} else if ( msgtype == LDAP_RES_EXTENDED ) {				if ( ber_peek_tag( &ber, &len ) ==				    LDAP_TAG_EXOP_RES_OID ) {					berrc = ber_scanf( &ber, "x" );				}				if ( berrc != LBER_ERROR &&				    ber_peek_tag( &ber, &len ) ==				    LDAP_TAG_EXOP_RES_VALUE ) {					berrc = ber_scanf( &ber, "x" );				}			}		}		/* pull out controls (if requested and any are present) */		if ( berrc != LBER_ERROR && serverctrlsp != NULL &&		    ( berrc = ber_scanf( &ber, "}" )) != LBER_ERROR ) {			err = nsldapi_get_controls( &ber, serverctrlsp );		}	}	if ( berrc == LBER_ERROR && err == LDAP_SUCCESS ) {		err = LDAP_DECODING_ERROR;	}	if ( errcodep != NULL ) {		*errcodep = errcode;	}	if ( matchednp != NULL ) {		*matchednp = m;	} else if ( m != NULL ) {		NSLDAPI_FREE( m );	}	if ( errmsgp != NULL ) {		*errmsgp = e;	} else if ( e != NULL ) {		NSLDAPI_FREE( e );	}	return( err );}