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 */
36 * Exit codes 101 through 109 are used for conditions in which
37 * we deliberately do NOT want the service to automatically
40 #define CTDLEXIT_CONFIG 101 /* Could not read citadel.config */
41 #define CTDLEXIT_CONTROL 102 /* Could not acquire lock */
42 #define CTDLEXIT_HOME 103 /* Citadel home directory not found */
43 #define CTDLEXIT_OOD 104 /* Out Of Date config - rerun setup */
44 #define CTDLEXIT_DB 105 /* Unable to initialize database */
50 * Here's the big one... the Citadel context structure.
52 * This structure keeps track of all information relating to a running
53 * session on the server. We keep one of these for each session thread.
57 struct CitContext *prev; /* Link to previous session in list */
58 struct CitContext *next; /* Link to next session in the list */
60 int state; /* thread state (see CON_ values below) */
61 int kill_me; /* Set to nonzero to flag for termination */
63 int cs_pid; /* session ID */
64 time_t lastcmd; /* time of last command executed */
65 time_t lastidle; /* For computing idle time */
67 char curr_user[USERNAME_SIZE]; /* name of current user */
68 int logged_in; /* logged in */
69 int internal_pgm; /* authenticated as internal program */
70 int nologin; /* not allowed to log in */
71 int is_local_socket; /* set to 1 if client is on unix domain sock */
72 int curr_view; /* The view type for the current user/room */
73 int is_master; /* Is this session logged in using the master user? */
75 char net_node[32] ;/* Is the client another Citadel server? */
76 time_t previous_login; /* Date/time of previous login */
77 char lastcmdname[5]; /* name of last command executed */
78 unsigned cs_flags; /* miscellaneous flags */
79 void (*h_command_function) (void) ; /* service command function */
80 void (*h_async_function) (void) ; /* do async msgs function */
81 int is_async; /* Nonzero if client accepts async msgs */
82 int async_waiting; /* Nonzero if there are async msgs waiting */
83 int input_waiting; /* Nonzero if there is client input waiting */
85 /* Client information */
86 int cs_clientdev; /* client developer ID */
87 int cs_clienttyp; /* client type code */
88 int cs_clientver; /* client version number */
89 char cs_clientname[32]; /* name of client software */
90 char cs_host[64]; /* host logged in from */
91 char cs_addr[64]; /* address logged in from */
93 /* The Internet type of thing */
94 char cs_inet_email[128]; /* Return address of outbound Internet mail */
95 char cs_inet_other_emails[1024]; /* User's other valid Internet email addresses */
96 char cs_inet_fn[128]; /* Friendly-name of outbound Internet mail */
98 FILE *download_fp; /* Fields relating to file transfer */
99 char download_desired_section[128];
102 char upl_path[PATH_MAX];
103 char upl_comment[256];
104 char upl_filedir[PATH_MAX];
108 struct ctdluser user; /* Database record buffers */
109 struct ctdlroom room;
111 /* Beginning of cryptography - session nonce */
112 char cs_nonce[NONCE_SIZE]; /* The nonce for this session's next auth transaction */
114 /* Redirect this session's output to a memory buffer? */
115 char *redirect_buffer; /* the buffer */
116 size_t redirect_len; /* length of data in buffer */
117 size_t redirect_alloc; /* length of allocated buffer */
124 char *output_buffer; /* hold output for one big dump */
127 /* A linked list of all instant messages sent to us. */
128 struct ExpressMessage *FirstExpressMessage;
129 int disable_exp; /* Set to 1 to disable incoming pages */
130 int newmail; /* Other sessions increment this */
132 /* Masqueraded values in the 'who is online' list */
133 char fake_username[USERNAME_SIZE];
134 char fake_hostname[64];
135 char fake_roomname[ROOMNAMELEN];
137 char preferred_formats[256]; /* Preferred MIME formats */
139 /* Dynamically allocated session data */
140 struct citimap *IMAP;
141 struct citpop3 *POP3;
142 struct citsmtp *SMTP;
143 struct citmgsve *MGSVE; /**< Managesieve Session struct */
144 struct cit_ical *CIT_ICAL; /* calendaring data */
145 struct ma_info *ma; /* multipart/alternative data */
146 const char* ServiceName; /**< whats our actual purpose? */
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()
176 * This is the control record for the message base...
179 long MMhighest; /* highest message number in file */
180 unsigned MMflags; /* Global system flags */
181 long MMnextuser; /* highest user number on system */
182 long MMnextroom; /* highest room number on system */
183 int version; /* Server-hosted upgrade level */
184 int fulltext_wordbreaker; /* ID of wordbreaker in use */
185 long MMfulltext; /* highest message number indexed */
188 extern struct CitContext *ContextList;
189 extern int ScheduledShutdown;
190 extern struct CitControl CitControl;
193 struct ExpressMessage {
194 struct ExpressMessage *next;
195 time_t timestamp; /* When this message was sent */
196 unsigned flags; /* Special instructions */
197 char sender[64]; /* Name of sending user */
198 char *text; /* Message text (if applicable) */
201 #define EM_BROADCAST 1 /* Broadcast message */
202 #define EM_GO_AWAY 2 /* Server requests client log off */
203 #define EM_CHAT 4 /* Server requests client enter chat */
206 struct ChatLine *next;
210 char chat_username[USERNAME_SIZE];
211 char chat_room[ROOMNAMELEN];
215 * Various things we need to lock and unlock
256 * message transfer formats
259 MT_CITADEL, /* Citadel proprietary */
260 MT_RFC822, /* RFC822 */
261 MT_MIME, /* MIME-formatted message */
262 MT_DOWNLOAD, /* Download a component */
263 MT_SPEW_SECTION /* Download a component in a single operation */
267 * Message format types in the database
269 #define FMT_CITADEL 0 /* Citadel vari-format (proprietary) */
270 #define FMT_FIXED 1 /* Fixed format (proprietary) */
271 #define FMT_RFC822 4 /* Standard (headers are in M field) */
275 * Citadel DataBases (define one for each cdb we need to open)
278 CDB_MSGMAIN, /* message base */
279 CDB_USERS, /* user file */
280 CDB_ROOMS, /* room index */
281 CDB_FLOORTAB, /* floor index */
282 CDB_MSGLISTS, /* room message lists */
283 CDB_VISIT, /* user/room relationships */
284 CDB_DIRECTORY, /* address book directory */
285 CDB_USETABLE, /* network use table */
286 CDB_BIGMSGS, /* larger message bodies */
287 CDB_FULLTEXT, /* full text search index */
288 CDB_EUIDINDEX, /* locate msgs by EUID */
289 MAXCDB /* total number of CDB's defined */
299 /* Structures and declarations for function hooks of various types */
301 struct LogFunctionHook {
302 struct LogFunctionHook *next;
304 void (*h_function_pointer) (char *);
306 extern struct LogFunctionHook *LogHookTable;
308 struct CleanupFunctionHook {
309 struct CleanupFunctionHook *next;
310 void (*h_function_pointer) (void);
312 extern struct CleanupFunctionHook *CleanupHookTable;
314 struct FixedOutputHook {
315 struct FixedOutputHook *next;
316 char content_type[64];
317 void (*h_function_pointer) (char *, int);
319 extern struct FixedOutputHook *FixedOutputTable;
324 * SessionFunctionHook extensions are used for any type of hook for which
325 * the context in which it's being called (which is determined by the event
326 * type) will make it obvious for the hook function to know where to look for
329 struct SessionFunctionHook {
330 struct SessionFunctionHook *next;
331 void (*h_function_pointer) (void);
334 extern struct SessionFunctionHook *SessionHookTable;
337 * Event types can't be enum'ed, because they must remain consistent between
338 * builds (to allow for binary modules built somewhere else)
340 #define EVT_STOP 0 /* Session is terminating */
341 #define EVT_START 1 /* Session is starting */
342 #define EVT_LOGIN 2 /* A user is logging in */
343 #define EVT_NEWROOM 3 /* Changing rooms */
344 #define EVT_LOGOUT 4 /* A user is logging out */
345 #define EVT_SETPASS 5 /* Setting or changing password */
346 #define EVT_CMD 6 /* Called after each server command */
347 #define EVT_RWHO 7 /* An RWHO command is being executed */
348 #define EVT_ASYNC 8 /* Doing asynchronous messages */
350 #define EVT_TIMER 50 /* Timer events are called once per minute
351 and are not tied to any session */
352 #define EVT_HOUSE 51 /* as needed houskeeping stuff */
354 * UserFunctionHook extensions are used for any type of hook which implements
355 * an operation on a user or username (potentially) other than the one
356 * operating the current session.
358 struct UserFunctionHook {
359 struct UserFunctionHook *next;
360 void (*h_function_pointer) (struct ctdluser *usbuf);
363 extern struct UserFunctionHook *UserHookTable;
365 #define EVT_PURGEUSER 100 /* Deleting a user */
366 #define EVT_NEWUSER 102 /* Creating a user */
369 * MessageFunctionHook extensions are used for hooks which implement handlers
370 * for various types of message operations (save, read, etc.)
372 struct MessageFunctionHook {
373 struct MessageFunctionHook *next;
374 int (*h_function_pointer) (struct CtdlMessage *msg);
377 extern struct MessageFunctionHook *MessageHookTable;
379 #define EVT_BEFOREREAD 200
380 #define EVT_BEFORESAVE 201
381 #define EVT_AFTERSAVE 202
382 #define EVT_SMTPSCAN 203 /* called before submitting a msg from SMTP */
386 * NetprocFunctionHook extensions are used for hooks which implement handlers
387 * for incoming network messages.
389 struct NetprocFunctionHook {
390 struct NetprocFunctionHook *next;
391 int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
393 extern struct NetprocFunctionHook *NetprocHookTable;
397 * DeleteFunctionHook extensions are used for hooks which get called when a
398 * message is about to be deleted.
400 struct DeleteFunctionHook {
401 struct DeleteFunctionHook *next;
402 void (*h_function_pointer) (char *target_room, long msgnum);
404 extern struct DeleteFunctionHook *DeleteHookTable;
408 * ExpressMessageFunctionHook extensions are used for hooks which implement
409 * the sending of an instant message through various channels. Any function
410 * registered should return the number of recipients to whom the message was
411 * successfully transmitted.
413 struct XmsgFunctionHook {
414 struct XmsgFunctionHook *next;
415 int (*h_function_pointer) (char *, char *, char *);
418 extern struct XmsgFunctionHook *XmsgHookTable;
420 /* Priority levels for paging functions (lower is better) */
422 XMSG_PRI_LOCAL, /* Other users on -this- server */
423 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
424 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
431 * ServiceFunctionHook extensions are used for hooks which implement various
432 * protocols (either on TCP or on unix domain sockets) directly in the Citadel server.
434 struct ServiceFunctionHook {
435 struct ServiceFunctionHook *next;
438 void (*h_greeting_function) (void) ;
439 void (*h_command_function) (void) ;
440 void (*h_async_function) (void) ;
442 const char* ServiceName; /* this is just for debugging and logging purposes. */
444 extern struct ServiceFunctionHook *ServiceHookTable;
448 * RoomFunctionHook extensions are used for hooks which impliment room
449 * processing functions when new messages are added EG. SIEVE.
451 struct RoomFunctionHook {
452 struct RoomFunctionHook *next;
453 int (*fcn_ptr) (struct ctdlroom *);
455 extern struct RoomFunctionHook *RoomHookTable;
458 struct MaintenanceThreadHook {
459 struct MaintenanceThreadHook *next;
461 void *(*fcn_ptr) (void *arg);
462 pthread_t MaintenanceThread_tid;
464 extern struct MaintenanceThreadHook *MaintenanceThreadHookTable;
467 struct SearchFunctionHook {
468 struct SearchFunctionHook *next;
469 void (*fcn_ptr) (int *, long **, char *);
472 extern struct SearchFunctionHook *SearchFunctionHookTable;
475 /* Defines the relationship of a user to a particular room */
481 unsigned int v_flags;
483 char v_answered[SIZ];
487 #define V_FORGET 1 /* User has zapped this room */
488 #define V_LOCKOUT 2 /* User is locked out of this room */
489 #define V_ACCESS 4 /* Access is granted to this room */
492 /* Supplementary data for a message on disk
493 * These are kept separate from the message itself for one of two reasons:
494 * 1. Either their values may change at some point after initial save, or
495 * 2. They are merely caches of data which exist somewhere else, for speed.
498 long meta_msgnum; /* Message number in *local* message base */
499 int meta_refcount; /* Number of rooms pointing to this msg */
500 char meta_content_type[64]; /* Cached MIME content-type */
501 long meta_rfc822_length; /* Cache of RFC822-translated msg length */
504 /* Calls to AdjRefCount() are queued and deferred, so the user doesn't
505 * have to wait for various disk-intensive operations to complete synchronously.
506 * This is the record format.
509 long arcq_msgnum; /* Message number being adjusted */
510 int arcq_delta; /* Adjustment ( usually 1 or -1 ) */
515 * Serialization routines use this struct to return a pointer and a length
523 /* Preferred field order */
524 /* ********** Important fields */
525 /* *************** Semi-important fields */
526 /* * Message text (MUST be last) */
527 #define FORDER "IPTAFONHRDBCEJGKLQSVWXZYUM"
529 #endif /* SERVER_H */