#include "snprintf.h"
#endif
+#include "ctdl_module.h"
+
/*
* network_talking_to() -- concurrency checker
*/
return;
}
for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
- if (filename[a] == '/') {
+ if ( (filename[a] == '/') || (filename[a] == '\\') ) {
filename[a] = '_';
}
}
char buf[PATH_MAX];
int a;
struct ctdlroom qrbuf;
+ int rv = 0;
extract_token(filename, cmdbuf, 0, '|', sizeof filename);
extract_token(newroom, cmdbuf, 1, '|', sizeof newroom);
}
for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
- if (filename[a] == '/') {
+ if ( (filename[a] == '/') || (filename[a] == '\\') ) {
filename[a] = '_';
}
}
return;
}
- if (getroom(&qrbuf, newroom) != 0) {
+ if (CtdlGetRoom(&qrbuf, newroom) != 0) {
cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, newroom);
return;
}
snprintf(buf, sizeof buf,
"cat ./files/%s/filedir |grep \"%s\" >>./files/%s/filedir",
CC->room.QRdirname, filename, qrbuf.QRdirname);
- system(buf);
+ rv = system(buf);
cprintf("%d File '%s' has been moved.\n", CIT_OK, filename);
}
-/*
- * send a file over the net
- */
-void cmd_netf(char *cmdbuf)
-{
- 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_token(filename, cmdbuf, 0, '|', sizeof filename);
- extract_token(destsys, cmdbuf, 1, '|', sizeof destsys);
-
- if (CtdlAccessCheck(ac_room_aide)) return;
-
- if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
- cprintf("%d No directory in this room.\n",
- ERROR + NOT_HERE);
- return;
- }
-
- if (IsEmptyStr(filename)) {
- cprintf("%d You must specify a file name.\n",
- ERROR + FILE_NOT_FOUND);
- return;
- }
-
- for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
- if (filename[a] == '/') {
- filename[a] = '_';
- }
- }
- snprintf(pathname, sizeof pathname, "./files/%s/%s",
- CC->room.QRdirname, filename);
- if (access(pathname, 0) != 0) {
- cprintf("%d File '%s' not found.\n",
- ERROR + FILE_NOT_FOUND, pathname);
- return;
- }
- snprintf(buf, sizeof buf, "sysop@%s", destsys);
- e = alias(buf);
- if (e != MES_IGNET) {
- cprintf("%d No such system: '%s'\n",
- ERROR + NO_SUCH_SYSTEM, destsys);
- return;
- }
- snprintf(outfile, sizeof outfile,
- "%s/nsf.%04lx.%04x",
- ctdl_netin_dir,
- (long)getpid(), ++seq);
- ofp = fopen(outfile, "a");
- if (ofp == NULL) {
- cprintf("%d internal error\n", ERROR + INTERNAL_ERROR);
- return;
- }
-
- putc(255, ofp);
- putc(MES_NORMAL, ofp);
- putc(0, ofp);
- fprintf(ofp, "P%s", CC->user.fullname);
- putc(0, ofp);
- time(&now);
- fprintf(ofp, "T%ld", (long) now);
- putc(0, ofp);
- fprintf(ofp, "A%s", CC->user.fullname);
- putc(0, ofp);
- fprintf(ofp, "O%s", CC->room.QRname);
- putc(0, ofp);
- fprintf(ofp, "N%s", NODENAME);
- putc(0, ofp);
- fprintf(ofp, "D%s", destsys);
- putc(0, ofp);
- fprintf(ofp, "SFILE");
- putc(0, ofp);
- putc('M', ofp);
- fclose(ofp);
-
- snprintf(buf, sizeof buf,
- "cd %s/%s; uuencode %s <%s 2>/dev/null >>%s",
- ctdl_file_dir,
- /* FIXME: detect uuencode while installation? or inline */
- CC->room.QRdirname, filename, filename, outfile);
- system(buf);
-
- ofp = fopen(outfile, "a");
- putc(0, ofp);
- fclose(ofp);
-
- cprintf("%d File '%s' has been sent to %s.\n", CIT_OK, filename,
- destsys);
- /* FIXME start a network run here. */
- return;
-}
-
/*
* This code is common to all commands which open a file for downloading,
* regardless of whether it's a file from the directory, an image, a network
}
for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
- if (filename[a] == '/') {
+ if ( (filename[a] == '/') || (filename[a] == '\\') ) {
filename[a] = '_';
}
}
char which_user[USERNAME_SIZE];
int which_floor;
int a;
+ int rv;
extract_token(filename, cmdbuf, 0, '|', sizeof filename);
if (!strcasecmp(filename, "_userpic_")) {
extract_token(which_user, cmdbuf, 1, '|', sizeof which_user);
- if (getuser(&usbuf, which_user) != 0) {
+ if (CtdlGetUser(&usbuf, which_user) != 0) {
cprintf("%d No such user.\n",
ERROR + NO_SUCH_USER);
return;
} else {
for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
filename[a] = tolower(filename[a]);
- if (filename[a] == '/') {
+ if ( (filename[a] == '/') || (filename[a] == '\\') ) {
filename[a] = '_';
}
}
ERROR + FILE_NOT_FOUND, pathname, strerror(errno));
return;
}
- fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
+ rv = fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
rewind (CC->download_fp);
OpenCmdResult(pathname, GuessMimeType(&MimeTestBuf[0], 32));
}
}
for (a = 0; !IsEmptyStr(&CC->upl_file[a]); ++a) {
- if (CC->upl_file[a] == '/') {
+ if ( (CC->upl_file[a] == '/') || (CC->upl_file[a] == '\\') ) {
CC->upl_file[a] = '_';
}
}
for (a = 0; !IsEmptyStr(&basenm[a]); ++a) {
basenm[a] = tolower(basenm[a]);
- if (basenm[a] == '/') {
+ if ( (basenm[a] == '/') || (basenm[a] == '\\') ) {
basenm[a] = '_';
}
}
/*
* close the download file
*/
-void cmd_clos(void)
+void cmd_clos(char *cmdbuf)
{
char buf[256];
/*
* abort an upload
*/
-void abort_upl(struct CitContext *who)
+void abort_upl(CitContext *who)
{
if (who->upload_fp != NULL) {
fclose(who->upload_fp);
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);
+ if (actual_bytes > 0) {
+ cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
+ client_write(buf, bytes);
+ }
+ else {
+ cprintf("%d %s\n", ERROR, strerror(errno));
+ }
free(buf);
}
{
int bytes;
char *buf;
+ int rv;
unbuffer_output();
cprintf("%d %d\n", SEND_BINARY, bytes);
buf = malloc(bytes + 1);
client_read(buf, bytes);
- fwrite(buf, bytes, 1, CC->upload_fp);
+ rv = fwrite(buf, bytes, 1, CC->upload_fp);
free(buf);
}
CC->upload_type = UPL_NET;
cprintf("%d Ok\n", CIT_OK);
}
+
+
+/*****************************************************************************/
+/* MODULE INITIALIZATION STUFF */
+/*****************************************************************************/
+
+CTDL_MODULE_INIT(file_ops)
+{
+ if (!threading) {
+ CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
+ CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
+ }
+ /* return our Subversion id for the Log */
+ return "$Id$";
+}