X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fdisptmpl.c;h=7ddad7700afe0e18fb2df0b569451c253cae249b;hb=7573a81efea63bc0e07d88ba4c9b6973d51d857d;hp=291316dcb62d8f9422630b42a162bf2e077c1558;hpb=13bd786abf3248e39428a8edac67c27772cb8dc0;p=openldap diff --git a/libraries/libldap/disptmpl.c b/libraries/libldap/disptmpl.c index 291316dcb6..7ddad7700a 100644 --- a/libraries/libldap/disptmpl.c +++ b/libraries/libldap/disptmpl.c @@ -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. * @@ -16,42 +21,39 @@ #include "portable.h" #include -#include -#include +#include + +#include #include #include +#include #ifdef HAVE_SYS_FILE_H #include #endif -#include - -#include "lber.h" -#include "ldap.h" +#include "ldap-int.h" #include "disptmpl.h" static void free_disptmpl LDAP_P(( struct ldap_disptmpl *tmpl )); -static int read_next_tmpl LDAP_P(( char **bufp, long *blenp, +static int read_next_tmpl LDAP_P(( char **bufp, ber_len_t *blenp, struct ldap_disptmpl **tmplp, int dtversion )); -int next_line_tokens LDAP_P(( char **bufp, long *blenp, char ***toksp )); -void free_strarray LDAP_P(( char **sap )); -static char *tmploptions[] = { +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", @@ -61,7 +63,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, @@ -71,7 +73,7 @@ static unsigned long itemsynids[] = { }; -static char *itemoptions[] = { +static const char *const itemoptions[] = { "ro", "sort", "1val", "hide", "required", "hideiffalse", @@ -79,7 +81,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, @@ -98,7 +100,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 ); @@ -116,7 +118,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 ); } @@ -126,26 +128,26 @@ 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=-1, version; char **toks; struct ldap_disptmpl *prevtmpl, *tmpl; - *tmpllistp = prevtmpl = NULLDISPTMPL; + *tmpllistp = prevtmpl = NULL; if ( next_line_tokens( &buf, &buflen, &toks ) != 2 || strcasecmp( toks[ 0 ], "version" ) != 0 ) { @@ -159,8 +161,8 @@ ldap_init_templates_buf( char *buf, long buflen, } 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; @@ -196,27 +198,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 ) { @@ -225,7 +227,7 @@ 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_FREE( ocp ); } } @@ -235,12 +237,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 ); } } @@ -252,20 +254,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 ); } - free( colp ); + LDAP_FREE( colp ); } } } - free( tmpl ); + LDAP_FREE( tmpl ); } } @@ -281,7 +283,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 ); } @@ -290,14 +292,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 ); } @@ -309,12 +311,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 ) { @@ -333,7 +335,7 @@ ldap_oc2template( char **oclist, struct ldap_disptmpl *tmpllist ) } } - return( NULLDISPTMPL ); + return( NULL ); } @@ -347,7 +349,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 ); } @@ -362,7 +364,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 ); } @@ -380,15 +382,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; @@ -397,10 +399,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 ) { @@ -413,9 +415,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; @@ -427,11 +429,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 ); } @@ -440,7 +442,7 @@ 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; @@ -460,13 +462,13 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, 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 ); return( LDAP_TMPL_ERR_MEM ); } tmpl->dt_name = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * template plural name comes next @@ -477,7 +479,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } tmpl->dt_pluralname = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * template icon name is next @@ -488,7 +490,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } tmpl->dt_iconname = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * template options come next @@ -511,7 +513,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, * object class list is next */ while (( tokcnt = next_line_tokens( bufp, blenp, &toks )) > 0 ) { - if (( ocp = (struct ldap_oclist *)calloc( 1, + if (( ocp = (struct ldap_oclist *)LDAP_CALLOC( 1, sizeof( struct ldap_oclist ))) == NULL ) { free_strarray( toks ); free_disptmpl( tmpl ); @@ -541,9 +543,9 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, 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 @@ -554,7 +556,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, return( LDAP_TMPL_ERR_SYNTAX ); } tmpl->dt_defrdnattrname = toks[ 0 ]; - free( (char *)toks ); + LDAP_FREE( (char *)toks ); /* * read default location for new entries @@ -567,9 +569,9 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, 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 @@ -590,7 +592,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, 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 ); free_disptmpl( tmpl ); @@ -601,8 +603,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; @@ -624,7 +626,7 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, 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 ); free_disptmpl( tmpl ); @@ -660,13 +662,13 @@ read_next_tmpl( char **bufp, long *blenp, struct ldap_disptmpl **tmplp, 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 ]; } @@ -674,7 +676,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 ); @@ -683,7 +685,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;