5 #define DEFAULT_HOST "localhost"
7 #define DEFAULT_HOST UDS
9 #define DEFAULT_PORT "citadel"
17 #include <openssl/ssl.h>
18 #include <openssl/err.h>
19 #include <openssl/rand.h>
26 /* Quick and dirty hack; we don't want to use malloc() in C++ */
28 #define ialloc(t) new t()
29 #define ifree(o) delete o
31 #define ialloc(t) malloc(sizeof(t))
32 #define ifree(o) free(o);
42 char site_location[64];
52 /* This class is responsible for the server connection */
53 typedef struct _CtdlIPC {
54 /* The server info for this connection */
55 struct CtdlServInfo ServInfo;
57 #if defined(HAVE_OPENSSL)
58 /* NULL if not encrypted, non-NULL otherwise */
61 #if defined(HAVE_PTHREAD_H)
62 /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
63 pthread_mutex_t mutex;
65 /* -1 if not connected, >= 0 otherwise */
67 /* 1 if server is local, 0 otherwise or if not connected */
69 /* 1 if a download is open on the server, 0 otherwise */
71 /* 1 if an upload is open on the server, 0 otherwise */
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);
80 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
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);
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 */
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 */
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? */
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? */
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 */
157 SubscribedRoomsWithNewMessages,
158 SubscribedRoomsWithNoNewMessages,
173 enum MessageDirection {
178 /* Shared Diffie-Hellman parameters */
179 #define DH_P "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383"
182 #define CIT_CIPHERS "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH" /* see ciphers(1) */
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,
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,
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,
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,
228 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
229 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
231 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
233 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
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,
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,
246 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
248 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
250 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
252 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
253 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
255 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
257 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
259 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
261 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
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,
267 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
268 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
270 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
271 int revision, const char *software_name, const char *hostname,
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,
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,
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);
314 /* ************************************************************************** */
315 /* Stuff below this line is not for public consumption */
316 /* ************************************************************************** */
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),
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),
332 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
334 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
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);
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);