Changed the Sieve API -- msiv_store() etc.
authorArt Cancro <ajc@citadel.org>
Tue, 31 Oct 2006 21:00:07 +0000 (21:00 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 31 Oct 2006 21:00:07 +0000 (21:00 +0000)
There is now a 'changes_made' parameter.  If set to nonzero, changes are saved
to disk; if set to zero, it just frees the data structure without writing
anything to disk.

citadel/serv_managesieve.c
citadel/serv_sieve.c
citadel/serv_sieve.h

index a6656c5b43193f0797828239e81ad2f31749b467..f93e20942d1d2c056d0e4888cfa0760401975c1c 100644 (file)
@@ -579,7 +579,7 @@ void managesieve_command_loop(void) {
        int length;
        int num_parms;
        struct sdm_userdata u;
-
+       int changes_made = 0;
 
        memset(&u, 0, sizeof(struct sdm_userdata));
 
@@ -622,20 +622,23 @@ void managesieve_command_loop(void) {
                }
                else if ((length>= 6) && (!strncasecmp(parms[0], "PUTSCRIPT", 9))){
                        cmd_mgsve_putscript(num_parms, parms, &u);
+                       changes_made = 1;
                }
                else if ((length>= 6) && (!strncasecmp(parms[0], "LISTSCRIPT", 10))){
                        cmd_mgsve_listscript(num_parms, parms,&u);
                }
                else if ((length>= 6) && (!strncasecmp(parms[0], "SETACTIVE", 9))){
                        cmd_mgsve_setactive(num_parms, parms,&u);
+                       changes_made = 1;
                }
                else if ((length>= 6) && (!strncasecmp(parms[0], "GETSCRIPT", 9))){
                        cmd_mgsve_getscript(num_parms, parms, &u);
                }
                else if ((length>= 6) && (!strncasecmp(parms[0], "DELETESCRIPT", 11))){
                        cmd_mgsve_deletescript(num_parms, parms, &u);
+                       changes_made = 1;
                }
-               msiv_store(&u);
+               msiv_store(&u, changes_made);
        }
        else {
                /// todo: log this.
index d5f667c19e81ca66f30bf3d3d5b25ce989326db3..109ed84c72396bdaa332c4f091a2869aafb0a89f 100644 (file)
@@ -676,8 +676,11 @@ void get_sieve_config_backend(long msgnum, void *userdata) {
 
 /* 
  * Write our citadel sieve config back to disk
+ * 
+ * (Set yes_write_to_disk to nonzero to make it actually write the config;
+ * otherwise it just frees the data structures.)
  */
-void rewrite_ctdl_sieve_config(struct sdm_userdata *u) {
+void rewrite_ctdl_sieve_config(struct sdm_userdata *u, int yes_write_to_disk) {
        char *text;
        struct sdm_script *sptr;
        struct sdm_vacation *vptr;
@@ -854,9 +857,7 @@ BAIL:
        }
 
        /* Rewrite the config if we have to */
-       if (u.lastproc > orig_lastproc) {
-               rewrite_ctdl_sieve_config(&u);
-       }
+       rewrite_ctdl_sieve_config(&u, (u.lastproc > orig_lastproc) ) ;
 }
 
 
@@ -914,8 +915,8 @@ void msiv_load(struct sdm_userdata *u) {
        }
 }
 
-void msiv_store(struct sdm_userdata *u) {
-       rewrite_ctdl_sieve_config(u);
+void msiv_store(struct sdm_userdata *u, int yes_write_to_disk) {
+       rewrite_ctdl_sieve_config(u, yes_write_to_disk);
 }
 
 
@@ -1060,6 +1061,7 @@ void cmd_msiv(char *argbuf) {
        char *script_content = NULL;
        struct sdm_script *s;
        int i;
+       int changes_made = 0;
 
        memset(&u, 0, sizeof(struct sdm_userdata));
 
@@ -1073,6 +1075,7 @@ void cmd_msiv(char *argbuf) {
                        cprintf("%d Transmit script now\n", SEND_LISTING);
                        script_content = CtdlReadMessageBody("000", config.c_maxmsglen, NULL, 0);
                        msiv_putscript(&u, script_name, script_content);
+                       changes_made = 1;
                }
                else {
                        cprintf("%d Invalid script name.\n", ERROR + ILLEGAL_VALUE);
@@ -1093,6 +1096,7 @@ void cmd_msiv(char *argbuf) {
                extract_token(script_name, argbuf, 1, '|', sizeof script_name);
                if (msiv_setactive(&u, script_name) == 0) {
                        cprintf("%d ok\n", CIT_OK);
+                       changes_made = 1;
                }
                else {
                        cprintf("%d Script '%s' does not exist.\n",
@@ -1119,6 +1123,7 @@ void cmd_msiv(char *argbuf) {
                i = msiv_deletescript(&u, script_name);
                if (i == 0) {
                        cprintf("%d ok\n", CIT_OK);
+                       changes_made = 1;
                }
                else if (i == 1) {
                        cprintf("%d Script '%s' does not exist.\n",
@@ -1141,7 +1146,7 @@ void cmd_msiv(char *argbuf) {
                cprintf("%d Invalid subcommand\n", ERROR + CMD_NOT_SUPPORTED);
        }
 
-       msiv_store(&u);
+       msiv_store(&u, changes_made);
 }
 
 
index 3213504f6159e121d3e679867806076f1b527dd1..168a8574f84f9081ab1975981cdb936c58bd8cf4 100644 (file)
@@ -62,7 +62,7 @@ void sieve_queue_room(struct ctdlroom *);
 void perform_sieve_processing(void);
 
 void msiv_load(struct sdm_userdata *u);
-void msiv_store(struct sdm_userdata *u);
+void msiv_store(struct sdm_userdata *u, int changes_made);
 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);