]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_upgrade.c
* Added BMBX to fix a problem
[citadel.git] / citadel / serv_upgrade.c
index cf24533404fe44e17aebb1ef27bb0eca157a1a9e..1a6323d4f6344dc3d25285d25417b5607c5ab01f 100644 (file)
@@ -1,4 +1,10 @@
-/* $Id$ */
+/*
+ * $Id$
+ *
+ * Transparently handle the upgrading of server data formats.
+ *
+ */
+
 #include "sysdep.h"
 #include <stdlib.h>
 #include <unistd.h>
 #include <pwd.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <sys/time.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
 #include <sys/wait.h>
 #include <string.h>
 #include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
 #include "citadel.h"
 #include "server.h"
-#include <syslog.h>
-#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
 #include "control.h"
 #include "dynloader.h"
 #include "database.h"
+#include "room_ops.h"
 #include "user_ops.h"
 #include "msgbase.h"
+#include "tools.h"
 #include "serv_upgrade.h"
 
 void do_pre555_usersupp_upgrade(void) {
@@ -60,6 +74,7 @@ void do_pre555_usersupp_upgrade(void) {
        /* ...and overwrite the records with new format records */
        rewind(fp);
        while (fread(&usbuf, sizeof(struct pre555usersupp), 1, fp) > 0) {
+           if (strlen(usbuf.fullname) > 0) {
                lprintf(9, "Upgrading <%s>\n", usbuf.fullname);
                memset(&newus, 0, sizeof(struct usersupp));
 
@@ -99,10 +114,10 @@ void do_pre555_usersupp_upgrade(void) {
                fwrite(vcard, strlen(vcard)+1, 1, tp);
                fclose(tp);
 
-               CtdlWriteObject(CONFIGROOM, "text/x-vcard",
-                       tempfilename, &newus, 0, 1);    
+               CtdlWriteObject(USERCONFIGROOM, "text/x-vcard",
+                       tempfilename, &newus, 0, 1, CM_SKIP_HOOKS);
                unlink(tempfilename);
-
+           }
        }
 
        fclose(fp);     /* this file deletes automatically */
@@ -122,7 +137,7 @@ void check_server_upgrades(void) {
                (CitControl.version / 100),
                (CitControl.version % 100) );
 
-       if (CitControl.version < config.c_setup_level) {
+       if (CitControl.version < REV_LEVEL) {
                lprintf(5, "Server hosted updates need to be processed at "
                                "this time.  Please wait...\n");
        }
@@ -130,19 +145,103 @@ void check_server_upgrades(void) {
                return;
        }
 
-
        if (CitControl.version < 555) do_pre555_usersupp_upgrade();
 
-
-       CitControl.version = config.c_setup_level;
+       CitControl.version = REV_LEVEL;
        put_control();
 }
 
 
 
 
+
+
+
+
+
+
+
+/* 
+ * Back end processing function for cmd_bmbx
+ */
+void cmd_bmbx_backend(struct quickroom *qrbuf, void *data) {
+       static struct RoomProcList *rplist = NULL;
+       struct RoomProcList *ptr;
+       struct quickroom qr;
+
+       /* Lazy programming here.  Call this function as a ForEachRoom backend
+        * in order to queue up the room names, or call it with a null room
+        * to make it do the processing.
+        */
+       if (qrbuf != NULL) {
+               ptr = (struct RoomProcList *)
+                       mallok(sizeof (struct RoomProcList));
+               if (ptr == NULL) return;
+
+               safestrncpy(ptr->name, qrbuf->QRname, sizeof ptr->name);
+               ptr->next = rplist;
+               rplist = ptr;
+               return;
+       }
+
+       while (rplist != NULL) {
+
+               if (lgetroom(&qr, rplist->name) == 0) {
+                       lprintf(9, "Processing <%s>...\n", rplist->name);
+                       if ( (qr.QRflags & QR_MAILBOX) == 0) {
+                               lprintf(9, "  -- not a mailbox\n");
+                       }
+                       else {
+
+                               qr.QRgen = time(NULL);
+                               lprintf(9, "  -- bumped!\n");
+                       }
+                       lputroom(&qr);
+               }
+
+               ptr = rplist;
+               rplist = rplist->next;
+               phree(ptr);
+       }
+}
+
+/*
+ * quick fix command to bump mailbox generation numbers
+ */
+void cmd_bmbx(char *argbuf) {
+       int really_do_this  = 0;
+
+       if (CtdlAccessCheck(ac_internal)) return;
+       really_do_this = extract_int(argbuf, 0);
+
+       if (really_do_this != 1) {
+               cprintf("%d You didn't really want to do that.\n", OK);
+               return;
+       }
+
+       ForEachRoom(cmd_bmbx_backend, NULL);
+       cmd_bmbx_backend(NULL, NULL);
+
+       cprintf("%d Mailbox generation numbers bumped.\n", OK);
+       return;
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
 char *Dynamic_Module_Init(void)
 {
        check_server_upgrades();
+       CtdlRegisterProtoHook(cmd_bmbx, "BMBX", "Bump mailboxes");
        return "$Id$";
 }