]> code.citadel.org Git - citadel.git/blob - citadel/server.h
* Removed some vestiges
[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         void (*h_async_function) (void) ;       /* do async msgs function */
96         int is_async;           /* Nonzero if client accepts async msgs */
97         int async_waiting;      /* Nonzero if there are async msgs waiting */
98         int input_waiting;      /* Nonzero if there is client input waiting */
99
100         /* feeping creaturisms... */
101         int cs_clientdev;       /* client developer ID */
102         int cs_clienttyp;       /* client type code */
103         int cs_clientver;       /* client version number */
104         char cs_clientname[32]; /* name of client software */
105         char cs_host[64];       /* host logged in from */
106         char cs_addr[64];       /* address logged in from */
107
108         /* The Internet type of thing */
109         char cs_inet_email[SIZ];/* Return address of outbound Internet mail */
110
111         FILE *download_fp;      /* Fields relating to file transfer */
112         FILE *upload_fp;
113         char upl_file[PATH_MAX];
114         char upl_path[PATH_MAX];
115         char upl_comment[SIZ];
116         char upl_filedir[PATH_MAX];
117         char dl_is_net;
118         char upload_type;
119
120         /* Beginning of cryptography - session nonce */
121         char cs_nonce[NONCE_SIZE];      /* The nonce for this session's next auth transaction */
122
123         /* Redirect this session's output to somewhere else? */
124         FILE *redirect_fp;
125         int redirect_sock;
126 #ifdef HAVE_OPENSSL
127         SSL *ssl;
128         int redirect_ssl;
129 #endif
130
131         int buffering;
132         char *output_buffer;    /* hold output for one big dump */
133         int buffer_len;
134
135         /* A linked list of all instant messages sent to us. */
136         struct ExpressMessage *FirstExpressMessage;
137         int disable_exp;        /* Set to 1 to disable incoming pages */
138         int newmail;            /* Other sessions increment this */
139
140         /* Masquerade... */
141         char fake_username[USERNAME_SIZE];      /* Fake username <bc> */ 
142         char fake_postname[USERNAME_SIZE];      /* Fake postname <bc> */
143         char fake_hostname[64];                 /* Fake hostname <bc> */
144         char fake_roomname[ROOMNAMELEN];        /* Fake roomname <bc> */
145
146         char preferred_formats[SIZ];            /* Preferred MIME formats */
147
148         /* Dynamically allocated session data */
149         struct CtdlSessData *FirstSessData;
150 };
151
152 typedef struct CitContext t_context;
153
154 /*
155  * Values for CitContext.state
156  * 
157  * A session that is doing nothing is in CON_IDLE state.  When activity
158  * is detected on the socket, it goes to CON_READY, indicating that it
159  * needs to have a worker thread bound to it.  When a thread binds to
160  * the session, it goes to CON_EXECUTING and does its thing.  When the
161  * transaction is finished, the thread sets it back to CON_IDLE and lets
162  * it go.
163  */
164 enum {
165         CON_IDLE,               /* This context is doing nothing */
166         CON_READY,              /* This context needs attention */
167         CON_EXECUTING,          /* This context is bound to a thread */
168 };
169
170
171 #define CS_STEALTH      1       /* stealth mode */
172 #define CS_CHAT         2       /* chat mode */
173 #define CS_POSTING      4       /* Posting */
174
175 struct CitContext *MyContext(void);
176 #define CC MyContext()
177
178 extern struct CitContext *ContextList;
179 extern int ScheduledShutdown;
180 extern struct CitControl CitControl;
181
182
183 struct ExpressMessage {
184         struct ExpressMessage *next;
185         time_t timestamp;       /* When this message was sent */
186         unsigned flags;         /* Special instructions */
187         char sender[64];        /* Name of sending user */
188         char *text;             /* Message text (if applicable) */
189 };
190
191 #define EM_BROADCAST    1       /* Broadcast message */
192 #define EM_GO_AWAY      2       /* Server requests client log off */
193 #define EM_CHAT         4       /* Server requests client enter chat */
194
195 struct ChatLine {
196         struct ChatLine *next;
197         int chat_seq;
198         time_t chat_time;
199         char chat_text[SIZ];
200         char chat_username[USERNAME_SIZE];
201         char chat_room[ROOMNAMELEN];
202 };
203
204 /*
205  * Various things we need to lock and unlock
206  */
207 enum {
208         S_USERS,
209         S_ROOMS,
210         S_SESSION_TABLE,
211         S_FLOORTAB,
212         S_CHATQUEUE,
213         S_CONTROL,
214         S_NETDB,
215         S_SUPPMSGMAIN,
216         S_CONFIG,
217         S_WORKER_LIST,
218         S_HOUSEKEEPING,
219         S_NTTLIST,
220         S_DIRECTORY,
221         S_NETCONFIGS,
222         S_PUBLIC_CLIENTS,
223         S_LDAP,
224         S_FLOORCACHE,
225         S_DEBUGMEMLEAKS,
226         MAX_SEMAPHORES
227 };
228
229
230 /*
231  * Upload types
232  */
233 #define UPL_FILE        0
234 #define UPL_NET         1
235 #define UPL_IMAGE       2
236
237
238 /*
239  * message transfer formats
240  */
241 enum {
242         MT_CITADEL,             /* Citadel proprietary */
243         MT_RFC822,              /* RFC822 */
244         MT_MIME,                /* MIME-formatted message */
245         MT_DOWNLOAD             /* Download a component */
246 };
247
248 /*
249  * Message format types in the database
250  */
251 #define FMT_CITADEL     0       /* Citadel vari-format (proprietary) */
252 #define FMT_FIXED       1       /* Fixed format (proprietary)        */
253 #define FMT_RFC822      4       /* Standard (headers are in M field) */
254
255
256 /*
257  * Citadel DataBases (define one for each cdb we need to open)
258  */
259 enum {
260         CDB_MSGMAIN,            /* message base                  */
261         CDB_USERS,              /* user file                     */
262         CDB_ROOMS,              /* room index                    */
263         CDB_FLOORTAB,           /* floor index                   */
264         CDB_MSGLISTS,           /* room message lists            */
265         CDB_VISIT,              /* user/room relationships       */
266         CDB_DIRECTORY,          /* address book directory        */
267         CDB_USETABLE,           /* network use table             */
268         CDB_BIGMSGS,            /* larger message bodies         */
269         MAXCDB                  /* total number of CDB's defined */
270 };
271
272 struct cdbdata {
273         size_t len;
274         char *ptr;
275 };
276
277
278
279 /* Structures and declarations for function hooks of various types */
280
281 struct LogFunctionHook {
282         struct LogFunctionHook *next;
283         int loglevel;
284         void (*h_function_pointer) (char *);
285 };
286 extern struct LogFunctionHook *LogHookTable;
287
288 struct CleanupFunctionHook {
289         struct CleanupFunctionHook *next;
290         void (*h_function_pointer) (void);
291 };
292 extern struct CleanupFunctionHook *CleanupHookTable;
293
294
295
296
297 /*
298  * SessionFunctionHook extensions are used for any type of hook for which
299  * the context in which it's being called (which is determined by the event
300  * type) will make it obvious for the hook function to know where to look for
301  * pertinent data.
302  */
303 struct SessionFunctionHook {
304         struct SessionFunctionHook *next;
305         void (*h_function_pointer) (void);
306         int eventtype;
307 };
308 extern struct SessionFunctionHook *SessionHookTable;
309
310 /* 
311  * Event types can't be enum'ed, because they must remain consistent between
312  * builds (to allow for binary modules built somewhere else)
313  */
314 #define EVT_STOP        0       /* Session is terminating */
315 #define EVT_START       1       /* Session is starting */
316 #define EVT_LOGIN       2       /* A user is logging in */
317 #define EVT_NEWROOM     3       /* Changing rooms */
318 #define EVT_LOGOUT      4       /* A user is logging out */
319 #define EVT_SETPASS     5       /* Setting or changing password */
320 #define EVT_CMD         6       /* Called after each server command */
321 #define EVT_RWHO        7       /* An RWHO command is being executed */
322 #define EVT_ASYNC       8       /* Doing asynchronous messages */
323
324 #define EVT_TIMER       50      /* Timer events are called once per minute
325                                    and are not tied to any session */
326
327 /*
328  * UserFunctionHook extensions are used for any type of hook which implements
329  * an operation on a user or username (potentially) other than the one
330  * operating the current session.
331  */
332 struct UserFunctionHook {
333         struct UserFunctionHook *next;
334         void (*h_function_pointer) (struct ctdluser *usbuf);
335         int eventtype;
336 };
337 extern struct UserFunctionHook *UserHookTable;
338
339 #define EVT_PURGEUSER   100     /* Deleting a user */
340 #define EVT_NEWUSER     102     /* Creating a user */
341
342 /*
343  * MessageFunctionHook extensions are used for hooks which implement handlers
344  * for various types of message operations (save, read, etc.)
345  */
346 struct MessageFunctionHook {
347         struct MessageFunctionHook *next;
348         int (*h_function_pointer) (struct CtdlMessage *msg);
349         int eventtype;
350 };
351 extern struct MessageFunctionHook *MessageHookTable;
352
353 #define EVT_BEFOREREAD  200
354 #define EVT_BEFORESAVE  201
355 #define EVT_AFTERSAVE   202
356 #define EVT_SMTPSCAN    203     /* called before submitting a msg from SMTP */
357
358
359
360 /*
361  * NetprocFunctionHook extensions are used for hooks which implement handlers
362  * for incoming network messages.
363  */
364 struct NetprocFunctionHook {
365         struct NetprocFunctionHook *next;
366         int (*h_function_pointer) (struct CtdlMessage *msg, char *target_room);
367 };
368 extern struct NetprocFunctionHook *NetprocHookTable;
369
370
371 /*
372  * DeleteFunctionHook extensions are used for hooks which get called when a
373  * message is about to be deleted.
374  */
375 struct DeleteFunctionHook {
376         struct DeleteFunctionHook *next;
377         void (*h_function_pointer) (char *target_room, long msgnum);
378 };
379 extern struct DeleteFunctionHook *DeleteHookTable;
380
381
382 /*
383  * ExpressMessageFunctionHook extensions are used for hooks which implement
384  * the sending of an instant message through various channels.  Any function
385  * registered should return the number of recipients to whom the message was
386  * successfully transmitted.
387  */
388 struct XmsgFunctionHook {
389         struct XmsgFunctionHook *next;
390         int (*h_function_pointer) (char *, char *, char *);
391         int order;
392 };
393 extern struct XmsgFunctionHook *XmsgHookTable;
394
395 /* Priority levels for paging functions (lower is better) */
396 enum {
397         XMSG_PRI_LOCAL,         /* Other users on -this- server */
398         XMSG_PRI_REMOTE,        /* Other users on a Citadel network (future) */
399         XMSG_PRI_FOREIGN,       /* Contacts on foreign instant message hosts */
400         MAX_XMSG_PRI
401 };
402
403
404
405 /*
406  * ServiceFunctionHook extensions are used for hooks which implement various
407  * non-Citadel services (on TCP protocols) directly in the Citadel server.
408  */
409 struct ServiceFunctionHook {
410         struct ServiceFunctionHook *next;
411         int tcp_port;
412         char *sockpath;
413         void (*h_greeting_function) (void) ;
414         void (*h_command_function) (void) ;
415         void (*h_async_function) (void) ;
416         int msock;
417 };
418 extern struct ServiceFunctionHook *ServiceHookTable;
419
420
421
422 /* Defines the relationship of a user to a particular room */
423 struct visit {
424         long v_roomnum;
425         long v_roomgen;
426         long v_usernum;
427         long v_lastseen;
428         unsigned int v_flags;
429         char v_seen[SIZ];
430         char v_answered[SIZ];
431         int v_view;
432 };
433
434 #define V_FORGET        1       /* User has zapped this room        */
435 #define V_LOCKOUT       2       /* User is locked out of this room  */
436 #define V_ACCESS        4       /* Access is granted to this room   */
437
438
439 /* Supplementary data for a message on disk
440  * (These are kept separately from the message itself because they are
441  * fields whose values may change at some point after the message is saved.)
442  */
443 struct MetaData {
444         long meta_msgnum;       /* Message number in *local* message base */
445         int meta_refcount;      /* Number of rooms which point to this msg */
446         char meta_content_type[64];
447         /* more stuff will be added to this record in the future */
448 };
449
450
451 /* 
452  * Serialization routines use this struct to return a pointer and a length
453  */
454 struct ser_ret {
455         size_t len;
456         char *ser;
457 };
458
459
460 /* Preferred field order */
461 /*               **********                     Important fields */
462 /*                         ***************      Semi-important fields */
463 /*                                        *     Message text (MUST be last) */
464 #define FORDER  "IPTAFONHRDBCEGJKLQSVWXYZUM"
465
466 #endif /* SERVER_H */