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.
33 void showTemplate( template )
37 char filename[MAXPATHLEN], buffer[BUFSIZ];
41 if ( template == NULL || *template == '\0' )
43 sprintf( filename, "%s/templates/%s", configDir, template );
44 if ( ( description = fopen( filename, "r" ) ) == NULL )
45 printFormatted( lineLength, TRUE, stdout,
46 "Cannot find template %s", template );
48 while ( fgets( buffer, BUFSIZ, description ) != NULL ) {
51 ( buffer[i] == '\n' || buffer[i] == '\r' ) )
53 printFormatted( lineLength, FALSE, stdout,
56 fclose( description );
60 void listTemplates( 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,
92 char **specifyAttributes( objectClass )
97 char filename[MAXPATHLEN], buffer[BUFSIZ];
99 int max = ATTRIBUTE_INCREMENT;
102 if ( objectClass == NULL || *objectClass == '\0' )
104 sprintf( filename, "%s/templates/%s", configDir,
105 lowerCase( objectClass ) );
106 if ( ( description = fopen( filename, "r" ) ) == NULL )
108 if ( ( attributes = (char **)malloc( max*sizeof(char *) ) ) == NULL ) {
109 printFormatted( lineLength, TRUE, stdout,
110 "Error while attempting to create attribute list - %s",
114 while ( fgets( buffer, BUFSIZ, description ) != NULL ) {
115 i = strlen( buffer );
116 while ( i-- > 0 && ( buffer[i] == '\n' || buffer[i] == '\r' ) )
118 attributes[number++] = strdup( buffer );
119 if ( number == max ) {
120 max += ATTRIBUTE_INCREMENT;
121 if ( ( attributes = (char **)realloc( attributes, max*sizeof(char *)) ) == NULL ) {
122 printFormatted( lineLength, TRUE, stdout,
123 "Error while attempting to extend attribute list - %s",
129 attributes[number] = NULL;
130 fclose( description );
134 char *templateToObjectClass( template )
140 if ( template == NULL || *template == '\0' ) {
141 printFormatted( lineLength, TRUE, stdout,
142 "Unrecognised template" );
143 return "unrecognised";
145 for ( i = 0; i < numberOfTemplates; i++ )
146 if ( EQ( template, templateTranslationTable[i].key ) )
147 return templateTranslationTable[i].value;
148 printFormatted( lineLength, TRUE, stdout,
149 "Template (%s) not recognised, assuming that it is already an objectClass",
154 char *objectClassToTemplate( objectClass )
160 if ( objectClass == NULL || *objectClass == '\0' ) {
161 printFormatted( lineLength, TRUE, stdout,
162 "Unrecognised template" );
163 return "unrecognised";
165 for ( i = 0; i < numberOfTemplates; i++ )
166 if ( EQ( objectClass, templateTranslationTable[i].value ) )
167 return templateTranslationTable[i].key;