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