]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/disptmpl.c
cleanup
[openldap] / libraries / libldap / disptmpl.c
index be418309e982a74b6d594fa808fd69e5ac825a4d..f1cf4117ce83b6844b895e7f8aec6ec22df7586c 100644 (file)
@@ -1,4 +1,9 @@
+/* $OpenLDAP$ */
 /*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  * Copyright (c) 1993, 1994 Regents of the University of Michigan.
  * All rights reserved.
  *
  * 7 March 1994 by Mark C Smith
  */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef MACOS
-#include "macos.h"
-#else /* MACOS */
-#ifdef DOS
-#include <malloc.h>
-#include "msdos.h"
-#else /* DOS */
-#include <sys/types.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/string.h>
+#include <ac/time.h>
+#include <ac/unistd.h>
+
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
-#ifndef VMS
-#include <unistd.h>
-#endif /* VMS */
-#endif /* DOS */
-#endif /* MACOS */
-
-#include "lber.h"
-#include "ldap.h"
+#endif
+
+#include "ldap-int.h"
 #include "disptmpl.h"
 
-#ifndef NEEDPROTOS
-static void free_disptmpl();
-static int read_next_tmpl();
-int next_line_tokens();
-void free_strarray();
-#else /* !NEEDPROTOS */
-static void free_disptmpl( struct ldap_disptmpl *tmpl );
-static int read_next_tmpl( char **bufp, long *blenp,
-       struct ldap_disptmpl **tmplp, int dtversion );
-int next_line_tokens( char **bufp, long *blenp, char ***toksp );
-void free_strarray( char **sap );
-#endif /* !NEEDPROTOS */
-
-static char            *tmploptions[] = {
+static void free_disptmpl LDAP_P(( struct ldap_disptmpl *tmpl ));
+static int read_next_tmpl LDAP_P(( char **bufp, ber_len_t *blenp,
+       struct ldap_disptmpl **tmplp, int dtversion ));
+
+static const char *const       tmploptions[] = {
     "addable", "modrdn",
     "altview",
     NULL
 };
 
 
-static unsigned long   tmploptvals[] = {
+static const unsigned long     tmploptvals[] = {
     LDAP_DTMPL_OPT_ADDABLE, LDAP_DTMPL_OPT_ALLOWMODRDN,
     LDAP_DTMPL_OPT_ALTVIEW,
 };
 
 
-static char            *itemtypes[] = {
+static const char *const       itemtypes[] = {
     "cis",                     "mls",                  "dn",
     "bool",                    "jpeg",                 "jpegbtn",
     "fax",                     "faxbtn",               "audiobtn",
@@ -72,7 +62,7 @@ static char           *itemtypes[] = {
     NULL
 };
 
-static unsigned long   itemsynids[] = {
+static const unsigned long     itemsynids[] = {
     LDAP_SYN_CASEIGNORESTR,    LDAP_SYN_MULTILINESTR,  LDAP_SYN_DN,
     LDAP_SYN_BOOLEAN,          LDAP_SYN_JPEGIMAGE,     LDAP_SYN_JPEGBUTTON,
     LDAP_SYN_FAXIMAGE,         LDAP_SYN_FAXBUTTON,     LDAP_SYN_AUDIOBUTTON,
@@ -82,7 +72,7 @@ static unsigned long  itemsynids[] = {
 };
 
 
-static char            *itemoptions[] = {
+static const char *const       itemoptions[] = {
     "ro",                              "sort",
     "1val",                            "hide",
     "required",                                "hideiffalse",
@@ -90,7 +80,7 @@ static char           *itemoptions[] = {
 };
 
 
-static unsigned long   itemoptvals[] = {
+static const unsigned long     itemoptvals[] = {
     LDAP_DITEM_OPT_READONLY,           LDAP_DITEM_OPT_SORTVALUES,
     LDAP_DITEM_OPT_SINGLEVALUED,       LDAP_DITEM_OPT_HIDEIFEMPTY,
     LDAP_DITEM_OPT_VALUEREQUIRED,      LDAP_DITEM_OPT_HIDEIFFALSE,
@@ -109,7 +99,7 @@ ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp )
     long       rlen, len;
     int                rc, eof;
 
-    *tmpllistp = NULLDISPTMPL;
+    *tmpllistp = NULL;
 
     if (( fp = fopen( file, "r" )) == NULL ) {
        return( LDAP_TMPL_ERR_FILE );
@@ -127,7 +117,7 @@ ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp )
        return( LDAP_TMPL_ERR_FILE );
     }
 
-    if (( buf = malloc( (size_t)len )) == NULL ) {
+    if (( buf = LDAP_MALLOC( (size_t)len )) == NULL ) {
        fclose( fp );
        return( LDAP_TMPL_ERR_MEM );
     }
@@ -137,41 +127,41 @@ ldap_init_templates( char *file, struct ldap_disptmpl **tmpllistp )
     fclose( fp );
 
     if ( rlen != len && !eof ) {       /* error:  didn't get the whole file */
-       free( buf );
+       LDAP_FREE( buf );
        return( LDAP_TMPL_ERR_FILE );
     }
 
     rc = ldap_init_templates_buf( buf, rlen, tmpllistp );
-    free( buf );
+    LDAP_FREE( buf );
 
     return( rc );
 }
 
 
 int
-ldap_init_templates_buf( char *buf, long buflen,
+ldap_init_templates_buf( char *buf, ber_len_t buflen,
        struct ldap_disptmpl **tmpllistp )
 {
-    int                                rc, version;
+    int                                rc=-1, version;
     char                       **toks;
     struct ldap_disptmpl       *prevtmpl, *tmpl;
 
-    *tmpllistp = prevtmpl = NULLDISPTMPL;
+    *tmpllistp = prevtmpl = NULL;
 
-    if ( next_line_tokens( &buf, &buflen, &toks ) != 2 ||
+    if ( ldap_int_next_line_tokens( &buf, &buflen, &toks ) != 2 ||
            strcasecmp( toks[ 0 ], "version" ) != 0 ) {
-       free_strarray( toks );
+       LDAP_VFREE( toks );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
     version = atoi( toks[ 1 ] );
-    free_strarray( toks );
+    LDAP_VFREE( toks );
     if ( version != LDAP_TEMPLATE_VERSION ) {
        return( LDAP_TMPL_ERR_VERSION );
     }
 
     while ( buflen > 0 && ( rc = read_next_tmpl( &buf, &buflen, &tmpl,
-           version )) == 0 && tmpl != NULLDISPTMPL ) {
-       if ( prevtmpl == NULLDISPTMPL ) {
+           version )) == 0 && tmpl != NULL ) {
+       if ( prevtmpl == NULL ) {
            *tmpllistp = tmpl;
        } else {
            prevtmpl->dt_next = tmpl;
@@ -207,27 +197,27 @@ free_disptmpl( struct ldap_disptmpl *tmpl )
 {
     if ( tmpl != NULL ) {
        if ( tmpl->dt_name != NULL ) {
-           free(  tmpl->dt_name );
+           LDAP_FREE(  tmpl->dt_name );
        }
 
        if ( tmpl->dt_pluralname != NULL ) {
-           free( tmpl->dt_pluralname );
+           LDAP_FREE( tmpl->dt_pluralname );
        }
 
        if ( tmpl->dt_iconname != NULL ) {
-           free( tmpl->dt_iconname );
+           LDAP_FREE( tmpl->dt_iconname );
        }
 
        if ( tmpl->dt_authattrname != NULL ) {
-           free( tmpl->dt_authattrname );
+           LDAP_FREE( tmpl->dt_authattrname );
        }
 
        if ( tmpl->dt_defrdnattrname != NULL ) {
-           free( tmpl->dt_defrdnattrname );
+           LDAP_FREE( tmpl->dt_defrdnattrname );
        }
 
        if ( tmpl->dt_defaddlocation != NULL ) {
-           free( tmpl->dt_defaddlocation );
+           LDAP_FREE( tmpl->dt_defaddlocation );
        }
 
        if (  tmpl->dt_oclist != NULL ) {
@@ -235,8 +225,8 @@ free_disptmpl( struct ldap_disptmpl *tmpl )
 
            for ( ocp = tmpl->dt_oclist; ocp != NULL; ocp = nextocp ) {
                nextocp = ocp->oc_next;
-               free_strarray( ocp->oc_objclasses );
-               free( ocp );
+               LDAP_VFREE( ocp->oc_objclasses );
+               LDAP_FREE( ocp );
            }
        }
 
@@ -246,12 +236,12 @@ free_disptmpl( struct ldap_disptmpl *tmpl )
            for ( adp = tmpl->dt_adddeflist; adp != NULL; adp = nextadp ) {
                nextadp = adp->ad_next;
                if( adp->ad_attrname != NULL ) {
-                   free( adp->ad_attrname );
+                   LDAP_FREE( adp->ad_attrname );
                }
                if( adp->ad_value != NULL ) {
-                   free( adp->ad_value );
+                   LDAP_FREE( adp->ad_value );
                }
-               free( adp );
+               LDAP_FREE( adp );
            }
        }
 
@@ -263,20 +253,20 @@ free_disptmpl( struct ldap_disptmpl *tmpl )
                for ( colp = rowp; colp != NULL; colp = nextcolp ) {
                    nextcolp = colp->ti_next_in_row;
                    if ( colp->ti_attrname != NULL ) {
-                       free( colp->ti_attrname );
+                       LDAP_FREE( colp->ti_attrname );
                    }
                    if ( colp->ti_label != NULL ) {
-                       free( colp->ti_label );
+                       LDAP_FREE( colp->ti_label );
                    }
                    if ( colp->ti_args != NULL ) {
-                       free_strarray( colp->ti_args );
+                       LDAP_VFREE( colp->ti_args );
                    }
-                   free( colp );
+                   LDAP_FREE( colp );
                }
            }
        }
 
-       free( tmpl );
+       LDAP_FREE( tmpl );
     }
 }
 
@@ -292,7 +282,7 @@ struct ldap_disptmpl *
 ldap_next_disptmpl( struct ldap_disptmpl *tmpllist,
        struct ldap_disptmpl *tmpl )
 {
-    return( tmpl == NULLDISPTMPL ? tmpl : tmpl->dt_next );
+    return( tmpl == NULL ? tmpl : tmpl->dt_next );
 }
 
 
@@ -301,14 +291,14 @@ ldap_name2template( char *name, struct ldap_disptmpl *tmpllist )
 {
     struct ldap_disptmpl       *dtp;
 
-    for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULLDISPTMPL;
+    for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULL;
            dtp = ldap_next_disptmpl( tmpllist, dtp )) {
        if ( strcasecmp( name, dtp->dt_name ) == 0 ) {
            return( dtp );
        }
     }
 
-    return( NULLDISPTMPL );
+    return( NULL );
 }
 
 
@@ -320,12 +310,12 @@ ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist )
     int                                i, j, needcnt, matchcnt;
 
     if ( tmpllist == NULL || oclist == NULL || oclist[ 0 ] == NULL ) {
-       return( NULLDISPTMPL );
+       return( NULL );
     }
 
-    for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULLDISPTMPL;
+    for ( dtp = ldap_first_disptmpl( tmpllist ); dtp != NULL;
                dtp = ldap_next_disptmpl( tmpllist, dtp )) {
-       for ( oclp = dtp->dt_oclist; oclp != NULLOCLIST;
+       for ( oclp = dtp->dt_oclist; oclp != NULL;
                oclp = oclp->oc_next ) {
            needcnt = matchcnt = 0;
            for ( i = 0; oclp->oc_objclasses[ i ] != NULL; ++i ) {
@@ -344,7 +334,7 @@ ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist )
        }
     }
 
-    return( NULLDISPTMPL );
+    return( NULL );
 }
 
 
@@ -358,7 +348,7 @@ ldap_first_tmplrow( struct ldap_disptmpl *tmpl )
 struct ldap_tmplitem *
 ldap_next_tmplrow( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row )
 {
-    return( row == NULLTMPLITEM ? row : row->ti_next_in_col );
+    return( row == NULL ? row : row->ti_next_in_col );
 }
 
 
@@ -373,7 +363,7 @@ struct ldap_tmplitem *
 ldap_next_tmplcol( struct ldap_disptmpl *tmpl, struct ldap_tmplitem *row,
        struct ldap_tmplitem *col )
 {
-    return( col == NULLTMPLITEM ? col : col->ti_next_in_row );
+    return( col == NULL ? col : col->ti_next_in_row );
 }
 
 
@@ -391,15 +381,15 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
     attrcnt = 0;
     memerr = 0;
 
-    if (( attrs = (char **)malloc( sizeof( char * ))) == NULL ) {
+    if (( attrs = (char **)LDAP_MALLOC( sizeof( char * ))) == NULL ) {
        return( NULL );
     }
 
     if ( includeattrs != NULL ) {
        for ( i = 0; !memerr && includeattrs[ i ] != NULL; ++i ) {
-           if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) *
+           if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) *
                    sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
-                   strdup( includeattrs[ i ] )) == NULL ) {
+                   LDAP_STRDUP( includeattrs[ i ] )) == NULL ) {
                memerr = 1;
            } else {
                attrs[ attrcnt ] = NULL;
@@ -408,10 +398,10 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
     }
 
     for ( tirowp = ldap_first_tmplrow( tmpl );
-           !memerr && tirowp != NULLTMPLITEM;
+           !memerr && tirowp != NULL;
            tirowp = ldap_next_tmplrow( tmpl, tirowp )) {
        for ( ticolp = ldap_first_tmplcol( tmpl, tirowp );
-               ticolp != NULLTMPLITEM;
+               ticolp != NULL;
                ticolp = ldap_next_tmplcol( tmpl, tirowp, ticolp )) {
 
            if ( syntaxmask != 0 ) {
@@ -424,9 +414,9 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
            }
 
            if ( ticolp->ti_attrname != NULL ) {
-               if (( attrs = (char **)realloc( attrs, ( attrcnt + 2 ) *
+               if (( attrs = (char **)LDAP_REALLOC( attrs, ( attrcnt + 2 ) *
                        sizeof( char * ))) == NULL || ( attrs[ attrcnt++ ] =
-                       strdup( ticolp->ti_attrname )) == NULL ) {
+                       LDAP_STRDUP( ticolp->ti_attrname )) == NULL ) {
                    memerr = 1;
                } else {
                    attrs[ attrcnt ] = NULL;
@@ -438,11 +428,11 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
     if ( memerr || attrcnt == 0 ) {
        for ( i = 0; i < attrcnt; ++i ) {
            if ( attrs[ i ] != NULL ) {
-               free( attrs[ i ] );
+               LDAP_FREE( attrs[ i ] );
            }
        }
 
-       free( (char *)attrs );
+       LDAP_FREE( (char *)attrs );
        return( NULL );
     }
 
@@ -451,61 +441,61 @@ ldap_tmplattrs( struct ldap_disptmpl *tmpl, char **includeattrs,
 
 
 static int
-read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
+read_next_tmpl( char **bufp, ber_len_t *blenp, struct ldap_disptmpl **tmplp,
        int dtversion )
 {
     int                                i, j, tokcnt, samerow, adsource;
     char                       **toks, *itemopts;
     struct ldap_disptmpl       *tmpl;
-    struct ldap_oclist         *ocp, *prevocp;
-    struct ldap_adddeflist     *adp, *prevadp;
-    struct ldap_tmplitem       *rowp, *ip, *previp;
+    struct ldap_oclist         *ocp, *prevocp = NULL;
+    struct ldap_adddeflist     *adp, *prevadp = NULL;
+    struct ldap_tmplitem       *rowp = NULL, *ip, *previp = NULL;
 
     *tmplp = NULL;
 
     /*
      * template name comes first
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
+       LDAP_VFREE( toks );
        return( tokcnt == 0 ? 0 : LDAP_TMPL_ERR_SYNTAX );
     }
 
-    if (( tmpl = (struct ldap_disptmpl *)calloc( 1,
+    if (( tmpl = (struct ldap_disptmpl *)LDAP_CALLOC( 1,
            sizeof( struct ldap_disptmpl ))) == NULL ) {
-       free_strarray( toks );
+       LDAP_VFREE( toks );
        return(  LDAP_TMPL_ERR_MEM );
     }
     tmpl->dt_name = toks[ 0 ];
-    free( (char *)toks );
+    LDAP_FREE( (char *)toks );
 
     /*
      * template plural name comes next
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
+       LDAP_VFREE( toks );
        free_disptmpl( tmpl );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
     tmpl->dt_pluralname = toks[ 0 ];
-    free( (char *)toks );
+    LDAP_FREE( (char *)toks );
 
     /*
      * template icon name is next
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
+       LDAP_VFREE( toks );
        free_disptmpl( tmpl );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
     tmpl->dt_iconname = toks[ 0 ];
-    free( (char *)toks );
+    LDAP_FREE( (char *)toks );
 
     /*
      * template options come next
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) < 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) < 1 ) {
+       LDAP_VFREE( toks );
        free_disptmpl( tmpl );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
@@ -516,15 +506,15 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
            }
        }
     }
-    free_strarray( toks );
+    LDAP_VFREE( toks );
 
     /*
      * object class list is next
      */
-    while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
-       if (( ocp = (struct ldap_oclist *)calloc( 1,
+    while (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
+       if (( ocp = (struct ldap_oclist *)LDAP_CALLOC( 1,
                sizeof( struct ldap_oclist ))) == NULL ) {
-           free_strarray( toks );
+           LDAP_VFREE( toks );
            free_disptmpl( tmpl );
            return( LDAP_TMPL_ERR_MEM );
        }
@@ -544,48 +534,48 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
     /*
      * read name of attribute to authenticate as
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
+       LDAP_VFREE( toks );
        free_disptmpl( tmpl );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
     if ( toks[ 0 ][ 0 ] != '\0' ) {
        tmpl->dt_authattrname = toks[ 0 ];
     } else {
-       free( toks[ 0 ] );
+       LDAP_FREE( toks[ 0 ] );
     }
-    free( (char *)toks );
+    LDAP_FREE( (char *)toks );
 
     /*
      * read default attribute to use for RDN
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
+       LDAP_VFREE( toks );
        free_disptmpl( tmpl );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
     tmpl->dt_defrdnattrname = toks[ 0 ];
-    free( (char *)toks );
+    LDAP_FREE( (char *)toks );
 
     /*
      * read default location for new entries
      */
-    if (( tokcnt = next_line_tokens( bufp, blenp, &toks )) != 1 ) {
-       free_strarray( toks );
+    if (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) != 1 ) {
+       LDAP_VFREE( toks );
        free_disptmpl( tmpl );
        return( LDAP_TMPL_ERR_SYNTAX );
     }
     if ( toks[ 0 ][ 0 ] != '\0' ) {
        tmpl->dt_defaddlocation = toks[ 0 ];
     } else {
-       free( toks[ 0 ] );
+       LDAP_FREE( toks[ 0 ] );
     }
-    free( (char *)toks );
+    LDAP_FREE( (char *)toks );
 
     /*
      * read list of rules used to define default values for new entries
      */
-    while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
+    while (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
        if ( strcasecmp( ADDEF_CONSTANT, toks[ 0 ] ) == 0 ) {
            adsource = LDAP_ADSRC_CONSTANTVALUE;
        } else if ( strcasecmp( ADDEF_ADDERSDN, toks[ 0 ] ) == 0 ) {
@@ -596,14 +586,14 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
        if ( adsource == 0 || tokcnt < 2 ||
                ( adsource == LDAP_ADSRC_CONSTANTVALUE && tokcnt != 3 ) ||
                ( adsource == LDAP_ADSRC_ADDERSDN && tokcnt != 2 )) {
-           free_strarray( toks );
+           LDAP_VFREE( toks );
            free_disptmpl( tmpl );
            return( LDAP_TMPL_ERR_SYNTAX );
        }
                
-       if (( adp = (struct ldap_adddeflist *)calloc( 1,
+       if (( adp = (struct ldap_adddeflist *)LDAP_CALLOC( 1,
                sizeof( struct ldap_adddeflist ))) == NULL ) {
-           free_strarray( toks );
+           LDAP_VFREE( toks );
            free_disptmpl( tmpl );
            return( LDAP_TMPL_ERR_MEM );
        }
@@ -612,8 +602,8 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
        if ( adsource == LDAP_ADSRC_CONSTANTVALUE ) {
            adp->ad_value = toks[ 2 ];
        }
-       free( toks[ 0 ] );
-       free( (char *)toks );
+       LDAP_FREE( toks[ 0 ] );
+       LDAP_FREE( (char *)toks );
 
        if ( tmpl->dt_adddeflist == NULL ) {
            tmpl->dt_adddeflist = adp;
@@ -627,17 +617,17 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
      * item list is next
      */
     samerow = 0;
-    while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) {
+    while (( tokcnt = ldap_int_next_line_tokens( bufp, blenp, &toks )) > 0 ) {
        if ( strcasecmp( toks[ 0 ], "item" ) == 0 ) {
            if ( tokcnt < 4 ) {
-               free_strarray( toks );
+               LDAP_VFREE( toks );
                free_disptmpl( tmpl );
                return( LDAP_TMPL_ERR_SYNTAX );
            }
 
-           if (( ip = (struct ldap_tmplitem *)calloc( 1,
+           if (( ip = (struct ldap_tmplitem *)LDAP_CALLOC( 1,
                    sizeof( struct ldap_tmplitem ))) == NULL ) {
-               free_strarray( toks );
+               LDAP_VFREE( toks );
                free_disptmpl( tmpl );
                return( LDAP_TMPL_ERR_MEM );
            }
@@ -653,7 +643,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
                    }
                }
                if ( itemoptions[ i ] == NULL ) {
-                   free_strarray( toks );
+                   LDAP_VFREE( toks );
                    free_disptmpl( tmpl );
                    return( LDAP_TMPL_ERR_SYNTAX );
                }
@@ -666,18 +656,18 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
                }
            }
            if ( itemtypes[ i ] == NULL ) {
-               free_strarray( toks );
+               LDAP_VFREE( toks );
                free_disptmpl( tmpl );
                return( LDAP_TMPL_ERR_SYNTAX );
            }
 
-           free( toks[ 0 ] );
-           free( toks[ 1 ] );
+           LDAP_FREE( toks[ 0 ] );
+           LDAP_FREE( toks[ 1 ] );
            ip->ti_syntaxid = itemsynids[ i ];
            ip->ti_label = toks[ 2 ];
            if ( toks[ 3 ][ 0 ] == '\0' ) {
                ip->ti_attrname = NULL;
-               free( toks[ 3 ] );
+               LDAP_FREE( toks[ 3 ] );
            } else {
                ip->ti_attrname = toks[ 3 ];
            }
@@ -685,7 +675,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
                for ( i = 0; toks[ i + 4 ] != NULL; ++i ) {
                    ;
                }
-               if (( ip->ti_args = (char **) calloc( i + 1, sizeof( char * )))
+               if (( ip->ti_args = (char **) LDAP_CALLOC( i + 1, sizeof( char * )))
                        == NULL ) {
                    free_disptmpl( tmpl );
                    return( LDAP_TMPL_ERR_MEM );
@@ -694,7 +684,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
                    ip->ti_args[ i ] = toks[ i + 4 ];
                }
            }
-           free( (char *)toks );
+           LDAP_FREE( (char *)toks );
 
            if ( tmpl->dt_items == NULL ) {
                tmpl->dt_items = rowp = ip;
@@ -707,10 +697,10 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp,
            previp = ip;
            samerow = 0;
        } else if ( strcasecmp( toks[ 0 ], "samerow" ) == 0 ) {
-           free_strarray( toks );
+           LDAP_VFREE( toks );
            samerow = 1;
        } else {
-           free_strarray( toks );
+           LDAP_VFREE( toks );
            free_disptmpl( tmpl );
            return( LDAP_TMPL_ERR_SYNTAX );
        }