]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/controls.c
Minor adjustments based upon initial read of draft-ietf-ldapext-ldap-c-api-04.txt.
[openldap] / libraries / libldap / controls.c
index 7c6249fb6cc2bde71db9088b63d4110eaf049e7c..cc07664c90681f2e62808926cc96ea9c56cd1180 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  * 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 );
@@ -62,13 +64,13 @@ int ldap_int_put_controls(
        }
 
        /* 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;
@@ -77,7 +79,7 @@ int ldap_int_put_controls(
 
                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;
@@ -92,14 +94,14 @@ int ldap_int_put_controls(
                }
 
 
-               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;
        }
@@ -112,12 +114,15 @@ int ldap_int_get_controls(
        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);
@@ -127,6 +132,7 @@ int ldap_int_get_controls(
                return LDAP_SUCCESS;
        }
 
+
        if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
                if( tag == LBER_ERROR ) {
                        /* decoding error */
@@ -179,14 +185,16 @@ int ldap_int_get_controls(
                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 ) {
@@ -242,10 +250,10 @@ 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 );
@@ -255,7 +263,8 @@ ldap_controls_free( LDAPControl **controls )
 /*
  * Duplicate an array of LDAPControl
  */
-LDAPControl **ldap_controls_dup( const LDAPControl **controls )
+LDAPControl **
+ldap_controls_dup( LDAPControl *const *controls )
 {
        LDAPControl **new;
        int i;
@@ -297,7 +306,8 @@ LDAPControl **ldap_controls_dup( const LDAPControl **controls )
 /*
  * Duplicate a LDAPControl
  */
-LDAPControl *ldap_control_dup( const LDAPControl *c )
+LDAPControl *
+ldap_control_dup( const LDAPControl *c )
 {
        LDAPControl *new;