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 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 */
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 */
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? */
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? */
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 */
158 SubscribedRoomsWithNewMessages,
159 SubscribedRoomsWithNoNewMessages,
174 enum MessageDirection {
179 /* Shared Diffie-Hellman parameters */
180 #define DH_P "1A74527AEE4EE2568E85D4FB2E65E18C9394B9C80C42507D7A6A0DBE9A9A54B05A9A96800C34C7AA5297095B69C88901EEFD127F969DCA26A54C0E0B5C5473EBAEB00957D2633ECAE3835775425DE66C0DE6D024DBB17445E06E6B0C78415E589B8814F08531D02FD43778451E7685541079CFFB79EF0D26EFEEBBB69D1E80383"
183 #define CIT_CIPHERS "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH" /* see ciphers(1) */
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,
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,
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,
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,
229 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
230 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
232 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
234 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
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,
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,
247 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
249 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
251 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
253 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
254 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
256 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
258 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
260 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
262 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
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,
268 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
269 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname,
271 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
272 int revision, const char *software_name, const char *hostname,
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,
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,
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);
315 /* ************************************************************************** */
316 /* Stuff below this line is not for public consumption */
317 /* ************************************************************************** */
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),
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),
333 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
335 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
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);
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);