]> code.citadel.org Git - citadel.git/blob - citadel/citadel_ipc.h
3e36ade4eafa2e007176f78e76998e4349b8a901
[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, int *subject_required, 
218                                            const struct ctdlipcmessage *mr,
219                                            char *cret);
220 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret);
221 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret);
222 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum,
223                 const char *destroom, char *cret);
224 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret);
225 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname,
226                 int type, const char *password, int floor, char *cret);
227 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret);
228 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret,
229                 char *cret);
230 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
231 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
232                 char *cret);
233 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
234                 char *cret);
235 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
236                 char *cret);
237 int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **list, char *cret);
238 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret);
239 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret);
240 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret);
241 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom,
242                 char *cret);
243 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename,
244                 const char *destnode, char *cret);
245 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret);
246 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
247                 size_t resume,
248                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
249                 char *cret);
250 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
251                 void **buf,
252                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
253                 char *cret);
254 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
255                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
256                 char *cret);
257 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
258                 const char *path,
259                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
260                 char *cret);
261 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
262                 const char *save_as,
263                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
264                 char *cret);
265 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret);
266 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret);
267 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name,
268                 char *cret);
269 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
270 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
271                 char *cret);
272 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
273                 int revision, const char *software_name, const char *hostname,
274                 char *cret);
275 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username,
276                 const char *text, char *cret);
277 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret);
278 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret);
279 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret);
280 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing,
281                 char *cret);
282 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret);
283 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret);
284 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret);
285 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret);
286 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret);
287 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
288                 char *cret);
289 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret);
290 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret);
291 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret);
292 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert);
293 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
294                                  struct ctdluser **uret, char *cret);
295 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret);
296 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
297                 struct ExpirePolicy **policy, char *cret);
298 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
299                 struct ExpirePolicy *policy, char *cret);
300 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret);
301 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret);
302 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
303                 char **listing, char *cret);
304 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
305                const char *listing, char *cret);
306 int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
307 int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
308 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
309 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
310 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);
311 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret);
312 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats);
313 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret);
314 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret);
315
316 /* ************************************************************************** */
317 /*             Stuff below this line is not for public consumption            */
318 /* ************************************************************************** */
319
320 INLINE void CtdlIPC_lock(CtdlIPC *ipc);
321 INLINE void CtdlIPC_unlock(CtdlIPC *ipc);
322 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest);
323 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing);
324 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset,
325                 size_t bytes, char *cret);
326 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret);
327 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
328                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
329                 char *cret);
330 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret);
331 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
332                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
333                 char *cret);
334 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
335                 size_t resume,
336                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
337                 char *cret);
338 int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command,
339                 const char *to_send, size_t bytes_to_send, char **to_receive,
340                 size_t *bytes_to_receive, char *proto_response);
341
342 /* Internals */
343 int starttls(CtdlIPC *ipc);
344 void setCryptoStatusHook(void (*hook)(char *s));
345 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state));
346 /* This is all Ford's doing.  FIXME: figure out what it's doing */
347 extern int (*error_printf)(char *s, ...);
348 void setIPCDeathHook(void (*hook)(void));
349 void setIPCErrorPrintf(int (*func)(char *s, ...));
350 void connection_died(CtdlIPC* ipc, int using_ssl);
351 int CtdlIPC_getsockfd(CtdlIPC* ipc);
352 char CtdlIPC_get(CtdlIPC* ipc);
353
354 #ifdef __cplusplus
355 }
356 #endif