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