+/* $OpenLDAP$ */
/*
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
-/*
- * LDAP controls
+
+/* LDAPv3 Controls (RFC2251)
+ *
+ * Controls ::= SEQUENCE OF Control
+ *
+ * Control ::= SEQUENCE {
+ * controlType LDAPOID,
+ * criticality BOOLEAN DEFAULT FALSE,
+ * controlValue OCTET STRING OPTIONAL
+ * }
*/
#include "portable.h"
* ldap_int_put_controls
*/
-int ldap_int_put_controls(
+int
+ldap_int_put_controls(
LDAP *ld,
- LDAPControl **ctrls,
+ LDAPControl *const *ctrls,
BerElement *ber )
{
- LDAPControl **c;
+ LDAPControl *const *c;
assert( ld != NULL );
assert( ber != NULL );
}
/* Controls are encoded as a sequence of sequences */
- if( ber_printf( ber, "t{", LDAP_TAG_CONTROLS ) == -1 ) {
+ if( ber_printf( ber, "t{"/*}*/, LDAP_TAG_CONTROLS ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
return ld->ld_errno;
}
for( c = ctrls ; *c != NULL; c++ ) {
- if ( ber_printf( ber, "{s",
+ if ( ber_printf( ber, "{s" /*}*/,
(*c)->ldctl_oid ) == -1 )
{
ld->ld_errno = LDAP_ENCODING_ERROR;
if( (*c)->ldctl_iscritical /* only if true */
&& ( ber_printf( ber, "b",
- (*c)->ldctl_iscritical ) == -1 ) )
+ (ber_int_t) (*c)->ldctl_iscritical ) == -1 ) )
{
ld->ld_errno = LDAP_ENCODING_ERROR;
return ld->ld_errno;
}
- if( ber_printf( ber, "}" ) == -1 ) {
+ if( ber_printf( ber, /*{*/"}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
return ld->ld_errno;
}
}
- if( ber_printf( ber, "}" ) == -1 ) {
+ if( ber_printf( ber, /*{*/"}" ) == -1 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
return ld->ld_errno;
}
return LDAP_SUCCESS;
}
-int ldap_int_get_controls LDAP_P((
+int ldap_int_get_controls(
BerElement *ber,
- LDAPControl ***ctrls ))
+ LDAPControl ***ctrls )
{
int nctrls;
- unsigned long tag, len;
+ ber_tag_t tag;
+ ber_len_t len;
char *opaque;
assert( ber != NULL );
- assert( ctrls != NULL );
+ if( ctrls == NULL ) {
+ return LDAP_SUCCESS;
+ }
*ctrls = NULL;
len = ber_pvt_ber_remaining(ber);
return LDAP_SUCCESS;
}
+
if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
if( tag == LBER_ERROR ) {
/* decoding error */
return LDAP_NO_MEMORY;
}
- ctrls[nctrls] = NULL;
+ *ctrls[nctrls] = NULL;
for( tag = ber_first_element( ber, &len, &opaque );
tag != LBER_ERROR;
tctrls[nctrls++] = tctrl;
tctrls[nctrls] = NULL;
- tag = ber_scanf( ber, "{a", &tctrl->ldctl_oid );
+ tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid );
if( tag != LBER_ERROR ) {
tag = ber_peek_tag( ber, &len );
}
if( tag == LBER_BOOLEAN ) {
- tag = ber_scanf( ber, "b", &tctrl->ldctl_iscritical );
+ ber_int_t crit;
+ tag = ber_scanf( ber, "b", &crit );
+ tctrl->ldctl_iscritical = crit ? (char) 0 : (char) ~0;
}
if( tag != LBER_ERROR ) {
void
ldap_control_free( LDAPControl *c )
{
+ assert( c != NULL );
+
if ( c != NULL ) {
if( c->ldctl_oid != NULL) {
LDAP_FREE( c->ldctl_oid );
void
ldap_controls_free( LDAPControl **controls )
{
+ assert( controls != NULL );
+
if ( controls != NULL ) {
- LDAPControl *c;
+ int i;
- for(c = *controls; c != NULL; c++) {
- ldap_control_free( c );
+ for( i=0; controls[i] != NULL; i++) {
+ ldap_control_free( controls[i] );
}
LDAP_FREE( controls );
/*
* Duplicate an array of LDAPControl
*/
-LDAPControl **ldap_controls_dup( const LDAPControl **controls )
+LDAPControl **
+ldap_controls_dup( LDAPControl *const *controls )
{
LDAPControl **new;
int i;
/*
* Duplicate a LDAPControl
*/
-LDAPControl *ldap_control_dup( const LDAPControl *c )
+LDAPControl *
+ldap_control_dup( const LDAPControl *c )
{
LDAPControl *new;