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