2 static char copyright[] = "Copyright 1992 The University of Adelaide";
8 * Author: Mark R. Prior
9 * Communications and Systems Branch
10 * Information Technology Division
11 * The University of Adelaide
12 * E-mail: mrp@itd.adelaide.edu.au
16 * This module deals with whois++ templates
18 * Redistribution and use in source and binary forms are permitted
19 * provided that the above copyright notice and this paragraph are
20 * duplicated in all such forms and that any documentation,
21 * advertising materials, and other materials related to such
22 * distribution and use acknowledge that the software was developed
23 * by the University of Adelaide. The name of the University may not
24 * be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
27 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
28 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
36 showTemplate( char *template )
38 char filename[MAXPATHLEN], buffer[BUFSIZ];
42 if ( template == NULL || *template == '\0' )
44 sprintf( filename, "%s/templates/%s", configDir, template );
45 if ( ( description = fopen( filename, "r" ) ) == NULL )
46 printFormatted( lineLength, TRUE, stdout,
47 "Cannot find template %s", template );
49 while ( fgets( buffer, BUFSIZ, description ) != NULL ) {
52 ( buffer[i] == '\n' || buffer[i] == '\r' ) )
54 printFormatted( lineLength, FALSE, stdout,
57 fclose( description );
62 listTemplates( char *query )
64 char filename[MAXPATHLEN];
68 if ( query == NULL || *query == '\0' ) {
69 sprintf( filename, "%s/templates", configDir );
70 if ( ( dir = opendir( filename ) ) == NULL ) {
71 printFormatted( lineLength, TRUE, stdout,
72 "Cannot access template descriptions - %s",
76 for ( entry = readdir( dir ); entry != NULL; entry = readdir( dir ) )
77 if ( !EQ(entry->d_name, "." ) && !EQ(entry->d_name, ".." ) )
78 printFormatted( lineLength, FALSE, stdout,
79 " %s", lowerCase( entry->d_name ) );
82 sprintf( filename, "%s/templates/%s", configDir, query );
83 if ( fopen( filename, "r" ) == NULL )
84 printFormatted( lineLength, TRUE, stdout,
85 "No such template (%s)", query );
87 printFormatted( lineLength, FALSE, stdout,
93 specifyAttributes( char *objectClass )
96 char filename[MAXPATHLEN], buffer[BUFSIZ];
98 int max = ATTRIBUTE_INCREMENT;
101 if ( objectClass == NULL || *objectClass == '\0' )
103 sprintf( filename, "%s/templates/%s", configDir,
104 lowerCase( objectClass ) );
105 if ( ( description = fopen( filename, "r" ) ) == NULL )
107 if ( ( attributes = (char **)malloc( max*sizeof(char *) ) ) == NULL ) {
108 printFormatted( lineLength, TRUE, stdout,
109 "Error while attempting to create attribute list - %s",
113 while ( fgets( buffer, BUFSIZ, description ) != NULL ) {
114 i = strlen( buffer );
115 while ( i-- > 0 && ( buffer[i] == '\n' || buffer[i] == '\r' ) )
117 attributes[number++] = strdup( buffer );
118 if ( number == max ) {
119 max += ATTRIBUTE_INCREMENT;
120 if ( ( attributes = (char **)realloc( attributes, max*sizeof(char *)) ) == NULL ) {
121 printFormatted( lineLength, TRUE, stdout,
122 "Error while attempting to extend attribute list - %s",
128 attributes[number] = NULL;
129 fclose( description );
134 templateToObjectClass( char *template )
138 if ( template == NULL || *template == '\0' ) {
139 printFormatted( lineLength, TRUE, stdout,
140 "Unrecognised template" );
141 return "unrecognised";
143 for ( i = 0; i < numberOfTemplates; i++ )
144 if ( EQ( template, templateTranslationTable[i].key ) )
145 return templateTranslationTable[i].value;
146 printFormatted( lineLength, TRUE, stdout,
147 "Template (%s) not recognised, assuming that it is already an objectClass",
153 objectClassToTemplate( char *objectClass )
157 if ( objectClass == NULL || *objectClass == '\0' ) {
158 printFormatted( lineLength, TRUE, stdout,
159 "Unrecognised template" );
160 return "unrecognised";
162 for ( i = 0; i < numberOfTemplates; i++ )
163 if ( EQ( objectClass, templateTranslationTable[i].value ) )
164 return templateTranslationTable[i].key;