Changes to dynloader et al to handle ICQ module being written
[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         long *msglist;
44         int num_msgs;
45
46         char curr_user[32];     /* name of current user */
47         int logged_in;          /* logged in */
48         int internal_pgm;       /* authenticated as internal program */
49         char temp[32];          /* temp file name */
50         int nologin;            /* not allowed to log in */
51
52         char net_node[32];
53         THREAD mythread;
54         int n_crit;             /* number of critical sections open */
55         int client_socket;
56         int cs_pid;             /* session ID */
57         char cs_room[ROOMNAMELEN];      /* current room */
58         time_t cs_lastupdt;     /* time of last update */
59         time_t lastcmd;         /* time of last command executed */
60         time_t lastidle;        /* For computing idle time */
61         char lastcmdname[5];    /* name of last command executed */
62         unsigned cs_flags;      /* miscellaneous flags */
63
64         /* feeping creaturisms... */
65         int cs_clientdev;       /* client developer ID */
66         int cs_clienttyp;       /* client type code */
67         int cs_clientver;       /* client version number */
68         char cs_clientname[32]; /* name of client software */
69         char cs_host[25];       /* host logged in from */
70
71         FILE *download_fp;      /* Fields relating to file transfer */
72         FILE *upload_fp;
73         char upl_file[256];
74         char upl_path[256];
75         char upl_comment[256];
76         char upl_filedir[256];
77         char chat_room[20];     /* The chat room */
78         char dl_is_net;
79         char upload_type;
80
81         struct ExpressMessage *FirstExpressMessage;
82
83         char fake_username[32]; /* Fake username <bc>                */
84         char fake_postname[32]; /* Fake postname <bc>                */
85         char fake_hostname[25]; /* Name of the fake hostname <bc>    */
86         char fake_roomname[ROOMNAMELEN];        /* Name of the fake room <bc> */
87
88         int FloorBeingSearched; /* This is used by cmd_lrms() etc.   */
89         struct CtdlSessData *FirstSessData;
90 };
91
92 typedef struct CitContext t_context;
93
94 #define CS_STEALTH      1       /* stealth mode */
95 #define CS_CHAT         2       /* chat mode */
96 #define CS_POSTING      4       /* Posting */
97
98 struct CitContext *MyContext(void);
99 #define CC ((struct CitContext *)MyContext())
100
101 extern struct CitContext *ContextList;
102 extern int ScheduledShutdown;
103 extern struct CitControl CitControl;
104
105
106 struct ExpressMessage {
107         struct ExpressMessage *next;
108         time_t timestamp;       /* When this message was sent */
109         unsigned flags;         /* Special instructions */
110         char sender[64];        /* Name of sending user */
111         char *text;             /* Message text (if applicable) */
112 };
113
114 #define EM_BROADCAST    1       /* Broadcast message */
115 #define EM_GO_AWAY      2       /* Server requests client log off */
116 #define EM_CHAT         4       /* Server requests client enter chat */
117
118 struct ChatLine {
119         struct ChatLine *next;
120         int chat_seq;
121         time_t chat_time;
122         char chat_text[256];
123         char chat_room[20];
124         char chat_username[32];
125 };
126
127 /*
128  * Various things we need to lock and unlock
129  */
130 enum {
131         S_USERSUPP,
132         S_USER_TRANS,
133         S_QUICKROOM,
134         S_MSGMAIN,
135         S_CALLLOG,
136         S_SESSION_TABLE,
137         S_FLOORTAB,
138         S_CHATQUEUE,
139         S_CONTROL,
140         S_HOUSEKEEPING,
141         S_DATABASE,
142         S_NETDB,
143         S_SUPPMSGMAIN,
144         MAX_SEMAPHORES
145 };
146
147
148 /*
149  * Upload types
150  */
151 #define UPL_FILE        0
152 #define UPL_NET         1
153 #define UPL_IMAGE       2
154
155
156 /*
157  * message transfer formats
158  */
159 enum {
160         MT_CITADEL,             /* Citadel proprietary */
161         MT_DATE,                /* We're only looking for the date */
162         MT_RFC822,              /* RFC822 */
163         MT_RAW,                 /* IGnet raw format */
164         MT_MIME,                /* MIME-formatted message */
165         MT_DOWNLOAD             /* Download a component */
166 };
167
168
169 /*
170  * Citadel DataBases (define one for each cdb we need to open)
171  */
172 enum {
173         CDB_MSGMAIN,            /* message base                  */
174         CDB_USERSUPP,           /* user file                     */
175         CDB_QUICKROOM,          /* room index                    */
176         CDB_FLOORTAB,           /* floor index                   */
177         CDB_MSGLISTS,           /* room message lists            */
178         CDB_VISIT,              /* user/room relationships       */
179         MAXCDB                  /* total number of CDB's defined */
180 };
181
182 struct cdbdata {
183         size_t len;
184         char *ptr;
185 };
186
187
188 /* Structures and declarations for function hooks of various types */
189
190 struct LogFunctionHook {
191         struct LogFunctionHook *next;
192         int loglevel;
193         void (*h_function_pointer) (char *);
194 };
195 extern struct LogFunctionHook *LogHookTable;
196
197 struct CleanupFunctionHook {
198         struct CleanupFunctionHook *next;
199         void (*h_function_pointer) (void);
200 };
201 extern struct CleanupFunctionHook *CleanupHookTable;
202
203
204 /*
205  * SessionFunctionHook extensions are used for any type of hook for which
206  * the context in which it's being called (which is determined by the event
207  * type) will make it obvious for the hook function to know where to look for
208  * pertinent data.
209  */
210 struct SessionFunctionHook {
211         struct SessionFunctionHook *next;
212         void (*h_function_pointer) (void);
213         int eventtype;
214 };
215 extern struct SessionFunctionHook *SessionHookTable;
216
217 /* 
218  * Event types can't be enum'ed, because they must remain consistent between
219  * builds (to allow for binary modules built somewhere else)
220  */
221 #define EVT_STOP        0       /* Session is terminating */
222 #define EVT_START       1       /* Session is starting */
223 #define EVT_LOGIN       2       /* A user is logging in */
224 #define EVT_NEWROOM     3       /* Changing rooms */
225 #define EVT_LOGOUT      4       /* A user is logging out */
226 #define EVT_SETPASS     5       /* Setting or changing password */
227 #define EVT_CMD         6       /* Called after each server command */
228
229
230 /*
231  * UserFunctionHook extensions are used for any type of hook which implements
232  * an operation on a user or username (potentially) other than the one
233  * operating the current session.
234  */
235 struct UserFunctionHook {
236         struct UserFunctionHook *next;
237         void (*h_function_pointer) (char *username, long usernum);
238         int eventtype;
239 };
240 extern struct UserFunctionHook *UserHookTable;
241
242 #define EVT_PURGEUSER   100     /* Deleting a user */
243 #define EVT_OUTPUTMSG   101     /* Outputting a message */
244
245
246 /* Defines the relationship of a user to a particular room */
247 struct visit {
248         long v_roomnum;
249         long v_roomgen;
250         long v_usernum;
251         long v_lastseen;
252         unsigned int v_flags;
253 };
254
255 #define V_FORGET        1       /* User has zapped this room        */
256 #define V_LOCKOUT       2       /* User is locked out of this room  */
257 #define V_ACCESS        4       /* Access is granted to this room   */
258
259 #define UA_KNOWN                2
260 #define UA_GOTOALLOWED          4
261 #define UA_HASNEWMSGS           8
262 #define UA_ZAPPED               16
263
264
265 /* Supplementary data for a message on disk
266  * (These are kept separately from the message itself because they are
267  * fields whose values may change at some point after the message is saved.)
268  */
269 struct SuppMsgInfo {
270         long smi_msgnum;        /* Redundant, but useful for self-check */
271         int smi_refcount;       /* Number of rooms which point to this msg */
272         /* more stuff will be added to this record in the future */
273 };
274
275
276
277 /* Built-in debuggable stuff for checking for memory leaks */
278 #ifdef DEBUG_MEMORY_LEAKS
279
280 #define mallok(howbig)  tracked_malloc(howbig, __FILE__, __LINE__)
281 #define phree(whichptr) tracked_free(whichptr)
282 #define reallok(whichptr,howbig)        tracked_realloc(whichptr,howbig)
283
284 void *tracked_malloc(size_t, char *, int);
285 void tracked_free(void *);
286 void *tracked_realloc(void *, size_t);
287 void dump_tracked(void);
288
289 struct TheHeap {
290         struct TheHeap *next;
291         char h_file[32];
292         int h_line;
293         void *h_ptr;
294 };
295
296 extern struct TheHeap *heap;
297
298 #else
299
300 #define mallok(howbig)  malloc(howbig)
301 #define phree(whichptr) free(whichptr)
302 #define reallok(whichptr,howbig)        realloc(whichptr,howbig)
303
304 #endif