1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  * Portions Copyright %G% Sun Microsystems, Inc.
4*0Sstevel@tonic-gate  * All Rights Reserved
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  */
7*0Sstevel@tonic-gate 
8*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
9*0Sstevel@tonic-gate 
10*0Sstevel@tonic-gate /*
11*0Sstevel@tonic-gate  *  Copyright (c) 1994 The Regents of the University of Michigan.
12*0Sstevel@tonic-gate  *  All rights reserved.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  *  free.c - some free routines are included here to avoid having to
15*0Sstevel@tonic-gate  *           link in lots of extra code when not using certain features
16*0Sstevel@tonic-gate  */
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate #ifndef lint
19*0Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1994 The Regents of the University of Michigan.\nAll rights reserved.\n";
20*0Sstevel@tonic-gate #endif
21*0Sstevel@tonic-gate 
22*0Sstevel@tonic-gate 
23*0Sstevel@tonic-gate #include <stdio.h>
24*0Sstevel@tonic-gate #include <string.h>
25*0Sstevel@tonic-gate #include <ctype.h>
26*0Sstevel@tonic-gate #ifdef MACOS
27*0Sstevel@tonic-gate #include <stdlib.h>
28*0Sstevel@tonic-gate #include "macos.h"
29*0Sstevel@tonic-gate #else /* MACOS */
30*0Sstevel@tonic-gate #ifdef DOS
31*0Sstevel@tonic-gate #include <malloc.h>
32*0Sstevel@tonic-gate #include "msdos.h"
33*0Sstevel@tonic-gate #else /* DOS */
34*0Sstevel@tonic-gate #include <sys/types.h>
35*0Sstevel@tonic-gate #include <stdlib.h>
36*0Sstevel@tonic-gate #endif /* DOS */
37*0Sstevel@tonic-gate #endif /* MACOS */
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #include "lber.h"
40*0Sstevel@tonic-gate #include "ldap.h"
41*0Sstevel@tonic-gate #include "ldap-private.h"
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate void
44*0Sstevel@tonic-gate ldap_getfilter_free( LDAPFiltDesc *lfdp )
45*0Sstevel@tonic-gate {
46*0Sstevel@tonic-gate     LDAPFiltList	*flp, *nextflp;
47*0Sstevel@tonic-gate     LDAPFiltInfo	*fip, *nextfip;
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate     for ( flp = lfdp->lfd_filtlist; flp != NULL; flp = nextflp ) {
50*0Sstevel@tonic-gate 	for ( fip = flp->lfl_ilist; fip != NULL; fip = nextfip ) {
51*0Sstevel@tonic-gate 	    nextfip = fip->lfi_next;
52*0Sstevel@tonic-gate 	    free( fip->lfi_filter );
53*0Sstevel@tonic-gate 	    free( fip->lfi_desc );
54*0Sstevel@tonic-gate 	    free( fip );
55*0Sstevel@tonic-gate 	}
56*0Sstevel@tonic-gate 	nextflp = flp->lfl_next;
57*0Sstevel@tonic-gate 	free( flp->lfl_pattern );
58*0Sstevel@tonic-gate 	free( flp->lfl_delims );
59*0Sstevel@tonic-gate 	free( flp->lfl_tag );
60*0Sstevel@tonic-gate 	free( flp );
61*0Sstevel@tonic-gate     }
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate     if ( lfdp->lfd_curvalcopy != NULL ) {
64*0Sstevel@tonic-gate 	free( lfdp->lfd_curvalcopy );
65*0Sstevel@tonic-gate     }
66*0Sstevel@tonic-gate     if ( lfdp->lfd_curvalwords != NULL ) {
67*0Sstevel@tonic-gate 	free( lfdp->lfd_curvalwords );
68*0Sstevel@tonic-gate     }
69*0Sstevel@tonic-gate     if ( lfdp->lfd_filtprefix != NULL ) {
70*0Sstevel@tonic-gate 	free( lfdp->lfd_filtprefix );
71*0Sstevel@tonic-gate     }
72*0Sstevel@tonic-gate     if ( lfdp->lfd_filtsuffix != NULL ) {
73*0Sstevel@tonic-gate 	free( lfdp->lfd_filtsuffix );
74*0Sstevel@tonic-gate     }
75*0Sstevel@tonic-gate 
76*0Sstevel@tonic-gate     free( lfdp );
77*0Sstevel@tonic-gate }
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate /*
80*0Sstevel@tonic-gate  * free a null-terminated array of pointers to mod structures. the
81*0Sstevel@tonic-gate  * structures are freed, not the array itself, unless the freemods
82*0Sstevel@tonic-gate  * flag is set.
83*0Sstevel@tonic-gate  */
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate void
86*0Sstevel@tonic-gate ldap_mods_free( LDAPMod **mods, int freemods )
87*0Sstevel@tonic-gate {
88*0Sstevel@tonic-gate 	int	i;
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	if ( mods == NULL )
91*0Sstevel@tonic-gate 		return;
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 	for ( i = 0; mods[i] != NULL; i++ ) {
94*0Sstevel@tonic-gate 		if ( mods[i]->mod_op & LDAP_MOD_BVALUES ) {
95*0Sstevel@tonic-gate 			ber_bvecfree( mods[i]->mod_bvalues );
96*0Sstevel@tonic-gate 		} else {
97*0Sstevel@tonic-gate 			ldap_value_free( mods[i]->mod_values );
98*0Sstevel@tonic-gate 		}
99*0Sstevel@tonic-gate 		if (mods[i]->mod_type)
100*0Sstevel@tonic-gate 			free(mods[i]->mod_type);
101*0Sstevel@tonic-gate 		free( (char *) mods[i] );
102*0Sstevel@tonic-gate 	}
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 	if ( freemods )
105*0Sstevel@tonic-gate 		free( (char *) mods );
106*0Sstevel@tonic-gate }
107