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