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