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