* add more module handlers:
[citadel.git] / webcit / mk_module_init.sh
index 4f58db1e395a29983611314ef6df8d41520fd233..e3c91a1a311c5212069c10c851e833a2c6825d7c 100755 (executable)
@@ -29,6 +29,61 @@ U_FILE="$CUR_DIR/modules_upgrade.c"
 
 /usr/bin/printf "Scanning extension modules for entry points.\n"
 
+rm -f $C_FILE $H_FILE
+
+# server lifetime:
+START_FUNCS=`grep ServerStartModule_ *.c |sed "s;.*:;;" |sort -u`
+INIT_FUNCS=`grep InitModule_ *.c |sed "s;.*:;;" |sort -u`
+FINALIZE_FUNCS=`grep FinalizeModule_ *.c |sed "s;.*:;;" |sort -u`
+SHUTDOWN_FUNCS=`grep ServerShutdownModule_ *.c |sed "s;.*:;;" |sort -u`
+
+# session hooks:
+SESS_NEW_FUNCS=`grep SessionNewModule_ *.c |sed "s;.*:;;" |sort -u`
+SESS_ATTACH_FUNCS=`grep SessionAttachModule_ *.c |sed "s;.*:;;" |sort -u`
+SESS_DETACH_FUNCS=`grep SessionDetachModule_ *.c |sed "s;.*:;;" |sort -u`
+SESS_DESTROY_FUNCS=`grep SessionDestroyModule_ *.c |sed "s;.*:;;" |sort -u`
+
+
+#SESS_NEW_FUNCS=`grep SessionNewModule_ *.c |sed "s;.*:;;" |sort -u`
+
+
+#start the header file
+cat <<EOF > $H_FILE
+/* 
+ * $H_FILE
+ * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
+ */
+
+
+#ifndef MODULES_INIT_H
+#define MODULES_INIT_H
+extern size_t nSizErrmsg;
+
+
+/* 
+ * server lifetime: 
+ */
+void initialise_modules (void);
+void start_modules (void);
+void shutdown_modules (void);
+
+
+/*
+ * Session lifetime:
+ */
+void session_new_modules (wcsession *sess);
+void session_attach_modules (wcsession *sess);
+void session_detach_modules (wcsession *sess);
+void session_destroy_modules (wcsession *sess);
+
+
+
+/*
+ * forwards...
+ */
+
+EOF
+
 
 #start of the files which inturn removes any existing file
 #
@@ -77,49 +132,239 @@ cat <<EOF  >$C_FILE
 void LogPrintMessages(long err);
 extern long DetailErrorFlags;
 
+void start_modules (void)
+{
+EOF
+#********************************************************************************
+# server  ******** start ********  module logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Server Start Hooks: */
+EOF
+for HOOK in $START_FUNCS; do
+HOOKNAME=`echo $HOOK |sed "s;ServerStartModule_;;"`
+# Add this entry point to the .c file
+cat <<EOF >> $C_FILE
+#ifdef DBG_PRINNT_HOOKS_AT_START
+       lprintf (CTDL_INFO, "Starting $HOOKNAME\n");
+#endif
+       $HOOK();
+EOF
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+extern void $HOOK(void);
+EOF
+done
+
+
+#********************************************************************************
+# server module  ******** initialisation ********  logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Server Init Hooks: */
+EOF
+
+cat <<EOF  >>$C_FILE
+}
 
 
 void initialise_modules (void)
 {
 
 EOF
+for HOOK in $INIT_FUNCS; do
+    HOOKNAME=`echo $HOOK |sed "s;InitModule_;;"`
+# Add this entry point to the .c file
+    cat <<EOF >> $C_FILE
+#ifdef DBG_PRINNT_HOOKS_AT_START
+       lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
+#endif
+       $HOOK();
+EOF
+# Add this entry point to the .h file
+    cat <<EOF >> $H_FILE
+extern void $HOOK(void);
+EOF
+done
 
 
-#start the header file
-cat <<EOF > $H_FILE
-/* 
- * $H_FILE
- * Auto generated by mk_modules_init.sh DO NOT EDIT THIS FILE
- */
 
 
-#ifndef MODULES_INIT_H
-#define MODULES_INIT_H
-extern size_t nSizErrmsg;
-void initialise_modules (void);
+#********************************************************************************
+# server module    ***** shutdown *****  logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Server shutdown Hooks: */
+EOF
+cat <<EOF  >>$C_FILE
+}
+
+
+void shutdown_modules (void)
+{
+
+EOF
+for HOOK in $SHUTDOWN_FUNCS; do
+HOOKNAME=`echo $HOOK |sed "s;ServerShutdownModule_;;"`
+# Add this entry point to the .c file
+cat <<EOF >> $C_FILE
+#ifdef DBG_PRINNT_HOOKS_AT_START
+       lprintf (CTDL_INFO, "Shutting down $HOOKNAME\n");
+#endif
+       $HOOK();
+EOF
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+extern void $HOOK(void);
+EOF
+done
 
 
+
+
+#********************************************************************************
+# NEW-session module logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Session New Hooks: */
 EOF
+cat <<EOF  >>$C_FILE
+}
 
 
-INIT_FUNCS=`grep InitModule_ *.c |sed "s;.*:;;"`
+void session_new_modules (wcsession *sess)
+{
 
-for HOOK in $INIT_FUNCS; do
-HOOKNAME=`echo $HOOK |sed "s;InitModule_;;"`
+EOF
+for HOOK in $SESS_NEW_FUNCS; do
+HOOKNAME=`echo $HOOK |sed "s;SessionNewModule_;;"`
 # Add this entry point to the .c file
 cat <<EOF >> $C_FILE
 #ifdef DBG_PRINNT_HOOKS_AT_START
        lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
 #endif
-       $HOOK();
+       $HOOK(sess);
+EOF
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+extern void $HOOK(wcsession *sess);
+EOF
+done
+
+
+
+#********************************************************************************
+# ATTACH-Session module logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Session Attach Hooks: */
+EOF
+cat <<EOF  >>$C_FILE
+}
+
+
+void session_attach_modules (wcsession *sess)
+{
+
+EOF
+for HOOK in $SESS_ATTACH_FUNCS; do
+HOOKNAME=`echo $HOOK |sed "s;SessionAttachModule_;;"`
+# Add this entry point to the .c file
+cat <<EOF >> $C_FILE
+#ifdef DBG_PRINNT_HOOKS_AT_START
+       lprintf (CTDL_INFO, "Attaching Session; $HOOKNAME\n");
+#endif
+       $HOOK(sess);
 EOF
 # Add this entry point to the .h file
 cat <<EOF >> $H_FILE
-       extern void $HOOK(void);
+extern void $HOOK(wcsession *sess);
 EOF
 done
 
 
-/usr/bin/printf "}\n" >> $C_FILE
 
-/usr/bin/printf "\n#endif /* MODULES_INIT_H */\n" >> $H_FILE
+#********************************************************************************
+# DETACH-Session module logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Session detach Hooks: */
+EOF
+cat <<EOF  >>$C_FILE
+}
+
+
+void session_detach_modules (wcsession *sess)
+{
+
+EOF
+for HOOK in $SESS_DETACH_FUNCS; do
+HOOKNAME=`echo $HOOK |sed "s;SessionDetachModule_;;"`
+# Add this entry point to the .c file
+cat <<EOF >> $C_FILE
+#ifdef DBG_PRINNT_HOOKS_AT_START
+       lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
+#endif
+       $HOOK(sess);
+EOF
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+extern void $HOOK(wcsession *sess);
+EOF
+done
+
+
+
+
+#********************************************************************************
+# DESTROY-Session module logic.
+#********************************************************************************
+cat <<EOF >> $H_FILE
+
+/* Session destroy Hooks: */
+EOF
+cat <<EOF  >>$C_FILE
+}
+
+
+void session_destroy_modules (wcsession *sess)
+{
+
+EOF
+for HOOK in $SESS_DESTROY_FUNCS; do
+HOOKNAME=`echo $HOOK |sed "s;SessionDestroyModule_;;"`
+# Add this entry point to the .c file
+cat <<EOF >> $C_FILE
+#ifdef DBG_PRINNT_HOOKS_AT_START
+       lprintf (CTDL_INFO, "Initializing $HOOKNAME\n");
+#endif
+       $HOOK(sess);
+EOF
+# Add this entry point to the .h file
+cat <<EOF >> $H_FILE
+extern void $HOOK(wcsession *sess);
+EOF
+done
+
+
+
+
+
+
+cat <<EOF  >>$C_FILE
+}
+
+EOF
+
+
+cat <<EOF  >> $H_FILE
+
+#endif /* MODULES_INIT_H */
+
+EOF