* add more module handlers:
[citadel.git] / webcit / mk_module_init.sh
1 #!/bin/sh
2 #
3 # Script to generate $C_FILE
4 #
5
6 ECHO=/usr/bin/printf
7
8 #MINUS_e=X`$ECHO -n -e`
9 #if [ $MINUS_e != "X" ] ; then
10 #       MINUS_e=""
11 #else
12 #       MINUS_e="-e"
13 #fi
14
15 #MINUS_E=X`$ECHO -n -E`
16 #if [ $MINUS_E != "X" ] ; then
17 #       MINUS_E=""
18 #else
19 #       MINUS_E="-E"
20 #fi
21
22
23 CUR_DIR=`pwd`
24 C_FILE="$CUR_DIR/modules_init.c"
25 H_FILE="$CUR_DIR/modules_init.h"
26 MOD_FILE="$CUR_DIR/Make_modules"
27 SRC_FILE="$CUR_DIR/Make_sources"
28 U_FILE="$CUR_DIR/modules_upgrade.c"
29
30 /usr/bin/printf "Scanning extension modules for entry points.\n"
31
32 rm -f $C_FILE $H_FILE
33
34 # server lifetime:
35 START_FUNCS=`grep ServerStartModule_ *.c |sed "s;.*:;;" |sort -u`
36 INIT_FUNCS=`grep InitModule_ *.c |sed "s;.*:;;" |sort -u`
37 FINALIZE_FUNCS=`grep FinalizeModule_ *.c |sed "s;.*:;;" |sort -u`
38 SHUTDOWN_FUNCS=`grep ServerShutdownModule_ *.c |sed "s;.*:;;" |sort -u`
39
40 # session hooks:
41 SESS_NEW_FUNCS=`grep SessionNewModule_ *.c |sed "s;.*:;;" |sort -u`
42 SESS_ATTACH_FUNCS=`grep SessionAttachModule_ *.c |sed "s;.*:;;" |sort -u`
43 SESS_DETACH_FUNCS=`grep SessionDetachModule_ *.c |sed "s;.*:;;" |sort -u`
44 SESS_DESTROY_FUNCS=`grep SessionDestroyModule_ *.c |sed "s;.*:;;" |sort -u`
45
46
47 #SESS_NEW_FUNCS=`grep SessionNewModule_ *.c |sed "s;.*:;;" |sort -u`
48
49
50 #start the header file
51 cat <<EOF > $H_FILE
52 /* 
53  * $H_FILE
54  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
55  */
56
57
58 #ifndef MODULES_INIT_H
59 #define MODULES_INIT_H
60 extern size_t nSizErrmsg;
61
62
63 /* 
64  * server lifetime: 
65  */
66 void initialise_modules (void);
67 void start_modules (void);
68 void shutdown_modules (void);
69
70
71 /*
72  * Session lifetime:
73  */
74 void session_new_modules (wcsession *sess);
75 void session_attach_modules (wcsession *sess);
76 void session_detach_modules (wcsession *sess);
77 void session_destroy_modules (wcsession *sess);
78
79
80
81 /*
82  * forwards...
83  */
84
85 EOF
86
87
88 #start of the files which inturn removes any existing file
89 #
90
91 # start the Makefile included file for $SERV_MODULES
92 cat <<EOF  >$MOD_FILE
93 #
94 # Make_modules
95 # This file is to be included by Makefile to dynamically add modules to the build process
96 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
97 #
98
99 EOF
100
101 # start the Makefile included file for $SOURCES
102 cat <<EOF  >$SRC_FILE
103 #
104 # Make_sources
105 # This file is to be included by Makefile to dynamically add modules to the build process
106 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
107 #
108
109 EOF
110
111 # start the c file
112 cat <<EOF  >$C_FILE
113 /*
114  * $C_FILE
115  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
116  */
117
118
119
120 #include "sysdep.h"
121 #include <stdlib.h>
122 #include <time.h>
123 #include <ctype.h>
124 #include <stdio.h>
125 #include <sys/types.h>
126 #include <unistd.h>
127 #include <libcitadel.h>
128 #include "webcit.h"
129 #include "modules_init.h"
130 #include "webserver.h"
131
132 void LogPrintMessages(long err);
133 extern long DetailErrorFlags;
134
135 void start_modules (void)
136 {
137 EOF
138 #********************************************************************************
139 # server  ******** start ********  module logic.
140 #********************************************************************************
141 cat <<EOF >> $H_FILE
142
143 /* Server Start Hooks: */
144 EOF
145 for HOOK in $START_FUNCS; do
146 HOOKNAME=`echo $HOOK |sed "s;ServerStartModule_;;"`
147 # Add this entry point to the .c file
148 cat <<EOF >> $C_FILE
149 #ifdef DBG_PRINNT_HOOKS_AT_START
150         lprintf (CTDL_INFO, "Starting $HOOKNAME\n");
151 #endif
152         $HOOK();
153 EOF
154 # Add this entry point to the .h file
155 cat <<EOF >> $H_FILE
156 extern void $HOOK(void);
157 EOF
158 done
159
160
161 #********************************************************************************
162 # server module  ******** initialisation ********  logic.
163 #********************************************************************************
164 cat <<EOF >> $H_FILE
165
166 /* Server Init Hooks: */
167 EOF
168
169 cat <<EOF  >>$C_FILE
170 }
171
172
173 void initialise_modules (void)
174 {
175
176 EOF
177 for HOOK in $INIT_FUNCS; do
178     HOOKNAME=`echo $HOOK |sed "s;InitModule_;;"`
179 # Add this entry point to the .c file
180     cat <<EOF >> $C_FILE
181 #ifdef DBG_PRINNT_HOOKS_AT_START
182         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
183 #endif
184         $HOOK();
185 EOF
186 # Add this entry point to the .h file
187     cat <<EOF >> $H_FILE
188 extern void $HOOK(void);
189 EOF
190 done
191
192
193
194
195 #********************************************************************************
196 # server module    ***** shutdown *****  logic.
197 #********************************************************************************
198 cat <<EOF >> $H_FILE
199
200 /* Server shutdown Hooks: */
201 EOF
202 cat <<EOF  >>$C_FILE
203 }
204
205
206 void shutdown_modules (void)
207 {
208
209 EOF
210 for HOOK in $SHUTDOWN_FUNCS; do
211 HOOKNAME=`echo $HOOK |sed "s;ServerShutdownModule_;;"`
212 # Add this entry point to the .c file
213 cat <<EOF >> $C_FILE
214 #ifdef DBG_PRINNT_HOOKS_AT_START
215         lprintf (CTDL_INFO, "Shutting down $HOOKNAME\n");
216 #endif
217         $HOOK();
218 EOF
219 # Add this entry point to the .h file
220 cat <<EOF >> $H_FILE
221 extern void $HOOK(void);
222 EOF
223 done
224
225
226
227
228 #********************************************************************************
229 # NEW-session module logic.
230 #********************************************************************************
231 cat <<EOF >> $H_FILE
232
233 /* Session New Hooks: */
234 EOF
235 cat <<EOF  >>$C_FILE
236 }
237
238
239 void session_new_modules (wcsession *sess)
240 {
241
242 EOF
243 for HOOK in $SESS_NEW_FUNCS; do
244 HOOKNAME=`echo $HOOK |sed "s;SessionNewModule_;;"`
245 # Add this entry point to the .c file
246 cat <<EOF >> $C_FILE
247 #ifdef DBG_PRINNT_HOOKS_AT_START
248         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
249 #endif
250         $HOOK(sess);
251 EOF
252 # Add this entry point to the .h file
253 cat <<EOF >> $H_FILE
254 extern void $HOOK(wcsession *sess);
255 EOF
256 done
257
258
259
260 #********************************************************************************
261 # ATTACH-Session module logic.
262 #********************************************************************************
263 cat <<EOF >> $H_FILE
264
265 /* Session Attach Hooks: */
266 EOF
267 cat <<EOF  >>$C_FILE
268 }
269
270
271 void session_attach_modules (wcsession *sess)
272 {
273
274 EOF
275 for HOOK in $SESS_ATTACH_FUNCS; do
276 HOOKNAME=`echo $HOOK |sed "s;SessionAttachModule_;;"`
277 # Add this entry point to the .c file
278 cat <<EOF >> $C_FILE
279 #ifdef DBG_PRINNT_HOOKS_AT_START
280         lprintf (CTDL_INFO, "Attaching Session; $HOOKNAME\n");
281 #endif
282         $HOOK(sess);
283 EOF
284 # Add this entry point to the .h file
285 cat <<EOF >> $H_FILE
286 extern void $HOOK(wcsession *sess);
287 EOF
288 done
289
290
291
292 #********************************************************************************
293 # DETACH-Session module logic.
294 #********************************************************************************
295 cat <<EOF >> $H_FILE
296
297 /* Session detach Hooks: */
298 EOF
299 cat <<EOF  >>$C_FILE
300 }
301
302
303 void session_detach_modules (wcsession *sess)
304 {
305
306 EOF
307 for HOOK in $SESS_DETACH_FUNCS; do
308 HOOKNAME=`echo $HOOK |sed "s;SessionDetachModule_;;"`
309 # Add this entry point to the .c file
310 cat <<EOF >> $C_FILE
311 #ifdef DBG_PRINNT_HOOKS_AT_START
312         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
313 #endif
314         $HOOK(sess);
315 EOF
316 # Add this entry point to the .h file
317 cat <<EOF >> $H_FILE
318 extern void $HOOK(wcsession *sess);
319 EOF
320 done
321
322
323
324
325 #********************************************************************************
326 # DESTROY-Session module logic.
327 #********************************************************************************
328 cat <<EOF >> $H_FILE
329
330 /* Session destroy Hooks: */
331 EOF
332 cat <<EOF  >>$C_FILE
333 }
334
335
336 void session_destroy_modules (wcsession *sess)
337 {
338
339 EOF
340 for HOOK in $SESS_DESTROY_FUNCS; do
341 HOOKNAME=`echo $HOOK |sed "s;SessionDestroyModule_;;"`
342 # Add this entry point to the .c file
343 cat <<EOF >> $C_FILE
344 #ifdef DBG_PRINNT_HOOKS_AT_START
345         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
346 #endif
347         $HOOK(sess);
348 EOF
349 # Add this entry point to the .h file
350 cat <<EOF >> $H_FILE
351 extern void $HOOK(wcsession *sess);
352 EOF
353 done
354
355
356
357
358
359
360 cat <<EOF  >>$C_FILE
361 }
362
363 EOF
364
365
366 cat <<EOF  >> $H_FILE
367
368 #endif /* MODULES_INIT_H */
369
370 EOF