b6cd9afa74ad9ac67bfc99d093becc942bf69e1e
[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  * Here's the big one... the Citadel context structure.
12  *
13  * This structure keeps track of all information relating to a running 
14  * session on the server.  We keep one of these for each session thread.
15  *
16  * Note that the first element is "*next" so that it may be used without
17  * modification in a linked list.
18  */
19 struct CitContext {
20         struct CitContext *next;        /* Link to next session in the list */
21
22         struct usersupp usersupp;       /* Database record buffers */
23         struct quickroom quickroom;
24         
25         long *msglist;
26         int num_msgs;
27
28         char curr_user[32];             /* name of current user */
29         int logged_in;                  /* logged in */
30         int internal_pgm;               /* authenticated as internal program */
31         char temp[32];                  /* temp file name */
32         int nologin;                    /* not allowed to log in */
33
34         char net_node[32];
35         THREAD mythread;
36         int n_crit;                     /* number of critical sections open */
37         int client_socket;
38         int cs_pid;                     /* session ID */
39         char cs_room[ROOMNAMELEN];      /* current room */
40         time_t cs_lastupdt;             /* time of last update */
41         time_t lastcmd;                 /* time of last command executed */
42         time_t lastidle;                /* For computing idle time */
43         char lastcmdname[5];            /* name of last command executed */
44         unsigned cs_flags;              /* miscellaneous flags */
45
46                                         /* feeping creaturisms... */
47         int cs_clientdev;               /* client developer ID */
48         int cs_clienttyp;               /* client type code */
49         int cs_clientver;               /* client version number */
50         char cs_clientname[32];         /* name of client software */
51         char cs_host[25];               /* host logged in from */
52
53         FILE *download_fp;              /* Fields relating to file transfer */
54         FILE *upload_fp;
55         char upl_file[256];
56         char upl_path[256];
57         char upl_comment[256];
58         char upl_filedir[256];
59         char chat_room[20];             /* The chat room */
60         char dl_is_net;
61         char upload_type;
62
63         struct ExpressMessage *FirstExpressMessage;
64
65         char fake_username[32];         /* Fake username <bc>                */
66         char fake_postname[32];         /* Fake postname <bc>                */
67         char fake_hostname[25];         /* Name of the fake hostname <bc>    */
68         char fake_roomname[ROOMNAMELEN];/* Name of the fake room <bc>        */
69
70         int FloorBeingSearched;         /* This is used by cmd_lrms() etc.   */
71         char desired_section[64];       /* This is used for MIME downloads   */
72         };
73
74 typedef struct CitContext t_context;
75
76 #define CS_STEALTH      1               /* stealth mode */
77 #define CS_CHAT         2               /* chat mode */
78 #define CS_POSTING      4               /* Posting */
79
80 struct CitContext *MyContext(void);
81 #define CC ((struct CitContext *)MyContext())
82
83 extern struct CitContext *ContextList;
84 extern int ScheduledShutdown;
85 extern struct CitControl CitControl;
86
87
88 struct ExpressMessage {
89         struct ExpressMessage *next;
90         time_t timestamp;               /* When this message was sent */
91         unsigned flags;                 /* Special instructions */
92         char sender[64];                /* Name of sending user */
93         char *text;                     /* Message text (if applicable) */
94         };
95
96 #define EM_BROADCAST    1               /* Broadcast message */
97 #define EM_GO_AWAY      2               /* Server requests client log off */
98 #define EM_CHAT         4               /* Server requests client enter chat */
99
100 struct ChatLine {
101         struct ChatLine *next;
102         int chat_seq;
103         time_t chat_time;
104         char chat_text[256];
105         char chat_room[20];
106         char chat_username[32];
107         };
108
109 /*
110  * Various things we need to lock and unlock
111  */
112 #define S_USERSUPP      0
113 #define S_USER_TRANS    1
114 #define S_QUICKROOM     2
115 #define S_MSGMAIN       3
116 #define S_CALLLOG       4
117 #define S_SESSION_TABLE 5
118 #define S_FLOORTAB      6
119 #define S_CHATQUEUE     7
120 #define S_CONTROL       8
121 #define S_HOUSEKEEPING  9
122 #define S_DATABASE      10
123 #define S_NETDB         11
124 #define MAX_SEMAPHORES  12
125
126
127 /*
128  * Upload types
129  */
130 #define UPL_FILE        0
131 #define UPL_NET         1
132 #define UPL_IMAGE       2
133
134
135 /*
136  * message transfer formats
137  */
138 #define MT_CITADEL      0               /* Citadel proprietary */
139 #define MT_DATE         1               /* We're only looking for the date */
140 #define MT_RFC822       2               /* RFC822 */
141 #define MT_RAW          3               /* IGnet raw format */
142 #define MT_MIME         4               /* MIME-formatted message */
143 #define MT_DOWNLOAD     5               /* Download a component */
144
145
146 /*
147  * Citadel DataBases (define one for each cdb we need to open)
148  */
149 #define CDB_MSGMAIN     0       /* message base                  */
150 #define CDB_USERSUPP    1       /* user file                     */
151 #define CDB_QUICKROOM   2       /* room index                    */
152 #define CDB_FLOORTAB    3       /* floor index                   */
153 #define CDB_MSGLISTS    4       /* room message lists            */
154 #define CDB_VISIT       5       /* user/room relationships       */
155 #define MAXCDB          6       /* total number of CDB's defined */
156
157 struct cdbdata {
158         size_t len;
159         char *ptr;
160         };
161
162
163 /* Structures and declarations for function hooks of various types */
164
165 struct LogFunctionHook {
166         struct LogFunctionHook *next;
167         int loglevel;
168         void (*h_function_pointer) (char *);
169         };
170 extern struct LogFunctionHook *LogHookTable;
171
172 struct CleanupFunctionHook {
173         struct CleanupFunctionHook *next;
174         void (*h_function_pointer) (void);
175         };
176 extern struct CleanupFunctionHook *CleanupHookTable;
177
178
179 /*
180  * SessionFunctionHook extensions are used for any type of hook for which
181  * the context in which it's being called (which is determined by the event
182  * type) will make it obvious for the hook function to know where to look for
183  * pertinent data.
184  */
185 struct SessionFunctionHook {
186         struct SessionFunctionHook *next;
187         void (*h_function_pointer) (void);
188         int eventtype;
189         };
190 extern struct SessionFunctionHook *SessionHookTable;
191
192 #define EVT_STOP        0       /* Session is terminating */
193 #define EVT_START       1       /* Session is starting */
194 #define EVT_LOGIN       2       /* A user is logging in */
195 #define EVT_NEWROOM     3       /* Changing rooms */
196 #define EVT_LOGOUT      4       /* A user is logging out */
197 #define EVT_SETPASS     5       /* Setting or changing password */
198
199
200 /*
201  * UserFunctionHook extensions are used for any type of hook which implements
202  * an operation on a user or username (potentially) other than the one
203  * operating the current session.
204  */
205 struct UserFunctionHook {
206         struct UserFunctionHook *next;
207         void (*h_function_pointer) (char *username, long usernum);
208         int eventtype;
209         };
210 extern struct UserFunctionHook *UserHookTable;
211
212 #define EVT_PURGEUSER   100     /* Deleting a user */
213 #define EVT_OUTPUTMSG   101     /* Outputting a message */
214
215
216 /* Defines the relationship of a user to a particular room */
217 struct visit {
218         long v_roomnum;
219         long v_roomgen;
220         long v_usernum;
221         long v_lastseen;
222         unsigned int v_flags;
223         };
224
225 #define V_FORGET        1               /* User has zapped this room        */
226 #define V_LOCKOUT       2               /* User is locked out of this room  */
227 #define V_ACCESS        4               /* Access is granted to this room   */
228
229 #define UA_KNOWN                2
230 #define UA_GOTOALLOWED          4
231 #define UA_HASNEWMSGS           8
232 #define UA_ZAPPED               16
233
234
235
236 /* Built-in debuggable stuff for checking for memory leaks */
237 #ifdef DEBUG_MEMORY_LEAKS
238
239 #define mallok(howbig)  tracked_malloc(howbig, __FILE__, __LINE__)
240 #define phree(whichptr) tracked_free(whichptr)
241 #define reallok(whichptr,howbig)        tracked_realloc(whichptr,howbig)
242
243 void *tracked_malloc(size_t, char *, int);
244 void tracked_free(void *);
245 void *tracked_realloc(void *, size_t);
246 void dump_tracked(void);
247
248 struct TheHeap {
249         struct TheHeap *next;
250         char h_file[32];
251         int h_line;
252         void *h_ptr;
253         };
254
255 extern struct TheHeap *heap;
256
257 #else
258
259 #define mallok(howbig)  malloc(howbig)
260 #define phree(whichptr) free(whichptr)
261 #define reallok(whichptr,howbig)        realloc(whichptr,howbig)
262
263 #endif