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 */
44 * Here's the big one... the Citadel context structure.
46 * This structure keeps track of all information relating to a running
47 * session on the server. We keep one of these for each session thread.
49 * Note that the first element is "*next" so that it may be used without
50 * modification in a linked list.
53 struct CitContext *next; /* Link to next session in the list */
55 struct usersupp usersupp; /* Database record buffers */
56 struct quickroom quickroom;
58 char curr_user[32]; /* name of current user */
59 int logged_in; /* logged in */
60 int internal_pgm; /* authenticated as internal program */
61 char temp[32]; /* temp file name */
62 int nologin; /* not allowed to log in */
66 int n_crit; /* number of critical sections open */
68 int cs_pid; /* session ID */
69 char cs_room[ROOMNAMELEN]; /* current room */
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 #define CS_STEALTH 1 /* stealth mode */
107 #define CS_CHAT 2 /* chat mode */
108 #define CS_POSTING 4 /* Posting */
110 struct CitContext *MyContext(void);
111 #define CC ((struct CitContext *)MyContext())
113 extern struct CitContext *ContextList;
114 extern int ScheduledShutdown;
115 extern struct CitControl CitControl;
118 struct ExpressMessage {
119 struct ExpressMessage *next;
120 time_t timestamp; /* When this message was sent */
121 unsigned flags; /* Special instructions */
122 char sender[64]; /* Name of sending user */
123 char *text; /* Message text (if applicable) */
126 #define EM_BROADCAST 1 /* Broadcast message */
127 #define EM_GO_AWAY 2 /* Server requests client log off */
128 #define EM_CHAT 4 /* Server requests client enter chat */
131 struct ChatLine *next;
136 char chat_username[32];
140 * Various things we need to lock and unlock
169 * message transfer formats
172 MT_CITADEL, /* Citadel proprietary */
173 MT_RFC822, /* RFC822 */
174 MT_MIME, /* MIME-formatted message */
175 MT_DOWNLOAD /* Download a component */
180 * Citadel DataBases (define one for each cdb we need to open)
183 CDB_MSGMAIN, /* message base */
184 CDB_USERSUPP, /* user file */
185 CDB_QUICKROOM, /* room index */
186 CDB_FLOORTAB, /* floor index */
187 CDB_MSGLISTS, /* room message lists */
188 CDB_VISIT, /* user/room relationships */
189 MAXCDB /* total number of CDB's defined */
199 /* Structures and declarations for function hooks of various types */
201 struct LogFunctionHook {
202 struct LogFunctionHook *next;
204 void (*h_function_pointer) (char *);
206 extern struct LogFunctionHook *LogHookTable;
208 struct CleanupFunctionHook {
209 struct CleanupFunctionHook *next;
210 void (*h_function_pointer) (void);
212 extern struct CleanupFunctionHook *CleanupHookTable;
218 * SessionFunctionHook extensions are used for any type of hook for which
219 * the context in which it's being called (which is determined by the event
220 * type) will make it obvious for the hook function to know where to look for
223 struct SessionFunctionHook {
224 struct SessionFunctionHook *next;
225 void (*h_function_pointer) (void);
228 extern struct SessionFunctionHook *SessionHookTable;
231 * Event types can't be enum'ed, because they must remain consistent between
232 * builds (to allow for binary modules built somewhere else)
234 #define EVT_STOP 0 /* Session is terminating */
235 #define EVT_START 1 /* Session is starting */
236 #define EVT_LOGIN 2 /* A user is logging in */
237 #define EVT_NEWROOM 3 /* Changing rooms */
238 #define EVT_LOGOUT 4 /* A user is logging out */
239 #define EVT_SETPASS 5 /* Setting or changing password */
240 #define EVT_CMD 6 /* Called after each server command */
241 #define EVT_RWHO 7 /* An RWHO command is being executed */
248 * UserFunctionHook extensions are used for any type of hook which implements
249 * an operation on a user or username (potentially) other than the one
250 * operating the current session.
252 struct UserFunctionHook {
253 struct UserFunctionHook *next;
254 void (*h_function_pointer) (char *username, long usernum);
257 extern struct UserFunctionHook *UserHookTable;
259 #define EVT_PURGEUSER 100 /* Deleting a user */
260 #define EVT_OUTPUTMSG 101 /* Outputting a message */
264 * MessageFunctionHook extensions are used for hooks which implement handlers
265 * for various types of message operations (save, read, etc.)
267 struct MessageFunctionHook {
268 struct MessageFunctionHook *next;
269 int (*h_function_pointer) (struct CtdlMessage *msg);
272 extern struct MessageFunctionHook *MessageHookTable;
274 #define EVT_BEFOREREAD 200
275 #define EVT_BEFORESAVE 201
276 #define EVT_AFTERSAVE 202
280 * ExpressMessageFunctionHook extensions are used for hooks which implement
281 * the sending of an express message through various channels. Any function
282 * registered should return the number of recipients to whom the message was
283 * successfully transmitted.
285 struct XmsgFunctionHook {
286 struct XmsgFunctionHook *next;
287 int (*h_function_pointer) (char *, char *, char *);
290 extern struct XmsgFunctionHook *XmsgHookTable;
292 /* Priority levels for paging functions (lower is better) */
294 XMSG_PRI_LOCAL, /* Other users on -this- server */
295 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
296 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
304 /* Defines the relationship of a user to a particular room */
310 unsigned int v_flags;
313 #define V_FORGET 1 /* User has zapped this room */
314 #define V_LOCKOUT 2 /* User is locked out of this room */
315 #define V_ACCESS 4 /* Access is granted to this room */
318 #define UA_GOTOALLOWED 4
319 #define UA_HASNEWMSGS 8
323 /* Supplementary data for a message on disk
324 * (These are kept separately from the message itself because they are
325 * fields whose values may change at some point after the message is saved.)
328 long smi_msgnum; /* Message number in *local* message base */
329 int smi_refcount; /* Number of rooms which point to this msg */
330 char smi_content_type[64];
331 /* more stuff will be added to this record in the future */
336 /* Built-in debuggable stuff for checking for memory leaks */
337 #ifdef DEBUG_MEMORY_LEAKS
339 #define mallok(howbig) tracked_malloc(howbig, __FILE__, __LINE__)
340 #define phree(whichptr) tracked_free(whichptr)
341 #define reallok(whichptr,howbig) tracked_realloc(whichptr,howbig)
342 #define strdoop(orig) tracked_strdup(orig, __FILE__, __LINE__)
344 void *tracked_malloc(size_t, char *, int);
345 void tracked_free(void *);
346 void *tracked_realloc(void *, size_t);
347 void dump_tracked(void);
348 char *tracked_strdup(const char *, char *, int);
351 struct TheHeap *next;
357 extern struct TheHeap *heap;
361 #define mallok(howbig) malloc(howbig)
362 #define phree(whichptr) free(whichptr)
363 #define reallok(whichptr,howbig) realloc(whichptr,howbig)
364 #define strdoop(orig) strdup(orig)
371 * Serialization routines use this struct to return a pointer and a length
379 /* Preferred field order */
380 /* ********* Important fields */
381 /* **************** Semi-important fields */
382 /* * Message text (MUST be last) */
383 #define FORDER "IPTAONHRDBCEFGJKLQSUVWXYZM"