]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_vandelay.c
- declare *printf format specifiers if gcc detected
[citadel.git] / citadel / serv_vandelay.c
index 7c5dac0d2795dc0d2490a3f36a92df546c49a0c0..d364740cbd027c664775a77ba3024067a996f1bc 100644 (file)
 #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 <ctype.h>
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include <time.h>
 #include "sysdep_decls.h"
 #include "citserver.h"
 #include "support.h"
@@ -35,8 +46,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) {
@@ -49,7 +60,7 @@ void artv_export_users_backend(struct usersupp *usbuf, void *data) {
        cprintf("%ld\n", usbuf->posted);
        cprintf("%d\n", usbuf->axlevel);
        cprintf("%ld\n", usbuf->usernum);
-       cprintf("%ld\n", usbuf->lastcall);
+       cprintf("%ld\n", (long)usbuf->lastcall);
        cprintf("%d\n", usbuf->USuserpurge);
        cprintf("%s\n", usbuf->fullname);
        cprintf("%d\n", usbuf->USscreenwidth);
@@ -63,7 +74,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);
 }
@@ -75,12 +86,12 @@ void artv_export_rooms_backend(struct quickroom *qrbuf, void *data) {
        cprintf("%s\n", qrbuf->QRpasswd);
        cprintf("%ld\n", qrbuf->QRroomaide);
        cprintf("%ld\n", qrbuf->QRhighest);
-       cprintf("%ld\n", qrbuf->QRgen);
+       cprintf("%ld\n", (long)qrbuf->QRgen);
        cprintf("%u\n", qrbuf->QRflags);
        cprintf("%s\n", qrbuf->QRdirname);
        cprintf("%ld\n", qrbuf->QRinfo);
        cprintf("%d\n", qrbuf->QRfloor);
-       cprintf("%ld\n", qrbuf->QRmtime);
+       cprintf("%ld\n", (long)qrbuf->QRmtime);
        cprintf("%d\n", qrbuf->QRep.expire_mode);
        cprintf("%d\n", qrbuf->QRep.expire_value);
        cprintf("%ld\n", qrbuf->QRnumber);
@@ -91,7 +102,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 +110,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);
@@ -157,7 +168,14 @@ void artv_export_visits(void) {
                cprintf("%ld\n", vbuf.v_roomnum);
                cprintf("%ld\n", vbuf.v_roomgen);
                cprintf("%ld\n", vbuf.v_usernum);
-               cprintf("%ld\n", vbuf.v_lastseen);
+
+               if (strlen(vbuf.v_seen) > 0) {
+                       cprintf("%s\n", vbuf.v_seen);
+               }
+               else {
+                       cprintf("%ld\n", vbuf.v_lastseen);
+               }
+
                cprintf("%u\n", vbuf.v_flags);
        }
 }
@@ -168,8 +186,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 */
@@ -189,7 +207,7 @@ void artv_export_message(long msgnum) {
        sprintf(buf, "./base64 -e >%s", tempfile);
        fp = popen(buf, "w");
        fwrite(smr.ser, smr.len, 1, fp);
-       fclose(fp);
+       pclose(fp);
 
        phree(smr.ser);
 
@@ -206,7 +224,7 @@ void artv_export_message(long msgnum) {
 
 
 void artv_export_messages(void) {
-       char buf[256];
+       char buf[SIZ];
        long msgnum;
        int count = 0;
 
@@ -220,7 +238,7 @@ void artv_export_messages(void) {
                }
        }
        fclose(artv_global_message_list);
-       lprintf(7, "Exported %ld messages.\n", count);
+       lprintf(7, "Exported %d messages.\n", count);
 }
 
 
@@ -289,7 +307,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);
@@ -335,7 +353,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);
@@ -349,7 +367,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);
@@ -371,7 +389,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;
@@ -406,7 +424,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);
@@ -423,12 +441,19 @@ void artv_import_floor(void) {
  */
 void artv_import_visit(void) {
        struct visit vbuf;
-       char buf[256];
+       char buf[SIZ];
+       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_gets(buf);       vbuf.v_lastseen = atol(buf);
+
+       client_gets(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);
        put_visit(&vbuf);
        lprintf(7, "Imported visit %ld/%ld/%ld\n",
@@ -440,10 +465,10 @@ void artv_import_visit(void) {
 void artv_import_message(void) {
        struct SuppMsgInfo smi;
        long msgnum;
-       int msglen;
+       long msglen;
        FILE *fp;
-       char buf[256];
-       char tempfile[256];
+       char buf[SIZ];
+       char tempfile[SIZ];
        char *mbuf;
 
        memset(&smi, 0, sizeof(struct SuppMsgInfo));
@@ -462,7 +487,7 @@ void artv_import_message(void) {
        while (client_gets(buf), strcasecmp(buf, END_OF_MESSAGE)) {
                fprintf(fp, "%s\n", buf);
        }
-       fclose(fp);
+       pclose(fp);
        fp = fopen(tempfile, "rb");
        fseek(fp, 0L, SEEK_END);
        msglen = ftell(fp);
@@ -474,9 +499,7 @@ void artv_import_message(void) {
        fread(mbuf, msglen, 1, fp);
        fclose(fp);
 
-        begin_critical_section(S_MSGMAIN);
         cdb_store(CDB_MSGMAIN, &msgnum, sizeof(long), mbuf, msglen);
-        end_critical_section(S_MSGMAIN);
 
        phree(mbuf);
        unlink(tempfile);
@@ -489,8 +512,8 @@ void artv_import_message(void) {
 
 
 void artv_do_import(void) {
-       char buf[256];
-       char s_version[256];
+       char buf[SIZ];
+       char s_version[SIZ];
        int version;
 
        cprintf("%d sock it to me\n", SEND_LISTING);
@@ -503,7 +526,7 @@ void artv_do_import(void) {
                        version = atoi(s_version);
                        if ((version < REV_MIN) || (version > REV_LEVEL)) {
                                lprintf(7, "Version mismatch - aborting\n");
-                               goto artv_flush_import;
+                               break;
                        }
                }
                else if (!strcasecmp(buf, "config")) artv_import_config();
@@ -513,9 +536,9 @@ void artv_do_import(void) {
                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"))  ;;
 }
@@ -523,10 +546,10 @@ 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 */
+       if (CtdlAccessCheck(ac_internal)) return;
        if (is_running) {
                cprintf("%d The importer/exporter is already running.\n",
                        ERROR);