* give all commands their own function
[citadel.git] / citadel / file_ops.c
1 /* 
2  * $Id$
3  *
4  * Server functions which handle file transfers and room directories.
5  *
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <sys/stat.h>
14 #include <errno.h>
15 #include <ctype.h>
16 #include <string.h>
17 #include <sys/stat.h>
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #include <limits.h>
31 #include <libcitadel.h>
32 #include "citadel.h"
33 #include "server.h"
34 #include "config.h"
35 #include "file_ops.h"
36 #include "sysdep_decls.h"
37 #include "user_ops.h"
38 #include "support.h"
39 #include "room_ops.h"
40 #include "msgbase.h"
41 #include "citserver.h"
42 #include "threads.h"
43
44 #ifndef HAVE_SNPRINTF
45 #include "snprintf.h"
46 #endif
47
48 #include "ctdl_module.h"
49
50 /*
51  * network_talking_to()  --  concurrency checker
52  */
53 int network_talking_to(char *nodename, int operation) {
54
55         static char *nttlist = NULL;
56         char *ptr = NULL;
57         int i;
58         char buf[SIZ];
59         int retval = 0;
60
61         begin_critical_section(S_NTTLIST);
62
63         switch(operation) {
64
65                 case NTT_ADD:
66                         if (nttlist == NULL) nttlist = strdup("");
67                         if (nttlist == NULL) break;
68                         nttlist = (char *)realloc(nttlist,
69                                 (strlen(nttlist) + strlen(nodename) + 3) );
70                         strcat(nttlist, "|");
71                         strcat(nttlist, nodename);
72                         break;
73
74                 case NTT_REMOVE:
75                         if (nttlist == NULL) break;
76                         if (IsEmptyStr(nttlist)) break;
77                         ptr = malloc(strlen(nttlist));
78                         if (ptr == NULL) break;
79                         strcpy(ptr, "");
80                         for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
81                                 extract_token(buf, nttlist, i, '|', sizeof buf);
82                                 if ( (!IsEmptyStr(buf))
83                                      && (strcasecmp(buf, nodename)) ) {
84                                                 strcat(ptr, buf);
85                                                 strcat(ptr, "|");
86                                 }
87                         }
88                         free(nttlist);
89                         nttlist = ptr;
90                         break;
91
92                 case NTT_CHECK:
93                         if (nttlist == NULL) break;
94                         if (IsEmptyStr(nttlist)) break;
95                         for (i = 0; i < num_tokens(nttlist, '|'); ++i) {
96                                 extract_token(buf, nttlist, i, '|', sizeof buf);
97                                 if (!strcasecmp(buf, nodename)) ++retval;
98                         }
99                         break;
100         }
101
102         if (nttlist != NULL) CtdlLogPrintf(CTDL_DEBUG, "nttlist=<%s>\n", nttlist);
103         end_critical_section(S_NTTLIST);
104         return(retval);
105 }
106
107
108
109
110 /*
111  * Server command to delete a file from a room's directory
112  */
113 void cmd_delf(char *filename)
114 {
115         char pathname[64];
116         int a;
117
118         if (CtdlAccessCheck(ac_room_aide))
119                 return;
120
121         if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
122                 cprintf("%d No directory in this room.\n",
123                         ERROR + NOT_HERE);
124                 return;
125         }
126
127         if (IsEmptyStr(filename)) {
128                 cprintf("%d You must specify a file name.\n",
129                         ERROR + FILE_NOT_FOUND);
130                 return;
131         }
132         for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
133                 if ( (filename[a] == '/') || (filename[a] == '\\') ) {
134                         filename[a] = '_';
135                 }
136         }
137         snprintf(pathname, sizeof pathname,
138                          "%s/%s/%s",
139                          ctdl_file_dir,
140                          CC->room.QRdirname, filename);
141         a = unlink(pathname);
142         if (a == 0) {
143                 cprintf("%d File '%s' deleted.\n", CIT_OK, pathname);
144         }
145         else {
146                 cprintf("%d File '%s' not found.\n",
147                         ERROR + FILE_NOT_FOUND, pathname);
148         }
149 }
150
151
152
153
154 /*
155  * move a file from one room directory to another
156  */
157 void cmd_movf(char *cmdbuf)
158 {
159         char filename[PATH_MAX];
160         char pathname[PATH_MAX];
161         char newpath[PATH_MAX];
162         char newroom[ROOMNAMELEN];
163         char buf[PATH_MAX];
164         int a;
165         struct ctdlroom qrbuf;
166
167         extract_token(filename, cmdbuf, 0, '|', sizeof filename);
168         extract_token(newroom, cmdbuf, 1, '|', sizeof newroom);
169
170         if (CtdlAccessCheck(ac_room_aide)) return;
171
172         if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
173                 cprintf("%d No directory in this room.\n",
174                         ERROR + NOT_HERE);
175                 return;
176         }
177
178         if (IsEmptyStr(filename)) {
179                 cprintf("%d You must specify a file name.\n",
180                         ERROR + FILE_NOT_FOUND);
181                 return;
182         }
183
184         for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
185                 if ( (filename[a] == '/') || (filename[a] == '\\') ) {
186                         filename[a] = '_';
187                 }
188         }
189         snprintf(pathname, sizeof pathname, "./files/%s/%s",
190                  CC->room.QRdirname, filename);
191         if (access(pathname, 0) != 0) {
192                 cprintf("%d File '%s' not found.\n",
193                         ERROR + FILE_NOT_FOUND, pathname);
194                 return;
195         }
196
197         if (getroom(&qrbuf, newroom) != 0) {
198                 cprintf("%d '%s' does not exist.\n", ERROR + ROOM_NOT_FOUND, newroom);
199                 return;
200         }
201         if ((qrbuf.QRflags & QR_DIRECTORY) == 0) {
202                 cprintf("%d '%s' is not a directory room.\n",
203                         ERROR + NOT_HERE, qrbuf.QRname);
204                 return;
205         }
206         snprintf(newpath, sizeof newpath, "./files/%s/%s", qrbuf.QRdirname,
207                  filename);
208         if (link(pathname, newpath) != 0) {
209                 cprintf("%d Couldn't move file: %s\n", ERROR + INTERNAL_ERROR,
210                         strerror(errno));
211                 return;
212         }
213         unlink(pathname);
214
215         /* this is a crude method of copying the file description */
216         snprintf(buf, sizeof buf,
217                  "cat ./files/%s/filedir |grep \"%s\" >>./files/%s/filedir",
218                  CC->room.QRdirname, filename, qrbuf.QRdirname);
219         system(buf);
220         cprintf("%d File '%s' has been moved.\n", CIT_OK, filename);
221 }
222
223
224 /*
225  * This code is common to all commands which open a file for downloading,
226  * regardless of whether it's a file from the directory, an image, a network
227  * spool file, a MIME attachment, etc.
228  * It examines the file and displays the OK result code and some information
229  * about the file.  NOTE: this stuff is Unix dependent.
230  */
231 void OpenCmdResult(char *filename, const char *mime_type)
232 {
233         struct stat statbuf;
234         time_t modtime;
235         long filesize;
236
237         fstat(fileno(CC->download_fp), &statbuf);
238         filesize = (long) statbuf.st_size;
239         modtime = (time_t) statbuf.st_mtime;
240
241         cprintf("%d %ld|%ld|%s|%s\n",
242                 CIT_OK, filesize, (long)modtime, filename, mime_type);
243 }
244
245
246 /*
247  * open a file for downloading
248  */
249 void cmd_open(char *cmdbuf)
250 {
251         char filename[256];
252         char pathname[PATH_MAX];
253         int a;
254
255         extract_token(filename, cmdbuf, 0, '|', sizeof filename);
256
257         if (CtdlAccessCheck(ac_logged_in)) return;
258
259         if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
260                 cprintf("%d No directory in this room.\n",
261                         ERROR + NOT_HERE);
262                 return;
263         }
264
265         if (IsEmptyStr(filename)) {
266                 cprintf("%d You must specify a file name.\n",
267                         ERROR + FILE_NOT_FOUND);
268                 return;
269         }
270
271         if (CC->download_fp != NULL) {
272                 cprintf("%d You already have a download file open.\n",
273                         ERROR + RESOURCE_BUSY);
274                 return;
275         }
276
277         for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
278                 if ( (filename[a] == '/') || (filename[a] == '\\') ) {
279                         filename[a] = '_';
280                 }
281         }
282
283         snprintf(pathname, sizeof pathname,
284                          "%s/%s/%s",
285                          ctdl_file_dir,
286                          CC->room.QRdirname, filename);
287         CC->download_fp = fopen(pathname, "r");
288
289         if (CC->download_fp == NULL) {
290                 cprintf("%d cannot open %s: %s\n",
291                         ERROR + INTERNAL_ERROR, pathname, strerror(errno));
292                 return;
293         }
294
295         OpenCmdResult(filename, "application/octet-stream");
296 }
297
298 /*
299  * open an image file
300  */
301 void cmd_oimg(char *cmdbuf)
302 {
303         char filename[256];
304         char pathname[PATH_MAX];
305         char MimeTestBuf[32];
306         struct ctdluser usbuf;
307         char which_user[USERNAME_SIZE];
308         int which_floor;
309         int a;
310
311         extract_token(filename, cmdbuf, 0, '|', sizeof filename);
312
313         if (IsEmptyStr(filename)) {
314                 cprintf("%d You must specify a file name.\n",
315                         ERROR + FILE_NOT_FOUND);
316                 return;
317         }
318
319         if (CC->download_fp != NULL) {
320                 cprintf("%d You already have a download file open.\n",
321                         ERROR + RESOURCE_BUSY);
322                 return;
323         }
324
325         if (!strcasecmp(filename, "_userpic_")) {
326                 extract_token(which_user, cmdbuf, 1, '|', sizeof which_user);
327                 if (getuser(&usbuf, which_user) != 0) {
328                         cprintf("%d No such user.\n",
329                                 ERROR + NO_SUCH_USER);
330                         return;
331                 }
332                 snprintf(pathname, sizeof pathname, 
333                                  "%s/%ld",
334                                  ctdl_usrpic_dir,
335                                  usbuf.usernum);
336         } else if (!strcasecmp(filename, "_floorpic_")) {
337                 which_floor = extract_int(cmdbuf, 1);
338                 snprintf(pathname, sizeof pathname,
339                                  "%s/floor.%d",
340                                  ctdl_image_dir, which_floor);
341         } else if (!strcasecmp(filename, "_roompic_")) {
342                 assoc_file_name(pathname, sizeof pathname, &CC->room, ctdl_image_dir);
343         } else {
344                 for (a = 0; !IsEmptyStr(&filename[a]); ++a) {
345                         filename[a] = tolower(filename[a]);
346                         if ( (filename[a] == '/') || (filename[a] == '\\') ) {
347                                 filename[a] = '_';
348                         }
349                 }
350                 snprintf(pathname, sizeof pathname,
351                                  "%s/%s",
352                                  ctdl_image_dir,
353                                  filename);
354         }
355
356         CC->download_fp = fopen(pathname, "rb");
357         if (CC->download_fp == NULL) {
358                 strcat(pathname, ".gif");
359                 CC->download_fp = fopen(pathname, "rb");
360         }
361         if (CC->download_fp == NULL) {
362                 cprintf("%d Cannot open %s: %s\n",
363                         ERROR + FILE_NOT_FOUND, pathname, strerror(errno));
364                 return;
365         }
366         fread(&MimeTestBuf[0], 1, 32, CC->download_fp);
367         rewind (CC->download_fp);
368         OpenCmdResult(pathname, GuessMimeType(&MimeTestBuf[0], 32));
369 }
370
371 /*
372  * open a file for uploading
373  */
374 void cmd_uopn(char *cmdbuf)
375 {
376         int a;
377
378         extract_token(CC->upl_file, cmdbuf, 0, '|', sizeof CC->upl_file);
379         extract_token(CC->upl_mimetype, cmdbuf, 1, '|', sizeof CC->upl_mimetype);
380         extract_token(CC->upl_comment, cmdbuf, 2, '|', sizeof CC->upl_comment);
381
382         if (CtdlAccessCheck(ac_logged_in)) return;
383
384         if ((CC->room.QRflags & QR_DIRECTORY) == 0) {
385                 cprintf("%d No directory in this room.\n",
386                         ERROR + NOT_HERE);
387                 return;
388         }
389
390         if (IsEmptyStr(CC->upl_file)) {
391                 cprintf("%d You must specify a file name.\n",
392                         ERROR + FILE_NOT_FOUND);
393                 return;
394         }
395
396         if (CC->upload_fp != NULL) {
397                 cprintf("%d You already have a upload file open.\n",
398                         ERROR + RESOURCE_BUSY);
399                 return;
400         }
401
402         for (a = 0; !IsEmptyStr(&CC->upl_file[a]); ++a) {
403                 if ( (CC->upl_file[a] == '/') || (CC->upl_file[a] == '\\') ) {
404                         CC->upl_file[a] = '_';
405                 }
406         }
407         snprintf(CC->upl_path, sizeof CC->upl_path, 
408                          "%s/%s/%s",
409                          ctdl_file_dir,
410                          CC->room.QRdirname, CC->upl_file);
411         snprintf(CC->upl_filedir, sizeof CC->upl_filedir,
412                          "%s/%s/filedir", 
413                          ctdl_file_dir,
414                          CC->room.QRdirname);
415
416         CC->upload_fp = fopen(CC->upl_path, "r");
417         if (CC->upload_fp != NULL) {
418                 fclose(CC->upload_fp);
419                 CC->upload_fp = NULL;
420                 cprintf("%d '%s' already exists\n",
421                         ERROR + ALREADY_EXISTS, CC->upl_path);
422                 return;
423         }
424
425         CC->upload_fp = fopen(CC->upl_path, "wb");
426         if (CC->upload_fp == NULL) {
427                 cprintf("%d Cannot open %s: %s\n",
428                         ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno));
429                 return;
430         }
431         cprintf("%d Ok\n", CIT_OK);
432 }
433
434
435
436 /*
437  * open an image file for uploading
438  */
439 void cmd_uimg(char *cmdbuf)
440 {
441         int is_this_for_real;
442         char basenm[256];
443         int which_floor;
444         int a;
445
446         if (num_parms(cmdbuf) < 2) {
447                 cprintf("%d Usage error.\n", ERROR + ILLEGAL_VALUE);
448                 return;
449         }
450
451         is_this_for_real = extract_int(cmdbuf, 0);
452         extract_token(CC->upl_mimetype, cmdbuf, 1, '|', sizeof CC->upl_mimetype);
453         extract_token(basenm, cmdbuf, 2, '|', sizeof basenm);
454         if (CC->upload_fp != NULL) {
455                 cprintf("%d You already have an upload file open.\n",
456                         ERROR + RESOURCE_BUSY);
457                 return;
458         }
459
460         strcpy(CC->upl_path, "");
461
462         for (a = 0; !IsEmptyStr(&basenm[a]); ++a) {
463                 basenm[a] = tolower(basenm[a]);
464                 if ( (basenm[a] == '/') || (basenm[a] == '\\') ) {
465                         basenm[a] = '_';
466                 }
467         }
468
469         if (CC->user.axlevel >= 6) {
470                 snprintf(CC->upl_path, sizeof CC->upl_path, 
471                                  "%s/%s",
472                                  ctdl_image_dir,
473                                  basenm);
474         }
475
476         if (!strcasecmp(basenm, "_userpic_")) {
477                 snprintf(CC->upl_path, sizeof CC->upl_path,
478                                  "%s/%ld.gif",
479                                  ctdl_usrpic_dir,
480                                  CC->user.usernum);
481         }
482
483         if ((!strcasecmp(basenm, "_floorpic_"))
484             && (CC->user.axlevel >= 6)) {
485                 which_floor = extract_int(cmdbuf, 2);
486                 snprintf(CC->upl_path, sizeof CC->upl_path,
487                                  "%s/floor.%d.gif",
488                                  ctdl_image_dir,
489                                  which_floor);
490         }
491
492         if ((!strcasecmp(basenm, "_roompic_")) && (is_room_aide())) {
493                 assoc_file_name(CC->upl_path, sizeof CC->upl_path, &CC->room, ctdl_image_dir);
494         }
495
496         if (IsEmptyStr(CC->upl_path)) {
497                 cprintf("%d Higher access required.\n",
498                         ERROR + HIGHER_ACCESS_REQUIRED);
499                 return;
500         }
501
502         if (is_this_for_real == 0) {
503                 cprintf("%d Ok to send image\n", CIT_OK);
504                 return;
505         }
506
507         CC->upload_fp = fopen(CC->upl_path, "wb");
508         if (CC->upload_fp == NULL) {
509                 cprintf("%d Cannot open %s: %s\n",
510                         ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno));
511                 return;
512         }
513         cprintf("%d Ok\n", CIT_OK);
514         CC->upload_type = UPL_IMAGE;
515 }
516
517
518 /*
519  * close the download file
520  */
521 void cmd_clos(char *cmdbuf)
522 {
523         char buf[256];
524
525         if (CC->download_fp == NULL) {
526                 cprintf("%d You don't have a download file open.\n",
527                         ERROR + RESOURCE_NOT_OPEN);
528                 return;
529         }
530
531         fclose(CC->download_fp);
532         CC->download_fp = NULL;
533
534         if (CC->dl_is_net == 1) {
535                 CC->dl_is_net = 0;
536                 snprintf(buf, sizeof buf, 
537                                  "%s/%s",
538                                  ctdl_netout_dir,
539                                  CC->net_node);
540                 unlink(buf);
541         }
542
543         cprintf("%d Ok\n", CIT_OK);
544 }
545
546
547 /*
548  * abort an upload
549  */
550 void abort_upl(struct CitContext *who)
551 {
552         if (who->upload_fp != NULL) {
553                 fclose(who->upload_fp);
554                 who->upload_fp = NULL;
555                 unlink(CC->upl_path);
556         }
557 }
558
559
560
561 /*
562  * close the upload file
563  */
564 void cmd_ucls(char *cmd)
565 {
566         FILE *fp;
567         char upload_notice[512];
568
569         if (CC->upload_fp == NULL) {
570                 cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN);
571                 return;
572         }
573
574         fclose(CC->upload_fp);
575         CC->upload_fp = NULL;
576
577         if ((!strcasecmp(cmd, "1")) && (CC->upload_type != UPL_FILE)) {
578                 CC->upload_type = UPL_FILE;
579                 cprintf("%d Upload completed.\n", CIT_OK);
580
581                 /* FIXME ... here we need to trigger a network run */
582
583                 return;
584         }
585
586         if (!strcasecmp(cmd, "1")) {
587                 cprintf("%d File '%s' saved.\n", CIT_OK, CC->upl_path);
588                 fp = fopen(CC->upl_filedir, "a");
589                 if (fp == NULL) {
590                         fp = fopen(CC->upl_filedir, "w");
591                 }
592                 if (fp != NULL) {
593                         fprintf(fp, "%s %s %s\n", CC->upl_file,
594                                 CC->upl_mimetype,
595                                 CC->upl_comment);
596                         fclose(fp);
597                 }
598
599                 /* put together an upload notice */
600                 snprintf(upload_notice, sizeof upload_notice,
601                         "NEW UPLOAD: '%s'\n %s\n%s\n",
602                          CC->upl_file, 
603                          CC->upl_comment, 
604                          CC->upl_mimetype);
605                 quickie_message(CC->curr_user, NULL, NULL, CC->room.QRname,
606                                 upload_notice, 0, NULL);
607         } else {
608                 abort_upl(CC);
609                 cprintf("%d File '%s' aborted.\n", CIT_OK, CC->upl_path);
610         }
611 }
612
613
614
615 /*
616  * read from the download file
617  */
618 void cmd_read(char *cmdbuf)
619 {
620         long start_pos;
621         size_t bytes;
622         size_t actual_bytes;
623         char *buf = NULL;
624
625         start_pos = extract_long(cmdbuf, 0);
626         bytes = extract_int(cmdbuf, 1);
627
628         if (CC->download_fp == NULL) {
629                 cprintf("%d You don't have a download file open.\n",
630                         ERROR + RESOURCE_NOT_OPEN);
631                 return;
632         }
633
634         if (bytes > 100000) bytes = 100000;
635         buf = malloc(bytes + 1);
636
637         fseek(CC->download_fp, start_pos, 0);
638         actual_bytes = fread(buf, 1, bytes, CC->download_fp);
639         cprintf("%d %d\n", BINARY_FOLLOWS, (int)actual_bytes);
640         client_write(buf, actual_bytes);
641         free(buf);
642 }
643
644
645
646 /*
647  * write to the upload file
648  */
649 void cmd_writ(char *cmdbuf)
650 {
651         int bytes;
652         char *buf;
653
654         unbuffer_output();
655
656         bytes = extract_int(cmdbuf, 0);
657
658         if (CC->upload_fp == NULL) {
659                 cprintf("%d You don't have an upload file open.\n", ERROR + RESOURCE_NOT_OPEN);
660                 return;
661         }
662
663         if (bytes > 100000) {
664                 cprintf("%d You may not write more than 100000 bytes.\n",
665                         ERROR + TOO_BIG);
666                 return;
667         }
668
669         cprintf("%d %d\n", SEND_BINARY, bytes);
670         buf = malloc(bytes + 1);
671         client_read(buf, bytes);
672         fwrite(buf, bytes, 1, CC->upload_fp);
673         free(buf);
674 }
675
676
677
678
679 /*
680  * cmd_ndop() - open a network spool file for downloading
681  */
682 void cmd_ndop(char *cmdbuf)
683 {
684         char pathname[256];
685         struct stat statbuf;
686
687         if (IsEmptyStr(CC->net_node)) {
688                 cprintf("%d Not authenticated as a network node.\n",
689                         ERROR + NOT_LOGGED_IN);
690                 return;
691         }
692
693         if (CC->download_fp != NULL) {
694                 cprintf("%d You already have a download file open.\n",
695                         ERROR + RESOURCE_BUSY);
696                 return;
697         }
698
699         snprintf(pathname, sizeof pathname, 
700                          "%s/%s",
701                          ctdl_netout_dir,
702                          CC->net_node);
703
704         /* first open the file in append mode in order to create a
705          * zero-length file if it doesn't already exist 
706          */
707         CC->download_fp = fopen(pathname, "a");
708         if (CC->download_fp != NULL)
709                 fclose(CC->download_fp);
710
711         /* now open it */
712         CC->download_fp = fopen(pathname, "r");
713         if (CC->download_fp == NULL) {
714                 cprintf("%d cannot open %s: %s\n",
715                         ERROR + INTERNAL_ERROR, pathname, strerror(errno));
716                 return;
717         }
718
719
720         /* set this flag so other routines know that the download file
721          * currently open is a network spool file 
722          */
723         CC->dl_is_net = 1;
724
725         stat(pathname, &statbuf);
726         cprintf("%d %ld\n", CIT_OK, (long)statbuf.st_size);
727 }
728
729 /*
730  * cmd_nuop() - open a network spool file for uploading
731  */
732 void cmd_nuop(char *cmdbuf)
733 {
734         static int seq = 1;
735
736         if (IsEmptyStr(CC->net_node)) {
737                 cprintf("%d Not authenticated as a network node.\n",
738                         ERROR + NOT_LOGGED_IN);
739                 return;
740         }
741
742         if (CC->upload_fp != NULL) {
743                 cprintf("%d You already have an upload file open.\n",
744                         ERROR + RESOURCE_BUSY);
745                 return;
746         }
747
748         snprintf(CC->upl_path, sizeof CC->upl_path,
749                          "%s/%s.%04lx.%04x",
750                          ctdl_netin_dir,
751                          CC->net_node, 
752                          (long)getpid(), 
753                          ++seq);
754
755         CC->upload_fp = fopen(CC->upl_path, "r");
756         if (CC->upload_fp != NULL) {
757                 fclose(CC->upload_fp);
758                 CC->upload_fp = NULL;
759                 cprintf("%d '%s' already exists\n",
760                         ERROR + ALREADY_EXISTS, CC->upl_path);
761                 return;
762         }
763
764         CC->upload_fp = fopen(CC->upl_path, "w");
765         if (CC->upload_fp == NULL) {
766                 cprintf("%d Cannot open %s: %s\n",
767                         ERROR + INTERNAL_ERROR, CC->upl_path, strerror(errno));
768                 return;
769         }
770
771         CC->upload_type = UPL_NET;
772         cprintf("%d Ok\n", CIT_OK);
773 }
774
775
776 /*****************************************************************************/
777 /*                      MODULE INITIALIZATION STUFF                          */
778 /*****************************************************************************/
779
780 CTDL_MODULE_INIT(file_ops)
781 {
782         CtdlRegisterProtoHook(cmd_delf, "DELF", "Autoconverted. TODO: document me.");
783         CtdlRegisterProtoHook(cmd_movf, "MOVF", "Autoconverted. TODO: document me.");
784         CtdlRegisterProtoHook(cmd_open, "OPEN", "Autoconverted. TODO: document me.");
785         CtdlRegisterProtoHook(cmd_clos, "CLOS", "Autoconverted. TODO: document me.");
786         CtdlRegisterProtoHook(cmd_uopn, "UOPN", "Autoconverted. TODO: document me.");
787         CtdlRegisterProtoHook(cmd_ucls, "UCLS", "Autoconverted. TODO: document me.");
788         CtdlRegisterProtoHook(cmd_read, "READ", "Autoconverted. TODO: document me.");
789         CtdlRegisterProtoHook(cmd_writ, "WRIT", "Autoconverted. TODO: document me.");
790         CtdlRegisterProtoHook(cmd_oimg, "OIMG", "Autoconverted. TODO: document me.");
791         CtdlRegisterProtoHook(cmd_ndop, "NDOP", "Autoconverted. TODO: document me.");
792         CtdlRegisterProtoHook(cmd_nuop, "NUOP", "Autoconverted. TODO: document me.");
793         CtdlRegisterProtoHook(cmd_uimg, "UIMG", "Autoconverted. TODO: document me.");
794         /* return our Subversion id for the Log */
795         return "$Id$";
796 }