From bcbaf2800c778043c12f9fd2d719ca9271ac6cb4 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 22 Jun 2012 23:28:52 +0200 Subject: [PATCH] MODULES: add priorities in execution - specialy the EV_TIMER callbacks were suffering from wrong order execution which caused bad behaviours: - network queueing now is executed before mail queue handling -> mailinglist posts are sent in < 60s instead of < 120s as before - network spool consolidation is done before running the citadel networkers; that way the NTT-list won't be locked by running networkers --- citadel/include/ctdl_module.h | 28 +++++++++++++++++-- citadel/modules/calendar/serv_calendar.c | 6 ++-- citadel/modules/checkpoint/serv_checkpoint.c | 2 +- citadel/modules/crypto/serv_crypto.c | 2 +- citadel/modules/expire/serv_expire.c | 2 +- citadel/modules/extnotify/extnotify_main.c | 2 +- citadel/modules/fulltext/serv_fulltext.c | 2 +- citadel/modules/imap/serv_imap.c | 2 +- citadel/modules/instmsg/serv_instmsg.c | 8 +++--- .../modules/managesieve/serv_managesieve.c | 2 +- citadel/modules/network/serv_network.c | 6 ++-- citadel/modules/network/serv_networkclient.c | 2 +- citadel/modules/newuser/serv_newuser.c | 2 +- citadel/modules/openid/serv_openid_rp.c | 2 +- citadel/modules/pop3/serv_pop3.c | 2 +- citadel/modules/pop3client/serv_pop3client.c | 2 +- citadel/modules/roomchat/serv_roomchat.c | 4 +-- citadel/modules/rssclient/serv_rssclient.c | 2 +- citadel/modules/sieve/serv_sieve.c | 2 +- citadel/modules/smtp/serv_smtp.c | 2 +- citadel/modules/smtp/serv_smtpqueue.c | 2 +- citadel/modules/test/serv_test.c | 8 +++--- citadel/modules/vcard/serv_vcard.c | 4 +-- citadel/modules/xmpp/serv_xmpp.c | 10 +++---- citadel/serv_extensions.c | 21 ++++++++++---- citadel/server_main.c | 2 +- 26 files changed, 81 insertions(+), 48 deletions(-) diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index 9bcdb34a5..9b7f8e2f9 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -76,8 +76,32 @@ /* * Hook functions available to modules. */ - -void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType); +/* Priorities for */ +#define PRIO_QUEUE 500 +#define PRIO_AGGR 1000 +#define PRIO_SEND 1500 +#define PRIO_CLEANUP 2000 +/* Priorities for EVT_HOUSE */ +#define PRIO_HOUSE 3000 +/* Priorities for EVT_LOGIN */ +#define PRIO_CREATE 10000 +/* Priorities for EVT_LOGOUT */ +#define PRIO_LOGOUT 15000 +/* Priorities for EVT_LOGIN */ +#define PRIO_LOGIN 20000 +/* Priorities for EVT_START */ +#define PRIO_START 25000 +/* Priorities for EVT_STOP */ +#define PRIO_STOP 30000 +/* Priorities for EVT_ASYNC */ +#define PRIO_ASYNC 35000 +/* Priorities for EVT_SHUTDOWN */ +#define PRIO_SHUTDOWN 40000 +/* Priorities for EVT_UNSTEALTH */ +#define PRIO_UNSTEALTH 45000 +/* Priorities for EVT_STEALTH */ +#define PRIO_STEALTH 50000 +void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority); void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType); void CtdlShutdownServiceHooks(void); diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index 6f8e3feb5..d9236bd33 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -2600,10 +2600,10 @@ CTDL_MODULE_INIT(calendar) /* Initialize our hook functions */ CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE); CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE); - CtdlRegisterSessionHook(ical_CtdlCreateRoom, EVT_LOGIN); + CtdlRegisterSessionHook(ical_CtdlCreateRoom, EVT_LOGIN, PRIO_LOGIN + 1); CtdlRegisterProtoHook(cmd_ical, "ICAL", "Citadel iCal commands"); - CtdlRegisterSessionHook(ical_session_startup, EVT_START); - CtdlRegisterSessionHook(ical_session_shutdown, EVT_STOP); + CtdlRegisterSessionHook(ical_session_startup, EVT_START, PRIO_START + 1); + CtdlRegisterSessionHook(ical_session_shutdown, EVT_STOP, PRIO_STOP + 80); CtdlRegisterFixedOutputHook("text/calendar", ical_fixed_output); CtdlRegisterFixedOutputHook("application/ics", ical_fixed_output); CtdlRegisterCleanupHook(serv_calendar_destroy); diff --git a/citadel/modules/checkpoint/serv_checkpoint.c b/citadel/modules/checkpoint/serv_checkpoint.c index ba51abd44..60e829c7d 100644 --- a/citadel/modules/checkpoint/serv_checkpoint.c +++ b/citadel/modules/checkpoint/serv_checkpoint.c @@ -61,7 +61,7 @@ CTDL_MODULE_INIT(checkpoint) { if (threading) { - CtdlRegisterSessionHook(cdb_checkpoint, EVT_TIMER); + CtdlRegisterSessionHook(cdb_checkpoint, EVT_TIMER, PRIO_CLEANUP + 10); } /* return our module name for the log */ return "checkpoint"; diff --git a/citadel/modules/crypto/serv_crypto.c b/citadel/modules/crypto/serv_crypto.c index ea5428219..a9761a549 100644 --- a/citadel/modules/crypto/serv_crypto.c +++ b/citadel/modules/crypto/serv_crypto.c @@ -385,7 +385,7 @@ void init_ssl(void) CtdlRegisterProtoHook(cmd_stls, "STLS", "Start SSL/TLS session"); CtdlRegisterProtoHook(cmd_gtls, "GTLS", "Get SSL/TLS session status"); - CtdlRegisterSessionHook(endtls, EVT_STOP); + CtdlRegisterSessionHook(endtls, EVT_STOP, PRIO_STOP + 10); } diff --git a/citadel/modules/expire/serv_expire.c b/citadel/modules/expire/serv_expire.c index d81880858..e03d43b6a 100644 --- a/citadel/modules/expire/serv_expire.c +++ b/citadel/modules/expire/serv_expire.c @@ -951,7 +951,7 @@ CTDL_MODULE_INIT(expire) CtdlRegisterProtoHook(cmd_tdap, "TDAP", "Manually initiate auto-purger"); CtdlRegisterProtoHook(cmd_gpex, "GPEX", "Get expire policy"); CtdlRegisterProtoHook(cmd_spex, "SPEX", "Set expire policy"); - CtdlRegisterSessionHook(purge_databases, EVT_TIMER); + CtdlRegisterSessionHook(purge_databases, EVT_TIMER, PRIO_CLEANUP + 20); } /* return our module name for the log */ diff --git a/citadel/modules/extnotify/extnotify_main.c b/citadel/modules/extnotify/extnotify_main.c index 8d99f6f1c..a519548fa 100644 --- a/citadel/modules/extnotify/extnotify_main.c +++ b/citadel/modules/extnotify/extnotify_main.c @@ -471,7 +471,7 @@ CTDL_MODULE_INIT(extnotify) if (!threading) { create_extnotify_queue(); - CtdlRegisterSessionHook(do_extnotify_queue, EVT_TIMER); + CtdlRegisterSessionHook(do_extnotify_queue, EVT_TIMER, PRIO_SEND + 10); } /* return our module name for the log */ return "extnotify"; diff --git a/citadel/modules/fulltext/serv_fulltext.c b/citadel/modules/fulltext/serv_fulltext.c index cc3906867..b0e3d5e7b 100644 --- a/citadel/modules/fulltext/serv_fulltext.c +++ b/citadel/modules/fulltext/serv_fulltext.c @@ -507,7 +507,7 @@ CTDL_MODULE_INIT(fulltext) CtdlRegisterDeleteHook(ft_delete_remove); CtdlRegisterSearchFuncHook(ft_search, "fulltext"); CtdlRegisterCleanupHook(noise_word_cleanup); - CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER); + CtdlRegisterSessionHook(do_fulltext_indexing, EVT_TIMER, PRIO_CLEANUP + 300); } /* return our module name for the log */ return "fulltext"; diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index 46a6ba7d9..a7b80d989 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -1721,7 +1721,7 @@ CTDL_MODULE_INIT(imap) CtdlRegisterServiceHook(config.c_imaps_port, NULL, imaps_greeting, imap_command_loop, NULL, CitadelServiceIMAPS); #endif - CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP); + CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP, PRIO_STOP + 30); CtdlRegisterCleanupHook(imap_cleanup); } diff --git a/citadel/modules/instmsg/serv_instmsg.c b/citadel/modules/instmsg/serv_instmsg.c index 84acbc4f2..040c1b42e 100644 --- a/citadel/modules/instmsg/serv_instmsg.c +++ b/citadel/modules/instmsg/serv_instmsg.c @@ -599,11 +599,11 @@ CTDL_MODULE_INIT(instmsg) CtdlRegisterProtoHook(cmd_sexp, "SEXP", "Send an instant message"); CtdlRegisterProtoHook(cmd_dexp, "DEXP", "Disable instant messages"); CtdlRegisterProtoHook(cmd_reqt, "REQT", "Request client termination"); - CtdlRegisterSessionHook(cmd_gexp_async, EVT_ASYNC); - CtdlRegisterSessionHook(delete_instant_messages, EVT_STOP); + CtdlRegisterSessionHook(cmd_gexp_async, EVT_ASYNC, PRIO_ASYNC + 1); + CtdlRegisterSessionHook(delete_instant_messages, EVT_STOP, PRIO_STOP + 1); CtdlRegisterXmsgHook(send_instant_message, XMSG_PRI_LOCAL); - CtdlRegisterSessionHook(instmsg_timer, EVT_TIMER); - CtdlRegisterSessionHook(instmsg_shutdown, EVT_SHUTDOWN); + CtdlRegisterSessionHook(instmsg_timer, EVT_TIMER, PRIO_CLEANUP + 400); + CtdlRegisterSessionHook(instmsg_shutdown, EVT_SHUTDOWN, PRIO_SHUTDOWN + 10); } /* return our module name for the log */ diff --git a/citadel/modules/managesieve/serv_managesieve.c b/citadel/modules/managesieve/serv_managesieve.c index fe7b54239..a256d3deb 100644 --- a/citadel/modules/managesieve/serv_managesieve.c +++ b/citadel/modules/managesieve/serv_managesieve.c @@ -666,7 +666,7 @@ CTDL_MODULE_INIT(managesieve) managesieve_command_loop, NULL, CitadelServiceManageSieve); - CtdlRegisterSessionHook(managesieve_cleanup_function, EVT_STOP); + CtdlRegisterSessionHook(managesieve_cleanup_function, EVT_STOP, PRIO_STOP + 30); } /* return our module name for the log */ diff --git a/citadel/modules/network/serv_network.c b/citadel/modules/network/serv_network.c index 5ab8892a0..a100965c7 100644 --- a/citadel/modules/network/serv_network.c +++ b/citadel/modules/network/serv_network.c @@ -734,12 +734,12 @@ CTDL_MODULE_INIT(network) { CtdlRegisterDebugFlagHook(HKEY("networktalkingto"), SetNTTDebugEnabled, &NTTDebugEnabled); CtdlRegisterCleanupHook(cleanup_nttlist); - CtdlRegisterSessionHook(network_cleanup_function, EVT_STOP); - CtdlRegisterSessionHook(network_logout_hook, EVT_LOGOUT); + CtdlRegisterSessionHook(network_cleanup_function, EVT_STOP, PRIO_STOP + 30); + CtdlRegisterSessionHook(network_logout_hook, EVT_LOGOUT, PRIO_LOGOUT + 10); CtdlRegisterProtoHook(cmd_nsyn, "NSYN", "Synchronize room to node"); CtdlRegisterRoomHook(network_room_handler); CtdlRegisterCleanupHook(destroy_network_queue_room_locked); - CtdlRegisterSessionHook(network_do_queue, EVT_TIMER); + CtdlRegisterSessionHook(network_do_queue, EVT_TIMER, PRIO_QUEUE + 10); } return "network"; } diff --git a/citadel/modules/network/serv_networkclient.c b/citadel/modules/network/serv_networkclient.c index 8ee884619..d5cf394ea 100644 --- a/citadel/modules/network/serv_networkclient.c +++ b/citadel/modules/network/serv_networkclient.c @@ -1043,7 +1043,7 @@ CTDL_MODULE_INIT(network_client) { CtdlFillSystemContext(&networker_client_CC, "CitNetworker"); - CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER); + CtdlRegisterSessionHook(network_do_clientqueue, EVT_TIMER, PRIO_SEND + 10); CtdlRegisterDebugFlagHook(HKEY("networkclient"), LogDebugEnableNetworkClient, &NetworkClientDebugEnabled); } diff --git a/citadel/modules/newuser/serv_newuser.c b/citadel/modules/newuser/serv_newuser.c index 2be9b1a5a..64ffc8a28 100644 --- a/citadel/modules/newuser/serv_newuser.c +++ b/citadel/modules/newuser/serv_newuser.c @@ -110,7 +110,7 @@ CTDL_MODULE_INIT(newuser) { if (!threading) { - CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN); + CtdlRegisterSessionHook(CopyNewUserGreetings, EVT_LOGIN, PRIO_LOGIN + 1); } /* return our module name for the log */ diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index 69006e48e..ecb4ef387 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -1140,7 +1140,7 @@ CTDL_MODULE_INIT(openid_rp) CtdlRegisterProtoHook(cmd_oidc, "OIDC", "Create new user after validating OpenID"); CtdlRegisterProtoHook(cmd_oida, "OIDA", "List all OpenIDs in the database"); } - CtdlRegisterSessionHook(openid_cleanup_function, EVT_LOGOUT); + CtdlRegisterSessionHook(openid_cleanup_function, EVT_LOGOUT, PRIO_LOGOUT + 10); CtdlRegisterUserHook(openid_purge, EVT_PURGEUSER); openid_level_supported = 1; /* This module supports OpenID 1.0 only */ } diff --git a/citadel/modules/pop3/serv_pop3.c b/citadel/modules/pop3/serv_pop3.c index 3de0bf57d..de4d7a065 100644 --- a/citadel/modules/pop3/serv_pop3.c +++ b/citadel/modules/pop3/serv_pop3.c @@ -679,7 +679,7 @@ CTDL_MODULE_INIT(pop3) NULL, CitadelServicePop3S); #endif - CtdlRegisterSessionHook(pop3_cleanup_function, EVT_STOP); + CtdlRegisterSessionHook(pop3_cleanup_function, EVT_STOP, PRIO_STOP + 30); } /* return our module name for the log */ diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index 599a35e69..c14e5da73 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -1260,7 +1260,7 @@ CTDL_MODULE_INIT(pop3client) pthread_mutex_init(&POP3QueueMutex, NULL); POP3QueueRooms = NewHash(1, lFlathash); POP3FetchUrls = NewHash(1, NULL); - CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER); + CtdlRegisterSessionHook(pop3client_scan, EVT_TIMER, PRIO_AGGR + 50); CtdlRegisterEVCleanupHook(pop3_cleanup); CtdlRegisterDebugFlagHook(HKEY("pop3client"), LogDebugEnablePOP3Client, &POP3ClientDebugEnabled); } diff --git a/citadel/modules/roomchat/serv_roomchat.c b/citadel/modules/roomchat/serv_roomchat.c index b0a7ccda4..c153c4f11 100644 --- a/citadel/modules/roomchat/serv_roomchat.c +++ b/citadel/modules/roomchat/serv_roomchat.c @@ -267,8 +267,8 @@ CTDL_MODULE_INIT(roomchat) if (!threading) { CtdlRegisterProtoHook(cmd_rcht, "RCHT", "Participate in real time chat in a room"); - CtdlRegisterSessionHook(roomchat_timer, EVT_TIMER); - CtdlRegisterSessionHook(roomchat_shutdown, EVT_SHUTDOWN); + CtdlRegisterSessionHook(roomchat_timer, EVT_TIMER, PRIO_CLEANUP + 400); + CtdlRegisterSessionHook(roomchat_shutdown, EVT_SHUTDOWN, PRIO_SHUTDOWN + 55); } /* return our module name for the log */ diff --git a/citadel/modules/rssclient/serv_rssclient.c b/citadel/modules/rssclient/serv_rssclient.c index c1e08b811..7bde9791d 100644 --- a/citadel/modules/rssclient/serv_rssclient.c +++ b/citadel/modules/rssclient/serv_rssclient.c @@ -592,7 +592,7 @@ CTDL_MODULE_INIT(rssclient) RSSQueueRooms = NewHash(1, lFlathash); RSSFetchUrls = NewHash(1, NULL); syslog(LOG_INFO, "%s\n", curl_version()); - CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER); + CtdlRegisterSessionHook(rssclient_scan, EVT_TIMER, PRIO_AGGR + 300); CtdlRegisterEVCleanupHook(rss_cleanup); CtdlRegisterDebugFlagHook(HKEY("rssclient"), LogDebugEnableRSSClient, &RSSClientDebugEnabled); } diff --git a/citadel/modules/sieve/serv_sieve.c b/citadel/modules/sieve/serv_sieve.c index 7d56d5e0a..abce872ce 100644 --- a/citadel/modules/sieve/serv_sieve.c +++ b/citadel/modules/sieve/serv_sieve.c @@ -1354,7 +1354,7 @@ CTDL_MODULE_INIT(sieve) ctdl_sieve_init(); CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts"); CtdlRegisterRoomHook(serv_sieve_room); - CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE); + CtdlRegisterSessionHook(perform_sieve_processing, EVT_HOUSE, PRIO_HOUSE + 10); CtdlRegisterCleanupHook(cleanup_sieve); } diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index d6f8e2a30..cc026916d 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -961,7 +961,7 @@ CTDL_MODULE_INIT(smtp) NULL, CitadelServiceSMTP_LMTP_UNF); - CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP); + CtdlRegisterSessionHook(smtp_cleanup_function, EVT_STOP, PRIO_STOP + 250); } /* return our module name for the log */ diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index 589b13a48..2430d0db8 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -1137,7 +1137,7 @@ CTDL_MODULE_INIT(smtp_queu) CtdlRegisterEVCleanupHook(smtp_evq_cleanup); CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands"); - CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER); + CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_SEND + 10); } /* return our Subversion id for the Log */ diff --git a/citadel/modules/test/serv_test.c b/citadel/modules/test/serv_test.c index c82ecb87c..bbb0e5416 100644 --- a/citadel/modules/test/serv_test.c +++ b/citadel/modules/test/serv_test.c @@ -74,10 +74,10 @@ CTDL_MODULE_INIT(test) if (!threading) { CtdlRegisterCleanupHook(CleanupTest); - CtdlRegisterSessionHook(NewRoomTest, EVT_NEWROOM); - CtdlRegisterSessionHook(SessionStartTest, EVT_START); - CtdlRegisterSessionHook(SessionStopTest, EVT_STOP); - CtdlRegisterSessionHook(LoginTest, EVT_LOGIN); + CtdlRegisterSessionHook(NewRoomTest, EVT_NEWROOM, 1); + CtdlRegisterSessionHook(SessionStartTest, EVT_START, 1); + CtdlRegisterSessionHook(SessionStopTest, EVT_STOP, 1); + CtdlRegisterSessionHook(LoginTest, EVT_LOGIN, 1); } #endif diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index 9505ba185..edcbd4cce 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -1452,7 +1452,7 @@ CTDL_MODULE_INIT(vcard) if (!threading) { - CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN); + CtdlRegisterSessionHook(vcard_session_login_hook, EVT_LOGIN, PRIO_LOGIN + 70); CtdlRegisterMessageHook(vcard_upload_beforesave, EVT_BEFORESAVE); CtdlRegisterMessageHook(vcard_upload_aftersave, EVT_AFTERSAVE); CtdlRegisterDeleteHook(vcard_delete_remove); @@ -1466,7 +1466,7 @@ CTDL_MODULE_INIT(vcard) CtdlRegisterUserHook(vcard_newuser, EVT_NEWUSER); CtdlRegisterUserHook(vcard_purge, EVT_PURGEUSER); CtdlRegisterNetprocHook(vcard_extract_from_network); - CtdlRegisterSessionHook(store_harvested_addresses, EVT_TIMER); + CtdlRegisterSessionHook(store_harvested_addresses, EVT_TIMER, PRIO_CLEANUP + 470); CtdlRegisterFixedOutputHook("text/x-vcard", vcard_fixed_output); CtdlRegisterFixedOutputHook("text/vcard", vcard_fixed_output); diff --git a/citadel/modules/xmpp/serv_xmpp.c b/citadel/modules/xmpp/serv_xmpp.c index 374c49142..7d8fbc67d 100644 --- a/citadel/modules/xmpp/serv_xmpp.c +++ b/citadel/modules/xmpp/serv_xmpp.c @@ -633,11 +633,11 @@ CTDL_MODULE_INIT(xmpp) CitadelServiceXMPP ); CtdlRegisterDebugFlagHook(HKEY("serv_xmpp"), LogXMPPSrvDebugEnable, &XMPPSrvDebugEnable); - CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP); - CtdlRegisterSessionHook(xmpp_login_hook, EVT_LOGIN); - CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT); - CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH); - CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH); + CtdlRegisterSessionHook(xmpp_cleanup_function, EVT_STOP, PRIO_STOP + 70); + CtdlRegisterSessionHook(xmpp_login_hook, EVT_LOGIN, PRIO_LOGIN + 90); + CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT, PRIO_LOGOUT + 90); + CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH, PRIO_UNSTEALTH + 1); + CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH, PRIO_STEALTH + 1); CtdlRegisterCleanupHook(xmpp_cleanup_events); } diff --git a/citadel/serv_extensions.c b/citadel/serv_extensions.c index a742c6191..b03741e7a 100644 --- a/citadel/serv_extensions.c +++ b/citadel/serv_extensions.c @@ -87,6 +87,7 @@ extern FixedOutputHook *FixedOutputTable; typedef struct SessionFunctionHook SessionFunctionHook; struct SessionFunctionHook { SessionFunctionHook *next; + int Priority; void (*h_function_pointer) (void); int eventtype; }; @@ -595,20 +596,28 @@ void CtdlDestroyEVCleanupHooks(void) } -void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType) +void CtdlRegisterSessionHook(void (*fcn_ptr) (void), int EventType, int Priority) { - SessionFunctionHook *newfcn; newfcn = (SessionFunctionHook *) malloc(sizeof(SessionFunctionHook)); - newfcn->next = SessionHookTable; + newfcn->Priority = Priority; newfcn->h_function_pointer = fcn_ptr; newfcn->eventtype = EventType; - SessionHookTable = newfcn; - MOD_syslog(LOG_DEBUG, "Registered a new session function (type %d)\n", - EventType); + SessionFunctionHook **pfcn; + pfcn = &SessionHookTable; + while ((*pfcn != NULL) && + ((*pfcn)->Priority < newfcn->Priority) && + ((*pfcn)->next != NULL)) + pfcn = &(*pfcn)->next; + + newfcn->next = *pfcn; + *pfcn = newfcn; + + MOD_syslog(LOG_DEBUG, "Registered a new session function (type %d Priority %d)\n", + EventType, Priority); } diff --git a/citadel/server_main.c b/citadel/server_main.c index 0dc52a0e4..b0cd8f167 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -371,7 +371,7 @@ int main(int argc, char **argv) } /* We want to check for idle sessions once per minute */ - CtdlRegisterSessionHook(terminate_idle_sessions, EVT_TIMER); + CtdlRegisterSessionHook(terminate_idle_sessions, EVT_TIMER, PRIO_CLEANUP + 1); go_threading(); -- 2.30.2