]> code.citadel.org Git - citadel.git/blobdiff - citadel/file_ops.c
* Variable names, comments, documentation, etc... removed the acronym 'BBS'
[citadel.git] / citadel / file_ops.c
index 7a6a771cd0b7d82907190549b32e7890eb05f457..7595fd853a765ed9ddeb3d17b82bf965fce5ca4e 100644 (file)
@@ -65,9 +65,9 @@ int network_talking_to(char *nodename, int operation) {
        switch(operation) {
 
                case NTT_ADD:
-                       if (nttlist == NULL) nttlist = strdoop("");
+                       if (nttlist == NULL) nttlist = strdup("");
                        if (nttlist == NULL) break;
-                       nttlist = (char *)reallok(nttlist,
+                       nttlist = (char *)realloc(nttlist,
                                (strlen(nttlist) + strlen(nodename) + 3) );
                        strcat(nttlist, "|");
                        strcat(nttlist, nodename);
@@ -76,18 +76,18 @@ int network_talking_to(char *nodename, int operation) {
                case NTT_REMOVE:
                        if (nttlist == NULL) break;
                        if (strlen(nttlist) == 0) break;
-                       ptr = mallok(strlen(nttlist));
+                       ptr = malloc(strlen(nttlist));
                        if (ptr == NULL) break;
                        strcpy(ptr, "");
                        for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
-                               extract(buf, nttlist, i);
+                               extract_token(buf, nttlist, i, '|', sizeof buf);
                                if ( (strlen(buf) > 0)
                                     && (strcasecmp(buf, nodename)) ) {
                                                strcat(ptr, buf);
                                                strcat(ptr, "|");
                                }
                        }
-                       phree(nttlist);
+                       free(nttlist);
                        nttlist = ptr;
                        break;
 
@@ -95,13 +95,13 @@ int network_talking_to(char *nodename, int operation) {
                        if (nttlist == NULL) break;
                        if (strlen(nttlist) == 0) break;
                        for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
-                               extract(buf, nttlist, i);
+                               extract_token(buf, nttlist, i, '|', sizeof buf);
                                if (!strcasecmp(buf, nodename)) ++retval;
                        }
                        break;
        }
 
-       if (nttlist != NULL) lprintf(9, "nttlist=<%s>\n", nttlist);
+       if (nttlist != NULL) lprintf(CTDL_DEBUG, "nttlist=<%s>\n", nttlist);
        end_critical_section(S_NTTLIST);
        return(retval);
 }
@@ -156,16 +156,16 @@ void cmd_delf(char *filename)
  */
 void cmd_movf(char *cmdbuf)
 {
-       char filename[SIZ];
-       char pathname[SIZ];
-       char newpath[SIZ];
-       char newroom[SIZ];
-       char buf[SIZ];
+       char filename[PATH_MAX];
+       char pathname[PATH_MAX];
+       char newpath[PATH_MAX];
+       char newroom[ROOMNAMELEN];
+       char buf[PATH_MAX];
        int a;
        struct ctdlroom qrbuf;
 
-       extract(filename, cmdbuf, 0);
-       extract(newroom, cmdbuf, 1);
+       extract_token(filename, cmdbuf, 0, '|', sizeof filename);
+       extract_token(newroom, cmdbuf, 1, '|', sizeof newroom);
 
        if (CtdlAccessCheck(ac_room_aide)) return;
 
@@ -195,7 +195,7 @@ void cmd_movf(char *cmdbuf)
        }
 
        if (getroom(&qrbuf, newroom) != 0) {
-               cprintf("%d '%s' does not exist.\n", ERROR, newroom);
+               cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, newroom);
                return;
        }
        if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
@@ -206,7 +206,7 @@ void cmd_movf(char *cmdbuf)
        snprintf(newpath, sizeof newpath, "./files/%s/%s", qrbuf.QRdirname,
                 filename);
        if (link(pathname, newpath) != 0) {
-               cprintf("%d Couldn't move file: %s\n", ERROR,
+               cprintf("%d Couldn't move file: %s\n", ERROR + INTERNAL_ERROR,
                        strerror(errno));
                return;
        }
@@ -226,15 +226,15 @@ void cmd_movf(char *cmdbuf)
  */
 void cmd_netf(char *cmdbuf)
 {
-       char pathname[SIZ], filename[SIZ], destsys[SIZ], buf[SIZ];
-       char outfile[SIZ];
+       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(filename, cmdbuf, 0);
-       extract(destsys, cmdbuf, 1);
+       extract_token(filename, cmdbuf, 0, '|', sizeof filename);
+       extract_token(destsys, cmdbuf, 1, '|', sizeof destsys);
 
        if (CtdlAccessCheck(ac_room_aide)) return;
 
@@ -271,10 +271,10 @@ void cmd_netf(char *cmdbuf)
        }
        snprintf(outfile, sizeof outfile,
                 "%s/network/spoolin/nsf.%04lx.%04x",
-                BBSDIR, (long)getpid(), ++seq);
+                CTDLDIR, (long)getpid(), ++seq);
        ofp = fopen(outfile, "a");
        if (ofp == NULL) {
-               cprintf("%d internal error\n", ERROR);
+               cprintf("%d internal error\n", ERROR + INTERNAL_ERROR);
                return;
        }
 
@@ -341,11 +341,11 @@ void OpenCmdResult(char *filename, char *mime_type)
  */
 void cmd_open(char *cmdbuf)
 {
-       char filename[SIZ];
-       char pathname[SIZ];
+       char filename[256];
+       char pathname[PATH_MAX];
        int a;
 
-       extract(filename, cmdbuf, 0);
+       extract_token(filename, cmdbuf, 0, '|', sizeof filename);
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
@@ -363,7 +363,7 @@ void cmd_open(char *cmdbuf)
 
        if (CC->download_fp != NULL) {
                cprintf("%d You already have a download file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
 
@@ -379,7 +379,7 @@ void cmd_open(char *cmdbuf)
 
        if (CC->download_fp == NULL) {
                cprintf("%d cannot open %s: %s\n",
-                       ERROR, pathname, strerror(errno));
+                       ERROR + INTERNAL_ERROR, pathname, strerror(errno));
                return;
        }
 
@@ -391,14 +391,14 @@ void cmd_open(char *cmdbuf)
  */
 void cmd_oimg(char *cmdbuf)
 {
-       char filename[SIZ];
-       char pathname[SIZ];
+       char filename[256];
+       char pathname[PATH_MAX];
        struct ctdluser usbuf;
        char which_user[USERNAME_SIZE];
        int which_floor;
        int a;
 
-       extract(filename, cmdbuf, 0);
+       extract_token(filename, cmdbuf, 0, '|', sizeof filename);
 
        if (strlen(filename) == 0) {
                cprintf("%d You must specify a file name.\n",
@@ -408,12 +408,12 @@ void cmd_oimg(char *cmdbuf)
 
        if (CC->download_fp != NULL) {
                cprintf("%d You already have a download file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
 
        if (!strcasecmp(filename, "_userpic_")) {
-               extract(which_user, cmdbuf, 1);
+               extract_token(which_user, cmdbuf, 1, '|', sizeof which_user);
                if (getuser(&usbuf, which_user) != 0) {
                        cprintf("%d No such user.\n",
                                ERROR + NO_SUCH_USER);
@@ -455,8 +455,8 @@ void cmd_uopn(char *cmdbuf)
 {
        int a;
 
-       extract(CC->upl_file, cmdbuf, 0);
-       extract(CC->upl_comment, cmdbuf, 1);
+       extract_token(CC->upl_file, cmdbuf, 0, '|', sizeof CC->upl_file);
+       extract_token(CC->upl_comment, cmdbuf, 1, '|', sizeof CC->upl_comment);
 
        if (CtdlAccessCheck(ac_logged_in)) return;
 
@@ -474,7 +474,7 @@ void cmd_uopn(char *cmdbuf)
 
        if (CC->upload_fp != NULL) {
                cprintf("%d You already have a upload file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
 
@@ -500,7 +500,7 @@ void cmd_uopn(char *cmdbuf)
        CC->upload_fp = fopen(CC->upl_path, "wb");
        if (CC->upload_fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
-                       ERROR, CC->upl_path, strerror(errno));
+                       ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno));
                return;
        }
        cprintf("%d Ok\n", CIT_OK);
@@ -514,20 +514,20 @@ void cmd_uopn(char *cmdbuf)
 void cmd_uimg(char *cmdbuf)
 {
        int is_this_for_real;
-       char basenm[SIZ];
+       char basenm[256];
        int which_floor;
        int a;
 
        if (num_parms(cmdbuf) < 2) {
-               cprintf("%d Usage error.\n", ERROR);
+               cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
                return;
        }
 
        is_this_for_real = extract_int(cmdbuf, 0);
-       extract(basenm, cmdbuf, 1);
+       extract_token(basenm, cmdbuf, 1, '|', sizeof basenm);
        if (CC->upload_fp != NULL) {
                cprintf("%d You already have an upload file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
 
@@ -575,7 +575,7 @@ void cmd_uimg(char *cmdbuf)
        CC->upload_fp = fopen(CC->upl_path, "wb");
        if (CC->upload_fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
-                       ERROR, CC->upl_path, strerror(errno));
+                       ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno));
                return;
        }
        cprintf("%d Ok\n", CIT_OK);
@@ -588,11 +588,11 @@ void cmd_uimg(char *cmdbuf)
  */
 void cmd_clos(void)
 {
-       char buf[SIZ];
+       char buf[256];
 
        if (CC->download_fp == NULL) {
                cprintf("%d You don't have a download file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_NOT_OPEN);
                return;
        }
 
@@ -601,7 +601,7 @@ void cmd_clos(void)
 
        if (CC->dl_is_net == 1) {
                CC->dl_is_net = 0;
-               snprintf(buf, sizeof buf, "%s/network/spoolout/%s", BBSDIR,
+               snprintf(buf, sizeof buf, "%s/network/spoolout/%s", CTDLDIR,
                         CC->net_node);
                unlink(buf);
        }
@@ -633,7 +633,7 @@ void cmd_ucls(char *cmd)
        char upload_notice[512];
 
        if (CC->upload_fp == NULL) {
-               cprintf("%d You don't have an upload file open.\n", ERROR);
+               cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN);
                return;
        }
 
@@ -683,23 +683,25 @@ void cmd_read(char *cmdbuf)
        long start_pos;
        size_t bytes;
        size_t actual_bytes;
-       char buf[4096];
+       char *buf = NULL;
 
        start_pos = extract_long(cmdbuf, 0);
        bytes = extract_int(cmdbuf, 1);
 
        if (CC->download_fp == NULL) {
                cprintf("%d You don't have a download file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_NOT_OPEN);
                return;
        }
 
-       if (bytes > 4096) bytes = 4096;
+       if (bytes > 100000) bytes = 100000;
+       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);
+       free(buf);
 }
 
 
@@ -710,24 +712,28 @@ void cmd_read(char *cmdbuf)
 void cmd_writ(char *cmdbuf)
 {
        int bytes;
-       char buf[4096];
+       char *buf;
+
+       unbuffer_output();
 
        bytes = extract_int(cmdbuf, 0);
 
        if (CC->upload_fp == NULL) {
-               cprintf("%d You don't have an upload file open.\n", ERROR);
+               cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN);
                return;
        }
 
-       if (bytes > 4096) {
-               cprintf("%d You may not write more than 4096 bytes.\n",
-                       ERROR);
+       if (bytes > 100000) {
+               cprintf("%d You may not write more than 100000 bytes.\n",
+                       ERROR + TOO_BIG);
                return;
        }
 
        cprintf("%d %d\n", SEND_BINARY, bytes);
+       buf = malloc(bytes + 1);
        client_read(buf, bytes);
        fwrite(buf, bytes, 1, CC->upload_fp);
+       free(buf);
 }
 
 
@@ -738,7 +744,7 @@ void cmd_writ(char *cmdbuf)
  */
 void cmd_ndop(char *cmdbuf)
 {
-       char pathname[SIZ];
+       char pathname[256];
        struct stat statbuf;
 
        if (strlen(CC->net_node) == 0) {
@@ -749,12 +755,12 @@ void cmd_ndop(char *cmdbuf)
 
        if (CC->download_fp != NULL) {
                cprintf("%d You already have a download file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
 
        snprintf(pathname, sizeof pathname, "%s/network/spoolout/%s",
-                BBSDIR, CC->net_node);
+                CTDLDIR, CC->net_node);
 
        /* first open the file in append mode in order to create a
         * zero-length file if it doesn't already exist 
@@ -767,7 +773,7 @@ void cmd_ndop(char *cmdbuf)
        CC->download_fp = fopen(pathname, "r");
        if (CC->download_fp == NULL) {
                cprintf("%d cannot open %s: %s\n",
-                       ERROR, pathname, strerror(errno));
+                       ERROR + INTERNAL_ERROR, pathname, strerror(errno));
                return;
        }
 
@@ -796,13 +802,13 @@ void cmd_nuop(char *cmdbuf)
 
        if (CC->upload_fp != NULL) {
                cprintf("%d You already have an upload file open.\n",
-                       ERROR);
+                       ERROR + RESOURCE_BUSY);
                return;
        }
 
        snprintf(CC->upl_path, sizeof CC->upl_path,
                 "%s/network/spoolin/%s.%04lx.%04x",
-                BBSDIR, CC->net_node, (long)getpid(), ++seq);
+                CTDLDIR, CC->net_node, (long)getpid(), ++seq);
 
        CC->upload_fp = fopen(CC->upl_path, "r");
        if (CC->upload_fp != NULL) {
@@ -816,7 +822,7 @@ void cmd_nuop(char *cmdbuf)
        CC->upload_fp = fopen(CC->upl_path, "w");
        if (CC->upload_fp == NULL) {
                cprintf("%d Cannot open %s: %s\n",
-                       ERROR, CC->upl_path, strerror(errno));
+                       ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno));
                return;
        }