]> code.citadel.org Git - citadel.git/blob - citadel/server.h
Initial revision
[citadel.git] / citadel / server.h
1 /* $Id$ */
2 typedef pthread_t THREAD;
3
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!
6  */
7 #define DEBUG_MEMORY_LEAKS
8
9
10 /*
11  * Generic per-session variable or data structure storage
12  */
13 struct CtdlSessData {
14         struct CtdlSessData *next;
15         unsigned long sym_id;
16         void *sym_data;
17 };
18
19 /*
20  * Static user data symbol types
21  */
22 enum {
23         SYM_DESIRED_SECTION,            /* Used by the MIME parser */
24         SYM_MAX
25 };
26
27
28 /*
29  * Here's the big one... the Citadel context structure.
30  *
31  * This structure keeps track of all information relating to a running 
32  * session on the server.  We keep one of these for each session thread.
33  *
34  * Note that the first element is "*next" so that it may be used without
35  * modification in a linked list.
36  */
37 struct CitContext {
38         struct CitContext *next;        /* Link to next session in the list */
39
40         struct usersupp usersupp;       /* Database record buffers */
41         struct quickroom quickroom;
42
43         char curr_user[32];     /* name of current user */
44         int logged_in;          /* logged in */
45         int internal_pgm;       /* authenticated as internal program */
46         char temp[32];          /* temp file name */
47         int nologin;            /* not allowed to log in */
48
49         char net_node[32];
50         THREAD mythread;
51         int n_crit;             /* number of critical sections open */
52         int client_socket;
53         int cs_pid;             /* session ID */
54         char cs_room[ROOMNAMELEN];      /* current room */
55         time_t cs_lastupdt;     /* time of last update */
56         time_t lastcmd;         /* time of last command executed */
57         time_t lastidle;        /* For computing idle time */
58         char lastcmdname[5];    /* name of last command executed */
59         unsigned cs_flags;      /* miscellaneous flags */
60
61         /* feeping creaturisms... */
62         int cs_clientdev;       /* client developer ID */
63         int cs_clienttyp;       /* client type code */
64         int cs_clientver;       /* client version number */
65         char cs_clientname[32]; /* name of client software */
66         char cs_host[26];       /* host logged in from */
67
68         FILE *download_fp;      /* Fields relating to file transfer */
69         FILE *upload_fp;
70         char upl_file[256];
71         char upl_path[256];
72         char upl_comment[256];
73         char upl_filedir[256];
74         char chat_room[20];     /* The chat room */
75         char dl_is_net;
76         char upload_type;
77
78         struct ExpressMessage *FirstExpressMessage;
79
80         char fake_username[32]; /* Fake username <bc>                */
81         char fake_postname[32]; /* Fake postname <bc>                */
82         char fake_hostname[25]; /* Name of the fake hostname <bc>    */
83         char fake_roomname[ROOMNAMELEN];        /* Name of the fake room <bc> */
84
85         int FloorBeingSearched; /* This is used by cmd_lrms() etc.   */
86         struct CtdlSessData *FirstSessData;
87 };
88
89 typedef struct CitContext t_context;
90
91 #define CS_STEALTH      1       /* stealth mode */
92 #define CS_CHAT         2       /* chat mode */
93 #define CS_POSTING      4       /* Posting */
94
95 struct CitContext *MyContext(void);
96 #define CC ((struct CitContext *)MyContext())
97
98 extern struct CitContext *ContextList;
99 extern int ScheduledShutdown;
100 extern struct CitControl CitControl;
101
102
103 struct ExpressMessage {
104         struct ExpressMessage *next;
105         time_t timestamp;       /* When this message was sent */
106         unsigned flags;         /* Special instructions */
107         char sender[64];        /* Name of sending user */
108         char *text;             /* Message text (if applicable) */
109 };
110
111 #define EM_BROADCAST    1       /* Broadcast message */
112 #define EM_GO_AWAY      2       /* Server requests client log off */
113 #define EM_CHAT         4       /* Server requests client enter chat */
114
115 struct ChatLine {
116         struct ChatLine *next;
117         int chat_seq;
118         time_t chat_time;
119         char chat_text[256];
120         char chat_room[20];
121         char chat_username[32];
122 };
123
124 /*
125  * Various things we need to lock and unlock
126  */
127 enum {
128         S_USERSUPP,
129         S_USER_TRANS,
130         S_QUICKROOM,
131         S_MSGMAIN,
132         S_CALLLOG,
133         S_SESSION_TABLE,
134         S_FLOORTAB,
135         S_CHATQUEUE,
136         S_CONTROL,
137         S_HOUSEKEEPING,
138         S_DATABASE,
139         S_NETDB,
140         S_SUPPMSGMAIN,
141         MAX_SEMAPHORES
142 };
143
144
145 /*
146  * Upload types
147  */
148 #define UPL_FILE        0
149 #define UPL_NET         1
150 #define UPL_IMAGE       2
151
152
153 /*
154  * message transfer formats
155  */
156 enum {
157         MT_CITADEL,             /* Citadel proprietary */
158         MT_RFC822,              /* RFC822 */
159         MT_MIME,                /* MIME-formatted message */
160         MT_DOWNLOAD             /* Download a component */
161 };
162
163
164 /*
165  * Citadel DataBases (define one for each cdb we need to open)
166  */
167 enum {
168         CDB_MSGMAIN,            /* message base                  */
169         CDB_USERSUPP,           /* user file                     */
170         CDB_QUICKROOM,          /* room index                    */
171         CDB_FLOORTAB,           /* floor index                   */
172         CDB_MSGLISTS,           /* room message lists            */
173         CDB_VISIT,              /* user/room relationships       */
174         MAXCDB                  /* total number of CDB's defined */
175 };
176
177 struct cdbdata {
178         size_t len;
179         char *ptr;
180 };
181
182
183
184 /* Structures and declarations for function hooks of various types */
185
186 struct LogFunctionHook {
187         struct LogFunctionHook *next;
188         int loglevel;
189         void (*h_function_pointer) (char *);
190 };
191 extern struct LogFunctionHook *LogHookTable;
192
193 struct CleanupFunctionHook {
194         struct CleanupFunctionHook *next;
195         void (*h_function_pointer) (void);
196 };
197 extern struct CleanupFunctionHook *CleanupHookTable;
198
199
200
201
202 /*
203  * SessionFunctionHook extensions are used for any type of hook for which
204  * the context in which it's being called (which is determined by the event
205  * type) will make it obvious for the hook function to know where to look for
206  * pertinent data.
207  */
208 struct SessionFunctionHook {
209         struct SessionFunctionHook *next;
210         void (*h_function_pointer) (void);
211         int eventtype;
212 };
213 extern struct SessionFunctionHook *SessionHookTable;
214
215 /* 
216  * Event types can't be enum'ed, because they must remain consistent between
217  * builds (to allow for binary modules built somewhere else)
218  */
219 #define EVT_STOP        0       /* Session is terminating */
220 #define EVT_START       1       /* Session is starting */
221 #define EVT_LOGIN       2       /* A user is logging in */
222 #define EVT_NEWROOM     3       /* Changing rooms */
223 #define EVT_LOGOUT      4       /* A user is logging out */
224 #define EVT_SETPASS     5       /* Setting or changing password */
225 #define EVT_CMD         6       /* Called after each server command */
226 #define EVT_RWHO        7       /* An RWHO command is being executed */
227
228
229
230
231
232 /*
233  * UserFunctionHook extensions are used for any type of hook which implements
234  * an operation on a user or username (potentially) other than the one
235  * operating the current session.
236  */
237 struct UserFunctionHook {
238         struct UserFunctionHook *next;
239         void (*h_function_pointer) (char *username, long usernum);
240         int eventtype;
241 };
242 extern struct UserFunctionHook *UserHookTable;
243
244 #define EVT_PURGEUSER   100     /* Deleting a user */
245 #define EVT_OUTPUTMSG   101     /* Outputting a message */
246
247
248
249
250 /*
251  * ExpressMessageFunctionHook extensions are used for hooks which implement
252  * the sending of an express message through various channels.  Any function
253  * registered should return the number of recipients to whom the message was
254  * successfully transmitted.
255  */
256 struct XmsgFunctionHook {
257         struct XmsgFunctionHook *next;
258         int (*h_function_pointer) (char *, char *, char *);
259         int order;
260 };
261 extern struct XmsgFunctionHook *XmsgHookTable;
262
263 /* Priority levels for paging functions (lower is better) */
264 enum {
265         XMSG_PRI_LOCAL,         /* Other users on -this- server */
266         XMSG_PRI_REMOTE,        /* Other users on a Citadel network (future) */
267         XMSG_PRI_FOREIGN,       /* Contacts on foreign instant message hosts */
268         MAX_XMSG_PRI
269 };
270
271
272
273
274
275 /* Defines the relationship of a user to a particular room */
276 struct visit {
277         long v_roomnum;
278         long v_roomgen;
279         long v_usernum;
280         long v_lastseen;
281         unsigned int v_flags;
282 };
283
284 #define V_FORGET        1       /* User has zapped this room        */
285 #define V_LOCKOUT       2       /* User is locked out of this room  */
286 #define V_ACCESS        4       /* Access is granted to this room   */
287
288 #define UA_KNOWN                2
289 #define UA_GOTOALLOWED          4
290 #define UA_HASNEWMSGS           8
291 #define UA_ZAPPED               16
292
293
294 /* Supplementary data for a message on disk
295  * (These are kept separately from the message itself because they are
296  * fields whose values may change at some point after the message is saved.)
297  */
298 struct SuppMsgInfo {
299         long smi_msgnum;        /* Message number in *local* message base */
300         int smi_refcount;       /* Number of rooms which point to this msg */
301         char smi_content_type[64];
302         /* more stuff will be added to this record in the future */
303 };
304
305
306
307 /* Built-in debuggable stuff for checking for memory leaks */
308 #ifdef DEBUG_MEMORY_LEAKS
309
310 #define mallok(howbig)          tracked_malloc(howbig, __FILE__, __LINE__)
311 #define phree(whichptr)                 tracked_free(whichptr)
312 #define reallok(whichptr,howbig)        tracked_realloc(whichptr,howbig)
313 #define strdoop(orig)           tracked_strdup(orig, __FILE__, __LINE__)
314
315 void *tracked_malloc(size_t, char *, int);
316 void tracked_free(void *);
317 void *tracked_realloc(void *, size_t);
318 void dump_tracked(void);
319 char *tracked_strdup(const char *, char *, int);
320
321 struct TheHeap {
322         struct TheHeap *next;
323         char h_file[32];
324         int h_line;
325         void *h_ptr;
326 };
327
328 extern struct TheHeap *heap;
329
330 #else
331
332 #define mallok(howbig)                  malloc(howbig)
333 #define phree(whichptr)                 free(whichptr)
334 #define reallok(whichptr,howbig)        realloc(whichptr,howbig)
335 #define strdoop(orig)                   strdup(orig)
336
337
338 #endif
339
340
341 /*
342  * New format for a message in memory
343  */
344 #define CTDLMESSAGE_MAGIC               0x159d
345 struct CtdlMessage {
346         int cm_magic;                   /* Self-check */
347         char cm_anon_type;              /* Anonymous or author-visible */
348         char cm_format_type;            /* Format type */
349         char *cm_fields[256];           /* Data fields */
350 };