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