d7c2361dcce4ae96783876a023e005f30980fb4b
[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  * For the time being, all known userdata symbols are defined here.
21  */
22 #define SYM_DESIRED_SECTION             0x00000001
23
24
25 /*
26  * Here's the big one... the Citadel context structure.
27  *
28  * This structure keeps track of all information relating to a running 
29  * session on the server.  We keep one of these for each session thread.
30  *
31  * Note that the first element is "*next" so that it may be used without
32  * modification in a linked list.
33  */
34 struct CitContext {
35         struct CitContext *next;        /* Link to next session in the list */
36
37         struct usersupp usersupp;       /* Database record buffers */
38         struct quickroom quickroom;
39
40         long *msglist;
41         int num_msgs;
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[25];       /* 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 #define S_USERSUPP      0
128 #define S_USER_TRANS    1
129 #define S_QUICKROOM     2
130 #define S_MSGMAIN       3
131 #define S_CALLLOG       4
132 #define S_SESSION_TABLE 5
133 #define S_FLOORTAB      6
134 #define S_CHATQUEUE     7
135 #define S_CONTROL       8
136 #define S_HOUSEKEEPING  9
137 #define S_DATABASE      10
138 #define S_NETDB         11
139 #define MAX_SEMAPHORES  12
140
141
142 /*
143  * Upload types
144  */
145 #define UPL_FILE        0
146 #define UPL_NET         1
147 #define UPL_IMAGE       2
148
149
150 /*
151  * message transfer formats
152  */
153 #define MT_CITADEL      0       /* Citadel proprietary */
154 #define MT_DATE         1       /* We're only looking for the date */
155 #define MT_RFC822       2       /* RFC822 */
156 #define MT_RAW          3       /* IGnet raw format */
157 #define MT_MIME         4       /* MIME-formatted message */
158 #define MT_DOWNLOAD     5       /* Download a component */
159
160
161 /*
162  * Citadel DataBases (define one for each cdb we need to open)
163  */
164 #define CDB_MSGMAIN     0       /* message base                  */
165 #define CDB_USERSUPP    1       /* user file                     */
166 #define CDB_QUICKROOM   2       /* room index                    */
167 #define CDB_FLOORTAB    3       /* floor index                   */
168 #define CDB_MSGLISTS    4       /* room message lists            */
169 #define CDB_VISIT       5       /* user/room relationships       */
170 #define MAXCDB          6       /* total number of CDB's defined */
171
172 struct cdbdata {
173         size_t len;
174         char *ptr;
175 };
176
177
178 /* Structures and declarations for function hooks of various types */
179
180 struct LogFunctionHook {
181         struct LogFunctionHook *next;
182         int loglevel;
183         void (*h_function_pointer) (char *);
184 };
185 extern struct LogFunctionHook *LogHookTable;
186
187 struct CleanupFunctionHook {
188         struct CleanupFunctionHook *next;
189         void (*h_function_pointer) (void);
190 };
191 extern struct CleanupFunctionHook *CleanupHookTable;
192
193
194 /*
195  * SessionFunctionHook extensions are used for any type of hook for which
196  * the context in which it's being called (which is determined by the event
197  * type) will make it obvious for the hook function to know where to look for
198  * pertinent data.
199  */
200 struct SessionFunctionHook {
201         struct SessionFunctionHook *next;
202         void (*h_function_pointer) (void);
203         int eventtype;
204 };
205 extern struct SessionFunctionHook *SessionHookTable;
206
207 #define EVT_STOP        0       /* Session is terminating */
208 #define EVT_START       1       /* Session is starting */
209 #define EVT_LOGIN       2       /* A user is logging in */
210 #define EVT_NEWROOM     3       /* Changing rooms */
211 #define EVT_LOGOUT      4       /* A user is logging out */
212 #define EVT_SETPASS     5       /* Setting or changing password */
213
214
215 /*
216  * UserFunctionHook extensions are used for any type of hook which implements
217  * an operation on a user or username (potentially) other than the one
218  * operating the current session.
219  */
220 struct UserFunctionHook {
221         struct UserFunctionHook *next;
222         void (*h_function_pointer) (char *username, long usernum);
223         int eventtype;
224 };
225 extern struct UserFunctionHook *UserHookTable;
226
227 #define EVT_PURGEUSER   100     /* Deleting a user */
228 #define EVT_OUTPUTMSG   101     /* Outputting a message */
229
230
231 /* Defines the relationship of a user to a particular room */
232 struct visit {
233         long v_roomnum;
234         long v_roomgen;
235         long v_usernum;
236         long v_lastseen;
237         unsigned int v_flags;
238 };
239
240 #define V_FORGET        1       /* User has zapped this room        */
241 #define V_LOCKOUT       2       /* User is locked out of this room  */
242 #define V_ACCESS        4       /* Access is granted to this room   */
243
244 #define UA_KNOWN                2
245 #define UA_GOTOALLOWED          4
246 #define UA_HASNEWMSGS           8
247 #define UA_ZAPPED               16
248
249
250
251 /* Built-in debuggable stuff for checking for memory leaks */
252 #ifdef DEBUG_MEMORY_LEAKS
253
254 #define mallok(howbig)  tracked_malloc(howbig, __FILE__, __LINE__)
255 #define phree(whichptr) tracked_free(whichptr)
256 #define reallok(whichptr,howbig)        tracked_realloc(whichptr,howbig)
257
258 void *tracked_malloc(size_t, char *, int);
259 void tracked_free(void *);
260 void *tracked_realloc(void *, size_t);
261 void dump_tracked(void);
262
263 struct TheHeap {
264         struct TheHeap *next;
265         char h_file[32];
266         int h_line;
267         void *h_ptr;
268 };
269
270 extern struct TheHeap *heap;
271
272 #else
273
274 #define mallok(howbig)  malloc(howbig)
275 #define phree(whichptr) free(whichptr)
276 #define reallok(whichptr,howbig)        realloc(whichptr,howbig)
277
278 #endif