From 079f33bf491a2718e54829da13804d266f935204 Mon Sep 17 00:00:00 2001 From: Dave West Date: Fri, 3 Aug 2007 22:12:16 +0000 Subject: [PATCH] Continue phase 2 of modules stuff. Moved some more stuff into the relevant modules/* directories. modified Makefile.in to build them. Created a new Hook to register a maintenance thread. This allowed serv_fulltext.c to become independant of one file. New thread hook should be easy enough to extend to other threads and get stats of threads. Still more to be done on this to seperate the rest of the modules so they don't rely on specifics of each other. Moved db checkpoint thread to new hook mechanism. Remind me to document that mechanism 8-) --- citadel/Makefile.in | 36 +++++++++++-------- citadel/citserver.c | 15 ++++---- citadel/database_sleepycat.c | 2 ++ citadel/include/ctdl_module.h | 7 ++++ citadel/journaling.c | 2 +- citadel/{ => modules/crypto}/serv_crypto.h | 0 citadel/modules/expire/serv_expire.c | 2 +- citadel/modules/fulltext/serv_fulltext.c | 1 + citadel/{ => modules/imap}/imap_acl.c | 0 citadel/{ => modules/imap}/imap_acl.h | 2 +- citadel/{ => modules/imap}/imap_fetch.c | 0 citadel/{ => modules/imap}/imap_fetch.h | 0 citadel/{ => modules/imap}/imap_list.c | 3 -- citadel/{ => modules/imap}/imap_list.h | 0 citadel/{ => modules/imap}/imap_metadata.c | 0 citadel/{ => modules/imap}/imap_metadata.h | 0 citadel/{ => modules/imap}/imap_misc.c | 0 citadel/{ => modules/imap}/imap_misc.h | 0 citadel/{ => modules/imap}/imap_search.c | 2 +- citadel/{ => modules/imap}/imap_search.h | 0 citadel/{ => modules/imap}/imap_store.c | 0 citadel/{ => modules/imap}/imap_store.h | 0 citadel/{ => modules/imap}/imap_tools.c | 0 citadel/{ => modules/imap}/serv_imap.c | 12 ++----- citadel/{ => modules/imap}/serv_imap.h | 0 citadel/{ => modules/ldap}/serv_ldap.h | 0 citadel/modules/listsub/serv_listsub.c | 1 - .../modules/managesieve/serv_managesieve.c | 14 ++------ citadel/modules/netfilter/serv_netfilter.c | 2 +- citadel/modules/pop3/serv_pop3.c | 11 ++---- citadel/modules/smtp/serv_smtp.c | 12 ++----- citadel/modules/vcard/serv_vcard.c | 1 - citadel/msgbase.c | 3 +- citadel/serv_extensions.c | 29 ++++++++++++++- citadel/server.h | 9 +++++ citadel/server_main.c | 2 +- citadel/sysdep.c | 28 ++++++++------- citadel/sysdep_decls.h | 2 -- 38 files changed, 107 insertions(+), 91 deletions(-) rename citadel/{ => modules/crypto}/serv_crypto.h (100%) rename citadel/{ => modules/imap}/imap_acl.c (100%) rename citadel/{ => modules/imap}/imap_acl.h (95%) rename citadel/{ => modules/imap}/imap_fetch.c (100%) rename citadel/{ => modules/imap}/imap_fetch.h (100%) rename citadel/{ => modules/imap}/imap_list.c (99%) rename citadel/{ => modules/imap}/imap_list.h (100%) rename citadel/{ => modules/imap}/imap_metadata.c (100%) rename citadel/{ => modules/imap}/imap_metadata.h (100%) rename citadel/{ => modules/imap}/imap_misc.c (100%) rename citadel/{ => modules/imap}/imap_misc.h (100%) rename citadel/{ => modules/imap}/imap_search.c (99%) rename citadel/{ => modules/imap}/imap_search.h (100%) rename citadel/{ => modules/imap}/imap_store.c (100%) rename citadel/{ => modules/imap}/imap_store.h (100%) rename citadel/{ => modules/imap}/imap_tools.c (100%) rename citadel/{ => modules/imap}/serv_imap.c (99%) rename citadel/{ => modules/imap}/serv_imap.h (100%) rename citadel/{ => modules/ldap}/serv_ldap.h (100%) diff --git a/citadel/Makefile.in b/citadel/Makefile.in index f2c63032e..3c4e6511a 100644 --- a/citadel/Makefile.in +++ b/citadel/Makefile.in @@ -36,15 +36,15 @@ SERV_MODULES=modules/chat/serv_chat.o \ modules/vcard/serv_vcard.o \ vcard.o \ modules/mrtg/serv_mrtg.o \ - serv_imap.o \ - imap_fetch.o \ - imap_misc.o \ - imap_search.o \ - imap_store.o \ - imap_acl.o \ - imap_metadata.o \ - imap_tools.o \ - imap_list.o \ + modules/imap/serv_imap.o \ + modules/imap/imap_fetch.o \ + modules/imap/imap_misc.o \ + modules/imap/imap_search.o \ + modules/imap/imap_store.o \ + modules/imap/imap_acl.o \ + modules/imap/imap_metadata.o \ + modules/imap/imap_tools.o \ + modules/imap/imap_list.o \ modules/fulltext/serv_fulltext.o \ modules/fulltext/ft_wordbreaker.o \ crc16.o \ @@ -107,8 +107,8 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c chkpw.c citadel.c citadel_ipc.c \ citmail.c citserver.c client_chat.c client_passwords.c \ clientsocket.c commands.c config.c control.c $(DATABASE) \ domain.c serv_extensions.c file_ops.c genstamp.c getutline.c \ - housekeeping.c html.c ical_dezonify.c imap_fetch.c imap_misc.c \ - imap_search.c imap_store.c imap_tools.c internet_addressing.c \ + housekeeping.c html.c ical_dezonify.c \ + internet_addressing.c \ ipc_c_tcp.c locate_host.c md5.c messages.c \ modules/autocompletion/serv_autocompletion.c \ mime_parser.c msgbase.c msgform.c parsedate.c policy.c \ @@ -119,7 +119,15 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c chkpw.c citadel.c citadel_ipc.c \ modules/chat/serv_chat.c \ modules/crypto/serv_crypto.c \ modules/expire/serv_expire.c \ - serv_imap.c \ + modules/imap/serv_imap.c \ + modules/imap/imap_search.c \ + modules/imap/imap_store.c \ + modules/imap/imap_tools.c \ + modules/imap/imap_fetch.c \ + modules/imap/imap_misc.c \ + modules/imap/imap_acl.c \ + modules/imap/imap_list.c \ + modules/imap/imap_metadata.c \ modules/inetcfg/serv_inetcfg.c \ modules/listsub/serv_listsub.c \ modules/mrtg/serv_mrtg.c \ @@ -139,13 +147,13 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c chkpw.c citadel.c citadel_ipc.c \ server_main.c \ modules/sieve/serv_sieve.c \ modules/funambol/serv_funambol.c \ - setup.c snprintf.c imap_acl.c \ + setup.c snprintf.c \ stress.c support.c sysdep.c tools.c user_ops.c userlist.c \ whobbs.c vcard.c \ modules/notes/serv_notes.c \ modules/fulltext/serv_fulltext.c \ modules/fulltext/ft_wordbreaker.c \ - crc16.c journaling.c citadel_dirs.c imap_list.c imap_metadata.c \ + crc16.c journaling.c citadel_dirs.c \ modules/test/serv_test.c DEP_FILES=$(SOURCES:.c=.d) modules_init.d diff --git a/citadel/citserver.c b/citadel/citserver.c index 262cb2b32..90a7f4f96 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -53,7 +53,7 @@ #include "control.h" #include "tools.h" #include "euidindex.h" -#include "serv_network.h" +#include "serv_network.h" /* Needed for destroy_network_queue_room called from master_cleanup */ #ifndef HAVE_SNPRINTF #include "snprintf.h" @@ -125,6 +125,7 @@ void master_startup(void) { */ void master_cleanup(int exitcode) { struct CleanupFunctionHook *fcn; + struct MaintenanceThreadHook *m_fcn; static int already_cleaning_up = 0; if (already_cleaning_up) while(1) sleep(1); @@ -138,13 +139,11 @@ void master_cleanup(int exitcode) { /* Close the AdjRefCount queue file */ AdjRefCount(-1, 0); - /* Shut down the indexer thread */ - lprintf(CTDL_INFO, "Waiting for the indexer thread to shut down\n"); - pthread_join(indexer_thread_tid, NULL); - - /* Shut down the checkpoint thread */ - lprintf(CTDL_INFO, "Waiting for the checkpoint thread to shut down\n"); - pthread_join(checkpoint_thread_tid, NULL); + for (m_fcn = MaintenanceThreadHookTable; m_fcn != NULL; m_fcn = m_fcn->next) { + lprintf(CTDL_INFO, "Waiting for maintenance thread \"%s\" to shut down\n", m_fcn->name); + pthread_join(m_fcn->MaintenanceThread_tid, NULL); + } + /* Close databases */ lprintf(CTDL_INFO, "Closing databases\n"); diff --git a/citadel/database_sleepycat.c b/citadel/database_sleepycat.c index e01c0adad..bf1165688 100644 --- a/citadel/database_sleepycat.c +++ b/citadel/database_sleepycat.c @@ -451,6 +451,8 @@ void open_databases(void) } cdb_allocate_tsd(); + + CtdlRegisterMaintenanceThread ("checkpoint", checkpoint_thread); } diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index ed8e7c9c7..a839ffbab 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -62,4 +62,11 @@ void CtdlRegisterFixedOutputHook(char *content_type, ); void CtdlUnRegisterFixedOutputHook(char *content_type); +void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg)); + +/* TODODRW: This needs to be changed into a hook type interface + * for now we have this horrible hack + */ +void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response); + #endif /* CTDL_MODULE_H */ diff --git a/citadel/journaling.c b/citadel/journaling.c index 4d18623c5..9a7088722 100644 --- a/citadel/journaling.c +++ b/citadel/journaling.c @@ -47,7 +47,7 @@ #include "genstamp.h" #include "internet_addressing.h" #include "vcard.h" -#include "serv_vcard.h" +#include "serv_vcard.h" /* Needed for vcard_getuser and extract_inet_email_addrs */ #include "journaling.h" struct jnlq *jnlq = NULL; /* journal queue */ diff --git a/citadel/serv_crypto.h b/citadel/modules/crypto/serv_crypto.h similarity index 100% rename from citadel/serv_crypto.h rename to citadel/modules/crypto/serv_crypto.h diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index 66b46570d..d6f2c9b6f 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -60,7 +60,7 @@ #include "msgbase.h" #include "user_ops.h" #include "control.h" -#include "serv_network.h" +#include "serv_network.h" /* Needed for defenition of UseTable */ #include "tools.h" diff --git a/citadel/modules/fulltext/serv_fulltext.c b/citadel/modules/fulltext/serv_fulltext.c index f6e2c672a..b5753fbf6 100644 --- a/citadel/modules/fulltext/serv_fulltext.c +++ b/citadel/modules/fulltext/serv_fulltext.c @@ -473,6 +473,7 @@ CTDL_MODULE_INIT(fulltext) { initialize_ft_cache(); CtdlRegisterProtoHook(cmd_srch, "SRCH", "Full text search"); + CtdlRegisterMaintenanceThread ("indexer", indexer_thread); /* return our Subversion id for the Log */ return "$Id$"; diff --git a/citadel/imap_acl.c b/citadel/modules/imap/imap_acl.c similarity index 100% rename from citadel/imap_acl.c rename to citadel/modules/imap/imap_acl.c diff --git a/citadel/imap_acl.h b/citadel/modules/imap/imap_acl.h similarity index 95% rename from citadel/imap_acl.h rename to citadel/modules/imap/imap_acl.h index 5d8a84036..bfc2c144a 100644 --- a/citadel/imap_acl.h +++ b/citadel/modules/imap/imap_acl.h @@ -1,5 +1,5 @@ /* - * $Id: $ + * $Id$ * */ diff --git a/citadel/imap_fetch.c b/citadel/modules/imap/imap_fetch.c similarity index 100% rename from citadel/imap_fetch.c rename to citadel/modules/imap/imap_fetch.c diff --git a/citadel/imap_fetch.h b/citadel/modules/imap/imap_fetch.h similarity index 100% rename from citadel/imap_fetch.h rename to citadel/modules/imap/imap_fetch.h diff --git a/citadel/imap_list.c b/citadel/modules/imap/imap_list.c similarity index 99% rename from citadel/imap_list.c rename to citadel/modules/imap/imap_list.c index be01c99a7..57bb65864 100644 --- a/citadel/imap_list.c +++ b/citadel/modules/imap/imap_list.c @@ -55,9 +55,6 @@ #include "imap_misc.h" #include "imap_list.h" -#ifdef HAVE_OPENSSL -#include "serv_crypto.h" -#endif /* * Used by LIST and LSUB to show the floors in the listing diff --git a/citadel/imap_list.h b/citadel/modules/imap/imap_list.h similarity index 100% rename from citadel/imap_list.h rename to citadel/modules/imap/imap_list.h diff --git a/citadel/imap_metadata.c b/citadel/modules/imap/imap_metadata.c similarity index 100% rename from citadel/imap_metadata.c rename to citadel/modules/imap/imap_metadata.c diff --git a/citadel/imap_metadata.h b/citadel/modules/imap/imap_metadata.h similarity index 100% rename from citadel/imap_metadata.h rename to citadel/modules/imap/imap_metadata.h diff --git a/citadel/imap_misc.c b/citadel/modules/imap/imap_misc.c similarity index 100% rename from citadel/imap_misc.c rename to citadel/modules/imap/imap_misc.c diff --git a/citadel/imap_misc.h b/citadel/modules/imap/imap_misc.h similarity index 100% rename from citadel/imap_misc.h rename to citadel/modules/imap/imap_misc.h diff --git a/citadel/imap_search.c b/citadel/modules/imap/imap_search.c similarity index 99% rename from citadel/imap_search.c rename to citadel/modules/imap/imap_search.c index 1c647774b..64f26f648 100644 --- a/citadel/imap_search.c +++ b/citadel/modules/imap/imap_search.c @@ -48,7 +48,7 @@ #include "imap_fetch.h" #include "imap_search.h" #include "genstamp.h" -#include "serv_fulltext.h" +#include "serv_fulltext.h" /* Needed for ft_search */ /* diff --git a/citadel/imap_search.h b/citadel/modules/imap/imap_search.h similarity index 100% rename from citadel/imap_search.h rename to citadel/modules/imap/imap_search.h diff --git a/citadel/imap_store.c b/citadel/modules/imap/imap_store.c similarity index 100% rename from citadel/imap_store.c rename to citadel/modules/imap/imap_store.c diff --git a/citadel/imap_store.h b/citadel/modules/imap/imap_store.h similarity index 100% rename from citadel/imap_store.h rename to citadel/modules/imap/imap_store.h diff --git a/citadel/imap_tools.c b/citadel/modules/imap/imap_tools.c similarity index 100% rename from citadel/imap_tools.c rename to citadel/modules/imap/imap_tools.c diff --git a/citadel/serv_imap.c b/citadel/modules/imap/serv_imap.c similarity index 99% rename from citadel/serv_imap.c rename to citadel/modules/imap/serv_imap.c index be4132ea3..a391e91ac 100644 --- a/citadel/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -57,10 +57,6 @@ #include "imap_metadata.h" #include "imap_misc.h" -#ifdef HAVE_OPENSSL -#include "serv_crypto.h" -#endif - #include "ctdl_module.h" @@ -506,12 +502,10 @@ void imap_greeting(void) /* * IMAPS is just like IMAP, except it goes crypto right away. */ -#ifdef HAVE_OPENSSL void imaps_greeting(void) { - CtdlStartTLS(NULL, NULL, NULL); + CtdlModuleStartCryptoMsgs(NULL, NULL, NULL); imap_greeting(); } -#endif /* @@ -639,7 +633,6 @@ void imap_auth_login_pass(char *cmd) /* * implements the STARTTLS command (Citadel API version) */ -#ifdef HAVE_OPENSSL void imap_starttls(int num_parms, char *parms[]) { char ok_response[SIZ]; @@ -655,9 +648,8 @@ void imap_starttls(int num_parms, char *parms[]) sprintf(error_response, "%s BAD Internal error\r\n", parms[0]); - CtdlStartTLS(ok_response, nosup_response, error_response); + CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response); } -#endif /* diff --git a/citadel/serv_imap.h b/citadel/modules/imap/serv_imap.h similarity index 100% rename from citadel/serv_imap.h rename to citadel/modules/imap/serv_imap.h diff --git a/citadel/serv_ldap.h b/citadel/modules/ldap/serv_ldap.h similarity index 100% rename from citadel/serv_ldap.h rename to citadel/modules/ldap/serv_ldap.h diff --git a/citadel/modules/listsub/serv_listsub.c b/citadel/modules/listsub/serv_listsub.c index 93e93553b..6a0374533 100644 --- a/citadel/modules/listsub/serv_listsub.c +++ b/citadel/modules/listsub/serv_listsub.c @@ -45,7 +45,6 @@ #include "msgbase.h" #include "tools.h" #include "internet_addressing.h" -#include "serv_network.h" #include "clientsocket.h" #include "file_ops.h" diff --git a/citadel/modules/managesieve/serv_managesieve.c b/citadel/modules/managesieve/serv_managesieve.c index c43d8aa19..56c28a327 100644 --- a/citadel/modules/managesieve/serv_managesieve.c +++ b/citadel/modules/managesieve/serv_managesieve.c @@ -51,17 +51,13 @@ #include "msgbase.h" #include "tools.h" #include "internet_addressing.h" -#include "imap_tools.h" +#include "imap_tools.h" /* Needed for imap_parameterize */ #include "genstamp.h" #include "domain.h" #include "clientsocket.h" #include "locate_host.h" #include "citadel_dirs.h" -#ifdef HAVE_OPENSSL -#include "serv_crypto.h" -#endif - #ifndef HAVE_SNPRINTF #include "snprintf.h" #endif @@ -246,17 +242,15 @@ void cmd_mgsve_auth(int num_parms, char **parms, struct sdm_userdata *u) } -#ifdef HAVE_OPENSSL /** * STARTTLS command chapter 2.2 */ void cmd_mgsve_starttls(void) { /** answer with OK, and fire off tls session. */ cprintf("OK\r\n"); - CtdlStartTLS(NULL, NULL, NULL); + CtdlModuleStartCryptoMsgs(NULL, NULL, NULL); cmd_mgsve_caps(); } -#endif @@ -477,7 +471,6 @@ void mgsve_auth(char *argbuf) { /* * implements the STARTTLS command (Citadel API version) */ -#ifdef HAVE_OPENSSL void _mgsve_starttls(void) { char ok_response[SIZ]; @@ -490,9 +483,8 @@ void _mgsve_starttls(void) "554 5.7.3 TLS not supported here\r\n"); sprintf(error_response, "554 5.7.3 Internal error\r\n"); - CtdlStartTLS(ok_response, nosup_response, error_response); + CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response); } -#endif /* diff --git a/citadel/modules/netfilter/serv_netfilter.c b/citadel/modules/netfilter/serv_netfilter.c index 31fced57b..edaf01d4f 100644 --- a/citadel/modules/netfilter/serv_netfilter.c +++ b/citadel/modules/netfilter/serv_netfilter.c @@ -41,7 +41,7 @@ #include "policy.h" #include "database.h" #include "msgbase.h" -#include "serv_network.h" +#include "serv_network.h" /* Needed for defenition of FilterList */ #include "tools.h" diff --git a/citadel/modules/pop3/serv_pop3.c b/citadel/modules/pop3/serv_pop3.c index c49c5cad9..ba2faa1e1 100644 --- a/citadel/modules/pop3/serv_pop3.c +++ b/citadel/modules/pop3/serv_pop3.c @@ -56,9 +56,6 @@ #include "serv_pop3.h" #include "md5.h" -#ifdef HAVE_OPENSSL -#include "serv_crypto.h" -#endif #include "ctdl_module.h" @@ -99,12 +96,10 @@ void pop3_greeting(void) { /* * POP3S is just like POP3, except it goes crypto right away. */ -#ifdef HAVE_OPENSSL void pop3s_greeting(void) { - CtdlStartTLS(NULL, NULL, NULL); + CtdlModuleStartCryptoMsgs(NULL, NULL, NULL); pop3_greeting(); } -#endif @@ -589,7 +584,6 @@ void pop3_uidl(char *argbuf) { /* * implements the STLS command (Citadel API version) */ -#ifdef HAVE_OPENSSL void pop3_stls(void) { char ok_response[SIZ]; @@ -602,9 +596,8 @@ void pop3_stls(void) "-ERR TLS not supported here\r\n"); sprintf(error_response, "-ERR Internal error\r\n"); - CtdlStartTLS(ok_response, nosup_response, error_response); + CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response); } -#endif diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index c2329ba91..f24701ac0 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -74,10 +74,6 @@ #include "locate_host.h" #include "citadel_dirs.h" -#ifdef HAVE_OPENSSL -#include "serv_crypto.h" -#endif - #ifndef HAVE_SNPRINTF @@ -168,12 +164,10 @@ void smtp_greeting(int is_msa) /* * SMTPS is just like SMTP, except it goes crypto right away. */ -#ifdef HAVE_OPENSSL void smtps_greeting(void) { - CtdlStartTLS(NULL, NULL, NULL); + CtdlModuleStartCryptoMsgs(NULL, NULL, NULL); smtp_greeting(0); } -#endif /* @@ -797,7 +791,6 @@ void smtp_data(void) { /* * implements the STARTTLS command (Citadel API version) */ -#ifdef HAVE_OPENSSL void smtp_starttls(void) { char ok_response[SIZ]; @@ -810,10 +803,9 @@ void smtp_starttls(void) "554 5.7.3 TLS not supported here\r\n"); sprintf(error_response, "554 5.7.3 Internal error\r\n"); - CtdlStartTLS(ok_response, nosup_response, error_response); + CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response); smtp_rset(0); } -#endif diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index ba292dfeb..dbedf1fd8 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -62,7 +62,6 @@ #include "tools.h" #include "mime_parser.h" #include "vcard.h" -#include "serv_ldap.h" #include "serv_vcard.h" diff --git a/citadel/msgbase.c b/citadel/msgbase.c index e110a11e9..51bf426f1 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -49,12 +49,11 @@ #include "html.h" #include "genstamp.h" #include "internet_addressing.h" -#include "serv_fulltext.h" +#include "serv_fulltext.h" /* Needed for ft_search and ft_index_message */ #include "vcard.h" #include "euidindex.h" #include "journaling.h" #include "citadel_dirs.h" -#include "serv_network.h" long config_msgnum; diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index 1acd40e09..78d721704 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -23,6 +23,8 @@ #include "tools.h" #include "config.h" +#include "modules/crypto/serv_crypto.h" /* Needed until a universal crypto startup hook is implimented for CtdlStartTLS */ + #ifndef HAVE_SNPRINTF #include #include "snprintf.h" @@ -38,7 +40,7 @@ struct DeleteFunctionHook *DeleteHookTable = NULL; struct ServiceFunctionHook *ServiceHookTable = NULL; struct FixedOutputHook *FixedOutputTable = NULL; struct RoomFunctionHook *RoomHookTable = NULL; - +struct MaintenanceThreadHook *MaintenanceThreadHookTable = NULL; struct ProtoFunctionHook { void (*handler) (char *cmdbuf); @@ -1014,3 +1016,28 @@ int PerformXmsgHooks(char *sender, char *recp, char *msg) } return total_sent; } + +void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg)) +{ + struct MaintenanceThreadHook *newfcn; + + newfcn = (struct MaintenanceThreadHook *) + malloc(sizeof(struct MaintenanceThreadHook)); + newfcn->name = name; + newfcn->next = MaintenanceThreadHookTable; + newfcn->fcn_ptr = thread_proc; + MaintenanceThreadHookTable = newfcn; + + lprintf(CTDL_INFO, "Registered a new maintenance thread function\n"); +} + + +/* + * Dirty hack until we impliment a hook mechanism for this + */ +void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response) +{ +#ifdef HAVE_OPENSSL + CtdlStartTLS (ok_response, nosup_response, error_response); +#endif +} diff --git a/citadel/server.h b/citadel/server.h index c455cff53..11cd6319b 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -451,6 +451,15 @@ struct RoomFunctionHook { extern struct RoomFunctionHook *RoomHookTable; +struct MaintenanceThreadHook { + struct MaintenanceThreadHook *next; + char *name; + void *(*fcn_ptr) (void *arg); + pthread_t MaintenanceThread_tid; +}; +extern struct MaintenanceThreadHook *MaintenanceThreadHookTable; + + /* Defines the relationship of a user to a particular room */ struct visit { diff --git a/citadel/server_main.c b/citadel/server_main.c index 23ef71d91..318f72e2b 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -297,7 +297,7 @@ int main(int argc, char **argv) } end_critical_section(S_WORKER_LIST); - /* Create the indexer thread. */ + /* Create the maintenance threads. */ create_maintenance_threads(); /* This thread is now useless. It can't be turned into a worker diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 64ea7ee6b..1ce836558 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -61,8 +61,7 @@ #include "database.h" #include "housekeeping.h" #include "tools.h" -#include "serv_crypto.h" -#include "serv_fulltext.h" +#include "modules/crypto/serv_crypto.h" /* Needed for init_ssl, client_write_ssl, client_read_ssl, destruct_ssl */ #ifdef HAVE_SYS_SELECT_H #include @@ -94,8 +93,6 @@ struct CitContext masterCC; time_t last_purge = 0; /* Last dead session purge */ static int num_threads = 0; /* Current number of threads */ int num_sessions = 0; /* Current number of sessions */ -pthread_t indexer_thread_tid; -pthread_t checkpoint_thread_tid; int syslog_facility = LOG_DAEMON; int enable_syslog = 0; @@ -980,8 +977,7 @@ void DestroyWorkerList(void) } /* - * Create the indexer thread and begin its operation. - * Then create the checkpoint thread and begin its operation. + * Create the maintenance threads and begin their operation. */ void create_maintenance_threads(void) { int ret; @@ -1004,17 +1000,23 @@ void create_maintenance_threads(void) { pthread_attr_destroy(&attr); return; } + + struct MaintenanceThreadHook *fcn; - if ((ret = pthread_create(&indexer_thread_tid, &attr, indexer_thread, NULL) != 0)) { - lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret)); - } + lprintf(CTDL_DEBUG, "Performing startup of maintenance thread hooks\n"); - if ((ret = pthread_create(&checkpoint_thread_tid, &attr, checkpoint_thread, NULL) != 0)) { - lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret)); + for (fcn = MaintenanceThreadHookTable; fcn != NULL; fcn = fcn->next) { + if ((ret = pthread_create(&(fcn->MaintenanceThread_tid), &attr, fcn->fcn_ptr, NULL) != 0)) { + lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret)); + } + else + { + lprintf(CTDL_NOTICE, "Spawned a new maintenance thread \"%s\" (%ld). \n", fcn->name, + fcn->MaintenanceThread_tid); + } } - lprintf(CTDL_NOTICE, "Spawned indexer (%ld) and checkpoint (%ld) thread. \n", - indexer_thread_tid, checkpoint_thread_tid); + pthread_attr_destroy(&attr); } diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index a1e551c9f..54d889384 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -106,7 +106,5 @@ void dump_heap(void); #endif void create_maintenance_threads(void); -extern pthread_t indexer_thread_tid; -extern pthread_t checkpoint_thread_tid; #endif /* SYSDEP_DECLS_H */ -- 2.30.2