X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fctdlproto%2Fserv_file.c;h=9af465e4d2648386352b6305eef523018cbd5f8a;hb=dc48bee02071eb3eb2f535e203c36c528e1547a8;hp=92dd92d49af37e046e916305dc92518c794b486a;hpb=5c39ca8a3c875df98163fed8923c258f21bb3f66;p=citadel.git diff --git a/citadel/modules/ctdlproto/serv_file.c b/citadel/modules/ctdlproto/serv_file.c index 92dd92d49..9af465e4d 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-2017 by the citadel.org team + * Copyright (c) 1987-2018 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. @@ -347,7 +347,6 @@ void cmd_uimg(char *cmdbuf) return; } cprintf("%d Ok\n", CIT_OK); - CC->upload_type = UPL_IMAGE; } @@ -356,8 +355,6 @@ void cmd_uimg(char *cmdbuf) */ void cmd_clos(char *cmdbuf) { - char buf[256]; - if (CC->download_fp == NULL) { cprintf("%d You don't have a download file open.\n", ERROR + RESOURCE_NOT_OPEN); return; @@ -365,13 +362,6 @@ void cmd_clos(char *cmdbuf) fclose(CC->download_fp); CC->download_fp = NULL; - - if (CC->dl_is_net == 1) { - CC->dl_is_net = 0; - snprintf(buf, sizeof buf, "%s/%s", ctdl_netout_dir, CC->net_node); - unlink(buf); - } - cprintf("%d Ok\n", CIT_OK); } @@ -394,65 +384,41 @@ void abort_upl(CitContext *who) */ void cmd_ucls(char *cmd) { - struct CitContext *CCC = CC; FILE *fp; - char upload_notice[512]; - static int seq = 0; + char upload_notice[SIZ]; - if (CCC->upload_fp == NULL) { + if (CC->upload_fp == NULL) { cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN); return; } fclose(CC->upload_fp); - CCC->upload_fp = NULL; - - if ((!strcasecmp(cmd, "1")) && (CCC->upload_type != UPL_FILE)) { - cprintf("%d Upload completed.\n", CIT_OK); - - if (CCC->upload_type == UPL_NET) { - char final_filename[PATH_MAX]; - snprintf(final_filename, sizeof final_filename, "%s/%s.%04lx.%04x", ctdl_netin_dir, CCC->net_node, (long)getpid(), ++seq); - - if (link(CCC->upl_path, final_filename) == 0) { - syslog(LOG_INFO, "UCLS: updoaded %s", final_filename); - unlink(CCC->upl_path); - } - else { - syslog(LOG_INFO, "Cannot link %s to %s: %s", - CCC->upl_path, final_filename, strerror(errno) - ); - } - } - - CCC->upload_type = UPL_FILE; - return; - } + CC->upload_fp = NULL; if (!strcasecmp(cmd, "1")) { - cprintf("%d File '%s' saved.\n", CIT_OK, CCC->upl_path); - fp = fopen(CCC->upl_filedir, "a"); + cprintf("%d File '%s' saved.\n", CIT_OK, CC->upl_path); + fp = fopen(CC->upl_filedir, "a"); if (fp == NULL) { - fp = fopen(CCC->upl_filedir, "w"); + fp = fopen(CC->upl_filedir, "w"); } if (fp != NULL) { - fprintf(fp, "%s %s %s\n", CCC->upl_file, CCC->upl_mimetype, CCC->upl_comment); + fprintf(fp, "%s %s %s\n", CC->upl_file, CC->upl_mimetype, CC->upl_comment); fclose(fp); } - if ((CCC->room.QRflags2 & QR2_NOUPLMSG) == 0) { + if ((CC->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); + CC->upl_file, + CC->upl_comment, + CC->upl_mimetype + ); + quickie_message(CC->curr_user, NULL, NULL, CC->room.QRname, upload_notice, 0, NULL); } } else { - abort_upl(CCC); - cprintf("%d File '%s' aborted.\n", CIT_OK, CCC->upl_path); + abort_upl(CC); + cprintf("%d File '%s' aborted.\n", CIT_OK, CC->upl_path); } } @@ -487,11 +453,11 @@ void cmd_read(char *cmdbuf) rc = fseek(CC->download_fp, start_pos, 0); if (rc < 0) { - cprintf("%d your file is smaller then %ld.\n", ERROR + ILLEGAL_VALUE, start_pos); - syslog(LOG_ERR, "your file %s is smaller then %ld. [%s]", - CC->upl_path, - start_pos, - strerror(errno) + cprintf("%d your file is smaller than %ld.\n", ERROR + ILLEGAL_VALUE, start_pos); + syslog(LOG_ERR, "serv_file: your file %s is smaller than %ld [%s]", + CC->upl_path, + start_pos, + strerror(errno) ); return; @@ -540,111 +506,12 @@ void cmd_writ(char *cmdbuf) client_read(buf, bytes); rv = fwrite(buf, bytes, 1, CCC->upload_fp); if (rv == -1) { - syslog(LOG_EMERG, "Couldn't write: %s", strerror(errno)); + syslog(LOG_ERR, "serv_file: %s", strerror(errno)); } free(buf); } -/* - * cmd_ndop() - open a network spool file for downloading - */ -void cmd_ndop(char *cmdbuf) -{ - struct CitContext *CCC = CC; - char pathname[256]; - struct stat statbuf; - - if (IsEmptyStr(CCC->net_node)) { - cprintf("%d Not authenticated as a network node.\n", - ERROR + NOT_LOGGED_IN); - return; - } - - if (CCC->download_fp != NULL) { - cprintf("%d You already have a download file open.\n", - ERROR + RESOURCE_BUSY); - return; - } - - snprintf(pathname, sizeof pathname, - "%s/%s", - ctdl_netout_dir, - CCC->net_node); - - /* first open the file in append mode in order to create a - * zero-length file if it doesn't already exist - */ - CCC->download_fp = fopen(pathname, "a"); - if (CCC->download_fp != NULL) - fclose(CCC->download_fp); - - /* now open it */ - 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; - } - - - /* set this flag so other routines know that the download file - * currently open is a network spool file - */ - CCC->dl_is_net = 1; - - stat(pathname, &statbuf); - CCC->download_fp_total = statbuf.st_size; - cprintf("%d %ld\n", CIT_OK, (long)statbuf.st_size); -} - - -/* - * cmd_nuop() - open a network spool file for uploading - */ -void cmd_nuop(char *cmdbuf) -{ - static int seq = 1; - - if (IsEmptyStr(CC->net_node)) { - cprintf("%d Not authenticated as a network node.\n", - ERROR + NOT_LOGGED_IN); - return; - } - - if (CC->upload_fp != NULL) { - cprintf("%d You already have an upload file open.\n", - ERROR + RESOURCE_BUSY); - return; - } - - snprintf(CC->upl_path, sizeof CC->upl_path, - "%s/%s.%04lx.%04x", - ctdl_nettmp_dir, - CC->net_node, - (long)getpid(), - ++seq - ); - - CC->upload_fp = fopen(CC->upl_path, "r"); - if (CC->upload_fp != NULL) { - fclose(CC->upload_fp); - CC->upload_fp = NULL; - cprintf("%d '%s' already exists\n", ERROR + ALREADY_EXISTS, CC->upl_path); - return; - } - - CC->upload_fp = fopen(CC->upl_path, "w"); - if (CC->upload_fp == NULL) { - cprintf("%d Cannot open %s: %s\n", ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno)); - return; - } - - CC->upload_type = UPL_NET; - cprintf("%d Ok\n", CIT_OK); -} - - void files_logout_hook(void) { CitContext *CCC = MyContext(); @@ -741,7 +608,7 @@ void cmd_mesg(char *mname) ERROR + FILE_NOT_FOUND, targ, strerror(errno)); return; } - cprintf("%d %s\n", LISTING_FOLLOWS,buf); + cprintf("%d %s\n", LISTING_FOLLOWS, buf); while (fgets(buf, (sizeof buf - 1), mfp) != NULL) { buf[strlen(buf)-1] = 0; @@ -808,8 +675,6 @@ CTDL_MODULE_INIT(file_ops) CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Close an upload file transfer"); CtdlRegisterProtoHook(cmd_read, "READ", "File transfer read operation"); CtdlRegisterProtoHook(cmd_writ, "WRIT", "File transfer write operation"); - CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Open a network spool file for download"); - CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Open a network spool file for upload"); CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Open an image file for download"); CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Upload an image file"); CtdlRegisterProtoHook(cmd_mesg, "MESG", "fetch system banners");