<E>nter-message command in the text client now warns the user that this creates a...
[citadel.git] / textclient / textclient.h
1 /*
2  * Copyright (c) 1987-2019 by the citadel.org team
3  *
4  *  This program is open source software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 3.
6  *
7  *  This program is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *  GNU General Public License for more details.
11  */
12
13 #define UDS                     "_UDS_"
14 #define DEFAULT_HOST            "localhost"
15 #define DEFAULT_PORT            "504"
16 #define CLIENT_VERSION          925
17 #define CLIENT_TYPE             0
18
19 /* commands we can send to the stty_ctdl() routine */
20 #define SB_NO_INTR              0               // set to Citadel client mode, i/q disabled
21 #define SB_YES_INTR             1               // set to Citadel client mode, i/q enabled
22 #define SB_SAVE                 2               // save settings
23 #define SB_RESTORE              3               // restore settings
24 #define SB_LAST                 4               // redo the last command sent
25
26 #define UGLISTLEN               100             // you get a ungoto list of this size */
27 #define ROOMNAMELEN             128             // The size of a roomname string
28 #define USERNAME_SIZE           64              // The size of a username string
29 #define MAX_EDITORS             5               // number of external editors supported, must be at least 1
30 #define NONCE_SIZE              128             // Added by <bc> to allow for APOP auth 
31
32 #define S_KEEPALIVE             30              // How often (in seconds) to send keepalives to the server
33
34 #define READ_HEADER             2
35 #define READ_MSGBODY            3
36
37 #define NUM_CONFIGS             72
38
39 #define NEXT_KEY                15
40 #define STOP_KEY                3
41
42 /* citadel.rc stuff */
43 #define RC_NO                   0               /* always no */
44 #define RC_YES                  1               /* always yes */
45 #define RC_DEFAULT              2               /* setting depends on user config */
46
47 /* keepalives */
48 enum {
49         KA_NO,                          /* no keepalives */
50         KA_YES,                         /* full keepalives */
51         KA_HALF                         /* half keepalives */
52 };
53
54 /* for <;G>oto and <;S>kip commands */
55 #define GF_GOTO         0               /* <;G>oto floor mode */
56 #define GF_SKIP         1               /* <;S>kip floor mode */
57 #define GF_ZAP          2               /* <;Z>ap floor mode */
58
59 /* Can messages be entered in this room? */
60 #define ENTMSG_OK_NO    0               /* You may not enter messages here */
61 #define ENTMSG_OK_YES   1               /* Go ahead! */
62 #define ENTMSG_OK_BLOG  2               /* Yes, but warn the user about how blog rooms work */
63
64 /*
65  * Colors for color() command
66  */
67 #define DIM_BLACK       0
68 #define DIM_RED         1
69 #define DIM_GREEN       2
70 #define DIM_YELLOW      3
71 #define DIM_BLUE        4
72 #define DIM_MAGENTA     5
73 #define DIM_CYAN        6
74 #define DIM_WHITE       7
75 #define BRIGHT_BLACK    8
76 #define BRIGHT_RED      9
77 #define BRIGHT_GREEN    10
78 #define BRIGHT_YELLOW   11
79 #define BRIGHT_BLUE     12
80 #define BRIGHT_MAGENTA  13
81 #define BRIGHT_CYAN     14
82 #define BRIGHT_WHITE    15
83 #define COLOR_PUSH      16      /* Save current color */
84 #define COLOR_POP       17      /* Restore saved color */
85 #define ORIGINAL_PAIR   -1      /* Default terminal colors */
86
87 typedef void (*sighandler_t)(int);
88
89
90
91 #include <stdlib.h>
92 #include <unistd.h>
93 #include <fcntl.h>
94 #include <stdio.h>
95 #include <ctype.h>
96 #include <string.h>
97 #include <time.h>
98 #include <limits.h>
99 #include <sys/types.h>
100 #include <sys/wait.h>
101 #include <sys/stat.h>
102 #include <sys/ioctl.h>
103 #include <termios.h>
104 //      #include <sgtty.h>      not needed if we have termios.h
105 #include <stdlib.h>
106 #include <ctype.h>
107 #include <sys/socket.h>
108 #include <arpa/inet.h>
109 #include <netinet/in.h>
110 #include <netdb.h>
111 #include <sys/un.h>
112 #include <errno.h>
113 #include <signal.h>
114 #include <pwd.h>
115 #include <stdarg.h>
116 #include <errno.h>
117 #include <signal.h>
118 #include <malloc.h>
119 #include <stdarg.h>
120 #include <sys/select.h>
121 #include <dirent.h>
122 #include <libcitadel.h>
123
124 #include <limits.h>
125 #ifdef HAVE_PTHREAD_H
126 #include <pthread.h>
127 #endif
128 #ifdef HAVE_OPENSSL
129 #include <openssl/ssl.h>
130 #include <openssl/err.h>
131 #include <openssl/rand.h>
132 #endif
133
134
135 struct CtdlServInfo {
136         int pid;
137         char nodename[32];
138         char humannode[64];
139         char fqdn[64];
140         char software[64];
141         int rev_level;
142         char site_location[64];
143         char sysadm[64];
144         char moreprompt[256];
145         int ok_floors;
146         int paging_level;
147         int supports_qnop;
148         int supports_ldap;
149         int newuser_disabled;
150         char default_cal_zone[256];
151         double load_avg;
152         double worker_avg;
153         int thread_count;
154         int has_sieve;
155         int fulltext_enabled;
156         char svn_revision[256];
157         int guest_logins;
158 };
159
160
161 /*
162  * This class is responsible for the server connection
163  */
164 typedef struct _CtdlIPC {
165         struct CtdlServInfo ServInfo;   /* The server info for this connection */
166 #if defined(HAVE_OPENSSL)
167         SSL *ssl;                       /* NULL if not encrypted, non-NULL otherwise */
168 #endif
169         int sock;                       /* Socket for connection to server, or -1 if not connected */
170         int isLocal;                    /* 1 if server is local, 0 otherwise or if not connected */
171         int downloading;                /* 1 if a download is open on the server, 0 otherwise */
172         int uploading;                  /* 1 if an upload is open on the server, 0 otherwise */
173         time_t last_command_sent;       /* Time the last command was sent to the server */
174         char *Buf;                      /* Our buffer for linebuffered read. */
175         size_t BufSize;
176         size_t BufUsed;
177         char *BufPtr;
178         void (*network_status_cb)(int state);   /* Callback for update on whether the IPC is locked */
179         char ip_hostname[256];          /* host name of server to which we are connected (if network) */
180         char ip_address[64];            /* IP address of server to which we are connected (if network) */
181 } CtdlIPC;
182
183 extern char *axdefs[];
184 extern char *viewdefs[];
185 extern char fullname[USERNAME_SIZE];
186 extern unsigned room_flags;
187 extern char room_name[ROOMNAMELEN];
188 extern struct CtdlServInfo serv_info;
189 extern char axlevel;
190 extern char is_room_aide;
191 extern unsigned userflags;
192 extern char sigcaught;
193 extern char editor_paths[MAX_EDITORS][SIZ];
194 extern char printcmd[SIZ];
195 extern char imagecmd[SIZ];
196 extern char have_xterm;
197 extern char rc_username[USERNAME_SIZE];
198 extern char rc_password[32];
199 extern char rc_floor_mode;
200 extern time_t rc_idle_threshold;
201 #ifdef HAVE_OPENSSL
202 extern char rc_encrypt;                 /* from the citadel.rc file */
203 extern char arg_encrypt;                /* from the command line */
204 #endif
205 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
206 extern char rc_screen;
207 extern char arg_screen;
208 #endif
209 extern char rc_alt_semantics;
210 extern char instant_msgs;
211 void ctdl_logoff(char *file, int line, CtdlIPC *ipc, int code);
212 #define logoff(ipc, code)       ctdl_logoff(__FILE__, __LINE__, (ipc), (code))
213 void formout(CtdlIPC *ipc, char *name);
214 void sighandler(int which_sig);
215 extern int secure;
216 void remove_march(char *roomname, int floornum);
217 void calc_dirs_n_files(int relh, int home, const char *relhome, char  *ctdldir, int dbg);
218
219 /*
220  * This struct stores a list of rooms with new messages which the client
221  * fetches from the server.  This allows the client to "march" through
222  * relevant rooms without having to ask the server each time where to go next.
223  */
224 typedef struct ExpirePolicy ExpirePolicy;
225 struct ExpirePolicy {
226         int expire_mode;
227         int expire_value;
228 };
229
230 typedef struct march march;
231 struct march {
232         struct march *next;
233         char march_name[ROOMNAMELEN];
234         unsigned int march_flags;
235         char march_floor;
236         char march_order;
237         unsigned int march_flags2;
238         int march_access;
239 };
240
241 /*
242  * This is NOT the same 'struct ctdluser' from the server.
243  */
244 typedef struct ctdluser ctdluser;
245 struct ctdluser {                       // User record
246         int version;                    // Cit vers. which created this rec
247         uid_t uid;                      // Associate with a unix account?
248         char password[32];              // password
249         unsigned flags;                 // See US_ flags below
250         long timescalled;               // Total number of logins
251         long posted;                    // Number of messages ever submitted
252         uint8_t axlevel;                // Access level
253         long usernum;                   // User number (never recycled)
254         time_t lastcall;                // Date/time of most recent login
255         int USuserpurge;                // Purge time (in days) for user
256         char fullname[64];              // Display name (primary identifier)
257         char emailaddrs[512];           // Internet email addresses
258 };
259
260 typedef struct ctdlroom ctdlroom;
261 struct ctdlroom {
262         char QRname[ROOMNAMELEN];       /* Name of room                     */
263         char QRpasswd[10];              /* Only valid if it's a private rm  */
264         long QRroomaide;                /* User number of room aide         */
265         long QRhighest;                 /* Highest message NUMBER in room   */
266         time_t QRgen;                   /* Generation number of room        */
267         unsigned QRflags;               /* See flag values below            */
268         char QRdirname[15];             /* Directory name, if applicable    */
269         long QRinfo;                    /* Info file update relative to msgs*/
270         char QRfloor;                   /* Which floor this room is on      */
271         time_t QRmtime;                 /* Date/time of last post           */
272         struct ExpirePolicy QRep;       /* Message expiration policy        */
273         long QRnumber;                  /* Globally unique room number      */
274         char QRorder;                   /* Sort key for room listing order  */
275         unsigned QRflags2;              /* Additional flags                 */
276         int QRdefaultview;              /* How to display the contents      */
277 };
278
279
280 /* C constructor */
281 CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf);
282 /* C destructor */
283 void CtdlIPC_delete(CtdlIPC* ipc);
284 /* Convenience destructor; also nulls out caller's pointer */
285 void CtdlIPC_delete_ptr(CtdlIPC** pipc);
286 /* Read a line from server, discarding newline, for chat, will go away */
287 void CtdlIPC_chat_recv(CtdlIPC* ipc, char *buf);
288 /* Write a line to server, adding newline, for chat, will go away */
289 void CtdlIPC_chat_send(CtdlIPC* ipc, const char *buf);
290
291 struct ctdlipcroom {
292         char RRname[ROOMNAMELEN];       /* Name of room */
293         long RRunread;                  /* Number of unread messages */
294         long RRtotal;                   /* Total number of messages in room */
295         char RRinfoupdated;             /* Nonzero if info was updated */
296         unsigned RRflags;               /* Various flags (see LKRN) */
297         unsigned RRflags2;              /* Various flags (see LKRN) */
298         long RRhighest;                 /* Highest message number in room */
299         long RRlastread;                /* Highest message user has read */
300         char RRismailbox;               /* Is this room a mailbox room? */
301         char RRaide;                    /* User can do aide commands in room */
302         long RRnewmail;                 /* Number of new mail messages */
303         char RRfloor;                   /* Which floor this room is on */
304         char RRcurrentview;             /* The user's current view for this room */
305         char RRdefaultview;             /* The default view for this room */
306 };
307
308
309 struct parts {
310         struct parts *next;
311         char number[16];                /* part number */
312         char name[PATH_MAX];            /* Name */
313         char filename[PATH_MAX];        /* Suggested filename */
314         char mimetype[SIZ];             /* MIME type */
315         char disposition[SIZ];          /* Content disposition */
316         unsigned long length;           /* Content length */
317 };
318
319
320 struct ctdlipcmessage {
321         char msgid[SIZ];                /* Original message ID */
322         char path[SIZ];                 /* Return path to sender */
323         char zaps[SIZ];                 /* Message ID that this supersedes */
324         char subject[SIZ];              /* Message subject */
325         char email[SIZ];                /* Email address of sender */
326         char author[SIZ];               /* Sender of message */
327         char recipient[SIZ];            /* Recipient of message */
328         char room[SIZ];                 /* Originating room */
329         struct parts *attachments;      /* Available attachments */
330         char *text;                     /* Message text */
331         int type;                       /* Message type */
332         time_t time;                    /* Time message was posted */
333         char nhdr;                      /* Suppress message header? */
334         char anonymous;                 /* An anonymous message */
335         char mime_chosen[SIZ];          /* Chosen MIME part to output */
336         char content_type[SIZ];         /* How would you like that? */
337         char references[SIZ];           /* Thread references */
338 };
339
340
341 struct ctdlipcfile {
342         char remote_name[PATH_MAX];     /* Filename on server */
343         char local_name[PATH_MAX];      /* Filename on client */
344         char description[80];           /* Description on server */
345         FILE *local_fd;                 /* Open file on client */
346         size_t size;                    /* Size of file in octets */
347         unsigned int upload:1;          /* uploading? 0 if downloading */
348         unsigned int complete:1;        /* Transfer has finished? */
349 };
350
351
352 struct ctdlipcmisc {
353         long newmail;                   /* Number of new Mail messages */
354         char needregis;                 /* Nonzero if user needs to register */
355         char needvalid;                 /* Nonzero if users need validation */
356 };
357
358 enum RoomList {
359         SubscribedRooms,
360         SubscribedRoomsWithNewMessages,
361         SubscribedRoomsWithNoNewMessages,
362         UnsubscribedRooms,
363         AllAccessibleRooms,
364         AllPublicRooms
365 };
366 #define AllFloors -1
367 enum MessageList {
368         AllMessages,
369         OldMessages,
370         NewMessages,
371         LastMessages,
372         FirstMessages,
373         MessagesGreaterThan,
374         MessagesLessThan
375 };
376 enum MessageDirection {
377         ReadReverse = -1,
378         ReadForward = 1
379 };
380 extern char file_citadel_rc[PATH_MAX];
381 extern char file_citadel_config[PATH_MAX];
382
383 /* Shared Diffie-Hellman parameters */
384 #define DH_P            "F6E33BD70D475906ABCFB368DA2D1E5611D57DFDAC6A10CD78F406D6952519C74E21FFDCC5A780B9359722AACC8036E4CD24D5F5165EAC9EF226DBD9BBCF678F8DDEE86386F1BC20E291A9854A513A2CA326B411DC92E38F2ED2FEB6A3B792F13DB6550371FDBAC5ECA373BE5050CA4905431CA86088737D52B36C8D13CE9CB4EEF4C910285035E8329DD07551A80B87775676DD1067395CCEE9040C9B8BF998C528B3772B4C590A2CF18C5E58929BFCB538A62638B7437A9C68572D15287E97692B0B1EC5444D9DAB6EB062D20B79CA005EC5035065567AFD1FEF9B251D74747C6065D8C8B6B0862D1EE03F3A244C429EADE0CCC5C3A4196F5CBF5AA01A9026EFB20AA90E462BD64620278F271905EB604F38E6CFAE412EAA6C468E3B58170909BC18662FE2053224F30BE4FDB93BF9FBF969D91A5427A0665AC7BD1C43701B991094C92F7A935063055617142164F02973EB4ED86DD74D2BBAB3CD3B28F7BBD8D9F925B0FE92F7F7D0568D783F9ECE7AF96FB5AF274B586924B64639733A73ACA8F2BD1E970DF51ADDD983F7F6361A2B0DC4F086DE26D8656EC8813DE4B74D6D57BC1E690AC2FF1682B7E16938565A41D1DC64C75ADB81DA4582613FC68C0FDD327D35E2CDF20D009465303773EF3870FBDB0985EE7002A95D7912BBCC78187C29DB046763B7FABFF44EABE820F8ED0D7230AA0AF24F428F82448345BC099B"
385 #define DH_G            "2"
386 #define DH_L            4096
387 #define CIT_CIPHERS     "ALL:RC4+RSA:+SSLv2:+TLSv1:!MD5:@STRENGTH"      /* see ciphers(1) */
388
389 int CtdlIPCNoop(CtdlIPC *ipc);
390 int CtdlIPCEcho(CtdlIPC *ipc, const char *arg, char *cret);
391 int CtdlIPCQuit(CtdlIPC *ipc);
392 int CtdlIPCLogout(CtdlIPC *ipc);
393 int CtdlIPCTryLogin(CtdlIPC *ipc, const char *username, char *cret);
394 int CtdlIPCTryPassword(CtdlIPC *ipc, const char *passwd, char *cret);
395 int CtdlIPCTryApopPassword(CtdlIPC *ipc, const char *response, char *cret);
396 int CtdlIPCCreateUser(CtdlIPC *ipc, const char *username, int selfservice,
397                 char *cret);
398 int CtdlIPCChangePassword(CtdlIPC *ipc, const char *passwd, char *cret);
399 int CtdlIPCKnownRooms(CtdlIPC *ipc, enum RoomList which, int floor,
400                 struct march **listing, char *cret);
401 int CtdlIPCGetConfig(CtdlIPC *ipc, struct ctdluser **uret, char *cret);
402 int CtdlIPCSetConfig(CtdlIPC *ipc, struct ctdluser *uret, char *cret);
403 int CtdlIPCGotoRoom(CtdlIPC *ipc, const char *room, const char *passwd,
404                 struct ctdlipcroom **rret, char *cret);
405 int CtdlIPCGetMessages(CtdlIPC *ipc, enum MessageList which, int whicharg,
406                 const char *mtemplate, unsigned long **mret, char *cret);
407 int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
408                 struct ctdlipcmessage **mret, char *cret);
409 int CtdlIPCWhoKnowsRoom(CtdlIPC *ipc, char **listing, char *cret);
410 int CtdlIPCServerInfo(CtdlIPC *ipc, char *cret);
411 /* int CtdlIPCReadDirectory(CtdlIPC *ipc, struct ctdlipcfile **files, char *cret); */
412 int CtdlIPCReadDirectory(CtdlIPC *ipc, char **listing, char *cret);
413 int CtdlIPCSetLastRead(CtdlIPC *ipc, long msgnum, char *cret);
414 int CtdlIPCInviteUserToRoom(CtdlIPC *ipc, const char *username, char *cret);
415 int CtdlIPCKickoutUserFromRoom(CtdlIPC *ipc, const char *username, char *cret);
416 int CtdlIPCGetRoomAttributes(CtdlIPC *ipc, struct ctdlroom **qret, char *cret);
417 int CtdlIPCSetRoomAttributes(CtdlIPC *ipc, int forget, struct ctdlroom *qret,
418                 char *cret);
419 int CtdlIPCGetRoomAide(CtdlIPC *ipc, char *cret);
420 int CtdlIPCSetRoomAide(CtdlIPC *ipc, const char *username, char *cret);
421 int CtdlIPCPostMessage(CtdlIPC *ipc, int flag, int *subject_required, 
422                                            struct ctdlipcmessage *mr,
423                                            char *cret);
424 int CtdlIPCRoomInfo(CtdlIPC *ipc, char **iret, char *cret);
425 int CtdlIPCDeleteMessage(CtdlIPC *ipc, long msgnum, char *cret);
426 int CtdlIPCMoveMessage(CtdlIPC *ipc, int copy, long msgnum,
427                 const char *destroom, char *cret);
428 int CtdlIPCDeleteRoom(CtdlIPC *ipc, int for_real, char *cret);
429 int CtdlIPCCreateRoom(CtdlIPC *ipc, int for_real, const char *roomname,
430                 int type, const char *password, int floor, char *cret);
431 int CtdlIPCForgetRoom(CtdlIPC *ipc, char *cret);
432 int CtdlIPCSystemMessage(CtdlIPC *ipc, const char *message, char **mret,
433                 char *cret);
434 int CtdlIPCNextUnvalidatedUser(CtdlIPC *ipc, char *cret);
435 int CtdlIPCGetUserRegistration(CtdlIPC *ipc, const char *username, char **rret,
436                 char *cret);
437 int CtdlIPCValidateUser(CtdlIPC *ipc, const char *username, int axlevel,
438                 char *cret);
439 int CtdlIPCSetRoomInfo(CtdlIPC *ipc, int for_real, const char *info,
440                 char *cret);
441 int CtdlIPCUserListing(CtdlIPC *ipc, char *searchstring, char **list, char *cret);
442 int CtdlIPCSetRegistration(CtdlIPC *ipc, const char *info, char *cret);
443 int CtdlIPCMiscCheck(CtdlIPC *ipc, struct ctdlipcmisc *chek, char *cret);
444 int CtdlIPCDeleteFile(CtdlIPC *ipc, const char *filename, char *cret);
445 int CtdlIPCMoveFile(CtdlIPC *ipc, const char *filename, const char *destroom, char *cret);
446 int CtdlIPCNetSendFile(CtdlIPC *ipc, const char *filename, const char *destnode, char *cret);
447 int CtdlIPCOnlineUsers(CtdlIPC *ipc, char **listing, time_t *stamp, char *cret);
448 int CtdlIPCFileDownload(CtdlIPC *ipc, const char *filename, void **buf,
449                 size_t resume,
450                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
451                 char *cret);
452 int CtdlIPCAttachmentDownload(CtdlIPC *ipc, long msgnum, const char *part,
453                 void **buf,
454                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
455                 char *cret);
456 int CtdlIPCImageDownload(CtdlIPC *ipc, const char *filename, void **buf,
457                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
458                 char *cret);
459 int CtdlIPCFileUpload(CtdlIPC *ipc, const char *save_as, const char *comment,
460                 const char *path, 
461                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
462                 char *cret);
463 int CtdlIPCImageUpload(CtdlIPC *ipc, int for_real, const char *path,
464                 const char *save_as,
465                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
466                 char *cret);
467 int CtdlIPCQueryUsername(CtdlIPC *ipc, const char *username, char *cret);
468 int CtdlIPCFloorListing(CtdlIPC *ipc, char **listing, char *cret);
469 int CtdlIPCCreateFloor(CtdlIPC *ipc, int for_real, const char *name, char *cret);
470 int CtdlIPCDeleteFloor(CtdlIPC *ipc, int for_real, int floornum, char *cret);
471 int CtdlIPCEditFloor(CtdlIPC *ipc, int floornum, const char *floorname, char *cret);
472 int CtdlIPCIdentifySoftware(CtdlIPC *ipc, int developerid, int clientid,
473                 int revision, const char *software_name, const char *hostname,
474                 char *cret);
475 int CtdlIPCSendInstantMessage(CtdlIPC *ipc, const char *username, const char *text, char *cret);
476 int CtdlIPCGetInstantMessage(CtdlIPC *ipc, char **listing, char *cret);
477 int CtdlIPCEnableInstantMessageReceipt(CtdlIPC *ipc, int mode, char *cret);
478 int CtdlIPCSetBio(CtdlIPC *ipc, char *bio, char *cret);
479 int CtdlIPCGetBio(CtdlIPC *ipc, const char *username, char **listing, char *cret);
480 int CtdlIPCListUsersWithBios(CtdlIPC *ipc, char **listing, char *cret);
481 int CtdlIPCStealthMode(CtdlIPC *ipc, int mode, char *cret);
482 int CtdlIPCTerminateSession(CtdlIPC *ipc, int sid, char *cret);
483 int CtdlIPCTerminateServerNow(CtdlIPC *ipc, char *cret);
484 int CtdlIPCTerminateServerScheduled(CtdlIPC *ipc, int mode, char *cret);
485 int CtdlIPCEnterSystemMessage(CtdlIPC *ipc, const char *filename, const char *text, char *cret);
486 time_t CtdlIPCServerTime(CtdlIPC *ipc, char *crert);
487 int CtdlIPCAideGetUserParameters(CtdlIPC *ipc, const char *who, struct ctdluser **uret, char *cret);
488 int CtdlIPCAideGetEmailAddresses(CtdlIPC *ipc, const char *who, char *, char *cret);
489 int CtdlIPCAideSetUserParameters(CtdlIPC *ipc, const struct ctdluser *uret, char *cret);
490 int CtdlIPCAideSetEmailAddresses(CtdlIPC *ipc, const char *who, char *emailaddrs, char *cret);
491 int CtdlIPCRenameUser(CtdlIPC *ipc, char *oldname, char *newname, char *cret);
492 int CtdlIPCGetMessageExpirationPolicy(CtdlIPC *ipc, GPEXWhichPolicy which, struct ExpirePolicy **policy, char *cret);
493 int CtdlIPCSetMessageExpirationPolicy(CtdlIPC *ipc, int which, struct ExpirePolicy *policy, char *cret);
494 int CtdlIPCGetSystemConfig(CtdlIPC *ipc, char **listing, char *cret);
495 int CtdlIPCSetSystemConfig(CtdlIPC *ipc, const char *listing, char *cret);
496 int CtdlIPCGetSystemConfigByType(CtdlIPC *ipc, const char *mimetype, char **listing, char *cret);
497 int CtdlIPCSetSystemConfigByType(CtdlIPC *ipc, const char *mimetype, const char *listing, char *cret);
498 int CtdlIPCGetRoomNetworkConfig(CtdlIPC *ipc, char **listing, char *cret);
499 int CtdlIPCSetRoomNetworkConfig(CtdlIPC *ipc, const char *listing, char *cret);
500 int CtdlIPCRequestClientLogout(CtdlIPC *ipc, int session, char *cret);
501 int CtdlIPCSetMessageSeen(CtdlIPC *ipc, long msgnum, int seen, char *cret);
502 int CtdlIPCStartEncryption(CtdlIPC *ipc, char *cret);
503 int CtdlIPCDirectoryLookup(CtdlIPC *ipc, const char *address, char *cret);
504 int CtdlIPCSpecifyPreferredFormats(CtdlIPC *ipc, char *cret, char *formats);
505 int CtdlIPCInternalProgram(CtdlIPC *ipc, int secret, char *cret);
506
507 /* ************************************************************************** */
508 /*             Stuff below this line is not for public consumption            */
509 /* ************************************************************************** */
510
511 char *CtdlIPCReadListing(CtdlIPC *ipc, char *dest);
512 int CtdlIPCSendListing(CtdlIPC *ipc, const char *listing);
513 size_t CtdlIPCPartialRead(CtdlIPC *ipc, void **buf, size_t offset, size_t bytes, char *cret);
514 int CtdlIPCEndUpload(CtdlIPC *ipc, int discard, char *cret);
515 int CtdlIPCWriteUpload(CtdlIPC *ipc, FILE *uploadFP,
516                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
517                 char *cret);
518 int CtdlIPCEndDownload(CtdlIPC *ipc, char *cret);
519 int CtdlIPCReadDownload(CtdlIPC *ipc, void **buf, size_t bytes, size_t resume,
520                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
521                 char *cret);
522 int CtdlIPCHighSpeedReadDownload(CtdlIPC *ipc, void **buf, size_t bytes,
523                 size_t resume,
524                 void (*progress_gauge_callback)(CtdlIPC*, unsigned long, unsigned long),
525                 char *cret);
526 int CtdlIPCGenericCommand(CtdlIPC *ipc, const char *command,
527                 const char *to_send, size_t bytes_to_send, char **to_receive,
528                 size_t *bytes_to_receive, char *proto_response);
529
530 /* Internals */
531 int starttls(CtdlIPC *ipc);
532 void setCryptoStatusHook(void (*hook)(char *s));
533 void CtdlIPC_SetNetworkStatusCallback(CtdlIPC *ipc, void (*hook)(int state));
534 /* This is all Ford's doing.  FIXME: figure out what it's doing */
535 extern int (*error_printf)(char *s, ...);
536 void setIPCDeathHook(void (*hook)(void));
537 void setIPCErrorPrintf(int (*func)(char *s, ...));
538 void connection_died(CtdlIPC* ipc, int using_ssl);
539 int CtdlIPC_getsockfd(CtdlIPC* ipc);
540 char CtdlIPC_get(CtdlIPC* ipc);
541 void CtdlIPC_lock(CtdlIPC *ipc);
542 void CtdlIPC_unlock(CtdlIPC *ipc);
543 char *libcitadelclient_version_string(void);
544 void chatmode(CtdlIPC *ipc);
545 void page_user(CtdlIPC *ipc);
546 void quiet_mode(CtdlIPC *ipc);
547 void stealth_mode(CtdlIPC *ipc);
548 extern char last_paged[];
549
550 void determine_pwfilename(char *pwfile, size_t n);
551 void get_stored_password(
552                 char *host,
553                 char *port,
554                 char *username,
555                 char *password);
556 void set_stored_password(
557                 char *host,
558                 char *port,
559                 char *username,
560                 char *password);
561 void offer_to_remember_password(CtdlIPC *ipc,
562                 char *host,
563                 char *port,
564                 char *username,
565                 char *password);
566
567 void load_command_set(void);
568 void stty_ctdl(int cmd);
569 void newprompt(char *prompt, char *str, int len);
570 void strprompt(char *prompt, char *str, int len);
571 int boolprompt(char *prompt, int prev_val);
572 int intprompt(char *prompt, int ival, int imin, int imax);
573 int fmout(int width, FILE *fpin, char *text, FILE *fpout, int subst);
574 int getcmd(CtdlIPC *ipc, char *argbuf);
575 void display_help(CtdlIPC *ipc, char *name);
576 void color(int colornum);
577 void cls(int colornum);
578 void send_ansi_detect(void);
579 void look_for_ansi(void);
580 int inkey(void);
581 void set_keepalives(int s);
582 extern int enable_color;
583 int yesno(void);
584 int yesno_d(int d);
585 void keyopt(char *);
586 char keymenu(char *menuprompt, char *menustring);
587 void async_ka_start(void);
588 void async_ka_end(void);
589 int checkpagin(int lp, unsigned int pagin, unsigned int height);
590 char was_a_key_pressed(void);
591
592 #ifdef __GNUC__
593 void pprintf(const char *format, ...) __attribute__((__format__(__printf__,1,2)));
594 #else
595 void pprintf(const char *format, ...);
596 #endif
597
598
599 extern char rc_url_cmd[SIZ];
600 extern char rc_open_cmd[SIZ];
601 extern char rc_gotmail_cmd[SIZ];
602 extern int lines_printed;
603 extern int rc_remember_passwords;
604
605 #ifndef MD5_H
606 #define MD5_H
607
608 struct MD5Context {
609         uint32_t buf[4];
610         uint32_t bits[2];
611         uint32_t in[16];
612 };
613
614 void MD5Init(struct MD5Context *context);
615 void MD5Update(struct MD5Context *context, unsigned char const *buf,
616                unsigned len);
617 void MD5Final(unsigned char digest[16], struct MD5Context *context);
618 void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
619 char *make_apop_string(char *realpass, char *nonce, char *buffer, size_t n);
620
621 /*
622  * This is needed to make RSAREF happy on some MS-DOS compilers.
623  */
624 #ifndef HAVE_OPENSSL
625 typedef struct MD5Context MD5_CTX;
626 #endif
627
628 #define MD5_DIGEST_LEN          16
629 #define MD5_HEXSTRING_SIZE      33
630
631 #endif /* !MD5_H */
632
633
634 #define MAXURLS         50      /* Max embedded URL's per message */
635 extern int num_urls;
636 extern char urls[MAXURLS][SIZ];
637
638 int ka_system(char *shc);
639 int entmsg(CtdlIPC *ipc, int is_reply, int c, int masquerade);
640 void readmsgs(CtdlIPC *ipc, enum MessageList c, enum MessageDirection rdir, int q);
641 void edit_system_message(CtdlIPC *ipc, char *which_message);
642 pid_t ka_wait(int *kstatus);
643 void list_urls(CtdlIPC *ipc);
644 int client_make_message(CtdlIPC *ipc,
645                         char *filename,         /* temporary file name */
646                         char *recipient,        /* NULL if it's not mail */
647                         int anon_type,          /* see MES_ types in header file */
648                         int format_type,
649                         int mode,
650                         char *subject,
651                         int subject_required
652 );
653 void citedit(FILE *);
654 char *load_message_from_file(FILE *src);
655 int file_checksum(char *filename);
656 void listzrooms(CtdlIPC *ipc);
657 void readinfo(CtdlIPC *ipc);
658 void forget(CtdlIPC *ipc);
659 void entroom(CtdlIPC *ipc);
660 void killroom(CtdlIPC *ipc);
661 void invite(CtdlIPC *ipc);
662 void kickout(CtdlIPC *ipc);
663 void editthisroom(CtdlIPC *ipc);
664 void roomdir(CtdlIPC *ipc);
665 void download(CtdlIPC *ipc, int proto);
666 void ungoto(CtdlIPC *ipc);
667 void dotungoto(CtdlIPC *ipc, char *towhere);
668 void whoknows(CtdlIPC *ipc);
669 void enterinfo(CtdlIPC *ipc);
670 void knrooms(CtdlIPC *ipc, int kn_floor_mode);
671 void dotknown(CtdlIPC *ipc, int what, char *match);
672 void load_floorlist(CtdlIPC *ipc);
673 void create_floor(CtdlIPC *ipc);
674 void edit_floor(CtdlIPC *ipc);
675 void kill_floor(CtdlIPC *ipc);
676 void enter_bio(CtdlIPC *ipc);
677 int save_buffer(void *file, size_t filelen, const char *pathname);
678 void destination_directory(char *dest, const char *supplied_filename);
679 void do_edit(CtdlIPC *ipc, char *desc, char *read_cmd, char *check_cmd, char *write_cmd);
680
681
682 /* 
683  * This struct holds a list of rooms for client display.
684  * (oooh, a tree!)
685  */
686 struct ctdlroomlisting {
687         struct ctdlroomlisting *lnext;
688         struct ctdlroomlisting *rnext;
689         char rlname[ROOMNAMELEN];
690         unsigned rlflags;
691         int rlfloor;
692         int rlorder;
693         };
694
695
696 enum {
697         LISTRMS_NEW_ONLY,
698         LISTRMS_OLD_ONLY,
699         LISTRMS_ALL
700 };
701
702
703 void updatels(CtdlIPC *ipc);
704 void updatelsa(CtdlIPC *ipc);
705 void movefile(CtdlIPC *ipc);
706 void deletefile(CtdlIPC *ipc);
707 void netsendfile(CtdlIPC *ipc);
708 void entregis(CtdlIPC *ipc);
709 void subshell(void);
710 void upload(CtdlIPC *ipc, int c);
711 void cli_upload(CtdlIPC *ipc);
712 void validate(CtdlIPC *ipc);
713 void read_bio(CtdlIPC *ipc);
714 void cli_image_upload(CtdlIPC *ipc, char *keyname);
715 int room_prompt(unsigned int qrflags);
716 int val_user(CtdlIPC *ipc, char *user, int do_validate);
717
718 void edituser(CtdlIPC *ipc, int cmd);
719 void interr(int errnum);
720 int struncmp(char *lstr, char *rstr, int len);
721 int pattern(char *search, char *patn);
722 void enter_config(CtdlIPC* ipc, int mode);
723 void locate_host(CtdlIPC* ipc, char *hbuf);
724 void misc_server_cmd(CtdlIPC *ipc, char *cmd);
725 int nukedir(char *dirname);
726 void strproc(char *string);
727 void back(int spaces);
728 void progress(CtdlIPC* ipc, unsigned long curr, unsigned long cmax);
729 int set_attr(CtdlIPC *ipc, unsigned int sval, char *prompt, unsigned int sbit, int backwards);
730
731 void screen_new(void);
732 int scr_printf(char *fmt, ...);
733 #define SCR_NOBLOCK 0
734 #define SCR_BLOCK -1
735 int scr_getc(int delay);
736 int scr_putc(int c);
737 void scr_flush(void);
738 int scr_blockread(void);
739 sighandler_t scr_winch(int signum);
740 void wait_indicator(int state);
741 void ctdl_beep(void);
742 void scr_wait_indicator(int);
743 extern char status_line[];
744 extern void check_screen_dims(void);
745 extern int screenwidth;
746 extern int screenheight;
747 void do_internet_configuration(CtdlIPC *ipc);
748 void network_config_management(CtdlIPC *ipc, char *entrytype, char *comment);
749 void do_pop3client_configuration(CtdlIPC *ipc);
750 void do_rssclient_configuration(CtdlIPC *ipc);
751 void do_system_configuration(CtdlIPC *ipc);
752 extern char editor_path[PATH_MAX];
753 extern int enable_status_line;