]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
* compatibility with Berkeley DB < 3.3
[citadel.git] / citadel / file_ops.c
index d701a443c3d03947bb5651ea84aaa878e7c74a76..664a62ff33868a847c0c4cfb14ed738daae02aca 100644 (file)
 #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 +139,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 +216,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 +263,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 +307,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 +331,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);
 }
 
 
@@ -362,7 +425,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 +502,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 +557,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 +567,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 +577,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 +605,7 @@ void cmd_clos(void)
                unlink(buf);
        }
 
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }
 
 
@@ -578,7 +641,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 +649,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 +661,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);
        } 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);
        }
 }
 
@@ -717,7 +780,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 +823,5 @@ void cmd_nuop(char *cmdbuf)
        }
 
        CC->upload_type = UPL_NET;
-       cprintf("%d Ok\n", OK);
+       cprintf("%d Ok\n", CIT_OK);
 }