* Renamed "struct user" to "struct ctdluser"
[citadel.git] / citadel / file_ops.c
index 1d1e8705d87ff42274370e38bbed7eed37bb0fe7..f45099e39277aad679d4e728d2c544b4864ff605 100644 (file)
@@ -16,6 +16,7 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <ctype.h>
 #include <string.h>
 #include <sys/stat.h>
 
@@ -33,7 +34,7 @@
 #include <limits.h>
 #include "citadel.h"
 #include "server.h"
-#include "dynloader.h"
+#include "serv_extensions.h"
 #include "config.h"
 #include "file_ops.h"
 #include "sysdep_decls.h"
@@ -119,7 +120,7 @@ void cmd_delf(char *filename)
        if (CtdlAccessCheck(ac_room_aide))
                return;
 
-       if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
+       if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d No directory in this room.\n",
                        ERROR + NOT_HERE);
                return;
@@ -136,10 +137,10 @@ void cmd_delf(char *filename)
                }
        }
        snprintf(pathname, sizeof pathname, "./files/%s/%s",
-                CC->quickroom.QRdirname, filename);
+                CC->room.QRdirname, filename);
        a = unlink(pathname);
        if (a == 0) {
-               cprintf("%d File '%s' deleted.\n", OK, pathname);
+               cprintf("%d File '%s' deleted.\n", CIT_OK, pathname);
        }
        else {
                cprintf("%d File '%s' not found.\n",
@@ -161,14 +162,14 @@ void cmd_movf(char *cmdbuf)
        char newroom[SIZ];
        char buf[SIZ];
        int a;
-       struct quickroom qrbuf;
+       struct ctdlroom qrbuf;
 
        extract(filename, cmdbuf, 0);
        extract(newroom, cmdbuf, 1);
 
        if (CtdlAccessCheck(ac_room_aide)) return;
 
-       if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
+       if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d No directory in this room.\n",
                        ERROR + NOT_HERE);
                return;
@@ -186,7 +187,7 @@ void cmd_movf(char *cmdbuf)
                }
        }
        snprintf(pathname, sizeof pathname, "./files/%s/%s",
-                CC->quickroom.QRdirname, filename);
+                CC->room.QRdirname, filename);
        if (access(pathname, 0) != 0) {
                cprintf("%d File '%s' not found.\n",
                        ERROR + FILE_NOT_FOUND, pathname);
@@ -214,9 +215,9 @@ void cmd_movf(char *cmdbuf)
        /* this is a crude method of copying the file description */
        snprintf(buf, sizeof buf,
                 "cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
-                CC->quickroom.QRdirname, filename, qrbuf.QRdirname);
+                CC->room.QRdirname, filename, qrbuf.QRdirname);
        system(buf);
-       cprintf("%d File '%s' has been moved.\n", OK, filename);
+       cprintf("%d File '%s' has been moved.\n", CIT_OK, filename);
 }
 
 
@@ -237,7 +238,7 @@ void cmd_netf(char *cmdbuf)
 
        if (CtdlAccessCheck(ac_room_aide)) return;
 
-       if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
+       if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d No directory in this room.\n",
                        ERROR + NOT_HERE);
                return;
@@ -255,7 +256,7 @@ void cmd_netf(char *cmdbuf)
                }
        }
        snprintf(pathname, sizeof pathname, "./files/%s/%s",
-                CC->quickroom.QRdirname, filename);
+                CC->room.QRdirname, filename);
        if (access(pathname, 0) != 0) {
                cprintf("%d File '%s' not found.\n",
                        ERROR + FILE_NOT_FOUND, pathname);
@@ -280,14 +281,14 @@ void cmd_netf(char *cmdbuf)
        putc(255, ofp);
        putc(MES_NORMAL, ofp);
        putc(0, ofp);
-       fprintf(ofp, "Pcit%ld", CC->usersupp.usernum);
+       fprintf(ofp, "Pcit%ld", CC->user.usernum);
        putc(0, ofp);
        time(&now);
        fprintf(ofp, "T%ld", (long) now);
        putc(0, ofp);
-       fprintf(ofp, "A%s", CC->usersupp.fullname);
+       fprintf(ofp, "A%s", CC->user.fullname);
        putc(0, ofp);
-       fprintf(ofp, "O%s", CC->quickroom.QRname);
+       fprintf(ofp, "O%s", CC->room.QRname);
        putc(0, ofp);
        fprintf(ofp, "N%s", NODENAME);
        putc(0, ofp);
@@ -300,14 +301,14 @@ void cmd_netf(char *cmdbuf)
 
        snprintf(buf, sizeof buf,
                 "cd ./files/%s; uuencode %s <%s 2>/dev/null >>%s",
-                CC->quickroom.QRdirname, filename, filename, outfile);
+                CC->room.QRdirname, filename, filename, outfile);
        system(buf);
 
        ofp = fopen(outfile, "a");
        putc(0, ofp);
        fclose(ofp);
 
-       cprintf("%d File '%s' has been sent to %s.\n", OK, filename,
+       cprintf("%d File '%s' has been sent to %s.\n", CIT_OK, filename,
                destsys);
        /* FIXME start a network run here. */
        return;
@@ -331,7 +332,7 @@ void OpenCmdResult(char *filename, char *mime_type)
        modtime = (time_t) statbuf.st_mtime;
 
        cprintf("%d %ld|%ld|%s|%s\n",
-               OK, filesize, (long)modtime, filename, mime_type);
+               CIT_OK, filesize, (long)modtime, filename, mime_type);
 }
 
 
@@ -348,7 +349,7 @@ void cmd_open(char *cmdbuf)
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
+       if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d No directory in this room.\n",
                        ERROR + NOT_HERE);
                return;
@@ -373,7 +374,7 @@ void cmd_open(char *cmdbuf)
        }
 
        snprintf(pathname, sizeof pathname,
-                "./files/%s/%s", CC->quickroom.QRdirname, filename);
+                "./files/%s/%s", CC->room.QRdirname, filename);
        CC->download_fp = fopen(pathname, "r");
 
        if (CC->download_fp == NULL) {
@@ -392,8 +393,8 @@ void cmd_oimg(char *cmdbuf)
 {
        char filename[SIZ];
        char pathname[SIZ];
-       struct usersupp usbuf;
-       char which_user[32];
+       struct ctdluser usbuf;
+       char which_user[USERNAME_SIZE];
        int which_floor;
        int a;
 
@@ -425,7 +426,7 @@ void cmd_oimg(char *cmdbuf)
                snprintf(pathname, sizeof pathname,
                         "./images/floor.%d.gif", which_floor);
        } else if (!strcasecmp(filename, "_roompic_")) {
-               assoc_file_name(pathname, &CC->quickroom, "images");
+               assoc_file_name(pathname, sizeof pathname, &CC->room, "images");
        } else {
                for (a = 0; a < strlen(filename); ++a) {
                        filename[a] = tolower(filename[a]);
@@ -459,7 +460,7 @@ void cmd_uopn(char *cmdbuf)
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
-       if ((CC->quickroom.QRflags & QR_DIRECTORY) == 0) {
+       if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
                cprintf("%d No directory in this room.\n",
                        ERROR + NOT_HERE);
                return;
@@ -483,9 +484,9 @@ void cmd_uopn(char *cmdbuf)
                }
        }
        snprintf(CC->upl_path, sizeof CC->upl_path, "./files/%s/%s",
-                CC->quickroom.QRdirname, CC->upl_file);
+                CC->room.QRdirname, CC->upl_file);
        snprintf(CC->upl_filedir, sizeof CC->upl_filedir,
-                "./files/%s/filedir", CC->quickroom.QRdirname);
+                "./files/%s/filedir", CC->room.QRdirname);
 
        CC->upload_fp = fopen(CC->upl_path, "r");
        if (CC->upload_fp != NULL) {
@@ -502,7 +503,7 @@ void cmd_uopn(char *cmdbuf)
                        ERROR, CC->upl_path, strerror(errno));
                return;
        }
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }
 
 
@@ -539,25 +540,25 @@ void cmd_uimg(char *cmdbuf)
                }
        }
 
-       if (CC->usersupp.axlevel >= 6) {
+       if (CC->user.axlevel >= 6) {
                snprintf(CC->upl_path, sizeof CC->upl_path, "./images/%s",
                         basenm);
        }
 
        if (!strcasecmp(basenm, "_userpic_")) {
                snprintf(CC->upl_path, sizeof CC->upl_path,
-                        "./userpics/%ld.gif", CC->usersupp.usernum);
+                        "./userpics/%ld.gif", CC->user.usernum);
        }
 
        if ((!strcasecmp(basenm, "_floorpic_"))
-           && (CC->usersupp.axlevel >= 6)) {
+           && (CC->user.axlevel >= 6)) {
                which_floor = extract_int(cmdbuf, 2);
                snprintf(CC->upl_path, sizeof CC->upl_path,
                         "./images/floor.%d.gif", which_floor);
        }
 
        if ((!strcasecmp(basenm, "_roompic_")) && (is_room_aide())) {
-               assoc_file_name(CC->upl_path, &CC->quickroom, "images");
+               assoc_file_name(CC->upl_path, sizeof CC->upl_path, &CC->room, "images");
        }
 
        if (strlen(CC->upl_path) == 0) {
@@ -567,7 +568,7 @@ void cmd_uimg(char *cmdbuf)
        }
 
        if (is_this_for_real == 0) {
-               cprintf("%d Ok to send image\n", OK);
+               cprintf("%d Ok to send image\n", CIT_OK);
                return;
        }
 
@@ -577,7 +578,7 @@ void cmd_uimg(char *cmdbuf)
                        ERROR, CC->upl_path, strerror(errno));
                return;
        }
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
        CC->upload_type = UPL_IMAGE;
 }
 
@@ -605,7 +606,7 @@ void cmd_clos(void)
                unlink(buf);
        }
 
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }
 
 
@@ -641,7 +642,7 @@ void cmd_ucls(char *cmd)
 
        if ((!strcasecmp(cmd, "1")) && (CC->upload_type != UPL_FILE)) {
                CC->upload_type = UPL_FILE;
-               cprintf("%d Upload completed.\n", OK);
+               cprintf("%d Upload completed.\n", CIT_OK);
 
                /* FIXME ... here we need to trigger a network run */
 
@@ -649,7 +650,7 @@ void cmd_ucls(char *cmd)
        }
 
        if (!strcasecmp(cmd, "1")) {
-               cprintf("%d File '%s' saved.\n", OK, CC->upl_path);
+               cprintf("%d File '%s' saved.\n", CIT_OK, CC->upl_path);
                fp = fopen(CC->upl_filedir, "a");
                if (fp == NULL) {
                        fp = fopen(CC->upl_filedir, "w");
@@ -661,14 +662,14 @@ void cmd_ucls(char *cmd)
                }
 
                /* put together an upload notice */
-               sprintf(upload_notice,
+               snprintf(upload_notice, sizeof upload_notice,
                        "NEW UPLOAD: '%s'\n %s\n",
                        CC->upl_file, CC->upl_comment);
-               quickie_message(CC->curr_user, NULL, CC->quickroom.QRname,
-                               upload_notice);
+               quickie_message(CC->curr_user, NULL, CC->room.QRname,
+                               upload_notice, 0, NULL);
        } else {
                abort_upl(CC);
-               cprintf("%d File '%s' aborted.\n", OK, CC->upl_path);
+               cprintf("%d File '%s' aborted.\n", CIT_OK, CC->upl_path);
        }
 }
 
@@ -680,7 +681,8 @@ void cmd_ucls(char *cmd)
 void cmd_read(char *cmdbuf)
 {
        long start_pos;
-       int bytes;
+       size_t bytes;
+       size_t actual_bytes;
        char buf[4096];
 
        start_pos = extract_long(cmdbuf, 0);
@@ -692,16 +694,12 @@ void cmd_read(char *cmdbuf)
                return;
        }
 
-       if (bytes > 4096) {
-               cprintf("%d You may not read more than 4096 bytes.\n",
-                       ERROR);
-               return;
-       }
+       if (bytes > 4096) bytes = 4096;
 
        fseek(CC->download_fp, start_pos, 0);
-       fread(buf, bytes, 1, CC->download_fp);
-       cprintf("%d %d\n", BINARY_FOLLOWS, bytes);
-       client_write(buf, bytes);
+       actual_bytes = fread(buf, 1, bytes, CC->download_fp);
+       cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
+       client_write(buf, actual_bytes);
 }
 
 
@@ -780,7 +778,7 @@ void cmd_ndop(char *cmdbuf)
        CC->dl_is_net = 1;
 
        stat(pathname, &statbuf);
-       cprintf("%d %ld\n", OK, (long)statbuf.st_size);
+       cprintf("%d %ld\n", CIT_OK, (long)statbuf.st_size);
 }
 
 /*
@@ -823,5 +821,5 @@ void cmd_nuop(char *cmdbuf)
        }
 
        CC->upload_type = UPL_NET;
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }