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
11 * Generic per-session variable or data structure storage
14 struct CtdlSessData *next;
20 * Static user data symbol types
23 SYM_DESIRED_SECTION, /* Used by the MIME parser */
24 SYM_MA_INFO, /* Handles multipart/alternative */
30 * Here's the big one... the Citadel context structure.
32 * This structure keeps track of all information relating to a running
33 * session on the server. We keep one of these for each session thread.
35 * Note that the first element is "*next" so that it may be used without
36 * modification in a linked list.
39 struct CitContext *next; /* Link to next session in the list */
41 struct usersupp usersupp; /* Database record buffers */
42 struct quickroom quickroom;
44 char curr_user[32]; /* name of current user */
45 int logged_in; /* logged in */
46 int internal_pgm; /* authenticated as internal program */
47 char temp[32]; /* temp file name */
48 int nologin; /* not allowed to log in */
52 int n_crit; /* number of critical sections open */
54 int cs_pid; /* session ID */
55 char cs_room[ROOMNAMELEN]; /* current room */
56 time_t cs_lastupdt; /* time of last update */
57 time_t lastcmd; /* time of last command executed */
58 time_t lastidle; /* For computing idle time */
59 char lastcmdname[5]; /* name of last command executed */
60 unsigned cs_flags; /* miscellaneous flags */
62 /* feeping creaturisms... */
63 int cs_clientdev; /* client developer ID */
64 int cs_clienttyp; /* client type code */
65 int cs_clientver; /* client version number */
66 char cs_clientname[32]; /* name of client software */
67 char cs_host[26]; /* host logged in from */
69 FILE *download_fp; /* Fields relating to file transfer */
73 char upl_comment[256];
74 char upl_filedir[256];
75 char chat_room[20]; /* The chat room */
79 struct ExpressMessage *FirstExpressMessage;
81 char fake_username[32]; /* Fake username <bc> */
82 char fake_postname[32]; /* Fake postname <bc> */
83 char fake_hostname[25]; /* Name of the fake hostname <bc> */
84 char fake_roomname[ROOMNAMELEN]; /* Name of the fake room <bc> */
86 int FloorBeingSearched; /* This is used by cmd_lrms() etc. */
87 struct CtdlSessData *FirstSessData;
90 typedef struct CitContext t_context;
92 #define CS_STEALTH 1 /* stealth mode */
93 #define CS_CHAT 2 /* chat mode */
94 #define CS_POSTING 4 /* Posting */
96 struct CitContext *MyContext(void);
97 #define CC ((struct CitContext *)MyContext())
99 extern struct CitContext *ContextList;
100 extern int ScheduledShutdown;
101 extern struct CitControl CitControl;
104 struct ExpressMessage {
105 struct ExpressMessage *next;
106 time_t timestamp; /* When this message was sent */
107 unsigned flags; /* Special instructions */
108 char sender[64]; /* Name of sending user */
109 char *text; /* Message text (if applicable) */
112 #define EM_BROADCAST 1 /* Broadcast message */
113 #define EM_GO_AWAY 2 /* Server requests client log off */
114 #define EM_CHAT 4 /* Server requests client enter chat */
117 struct ChatLine *next;
122 char chat_username[32];
126 * Various things we need to lock and unlock
155 * message transfer formats
158 MT_CITADEL, /* Citadel proprietary */
159 MT_RFC822, /* RFC822 */
160 MT_MIME, /* MIME-formatted message */
161 MT_DOWNLOAD /* Download a component */
166 * Citadel DataBases (define one for each cdb we need to open)
169 CDB_MSGMAIN, /* message base */
170 CDB_USERSUPP, /* user file */
171 CDB_QUICKROOM, /* room index */
172 CDB_FLOORTAB, /* floor index */
173 CDB_MSGLISTS, /* room message lists */
174 CDB_VISIT, /* user/room relationships */
175 MAXCDB /* total number of CDB's defined */
185 /* Structures and declarations for function hooks of various types */
187 struct LogFunctionHook {
188 struct LogFunctionHook *next;
190 void (*h_function_pointer) (char *);
192 extern struct LogFunctionHook *LogHookTable;
194 struct CleanupFunctionHook {
195 struct CleanupFunctionHook *next;
196 void (*h_function_pointer) (void);
198 extern struct CleanupFunctionHook *CleanupHookTable;
204 * SessionFunctionHook extensions are used for any type of hook for which
205 * the context in which it's being called (which is determined by the event
206 * type) will make it obvious for the hook function to know where to look for
209 struct SessionFunctionHook {
210 struct SessionFunctionHook *next;
211 void (*h_function_pointer) (void);
214 extern struct SessionFunctionHook *SessionHookTable;
217 * Event types can't be enum'ed, because they must remain consistent between
218 * builds (to allow for binary modules built somewhere else)
220 #define EVT_STOP 0 /* Session is terminating */
221 #define EVT_START 1 /* Session is starting */
222 #define EVT_LOGIN 2 /* A user is logging in */
223 #define EVT_NEWROOM 3 /* Changing rooms */
224 #define EVT_LOGOUT 4 /* A user is logging out */
225 #define EVT_SETPASS 5 /* Setting or changing password */
226 #define EVT_CMD 6 /* Called after each server command */
227 #define EVT_RWHO 7 /* An RWHO command is being executed */
234 * UserFunctionHook extensions are used for any type of hook which implements
235 * an operation on a user or username (potentially) other than the one
236 * operating the current session.
238 struct UserFunctionHook {
239 struct UserFunctionHook *next;
240 void (*h_function_pointer) (char *username, long usernum);
243 extern struct UserFunctionHook *UserHookTable;
245 #define EVT_PURGEUSER 100 /* Deleting a user */
246 #define EVT_OUTPUTMSG 101 /* Outputting a message */
252 * ExpressMessageFunctionHook extensions are used for hooks which implement
253 * the sending of an express message through various channels. Any function
254 * registered should return the number of recipients to whom the message was
255 * successfully transmitted.
257 struct XmsgFunctionHook {
258 struct XmsgFunctionHook *next;
259 int (*h_function_pointer) (char *, char *, char *);
262 extern struct XmsgFunctionHook *XmsgHookTable;
264 /* Priority levels for paging functions (lower is better) */
266 XMSG_PRI_LOCAL, /* Other users on -this- server */
267 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
268 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
276 /* Defines the relationship of a user to a particular room */
282 unsigned int v_flags;
285 #define V_FORGET 1 /* User has zapped this room */
286 #define V_LOCKOUT 2 /* User is locked out of this room */
287 #define V_ACCESS 4 /* Access is granted to this room */
290 #define UA_GOTOALLOWED 4
291 #define UA_HASNEWMSGS 8
295 /* Supplementary data for a message on disk
296 * (These are kept separately from the message itself because they are
297 * fields whose values may change at some point after the message is saved.)
300 long smi_msgnum; /* Message number in *local* message base */
301 int smi_refcount; /* Number of rooms which point to this msg */
302 char smi_content_type[64];
303 /* more stuff will be added to this record in the future */
308 /* Built-in debuggable stuff for checking for memory leaks */
309 #ifdef DEBUG_MEMORY_LEAKS
311 #define mallok(howbig) tracked_malloc(howbig, __FILE__, __LINE__)
312 #define phree(whichptr) tracked_free(whichptr)
313 #define reallok(whichptr,howbig) tracked_realloc(whichptr,howbig)
314 #define strdoop(orig) tracked_strdup(orig, __FILE__, __LINE__)
316 void *tracked_malloc(size_t, char *, int);
317 void tracked_free(void *);
318 void *tracked_realloc(void *, size_t);
319 void dump_tracked(void);
320 char *tracked_strdup(const char *, char *, int);
323 struct TheHeap *next;
329 extern struct TheHeap *heap;
333 #define mallok(howbig) malloc(howbig)
334 #define phree(whichptr) free(whichptr)
335 #define reallok(whichptr,howbig) realloc(whichptr,howbig)
336 #define strdoop(orig) strdup(orig)
343 * New format for a message in memory
345 #define CTDLMESSAGE_MAGIC 0x159d
347 int cm_magic; /* Self-check */
348 char cm_anon_type; /* Anonymous or author-visible */
349 char cm_format_type; /* Format type */
350 char *cm_fields[256]; /* Data fields */
353 /* Preferred field order */
354 /* ********* Important fields */
355 /* **************** Semi-important fields */
356 /* * Message text (MUST be last) */
357 #define FORDER "IPTAONHRDBCEFGJKLQSUVWXYZM"