]> code.citadel.org Git - citadel.git/blob - libCxClient/src/rooms.c
Initial revision
[citadel.git] / libCxClient / src / rooms.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: rooms.o
8  ** Date: 2000-10-15
9  ** Last Revision: 2000-10-15
10  ** Description: Functions which manipulate (build) room & floor lists.
11  ** CVS: $Id$
12  **/
13 #include        <stdio.h>
14 #include        <stdlib.h>
15 #include        <stdarg.h>
16 #include        <string.h>
17 #include        <CxClient.h>
18 #include        "autoconf.h"
19
20 /**
21  ** CxRmGoto(): Go to a room.  
22  **
23  ** [Expects]
24  **  (char *) room: The name of the room the user wishes to go to.
25  **  (int) operation: Which room to go to?
26  **             0: Goto specified room
27  **             1: Goto next room w/ unread messages
28  **             2: Ungoto
29  **
30  ** [Returns]
31  **  On Success: The room's full information structure [*]
32  **  On Failure: NULL
33  **/
34 ROOMINFO        *CxRmGoto(const char *room, int operation) {
35 ROOMINFO        *room_info;
36 char            *xmit, buf[255], *g_Ser[20];
37 int             rc, i;
38
39         if((room && *room) && !operation) {
40                 xmit = (char *)CxMalloc(strlen(room)+6);
41                 sprintf(xmit, "GOTO %s", room);
42                 CxClSend(xmit);
43                 CxFree(xmit);
44
45                 rc = CxClRecv(buf);
46
47                 /**
48                  ** If we successfully went to this room, return the
49                  ** room's information structure.
50                  **/
51                 if(CHECKRC(rc, RC_OK)) {
52                         CxSerialize(buf, &g_Ser);
53
54                         room_info = (ROOMINFO *)CxMalloc(sizeof(ROOMINFO));
55                         strcpy(room_info->name, g_Ser[0]);
56                         room_info->msgs_unread = atol(g_Ser[1]);
57                         room_info->msgs_total = atol(g_Ser[2]);
58                         room_info->info_flag = (short int) atoi(g_Ser[3]);
59                         room_info->flags = atol(g_Ser[4]);
60                         room_info->msgs_highest = atol(g_Ser[5]);
61                         room_info->msgs_highest_u = atol(g_Ser[6]);
62                         room_info->mailroom = (short int) atoi(g_Ser[7]);
63                         room_info->aide = (short int) atoi(g_Ser[8]);
64                         room_info->msgs_newmail = atol(g_Ser[9]);
65                         room_info->floor_id = atol(g_Ser[9]);
66
67                         DPF((DFA,"MEM/MDA:\t-1\t@0x%08x (Needs manual deallocation)", room_info));
68
69                         return(room_info);
70                 }
71
72                 /**
73                  ** Room not found, Returning NULL.
74                  **/
75                 return(NULL);
76
77         /**
78          ** GOTO Next Unread Room
79          **/
80         } else if(operation==1) {
81
82                 /**
83                  ** Set last-read pointer for this room.
84                  **/
85                 CxClSend("SLRP highest");
86                 CxClRecv(buf);
87
88                 /**
89                  ** Retrieve a list of all rooms w/ new messages.
90                  **/
91                 CxClSend("LKRN");
92                 rc = CxClRecv(buf);
93                 i = (int) xmit = 0;
94                 if(CHECKRC(rc, RC_LISTING)) {
95                         do {
96                                 rc = CxClRecv(buf);
97                                 if(rc) {
98                                         if(!i) {
99                                                 xmit = (char *)CxMalloc(strlen(buf)+6);
100                                                 strcpy(xmit, "GOTO ");
101                                                 strcat(xmit, buf);
102                                         }
103                                 }
104                         } while(rc<0);
105
106                         if(xmit) {
107                                 CxClSend(xmit);
108                                 CxFree(xmit);
109
110                                 rc = CxClRecv(buf);
111                                 if(CHECKRC(rc, RC_OK)) {
112                                         CxSerialize(buf, &g_Ser);
113                  
114                                         room_info = (ROOMINFO *)CxMalloc(sizeof(ROOMINFO));
115                                         strcpy(room_info->name, g_Ser[0]);
116                                         room_info->msgs_unread = atol(g_Ser[1]);
117                                         room_info->msgs_total = atol(g_Ser[2]);
118                                         room_info->info_flag = (short int) atoi(g_Ser[3]);
119                                         room_info->flags = atol(g_Ser[4]);
120                                         room_info->msgs_highest = atol(g_Ser[5]);
121                                         room_info->msgs_highest_u = atol(g_Ser[6]);
122                                         room_info->mailroom = (short int) atoi(g_Ser[7]);
123                                         room_info->aide = (short int) atoi(g_Ser[8]);
124                                         room_info->msgs_newmail = atol(g_Ser[9]);
125                                         room_info->floor_id = atol(g_Ser[9]);
126
127                                         DPF((DFA,"MEM/MDA:\t-1\t@0x%08x (Needs manual deallocation)", room_info));
128                  
129                                         return(room_info);
130                                 }
131                                 
132                         } else {
133                                 return(NULL);
134                         }
135                 }
136                 return(NULL);
137
138         /**
139          ** Unknown Operation
140          **/
141         } else {
142                 return(NULL);
143         }
144 }
145
146 /**
147  ** CxRmCreate(): Create a new room, using CERTAIN information provided in
148  ** a ROOMINFO struct.  Any unnecessary information is ignored.
149  **
150  ** [Expects]
151  **  ROOMINFO: Information about the room to be created.
152  **
153  ** [Returns]
154  **  On Success: 0
155  **  On Failure: 1: rm.mode is invalid.
156  **              2: rm.floor_id is invalid.
157  **              3: room exists.
158  **              4: not here/not allowed.
159  **/
160 int             CxRmCreate(ROOMINFO rm) {
161 char            buf[512];
162 int             rc;
163
164         DPF((DFA,"Creating room '%s'",rm.name));
165
166         /**
167          ** User provided an illegal room mode.  Can't continue.
168          **/
169         if((rm.mode<0) || (rm.mode>4)) {
170                 DPF((DFA,"FAILED rm.mode_is_invalid"));
171                 return(1);
172         }
173
174         /**
175          ** Floor id invalid (How do we check this?)
176          **/
177         if( 0 ) {
178                 DPF((DFA,"FAILED rm.floor_id_is_invalid"));
179                 return(2);
180         }
181
182         /**
183          ** Does the room already exist?
184          **/
185         if( 0 ) {
186                 DPF((DFA,"FAILED room_exists"));
187                 return(3);
188         }
189
190         sprintf(buf, "CRE8 1|%s|%d||%d", rm.name, rm.mode, rm.floor_id );
191         CxClSend(buf);
192         rc = CxClRecv(buf);
193         if( CHECKRC(rc, RC_OK)) {
194                 DPF((DFA,"Success!"));
195                 return(0);
196         } else {
197                 DPF((DFA,"FAILED %d:%s", rc, buf));
198                 return(4);
199         }
200 }
201
202 /**
203  ** CxRmList(): Retrieve a list of rooms on the current floor.  Return it
204  ** as a Character array.  THE CALLER IS RESPONSIBLE FOR DEALLOCATING THIS
205  ** MEMORY!!
206  **/
207 CXLIST          CxRmList() {
208 int             rc;
209 char            buf[255];
210 CXLIST          rooms = NULL;
211
212         DPF((DFA,"Retrieving list of rooms from the server."));
213
214         CxClSend("LKRA");
215         rc = CxClRecv( buf );
216         DPF((DFA,"%s [%d]",buf,rc));
217
218         if( CHECKRC(rc, RC_LISTING)) {
219
220                 do {
221                         rc = CxClRecv( buf );
222                         DPF((DFA,"%s [%d]",buf,rc));
223
224                         if(rc) {
225                                 rooms = (CXLIST) CxLlInsert(rooms,buf);
226                         }
227                 } while(rc < 0);
228
229                 return(rooms);
230         } else {
231                 return(NULL);
232         }
233 }
234
235 /**
236  ** CxFlList(): Retrieve a list of floors.
237  **/
238 CXLIST          CxFlList() {
239 int             rc;
240 char            buf[255];
241 CXLIST          floors = NULL;
242
243         DPF((DFA,"Retrieving list of floors from the server."));
244
245         CxClSend("LFLR");
246         rc = CxClRecv( buf );
247         DPF((DFA,"%s [%d]",buf,rc));
248
249         if( CHECKRC(rc, RC_LISTING)) {
250
251                 do {
252                         rc = CxClRecv( buf );
253                         DPF((DFA,"%s [%d]",buf,rc));
254
255                         if(rc) {
256                                 floors = (CXLIST) CxLlInsert(floors,buf);
257                         }
258                 } while(rc < 0);
259
260                 return(floors);
261         } else {
262                 return(NULL);
263         }
264 }
265
266