8 #define INLINE __inline__
15 #define OPENSSL_NO_KRB5 /* work around redhat b0rken ssl headers */
16 #include <openssl/ssl.h>
20 * New format for a message in memory
23 int cm_magic; /* Self-check (NOT SAVED TO DISK) */
24 char cm_anon_type; /* Anonymous or author-visible */
25 char cm_format_type; /* Format type */
26 char *cm_fields[256]; /* Data fields */
27 unsigned int cm_flags; /* How to handle (NOT SAVED TO DISK) */
30 #define CTDLMESSAGE_MAGIC 0x159d
31 #define CM_SKIP_HOOKS 0x01 /* Don't run server-side handlers */
35 * Here's the big one... the Citadel context structure.
37 * This structure keeps track of all information relating to a running
38 * session on the server. We keep one of these for each session thread.
40 * Note that the first element is "*next" so that it may be used without
41 * modification in a linked list.
44 struct CitContext *prev; /* Link to previous session in list */
45 struct CitContext *next; /* Link to next session in the list */
47 int state; /* thread state (see CON_ values below) */
48 int kill_me; /* Set to nonzero to flag for termination */
50 int cs_pid; /* session ID */
51 time_t lastcmd; /* time of last command executed */
52 time_t lastidle; /* For computing idle time */
54 char curr_user[USERNAME_SIZE]; /* name of current user */
55 int logged_in; /* logged in */
56 int internal_pgm; /* authenticated as internal program */
57 char temp[PATH_MAX]; /* temp file name */
58 int nologin; /* not allowed to log in */
59 int is_local_socket; /* set to 1 if client is on unix domain sock */
60 int curr_view; /* The view type for the current user/room */
62 char net_node[PATH_MAX];/* Is the client another Citadel server? */
63 time_t previous_login; /* Date/time of previous login */
64 char lastcmdname[5]; /* name of last command executed */
65 unsigned cs_flags; /* miscellaneous flags */
66 void (*h_command_function) (void) ; /* service command function */
67 void (*h_async_function) (void) ; /* do async msgs function */
68 int is_async; /* Nonzero if client accepts async msgs */
69 int async_waiting; /* Nonzero if there are async msgs waiting */
70 int input_waiting; /* Nonzero if there is client input waiting */
72 /* feeping creaturisms... */
73 int cs_clientdev; /* client developer ID */
74 int cs_clienttyp; /* client type code */
75 int cs_clientver; /* client version number */
76 char cs_clientname[32]; /* name of client software */
77 char cs_host[64]; /* host logged in from */
78 char cs_addr[64]; /* address logged in from */
80 /* The Internet type of thing */
81 char cs_inet_email[SIZ];/* Return address of outbound Internet mail */
83 FILE *download_fp; /* Fields relating to file transfer */
84 char download_desired_section[128];
86 char upl_file[PATH_MAX];
87 char upl_path[PATH_MAX];
88 char upl_comment[SIZ];
89 char upl_filedir[PATH_MAX];
93 struct ctdluser user; /* Database record buffers */
96 /* Beginning of cryptography - session nonce */
97 char cs_nonce[NONCE_SIZE]; /* The nonce for this session's next auth transaction */
99 /* Redirect this session's output to somewhere else? */
100 FILE *redirect_fp; /* a file instead (will go away) */
101 char *redirect_buffer; /* the buffer */
102 size_t redirect_len; /* length of data in buffer */
103 size_t redirect_alloc; /* length of allocated buffer */
110 char *output_buffer; /* hold output for one big dump */
113 /* A linked list of all instant messages sent to us. */
114 struct ExpressMessage *FirstExpressMessage;
115 int disable_exp; /* Set to 1 to disable incoming pages */
116 int newmail; /* Other sessions increment this */
119 char fake_username[USERNAME_SIZE]; /* Fake username <bc> */
120 char fake_postname[USERNAME_SIZE]; /* Fake postname <bc> */
121 char fake_hostname[64]; /* Fake hostname <bc> */
122 char fake_roomname[ROOMNAMELEN]; /* Fake roomname <bc> */
124 char preferred_formats[SIZ]; /* Preferred MIME formats */
126 /* Dynamically allocated session data */
127 struct citimap *IMAP;
128 struct citpop3 *POP3;
129 struct citsmtp *SMTP;
132 struct cit_ical *CIT_ICAL; /* calendaring data */
133 struct ma_info *ma; /* multipart/alternative data */
136 typedef struct CitContext t_context;
139 * Values for CitContext.state
141 * A session that is doing nothing is in CON_IDLE state. When activity
142 * is detected on the socket, it goes to CON_READY, indicating that it
143 * needs to have a worker thread bound to it. When a thread binds to
144 * the session, it goes to CON_EXECUTING and does its thing. When the
145 * transaction is finished, the thread sets it back to CON_IDLE and lets
149 CON_IDLE, /* This context is doing nothing */
150 CON_READY, /* This context needs attention */
151 CON_EXECUTING /* This context is bound to a thread */
155 #define CS_STEALTH 1 /* stealth mode */
156 #define CS_CHAT 2 /* chat mode */
157 #define CS_POSTING 4 /* Posting */
159 struct CitContext *MyContext(void);
160 #define CC MyContext()
162 extern struct CitContext *ContextList;
163 extern int ScheduledShutdown;
164 extern struct CitControl CitControl;
167 struct ExpressMessage {
168 struct ExpressMessage *next;
169 time_t timestamp; /* When this message was sent */
170 unsigned flags; /* Special instructions */
171 char sender[64]; /* Name of sending user */
172 char *text; /* Message text (if applicable) */
175 #define EM_BROADCAST 1 /* Broadcast message */
176 #define EM_GO_AWAY 2 /* Server requests client log off */
177 #define EM_CHAT 4 /* Server requests client enter chat */
180 struct ChatLine *next;
184 char chat_username[USERNAME_SIZE];
185 char chat_room[ROOMNAMELEN];
189 * Various things we need to lock and unlock
223 * message transfer formats
226 MT_CITADEL, /* Citadel proprietary */
227 MT_RFC822, /* RFC822 */
228 MT_MIME, /* MIME-formatted message */
229 MT_DOWNLOAD /* Download a component */
233 * Message format types in the database
235 #define FMT_CITADEL 0 /* Citadel vari-format (proprietary) */
236 #define FMT_FIXED 1 /* Fixed format (proprietary) */
237 #define FMT_RFC822 4 /* Standard (headers are in M field) */
241 * Citadel DataBases (define one for each cdb we need to open)
244 CDB_MSGMAIN, /* message base */
245 CDB_USERS, /* user file */
246 CDB_ROOMS, /* room index */
247 CDB_FLOORTAB, /* floor index */
248 CDB_MSGLISTS, /* room message lists */
249 CDB_VISIT, /* user/room relationships */
250 CDB_DIRECTORY, /* address book directory */
251 CDB_USETABLE, /* network use table */
252 CDB_BIGMSGS, /* larger message bodies */
253 MAXCDB /* total number of CDB's defined */
263 /* Structures and declarations for function hooks of various types */
265 struct LogFunctionHook {
266 struct LogFunctionHook *next;
268 void (*h_function_pointer) (char *);
270 extern struct LogFunctionHook *LogHookTable;
272 struct CleanupFunctionHook {
273 struct CleanupFunctionHook *next;
274 void (*h_function_pointer) (void);
276 extern struct CleanupFunctionHook *CleanupHookTable;
282 * SessionFunctionHook extensions are used for any type of hook for which
283 * the context in which it's being called (which is determined by the event
284 * type) will make it obvious for the hook function to know where to look for
287 struct SessionFunctionHook {
288 struct SessionFunctionHook *next;
289 void (*h_function_pointer) (void);
292 extern struct SessionFunctionHook *SessionHookTable;
295 * Event types can't be enum'ed, because they must remain consistent between
296 * builds (to allow for binary modules built somewhere else)
298 #define EVT_STOP 0 /* Session is terminating */
299 #define EVT_START 1 /* Session is starting */
300 #define EVT_LOGIN 2 /* A user is logging in */
301 #define EVT_NEWROOM 3 /* Changing rooms */
302 #define EVT_LOGOUT 4 /* A user is logging out */
303 #define EVT_SETPASS 5 /* Setting or changing password */
304 #define EVT_CMD 6 /* Called after each server command */
305 #define EVT_RWHO 7 /* An RWHO command is being executed */
306 #define EVT_ASYNC 8 /* Doing asynchronous messages */
308 #define EVT_TIMER 50 /* Timer events are called once per minute
309 and are not tied to any session */
312 * UserFunctionHook extensions are used for any type of hook which implements
313 * an operation on a user or username (potentially) other than the one
314 * operating the current session.
316 struct UserFunctionHook {
317 struct UserFunctionHook *next;
318 void (*h_function_pointer) (struct ctdluser *usbuf);
321 extern struct UserFunctionHook *UserHookTable;
323 #define EVT_PURGEUSER 100 /* Deleting a user */
324 #define EVT_NEWUSER 102 /* Creating a user */
327 * MessageFunctionHook extensions are used for hooks which implement handlers
328 * for various types of message operations (save, read, etc.)
330 struct MessageFunctionHook {
331 struct MessageFunctionHook *next;
332 int (*h_function_pointer) (struct CtdlMessage *msg);
335 extern struct MessageFunctionHook *MessageHookTable;
337 #define EVT_BEFOREREAD 200
338 #define EVT_BEFORESAVE 201
339 #define EVT_AFTERSAVE 202
340 #define EVT_SMTPSCAN 203 /* called before submitting a msg from SMTP */
345 * NetprocFunctionHook extensions are used for hooks which implement handlers
346 * for incoming network messages.
348 struct NetprocFunctionHook {
349 struct NetprocFunctionHook *next;
350 int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
352 extern struct NetprocFunctionHook *NetprocHookTable;
356 * DeleteFunctionHook extensions are used for hooks which get called when a
357 * message is about to be deleted.
359 struct DeleteFunctionHook {
360 struct DeleteFunctionHook *next;
361 void (*h_function_pointer) (char *target_room, long msgnum);
363 extern struct DeleteFunctionHook *DeleteHookTable;
367 * ExpressMessageFunctionHook extensions are used for hooks which implement
368 * the sending of an instant message through various channels. Any function
369 * registered should return the number of recipients to whom the message was
370 * successfully transmitted.
372 struct XmsgFunctionHook {
373 struct XmsgFunctionHook *next;
374 int (*h_function_pointer) (char *, char *, char *);
377 extern struct XmsgFunctionHook *XmsgHookTable;
379 /* Priority levels for paging functions (lower is better) */
381 XMSG_PRI_LOCAL, /* Other users on -this- server */
382 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
383 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
390 * ServiceFunctionHook extensions are used for hooks which implement various
391 * non-Citadel services (on TCP protocols) directly in the Citadel server.
393 struct ServiceFunctionHook {
394 struct ServiceFunctionHook *next;
397 void (*h_greeting_function) (void) ;
398 void (*h_command_function) (void) ;
399 void (*h_async_function) (void) ;
402 extern struct ServiceFunctionHook *ServiceHookTable;
406 /* Defines the relationship of a user to a particular room */
412 unsigned int v_flags;
414 char v_answered[SIZ];
418 #define V_FORGET 1 /* User has zapped this room */
419 #define V_LOCKOUT 2 /* User is locked out of this room */
420 #define V_ACCESS 4 /* Access is granted to this room */
423 /* Supplementary data for a message on disk
424 * These are kept separate from the message itself for one of two reasons:
425 * 1. Either their values may change at some point after initial save, or
426 * 2. They are merely caches of data which exist somewhere else, for speed.
429 long meta_msgnum; /* Message number in *local* message base */
430 int meta_refcount; /* Number of rooms pointing to this msg */
431 char meta_content_type[64]; /* Cached MIME content-type */
432 long meta_rfc822_length; /* Cache of RFC822-translated msg length */
437 * Serialization routines use this struct to return a pointer and a length
445 /* Preferred field order */
446 /* ********** Important fields */
447 /* *************** Semi-important fields */
448 /* * Message text (MUST be last) */
449 #define FORDER "IPTAFONHRDBCEGJKLQSVWXYZUM"
451 #endif /* SERVER_H */