]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
* partialy revert r8246; we're working in units of one here, so the number of units...
[citadel.git] / citadel / file_ops.c
index af4a872a1d5a43bbd840e0193a3c2d018f3f0f82..ced5a31d568c3fef6f83466c7e51313abfdd4fbc 100644 (file)
@@ -45,6 +45,8 @@
 #include "snprintf.h"
 #endif
 
+#include "ctdl_module.h"
+
 /*
  * network_talking_to()  --  concurrency checker
  */
@@ -161,6 +163,7 @@ void cmd_movf(char *cmdbuf)
        char buf[PATH_MAX];
        int a;
        struct ctdlroom qrbuf;
+       int rv = 0;
 
        extract_token(filename, cmdbuf, 0, '|', sizeof filename);
        extract_token(newroom, cmdbuf, 1, '|', sizeof newroom);
@@ -192,7 +195,7 @@ void cmd_movf(char *cmdbuf)
                return;
        }
 
-       if (getroom(&qrbuf, newroom) != 0) {
+       if (CtdlGetRoom(&qrbuf, newroom) != 0) {
                cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, newroom);
                return;
        }
@@ -214,107 +217,11 @@ void cmd_movf(char *cmdbuf)
        snprintf(buf, sizeof buf,
                 "cat ./files/%s/filedir |grep \"%s\" >>./files/%s/filedir",
                 CC->room.QRdirname, filename, qrbuf.QRdirname);
-       system(buf);
+       rv = system(buf);
        cprintf("%d File '%s' has been moved.\n", CIT_OK, filename);
 }
 
 
-/*
- * send a file over the net
- */
-void cmd_netf(char *cmdbuf)
-{
-       char pathname[256], filename[256], destsys[256], buf[256];
-       char outfile[256];
-       int a, e;
-       time_t now;
-       FILE *ofp;
-       static int seq = 1;
-
-       extract_token(filename, cmdbuf, 0, '|', sizeof filename);
-       extract_token(destsys, cmdbuf, 1, '|', sizeof destsys);
-
-       if (CtdlAccessCheck(ac_room_aide)) return;
-
-       if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
-               cprintf("%d No directory in this room.\n",
-                       ERROR + NOT_HERE);
-               return;
-       }
-
-       if (IsEmptyStr(filename)) {
-               cprintf("%d You must specify a file name.\n",
-                       ERROR + FILE_NOT_FOUND);
-               return;
-       }
-
-       for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
-               if ( (filename[a] == '/') || (filename[a] == '\\') ) {
-                       filename[a] = '_';
-               }
-       }
-       snprintf(pathname, sizeof pathname, "./files/%s/%s",
-                CC->room.QRdirname, filename);
-       if (access(pathname, 0) != 0) {
-               cprintf("%d File '%s' not found.\n",
-                       ERROR + FILE_NOT_FOUND, pathname);
-               return;
-       }
-       snprintf(buf, sizeof buf, "sysop@%s", destsys);
-       e = alias(buf);
-       if (e != MES_IGNET) {
-               cprintf("%d No such system: '%s'\n",
-                       ERROR + NO_SUCH_SYSTEM, destsys);
-               return;
-       }
-       snprintf(outfile, sizeof outfile,
-                        "%s/nsf.%04lx.%04x",
-                        ctdl_netin_dir,
-                        (long)getpid(), ++seq);
-       ofp = fopen(outfile, "a");
-       if (ofp == NULL) {
-               cprintf("%d internal error\n", ERROR + INTERNAL_ERROR);
-               return;
-       }
-
-       putc(255, ofp);
-       putc(MES_NORMAL, ofp);
-       putc(0, ofp);
-       fprintf(ofp, "P%s", CC->user.fullname);
-       putc(0, ofp);
-       time(&now);
-       fprintf(ofp, "T%ld", (long) now);
-       putc(0, ofp);
-       fprintf(ofp, "A%s", CC->user.fullname);
-       putc(0, ofp);
-       fprintf(ofp, "O%s", CC->room.QRname);
-       putc(0, ofp);
-       fprintf(ofp, "N%s", NODENAME);
-       putc(0, ofp);
-       fprintf(ofp, "D%s", destsys);
-       putc(0, ofp);
-       fprintf(ofp, "SFILE");
-       putc(0, ofp);
-       putc('M', ofp);
-       fclose(ofp);
-
-       snprintf(buf, sizeof buf,
-                        "cd %s/%s; uuencode %s <%s 2>/dev/null >>%s",
-                        ctdl_file_dir,
-                        /* FIXME: detect uuencode while installation? or inline */
-                        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", CIT_OK, filename,
-               destsys);
-       /* FIXME start a network run here. */
-       return;
-}
-
 /*
  * This code is common to all commands which open a file for downloading,
  * regardless of whether it's a file from the directory, an image, a network
@@ -401,6 +308,7 @@ void cmd_oimg(char *cmdbuf)
        char which_user[USERNAME_SIZE];
        int which_floor;
        int a;
+       int rv;
 
        extract_token(filename, cmdbuf, 0, '|', sizeof filename);
 
@@ -418,7 +326,7 @@ void cmd_oimg(char *cmdbuf)
 
        if (!strcasecmp(filename, "_userpic_")) {
                extract_token(which_user, cmdbuf, 1, '|', sizeof which_user);
-               if (getuser(&usbuf, which_user) != 0) {
+               if (CtdlGetUser(&usbuf, which_user) != 0) {
                        cprintf("%d No such user.\n",
                                ERROR + NO_SUCH_USER);
                        return;
@@ -457,7 +365,7 @@ void cmd_oimg(char *cmdbuf)
                        ERROR + FILE_NOT_FOUND, pathname, strerror(errno));
                return;
        }
-       fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
+       rv = fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
        rewind (CC->download_fp);
        OpenCmdResult(pathname, GuessMimeType(&MimeTestBuf[0], 32));
 }
@@ -612,7 +520,7 @@ void cmd_uimg(char *cmdbuf)
 /*
  * close the download file
  */
-void cmd_clos(void)
+void cmd_clos(char *cmdbuf)
 {
        char buf[256];
 
@@ -641,7 +549,7 @@ void cmd_clos(void)
 /*
  * abort an upload
  */
-void abort_upl(struct CitContext *who)
+void abort_upl(CitContext *who)
 {
        if (who->upload_fp != NULL) {
                fclose(who->upload_fp);
@@ -729,9 +637,15 @@ void cmd_read(char *cmdbuf)
        buf = malloc(bytes + 1);
 
        fseek(CC->download_fp, start_pos, 0);
+
        actual_bytes = fread(buf, 1, bytes, CC->download_fp);
-       cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
-       client_write(buf, actual_bytes);
+       if (actual_bytes > 0) {
+               cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
+               client_write(buf, bytes);
+       }
+       else {
+               cprintf("%d %s\n", ERROR, strerror(errno));
+       }
        free(buf);
 }
 
@@ -744,6 +658,7 @@ void cmd_writ(char *cmdbuf)
 {
        int bytes;
        char *buf;
+       int rv;
 
        unbuffer_output();
 
@@ -763,7 +678,7 @@ void cmd_writ(char *cmdbuf)
        cprintf("%d %d\n", SEND_BINARY, bytes);
        buf = malloc(bytes + 1);
        client_read(buf, bytes);
-       fwrite(buf, bytes, 1, CC->upload_fp);
+       rv = fwrite(buf, bytes, 1, CC->upload_fp);
        free(buf);
 }
 
@@ -865,3 +780,28 @@ void cmd_nuop(char *cmdbuf)
        CC->upload_type = UPL_NET;
        cprintf("%d Ok\n", CIT_OK);
 }
+
+
+/*****************************************************************************/
+/*                      MODULE INITIALIZATION STUFF                          */
+/*****************************************************************************/
+
+CTDL_MODULE_INIT(file_ops)
+{
+       if (!threading) {
+               CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
+               CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
+       }
+        /* return our Subversion id for the Log */
+       return "$Id$";
+}