]> code.citadel.org Git - citadel.git/blob - libCxClient/src/files.c
Initial revision
[citadel.git] / libCxClient / src / files.c
1 /**
2  ** libCxClient - Citadel/UX Extensible Client API
3  ** Copyright (c) 2000, Flaming Sword Productions
4  ** Copyright (c) 2001, The Citadel/UX Consortium
5  ** All Rights Reserved
6  **
7  ** Module: file.o
8  ** Date: 2000-11-16
9  ** Last Revision: 2000-11-16
10  ** Description: File directory/transfer functions.
11  ** CVS: $Id$
12  **/
13 #include        <stdio.h>
14 #include        <stdlib.h>
15 #include        <signal.h>
16 #include        <CxClient.h>
17 #include        "autoconf.h"
18 #include        "uname.h"
19
20 static void     (*_CxFiFunc)(const char *, void *);
21
22 /**
23  ** CxFiIndex(): Retrieve an index of files IN THE
24  ** CURRENT ROOM. 
25  **
26  ** [Returns]
27  **  Success: 1 blank entry + List of files in current room.
28  **  Success, No Files: 1 blank entry
29  **  Failure: NULL list.
30  **/
31 CXLIST          CxFiIndex() {
32 int             rc;
33 char            buf[512];
34 CXLIST          flist = 0;
35
36         DPF((DFA,"Retrieving file index."));
37
38         /**
39          ** Request directory listing from server.
40          **/
41         DPF((DFA,"Sending request..."));
42         CxClSend("RDIR");
43         rc = CxClRecv(buf);
44
45         /**
46          ** If this room allows directory listings...
47          **/
48         if(CHECKRC(rc,RC_LISTING)) {
49                 DPF((DFA,"LISTING_FOLLOWS..."));
50
51                 do {
52                         rc = CxClRecv(buf);
53                         DPF((DFA,"%s", buf));
54                         if(rc<0) {
55                                 flist = CxLlInsert(flist, buf);
56                         }
57                 } while(rc<0);
58                 DPF((DFA,"LISTING_COMPLETE"));
59
60                 return(flist);
61         
62         /**
63          ** ...otherwise, there's nothing to see here...
64          **/
65         } else {
66                 DPF((DFA, "No files found"));
67                 return(NULL);
68         }
69 }
70
71 /**
72  ** CxFiPut(): Send a file to the server.
73  **
74  ** [Expects]
75  **  (FILEINFO) f_info: File information
76  **  (int) f_ptr: open() file pointer.
77  **
78  ** [Returns]
79  **  Success: 0
80  **  Failure; Not Here: 1
81  **  Failure; Malformed file information: 2
82  **  Failure; File Exists: 3
83  **  Failure; Nonexistent FILE pointer.
84  **/
85 int             CxFiPut(FILEINFO f_info, int f_ptr) {
86         return(0);
87 }
88
89 /**
90  ** CxFiGet(): Download a file from the server.
91  **
92  ** [Expects]
93  **  (char *) name: Name of the file we are downloading.
94  **
95  ** [Returns]
96  **  Success: Ptr to malloc()ed tmp filename containing file data.
97  **  Failure: NULL
98  **/
99 char            *CxFiGet(const char *name) {
100
101
102         /**
103          ** Failed, return NULL.
104          **/
105         return(NULL);
106 }
107
108 /**
109  ** _CxFiHook(): We will hook ourselves into the Transport layer to
110  ** handle incoming file transfers.
111  **/
112 void            _CxFiHook(void *data) {
113         DPF((DFA, "Message received"));
114 }
115
116 /**
117  ** CxFiHook(): The user wishes to provide a hook application to
118  ** handle incoming file transfers.
119  **
120  ** [Expects]
121  **  func: The function that the user has written to handle file
122  **        downloads.
123  **        void func( const char *FILE_NAME, void *FILE_DATA);
124  **/
125 void            CxFiHook(void *func) {
126
127         DPF((DFA, "Hooking user func@0x%08x",func));
128
129         /**
130          ** If libCxClient has not already hooked this type of
131          ** message, we need to go ahead and hook it to our
132          ** internal routing function.
133          **/
134         if(!CxClCbExists(902)) {
135                 DPF((DFA, "Hooking into RC_902"));
136                 CxClCbRegister(902, _CxFiHook);
137         }
138
139         /**
140          ** Now, register the user's hooked function with
141          ** ourselves.  This instructs _CxFiHook() on
142          ** where to route data.
143          **/
144         DPF((DFA,"Registering user hook"));
145         _CxFiFunc = func;
146
147         DPF((DFA,"Ok, at this point, RC_902 messages should be routed to the user."));
148         DPF((DFA,"Don't blame me if it doesn't work.  You told me what to do, Brian."));
149 }