From: Art Cancro Date: Wed, 21 Nov 2007 04:54:19 +0000 (+0000) Subject: struct CitContext no longer contains separate module-specific pointers for X-Git-Tag: v7.86~2761 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=2ed96d7a59a16ca0ebb5707f32044dc411bde25a struct CitContext no longer contains separate module-specific pointers for things like IMAP state, SMTP state, POP3 state, managesieve state, etc. These four modules now use a single 'service_specific_data' pointer, which is cast to whatever data type the module is using. This is possible because only one is used at a time (a session cannot be POP3 and SMTP simultaneously, for example). As before, when a module allocates memory and places a pointer to it in this location, the module's cleanup function continues to be responsible for freeing it, and as before, it must not free this pointer under any other circumstances. Third-party modules which implement new server protocols now have a place to store session data without modifying the server core. Just follow one of the existing server protocol modules as an example. --- diff --git a/citadel/modules/imap/serv_imap.c b/citadel/modules/imap/serv_imap.c index c86518fb8..cd138b86d 100644 --- a/citadel/modules/imap/serv_imap.c +++ b/citadel/modules/imap/serv_imap.c @@ -491,7 +491,7 @@ void imap_greeting(void) { strcpy(CC->cs_clientname, "IMAP session"); - IMAP = malloc(sizeof (struct citimap)); + CC->session_specific_data = malloc(sizeof(struct citimap)); memset(IMAP, 0, sizeof(struct citimap)); IMAP->authstate = imap_as_normal; IMAP->cached_rfc822_data = NULL; diff --git a/citadel/modules/imap/serv_imap.h b/citadel/modules/imap/serv_imap.h index 59e30643e..e2b3f4334 100644 --- a/citadel/modules/imap/serv_imap.h +++ b/citadel/modules/imap/serv_imap.h @@ -67,7 +67,7 @@ enum { #define IMAP_RECENT 64 /* reportable but not setable */ -#define IMAP CC->IMAP +#define IMAP ((struct citimap *)CC->session_specific_data) /* * When loading arrays of message ID's into memory, increase the buffer to diff --git a/citadel/modules/managesieve/serv_managesieve.c b/citadel/modules/managesieve/serv_managesieve.c index 065702fa1..e40007d3f 100644 --- a/citadel/modules/managesieve/serv_managesieve.c +++ b/citadel/modules/managesieve/serv_managesieve.c @@ -95,12 +95,13 @@ enum { /** Command states for login authentication */ mgsve_plain }; -#define MGSVE CC->MGSVE +#define MGSVE ((struct citmgsve *)CC->session_specific_data) /*****************************************************************************/ /* MANAGESIEVE Server */ /*****************************************************************************/ + void sieve_outbuf_append(char *str) { size_t newlen = strlen(str)+1; @@ -144,7 +145,7 @@ void managesieve_greeting(void) { CC->internal_pgm = 1; CC->cs_flags |= CS_STEALTH; - MGSVE = malloc(sizeof(struct citmgsve)); + CC->session_specific_data = malloc(sizeof(struct citmgsve)); memset(MGSVE, 0, sizeof(struct citmgsve)); cmd_mgsve_caps(); } @@ -565,6 +566,20 @@ void managesieve_command_loop(void) { } +/* + * This cleanup function blows away the temporary memory and files used by + * the server. + */ +void managesieve_cleanup_function(void) { + + /* Don't do this stuff if this is not a managesieve session! */ + if (CC->h_command_function != managesieve_command_loop) return; + + lprintf(CTDL_DEBUG, "Performing managesieve cleanup hook\n"); + free(MGSVE); +} + + #endif /* HAVE_LIBSIEVE */ const char* CitadelServiceManageSieve = "ManageSieve"; @@ -572,13 +587,13 @@ CTDL_MODULE_INIT(managesieve) { #ifdef HAVE_LIBSIEVE - - CtdlRegisterServiceHook(config.c_managesieve_port, /* MGSVE */ + CtdlRegisterServiceHook(config.c_managesieve_port, NULL, managesieve_greeting, managesieve_command_loop, NULL, CitadelServiceManageSieve); + CtdlRegisterSessionHook(managesieve_cleanup_function, EVT_STOP); #else /* HAVE_LIBSIEVE */ diff --git a/citadel/modules/pop3/serv_pop3.c b/citadel/modules/pop3/serv_pop3.c index 6aaa628a4..dcdbb8ec6 100644 --- a/citadel/modules/pop3/serv_pop3.c +++ b/citadel/modules/pop3/serv_pop3.c @@ -85,7 +85,7 @@ void pop3_cleanup_function(void) { void pop3_greeting(void) { strcpy(CC->cs_clientname, "POP3 session"); CC->internal_pgm = 1; - POP3 = malloc(sizeof(struct citpop3)); + CC->session_specific_data = malloc(sizeof(struct citpop3)); memset(POP3, 0, sizeof(struct citpop3)); cprintf("+OK Citadel POP3 server %s\r\n", diff --git a/citadel/modules/pop3/serv_pop3.h b/citadel/modules/pop3/serv_pop3.h index 8c73f689d..c57520f5a 100644 --- a/citadel/modules/pop3/serv_pop3.h +++ b/citadel/modules/pop3/serv_pop3.h @@ -20,7 +20,7 @@ struct citpop3 { /* Information about the current session */ * incremented by one. */ -#define POP3 CC->POP3 +#define POP3 ((struct citpop3 *)CC->session_specific_data) void pop3_cleanup_function(void); void pop3_greeting(void); diff --git a/citadel/modules/smtp/serv_smtp.c b/citadel/modules/smtp/serv_smtp.c index b444ab4fe..77b2618ea 100644 --- a/citadel/modules/smtp/serv_smtp.c +++ b/citadel/modules/smtp/serv_smtp.c @@ -105,7 +105,7 @@ enum { /* Command states for login authentication */ smtp_plain }; -#define SMTP CC->SMTP +#define SMTP ((struct citsmtp *)CC->session_specific_data) int run_queue_now = 0; /* Set to 1 to ignore SMTP send retry times */ @@ -127,7 +127,7 @@ void smtp_greeting(int is_msa) strcpy(CC->cs_clientname, "SMTP session"); CC->internal_pgm = 1; CC->cs_flags |= CS_STEALTH; - SMTP = malloc(sizeof(struct citsmtp)); + CC->session_specific_data = malloc(sizeof(struct citsmtp)); memset(SMTP, 0, sizeof(struct citsmtp)); SMTP->is_msa = is_msa; diff --git a/citadel/server.h b/citadel/server.h index 95c820ef8..982aa37d8 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -139,10 +139,7 @@ struct CitContext { int msg4_dont_decode; /* Dynamically allocated session data */ - struct citimap *IMAP; - struct citpop3 *POP3; - struct citsmtp *SMTP; - struct citmgsve *MGSVE; /**< Managesieve Session struct */ + char *session_specific_data; /* Used by individual protocol modules */ struct cit_ical *CIT_ICAL; /* calendaring data */ struct ma_info *ma; /* multipart/alternative data */ const char* ServiceName; /**< whats our actual purpose? */