]> code.citadel.org Git - citadel.git/blob - citadel/citadel_ipc.h
d16689e20e76d488c5bffb95c77e12f7324deb0e
[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         long RRhighest;                 /* Highest message number in room */
97         long RRlastread;                /* Highest message user has read */
98         char RRismailbox;               /* Is this room a mailbox room? */
99         char RRaide;                    /* User can do aide commands in room */
100         long RRnewmail;                 /* Number of new mail messages */
101         char RRfloor;                   /* Which floor this room is on */
102 };
103
104
105 struct parts {
106         struct parts *next;
107         char number[16];                /* part number */
108         char name[PATH_MAX];            /* Name */
109         char filename[PATH_MAX];        /* Suggested filename */
110         char mimetype[SIZ];             /* MIME type */
111         char disposition[SIZ];          /* Content disposition */
112         unsigned long length;           /* Content length */
113 };
114
115
116 struct ctdlipcmessage {
117         char msgid[SIZ];                /* Original message ID */
118         char path[SIZ];                 /* Return path to sender */
119         char zaps[SIZ];                 /* Message ID that this supersedes */
120         char subject[SIZ];              /* Message subject */
121         char email[SIZ];                /* Email address of sender */
122         char author[SIZ];               /* Sender of message */
123         char recipient[SIZ];            /* Recipient of message */
124         char room[SIZ];                 /* Originating room */
125         char node[SIZ];                 /* Short nodename of origin system */
126         char hnod[SIZ];                 /* Humannode of origin system */
127         struct parts *attachments;      /* Available attachments */
128         char *text;                     /* Message text */
129         int type;                       /* Message type */
130         time_t time;                    /* Time message was posted */
131         char nhdr;                      /* Suppress message header? */
132         char anonymous;                 /* An anonymous message */
133         char mime_chosen[SIZ];          /* Chosen MIME part to output */
134         char content_type[SIZ];         /* How would you like that? */
135 };
136
137
138 struct ctdlipcfile {
139         char remote_name[PATH_MAX];     /* Filename on server */
140         char local_name[PATH_MAX];      /* Filename on client */
141         char description[80];           /* Description on server */
142         FILE *local_fd;                 /* Open file on client */
143         size_t size;                    /* Size of file in octets */
144         unsigned int upload:1;          /* uploading? 0 if downloading */
145         unsigned int complete:1;        /* Transfer has finished? */
146 };
147
148
149 struct ctdlipcmisc {
150         long newmail;                   /* Number of new Mail messages */
151         char needregis;                 /* Nonzero if user needs to register */
152         char needvalid;                 /* Nonzero if users need validation */
153 };
154
155 enum RoomList {
156         SubscribedRooms,
157         SubscribedRoomsWithNewMessages,
158         SubscribedRoomsWithNoNewMessages,
159         UnsubscribedRooms,
160         AllAccessibleRooms,
161         AllPublicRooms
162 };
163 #define AllFloors -1
164 enum MessageList {
165         AllMessages,
166         OldMessages,
167         NewMessages,
168         LastMessages,
169         FirstMessages,
170         MessagesGreaterThan,
171         MessagesLessThan
172 };
173 enum MessageDirection {
174         ReadReverse = -1,
175         ReadForward = 1
176 };
177
178 /* Shared Diffie-Hellman parameters */
179 #define DH_P            "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383"
180 #define DH_G            "2"
181 #define DH_L            1024
182 #define CIT_CIPHERS     "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH"      /* see ciphers(1) */
183
184 int CtdlIPCNoop(CtdlIPC *ipc);
185 int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret);
186 int CtdlIPCQuit(CtdlIPC *ipc);
187 int CtdlIPCLogout(CtdlIPC *ipc);
188 int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret);
189 int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret);
190 int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret);
191 int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice,
192                 char *cret);
193 int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret);
194 int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor,
195                 struct march **listing, char *cret);
196 int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret);
197 int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret);
198 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
199                 struct ctdlipcroom **rret, char *cret);
200 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
201                 const char *mtemplate, unsigned long **mret, char *cret);
202 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
203                 struct ctdlipcmessage **mret, char *cret);
204 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret);
205 int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret);
206 /* int CtdlIPCReadDirectory(CtdlIPC *ipc, struct ctdlipcfile **files, char *cret); */
207 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret);
208 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret);
209 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret);
210 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret);
211 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct ctdlroom **qret, char *cret);
212 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct ctdlroom *qret,
213                 char *cret);
214 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret);
215 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret);
216 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, const struct ctdlipcmessage *mr,
217                 char *cret);
218 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret);
219 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret);
220 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum,
221                 const char *destroom, char *cret);
222 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret);
223 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname,
224                 int type, const char *password, int floor, char *cret);
225 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret);
226 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret,
227                 char *cret);
228 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
229 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
230                 char *cret);
231 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
232                 char *cret);
233 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
234                 char *cret);
235 int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **list, char *cret);
236 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret);
237 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret);
238 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret);
239 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom,
240                 char *cret);
241 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename,
242                 const char *destnode, char *cret);
243 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret);
244 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
245                 size_t resume,
246                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
247                 char *cret);
248 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
249                 void **buf,
250                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
251                 char *cret);
252 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
253                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
254                 char *cret);
255 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
256                 const char *path,
257                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
258                 char *cret);
259 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
260                 const char *save_as,
261                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
262                 char *cret);
263 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret);
264 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret);
265 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name,
266                 char *cret);
267 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
268 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
269                 char *cret);
270 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
271                 int revision, const char *software_name, const char *hostname,
272                 char *cret);
273 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username,
274                 const char *text, char *cret);
275 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret);
276 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret);
277 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret);
278 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing,
279                 char *cret);
280 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret);
281 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret);
282 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret);
283 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret);
284 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret);
285 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
286                 char *cret);
287 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret);
288 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret);
289 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret);
290 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert);
291 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
292                                  struct ctdluser **uret, char *cret);
293 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret);
294 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
295                 struct ExpirePolicy **policy, char *cret);
296 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
297                 struct ExpirePolicy *policy, char *cret);
298 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret);
299 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret);
300 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
301                 char **listing, char *cret);
302 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
303                const char *listing, char *cret);
304 int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
305 int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
306 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
307 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
308 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);
309 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret);
310 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats);
311 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret);
312 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret);
313
314 /* ************************************************************************** */
315 /*             Stuff below this line is not for public consumption            */
316 /* ************************************************************************** */
317
318 INLINE void CtdlIPC_lock(CtdlIPC *ipc);
319 INLINE void CtdlIPC_unlock(CtdlIPC *ipc);
320 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest);
321 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing);
322 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset,
323                 size_t bytes, char *cret);
324 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret);
325 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
326                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
327                 char *cret);
328 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret);
329 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
330                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
331                 char *cret);
332 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
333                 size_t resume,
334                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
335                 char *cret);
336 int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command,
337                 const char *to_send, size_t bytes_to_send, char **to_receive,
338                 size_t *bytes_to_receive, char *proto_response);
339
340 /* Internals */
341 int starttls(CtdlIPC *ipc);
342 void setCryptoStatusHook(void (*hook)(char *s));
343 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state));
344 /* This is all Ford's doing.  FIXME: figure out what it's doing */
345 extern int (*error_printf)(char *s, ...);
346 void setIPCDeathHook(void (*hook)(void));
347 void setIPCErrorPrintf(int (*func)(char *s, ...));
348 void connection_died(CtdlIPC* ipc, int using_ssl);
349 int CtdlIPC_getsockfd(CtdlIPC* ipc);
350 char CtdlIPC_get(CtdlIPC* ipc);
351
352 #ifdef __cplusplus
353 }
354 #endif