]> code.citadel.org Git - citadel.git/blob - citadel/server.h
* Added function CtdlGetDynamicSymbol() for dynamic symbol allocation
[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         MAX_SEMAPHORES
144 };
145
146
147 /*
148  * Upload types
149  */
150 #define UPL_FILE        0
151 #define UPL_NET         1
152 #define UPL_IMAGE       2
153
154
155 /*
156  * message transfer formats
157  */
158 enum {
159         MT_CITADEL,             /* Citadel proprietary */
160         MT_DATE,                /* We're only looking for the date */
161         MT_RFC822,              /* RFC822 */
162         MT_RAW,                 /* IGnet raw format */
163         MT_MIME,                /* MIME-formatted message */
164         MT_DOWNLOAD             /* Download a component */
165 };
166
167
168 /*
169  * Citadel DataBases (define one for each cdb we need to open)
170  */
171 enum {
172         CDB_MSGMAIN,            /* message base                  */
173         CDB_USERSUPP,           /* user file                     */
174         CDB_QUICKROOM,          /* room index                    */
175         CDB_FLOORTAB,           /* floor index                   */
176         CDB_MSGLISTS,           /* room message lists            */
177         CDB_VISIT,              /* user/room relationships       */
178         MAXCDB                  /* total number of CDB's defined */
179 };
180
181 struct cdbdata {
182         size_t len;
183         char *ptr;
184 };
185
186
187 /* Structures and declarations for function hooks of various types */
188
189 struct LogFunctionHook {
190         struct LogFunctionHook *next;
191         int loglevel;
192         void (*h_function_pointer) (char *);
193 };
194 extern struct LogFunctionHook *LogHookTable;
195
196 struct CleanupFunctionHook {
197         struct CleanupFunctionHook *next;
198         void (*h_function_pointer) (void);
199 };
200 extern struct CleanupFunctionHook *CleanupHookTable;
201
202
203 /*
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
207  * pertinent data.
208  */
209 struct SessionFunctionHook {
210         struct SessionFunctionHook *next;
211         void (*h_function_pointer) (void);
212         int eventtype;
213 };
214 extern struct SessionFunctionHook *SessionHookTable;
215
216 /* 
217  * Event types can't be enum'ed, because they must remain consistent between
218  * builds (to allow for binary modules built somewhere else)
219  */
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
227
228 /*
229  * UserFunctionHook extensions are used for any type of hook which implements
230  * an operation on a user or username (potentially) other than the one
231  * operating the current session.
232  */
233 struct UserFunctionHook {
234         struct UserFunctionHook *next;
235         void (*h_function_pointer) (char *username, long usernum);
236         int eventtype;
237 };
238 extern struct UserFunctionHook *UserHookTable;
239
240 #define EVT_PURGEUSER   100     /* Deleting a user */
241 #define EVT_OUTPUTMSG   101     /* Outputting a message */
242
243
244 /* Defines the relationship of a user to a particular room */
245 struct visit {
246         long v_roomnum;
247         long v_roomgen;
248         long v_usernum;
249         long v_lastseen;
250         unsigned int v_flags;
251 };
252
253 #define V_FORGET        1       /* User has zapped this room        */
254 #define V_LOCKOUT       2       /* User is locked out of this room  */
255 #define V_ACCESS        4       /* Access is granted to this room   */
256
257 #define UA_KNOWN                2
258 #define UA_GOTOALLOWED          4
259 #define UA_HASNEWMSGS           8
260 #define UA_ZAPPED               16
261
262
263
264 /* Built-in debuggable stuff for checking for memory leaks */
265 #ifdef DEBUG_MEMORY_LEAKS
266
267 #define mallok(howbig)  tracked_malloc(howbig, __FILE__, __LINE__)
268 #define phree(whichptr) tracked_free(whichptr)
269 #define reallok(whichptr,howbig)        tracked_realloc(whichptr,howbig)
270
271 void *tracked_malloc(size_t, char *, int);
272 void tracked_free(void *);
273 void *tracked_realloc(void *, size_t);
274 void dump_tracked(void);
275
276 struct TheHeap {
277         struct TheHeap *next;
278         char h_file[32];
279         int h_line;
280         void *h_ptr;
281 };
282
283 extern struct TheHeap *heap;
284
285 #else
286
287 #define mallok(howbig)  malloc(howbig)
288 #define phree(whichptr) free(whichptr)
289 #define reallok(whichptr,howbig)        realloc(whichptr,howbig)
290
291 #endif