X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fctdlproto%2Fserv_file.c;h=2358507995be413a249c2d876c28332f00fd25ed;hb=d1dcc57fd3286c9e38b7f15eb2fb047279232628;hp=50661c7c75d64187e97edcdbef00a4d88fcc4bce;hpb=7c94d5bb68f1c448770d31205ec5ae12bd8a02ed;p=citadel.git diff --git a/citadel/modules/ctdlproto/serv_file.c b/citadel/modules/ctdlproto/serv_file.c index 50661c7c7..235850799 100644 --- a/citadel/modules/ctdlproto/serv_file.c +++ b/citadel/modules/ctdlproto/serv_file.c @@ -1,7 +1,7 @@ /* * Server functions which handle file transfers and room directories. * - * Copyright (c) 1987-2015 by the citadel.org team + * Copyright (c) 1987-2016 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. @@ -223,12 +223,9 @@ void cmd_open(char *cmdbuf) */ void cmd_oimg(char *cmdbuf) { - char filename[256]; + char filename[PATH_MAX]; char pathname[PATH_MAX]; char MimeTestBuf[32]; - struct ctdluser usbuf; - char which_user[USERNAME_SIZE]; - int which_floor; int a; int rv; @@ -246,25 +243,10 @@ void cmd_oimg(char *cmdbuf) return; } - if (!strcasecmp(filename, "_userpic_")) { - extract_token(which_user, cmdbuf, 1, '|', sizeof which_user); - if (CtdlGetUser(&usbuf, which_user) != 0) { - cprintf("%d No such user.\n", - ERROR + NO_SUCH_USER); - return; - } - snprintf(pathname, sizeof pathname, - "%s/%ld", - ctdl_usrpic_dir, - usbuf.usernum); - } else if (!strcasecmp(filename, "_floorpic_")) { - which_floor = extract_int(cmdbuf, 1); - snprintf(pathname, sizeof pathname, - "%s/floor.%d", - ctdl_image_dir, which_floor); - } else if (!strcasecmp(filename, "_roompic_")) { + if (!strcasecmp(filename, "_roompic_")) { assoc_file_name(pathname, sizeof pathname, &CC->room, ctdl_image_dir); - } else { + } + else { for (a = 0; !IsEmptyStr(&filename[a]); ++a) { filename[a] = tolower(filename[a]); if ( (filename[a] == '/') || (filename[a] == '\\') ) { @@ -305,6 +287,7 @@ void cmd_oimg(char *cmdbuf) OpenCmdResult(pathname, GuessMimeType(&MimeTestBuf[0], 32)); } + /* * open a file for uploading */ @@ -377,7 +360,6 @@ void cmd_uimg(char *cmdbuf) { int is_this_for_real; char basenm[256]; - int which_floor; int a; if (num_parms(cmdbuf) < 2) { @@ -410,22 +392,6 @@ void cmd_uimg(char *cmdbuf) basenm); } - if (!strcasecmp(basenm, "_userpic_")) { - snprintf(CC->upl_path, sizeof CC->upl_path, - "%s/%ld.gif", - ctdl_usrpic_dir, - CC->user.usernum); - } - - if ((!strcasecmp(basenm, "_floorpic_")) - && (CC->user.axlevel >= AxAideU)) { - which_floor = extract_int(cmdbuf, 2); - snprintf(CC->upl_path, sizeof CC->upl_path, - "%s/floor.%d.gif", - ctdl_image_dir, - which_floor); - } - if ((!strcasecmp(basenm, "_roompic_")) && (is_room_aide())) { assoc_file_name(CC->upl_path, sizeof CC->upl_path, &CC->room, ctdl_image_dir); } @@ -500,39 +466,40 @@ void abort_upl(CitContext *who) */ void cmd_ucls(char *cmd) { + struct CitContext *CCC = CC; FILE *fp; char upload_notice[512]; static int seq = 0; - if (CC->upload_fp == NULL) { + if (CCC->upload_fp == NULL) { cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN); return; } fclose(CC->upload_fp); - CC->upload_fp = NULL; + CCC->upload_fp = NULL; - if ((!strcasecmp(cmd, "1")) && (CC->upload_type != UPL_FILE)) { + if ((!strcasecmp(cmd, "1")) && (CCC->upload_type != UPL_FILE)) { cprintf("%d Upload completed.\n", CIT_OK); - if (CC->upload_type == UPL_NET) { + if (CCC->upload_type == UPL_NET) { char final_filename[PATH_MAX]; snprintf(final_filename, sizeof final_filename, "%s/%s.%04lx.%04x", ctdl_netin_dir, - CC->net_node, + CCC->net_node, (long)getpid(), ++seq ); - if (link(CC->upl_path, final_filename) == 0) { - syslog(LOG_INFO, "UCLS: updoaded %s\n", + if (link(CCC->upl_path, final_filename) == 0) { + CTDL_syslog(LOG_INFO, "UCLS: updoaded %s", final_filename); - unlink(CC->upl_path); + unlink(CCC->upl_path); } else { - syslog(LOG_ALERT, "Cannot link %s to %s: %s\n", - CC->upl_path, final_filename, strerror(errno) + CTDL_syslog(LOG_INFO, "Cannot link %s to %s: %s", + CCC->upl_path, final_filename, strerror(errno) ); } @@ -540,34 +507,36 @@ void cmd_ucls(char *cmd) /* FIXME ... here we need to trigger a network run */ } - CC->upload_type = UPL_FILE; + CCC->upload_type = UPL_FILE; return; } if (!strcasecmp(cmd, "1")) { - cprintf("%d File '%s' saved.\n", CIT_OK, CC->upl_path); - fp = fopen(CC->upl_filedir, "a"); + cprintf("%d File '%s' saved.\n", CIT_OK, CCC->upl_path); + fp = fopen(CCC->upl_filedir, "a"); if (fp == NULL) { - fp = fopen(CC->upl_filedir, "w"); + fp = fopen(CCC->upl_filedir, "w"); } if (fp != NULL) { - fprintf(fp, "%s %s %s\n", CC->upl_file, - CC->upl_mimetype, - CC->upl_comment); + fprintf(fp, "%s %s %s\n", CCC->upl_file, + CCC->upl_mimetype, + CCC->upl_comment); fclose(fp); } - /* put together an upload notice */ - snprintf(upload_notice, sizeof upload_notice, - "NEW UPLOAD: '%s'\n %s\n%s\n", - CC->upl_file, - CC->upl_comment, - CC->upl_mimetype); - quickie_message(CC->curr_user, NULL, NULL, CC->room.QRname, - upload_notice, 0, NULL); + if ((CCC->room.QRflags2 & QR2_NOUPLMSG) == 0) { + /* put together an upload notice */ + snprintf(upload_notice, sizeof upload_notice, + "NEW UPLOAD: '%s'\n %s\n%s\n", + CCC->upl_file, + CCC->upl_comment, + CCC->upl_mimetype); + quickie_message(CCC->curr_user, NULL, NULL, CCC->room.QRname, + upload_notice, 0, NULL); + } } else { - abort_upl(CC); - cprintf("%d File '%s' aborted.\n", CIT_OK, CC->upl_path); + abort_upl(CCC); + cprintf("%d File '%s' aborted.\n", CIT_OK, CCC->upl_path); } } @@ -603,11 +572,12 @@ void cmd_read(char *cmdbuf) rc = fseek(CC->download_fp, start_pos, 0); if (rc < 0) { + struct CitContext *CCC = CC; cprintf("%d your file is smaller then %ld.\n", ERROR + ILLEGAL_VALUE, start_pos); - syslog(LOG_ALERT, "your file %s is smaller then %ld. [%s]\n", - CC->upl_path, - start_pos, - strerror(errno)); + CTDL_syslog(LOG_ERR, "your file %s is smaller then %ld. [%s]\n", + CC->upl_path, + start_pos, + strerror(errno)); return; } @@ -628,6 +598,7 @@ void cmd_read(char *cmdbuf) */ void cmd_writ(char *cmdbuf) { + struct CitContext *CCC = CC; int bytes; char *buf; int rv; @@ -636,7 +607,7 @@ void cmd_writ(char *cmdbuf) bytes = extract_int(cmdbuf, 0); - if (CC->upload_fp == NULL) { + if (CCC->upload_fp == NULL) { cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN); return; } @@ -652,10 +623,10 @@ void cmd_writ(char *cmdbuf) cprintf("%d %d\n", SEND_BINARY, bytes); buf = malloc(bytes + 1); client_read(buf, bytes); - rv = fwrite(buf, bytes, 1, CC->upload_fp); + rv = fwrite(buf, bytes, 1, CCC->upload_fp); if (rv == -1) { - syslog(LOG_EMERG, "Couldn't write: %s\n", - strerror(errno)); + CTDL_syslog(LOG_EMERG, "Couldn't write: %s\n", + strerror(errno)); } free(buf); } @@ -668,16 +639,17 @@ void cmd_writ(char *cmdbuf) */ void cmd_ndop(char *cmdbuf) { + struct CitContext *CCC = CC; char pathname[256]; struct stat statbuf; - if (IsEmptyStr(CC->net_node)) { + if (IsEmptyStr(CCC->net_node)) { cprintf("%d Not authenticated as a network node.\n", ERROR + NOT_LOGGED_IN); return; } - if (CC->download_fp != NULL) { + if (CCC->download_fp != NULL) { cprintf("%d You already have a download file open.\n", ERROR + RESOURCE_BUSY); return; @@ -686,18 +658,18 @@ void cmd_ndop(char *cmdbuf) snprintf(pathname, sizeof pathname, "%s/%s", ctdl_netout_dir, - CC->net_node); + CCC->net_node); /* first open the file in append mode in order to create a * zero-length file if it doesn't already exist */ - CC->download_fp = fopen(pathname, "a"); - if (CC->download_fp != NULL) - fclose(CC->download_fp); + CCC->download_fp = fopen(pathname, "a"); + if (CCC->download_fp != NULL) + fclose(CCC->download_fp); /* now open it */ - CC->download_fp = fopen(pathname, "r"); - if (CC->download_fp == NULL) { + CCC->download_fp = fopen(pathname, "r"); + if (CCC->download_fp == NULL) { cprintf("%d cannot open %s: %s\n", ERROR + INTERNAL_ERROR, pathname, strerror(errno)); return; @@ -707,10 +679,10 @@ void cmd_ndop(char *cmdbuf) /* set this flag so other routines know that the download file * currently open is a network spool file */ - CC->dl_is_net = 1; + CCC->dl_is_net = 1; stat(pathname, &statbuf); - CC->download_fp_total = statbuf.st_size; + CCC->download_fp_total = statbuf.st_size; cprintf("%d %ld\n", CIT_OK, (long)statbuf.st_size); }