MSGS command can now do full text search on the room
[citadel.git] / citadel / serv_vandelay.c
index 469612eaf47379727d49ec8085104632f9027fa6..730eee13ce20f02dc82aa75d191360998da0748c 100644 (file)
 #include "citserver.h"
 #include "support.h"
 #include "config.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
 #include "database.h"
 #include "msgbase.h"
 #include "tools.h"
 #include "user_ops.h"
 #include "room_ops.h"
 #include "control.h"
+#include "euidindex.h"
 
 #define END_OF_MESSAGE "---eom---dbd---"
 
@@ -50,7 +51,7 @@ 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) {
+void artv_export_users_backend(struct ctdluser *usbuf, void *data) {
        cprintf("user\n");
        cprintf("%d\n", usbuf->version);
        cprintf("%ld\n", (long)usbuf->uid);
@@ -65,7 +66,6 @@ void artv_export_users_backend(struct usersupp *usbuf, void *data) {
        cprintf("%s\n", usbuf->fullname);
        cprintf("%d\n", usbuf->USscreenwidth);
        cprintf("%d\n", usbuf->USscreenheight);
-       cprintf("%d\n", usbuf->moderation_filter);
 }
 
 
@@ -80,7 +80,7 @@ void artv_export_room_msg(long msgnum, void *userdata) {
 }
 
 
-void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
+void artv_export_rooms_backend(struct ctdlroom *qrbuf, void *data) {
        cprintf("room\n");
        cprintf("%s\n", qrbuf->QRname);
        cprintf("%s\n", qrbuf->QRpasswd);
@@ -97,12 +97,13 @@ void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
        cprintf("%ld\n", qrbuf->QRnumber);
        cprintf("%d\n", qrbuf->QRorder);
        cprintf("%u\n", qrbuf->QRflags2);
+       cprintf("%d\n", qrbuf->QRdefaultview);
 
-       getroom(&CC->quickroom, qrbuf->QRname);
+       getroom(&CC->room, qrbuf->QRname);
        /* format of message list export is all message numbers output
         * one per line terminated by a 0.
         */
-       CtdlForEachMessage(MSGS_ALL, 0L, (-127), NULL, NULL,
+       CtdlForEachMessage(MSGS_ALL, 0L, NULL, NULL, NULL,
                artv_export_room_msg, NULL);
        cprintf("0\n");
 
@@ -113,8 +114,10 @@ void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
 void artv_export_rooms(void) {
        char cmd[SIZ];
        artv_global_message_list = fopen(artv_tempfilename1, "w");
-       ForEachRoom(artv_export_rooms_backend, NULL);
-       fclose(artv_global_message_list);
+       if (artv_global_message_list != NULL) {
+               ForEachRoom(artv_export_rooms_backend, NULL);
+               fclose(artv_global_message_list);
+       }
 
        /*
         * Process the 'global' message list.  (Sort it and remove dups.
@@ -122,9 +125,9 @@ void artv_export_rooms(void) {
         * this will be handled by exporting the reference count, not by
         * exporting the message multiple times.)
         */
-       sprintf(cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2);
+       snprintf(cmd, sizeof cmd, "sort <%s >%s", artv_tempfilename1, artv_tempfilename2);
        system(cmd);
-       sprintf(cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1);
+       snprintf(cmd, sizeof cmd, "uniq <%s >%s", artv_tempfilename2, artv_tempfilename1);
        system(cmd);
 }
 
@@ -177,7 +180,9 @@ void artv_export_visits(void) {
                        cprintf("%ld\n", vbuf.v_lastseen);
                }
 
+               cprintf("%s\n", vbuf.v_answered);
                cprintf("%u\n", vbuf.v_flags);
+               cprintf("%d\n", vbuf.v_view);
        }
 }
 
@@ -188,9 +193,9 @@ void artv_export_message(long msgnum) {
        struct ser_ret smr;
        FILE *fp;
        char buf[SIZ];
-       char tempfile[SIZ];
+       char tempfile[PATH_MAX];
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;        /* fail silently */
 
        cprintf("message\n");
@@ -198,27 +203,28 @@ void artv_export_message(long msgnum) {
        cprintf("%ld\n", msgnum);
        cprintf("%d\n", smi.meta_refcount);
        cprintf("%s\n", smi.meta_content_type);
-       cprintf("%d\n", smi.meta_mod);
 
        serialize_message(&smr, msg);
        CtdlFreeMessage(msg);
 
        /* write it in base64 */
-       strcpy(tempfile, tmpnam(NULL));
-       sprintf(buf, "./base64 -e >%s", tempfile);
+       CtdlMakeTempFileName(tempfile, sizeof tempfile);
+       snprintf(buf, sizeof buf, "./base64 -e >%s", tempfile);
        fp = popen(buf, "w");
        fwrite(smr.ser, smr.len, 1, fp);
        pclose(fp);
 
-       phree(smr.ser);
+       free(smr.ser);
 
        fp = fopen(tempfile, "r");
        unlink(tempfile);
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               buf[strlen(buf)-1] = 0;
-               cprintf("%s\n", buf);
+       if (fp != NULL) {
+               while (fgets(buf, sizeof(buf), fp) != NULL) {
+                       buf[strlen(buf)-1] = 0;
+                       cprintf("%s\n", buf);
+               }
+               fclose(fp);
        }
-       fclose(fp);
        cprintf("%s\n", END_OF_MESSAGE);
 }
 
@@ -230,16 +236,19 @@ void artv_export_messages(void) {
        int count = 0;
 
        artv_global_message_list = fopen(artv_tempfilename1, "r");
-       lprintf(7, "Opened %s\n", artv_tempfilename1);
-       while (fgets(buf, sizeof(buf), artv_global_message_list) != NULL) {
-               msgnum = atol(buf);
-               if (msgnum > 0L) {
-                       artv_export_message(msgnum);
-                       ++count;
+       if (artv_global_message_list != NULL) {
+               lprintf(CTDL_INFO, "Opened %s\n", artv_tempfilename1);
+               while (fgets(buf, sizeof(buf),
+                     artv_global_message_list) != NULL) {
+                       msgnum = atol(buf);
+                       if (msgnum > 0L) {
+                               artv_export_message(msgnum);
+                               ++count;
+                       }
                }
+               fclose(artv_global_message_list);
        }
-       fclose(artv_global_message_list);
-       lprintf(7, "Exported %d messages.\n", count);
+       lprintf(CTDL_INFO, "Exported %d messages.\n", count);
 }
 
 
@@ -256,7 +265,7 @@ void artv_do_export(void) {
        cprintf("%s\n", config.c_fqdn);
        cprintf("%s\n", config.c_humannode);
        cprintf("%s\n", config.c_phonenum);
-       cprintf("%ld\n", (long)config.c_bbsuid);
+       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);
@@ -265,15 +274,11 @@ void artv_do_export(void) {
        cprintf("%s\n", config.c_twitroom);
        cprintf("%s\n", config.c_moreprompt);
        cprintf("%d\n", config.c_restrict);
-       cprintf("%ld\n", config.c_msgbase);
-       cprintf("%s\n", config.c_bbs_city);
+       cprintf("%s\n", config.c_site_location);
        cprintf("%s\n", config.c_sysadm);
-       cprintf("%s\n", config.c_bucket_dir);
        cprintf("%d\n", config.c_setup_level);
        cprintf("%d\n", config.c_maxsessions);
-       cprintf("%s\n", config.c_net_password);
        cprintf("%d\n", config.c_port_number);
-       cprintf("%d\n", config.c_ipgm_secret);
        cprintf("%d\n", config.c_ep.expire_mode);
        cprintf("%d\n", config.c_ep.expire_value);
        cprintf("%d\n", config.c_userpurge);
@@ -285,7 +290,29 @@ void artv_do_export(void) {
        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_default_filter);
+       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);
 
        /* Export the control file */
        get_control();
@@ -310,45 +337,62 @@ void artv_do_export(void) {
 void artv_import_config(void) {
        char buf[SIZ];
 
-       lprintf(9, "Importing config file\n");
-       client_gets(config.c_nodename);
-       lprintf(9, "c_nodename = %s\n", config.c_nodename);
-       client_gets(config.c_fqdn);
-       client_gets(config.c_humannode);
-       client_gets(config.c_phonenum);
-       client_gets(buf);       config.c_bbsuid = atoi(buf);
-       client_gets(buf);       config.c_creataide = atoi(buf);
-       client_gets(buf);       config.c_sleeping = atoi(buf);
-       client_gets(buf);       config.c_initax = atoi(buf);
-       client_gets(buf);       config.c_regiscall = atoi(buf);
-       client_gets(buf);       config.c_twitdetect = atoi(buf);
-       client_gets(config.c_twitroom);
-       client_gets(config.c_moreprompt);
-       client_gets(buf);       config.c_restrict = atoi(buf);
-       client_gets(buf);       config.c_msgbase = atol(buf);
-       client_gets(config.c_bbs_city);
-       client_gets(config.c_sysadm);
-       lprintf(9, "c_sysadm = %s\n", config.c_sysadm);
-       client_gets(config.c_bucket_dir);
-       client_gets(buf);       config.c_setup_level = atoi(buf);
-       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);
-       client_gets(buf);       config.c_roompurge = atoi(buf);
-       client_gets(config.c_logpages);
-       client_gets(buf);       config.c_createax = atoi(buf);
-       client_gets(buf);       config.c_maxmsglen = atol(buf);
-       client_gets(buf);       config.c_min_workers = atoi(buf);
-       client_gets(buf);       config.c_max_workers = atoi(buf);
-       client_gets(buf);       config.c_pop3_port = atoi(buf);
-       client_gets(buf);       config.c_smtp_port = atoi(buf);
-       client_gets(buf);       config.c_default_filter = atoi(buf);
+       lprintf(CTDL_DEBUG, "Importing config file\n");
+       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);
+       config.c_enable_fulltext = 0;   /* always disable */
        put_config();
-       lprintf(7, "Imported config file\n");
+       lprintf(CTDL_INFO, "Imported config file\n");
 }
 
 
@@ -356,70 +400,71 @@ void artv_import_config(void) {
 void artv_import_control(void) {
        char buf[SIZ];
 
-       lprintf(9, "Importing control file\n");
-       client_gets(buf);       CitControl.MMhighest = atol(buf);
-       client_gets(buf);       CitControl.MMflags = atoi(buf);
-       client_gets(buf);       CitControl.MMnextuser = atol(buf);
-       client_gets(buf);       CitControl.MMnextroom = atol(buf);
-       client_gets(buf);       CitControl.version = atoi(buf);
+       lprintf(CTDL_DEBUG, "Importing control file\n");
+       client_getln(buf, sizeof buf);  CitControl.MMhighest = atol(buf);
+       client_getln(buf, sizeof buf);  CitControl.MMflags = atoi(buf);
+       client_getln(buf, sizeof buf);  CitControl.MMnextuser = atol(buf);
+       client_getln(buf, sizeof buf);  CitControl.MMnextroom = atol(buf);
+       client_getln(buf, sizeof buf);  CitControl.version = atoi(buf);
+       CitControl.MMfulltext = (-1L);  /* always flush */
        put_control();
-       lprintf(7, "Imported control file\n");
+       lprintf(CTDL_INFO, "Imported control file\n");
 }
 
 
 void artv_import_user(void) {
        char buf[SIZ];
-       struct usersupp usbuf;
-
-       client_gets(buf);       usbuf.version = atoi(buf);
-       client_gets(buf);       usbuf.uid = atoi(buf);
-       client_gets(usbuf.password);
-       client_gets(buf);       usbuf.flags = atoi(buf);
-       client_gets(buf);       usbuf.timescalled = atol(buf);
-       client_gets(buf);       usbuf.posted = atol(buf);
-       client_gets(buf);       usbuf.axlevel = atoi(buf);
-       client_gets(buf);       usbuf.usernum = atol(buf);
-       client_gets(buf);       usbuf.lastcall = atol(buf);
-       client_gets(buf);       usbuf.USuserpurge = atoi(buf);
-       client_gets(usbuf.fullname);
-       client_gets(buf);       usbuf.USscreenwidth = atoi(buf);
-       client_gets(buf);       usbuf.USscreenheight = atoi(buf);
-       client_gets(buf);       usbuf.moderation_filter = atoi(buf);
+       struct ctdluser usbuf;
+
+       client_getln(buf, sizeof buf);  usbuf.version = atoi(buf);
+       client_getln(buf, sizeof buf);  usbuf.uid = atoi(buf);
+       client_getln(usbuf.password, sizeof usbuf.password);
+       client_getln(buf, sizeof buf);  usbuf.flags = atoi(buf);
+       client_getln(buf, sizeof buf);  usbuf.timescalled = atol(buf);
+       client_getln(buf, sizeof buf);  usbuf.posted = atol(buf);
+       client_getln(buf, sizeof buf);  usbuf.axlevel = atoi(buf);
+       client_getln(buf, sizeof buf);  usbuf.usernum = atol(buf);
+       client_getln(buf, sizeof buf);  usbuf.lastcall = atol(buf);
+       client_getln(buf, sizeof buf);  usbuf.USuserpurge = atoi(buf);
+       client_getln(usbuf.fullname, sizeof usbuf.fullname);
+       client_getln(buf, sizeof buf);  usbuf.USscreenwidth = atoi(buf);
+       client_getln(buf, sizeof buf);  usbuf.USscreenheight = atoi(buf);
        putuser(&usbuf);
 }
 
 
 void artv_import_room(void) {
        char buf[SIZ];
-       struct quickroom qrbuf;
+       struct ctdlroom qrbuf;
        long msgnum;
        int msgcount = 0;
 
-       client_gets(qrbuf.QRname);
-       client_gets(qrbuf.QRpasswd);
-       client_gets(buf);       qrbuf.QRroomaide = atol(buf);
-       client_gets(buf);       qrbuf.QRhighest = atol(buf);
-       client_gets(buf);       qrbuf.QRgen = atol(buf);
-       client_gets(buf);       qrbuf.QRflags = atoi(buf);
-       client_gets(qrbuf.QRdirname);
-       client_gets(buf);       qrbuf.QRinfo = atol(buf);
-       client_gets(buf);       qrbuf.QRfloor = atoi(buf);
-       client_gets(buf);       qrbuf.QRmtime = atol(buf);
-       client_gets(buf);       qrbuf.QRep.expire_mode = atoi(buf);
-       client_gets(buf);       qrbuf.QRep.expire_value = atoi(buf);
-       client_gets(buf);       qrbuf.QRnumber = atol(buf);
-       client_gets(buf);       qrbuf.QRorder = atoi(buf);
-       client_gets(buf);       qrbuf.QRflags2 = atoi(buf);
+       client_getln(qrbuf.QRname, sizeof qrbuf.QRname);
+       client_getln(qrbuf.QRpasswd, sizeof qrbuf.QRpasswd);
+       client_getln(buf, sizeof buf);  qrbuf.QRroomaide = atol(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRhighest = atol(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRgen = atol(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRflags = atoi(buf);
+       client_getln(qrbuf.QRdirname, sizeof qrbuf.QRdirname);
+       client_getln(buf, sizeof buf);  qrbuf.QRinfo = atol(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRfloor = atoi(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRmtime = atol(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRep.expire_mode = atoi(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRep.expire_value = atoi(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRnumber = atol(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRorder = atoi(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRflags2 = atoi(buf);
+       client_getln(buf, sizeof buf);  qrbuf.QRdefaultview = atoi(buf);
        putroom(&qrbuf);
-       lprintf(7, "Imported room <%s>\n", qrbuf.QRname);
+       lprintf(CTDL_INFO, "Imported room <%s>\n", qrbuf.QRname);
        /* format of message list export is all message numbers output
         * one per line terminated by a 0.
         */
-       while (client_gets(buf), msgnum = atol(buf), msgnum > 0) {
-               CtdlSaveMsgPointerInRoom(qrbuf.QRname, msgnum, 0);
+       while (client_getln(buf, sizeof buf), msgnum = atol(buf), msgnum > 0) {
+               CtdlSaveMsgPointerInRoom(qrbuf.QRname, msgnum, 0, NULL);
                ++msgcount;
        }
-       lprintf(7, "(%d messages)\n", msgcount);
+       lprintf(CTDL_INFO, "(%d messages)\n", msgcount);
 }
 
 
@@ -428,14 +473,14 @@ void artv_import_floor(void) {
         int i;
        char buf[SIZ];
 
-       client_gets(buf);               i = atoi(buf);
-       client_gets(buf);               flbuf.f_flags = atoi(buf);
-       client_gets(flbuf.f_name);
-       client_gets(buf);               flbuf.f_ref_count = atoi(buf);
-       client_gets(buf);               flbuf.f_ep.expire_mode = atoi(buf);
-       client_gets(buf);               flbuf.f_ep.expire_value = atoi(buf);
+       client_getln(buf, sizeof buf);  i = atoi(buf);
+       client_getln(buf, sizeof buf);  flbuf.f_flags = atoi(buf);
+       client_getln(flbuf.f_name, sizeof flbuf.f_name);
+       client_getln(buf, sizeof buf);  flbuf.f_ref_count = atoi(buf);
+       client_getln(buf, sizeof buf);  flbuf.f_ep.expire_mode = atoi(buf);
+       client_getln(buf, sizeof buf);  flbuf.f_ep.expire_value = atoi(buf);
        putfloor(&flbuf, i);
-       lprintf(7, "Imported floor #%d (%s)\n", i, flbuf.f_name);
+       lprintf(CTDL_INFO, "Imported floor #%d (%s)\n", i, flbuf.f_name);
 }
 
 
@@ -447,18 +492,20 @@ void artv_import_visit(void) {
        int i;
        int is_textual_seen = 0;
 
-       client_gets(buf);       vbuf.v_roomnum = atol(buf);
-       client_gets(buf);       vbuf.v_roomgen = atol(buf);
-       client_gets(buf);       vbuf.v_usernum = atol(buf);
+       client_getln(buf, sizeof buf);  vbuf.v_roomnum = atol(buf);
+       client_getln(buf, sizeof buf);  vbuf.v_roomgen = atol(buf);
+       client_getln(buf, sizeof buf);  vbuf.v_usernum = atol(buf);
 
-       client_gets(buf);
+       client_getln(buf, sizeof buf);
        vbuf.v_lastseen = atol(buf);
        for (i=0; i<strlen(buf); ++i) if (!isdigit(buf[i])) is_textual_seen = 1;
        if (is_textual_seen)    strcpy(vbuf.v_seen, buf);
 
-       client_gets(buf);       vbuf.v_flags = atoi(buf);
+       client_getln(vbuf.v_answered, sizeof vbuf.v_answered);
+       client_getln(buf, sizeof buf);  vbuf.v_flags = atoi(buf);
+       client_getln(buf, sizeof buf);  vbuf.v_view = atoi(buf);
        put_visit(&vbuf);
-       lprintf(7, "Imported visit %ld/%ld/%ld\n",
+       lprintf(CTDL_INFO, "Imported visit %ld/%ld/%ld\n",
                vbuf.v_roomnum, vbuf.v_roomgen, vbuf.v_usernum);
 }
 
@@ -470,23 +517,22 @@ void artv_import_message(void) {
        long msglen;
        FILE *fp;
        char buf[SIZ];
-       char tempfile[SIZ];
+       char tempfile[PATH_MAX];
        char *mbuf;
 
        memset(&smi, 0, sizeof(struct MetaData));
-       client_gets(buf);       msgnum = atol(buf);
+       client_getln(buf, sizeof buf);  msgnum = atol(buf);
                                smi.meta_msgnum = msgnum;
-       client_gets(buf);       smi.meta_refcount = atoi(buf);
-       client_gets(smi.meta_content_type);
-       client_gets(buf);       smi.meta_mod = atoi(buf);
+       client_getln(buf, sizeof buf);  smi.meta_refcount = atoi(buf);
+       client_getln(smi.meta_content_type, sizeof smi.meta_content_type);
 
-       lprintf(7, "message #%ld\n", msgnum);
+       lprintf(CTDL_INFO, "message #%ld\n", msgnum);
 
        /* decode base64 message text */
-       strcpy(tempfile, tmpnam(NULL));
-       sprintf(buf, "./base64 -d >%s", tempfile);
+       CtdlMakeTempFileName(tempfile, sizeof tempfile);
+       snprintf(buf, sizeof buf, "./base64 -d >%s", tempfile);
        fp = popen(buf, "w");
-       while (client_gets(buf), strcasecmp(buf, END_OF_MESSAGE)) {
+       while (client_getln(buf, sizeof buf), strcasecmp(buf, END_OF_MESSAGE)) {
                fprintf(fp, "%s\n", buf);
        }
        pclose(fp);
@@ -494,20 +540,20 @@ void artv_import_message(void) {
        fseek(fp, 0L, SEEK_END);
        msglen = ftell(fp);
        fclose(fp);
-       lprintf(9, "msglen = %ld\n", msglen);
+       lprintf(CTDL_DEBUG, "msglen = %ld\n", msglen);
 
-       mbuf = mallok(msglen);
+       mbuf = malloc(msglen);
        fp = fopen(tempfile, "rb");
        fread(mbuf, msglen, 1, fp);
        fclose(fp);
 
         cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), mbuf, msglen);
 
-       phree(mbuf);
+       free(mbuf);
        unlink(tempfile);
 
        PutMetaData(&smi);
-       lprintf(7, "Imported message %ld\n", msgnum);
+       lprintf(CTDL_INFO, "Imported message %ld\n", msgnum);
 }
 
 
@@ -518,16 +564,18 @@ void artv_do_import(void) {
        char s_version[SIZ];
        int version;
 
+       unbuffer_output();
+
        cprintf("%d sock it to me\n", SEND_LISTING);
-       while (client_gets(buf), strcmp(buf, "000")) {
+       while (client_getln(buf, sizeof buf), strcmp(buf, "000")) {
 
-               lprintf(9, "import keyword: <%s>\n", buf);
+               lprintf(CTDL_DEBUG, "import keyword: <%s>\n", buf);
 
                if (!strcasecmp(buf, "version")) {
-                       client_gets(s_version);
+                       client_getln(s_version, sizeof s_version);
                        version = atoi(s_version);
-                       if ((version < REV_MIN) || (version > REV_LEVEL)) {
-                               lprintf(7, "Version mismatch - aborting\n");
+                       if ((version<EXPORT_REV_MIN) || (version>REV_LEVEL)) {
+                               lprintf(CTDL_ERR, "Version mismatch in ARTV import; aborting\n");
                                break;
                        }
                }
@@ -541,31 +589,32 @@ void artv_do_import(void) {
                else break;
 
        }
-       lprintf(7, "Invalid keyword <%s>.  Flushing input.\n", buf);
-       while (client_gets(buf), strcmp(buf, "000"))  ;;
+       lprintf(CTDL_INFO, "Invalid keyword <%s>.  Flushing input.\n", buf);
+       while (client_getln(buf, sizeof buf), strcmp(buf, "000"))  ;;
+       rebuild_euid_index();
 }
 
 
 
 void cmd_artv(char *cmdbuf) {
-       char cmd[SIZ];
+       char cmd[32];
        static int is_running = 0;
 
        if (CtdlAccessCheck(ac_internal)) return;
        if (is_running) {
                cprintf("%d The importer/exporter is already running.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
        is_running = 1;
 
-       strcpy(artv_tempfilename1, tmpnam(NULL));
-       strcpy(artv_tempfilename2, tmpnam(NULL));
+       CtdlMakeTempFileName(artv_tempfilename1, sizeof artv_tempfilename1);
+       CtdlMakeTempFileName(artv_tempfilename2, sizeof artv_tempfilename2);
 
-       extract(cmd, cmdbuf, 0);
+       extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
        if (!strcasecmp(cmd, "export")) artv_do_export();
        else if (!strcasecmp(cmd, "import")) artv_do_import();
-       else cprintf("%d illegal command\n", ERROR);
+       else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
 
        unlink(artv_tempfilename1);
        unlink(artv_tempfilename2);
@@ -576,7 +625,7 @@ void cmd_artv(char *cmdbuf) {
 
 
 
-char *Dynamic_Module_Init(void)
+char *serv_vandelay_init(void)
 {
        CtdlRegisterProtoHook(cmd_artv, "ARTV", "import/export data store");
        return "$Id$";