]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/controls.c
Move ldap_utf8_*() declarations from ldap-int.h to ldap_pvt.h.
[openldap] / libraries / libldap / controls.c
index f330685616d5e82f627e5d3d2f5dc8ac83254958..cab753e8810a00b3d20ccf2de46a485d66b16e5b 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;
        }
@@ -107,17 +109,20 @@ int ldap_int_put_controls(
        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);
@@ -127,6 +132,7 @@ int ldap_int_get_controls LDAP_P((
                return LDAP_SUCCESS;
        }
 
+
        if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
                if( tag == LBER_ERROR ) {
                        /* decoding error */
@@ -145,7 +151,7 @@ int ldap_int_get_controls LDAP_P((
                return LDAP_NO_MEMORY;
        }
 
-       ctrls[nctrls] = NULL;
+       *ctrls[nctrls] = NULL;
 
        for( tag = ber_first_element( ber, &len, &opaque );
                tag != LBER_ERROR;
@@ -179,14 +185,16 @@ int ldap_int_get_controls LDAP_P((
                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;