8 #define INLINE __inline__
15 #include <openssl/ssl.h>
19 * New format for a message in memory
22 int cm_magic; /* Self-check (NOT SAVED TO DISK) */
23 char cm_anon_type; /* Anonymous or author-visible */
24 char cm_format_type; /* Format type */
25 char *cm_fields[256]; /* Data fields */
26 unsigned int cm_flags; /* How to handle (NOT SAVED TO DISK) */
29 #define CTDLMESSAGE_MAGIC 0x159d
30 #define CM_SKIP_HOOKS 0x01 /* Don't run server-side handlers */
34 * Generic per-session variable or data structure storage
37 struct CtdlSessData *next;
43 * Static user data symbol types. Server extensions can ask for dynamic
44 * extensions to per-session data, but the symbol ID has to be listed here.
47 SYM_DESIRED_SECTION, /* Used by the MIME parser */
48 SYM_MA_INFO, /* Handles multipart/alternative */
49 SYM_REPL, /* Used for replication checking */
50 SYM_CIT_ICAL, /* Used by the calendar service */
51 SYM_IMAP, /* Used by the IMAP service */
52 SYM_POP3, /* Used by the POP3 service */
53 SYM_SMTP, /* Used by the SMTP service */
56 SYM_VCARD, /* vCard handling requires this */
62 * Here's the big one... the Citadel context structure.
64 * This structure keeps track of all information relating to a running
65 * session on the server. We keep one of these for each session thread.
67 * Note that the first element is "*next" so that it may be used without
68 * modification in a linked list.
71 struct CitContext *next; /* Link to next session in the list */
73 struct ctdluser user; /* Database record buffers */
76 int state; /* thread state (see CON_ values below) */
77 int kill_me; /* Set to nonzero to flag for termination */
79 char curr_user[USERNAME_SIZE]; /* name of current user */
80 int logged_in; /* logged in */
81 int internal_pgm; /* authenticated as internal program */
82 char temp[PATH_MAX]; /* temp file name */
83 int nologin; /* not allowed to log in */
84 int is_local_socket; /* set to 1 if client is on unix domain sock */
86 char net_node[PATH_MAX];/* Is the client another Citadel server? */
88 int cs_pid; /* session ID */
89 time_t lastcmd; /* time of last command executed */
90 time_t lastidle; /* For computing idle time */
91 time_t previous_login; /* Date/time of previous login */
92 char lastcmdname[5]; /* name of last command executed */
93 unsigned cs_flags; /* miscellaneous flags */
94 void (*h_command_function) (void) ; /* service command function */
95 int is_async; /* Nonzero if client accepts async msgs */
97 /* feeping creaturisms... */
98 int cs_clientdev; /* client developer ID */
99 int cs_clienttyp; /* client type code */
100 int cs_clientver; /* client version number */
101 char cs_clientname[32]; /* name of client software */
102 char cs_host[64]; /* host logged in from */
103 char cs_addr[64]; /* address logged in from */
105 /* The Internet type of thing */
106 char cs_inet_email[SIZ];/* Return address of outbound Internet mail */
108 FILE *download_fp; /* Fields relating to file transfer */
110 char upl_file[PATH_MAX];
111 char upl_path[PATH_MAX];
112 char upl_comment[SIZ];
113 char upl_filedir[PATH_MAX];
117 /* Beginning of cryptography - session nonce */
118 char cs_nonce[NONCE_SIZE]; /* The nonce for this session's next auth transaction */
120 /* Redirect this session's output to somewhere else? */
129 char *output_buffer; /* hold output for one big dump */
132 /* A linked list of all instant messages sent to us. */
133 struct ExpressMessage *FirstExpressMessage;
134 int disable_exp; /* Set to 1 to disable incoming pages */
135 int newmail; /* Other sessions increment this */
138 char fake_username[USERNAME_SIZE]; /* Fake username <bc> */
139 char fake_postname[USERNAME_SIZE]; /* Fake postname <bc> */
140 char fake_hostname[64]; /* Fake hostname <bc> */
141 char fake_roomname[ROOMNAMELEN]; /* Fake roomname <bc> */
143 char preferred_formats[SIZ]; /* Preferred MIME formats */
145 /* Dynamically allocated session data */
146 struct CtdlSessData *FirstSessData;
149 typedef struct CitContext t_context;
152 * Values for CitContext.state
154 * A session that is doing nothing is in CON_IDLE state. When activity
155 * is detected on the socket, it goes to CON_READY, indicating that it
156 * needs to have a worker thread bound to it. When a thread binds to
157 * the session, it goes to CON_EXECUTING and does its thing. When the
158 * transaction is finished, the thread sets it back to CON_IDLE and lets
162 CON_IDLE, /* This context is doing nothing */
163 CON_READY, /* This context needs attention */
164 CON_EXECUTING, /* This context is bound to a thread */
168 #define CS_STEALTH 1 /* stealth mode */
169 #define CS_CHAT 2 /* chat mode */
170 #define CS_POSTING 4 /* Posting */
172 struct CitContext *MyContext(void);
173 #define CC MyContext()
175 extern struct CitContext *ContextList;
176 extern int ScheduledShutdown;
177 extern struct CitControl CitControl;
180 struct ExpressMessage {
181 struct ExpressMessage *next;
182 time_t timestamp; /* When this message was sent */
183 unsigned flags; /* Special instructions */
184 char sender[64]; /* Name of sending user */
185 char *text; /* Message text (if applicable) */
188 #define EM_BROADCAST 1 /* Broadcast message */
189 #define EM_GO_AWAY 2 /* Server requests client log off */
190 #define EM_CHAT 4 /* Server requests client enter chat */
193 struct ChatLine *next;
197 char chat_username[USERNAME_SIZE];
198 char chat_room[ROOMNAMELEN];
202 * Various things we need to lock and unlock
238 * message transfer formats
241 MT_CITADEL, /* Citadel proprietary */
242 MT_RFC822, /* RFC822 */
243 MT_MIME, /* MIME-formatted message */
244 MT_DOWNLOAD /* Download a component */
248 * Message format types in the database
250 #define FMT_CITADEL 0 /* Citadel vari-format (proprietary) */
251 #define FMT_FIXED 1 /* Fixed format (proprietary) */
252 #define FMT_RFC822 4 /* Standard (headers are in M field) */
256 * Citadel DataBases (define one for each cdb we need to open)
259 CDB_MSGMAIN, /* message base */
260 CDB_USERS, /* user file */
261 CDB_ROOMS, /* room index */
262 CDB_FLOORTAB, /* floor index */
263 CDB_MSGLISTS, /* room message lists */
264 CDB_VISIT, /* user/room relationships */
265 CDB_DIRECTORY, /* address book directory */
266 CDB_USETABLE, /* network use table */
267 MAXCDB /* total number of CDB's defined */
277 /* Structures and declarations for function hooks of various types */
279 struct LogFunctionHook {
280 struct LogFunctionHook *next;
282 void (*h_function_pointer) (char *);
284 extern struct LogFunctionHook *LogHookTable;
286 struct CleanupFunctionHook {
287 struct CleanupFunctionHook *next;
288 void (*h_function_pointer) (void);
290 extern struct CleanupFunctionHook *CleanupHookTable;
296 * SessionFunctionHook extensions are used for any type of hook for which
297 * the context in which it's being called (which is determined by the event
298 * type) will make it obvious for the hook function to know where to look for
301 struct SessionFunctionHook {
302 struct SessionFunctionHook *next;
303 void (*h_function_pointer) (void);
306 extern struct SessionFunctionHook *SessionHookTable;
309 * Event types can't be enum'ed, because they must remain consistent between
310 * builds (to allow for binary modules built somewhere else)
312 #define EVT_STOP 0 /* Session is terminating */
313 #define EVT_START 1 /* Session is starting */
314 #define EVT_LOGIN 2 /* A user is logging in */
315 #define EVT_NEWROOM 3 /* Changing rooms */
316 #define EVT_LOGOUT 4 /* A user is logging out */
317 #define EVT_SETPASS 5 /* Setting or changing password */
318 #define EVT_CMD 6 /* Called after each server command */
319 #define EVT_RWHO 7 /* An RWHO command is being executed */
321 #define EVT_TIMER 50 /* Timer events are called once per minute
322 and are not tied to any session */
325 * UserFunctionHook extensions are used for any type of hook which implements
326 * an operation on a user or username (potentially) other than the one
327 * operating the current session.
329 struct UserFunctionHook {
330 struct UserFunctionHook *next;
331 void (*h_function_pointer) (struct ctdluser *usbuf);
334 extern struct UserFunctionHook *UserHookTable;
336 #define EVT_PURGEUSER 100 /* Deleting a user */
337 #define EVT_NEWUSER 102 /* Creating a user */
340 * MessageFunctionHook extensions are used for hooks which implement handlers
341 * for various types of message operations (save, read, etc.)
343 struct MessageFunctionHook {
344 struct MessageFunctionHook *next;
345 int (*h_function_pointer) (struct CtdlMessage *msg);
348 extern struct MessageFunctionHook *MessageHookTable;
350 #define EVT_BEFOREREAD 200
351 #define EVT_BEFORESAVE 201
352 #define EVT_AFTERSAVE 202
353 #define EVT_SMTPSCAN 203 /* called before submitting a msg from SMTP */
358 * NetprocFunctionHook extensions are used for hooks which implement handlers
359 * for incoming network messages.
361 struct NetprocFunctionHook {
362 struct NetprocFunctionHook *next;
363 int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
365 extern struct NetprocFunctionHook *NetprocHookTable;
369 * DeleteFunctionHook extensions are used for hooks which get called when a
370 * message is about to be deleted.
372 struct DeleteFunctionHook {
373 struct DeleteFunctionHook *next;
374 void (*h_function_pointer) (char *target_room, long msgnum);
376 extern struct DeleteFunctionHook *DeleteHookTable;
380 * ExpressMessageFunctionHook extensions are used for hooks which implement
381 * the sending of an instant message through various channels. Any function
382 * registered should return the number of recipients to whom the message was
383 * successfully transmitted.
385 struct XmsgFunctionHook {
386 struct XmsgFunctionHook *next;
387 int (*h_function_pointer) (char *, char *, char *);
390 extern struct XmsgFunctionHook *XmsgHookTable;
392 /* Priority levels for paging functions (lower is better) */
394 XMSG_PRI_LOCAL, /* Other users on -this- server */
395 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
396 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
403 * ServiceFunctionHook extensions are used for hooks which implement various
404 * non-Citadel services (on TCP protocols) directly in the Citadel server.
406 struct ServiceFunctionHook {
407 struct ServiceFunctionHook *next;
410 void (*h_greeting_function) (void) ;
411 void (*h_command_function) (void) ;
414 extern struct ServiceFunctionHook *ServiceHookTable;
418 /* Defines the relationship of a user to a particular room */
424 unsigned int v_flags;
426 char v_answered[SIZ];
430 #define V_FORGET 1 /* User has zapped this room */
431 #define V_LOCKOUT 2 /* User is locked out of this room */
432 #define V_ACCESS 4 /* Access is granted to this room */
435 /* Supplementary data for a message on disk
436 * (These are kept separately from the message itself because they are
437 * fields whose values may change at some point after the message is saved.)
440 long meta_msgnum; /* Message number in *local* message base */
441 int meta_refcount; /* Number of rooms which point to this msg */
442 char meta_content_type[64];
443 /* more stuff will be added to this record in the future */
448 * Serialization routines use this struct to return a pointer and a length
456 /* Preferred field order */
457 /* ********** Important fields */
458 /* *************** Semi-important fields */
459 /* * Message text (MUST be last) */
460 #define FORDER "IPTAFONHRDBCEGJKLQSVWXYZUM"
462 #endif /* SERVER_H */