2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
14 #include <ac/string.h>
22 ldap_control_free( LDAPControl *c )
25 if( c->ldctl_oid != NULL) {
29 if( c->ldctl_value.bv_val != NULL ) {
30 free( c->ldctl_value.bv_val );
38 * Free an array of LDAPControl's
41 ldap_controls_free( LDAPControl **controls )
43 if ( controls != NULL ) {
46 for(c = *controls; c != NULL; c++) {
47 ldap_control_free( c );
55 * Duplicate an array of LDAPControl
57 LDAPControl **ldap_controls_dup( LDAPControl **controls )
62 if ( controls == NULL ) {
66 /* count the controls */
67 for(i=0; controls[i] != NULL; i++) /* empty */ ;
70 /* no controls to duplicate */
74 new = (LDAPControl **) malloc( i * sizeof(LDAPControl *) );
77 /* memory allocation failure */
81 /* duplicate the controls */
82 for(i=0; controls[i] != NULL; i++) {
83 new[i] = ldap_control_dup( controls[i] );
85 if( new[i] == NULL ) {
86 ldap_controls_free( new );
97 * Duplicate a LDAPControl
99 LDAPControl *ldap_control_dup( LDAPControl *c )
107 new = (LDAPControl *) malloc( sizeof(LDAPControl) );
113 if( c->ldctl_oid != NULL ) {
114 new->ldctl_oid = strdup( c->ldctl_oid );
116 if(new->ldctl_oid == NULL) {
122 new->ldctl_oid = NULL;
125 if( c->ldctl_value.bv_len > 0 ) {
126 new->ldctl_value.bv_val = (char *) malloc( c->ldctl_value.bv_len );
128 if(new->ldctl_value.bv_val == NULL) {
129 if(new->ldctl_oid != NULL) {
130 free( new->ldctl_oid );
136 SAFEMEMCPY( new->ldctl_value.bv_val, c->ldctl_value.bv_val,
137 c->ldctl_value.bv_len );
139 new->ldctl_value.bv_len = c->ldctl_value.bv_len;
142 new->ldctl_value.bv_len = 0;
143 new->ldctl_value.bv_val = NULL;
146 new->ldctl_iscritical = c->ldctl_iscritical;
150 /* get the controls from the BerElement */
151 int ldap_get_ber_controls( BerElement *be, LDAPControl ***cp)
153 return LDAP_NOT_SUPPORTED;