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