]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vandelay.c
* Merged in code from the TRANSACTIONS branch for testing.
[citadel.git] / citadel / serv_vandelay.c
index f2c9e5c779307e7d34fe84f3c69d06c75725c96a..d1cbd2db857f3f60b8e31e31c8f8e5168517abd5 100644 (file)
@@ -35,8 +35,8 @@
 
 #define END_OF_MESSAGE "---eom---dbd---"
 
-char artv_tempfilename1[256];
-char artv_tempfilename2[256];
+char artv_tempfilename1[PATH_MAX];
+char artv_tempfilename2[PATH_MAX];
 FILE *artv_global_message_list;
 
 void artv_export_users_backend(struct usersupp *usbuf, void *data) {
@@ -63,7 +63,7 @@ void artv_export_users(void) {
 }
 
 
-void artv_export_room_msg(long msgnum) {
+void artv_export_room_msg(long msgnum, void *userdata) {
        cprintf("%ld\n", msgnum);
        fprintf(artv_global_message_list, "%ld\n", msgnum);
 }
@@ -91,7 +91,7 @@ void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
         * one per line terminated by a 0.
         */
        CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, NULL,
-               artv_export_room_msg);
+               artv_export_room_msg, NULL);
        cprintf("0\n");
 
 }
@@ -99,7 +99,7 @@ void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
 
 
 void artv_export_rooms(void) {
-       char cmd[256];
+       char cmd[SIZ];
        artv_global_message_list = fopen(artv_tempfilename1, "w");
        ForEachRoom(artv_export_rooms_backend, NULL);
        fclose(artv_global_message_list);
@@ -144,6 +144,7 @@ void artv_export_visits(void) {
        struct visit vbuf;
        struct cdbdata *cdbv;
 
+       cdb_begin_transaction();
        cdb_rewind(CDB_VISIT);
 
        while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
@@ -160,6 +161,7 @@ void artv_export_visits(void) {
                cprintf("%ld\n", vbuf.v_lastseen);
                cprintf("%u\n", vbuf.v_flags);
        }
+       cdb_end_transaction();
 }
 
 
@@ -168,8 +170,8 @@ void artv_export_message(long msgnum) {
        struct CtdlMessage *msg;
        struct ser_ret smr;
        FILE *fp;
-       char buf[256];
-       char tempfile[256];
+       char buf[SIZ];
+       char tempfile[SIZ];
 
        msg = CtdlFetchMessage(msgnum);
        if (msg == NULL) return;        /* fail silently */
@@ -206,7 +208,7 @@ void artv_export_message(long msgnum) {
 
 
 void artv_export_messages(void) {
-       char buf[256];
+       char buf[SIZ];
        long msgnum;
        int count = 0;
 
@@ -227,7 +229,9 @@ void artv_export_messages(void) {
 
 
 void artv_do_export(void) {
-       cprintf("%d Yikes.\n", LISTING_FOLLOWS);
+       cprintf("%d Exporting all Citadel databases.\n", LISTING_FOLLOWS);
+
+       cprintf("version\n%d\n", REV_LEVEL);
 
        /* export the config file */
        cprintf("config\n");
@@ -287,7 +291,7 @@ void artv_do_export(void) {
 
 
 void artv_import_config(void) {
-       char buf[256];
+       char buf[SIZ];
 
        lprintf(9, "Importing config file\n");
        client_gets(config.c_nodename);
@@ -313,6 +317,7 @@ void artv_import_config(void) {
        client_gets(buf);       config.c_maxsessions = atoi(buf);
        client_gets(config.c_net_password);
        client_gets(buf);       config.c_port_number = atoi(buf);
+       client_gets(buf);       config.c_ipgm_secret = atoi(buf);
        client_gets(buf);       config.c_ep.expire_mode = atoi(buf);
        client_gets(buf);       config.c_ep.expire_value = atoi(buf);
        client_gets(buf);       config.c_userpurge = atoi(buf);
@@ -332,7 +337,7 @@ void artv_import_config(void) {
 
 
 void artv_import_control(void) {
-       char buf[256];
+       char buf[SIZ];
 
        lprintf(9, "Importing control file\n");
        client_gets(buf);       CitControl.MMhighest = atol(buf);
@@ -346,7 +351,7 @@ void artv_import_control(void) {
 
 
 void artv_import_user(void) {
-       char buf[256];
+       char buf[SIZ];
        struct usersupp usbuf;
 
        client_gets(buf);       usbuf.version = atoi(buf);
@@ -368,7 +373,7 @@ void artv_import_user(void) {
 
 
 void artv_import_room(void) {
-       char buf[256];
+       char buf[SIZ];
        struct quickroom qrbuf;
        long msgnum;
        int msgcount = 0;
@@ -403,7 +408,7 @@ void artv_import_room(void) {
 void artv_import_floor(void) {
         struct floor flbuf;
         int i;
-       char buf[256];
+       char buf[SIZ];
 
        client_gets(buf);               i = atoi(buf);
        client_gets(buf);               flbuf.f_flags = atoi(buf);
@@ -420,7 +425,7 @@ void artv_import_floor(void) {
  */
 void artv_import_visit(void) {
        struct visit vbuf;
-       char buf[256];
+       char buf[SIZ];
 
        client_gets(buf);       vbuf.v_roomnum = atol(buf);
        client_gets(buf);       vbuf.v_roomgen = atol(buf);
@@ -439,8 +444,8 @@ void artv_import_message(void) {
        long msgnum;
        int msglen;
        FILE *fp;
-       char buf[256];
-       char tempfile[256];
+       char buf[SIZ];
+       char tempfile[SIZ];
        char *mbuf;
 
        memset(&smi, 0, sizeof(struct SuppMsgInfo));
@@ -450,6 +455,7 @@ void artv_import_message(void) {
        client_gets(smi.smi_content_type);
        client_gets(buf);       smi.smi_mod = atoi(buf);
 
+       lprintf(7, "message #%ld\n", msgnum);
 
        /* decode base64 message text */
        strcpy(tempfile, tmpnam(NULL));
@@ -458,8 +464,12 @@ void artv_import_message(void) {
        while (client_gets(buf), strcasecmp(buf, END_OF_MESSAGE)) {
                fprintf(fp, "%s\n", buf);
        }
+       fclose(fp);
+       fp = fopen(tempfile, "rb");
+       fseek(fp, 0L, SEEK_END);
        msglen = ftell(fp);
        fclose(fp);
+       lprintf(9, "msglen = %ld\n", msglen);
 
        mbuf = mallok(msglen);
        fp = fopen(tempfile, "rb");
@@ -481,23 +491,33 @@ void artv_import_message(void) {
 
 
 void artv_do_import(void) {
-       char buf[256];
+       char buf[SIZ];
+       char s_version[SIZ];
+       int version;
 
        cprintf("%d sock it to me\n", SEND_LISTING);
        while (client_gets(buf), strcmp(buf, "000")) {
 
                lprintf(9, "import keyword: <%s>\n", buf);
 
-               if (!strcasecmp(buf, "config")) artv_import_config();
+               if (!strcasecmp(buf, "version")) {
+                       client_gets(s_version);
+                       version = atoi(s_version);
+                       if ((version < REV_MIN) || (version > REV_LEVEL)) {
+                               lprintf(7, "Version mismatch - aborting\n");
+                               break;
+                       }
+               }
+               else if (!strcasecmp(buf, "config")) artv_import_config();
                else if (!strcasecmp(buf, "control")) artv_import_control();
                else if (!strcasecmp(buf, "user")) artv_import_user();
                else if (!strcasecmp(buf, "room")) artv_import_room();
                else if (!strcasecmp(buf, "floor")) artv_import_floor();
                else if (!strcasecmp(buf, "visit")) artv_import_visit();
                else if (!strcasecmp(buf, "message")) artv_import_message();
-               else goto artv_flush_import;
+               else break;
+
        }
-artv_flush_import:
        lprintf(7, "Invalid keyword <%s>.  Flushing input.\n", buf);
        while (client_gets(buf), strcmp(buf, "000"))  ;;
 }
@@ -505,7 +525,7 @@ artv_flush_import:
 
 
 void cmd_artv(char *cmdbuf) {
-       char cmd[256];
+       char cmd[SIZ];
        static int is_running = 0;
 
        if (CtdlAccessCheck(ac_aide)) return;   /* FIXME should be intpgm */