]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
* citadel.h: changed internal version number to 6.07
[citadel.git] / citadel / file_ops.c
index d701a443c3d03947bb5651ea84aaa878e7c74a76..dd5f2bdbd5d871517034f0e9854e42d3c6af04f2 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"
 #include "tools.h"
 #include "citserver.h"
 
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
+
+/*
+ * network_talking_to()  --  concurrency checker
+ */
+int network_talking_to(char *nodename, int operation) {
+
+       static char *nttlist = NULL;
+       char *ptr = NULL;
+       int i;
+       char buf[SIZ];
+       int retval = 0;
+
+       begin_critical_section(S_NTTLIST);
+
+       switch(operation) {
+
+               case NTT_ADD:
+                       if (nttlist == NULL) nttlist = strdoop("");
+                       if (nttlist == NULL) break;
+                       nttlist = (char *)reallok(nttlist,
+                               (strlen(nttlist) + strlen(nodename) + 3) );
+                       strcat(nttlist, "|");
+                       strcat(nttlist, nodename);
+                       break;
+
+               case NTT_REMOVE:
+                       if (nttlist == NULL) break;
+                       if (strlen(nttlist) == 0) break;
+                       ptr = mallok(strlen(nttlist));
+                       if (ptr == NULL) break;
+                       strcpy(ptr, "");
+                       for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
+                               extract(buf, nttlist, i);
+                               if ( (strlen(buf) > 0)
+                                    && (strcasecmp(buf, nodename)) ) {
+                                               strcat(ptr, buf);
+                                               strcat(ptr, "|");
+                               }
+                       }
+                       phree(nttlist);
+                       nttlist = ptr;
+                       break;
+
+               case NTT_CHECK:
+                       if (nttlist == NULL) break;
+                       if (strlen(nttlist) == 0) break;
+                       for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
+                               extract(buf, nttlist, i);
+                               if (!strcasecmp(buf, nodename)) ++retval;
+                       }
+                       break;
+       }
+
+       if (nttlist != NULL) lprintf(9, "nttlist=<%s>\n", nttlist);
+       end_critical_section(S_NTTLIST);
+       return(retval);
+}
+
+
+
 
 /*
  * Server command to delete a file from a room's directory
@@ -76,7 +140,7 @@ void cmd_delf(char *filename)
                 CC->quickroom.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",
@@ -153,7 +217,7 @@ void cmd_movf(char *cmdbuf)
                 "cat ./files/%s/filedir |grep %s >>./files/%s/filedir",
                 CC->quickroom.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);
 }
 
 
@@ -200,7 +264,7 @@ void cmd_netf(char *cmdbuf)
        }
        snprintf(buf, sizeof buf, "sysop@%s", destsys);
        e = alias(buf);
-       if (e != MES_BINARY) {
+       if (e != MES_IGNET) {
                cprintf("%d No such system: '%s'\n",
                        ERROR + NO_SUCH_SYSTEM, destsys);
                return;
@@ -244,9 +308,9 @@ void cmd_netf(char *cmdbuf)
        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);
-       system("nohup ./netproc -i >/dev/null 2>&1 &");
+       /* FIXME start a network run here. */
        return;
 }
 
@@ -268,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, modtime, filename, mime_type);
+               CIT_OK, filesize, (long)modtime, filename, mime_type);
 }
 
 
@@ -330,7 +394,7 @@ void cmd_oimg(char *cmdbuf)
        char filename[SIZ];
        char pathname[SIZ];
        struct usersupp usbuf;
-       char which_user[32];
+       char which_user[USERNAME_SIZE];
        int which_floor;
        int a;
 
@@ -362,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->quickroom, "images");
        } else {
                for (a = 0; a < strlen(filename); ++a) {
                        filename[a] = tolower(filename[a]);
@@ -439,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);
 }
 
 
@@ -494,7 +558,7 @@ void cmd_uimg(char *cmdbuf)
        }
 
        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->quickroom, "images");
        }
 
        if (strlen(CC->upl_path) == 0) {
@@ -504,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;
        }
 
@@ -514,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;
 }
 
@@ -542,7 +606,7 @@ void cmd_clos(void)
                unlink(buf);
        }
 
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }
 
 
@@ -578,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 */
 
@@ -586,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");
@@ -598,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);
+                               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);
        }
 }
 
@@ -617,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);
@@ -629,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);
 }
 
 
@@ -717,7 +778,7 @@ void cmd_ndop(char *cmdbuf)
        CC->dl_is_net = 1;
 
        stat(pathname, &statbuf);
-       cprintf("%d %ld\n", OK, statbuf.st_size);
+       cprintf("%d %ld\n", CIT_OK, (long)statbuf.st_size);
 }
 
 /*
@@ -760,5 +821,5 @@ void cmd_nuop(char *cmdbuf)
        }
 
        CC->upload_type = UPL_NET;
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }