1*004388ebScasper /*
2*004388ebScasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3*004388ebScasper * Use is subject to license terms.
4*004388ebScasper */
57c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
67c478bd9Sstevel@tonic-gate
77c478bd9Sstevel@tonic-gate /*
87c478bd9Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
97c478bd9Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
107c478bd9Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
117c478bd9Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
147c478bd9Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
157c478bd9Sstevel@tonic-gate * implied. See the License for the specific language governing
167c478bd9Sstevel@tonic-gate * rights and limitations under the License.
177c478bd9Sstevel@tonic-gate *
187c478bd9Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
197c478bd9Sstevel@tonic-gate * March 31, 1998.
207c478bd9Sstevel@tonic-gate *
217c478bd9Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
227c478bd9Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
237c478bd9Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
247c478bd9Sstevel@tonic-gate * Rights Reserved.
257c478bd9Sstevel@tonic-gate *
267c478bd9Sstevel@tonic-gate * Contributor(s):
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Copyright (c) 1990 Regents of the University of Michigan.
307c478bd9Sstevel@tonic-gate * All rights reserved.
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate * friendly.c
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #if 0
377c478bd9Sstevel@tonic-gate #ifndef lint
387c478bd9Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1993 Regents of the University of Michigan.\nAll rights reserved.\n";
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include "ldap-int.h"
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate char *
457c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_friendly_name(char * filename,char * name,FriendlyMap * map)467c478bd9Sstevel@tonic-gate ldap_friendly_name( char *filename, char *name, FriendlyMap *map )
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate int i, entries;
497c478bd9Sstevel@tonic-gate FILE *fp;
507c478bd9Sstevel@tonic-gate char *s;
517c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate if ( map == NULL ) {
547c478bd9Sstevel@tonic-gate return( name );
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate if ( NULL == name)
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate return (name);
597c478bd9Sstevel@tonic-gate }
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate if ( *map == NULL ) {
62*004388ebScasper if ( (fp = fopen( filename, "rF" )) == NULL )
637c478bd9Sstevel@tonic-gate return( name );
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate entries = 0;
667c478bd9Sstevel@tonic-gate while ( fgets( buf, sizeof(buf), fp ) != NULL ) {
677c478bd9Sstevel@tonic-gate if ( buf[0] != '#' )
687c478bd9Sstevel@tonic-gate entries++;
697c478bd9Sstevel@tonic-gate }
707c478bd9Sstevel@tonic-gate rewind( fp );
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate if ( (*map = (FriendlyMap)NSLDAPI_MALLOC( (entries + 1) *
737c478bd9Sstevel@tonic-gate sizeof(struct friendly) )) == NULL ) {
747c478bd9Sstevel@tonic-gate fclose( fp );
757c478bd9Sstevel@tonic-gate return( name );
767c478bd9Sstevel@tonic-gate }
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate i = 0;
797c478bd9Sstevel@tonic-gate while ( fgets( buf, sizeof(buf), fp ) != NULL && i < entries ) {
807c478bd9Sstevel@tonic-gate if ( buf[0] == '#' )
817c478bd9Sstevel@tonic-gate continue;
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate if ( (s = strchr( buf, '\n' )) != NULL )
847c478bd9Sstevel@tonic-gate *s = '\0';
857c478bd9Sstevel@tonic-gate
867c478bd9Sstevel@tonic-gate if ( (s = strchr( buf, '\t' )) == NULL )
877c478bd9Sstevel@tonic-gate continue;
887c478bd9Sstevel@tonic-gate *s++ = '\0';
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate if ( *s == '"' ) {
917c478bd9Sstevel@tonic-gate int esc = 0, found = 0;
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate for ( ++s; *s && !found; s++ ) {
947c478bd9Sstevel@tonic-gate switch ( *s ) {
957c478bd9Sstevel@tonic-gate case '\\':
967c478bd9Sstevel@tonic-gate esc = 1;
977c478bd9Sstevel@tonic-gate break;
987c478bd9Sstevel@tonic-gate case '"':
997c478bd9Sstevel@tonic-gate if ( !esc )
1007c478bd9Sstevel@tonic-gate found = 1;
1017c478bd9Sstevel@tonic-gate /* FALL */
1027c478bd9Sstevel@tonic-gate default:
1037c478bd9Sstevel@tonic-gate esc = 0;
1047c478bd9Sstevel@tonic-gate break;
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate (*map)[i].f_unfriendly = nsldapi_strdup( buf );
1107c478bd9Sstevel@tonic-gate (*map)[i].f_friendly = nsldapi_strdup( s );
1117c478bd9Sstevel@tonic-gate i++;
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate fclose( fp );
1157c478bd9Sstevel@tonic-gate (*map)[i].f_unfriendly = NULL;
1167c478bd9Sstevel@tonic-gate }
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate for ( i = 0; (*map)[i].f_unfriendly != NULL; i++ ) {
1197c478bd9Sstevel@tonic-gate if ( strcasecmp( name, (*map)[i].f_unfriendly ) == 0 )
1207c478bd9Sstevel@tonic-gate return( (*map)[i].f_friendly );
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate return( name );
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate void
1277c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_free_friendlymap(FriendlyMap * map)1287c478bd9Sstevel@tonic-gate ldap_free_friendlymap( FriendlyMap *map )
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate struct friendly* pF;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate if ( map == NULL || *map == NULL ) {
1337c478bd9Sstevel@tonic-gate return;
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate for ( pF = *map; pF->f_unfriendly; pF++ ) {
1377c478bd9Sstevel@tonic-gate NSLDAPI_FREE( pF->f_unfriendly );
1387c478bd9Sstevel@tonic-gate NSLDAPI_FREE( pF->f_friendly );
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate NSLDAPI_FREE( *map );
1417c478bd9Sstevel@tonic-gate *map = NULL;
1427c478bd9Sstevel@tonic-gate }
143