* Fixed a multiselect bug in the mailbox view. Ctrl-click was selecting a message...
[citadel.git] / citadel / citadel_ipc.h
blob01b0636223b784d142d4d600fb1326612814251f
1 /* $Id$ */
3 #define UDS "_UDS_"
4 #ifdef __CYGWIN__
5 #define DEFAULT_HOST "localhost"
6 #else
7 #define DEFAULT_HOST UDS
8 #endif
9 #define DEFAULT_PORT "citadel"
11 #include "sysdep.h"
12 #ifdef HAVE_PTHREAD_H
13 #include <pthread.h>
14 #endif
15 #ifdef HAVE_OPENSSL
16 #include <openssl/ssl.h>
17 #include <openssl/err.h>
18 #include <openssl/rand.h>
19 #endif
21 #include "server.h"
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
27 /* Quick and dirty hack; we don't want to use malloc() in C++ */
28 #ifdef __cplusplus
29 #define ialloc(t) new t()
30 #define ifree(o) delete o
31 #else
32 #define ialloc(t) malloc(sizeof(t))
33 #define ifree(o) free(o);
34 #endif
36 struct CtdlServInfo {
37 int pid;
38 char nodename[32];
39 char humannode[64];
40 char fqdn[64];
41 char software[64];
42 int rev_level;
43 char site_location[64];
44 char sysadm[64];
45 char moreprompt[256];
46 int ok_floors;
47 int paging_level;
48 int supports_qnop;
49 int supports_ldap;
50 int newuser_disabled;
51 char default_cal_zone[256];
52 double load_avg;
53 double worker_avg;
54 int thread_count;
55 int has_sieve;
56 int fulltext_enabled;
57 char svn_revision[256];
60 /* This class is responsible for the server connection */
61 typedef struct _CtdlIPC {
62 /* The server info for this connection */
63 struct CtdlServInfo ServInfo;
65 #if defined(HAVE_OPENSSL)
66 /* NULL if not encrypted, non-NULL otherwise */
67 SSL *ssl;
68 #endif
69 #if defined(HAVE_PTHREAD_H)
70 /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
71 pthread_mutex_t mutex;
72 #endif
73 /* -1 if not connected, >= 0 otherwise */
74 int sock;
75 /* 1 if server is local, 0 otherwise or if not connected */
76 int isLocal;
77 /* 1 if a download is open on the server, 0 otherwise */
78 int downloading;
79 /* 1 if an upload is open on the server, 0 otherwise */
80 int uploading;
81 /* Time the last command was sent to the server */
82 time_t last_command_sent;
83 /* Our buffer for linebuffered read. */
84 char *Buf;
85 size_t BufSize;
86 size_t BufUsed;
87 char *BufPtr;
88 /* Callback for update on whether the IPC is locked */
89 void (*network_status_cb)(int state);
90 } CtdlIPC;
92 /* C constructor */
93 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
94 /* C destructor */
95 void CtdlIPC_delete(CtdlIPC* ipc);
96 /* Convenience destructor; also nulls out caller's pointer */
97 void CtdlIPC_delete_ptr(CtdlIPC** pipc);
98 /* Read a line from server, discarding newline, for chat, will go away */
99 void CtdlIPC_chat_recv(CtdlIPC* ipc, char *buf);
100 /* Write a line to server, adding newline, for chat, will go away */
101 void CtdlIPC_chat_send(CtdlIPC* ipc, const char *buf);
103 struct ctdlipcroom {
104 char RRname[ROOMNAMELEN]; /* Name of room */
105 long RRunread; /* Number of unread messages */
106 long RRtotal; /* Total number of messages in room */
107 char RRinfoupdated; /* Nonzero if info was updated */
108 unsigned RRflags; /* Various flags (see LKRN) */
109 unsigned RRflags2; /* Various flags (see LKRN) */
110 long RRhighest; /* Highest message number in room */
111 long RRlastread; /* Highest message user has read */
112 char RRismailbox; /* Is this room a mailbox room? */
113 char RRaide; /* User can do aide commands in room */
114 long RRnewmail; /* Number of new mail messages */
115 char RRfloor; /* Which floor this room is on */
119 struct parts {
120 struct parts *next;
121 char number[16]; /* part number */
122 char name[PATH_MAX]; /* Name */
123 char filename[PATH_MAX]; /* Suggested filename */
124 char mimetype[SIZ]; /* MIME type */
125 char disposition[SIZ]; /* Content disposition */
126 unsigned long length; /* Content length */
130 struct ctdlipcmessage {
131 char msgid[SIZ]; /* Original message ID */
132 char path[SIZ]; /* Return path to sender */
133 char zaps[SIZ]; /* Message ID that this supersedes */
134 char subject[SIZ]; /* Message subject */
135 char email[SIZ]; /* Email address of sender */
136 char author[SIZ]; /* Sender of message */
137 char recipient[SIZ]; /* Recipient of message */
138 char room[SIZ]; /* Originating room */
139 char node[SIZ]; /* Short nodename of origin system */
140 char hnod[SIZ]; /* Humannode of origin system */
141 struct parts *attachments; /* Available attachments */
142 char *text; /* Message text */
143 int type; /* Message type */
144 time_t time; /* Time message was posted */
145 char nhdr; /* Suppress message header? */
146 char anonymous; /* An anonymous message */
147 char mime_chosen[SIZ]; /* Chosen MIME part to output */
148 char content_type[SIZ]; /* How would you like that? */
149 char references[SIZ]; /* Thread references */
153 struct ctdlipcfile {
154 char remote_name[PATH_MAX]; /* Filename on server */
155 char local_name[PATH_MAX]; /* Filename on client */
156 char description[80]; /* Description on server */
157 FILE *local_fd; /* Open file on client */
158 size_t size; /* Size of file in octets */
159 unsigned int upload:1; /* uploading? 0 if downloading */
160 unsigned int complete:1; /* Transfer has finished? */
164 struct ctdlipcmisc {
165 long newmail; /* Number of new Mail messages */
166 char needregis; /* Nonzero if user needs to register */
167 char needvalid; /* Nonzero if users need validation */
170 enum RoomList {
171 SubscribedRooms,
172 SubscribedRoomsWithNewMessages,
173 SubscribedRoomsWithNoNewMessages,
174 UnsubscribedRooms,
175 AllAccessibleRooms,
176 AllPublicRooms
178 #define AllFloors -1
179 enum MessageList {
180 AllMessages,
181 OldMessages,
182 NewMessages,
183 LastMessages,
184 FirstMessages,
185 MessagesGreaterThan,
186 MessagesLessThan
188 enum MessageDirection {
189 ReadReverse = -1,
190 ReadForward = 1
193 /* Shared Diffie-Hellman parameters */
194 #define DH_P "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383"
195 #define DH_G "2"
196 #define DH_L 1024
197 #define CIT_CIPHERS "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH" /* see ciphers(1) */
199 int CtdlIPCNoop(CtdlIPC *ipc);
200 int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret);
201 int CtdlIPCQuit(CtdlIPC *ipc);
202 int CtdlIPCLogout(CtdlIPC *ipc);
203 int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret);
204 int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret);
205 int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret);
206 int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice,
207 char *cret);
208 int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret);
209 int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor,
210 struct march **listing, char *cret);
211 int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret);
212 int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret);
213 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
214 struct ctdlipcroom **rret, char *cret);
215 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
216 const char *mtemplate, unsigned long **mret, char *cret);
217 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
218 struct ctdlipcmessage **mret, char *cret);
219 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret);
220 int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret);
221 /* int CtdlIPCReadDirectory(CtdlIPC *ipc, struct ctdlipcfile **files, char *cret); */
222 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret);
223 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret);
224 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret);
225 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret);
226 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct ctdlroom **qret, char *cret);
227 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct ctdlroom *qret,
228 char *cret);
229 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret);
230 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret);
231 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required,
232 struct ctdlipcmessage *mr,
233 char *cret);
234 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret);
235 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret);
236 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum,
237 const char *destroom, char *cret);
238 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret);
239 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname,
240 int type, const char *password, int floor, char *cret);
241 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret);
242 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret,
243 char *cret);
244 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
245 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
246 char *cret);
247 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
248 char *cret);
249 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
250 char *cret);
251 int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **list, char *cret);
252 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret);
253 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret);
254 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret);
255 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom,
256 char *cret);
257 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename,
258 const char *destnode, char *cret);
259 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret);
260 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
261 size_t resume,
262 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
263 char *cret);
264 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
265 void **buf,
266 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
267 char *cret);
268 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
269 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
270 char *cret);
271 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
272 const char *path,
273 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
274 char *cret);
275 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
276 const char *save_as,
277 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
278 char *cret);
279 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret);
280 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret);
281 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name,
282 char *cret);
283 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
284 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
285 char *cret);
286 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
287 int revision, const char *software_name, const char *hostname,
288 char *cret);
289 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username,
290 const char *text, char *cret);
291 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret);
292 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret);
293 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret);
294 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing,
295 char *cret);
296 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret);
297 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret);
298 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret);
299 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret);
300 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret);
301 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
302 char *cret);
303 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret);
304 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret);
305 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret);
306 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert);
307 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
308 struct ctdluser **uret, char *cret);
309 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret);
310 int CtdlIPCRenameUser(CtdlIPC *ipc, char *oldname, char *newname, char *cret);
311 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
312 struct ExpirePolicy **policy, char *cret);
313 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
314 struct ExpirePolicy *policy, char *cret);
315 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret);
316 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret);
317 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
318 char **listing, char *cret);
319 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
320 const char *listing, char *cret);
321 int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
322 int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
323 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
324 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
325 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);
326 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret);
327 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats);
328 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret);
329 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret);
331 /* ************************************************************************** */
332 /* Stuff below this line is not for public consumption */
333 /* ************************************************************************** */
335 INLINE void CtdlIPC_lock(CtdlIPC *ipc);
336 INLINE void CtdlIPC_unlock(CtdlIPC *ipc);
337 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest);
338 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing);
339 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset,
340 size_t bytes, char *cret);
341 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret);
342 int CtdlIPCWriteUpload(CtdlIPC *ipc, FILE *uploadFP,
343 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
344 char *cret);
345 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret);
346 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
347 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
348 char *cret);
349 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
350 size_t resume,
351 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
352 char *cret);
353 int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command,
354 const char *to_send, size_t bytes_to_send, char **to_receive,
355 size_t *bytes_to_receive, char *proto_response);
357 /* Internals */
358 int starttls(CtdlIPC *ipc);
359 void setCryptoStatusHook(void (*hook)(char *s));
360 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state));
361 /* This is all Ford's doing. FIXME: figure out what it's doing */
362 extern int (*error_printf)(char *s, ...);
363 void setIPCDeathHook(void (*hook)(void));
364 void setIPCErrorPrintf(int (*func)(char *s, ...));
365 void connection_died(CtdlIPC* ipc, int using_ssl);
366 int CtdlIPC_getsockfd(CtdlIPC* ipc);
367 char CtdlIPC_get(CtdlIPC* ipc);
369 #ifdef __cplusplus
371 #endif