61fe9318afba03dae8685ea3e123562aa33ecb18
[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 HTTP_DESTROY_FUNCS=`grep HttpDestroyModule_ *.c |sed "s;.*:;;" |sort -u`
47
48
49 #SESS_NEW_FUNCS=`grep SessionNewModule_ *.c |sed "s;.*:;;" |sort -u`
50
51
52 #start the header file
53 cat <<EOF > $H_FILE
54 /* 
55  * $H_FILE
56  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
57  */
58
59
60 #ifndef MODULES_INIT_H
61 #define MODULES_INIT_H
62 extern size_t nSizErrmsg;
63
64
65 /* 
66  * server lifetime: 
67  */
68 void initialise_modules (void);
69 void start_modules (void);
70 void shutdown_modules (void);
71
72
73 /*
74  * Session lifetime:
75  */
76 void session_new_modules (wcsession *sess);
77 void session_attach_modules (wcsession *sess);
78 void session_detach_modules (wcsession *sess);
79 void session_destroy_modules (wcsession **sess);
80
81 void http_destroy_modules (ParsedHttpHdrs *httpreq);
82
83
84
85 /*
86  * forwards...
87  */
88
89 EOF
90
91
92 #start of the files which inturn removes any existing file
93 #
94
95 # start the Makefile included file for $SERV_MODULES
96 cat <<EOF  >$MOD_FILE
97 #
98 # Make_modules
99 # This file is to be included by Makefile to dynamically add modules to the build process
100 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
101 #
102
103 EOF
104
105 # start the Makefile included file for $SOURCES
106 cat <<EOF  >$SRC_FILE
107 #
108 # Make_sources
109 # This file is to be included by Makefile to dynamically add modules to the build process
110 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
111 #
112
113 EOF
114
115 # start the c file
116 cat <<EOF  >$C_FILE
117 /*
118  * $C_FILE
119  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
120  */
121
122
123
124 #include "sysdep.h"
125 #include <stdlib.h>
126 #include <time.h>
127 #include <ctype.h>
128 #include <stdio.h>
129 #include <sys/types.h>
130 #include <unistd.h>
131 #include <libcitadel.h>
132 #include "webcit.h"
133 #include "modules_init.h"
134 #include "webserver.h"
135
136 void LogPrintMessages(long err);
137 extern long DetailErrorFlags;
138
139 void start_modules (void)
140 {
141 EOF
142 #********************************************************************************
143 # server  ******** start ********  module logic.
144 #********************************************************************************
145 cat <<EOF >> $H_FILE
146
147 /* Server Start Hooks: */
148 EOF
149 for HOOK in $START_FUNCS; do
150 HOOKNAME=`echo $HOOK |sed "s;ServerStartModule_;;"`
151 # Add this entry point to the .c file
152 cat <<EOF >> $C_FILE
153 #ifdef DBG_PRINNT_HOOKS_AT_START
154         lprintf (CTDL_INFO, "Starting $HOOKNAME\n");
155 #endif
156         $HOOK();
157 EOF
158 # Add this entry point to the .h file
159 cat <<EOF >> $H_FILE
160 extern void $HOOK(void);
161 EOF
162 done
163
164
165 #********************************************************************************
166 # server module  ******** initialisation ********  logic.
167 #********************************************************************************
168 cat <<EOF >> $H_FILE
169
170 /* Server Init Hooks: */
171 EOF
172
173 cat <<EOF  >>$C_FILE
174 }
175
176
177 void initialise_modules (void)
178 {
179
180 EOF
181 for HOOK in $INIT_FUNCS; do
182     HOOKNAME=`echo $HOOK |sed "s;InitModule_;;"`
183 # Add this entry point to the .c file
184     cat <<EOF >> $C_FILE
185 #ifdef DBG_PRINNT_HOOKS_AT_START
186         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
187 #endif
188         $HOOK();
189 EOF
190 # Add this entry point to the .h file
191     cat <<EOF >> $H_FILE
192 extern void $HOOK(void);
193 EOF
194 done
195
196
197
198
199 #********************************************************************************
200 # server module    ***** shutdown *****  logic.
201 #********************************************************************************
202 cat <<EOF >> $H_FILE
203
204 /* Server shutdown Hooks: */
205 EOF
206 cat <<EOF  >>$C_FILE
207 }
208
209
210 void shutdown_modules (void)
211 {
212
213 EOF
214 for HOOK in $SHUTDOWN_FUNCS; do
215 HOOKNAME=`echo $HOOK |sed "s;ServerShutdownModule_;;"`
216 # Add this entry point to the .c file
217 cat <<EOF >> $C_FILE
218 #ifdef DBG_PRINNT_HOOKS_AT_START
219         lprintf (CTDL_INFO, "Shutting down $HOOKNAME\n");
220 #endif
221         $HOOK();
222 EOF
223 # Add this entry point to the .h file
224 cat <<EOF >> $H_FILE
225 extern void $HOOK(void);
226 EOF
227 done
228
229
230
231
232 #********************************************************************************
233 # NEW-session module logic.
234 #********************************************************************************
235 cat <<EOF >> $H_FILE
236
237 /* Session New Hooks: */
238 EOF
239 cat <<EOF  >>$C_FILE
240 }
241
242
243 void session_new_modules (wcsession *sess)
244 {
245
246 EOF
247 for HOOK in $SESS_NEW_FUNCS; do
248 HOOKNAME=`echo $HOOK |sed "s;SessionNewModule_;;"`
249 # Add this entry point to the .c file
250 cat <<EOF >> $C_FILE
251 #ifdef DBG_PRINNT_HOOKS_AT_START
252         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
253 #endif
254         $HOOK(sess);
255 EOF
256 # Add this entry point to the .h file
257 cat <<EOF >> $H_FILE
258 extern void $HOOK(wcsession *sess);
259 EOF
260 done
261
262
263
264 #********************************************************************************
265 # ATTACH-Session module logic.
266 #********************************************************************************
267 cat <<EOF >> $H_FILE
268
269 /* Session Attach Hooks: */
270 EOF
271 cat <<EOF  >>$C_FILE
272 }
273
274
275 void session_attach_modules (wcsession *sess)
276 {
277
278 EOF
279 for HOOK in $SESS_ATTACH_FUNCS; do
280 HOOKNAME=`echo $HOOK |sed "s;SessionAttachModule_;;"`
281 # Add this entry point to the .c file
282 cat <<EOF >> $C_FILE
283 #ifdef DBG_PRINNT_HOOKS_AT_START
284         lprintf (CTDL_INFO, "Attaching Session; $HOOKNAME\n");
285 #endif
286         $HOOK(sess);
287 EOF
288 # Add this entry point to the .h file
289 cat <<EOF >> $H_FILE
290 extern void $HOOK(wcsession *sess);
291 EOF
292 done
293
294
295
296 #********************************************************************************
297 # DETACH-Session module logic.
298 #********************************************************************************
299 cat <<EOF >> $H_FILE
300
301 /* Session detach Hooks: */
302 EOF
303 cat <<EOF  >>$C_FILE
304 }
305
306
307 void session_detach_modules (wcsession *sess)
308 {
309
310 EOF
311 for HOOK in $SESS_DETACH_FUNCS; do
312 HOOKNAME=`echo $HOOK |sed "s;SessionDetachModule_;;"`
313 # Add this entry point to the .c file
314 cat <<EOF >> $C_FILE
315 #ifdef DBG_PRINNT_HOOKS_AT_START
316         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
317 #endif
318         $HOOK(sess);
319 EOF
320 # Add this entry point to the .h file
321 cat <<EOF >> $H_FILE
322 extern void $HOOK(wcsession *sess);
323 EOF
324 done
325
326
327
328
329 #********************************************************************************
330 # DESTROY-Session module logic.
331 #********************************************************************************
332 cat <<EOF >> $H_FILE
333
334 /* Session destroy Hooks: */
335 EOF
336 cat <<EOF  >>$C_FILE
337 }
338
339
340 void session_destroy_modules (wcsession **sess)
341 {
342
343 EOF
344 for HOOK in $SESS_DESTROY_FUNCS; do
345 HOOKNAME=`echo $HOOK |sed "s;SessionDestroyModule_;;"`
346 # Add this entry point to the .c file
347 cat <<EOF >> $C_FILE
348 #ifdef DBG_PRINNT_HOOKS_AT_START
349         lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
350 #endif
351         $HOOK(*sess);
352 EOF
353 # Add this entry point to the .h file
354 cat <<EOF >> $H_FILE
355 extern void $HOOK(wcsession *sess);
356 EOF
357 done
358
359
360 cat <<EOF  >>$C_FILE
361         free((*sess));
362         (*sess) = NULL;
363 }
364
365
366 EOF
367
368
369
370
371
372 #********************************************************************************
373 # DESTROY-Httprequest module logic.
374 #********************************************************************************
375 cat <<EOF >> $C_FILE
376
377 void http_destroy_modules (ParsedHttpHdrs *httpreq)
378 {
379 EOF
380
381 for HOOK in $HTTP_DESTROY_FUNCS; do
382 HOOKNAME=`echo $HOOK |sed "s;HttpDestroyModule_;;"`
383 # Add this entry point to the .c file
384 cat <<EOF >> $C_FILE
385 #ifdef DBG_PRINNT_HOOKS_AT_START
386         lprintf (CTDL_INFO, "Destructing $HOOKNAME\n");
387 #endif
388         $HOOK(httpreq);
389 EOF
390 # Add this entry point to the .h file
391 cat <<EOF >> $H_FILE
392 extern void $HOOK(ParsedHttpHdrs *httpreq);
393 EOF
394 done
395
396 cat <<EOF  >>$C_FILE
397 }
398 EOF
399
400
401
402
403
404
405
406 cat <<EOF  >> $H_FILE
407
408 #endif /* MODULES_INIT_H */
409
410 EOF