From fa52a28f55b1496e80bd61deaf273139c09747b3 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 18 Oct 2006 17:05:29 +0000 Subject: [PATCH] New global variable: extern char *msiv_extensions This is a list of all Sieve extensions which are available, separated by spaces. --- citadel/serv_sieve.c | 50 +++++++++++++++++++++++++++++++------------- citadel/serv_sieve.h | 2 +- 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/citadel/serv_sieve.c b/citadel/serv_sieve.c index f016491d7..c39549cc9 100644 --- a/citadel/serv_sieve.c +++ b/citadel/serv_sieve.c @@ -50,6 +50,7 @@ #include "serv_sieve.h" struct RoomProcList *sieve_list = NULL; +char *msiv_extensions = NULL; /* @@ -901,13 +902,6 @@ void msiv_putscript(struct sdm_userdata *u, char *script_name, char *script_cont } -/* - * Return the list of supported Sieve extensions - */ -char *msiv_listextensions(void) { - return "FIXME - this is not done yet"; -} - /* * Citadel protocol to manage sieve scripts. @@ -1007,15 +1001,17 @@ void cmd_msiv(char *argbuf) { -/* - * We don't really care about dumping the entire credits to the log - * every time the server is initialized. The documentation will suffice - * for that purpose. We are making a call to sieve2_credits() in order - * to demonstrate that we have successfully linked in to libsieve. - */ -void log_the_sieve2_credits(void) { +void ctdl_sieve_init(void) { char *cred = NULL; + sieve2_context_t *sieve2_context = NULL; + int res; + /* + * We don't really care about dumping the entire credits to the log + * every time the server is initialized. The documentation will suffice + * for that purpose. We are making a call to sieve2_credits() in order + * to demonstrate that we have successfully linked in to libsieve. + */ cred = strdup(sieve2_credits()); if (cred == NULL) return; @@ -1025,13 +1021,37 @@ void log_the_sieve2_credits(void) { lprintf(CTDL_INFO, "%s\n",cred); free(cred); + + /* Briefly initialize a Sieve parser instance just so we can list the + * extensions that are available. + */ + res = sieve2_alloc(&sieve2_context); + if (res != SIEVE2_OK) { + lprintf(CTDL_CRIT, "sieve2_alloc() returned %d: %s\n", res, sieve2_errstr(res)); + return; + } + + res = sieve2_callbacks(sieve2_context, ctdl_sieve_callbacks); + if (res != SIEVE2_OK) { + lprintf(CTDL_CRIT, "sieve2_callbacks() returned %d: %s\n", res, sieve2_errstr(res)); + goto BAIL; + } + + msiv_extensions = strdup(sieve2_listextensions(sieve2_context)); + lprintf(CTDL_INFO, "Extensions: %s\n", msiv_extensions); + +BAIL: res = sieve2_free(&sieve2_context); + if (res != SIEVE2_OK) { + lprintf(CTDL_CRIT, "sieve2_free() returned %d: %s\n", res, sieve2_errstr(res)); + } + } char *serv_sieve_init(void) { - log_the_sieve2_credits(); + ctdl_sieve_init(); CtdlRegisterProtoHook(cmd_msiv, "MSIV", "Manage Sieve scripts"); return "$Id: serv_sieve.c 3850 2005-09-13 14:00:24Z ajc $"; } diff --git a/citadel/serv_sieve.h b/citadel/serv_sieve.h index c06eb09c6..f64df6509 100644 --- a/citadel/serv_sieve.h +++ b/citadel/serv_sieve.h @@ -51,6 +51,6 @@ int msiv_setactive(struct sdm_userdata *u, char *script_name); char *msiv_getscript(struct sdm_userdata *u, char *script_name); int msiv_deletescript(struct sdm_userdata *u, char *script_name); void msiv_putscript(struct sdm_userdata *u, char *script_name, char *script_content); -char *msiv_listextensions(void); +extern char *msiv_extensions; #endif /* HAVE_LIBSIEVE */ -- 2.39.2