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 char curr_user[32]; /* name of current user */
60 int logged_in; /* logged in */
61 int internal_pgm; /* authenticated as internal program */
62 char temp[32]; /* temp file name */
63 int nologin; /* not allowed to log in */
67 int n_crit; /* number of critical sections open */
69 int cs_pid; /* session ID */
70 char cs_room[ROOMNAMELEN]; /* current room */
71 time_t cs_lastupdt; /* time of last update */
72 time_t lastcmd; /* time of last command executed */
73 time_t lastidle; /* For computing idle time */
74 char lastcmdname[5]; /* name of last command executed */
75 unsigned cs_flags; /* miscellaneous flags */
77 /* feeping creaturisms... */
78 int cs_clientdev; /* client developer ID */
79 int cs_clienttyp; /* client type code */
80 int cs_clientver; /* client version number */
81 char cs_clientname[32]; /* name of client software */
82 char cs_host[26]; /* host logged in from */
84 FILE *download_fp; /* Fields relating to file transfer */
88 char upl_comment[256];
89 char upl_filedir[256];
90 char chat_room[20]; /* The chat room */
94 struct ExpressMessage *FirstExpressMessage;
96 char fake_username[32]; /* Fake username <bc> */
97 char fake_postname[32]; /* Fake postname <bc> */
98 char fake_hostname[25]; /* Name of the fake hostname <bc> */
99 char fake_roomname[ROOMNAMELEN]; /* Name of the fake room <bc> */
101 int FloorBeingSearched; /* This is used by cmd_lrms() etc. */
102 struct CtdlSessData *FirstSessData;
105 typedef struct CitContext t_context;
107 #define CS_STEALTH 1 /* stealth mode */
108 #define CS_CHAT 2 /* chat mode */
109 #define CS_POSTING 4 /* Posting */
111 struct CitContext *MyContext(void);
112 #define CC ((struct CitContext *)MyContext())
114 extern struct CitContext *ContextList;
115 extern int ScheduledShutdown;
116 extern struct CitControl CitControl;
119 struct ExpressMessage {
120 struct ExpressMessage *next;
121 time_t timestamp; /* When this message was sent */
122 unsigned flags; /* Special instructions */
123 char sender[64]; /* Name of sending user */
124 char *text; /* Message text (if applicable) */
127 #define EM_BROADCAST 1 /* Broadcast message */
128 #define EM_GO_AWAY 2 /* Server requests client log off */
129 #define EM_CHAT 4 /* Server requests client enter chat */
132 struct ChatLine *next;
137 char chat_username[32];
141 * Various things we need to lock and unlock
170 * message transfer formats
173 MT_CITADEL, /* Citadel proprietary */
174 MT_RFC822, /* RFC822 */
175 MT_MIME, /* MIME-formatted message */
176 MT_DOWNLOAD /* Download a component */
181 * Citadel DataBases (define one for each cdb we need to open)
184 CDB_MSGMAIN, /* message base */
185 CDB_USERSUPP, /* user file */
186 CDB_QUICKROOM, /* room index */
187 CDB_FLOORTAB, /* floor index */
188 CDB_MSGLISTS, /* room message lists */
189 CDB_VISIT, /* user/room relationships */
190 MAXCDB /* total number of CDB's defined */
200 /* Structures and declarations for function hooks of various types */
202 struct LogFunctionHook {
203 struct LogFunctionHook *next;
205 void (*h_function_pointer) (char *);
207 extern struct LogFunctionHook *LogHookTable;
209 struct CleanupFunctionHook {
210 struct CleanupFunctionHook *next;
211 void (*h_function_pointer) (void);
213 extern struct CleanupFunctionHook *CleanupHookTable;
219 * SessionFunctionHook extensions are used for any type of hook for which
220 * the context in which it's being called (which is determined by the event
221 * type) will make it obvious for the hook function to know where to look for
224 struct SessionFunctionHook {
225 struct SessionFunctionHook *next;
226 void (*h_function_pointer) (void);
229 extern struct SessionFunctionHook *SessionHookTable;
232 * Event types can't be enum'ed, because they must remain consistent between
233 * builds (to allow for binary modules built somewhere else)
235 #define EVT_STOP 0 /* Session is terminating */
236 #define EVT_START 1 /* Session is starting */
237 #define EVT_LOGIN 2 /* A user is logging in */
238 #define EVT_NEWROOM 3 /* Changing rooms */
239 #define EVT_LOGOUT 4 /* A user is logging out */
240 #define EVT_SETPASS 5 /* Setting or changing password */
241 #define EVT_CMD 6 /* Called after each server command */
242 #define EVT_RWHO 7 /* An RWHO command is being executed */
249 * UserFunctionHook extensions are used for any type of hook which implements
250 * an operation on a user or username (potentially) other than the one
251 * operating the current session.
253 struct UserFunctionHook {
254 struct UserFunctionHook *next;
255 void (*h_function_pointer) (char *username, long usernum);
258 extern struct UserFunctionHook *UserHookTable;
260 #define EVT_PURGEUSER 100 /* Deleting a user */
261 #define EVT_OUTPUTMSG 101 /* Outputting a message */
265 * MessageFunctionHook extensions are used for hooks which implement handlers
266 * for various types of message operations (save, read, etc.)
268 struct MessageFunctionHook {
269 struct MessageFunctionHook *next;
270 int (*h_function_pointer) (struct CtdlMessage *msg);
273 extern struct MessageFunctionHook *MessageHookTable;
275 #define EVT_BEFOREREAD 200
276 #define EVT_BEFORESAVE 201
277 #define EVT_AFTERSAVE 202
281 * ExpressMessageFunctionHook extensions are used for hooks which implement
282 * the sending of an express message through various channels. Any function
283 * registered should return the number of recipients to whom the message was
284 * successfully transmitted.
286 struct XmsgFunctionHook {
287 struct XmsgFunctionHook *next;
288 int (*h_function_pointer) (char *, char *, char *);
291 extern struct XmsgFunctionHook *XmsgHookTable;
293 /* Priority levels for paging functions (lower is better) */
295 XMSG_PRI_LOCAL, /* Other users on -this- server */
296 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
297 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
305 /* Defines the relationship of a user to a particular room */
311 unsigned int v_flags;
314 #define V_FORGET 1 /* User has zapped this room */
315 #define V_LOCKOUT 2 /* User is locked out of this room */
316 #define V_ACCESS 4 /* Access is granted to this room */
319 #define UA_GOTOALLOWED 4
320 #define UA_HASNEWMSGS 8
324 /* Supplementary data for a message on disk
325 * (These are kept separately from the message itself because they are
326 * fields whose values may change at some point after the message is saved.)
329 long smi_msgnum; /* Message number in *local* message base */
330 int smi_refcount; /* Number of rooms which point to this msg */
331 char smi_content_type[64];
332 /* more stuff will be added to this record in the future */
337 /* Built-in debuggable stuff for checking for memory leaks */
338 #ifdef DEBUG_MEMORY_LEAKS
340 #define mallok(howbig) tracked_malloc(howbig, __FILE__, __LINE__)
341 #define phree(whichptr) tracked_free(whichptr)
342 #define reallok(whichptr,howbig) tracked_realloc(whichptr,howbig)
343 #define strdoop(orig) tracked_strdup(orig, __FILE__, __LINE__)
345 void *tracked_malloc(size_t, char *, int);
346 void tracked_free(void *);
347 void *tracked_realloc(void *, size_t);
348 void dump_tracked(void);
349 char *tracked_strdup(const char *, char *, int);
352 struct TheHeap *next;
358 extern struct TheHeap *heap;
362 #define mallok(howbig) malloc(howbig)
363 #define phree(whichptr) free(whichptr)
364 #define reallok(whichptr,howbig) realloc(whichptr,howbig)
365 #define strdoop(orig) strdup(orig)
372 * Serialization routines use this struct to return a pointer and a length
380 /* Preferred field order */
381 /* ********* Important fields */
382 /* **************** Semi-important fields */
383 /* * Message text (MUST be last) */
384 #define FORDER "IPTAONHRDBCEFGJKLQSUVWXYZM"