]> code.citadel.org Git - citadel.git/blob - citadel/server.h
d1ec072c822b0e3cf1073d594247f40be554f812
[citadel.git] / citadel / server.h
1 /* $Id$ */
2
3
4 #ifndef SERVER_H
5 #define SERVER_H
6
7 #ifdef __GNUC__
8 #define INLINE __inline__
9 #else
10 #define INLINE
11 #endif
12
13 #include "citadel.h"
14 #ifdef HAVE_OPENSSL
15 #include <openssl/ssl.h>
16 #endif
17
18 /*
19  * New format for a message in memory
20  */
21 struct CtdlMessage {
22         int cm_magic;                   /* Self-check (NOT SAVED TO DISK) */
23         char cm_anon_type;              /* Anonymous or author-visible */
24         char cm_format_type;            /* Format type */
25         char *cm_fields[256];           /* Data fields */
26         unsigned int cm_flags;          /* How to handle (NOT SAVED TO DISK) */
27 };
28
29 #define CTDLMESSAGE_MAGIC               0x159d
30 #define CM_SKIP_HOOKS   0x01            /* Don't run server-side handlers */
31
32
33 /*
34  * Generic per-session variable or data structure storage
35  */
36 struct CtdlSessData {
37         struct CtdlSessData *next;
38         unsigned long sym_id;
39         void *sym_data;
40 };
41
42 /*
43  * Static user data symbol types.  Server extensions can ask for dynamic
44  * extensions to per-session data, but the symbol ID has to be listed here.
45  */
46 enum {
47         SYM_DESIRED_SECTION,            /* Used by the MIME parser */
48         SYM_MA_INFO,                    /* Handles multipart/alternative */
49         SYM_REPL,                       /* Used for replication checking */
50         SYM_CIT_ICAL,                   /* Used by the calendar service */
51         SYM_IMAP,                       /* Used by the IMAP service */
52         SYM_POP3,                       /* Used by the POP3 service */
53         SYM_SMTP,                       /* Used by the SMTP service */
54         SYM_SMTP_RECPS,
55         SYM_SMTP_ROOMS,
56         SYM_VCARD,                      /* vCard handling requires this */
57         SYM_MAX
58 };
59
60
61 /*
62  * Here's the big one... the Citadel context structure.
63  *
64  * This structure keeps track of all information relating to a running 
65  * session on the server.  We keep one of these for each session thread.
66  *
67  * Note that the first element is "*next" so that it may be used without
68  * modification in a linked list.
69  */
70 struct CitContext {
71         struct CitContext *next;        /* Link to next session in the list */
72
73         struct ctdluser user;   /* Database record buffers */
74         struct ctdlroom room;
75
76         int state;              /* thread state (see CON_ values below) */
77         int kill_me;            /* Set to nonzero to flag for termination */
78
79         char curr_user[USERNAME_SIZE];  /* name of current user */
80         int logged_in;          /* logged in */
81         int internal_pgm;       /* authenticated as internal program */
82         char temp[PATH_MAX];    /* temp file name */
83         int nologin;            /* not allowed to log in */
84         int is_local_socket;    /* set to 1 if client is on unix domain sock */
85
86         char net_node[PATH_MAX];/* Is the client another Citadel server? */
87         int client_socket;
88         int cs_pid;             /* session ID */
89         time_t lastcmd;         /* time of last command executed */
90         time_t lastidle;        /* For computing idle time */
91         time_t previous_login;  /* Date/time of previous login */
92         char lastcmdname[5];    /* name of last command executed */
93         unsigned cs_flags;      /* miscellaneous flags */
94         void (*h_command_function) (void) ;     /* service command function */
95         int is_async;           /* Nonzero if client accepts async msgs */
96
97         /* feeping creaturisms... */
98         int cs_clientdev;       /* client developer ID */
99         int cs_clienttyp;       /* client type code */
100         int cs_clientver;       /* client version number */
101         char cs_clientname[32]; /* name of client software */
102         char cs_host[64];       /* host logged in from */
103         char cs_addr[64];       /* address logged in from */
104
105         /* The Internet type of thing */
106         char cs_inet_email[SIZ];/* Return address of outbound Internet mail */
107
108         FILE *download_fp;      /* Fields relating to file transfer */
109         FILE *upload_fp;
110         char upl_file[PATH_MAX];
111         char upl_path[PATH_MAX];
112         char upl_comment[SIZ];
113         char upl_filedir[PATH_MAX];
114         char dl_is_net;
115         char upload_type;
116
117         /* Beginning of cryptography - session nonce */
118         char cs_nonce[NONCE_SIZE];      /* The nonce for this session's next auth transaction */
119
120         /* Redirect this session's output to somewhere else? */
121         FILE *redirect_fp;
122         int redirect_sock;
123 #ifdef HAVE_OPENSSL
124         SSL *ssl;
125         int redirect_ssl;
126 #endif
127
128         int buffering;
129         char *output_buffer;    /* hold output for one big dump */
130         int buffer_len;
131
132         /* A linked list of all express messages sent to us. */
133         struct ExpressMessage *FirstExpressMessage;
134         int disable_exp;        /* Set to 1 to disable incoming pages */
135         int newmail;            /* Other sessions increment this */
136
137         /* Masquerade... */
138         char fake_username[USERNAME_SIZE];      /* Fake username <bc> */ 
139         char fake_postname[USERNAME_SIZE];      /* Fake postname <bc> */
140         char fake_hostname[64];                 /* Fake hostname <bc> */
141         char fake_roomname[ROOMNAMELEN];        /* Fake roomname <bc> */
142
143         char preferred_formats[SIZ];            /* Preferred MIME formats */
144
145         /* Dynamically allocated session data */
146         struct CtdlSessData *FirstSessData;
147 };
148
149 typedef struct CitContext t_context;
150
151 /* Values for CitContext.state */
152 enum {
153         CON_IDLE,               /* This context is doing nothing */
154         CON_READY,              /* This context is ready-to-run */
155         CON_EXECUTING,          /* This context is bound to a thread */
156 };
157
158
159 #define CS_STEALTH      1       /* stealth mode */
160 #define CS_CHAT         2       /* chat mode */
161 #define CS_POSTING      4       /* Posting */
162
163 struct CitContext *MyContext(void);
164 #define CC MyContext()
165
166 extern struct CitContext *ContextList;
167 extern int ScheduledShutdown;
168 extern struct CitControl CitControl;
169
170
171 struct ExpressMessage {
172         struct ExpressMessage *next;
173         time_t timestamp;       /* When this message was sent */
174         unsigned flags;         /* Special instructions */
175         char sender[64];        /* Name of sending user */
176         char *text;             /* Message text (if applicable) */
177 };
178
179 #define EM_BROADCAST    1       /* Broadcast message */
180 #define EM_GO_AWAY      2       /* Server requests client log off */
181 #define EM_CHAT         4       /* Server requests client enter chat */
182
183 struct ChatLine {
184         struct ChatLine *next;
185         int chat_seq;
186         time_t chat_time;
187         char chat_text[SIZ];
188         char chat_username[USERNAME_SIZE];
189         char chat_room[ROOMNAMELEN];
190 };
191
192 /*
193  * Various things we need to lock and unlock
194  */
195 enum {
196         S_USERS,
197         S_ROOMS,
198         S_SESSION_TABLE,
199         S_FLOORTAB,
200         S_CHATQUEUE,
201         S_CONTROL,
202         S_DATABASE,
203         S_NETDB,
204         S_SUPPMSGMAIN,
205         S_I_WANNA_SELECT,
206         S_CONFIG,
207         S_WORKER_LIST,
208         S_HOUSEKEEPING,
209         S_NTTLIST,
210         S_DIRECTORY,
211         S_NETCONFIGS,
212         S_PUBLIC_CLIENTS,
213         S_LDAP,
214         S_FLOORCACHE,
215         S_DEBUGMEMLEAKS,
216         MAX_SEMAPHORES
217 };
218
219
220 /*
221  * Upload types
222  */
223 #define UPL_FILE        0
224 #define UPL_NET         1
225 #define UPL_IMAGE       2
226
227
228 /*
229  * message transfer formats
230  */
231 enum {
232         MT_CITADEL,             /* Citadel proprietary */
233         MT_RFC822,              /* RFC822 */
234         MT_MIME,                /* MIME-formatted message */
235         MT_DOWNLOAD             /* Download a component */
236 };
237
238 /*
239  * Message format types in the database
240  */
241 #define FMT_CITADEL     0       /* Citadel vari-format (proprietary) */
242 #define FMT_FIXED       1       /* Fixed format (proprietary)        */
243 #define FMT_RFC822      4       /* Standard (headers are in M field) */
244
245
246 /*
247  * Citadel DataBases (define one for each cdb we need to open)
248  */
249 enum {
250         CDB_MSGMAIN,            /* message base                  */
251         CDB_USERS,              /* user file                     */
252         CDB_ROOMS,              /* room index                    */
253         CDB_FLOORTAB,           /* floor index                   */
254         CDB_MSGLISTS,           /* room message lists            */
255         CDB_VISIT,              /* user/room relationships       */
256         CDB_DIRECTORY,          /* address book directory        */
257         CDB_USETABLE,           /* network use table             */
258         MAXCDB                  /* total number of CDB's defined */
259 };
260
261 struct cdbdata {
262         size_t len;
263         char *ptr;
264 };
265
266
267
268 /* Structures and declarations for function hooks of various types */
269
270 struct LogFunctionHook {
271         struct LogFunctionHook *next;
272         int loglevel;
273         void (*h_function_pointer) (char *);
274 };
275 extern struct LogFunctionHook *LogHookTable;
276
277 struct CleanupFunctionHook {
278         struct CleanupFunctionHook *next;
279         void (*h_function_pointer) (void);
280 };
281 extern struct CleanupFunctionHook *CleanupHookTable;
282
283
284
285
286 /*
287  * SessionFunctionHook extensions are used for any type of hook for which
288  * the context in which it's being called (which is determined by the event
289  * type) will make it obvious for the hook function to know where to look for
290  * pertinent data.
291  */
292 struct SessionFunctionHook {
293         struct SessionFunctionHook *next;
294         void (*h_function_pointer) (void);
295         int eventtype;
296 };
297 extern struct SessionFunctionHook *SessionHookTable;
298
299 /* 
300  * Event types can't be enum'ed, because they must remain consistent between
301  * builds (to allow for binary modules built somewhere else)
302  */
303 #define EVT_STOP        0       /* Session is terminating */
304 #define EVT_START       1       /* Session is starting */
305 #define EVT_LOGIN       2       /* A user is logging in */
306 #define EVT_NEWROOM     3       /* Changing rooms */
307 #define EVT_LOGOUT      4       /* A user is logging out */
308 #define EVT_SETPASS     5       /* Setting or changing password */
309 #define EVT_CMD         6       /* Called after each server command */
310 #define EVT_RWHO        7       /* An RWHO command is being executed */
311
312 #define EVT_TIMER       50      /* Timer events are called once per minute
313                                    and are not tied to any session */
314
315 /*
316  * UserFunctionHook extensions are used for any type of hook which implements
317  * an operation on a user or username (potentially) other than the one
318  * operating the current session.
319  */
320 struct UserFunctionHook {
321         struct UserFunctionHook *next;
322         void (*h_function_pointer) (struct ctdluser *usbuf);
323         int eventtype;
324 };
325 extern struct UserFunctionHook *UserHookTable;
326
327 #define EVT_PURGEUSER   100     /* Deleting a user */
328 #define EVT_NEWUSER     102     /* Creating a user */
329
330 /*
331  * MessageFunctionHook extensions are used for hooks which implement handlers
332  * for various types of message operations (save, read, etc.)
333  */
334 struct MessageFunctionHook {
335         struct MessageFunctionHook *next;
336         int (*h_function_pointer) (struct CtdlMessage *msg);
337         int eventtype;
338 };
339 extern struct MessageFunctionHook *MessageHookTable;
340
341 #define EVT_BEFOREREAD  200
342 #define EVT_BEFORESAVE  201
343 #define EVT_AFTERSAVE   202
344 #define EVT_SMTPSCAN    203     /* called before submitting a msg from SMTP */
345
346
347
348 /*
349  * NetprocFunctionHook extensions are used for hooks which implement handlers
350  * for incoming network messages.
351  */
352 struct NetprocFunctionHook {
353         struct NetprocFunctionHook *next;
354         int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
355 };
356 extern struct NetprocFunctionHook *NetprocHookTable;
357
358
359 /*
360  * DeleteFunctionHook extensions are used for hooks which get called when a
361  * message is about to be deleted.
362  */
363 struct DeleteFunctionHook {
364         struct DeleteFunctionHook *next;
365         void (*h_function_pointer) (char *target_room, long msgnum);
366 };
367 extern struct DeleteFunctionHook *DeleteHookTable;
368
369
370 /*
371  * ExpressMessageFunctionHook extensions are used for hooks which implement
372  * the sending of an express message through various channels.  Any function
373  * registered should return the number of recipients to whom the message was
374  * successfully transmitted.
375  */
376 struct XmsgFunctionHook {
377         struct XmsgFunctionHook *next;
378         int (*h_function_pointer) (char *, char *, char *);
379         int order;
380 };
381 extern struct XmsgFunctionHook *XmsgHookTable;
382
383 /* Priority levels for paging functions (lower is better) */
384 enum {
385         XMSG_PRI_LOCAL,         /* Other users on -this- server */
386         XMSG_PRI_REMOTE,        /* Other users on a Citadel network (future) */
387         XMSG_PRI_FOREIGN,       /* Contacts on foreign instant message hosts */
388         MAX_XMSG_PRI
389 };
390
391
392
393 /*
394  * ServiceFunctionHook extensions are used for hooks which implement various
395  * non-Citadel services (on TCP protocols) directly in the Citadel server.
396  */
397 struct ServiceFunctionHook {
398         struct ServiceFunctionHook *next;
399         int tcp_port;
400         char *sockpath;
401         void (*h_greeting_function) (void) ;
402         void (*h_command_function) (void) ;
403         int msock;
404 };
405 extern struct ServiceFunctionHook *ServiceHookTable;
406
407
408
409 /* Defines the relationship of a user to a particular room */
410 struct visit {
411         long v_roomnum;
412         long v_roomgen;
413         long v_usernum;
414         long v_lastseen;
415         unsigned int v_flags;
416         char v_seen[SIZ];
417         char v_answered[SIZ];
418         int v_view;
419 };
420
421 #define V_FORGET        1       /* User has zapped this room        */
422 #define V_LOCKOUT       2       /* User is locked out of this room  */
423 #define V_ACCESS        4       /* Access is granted to this room   */
424
425
426 /* Supplementary data for a message on disk
427  * (These are kept separately from the message itself because they are
428  * fields whose values may change at some point after the message is saved.)
429  */
430 struct MetaData {
431         long meta_msgnum;       /* Message number in *local* message base */
432         int meta_refcount;      /* Number of rooms which point to this msg */
433         char meta_content_type[64];
434         /* more stuff will be added to this record in the future */
435 };
436
437
438 /* 
439  * Serialization routines use this struct to return a pointer and a length
440  */
441 struct ser_ret {
442         size_t len;
443         char *ser;
444 };
445
446
447 /* Preferred field order */
448 /*               **********                     Important fields */
449 /*                         ***************      Semi-important fields */
450 /*                                        *     Message text (MUST be last) */
451 #define FORDER  "IPTAFONHRDBCEGJKLQSVWXYZUM"
452
453 #endif /* SERVER_H */