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