HUGE PATCH. This moves all of mime_parser.c and all
[citadel.git] / citadel / modules / vandelay / serv_vandelay.c
index a77eb49208288ee52fc6af46eb4cbe3c5bad6e5b..576089f3ccd9492fb2bacd760cf80e3505411813 100644 (file)
@@ -30,6 +30,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -37,7 +38,6 @@
 #include "config.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "user_ops.h"
 #include "room_ops.h"
 #include "control.h"
@@ -77,17 +77,34 @@ void artv_export_users_backend(struct ctdluser *buf, void *data) {
        cprintf("%d\n", buf->USscreenheight);
 }
 
+void artv_dump_users_backend(struct ctdluser *buf, void *data) {
+       cprintf("user\n");
+
+#include "artv_dump.h"
+#include "dtds/user-defs.h"
+#include "undef_data.h"
+}
+
 
 void artv_export_users(void) {
        ForEachUser(artv_export_users_backend, NULL);
 }
 
+void artv_dump_users(void) {
+       ForEachUser(artv_dump_users_backend, NULL);
+}
+
 
 void artv_export_room_msg(long msgnum, void *userdata) {
        cprintf("%ld\n", msgnum);
        fprintf(artv_global_message_list, "%ld\n", msgnum);
 }
 
+void artv_dump_room_msg(long msgnum, void *userdata) {
+       cprintf(" msgnum: %ld\n", msgnum);
+       fprintf(artv_global_message_list, "%ld\n", msgnum);
+}//// TODO
+
 
 void artv_export_rooms_backend(struct ctdlroom *buf, void *data) {
        cprintf("room\n");
@@ -128,6 +145,28 @@ void artv_export_rooms_backend(struct ctdlroom *buf, void *data) {
 
 }
 
+void artv_dump_rooms_backend(struct ctdlroom *buf, void *data) {
+       cprintf("room\n");
+
+#include "artv_dump.h"
+#include "dtds/room-defs.h"
+#include "undef_data.h"
+
+       getroom(&CC->room, buf->QRname);
+       /* format of message list export is all message numbers output
+        * one per line terminated by a 0.
+        */
+//*/
+       getroom(&CC->room, buf->QRname);
+       /* format of message list export is all message numbers output
+        * one per line terminated by a 0.
+        */
+       CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
+               artv_dump_room_msg, NULL);
+       cprintf("\n\n");
+
+}
+
 
 
 void artv_export_rooms(void) {
@@ -150,6 +189,26 @@ void artv_export_rooms(void) {
        system(cmd);
 }
 
+void artv_dump_rooms(void) {
+       char cmd[SIZ];
+       artv_global_message_list = fopen(artv_tempfilename1, "w");
+       if (artv_global_message_list != NULL) {
+               ForEachRoom(artv_dump_rooms_backend, NULL);
+               fclose(artv_global_message_list);
+       }
+
+       /*
+        * Process the 'global' message list.  (Sort it and remove dups.
+        * Dups are ok because a message may be in more than one room, but
+        * this will be handled by exporting the reference count, not by
+        * exporting the message multiple times.)
+        */
+       snprintf(cmd, sizeof cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2);
+       system(cmd);
+       snprintf(cmd, sizeof cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1);
+       system(cmd);
+}
+
 
 void artv_export_floors(void) {
         struct floor qfbuf, *buf;
@@ -174,6 +233,22 @@ void artv_export_floors(void) {
        }
 }
 
+void artv_dump_floors(void) {
+        struct floor qfbuf, *buf;
+        int i;
+
+        for (i=0; i < MAXFLOORS; ++i) {
+               cprintf("floor\n");
+               cprintf("%d\n", i);
+                getfloor(&qfbuf, i);
+               buf = &qfbuf;
+
+#include "artv_serialize.h"
+#include "dtds/floor-defs.h"
+#include "undef_data.h"
+       }
+}
+
 
 
 
@@ -212,6 +287,40 @@ void artv_export_visits(void) {
        }
 }
 
+/* 
+ *  Traverse the visits file...
+ */
+void artv_dump_visits(void) {
+       struct visit vbuf;
+       struct cdbdata *cdbv;
+
+       cdb_rewind(CDB_VISIT);
+
+       while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
+               memset(&vbuf, 0, sizeof(struct visit));
+               memcpy(&vbuf, cdbv->ptr,
+                      ((cdbv->len > sizeof(struct visit)) ?
+                       sizeof(struct visit) : cdbv->len));
+               cdb_free(cdbv);
+
+               cprintf("---visit---\n");
+               cprintf(" Room-Num: %ld\n", vbuf.v_roomnum);
+               cprintf(" Room-Gen%ld\n", vbuf.v_roomgen);
+               cprintf(" User-Num%ld\n", vbuf.v_usernum);
+
+               if (!IsEmptyStr(vbuf.v_seen)) {
+                       cprintf(" Seen: %s\n", vbuf.v_seen);
+               }
+               else {
+                       cprintf(" LastSeen: %ld\n", vbuf.v_lastseen);
+               }
+
+               cprintf(" Answered: %s\n", vbuf.v_answered);
+               cprintf(" Flags: %u\n", vbuf.v_flags);
+               cprintf(" View: %d\n", vbuf.v_view);
+       }
+}
+
 
 void artv_export_message(long msgnum) {
        struct MetaData smi;
@@ -254,18 +363,39 @@ void artv_export_message(long msgnum) {
        cprintf("%s\n", END_OF_MESSAGE);
 }
 
+void artv_dump_message(long msgnum) {
+       struct MetaData smi;
+       struct CtdlMessage *msg;
+
+       msg = CtdlFetchMessage(msgnum, 1);
+       if (msg == NULL) return;        /* fail silently */
+
+       cprintf("message\n");
+       GetMetaData(&smi, msgnum);
+       cprintf(" MessageNum: %ld\n", msgnum);
+       cprintf(" MetaRefcount: %d\n", smi.meta_refcount);
+       cprintf(" MetaContentType: %s\n", smi.meta_content_type);
+
+       dump_message(msg, 80);
+       CtdlFreeMessage(msg);
+
+       cprintf("%s\n", END_OF_MESSAGE);
+}
+
 
 
 void artv_export_messages(void) {
        char buf[SIZ];
        long msgnum;
        int count = 0;
+       t_context *Ctx;
 
+       Ctx = CC;
        artv_global_message_list = fopen(artv_tempfilename1, "r");
        if (artv_global_message_list != NULL) {
                lprintf(CTDL_INFO, "Opened %s\n", artv_tempfilename1);
-               while (fgets(buf, sizeof(buf),
-                     artv_global_message_list) != NULL) {
+               while ((Ctx->kill_me != 1) && 
+                      (fgets(buf, sizeof(buf), artv_global_message_list) != NULL)) {
                        msgnum = atol(buf);
                        if (msgnum > 0L) {
                                artv_export_message(msgnum);
@@ -274,7 +404,36 @@ void artv_export_messages(void) {
                }
                fclose(artv_global_message_list);
        }
-       lprintf(CTDL_INFO, "Exported %d messages.\n", count);
+       if (Ctx->kill_me != 1)
+               lprintf(CTDL_INFO, "Exported %d messages.\n", count);
+       else
+               lprintf(CTDL_ERR, "Export aborted due to client disconnect! \n");
+}
+
+void artv_dump_messages(void) {
+       char buf[SIZ];
+       long msgnum;
+       int count = 0;
+       t_context *Ctx;
+
+       Ctx = CC;
+       artv_global_message_list = fopen(artv_tempfilename1, "r");
+       if (artv_global_message_list != NULL) {
+               lprintf(CTDL_INFO, "Opened %s\n", artv_tempfilename1);
+               while ((Ctx->kill_me != 1) && 
+                      (fgets(buf, sizeof(buf), artv_global_message_list) != NULL)) {
+                       msgnum = atol(buf);
+                       if (msgnum > 0L) {
+                               artv_dump_message(msgnum);
+                               ++count;
+                       }
+               }
+               fclose(artv_global_message_list);
+       }
+       if (Ctx->kill_me != 1)
+               lprintf(CTDL_INFO, "Exported %d messages.\n", count);
+       else
+               lprintf(CTDL_ERR, "Export aborted due to client disconnect! \n");
 }
 
 
@@ -283,83 +442,20 @@ void artv_export_messages(void) {
 void artv_do_export(void) {
        struct config *buf;
        buf = &config;
+       t_context *Ctx;
+
+       Ctx = CC;
        cprintf("%d Exporting all Citadel databases.\n", LISTING_FOLLOWS);
 
        cprintf("version\n%d\n", REV_LEVEL);
 
-       /* export the config file */
+       /* export the config file (this is done using x-macros) */
        cprintf("config\n");
 
 #include "artv_serialize.h"
 #include "dtds/config-defs.h"
 #include "undef_data.h"
 
-/*
-       cprintf("%s\n", config.c_nodename);
-       cprintf("%s\n", config.c_fqdn);
-       cprintf("%s\n", config.c_humannode);
-       cprintf("%s\n", config.c_phonenum);
-       cprintf("%ld\n", (long)config.c_ctdluid);
-       cprintf("%d\n", config.c_creataide);
-       cprintf("%d\n", config.c_sleeping);
-       cprintf("%d\n", config.c_initax);
-       cprintf("%d\n", config.c_regiscall);
-       cprintf("%d\n", config.c_twitdetect);
-       cprintf("%s\n", config.c_twitroom);
-       cprintf("%s\n", config.c_moreprompt);
-       cprintf("%d\n", config.c_restrict);
-       cprintf("%s\n", config.c_site_location);
-       cprintf("%s\n", config.c_sysadm);
-       cprintf("%d\n", config.c_setup_level);
-       cprintf("%d\n", config.c_maxsessions);
-       cprintf("%d\n", config.c_port_number);
-       cprintf("%d\n", config.c_ep.expire_mode);
-       cprintf("%d\n", config.c_ep.expire_value);
-       cprintf("%d\n", config.c_userpurge);
-       cprintf("%d\n", config.c_roompurge);
-       cprintf("%s\n", config.c_logpages);
-       cprintf("%d\n", config.c_createax);
-       cprintf("%ld\n", config.c_maxmsglen);
-       cprintf("%d\n", config.c_min_workers);
-       cprintf("%d\n", config.c_max_workers);
-       cprintf("%d\n", config.c_pop3_port);
-       cprintf("%d\n", config.c_smtp_port);
-       cprintf("%d\n", config.c_purge_hour);
-       cprintf("%d\n", config.c_mbxep.expire_mode);
-       cprintf("%d\n", config.c_mbxep.expire_value);
-       cprintf("%s\n", config.c_ldap_host);
-       cprintf("%d\n", config.c_ldap_port);
-       cprintf("%s\n", config.c_ldap_base_dn);
-       cprintf("%s\n", config.c_ldap_bind_dn);
-       cprintf("%s\n", config.c_ldap_bind_pw);
-       cprintf("%s\n", config.c_ip_addr);
-       cprintf("%d\n", config.c_msa_port);
-       cprintf("%d\n", config.c_imaps_port);
-       cprintf("%d\n", config.c_pop3s_port);
-       cprintf("%d\n", config.c_smtps_port);
-       cprintf("%d\n", config.c_rfc822_strict_from);
-       cprintf("%d\n", config.c_aide_zap);
-       cprintf("%d\n", config.c_imap_port);
-       cprintf("%ld\n", config.c_net_freq);
-       cprintf("%d\n", config.c_disable_newu);
-       cprintf("%s\n", config.c_baseroom);
-       cprintf("%s\n", config.c_aideroom);
-       cprintf("%d\n", config.c_auto_cull);
-       cprintf("%d\n", config.c_instant_expunge);
-       cprintf("%d\n", config.c_allow_spoofing);
-       cprintf("%d\n", config.c_journal_email);
-       cprintf("%d\n", config.c_journal_pubmsgs);
-       cprintf("%s\n", config.c_journal_dest);
-       cprintf("%s\n", config.c_default_cal_zone);
-       cprintf("%d\n", config.c_pftcpdict_port);
-       cprintf("%d\n", config.c_managesieve_port);
-       cprintf("%d\n", config.c_auth_mode);
-       cprintf("%s\n", config.c_funambol_host);
-       cprintf("%d\n", config.c_funambol_port);
-       cprintf("%s\n", config.c_funambol_source);
-       cprintf("%s\n", config.c_funambol_auth);
-       cprintf("%d\n", config.c_rbl_at_greeting);
-*/
        /* Export the control file */
        get_control();
        cprintf("control\n");
@@ -368,12 +464,55 @@ void artv_do_export(void) {
        cprintf("%ld\n", CitControl.MMnextuser);
        cprintf("%ld\n", CitControl.MMnextroom);
        cprintf("%d\n", CitControl.version);
+       if (Ctx->kill_me != 1)
+               artv_export_users();
+       if (Ctx->kill_me != 1)
+               artv_export_rooms();
+       if (Ctx->kill_me != 1)
+               artv_export_floors();
+       if (Ctx->kill_me != 1)
+               artv_export_visits();
+       if (Ctx->kill_me != 1)
+               artv_export_messages();
 
-       artv_export_users();
-       artv_export_rooms();
-       artv_export_floors();
-       artv_export_visits();
-       artv_export_messages();
+       cprintf("000\n");
+}
+
+void artv_do_dump(void) {
+       struct config *buf;
+       buf = &config;
+       t_context *Ctx;
+
+       Ctx = CC;
+       cprintf("%d dumping Citadel structures.\n", LISTING_FOLLOWS);
+
+       cprintf("version\n%d\n", REV_LEVEL);
+
+       /* export the config file (this is done using x-macros) */
+       cprintf("config\n");
+
+#include "artv_dump.h"
+#include "dtds/config-defs.h"
+#include "undef_data.h"
+
+       /* Export the control file */
+       get_control();
+       cprintf("control\n");
+       cprintf("%ld\n", CitControl.MMhighest);
+       cprintf("%u\n", CitControl.MMflags);
+       cprintf("%ld\n", CitControl.MMnextuser);
+       cprintf("%ld\n", CitControl.MMnextroom);
+       cprintf("%d\n", CitControl.version);
+       if (Ctx->kill_me != 1)
+               artv_dump_users();
+       if (Ctx->kill_me != 1)
+               artv_dump_rooms();
+       if (Ctx->kill_me != 1)
+               artv_dump_floors();
+       if (Ctx->kill_me != 1)
+               artv_dump_visits();
+       if (Ctx->kill_me != 1)
+               artv_dump_messages();
 
        cprintf("000\n");
 }
@@ -391,72 +530,6 @@ void artv_import_config(void) {
 #include "dtds/config-defs.h"
 #include "undef_data.h"
 
-/*
-       client_getln(config.c_nodename, sizeof config.c_nodename);
-       client_getln(config.c_fqdn, sizeof config.c_fqdn);
-       client_getln(config.c_humannode, sizeof config.c_humannode);
-       client_getln(config.c_phonenum, sizeof config.c_phonenum);
-       client_getln(buf, sizeof buf);  config.c_ctdluid = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_creataide = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_sleeping = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_initax = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_regiscall = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_twitdetect = atoi(buf);
-       client_getln(config.c_twitroom, sizeof config.c_twitroom);
-       client_getln(config.c_moreprompt, sizeof config.c_moreprompt);
-       client_getln(buf, sizeof buf);  config.c_restrict = atoi(buf);
-       client_getln(config.c_site_location, sizeof config.c_site_location);
-       client_getln(config.c_sysadm, sizeof config.c_sysadm);
-       client_getln(buf, sizeof buf);  config.c_setup_level = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_maxsessions = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_port_number = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_ep.expire_mode = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_ep.expire_value = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_userpurge = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_roompurge = atoi(buf);
-       client_getln(config.c_logpages, sizeof config.c_logpages);
-       client_getln(buf, sizeof buf);  config.c_createax = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_maxmsglen = atol(buf);
-       client_getln(buf, sizeof buf);  config.c_min_workers = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_max_workers = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_pop3_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_smtp_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_purge_hour = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_mbxep.expire_mode = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_mbxep.expire_value = atoi(buf);
-       client_getln(config.c_ldap_host, sizeof config.c_ldap_host);
-       client_getln(buf, sizeof buf);  config.c_ldap_port = atoi(buf);
-       client_getln(config.c_ldap_base_dn, sizeof config.c_ldap_base_dn);
-       client_getln(config.c_ldap_bind_dn, sizeof config.c_ldap_bind_dn);
-       client_getln(config.c_ldap_bind_pw, sizeof config.c_ldap_bind_pw);
-       client_getln(config.c_ip_addr, sizeof config.c_ip_addr);
-       client_getln(buf, sizeof buf);  config.c_msa_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_imaps_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_pop3s_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_smtps_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_rfc822_strict_from = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_aide_zap = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_imap_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_net_freq = atol(buf);
-       client_getln(buf, sizeof buf);  config.c_disable_newu = atoi(buf);
-       client_getln(config.c_baseroom, sizeof config.c_baseroom);
-       client_getln(config.c_aideroom, sizeof config.c_aideroom);
-       client_getln(buf, sizeof buf);  config.c_auto_cull = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_instant_expunge = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_allow_spoofing = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_journal_email = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_journal_pubmsgs = atoi(buf);
-       client_getln(config.c_journal_dest, sizeof config.c_journal_dest);
-       client_getln(config.c_default_cal_zone, sizeof config.c_default_cal_zone);
-       client_getln(buf, sizeof buf);  config.c_pftcpdict_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_managesieve_port = atoi(buf);
-       client_getln(buf, sizeof buf);  config.c_auth_mode = atoi(buf);
-       client_getln(config.c_funambol_host, sizeof config.c_funambol_host);
-       client_getln(buf, sizeof buf); config.c_funambol_port = atoi(buf);
-       client_getln(config.c_funambol_source, sizeof config.c_funambol_source);
-       client_getln(config.c_funambol_auth, sizeof config.c_funambol_auth);
-       client_getln(buf, sizeof buf);  config.c_rbl_at_greeting = atoi(buf);
-*/
        config.c_enable_fulltext = 0;   /* always disable */
        put_config();
        lprintf(CTDL_INFO, "Imported config file\n");
@@ -587,7 +660,7 @@ void artv_import_visit(void) {
 
        client_getln(buf, sizeof buf);
        vbuf.v_lastseen = atol(buf);
-       for (i=0; !IsEmptyStr(&buf[i]); ++i) if (!isdigit(buf[i])) is_textual_seen = 1;
+       for (i=0; buf[i]; ++i) if (!isdigit(buf[i])) is_textual_seen = 1;
        if (is_textual_seen)    strcpy(vbuf.v_seen, buf);
 
        client_getln(vbuf.v_answered, sizeof vbuf.v_answered);
@@ -670,7 +743,7 @@ void artv_do_import(void) {
                        iterations = 0;
                }
                else {
-                       cprintf(".");
+                       cprintf(".");
                        if (iterations % 64 == 0)
                                cprintf("\n");
                        
@@ -719,6 +792,7 @@ void cmd_artv(char *cmdbuf) {
        extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
        if (!strcasecmp(cmd, "export")) artv_do_export();
        else if (!strcasecmp(cmd, "import")) artv_do_import();
+       else if (!strcasecmp(cmd, "dump")) artv_do_dump();
        else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
 
        unlink(artv_tempfilename1);