2 typedef pthread_t THREAD;
4 /* Uncomment this if you want to track memory leaks.
5 * This incurs some overhead, so don't use it unless you're debugging the code!
7 #define DEBUG_MEMORY_LEAKS
10 * New format for a message in memory
12 #define CTDLMESSAGE_MAGIC 0x159d
14 int cm_magic; /* Self-check */
15 char cm_anon_type; /* Anonymous or author-visible */
16 char cm_format_type; /* Format type */
17 char *cm_fields[256]; /* Data fields */
18 unsigned int cm_flags; /* How to handle (NOT SAVED TO DISK) */
21 #define CM_SKIP_HOOKS 0x01 /* Don't run server-side handlers */
25 * Generic per-session variable or data structure storage
28 struct CtdlSessData *next;
34 * Static user data symbol types
37 SYM_DESIRED_SECTION, /* Used by the MIME parser */
38 SYM_MA_INFO, /* Handles multipart/alternative */
39 SYM_REPL, /* Used for replication checking */
45 * Here's the big one... the Citadel context structure.
47 * This structure keeps track of all information relating to a running
48 * session on the server. We keep one of these for each session thread.
50 * Note that the first element is "*next" so that it may be used without
51 * modification in a linked list.
54 struct CitContext *next; /* Link to next session in the list */
56 struct usersupp usersupp; /* Database record buffers */
57 struct quickroom quickroom;
59 int state; /* thread state (see CON_ values below) */
61 char curr_user[32]; /* name of current user */
62 int logged_in; /* logged in */
63 int internal_pgm; /* authenticated as internal program */
64 char temp[32]; /* temp file name */
65 int nologin; /* not allowed to log in */
69 int cs_pid; /* session ID */
70 time_t cs_lastupdt; /* time of last update */
71 time_t lastcmd; /* time of last command executed */
72 time_t lastidle; /* For computing idle time */
73 char lastcmdname[5]; /* name of last command executed */
74 unsigned cs_flags; /* miscellaneous flags */
76 /* feeping creaturisms... */
77 int cs_clientdev; /* client developer ID */
78 int cs_clienttyp; /* client type code */
79 int cs_clientver; /* client version number */
80 char cs_clientname[32]; /* name of client software */
81 char cs_host[26]; /* host logged in from */
83 FILE *download_fp; /* Fields relating to file transfer */
87 char upl_comment[256];
88 char upl_filedir[256];
89 char chat_room[20]; /* The chat room */
93 struct ExpressMessage *FirstExpressMessage;
95 char fake_username[32]; /* Fake username <bc> */
96 char fake_postname[32]; /* Fake postname <bc> */
97 char fake_hostname[25]; /* Name of the fake hostname <bc> */
98 char fake_roomname[ROOMNAMELEN]; /* Name of the fake room <bc> */
100 int FloorBeingSearched; /* This is used by cmd_lrms() etc. */
101 struct CtdlSessData *FirstSessData;
104 typedef struct CitContext t_context;
106 /* Values for CitContext.state */
108 CON_IDLE, /* This context is doing nothing */
109 CON_EXECUTING, /* This context is bound to a thread */
110 CON_DYING /* This context is being terminated */
114 #define CS_STEALTH 1 /* stealth mode */
115 #define CS_CHAT 2 /* chat mode */
116 #define CS_POSTING 4 /* Posting */
118 struct CitContext *MyContext(void);
119 #define CC ((struct CitContext *)MyContext())
121 extern struct CitContext *ContextList;
122 extern int ScheduledShutdown;
123 extern struct CitControl CitControl;
126 struct ExpressMessage {
127 struct ExpressMessage *next;
128 time_t timestamp; /* When this message was sent */
129 unsigned flags; /* Special instructions */
130 char sender[64]; /* Name of sending user */
131 char *text; /* Message text (if applicable) */
134 #define EM_BROADCAST 1 /* Broadcast message */
135 #define EM_GO_AWAY 2 /* Server requests client log off */
136 #define EM_CHAT 4 /* Server requests client enter chat */
139 struct ChatLine *next;
144 char chat_username[32];
148 * Various things we need to lock and unlock
178 * message transfer formats
181 MT_CITADEL, /* Citadel proprietary */
182 MT_RFC822, /* RFC822 */
183 MT_MIME, /* MIME-formatted message */
184 MT_DOWNLOAD /* Download a component */
189 * Citadel DataBases (define one for each cdb we need to open)
192 CDB_MSGMAIN, /* message base */
193 CDB_USERSUPP, /* user file */
194 CDB_QUICKROOM, /* room index */
195 CDB_FLOORTAB, /* floor index */
196 CDB_MSGLISTS, /* room message lists */
197 CDB_VISIT, /* user/room relationships */
198 MAXCDB /* total number of CDB's defined */
208 /* Structures and declarations for function hooks of various types */
210 struct LogFunctionHook {
211 struct LogFunctionHook *next;
213 void (*h_function_pointer) (char *);
215 extern struct LogFunctionHook *LogHookTable;
217 struct CleanupFunctionHook {
218 struct CleanupFunctionHook *next;
219 void (*h_function_pointer) (void);
221 extern struct CleanupFunctionHook *CleanupHookTable;
227 * SessionFunctionHook extensions are used for any type of hook for which
228 * the context in which it's being called (which is determined by the event
229 * type) will make it obvious for the hook function to know where to look for
232 struct SessionFunctionHook {
233 struct SessionFunctionHook *next;
234 void (*h_function_pointer) (void);
237 extern struct SessionFunctionHook *SessionHookTable;
240 * Event types can't be enum'ed, because they must remain consistent between
241 * builds (to allow for binary modules built somewhere else)
243 #define EVT_STOP 0 /* Session is terminating */
244 #define EVT_START 1 /* Session is starting */
245 #define EVT_LOGIN 2 /* A user is logging in */
246 #define EVT_NEWROOM 3 /* Changing rooms */
247 #define EVT_LOGOUT 4 /* A user is logging out */
248 #define EVT_SETPASS 5 /* Setting or changing password */
249 #define EVT_CMD 6 /* Called after each server command */
250 #define EVT_RWHO 7 /* An RWHO command is being executed */
257 * UserFunctionHook extensions are used for any type of hook which implements
258 * an operation on a user or username (potentially) other than the one
259 * operating the current session.
261 struct UserFunctionHook {
262 struct UserFunctionHook *next;
263 void (*h_function_pointer) (char *username, long usernum);
266 extern struct UserFunctionHook *UserHookTable;
268 #define EVT_PURGEUSER 100 /* Deleting a user */
269 #define EVT_OUTPUTMSG 101 /* Outputting a message */
273 * MessageFunctionHook extensions are used for hooks which implement handlers
274 * for various types of message operations (save, read, etc.)
276 struct MessageFunctionHook {
277 struct MessageFunctionHook *next;
278 int (*h_function_pointer) (struct CtdlMessage *msg);
281 extern struct MessageFunctionHook *MessageHookTable;
283 #define EVT_BEFOREREAD 200
284 #define EVT_BEFORESAVE 201
285 #define EVT_AFTERSAVE 202
289 * ExpressMessageFunctionHook extensions are used for hooks which implement
290 * the sending of an express message through various channels. Any function
291 * registered should return the number of recipients to whom the message was
292 * successfully transmitted.
294 struct XmsgFunctionHook {
295 struct XmsgFunctionHook *next;
296 int (*h_function_pointer) (char *, char *, char *);
299 extern struct XmsgFunctionHook *XmsgHookTable;
301 /* Priority levels for paging functions (lower is better) */
303 XMSG_PRI_LOCAL, /* Other users on -this- server */
304 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
305 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
313 /* Defines the relationship of a user to a particular room */
319 unsigned int v_flags;
322 #define V_FORGET 1 /* User has zapped this room */
323 #define V_LOCKOUT 2 /* User is locked out of this room */
324 #define V_ACCESS 4 /* Access is granted to this room */
327 #define UA_GOTOALLOWED 4
328 #define UA_HASNEWMSGS 8
332 /* Supplementary data for a message on disk
333 * (These are kept separately from the message itself because they are
334 * fields whose values may change at some point after the message is saved.)
337 long smi_msgnum; /* Message number in *local* message base */
338 int smi_refcount; /* Number of rooms which point to this msg */
339 char smi_content_type[64];
340 /* more stuff will be added to this record in the future */
345 /* Built-in debuggable stuff for checking for memory leaks */
346 #ifdef DEBUG_MEMORY_LEAKS
348 #define mallok(howbig) tracked_malloc(howbig, __FILE__, __LINE__)
349 #define phree(whichptr) tracked_free(whichptr)
350 #define reallok(whichptr,howbig) tracked_realloc(whichptr,howbig)
351 #define strdoop(orig) tracked_strdup(orig, __FILE__, __LINE__)
353 void *tracked_malloc(size_t, char *, int);
354 void tracked_free(void *);
355 void *tracked_realloc(void *, size_t);
356 void dump_tracked(void);
357 char *tracked_strdup(const char *, char *, int);
360 struct TheHeap *next;
366 extern struct TheHeap *heap;
370 #define mallok(howbig) malloc(howbig)
371 #define phree(whichptr) free(whichptr)
372 #define reallok(whichptr,howbig) realloc(whichptr,howbig)
373 #define strdoop(orig) strdup(orig)
380 * Serialization routines use this struct to return a pointer and a length
388 /* Preferred field order */
389 /* ********* Important fields */
390 /* **************** Semi-important fields */
391 /* * Message text (MUST be last) */
392 #define FORDER "IPTAONHRDBCEFGJKLQSUVWXYZM"