Removed the logging facility from citserver, use syslog instead
[citadel.git] / citadel / scripts / 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
33 #start of the files which inturn removes any existing file
34 #
35
36 # start the Makefile included file for $SERV_MODULES
37 cat <<EOF  >$MOD_FILE
38 #
39 # Make_modules
40 # This file is to be included by Makefile to dynamically add modules to the build process
41 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
42 #
43
44 EOF
45
46 # start the Makefile included file for $SOURCES
47 cat <<EOF  >$SRC_FILE
48 #
49 # Make_sources
50 # This file is to be included by Makefile to dynamically add modules to the build process
51 # THIS FILE WAS AUTO GENERATED BY mk_modules_init.sh DO NOT EDIT THIS FILE
52 #
53
54 EOF
55
56 # start the upgrade file
57 cat <<EOF  >$U_FILE
58 /*
59  * $U_FILE
60  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
61  */
62
63
64
65 #include "sysdep.h"
66 #include <stdlib.h>
67 #include <unistd.h>
68 #include <time.h>
69 #include <ctype.h>
70 #include <stdio.h>
71 #include <sys/types.h>
72 #include <unistd.h>
73 #include <libcitadel.h>
74 #include "citadel.h"
75 #include "modules_init.h"
76 #include "sysdep_decls.h"
77
78
79
80
81 void upgrade_modules (void)
82 {
83
84     syslog(LOG_INFO, "Upgrade modules.\n");
85
86 EOF
87
88 # start the c file
89 cat <<EOF  >$C_FILE
90 /*
91  * $C_FILE
92  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
93  */
94
95
96
97 #include "sysdep.h"
98 #include <stdlib.h>
99 #include <time.h>
100 #include <ctype.h>
101 #include <stdio.h>
102 #include <sys/types.h>
103 #include <unistd.h>
104 #include <libcitadel.h>
105 #include "citadel.h"
106 #include "modules_init.h"
107 #include "sysdep_decls.h"
108
109
110 void LogPrintMessages(long err);
111 extern long DetailErrorFlags;
112
113
114
115 void initialise_modules (int threading)
116 {
117     long filter;
118     nSizErrmsg = 0;
119
120     if (threading)
121         syslog(LOG_INFO, "Initialize modules, CtdlThreads enabled.\n");
122     else
123         syslog(LOG_INFO, "Initialize modules, CtdlThreads not yet enabled.\n");
124 /* static server initialization: */
125         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(citserver));
126         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(control));
127         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(euidindex));
128         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(file_ops));
129         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(msgbase));
130         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(room_ops));
131         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL(user_ops));
132 /* dynamic modules: */
133
134 EOF
135
136
137 #start the header file
138 cat <<EOF > $H_FILE
139 /* 
140  * $H_FILE
141  * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
142  */
143
144
145 #ifndef MODULES_INIT_H
146 #define MODULES_INIT_H
147 #include "ctdl_module.h"
148 extern size_t nSizErrmsg;
149 void initialise_modules (int threading);
150 void upgrade_modules(void);
151
152         CTDL_MODULE_INIT(citserver);
153         CTDL_MODULE_INIT(control);
154         CTDL_MODULE_INIT(euidindex);
155         CTDL_MODULE_INIT(file_ops);
156         CTDL_MODULE_INIT(msgbase);
157         CTDL_MODULE_INIT(room_ops);
158         CTDL_MODULE_INIT(user_ops);
159 EOF
160
161 for i in serv_*.c
162 do
163         RES=X`grep CTDL_MODULE_INIT $i | cut -f2 -d\( | cut -f1 -d\)`
164         if [ $RES != "X" ] ; then
165                 RES_OUT=`echo $RES | cut -b2-`
166                 /usr/bin/printf "Found entry point in file $i\n"
167 cat <<EOF  >> $C_FILE
168         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL($RES_OUT));
169
170 EOF
171 cat <<EOF >>$H_FILE
172 CTDL_MODULE_INIT($RES_OUT);
173 EOF
174         fi
175         RES=X`grep CTDL_MODULE_UPGRADE $i | cut -f2 -d\( | cut -f1 -d\)`
176         if [ $RES != "X" ] ; then
177                 RES_OUT=`echo $RES | cut -b2-`
178                 /usr/bin/printf "Found upgrade point in file $i\n"
179 cat <<EOF  >> $U_FILE
180         syslog(LOG_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
181
182 EOF
183 cat <<EOF >>$H_FILE
184 CTDL_MODULE_UPGRADE($RES_OUT);
185 EOF
186         fi
187 done
188
189
190 if [ -d "modules" ] ; then
191         cd modules
192         for j in *
193         do
194                 if [ -d $j ] ; then
195                         cd $j
196                         for k in *.c
197                         do
198                                 if [ -f "$k" ] ; then
199 # Add this .c file to the Makefile included list of SOURCES
200 cat <<EOF >> $SRC_FILE
201 SOURCES += modules/$j/$k
202 EOF
203
204 # Generate a .o file name
205 O_FILE=`basename $k .c`
206 O_FILE="$O_FILE.o"
207 # Add this .o file to the Makefile included list of SERV_MODULES
208 cat <<EOF >> $MOD_FILE
209 SERV_MODULES += modules/$j/$O_FILE
210 EOF
211         
212                                         RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
213                                         if [ $RES != "X" ] ; then
214                                                 RES_OUT=`echo $RES | cut -b2-`
215                                                 /usr/bin/printf "Found entry point in file modules/$j/$k\n"
216 # Add this entry point to the .c file
217 cat <<EOF >> $C_FILE
218         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL($RES_OUT));
219 EOF
220 # Add this entry point to the .h file
221 cat <<EOF >> $H_FILE
222         CTDL_MODULE_INIT($RES_OUT);
223 EOF
224                                         fi
225                                         RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)`
226                                         if [ $RES != "X" ] ; then
227                                                 RES_OUT=`echo $RES | cut -b2-`
228                                                 /usr/bin/printf "Found upgrade point in file modules/$j/$k\n"
229 # Add this entry point to the .c file
230 cat <<EOF >> $U_FILE
231         syslog(LOG_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
232 EOF
233 # Add this entry point to the .h file
234 cat <<EOF >> $H_FILE
235         CTDL_MODULE_UPGRADE($RES_OUT);
236 EOF
237                                         fi
238                                 fi
239                         done
240                         cd ..
241                 fi
242         done
243 fi
244
245 cd $CUR_DIR
246
247 if [ -d "user_modules" ] ; then
248         cd user_modules
249         for j in *
250         do
251                 if [ -d $j ] ; then
252                         cd $j
253                         for k in *.c
254                         do
255                                 if [ -f "$k" ] ; then
256 # Add this .c file to the Makefile included list of SOURCES
257 cat <<EOF >> $SRC_FILE
258 SOURCES += user_modules/$j/$k
259 EOF
260
261 # Generate a .o file name
262 O_FILE=`basename $k .c`
263 O_FILE="$O_FILE.o"
264 # Add this .o file to the Makefile included list of SERV_MODULES
265 cat <<EOF >> $MOD_FILE
266 SERV_MODULES += user_modules/$j/$O_FILE
267 EOF
268         
269                                         RES=X`grep CTDL_MODULE_INIT $k | cut -f2 -d\( | cut -f1 -d\)`
270                                         if [ $RES != "X" ] ; then
271                                                 RES_OUT=`echo $RES | cut -b2-`
272                                                 /usr/bin/printf "Found entry point in file user_modules/$j/$k\n"
273 cat <<EOF >> $C_FILE
274         syslog(LOG_INFO, "Loaded module: %s\n", CTDL_INIT_CALL($RES_OUT));
275 EOF
276 cat <<EOF >> $H_FILE
277 CTDL_MODULE_INIT($RES_OUT);
278 EOF
279                                         fi
280                                         RES=X`grep CTDL_MODULE_UPGRADE $k | cut -f2 -d\( | cut -f1 -d\)`
281                                         if [ $RES != "X" ] ; then
282                                                 RES_OUT=`echo $RES | cut -b2-`
283                                                 /usr/bin/printf "Found upgrade point in file user_modules/$j/$k\n"
284 cat <<EOF >> $U_FILE
285         syslog(LOG_INFO, "%s\n", CTDL_UPGRADE_CALL($RES_OUT));
286 EOF
287 cat <<EOF >> $H_FILE
288 CTDL_MODULE_UPGRADE($RES_OUT);
289 EOF
290                                         fi
291                                 fi
292                         done
293                         cd ..
294                 fi
295         done
296 fi
297
298 cd $CUR_DIR
299
300 /usr/bin/printf "\n\n" >> $C_FILE
301 /usr/bin/printf "\tfor (filter = 1; filter != 0; filter = filter << 1)\n" >> $C_FILE
302 /usr/bin/printf "\t\tif ((filter & DetailErrorFlags) != 0)\n" >> $C_FILE
303 /usr/bin/printf "\t\t\tLogPrintMessages(filter);\n" >> $C_FILE
304 /usr/bin/printf "}\n" >> $C_FILE
305
306 #close the upgrade file
307 /usr/bin/printf "}\n" >> $U_FILE
308
309 /usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE