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.
{
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;
#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
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;
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();
}
}
+/*
+ * 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";
{
#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 */
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",
* incremented by one.
*/
-#define POP3 CC->POP3
+#define POP3 ((struct citpop3 *)CC->session_specific_data)
void pop3_cleanup_function(void);
void pop3_greeting(void);
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 */
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;
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? */