2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
20 ldap_control_free( LDAPControl *c )
23 if( c->ldctl_oid != NULL) {
27 if( c->ldctl_value.bv_val != NULL ) {
28 free( c->ldctl_value.bv_val );
36 * Free an array of LDAPControl's
39 ldap_controls_free( LDAPControl **controls )
41 if ( controls != NULL ) {
44 for(c = *controls; c != NULL; c++) {
45 ldap_control_free( c );
53 * Duplicate an array of LDAPControl
55 LDAPControl **ldap_controls_dup( LDAPControl **controls )
60 if ( controls == NULL ) {
64 /* count the controls */
65 for(i=0; controls[i] != NULL; i++) /* empty */ ;
68 /* no controls to duplicate */
72 new = (LDAPControl **) malloc( i * sizeof(LDAPControl *) );
75 /* memory allocation failure */
79 /* duplicate the controls */
80 for(i=0; controls[i] != NULL; i++) {
81 new[i] = ldap_control_dup( controls[i] );
83 if( new[i] == NULL ) {
84 ldap_controls_free( new );
95 * Duplicate a LDAPControl
97 LDAPControl *ldap_control_dup( LDAPControl *c )
105 new = (LDAPControl *) malloc( sizeof(LDAPControl) );
111 if( c->ldctl_oid != NULL ) {
112 new->ldctl_oid = strdup( c->ldctl_oid );
114 if(new->ldctl_oid == NULL) {
120 new->ldctl_oid = NULL;
123 if( c->ldctl_value.bv_len > 0 ) {
124 new->ldctl_value.bv_val = (char *) malloc( c->ldctl_value.bv_len );
126 if(new->ldctl_value.bv_val == NULL) {
127 if(new->ldctl_oid != NULL) {
128 free( new->ldctl_oid );
134 SAFEMEMCPY( new->ldctl_value.bv_val, c->ldctl_value.bv_val,
135 c->ldctl_value.bv_len );
137 new->ldctl_value.bv_len = c->ldctl_value.bv_len;
140 new->ldctl_value.bv_len = 0;
141 new->ldctl_value.bv_val = NULL;
144 new->ldctl_iscritical = c->ldctl_iscritical;
148 /* get the controls from the BerElement */
149 int ldap_get_ber_controls( BerElement *be, LDAPControl ***cp)
151 return LDAP_NOT_SUPPORTED;