1 /*
2  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * prof-int.h
10  */
11 
12 #ifndef __PROF_INT_H
13 
14 #include <time.h>
15 #include <com_err.h>
16 #include "prof_err.h"
17 #include <profile.h>
18 
19 #if defined(__STDC__) || defined(_MSDOS) || defined(_WIN32)
20 #define PROTOTYPE(x) x
21 #else
22 #define PROTOTYPE(x) ()
23 #endif
24 
25 #if defined(_MSDOS)
26 /* From k5-config.h */
27 #define SIZEOF_INT      2
28 #define SIZEOF_SHORT    2
29 #define SIZEOF_LONG     4
30 #endif
31 
32 #if defined(_WIN32)
33 #define SIZEOF_INT      4
34 #define SIZEOF_SHORT    2
35 #define SIZEOF_LONG     4
36 #endif
37 
38 #if defined(macintosh)
39 #define NO_SYS_TYPES_H
40 #define NO_SYS_STAT_H
41 #endif
42 
43 typedef long prf_magic_t;
44 
45 /*
46  * This is the structure which stores the profile information for a
47  * particular configuration file.
48  */
49 struct _prf_file_t {
50 	prf_magic_t	magic;
51 	char		*comment;
52 	profile_filespec_t filespec;
53 	struct profile_node *root;
54 	time_t		timestamp;
55 	int		flags;
56 	int		upd_serial;
57 	struct _prf_file_t *next;
58 };
59 
60 typedef struct _prf_file_t *prf_file_t;
61 
62 /*
63  * The profile flags
64  */
65 #define PROFILE_FILE_RW		0x0001
66 #define PROFILE_FILE_DIRTY	0x0002
67 
68 /*
69  * This structure defines the high-level, user visible profile_t
70  * object, which is used as a handle by users who need to query some
71  * configuration file(s)
72  */
73 struct _profile_t {
74 	prf_magic_t	magic;
75 	prf_file_t	first_file;
76 };
77 
78 typedef struct _profile_options {
79 	char *name;
80 	int  *value;
81 	int  found;
82 } profile_options_boolean;
83 
84 typedef struct _profile_times {
85 	char *name;
86 	char **value;
87 	int  found;
88 } profile_option_strings;
89 
90 /*
91  * Used by the profile iterator in prof_get.c
92  */
93 #define PROFILE_ITER_LIST_SECTION	0x0001
94 #define PROFILE_ITER_SECTIONS_ONLY	0x0002
95 #define PROFILE_ITER_RELATIONS_ONLY	0x0004
96 
97 #define PROFILE_ITER_FINAL_SEEN		0x0100
98 
99 /*
100  * Check if a filespec is last in a list (NULL on UNIX, invalid FSSpec on MacOS
101  */
102 
103 #ifdef PROFILE_USES_PATHS
104 #define	PROFILE_LAST_FILESPEC(x) (((x) == NULL) || ((x)[0] == '\0'))
105 #else
106 #define PROFILE_LAST_FILESPEC(x) (((x).vRefNum == 0) && ((x).parID == 0) && ((x).name[0] == '\0'))
107 #endif
108 
109 /* profile_parse.c */
110 
111 errcode_t profile_parse_file
112 	PROTOTYPE((FILE *f, struct profile_node **root));
113 
114 errcode_t profile_write_tree_file
115 	PROTOTYPE((struct profile_node *root, FILE *dstfile));
116 
117 
118 /* prof_tree.c */
119 
120 void profile_free_node
121 	PROTOTYPE((struct profile_node *relation));
122 
123 errcode_t profile_create_node
124 	PROTOTYPE((const char *name, const char *value,
125 		   struct profile_node **ret_node));
126 
127 errcode_t profile_verify_node
128 	PROTOTYPE((struct profile_node *node));
129 
130 errcode_t profile_add_node
131 	PROTOTYPE ((struct profile_node *section,
132 		    const char *name, const char *value,
133 		    struct profile_node **ret_node));
134 
135 errcode_t profile_make_node_final
136 	PROTOTYPE((struct profile_node *node));
137 
138 int profile_is_node_final
139 	PROTOTYPE((struct profile_node *node));
140 
141 const char *profile_get_node_name
142 	PROTOTYPE((struct profile_node *node));
143 
144 const char *profile_get_node_value
145 	PROTOTYPE((struct profile_node *node));
146 
147 errcode_t profile_find_node
148 	PROTOTYPE ((struct profile_node *section,
149 		    const char *name, const char *value,
150 		    int section_flag, void **state,
151 		    struct profile_node **node));
152 
153 errcode_t profile_find_node_relation
154 	PROTOTYPE ((struct profile_node *section,
155 		    const char *name, void **state,
156 		    char **ret_name, char **value));
157 
158 errcode_t profile_find_node_subsection
159 	PROTOTYPE ((struct profile_node *section,
160 		    const char *name, void **state,
161 		    char **ret_name, struct profile_node **subsection));
162 
163 errcode_t profile_get_node_parent
164 	PROTOTYPE ((struct profile_node *section,
165 		   struct profile_node **parent));
166 
167 errcode_t profile_delete_node_relation
168 	PROTOTYPE ((struct profile_node *section, const char *name));
169 
170 errcode_t profile_find_node_name
171 	PROTOTYPE ((struct profile_node *section, void **state,
172 		    char **ret_name));
173 
174 errcode_t profile_node_iterator_create
175 	PROTOTYPE((profile_t profile, const char **names,
176 		   int flags, void **ret_iter));
177 
178 void profile_node_iterator_free
179 	PROTOTYPE((void	**iter_p));
180 
181 errcode_t profile_node_iterator
182 	PROTOTYPE((void	**iter_p, struct profile_node **ret_node,
183 		   char **ret_name, char **ret_value));
184 
185 errcode_t profile_remove_node
186 	PROTOTYPE((struct profile_node *node));
187 
188 errcode_t profile_set_relation_value
189 	PROTOTYPE((struct profile_node *node, const char *new_value));
190 
191 errcode_t profile_rename_node
192 	PROTOTYPE((struct profile_node *node, const char *new_name));
193 
194 /* prof_file.c */
195 
196 errcode_t profile_open_file
197 	PROTOTYPE ((const_profile_filespec_t file, prf_file_t *ret_prof));
198 
199 errcode_t profile_update_file
200 	PROTOTYPE ((prf_file_t profile));
201 
202 errcode_t profile_flush_file
203 	PROTOTYPE ((prf_file_t profile));
204 
205 void profile_free_file
206 	PROTOTYPE ((prf_file_t profile));
207 
208 errcode_t profile_close_file
209 	PROTOTYPE ((prf_file_t profile));
210 
211 /* prof_init.c -- included from profile.h */
212 
213 /* prof_get.c */
214 
215 errcode_t profile_get_value
216 	PROTOTYPE ((profile_t profile, const char **names,
217 		    const char	**ret_value));
218 /* Others included from profile.h */
219 
220 /* prof_set.c -- included from profile.h */
221 
222 #define __PROF_INT_H
223 #endif
224