5 #define DEFAULT_HOST "localhost"
7 #define DEFAULT_HOST UDS
9 #define DEFAULT_PORT "citadel"
16 #include <openssl/ssl.h>
17 #include <openssl/err.h>
18 #include <openssl/rand.h>
27 /* Quick and dirty hack; we don't want to use malloc() in C++ */
29 #define ialloc(t) new t()
30 #define ifree(o) delete o
32 #define ialloc(t) malloc(sizeof(t))
33 #define ifree(o) free(o);
43 char site_location[64];
53 /* This class is responsible for the server connection */
54 typedef struct _CtdlIPC {
55 /* The server info for this connection */
56 struct CtdlServInfo ServInfo;
58 #if defined(HAVE_OPENSSL)
59 /* NULL if not encrypted, non-NULL otherwise */
62 #if defined(HAVE_PTHREAD_H)
63 /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
64 pthread_mutex_t mutex;
66 /* -1 if not connected, >= 0 otherwise */
68 /* 1 if server is local, 0 otherwise or if not connected */
70 /* 1 if a download is open on the server, 0 otherwise */
72 /* 1 if an upload is open on the server, 0 otherwise */
74 /* Time the last command was sent to the server */
75 time_t last_command_sent;
76 /* Our buffer for linebuffered read. */
81 /* Callback for update on whether the IPC is locked */
82 void (*network_status_cb)(int state);
86 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
88 void CtdlIPC_delete(CtdlIPC* ipc);
89 /* Convenience destructor; also nulls out caller's pointer */
90 void CtdlIPC_delete_ptr(CtdlIPC** pipc);
91 /* Read a line from server, discarding newline, for chat, will go away */
92 void CtdlIPC_chat_recv(CtdlIPC* ipc, char *buf);
93 /* Write a line to server, adding newline, for chat, will go away */
94 void CtdlIPC_chat_send(CtdlIPC* ipc, const char *buf);
97 char RRname[ROOMNAMELEN]; /* Name of room */
98 long RRunread; /* Number of unread messages */
99 long RRtotal; /* Total number of messages in room */
100 char RRinfoupdated; /* Nonzero if info was updated */
101 unsigned RRflags; /* Various flags (see LKRN) */
102 unsigned RRflags2; /* Various flags (see LKRN) */
103 long RRhighest; /* Highest message number in room */
104 long RRlastread; /* Highest message user has read */
105 char RRismailbox; /* Is this room a mailbox room? */
106 char RRaide; /* User can do aide commands in room */
107 long RRnewmail; /* Number of new mail messages */
108 char RRfloor; /* Which floor this room is on */
114 char number[16]; /* part number */
115 char name[PATH_MAX]; /* Name */
116 char filename[PATH_MAX]; /* Suggested filename */
117 char mimetype[SIZ]; /* MIME type */
118 char disposition[SIZ]; /* Content disposition */
119 unsigned long length; /* Content length */
123 struct ctdlipcmessage {
124 char msgid[SIZ]; /* Original message ID */
125 char path[SIZ]; /* Return path to sender */
126 char zaps[SIZ]; /* Message ID that this supersedes */
127 char subject[SIZ]; /* Message subject */
128 char email[SIZ]; /* Email address of sender */
129 char author[SIZ]; /* Sender of message */
130 char recipient[SIZ]; /* Recipient of message */
131 char room[SIZ]; /* Originating room */
132 char node[SIZ]; /* Short nodename of origin system */
133 char hnod[SIZ]; /* Humannode of origin system */
134 struct parts *attachments; /* Available attachments */
135 char *text; /* Message text */
136 int type; /* Message type */
137 time_t time; /* Time message was posted */
138 char nhdr; /* Suppress message header? */
139 char anonymous; /* An anonymous message */
140 char mime_chosen[SIZ]; /* Chosen MIME part to output */
141 char content_type[SIZ]; /* How would you like that? */
146 char remote_name[PATH_MAX]; /* Filename on server */
147 char local_name[PATH_MAX]; /* Filename on client */
148 char description[80]; /* Description on server */
149 FILE *local_fd; /* Open file on client */
150 size_t size; /* Size of file in octets */
151 unsigned int upload:1; /* uploading? 0 if downloading */
152 unsigned int complete:1; /* Transfer has finished? */
157 long newmail; /* Number of new Mail messages */
158 char needregis; /* Nonzero if user needs to register */
159 char needvalid; /* Nonzero if users need validation */
164 SubscribedRoomsWithNewMessages,
165 SubscribedRoomsWithNoNewMessages,
180 enum MessageDirection {
185 /* Shared Diffie-Hellman parameters */
186 #define DH_P "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383"
189 #define CIT_CIPHERS "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH" /* see ciphers(1) */
191 int CtdlIPCNoop(CtdlIPC *ipc);
192 int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret);
193 int CtdlIPCQuit(CtdlIPC *ipc);
194 int CtdlIPCLogout(CtdlIPC *ipc);
195 int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret);
196 int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret);
197 int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret);
198 int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice,
200 int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret);
201 int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor,
202 struct march **listing, char *cret);
203 int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret);
204 int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret);
205 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
206 struct ctdlipcroom **rret, char *cret);
207 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
208 const char *mtemplate, unsigned long **mret, char *cret);
209 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
210 struct ctdlipcmessage **mret, char *cret);
211 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret);
212 int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret);
213 /* int CtdlIPCReadDirectory(CtdlIPC *ipc, struct ctdlipcfile **files, char *cret); */
214 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret);
215 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret);
216 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret);
217 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret);
218 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct ctdlroom **qret, char *cret);
219 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct ctdlroom *qret,
221 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret);
222 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret);
223 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required,
224 const struct ctdlipcmessage *mr,
226 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret);
227 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret);
228 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum,
229 const char *destroom, char *cret);
230 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret);
231 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname,
232 int type, const char *password, int floor, char *cret);
233 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret);
234 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret,
236 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
237 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
239 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
241 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
243 int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **list, char *cret);
244 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret);
245 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret);
246 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret);
247 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom,
249 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename,
250 const char *destnode, char *cret);
251 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret);
252 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
254 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
256 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
258 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
260 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
261 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
263 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
265 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
267 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
269 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
271 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret);
272 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret);
273 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name,
275 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
276 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
278 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
279 int revision, const char *software_name, const char *hostname,
281 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username,
282 const char *text, char *cret);
283 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret);
284 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret);
285 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret);
286 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing,
288 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret);
289 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret);
290 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret);
291 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret);
292 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret);
293 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text,
295 int CtdlIPCChangeHostname(CtdlIPC *ipc, const char *hostname, char *cret);
296 int CtdlIPCChangeRoomname(CtdlIPC *ipc, const char *roomname, char *cret);
297 int CtdlIPCChangeUsername(CtdlIPC *ipc, const char *username, char *cret);
298 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert);
299 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who,
300 struct ctdluser **uret, char *cret);
301 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret);
302 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, int which,
303 struct ExpirePolicy **policy, char *cret);
304 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which,
305 struct ExpirePolicy *policy, char *cret);
306 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret);
307 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret);
308 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
309 char **listing, char *cret);
310 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype,
311 const char *listing, char *cret);
312 int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
313 int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
314 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
315 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
316 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);
317 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret);
318 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats);
319 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret);
320 int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret);
322 /* ************************************************************************** */
323 /* Stuff below this line is not for public consumption */
324 /* ************************************************************************** */
326 INLINE void CtdlIPC_lock(CtdlIPC *ipc);
327 INLINE void CtdlIPC_unlock(CtdlIPC *ipc);
328 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest);
329 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing);
330 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset,
331 size_t bytes, char *cret);
332 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret);
333 int CtdlIPCWriteUpload(CtdlIPC *ipc, const char *path,
334 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
336 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret);
337 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
338 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
340 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
342 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
344 int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command,
345 const char *to_send, size_t bytes_to_send, char **to_receive,
346 size_t *bytes_to_receive, char *proto_response);
349 int starttls(CtdlIPC *ipc);
350 void setCryptoStatusHook(void (*hook)(char *s));
351 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state));
352 /* This is all Ford's doing. FIXME: figure out what it's doing */
353 extern int (*error_printf)(char *s, ...);
354 void setIPCDeathHook(void (*hook)(void));
355 void setIPCErrorPrintf(int (*func)(char *s, ...));
356 void connection_died(CtdlIPC* ipc, int using_ssl);
357 int CtdlIPC_getsockfd(CtdlIPC* ipc);
358 char CtdlIPC_get(CtdlIPC* ipc);