16 ldap_control_free( LDAPControl *c )
19 if( c->ldctl_oid != NULL) {
23 if( c->ldctl_value.bv_val != NULL ) {
24 free( c->ldctl_value.bv_val );
32 * Free an array of LDAPControl's
35 ldap_controls_free( LDAPControl **controls )
37 if ( controls != NULL ) {
40 for(c = *controls; c != NULL; c++) {
41 ldap_control_free( c );
49 * Duplicate an array of LDAPControl
51 LDAPControl **ldap_controls_dup( LDAPControl **controls )
56 if ( controls == NULL ) {
60 /* count the controls */
61 for(i=0; controls[i] != NULL; i++) /* empty */ ;
64 /* no controls to duplicate */
68 new = (LDAPControl **) malloc( i * sizeof(LDAPControl *) );
71 /* memory allocation failure */
75 /* duplicate the controls */
76 for(i=0; controls[i] != NULL; i++) {
77 new[i] = ldap_control_dup( controls[i] );
79 if( new[i] == NULL ) {
80 ldap_controls_free( new );
91 * Duplicate a LDAPControl
93 LDAPControl *ldap_control_dup( LDAPControl *c )
101 new = (LDAPControl *) malloc( sizeof(LDAPControl) );
107 if( c->ldctl_oid != NULL ) {
108 new->ldctl_oid = ldap_strdup( c->ldctl_oid );
110 if(new->ldctl_oid == NULL) {
116 new->ldctl_oid = NULL;
119 if( c->ldctl_value.bv_len > 0 ) {
120 new->ldctl_value.bv_val = (char *) malloc( c->ldctl_value.bv_len );
122 if(new->ldctl_value.bv_val == NULL) {
123 if(new->ldctl_oid != NULL) {
124 free( new->ldctl_oid );
130 SAFEMEMCPY( new->ldctl_value.bv_val, c->ldctl_value.bv_val,
131 c->ldctl_value.bv_len );
133 new->ldctl_value.bv_len = c->ldctl_value.bv_len;
136 new->ldctl_value.bv_len = 0;
137 new->ldctl_value.bv_val = NULL;
140 new->ldctl_iscritical = c->ldctl_iscritical;