CC->kill_me now contains an enum indicating the REASON session was killed
[citadel.git] / citadel / server.h
1
2
3 #ifndef SERVER_H
4 #define SERVER_H
5
6 #ifdef __GNUC__
7 #define INLINE __inline__
8 #else
9 #define INLINE
10 #endif
11
12 #include "citadel.h"
13 #ifdef HAVE_OPENSSL
14 #define OPENSSL_NO_KRB5         /* work around redhat b0rken ssl headers */
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 #define CTDLEXIT_SHUTDOWN       0       /* Normal shutdown; do NOT auto-restart */
35
36 /*
37  * Exit codes 101 through 109 are used for conditions in which
38  * we deliberately do NOT want the service to automatically
39  * restart.
40  */
41 #define CTDLEXIT_CONFIG         101     /* Could not read citadel.config */
42 #define CTDLEXIT_CONTROL        102     /* Could not acquire lock */
43 #define CTDLEXIT_HOME           103     /* Citadel home directory not found */
44 #define CTDLEXIT_OOD            104     /* Out Of Date config - rerun setup */
45 #define CTDLEXIT_DB             105     /* Unable to initialize database */
46 #define CTDLEXIT_LIBCITADEL     106     /* Incorrect version of libcitadel */
47 #define CTDL_EXIT_UNSUP_AUTH    107     /* Unsupported auth mode configured */
48
49 /*
50  * Reasons why a session would be terminated (set CC->kill_me to these values)
51  */
52 enum {
53         KILLME_NOT,
54         KILLME_UNKNOWN,
55         KILLME_CLIENT_LOGGED_OUT,
56         KILLME_IDLE,
57         KILLME_CLIENT_DISCONNECTED,
58         KILLME_AUTHFAILED,
59         KILLME_SERVER_SHUTTING_DOWN,
60         KILLME_MAX_SESSIONS_EXCEEDED,
61         KILLME_ADMIN_TERMINATE,
62         KILLME_SELECT_INTERRUPTED,
63         KILLME_SELECT_FAILED,
64         KILLME_WRITE_FAILED,
65         KILLME_SIMULATION_WORKER,
66         KILLME_NOLOGIN,
67         KILLME_NO_CRYPTO,
68         KILLME_READSTRING_FAILED,
69         KILLME_MALLOC_FAILED,
70         KILLME_QUOTA,
71         KILLME_READ_FAILED,
72         KILLME_ILLEGAL_MANAGESIEVE_COMMAND,
73         KILLME_SPAMMER,
74         KILLME_XML_PARSER
75 };
76
77
78 #define CS_STEALTH      1       /* stealth mode */
79 #define CS_CHAT         2       /* chat mode */
80 #define CS_POSTING      4       /* Posting */
81
82
83 /*
84  * This is the control record for the message base... 
85  */
86 struct CitControl {
87         long MMhighest;                 /* highest message number in file   */
88         unsigned MMflags;               /* Global system flags              */
89         long MMnextuser;                /* highest user number on system    */
90         long MMnextroom;                /* highest room number on system    */
91         int version;                    /* Server-hosted upgrade level      */
92         int fulltext_wordbreaker;       /* ID of wordbreaker in use         */
93         long MMfulltext;                /* highest message number indexed   */
94         int MMdbversion;                /* Version of Berkeley DB used on previous server run */
95 };
96
97 extern int ScheduledShutdown;
98 extern struct CitControl CitControl;
99
100 struct ExpressMessage {
101         struct ExpressMessage *next;
102         time_t timestamp;       /* When this message was sent */
103         unsigned flags;         /* Special instructions */
104         char sender[256];       /* Name of sending user */
105         char sender_email[256]; /* Email or JID of sending user */
106         char *text;             /* Message text (if applicable) */
107 };
108
109 #define EM_BROADCAST    1       /* Broadcast message */
110 #define EM_GO_AWAY      2       /* Server requests client log off */
111 #define EM_CHAT         4       /* Server requests client enter chat */
112
113 /*
114  * Various things we need to lock and unlock
115  */
116 enum {
117         S_USERS,
118         S_ROOMS,
119         S_SESSION_TABLE,
120         S_FLOORTAB,
121         S_CHATQUEUE,
122         S_CONTROL,
123         S_NETDB,
124         S_SUPPMSGMAIN,
125         S_CONFIG,
126         S_HOUSEKEEPING,
127         S_NTTLIST,
128         S_DIRECTORY,
129         S_NETCONFIGS,
130         S_PUBLIC_CLIENTS,
131         S_FLOORCACHE,
132         S_DEBUGMEMLEAKS,
133         S_ATBF,
134         S_JOURNAL_QUEUE,
135         S_RPLIST,
136         S_SIEVELIST,
137         S_CHKPWD,
138         S_LOG,
139         S_NETSPOOL,
140         S_THREAD_LIST,
141         S_XMPP_QUEUE,
142         S_SCHEDULE_LIST,
143         S_SINGLE_USER,
144         S_LDAP,
145         S_IM_LOGS,
146         MAX_SEMAPHORES
147 };
148
149
150 /*
151  * Upload types
152  */
153 #define UPL_FILE        0
154 #define UPL_NET         1
155 #define UPL_IMAGE       2
156
157
158 /*
159  * message transfer formats
160  */
161 enum {
162         MT_CITADEL,             /* Citadel proprietary */
163         MT_RFC822,              /* RFC822 */
164         MT_MIME,                /* MIME-formatted message */
165         MT_DOWNLOAD,            /* Download a component */
166         MT_SPEW_SECTION         /* Download a component in a single operation */
167 };
168
169 /*
170  * Message format types in the database
171  */
172 #define FMT_CITADEL     0       /* Citadel vari-format (proprietary) */
173 #define FMT_FIXED       1       /* Fixed format (proprietary)        */
174 #define FMT_RFC822      4       /* Standard (headers are in M field) */
175
176
177 /*
178  * Citadel DataBases (define one for each cdb we need to open)
179  */
180 enum {
181         CDB_MSGMAIN,            /* message base                  */
182         CDB_USERS,              /* user file                     */
183         CDB_ROOMS,              /* room index                    */
184         CDB_FLOORTAB,           /* floor index                   */
185         CDB_MSGLISTS,           /* room message lists            */
186         CDB_VISIT,              /* user/room relationships       */
187         CDB_DIRECTORY,          /* address book directory        */
188         CDB_USETABLE,           /* network use table             */
189         CDB_BIGMSGS,            /* larger message bodies         */
190         CDB_FULLTEXT,           /* full text search index        */
191         CDB_EUIDINDEX,          /* locate msgs by EUID           */
192         CDB_USERSBYNUMBER,      /* index of users by number      */
193         CDB_OPENID,             /* associates OpenIDs with users */
194         MAXCDB                  /* total number of CDB's defined */
195 };
196
197 struct cdbdata {
198         size_t len;
199         char *ptr;
200 };
201
202
203 /* 
204  * Event types can't be enum'ed, because they must remain consistent between
205  * builds (to allow for binary modules built somewhere else)
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 #define EVT_CMD         6       /* Called after each server command */
214 #define EVT_RWHO        7       /* An RWHO command is being executed */
215 #define EVT_ASYNC       8       /* Doing asynchronous messages */
216 #define EVT_STEALTH     9       /* Entering stealth mode */
217 #define EVT_UNSTEALTH   10      /* Exiting stealth mode */
218
219 #define EVT_TIMER       50      /* Timer events are called once per minute
220                                    and are not tied to any session */
221 #define EVT_HOUSE       51      /* as needed houskeeping stuff */
222 #define EVT_SHUTDOWN    52      /* Server is shutting down */
223
224 #define EVT_PURGEUSER   100     /* Deleting a user */
225 #define EVT_NEWUSER     102     /* Creating a user */
226
227 #define EVT_BEFOREREAD  200
228 #define EVT_BEFORESAVE  201
229 #define EVT_AFTERSAVE   202
230 #define EVT_SMTPSCAN    203     /* called before submitting a msg from SMTP */
231 /* Priority levels for paging functions (lower is better) */
232 enum {
233         XMSG_PRI_LOCAL,         /* Other users on -this- server */
234         XMSG_PRI_REMOTE,        /* Other users on a Citadel network (future) */
235         XMSG_PRI_FOREIGN,       /* Contacts on foreign instant message hosts */
236         MAX_XMSG_PRI
237 };
238
239
240 /* Defines the relationship of a user to a particular room */
241 typedef struct __visit {
242         long v_roomnum;
243         long v_roomgen;
244         long v_usernum;
245         long v_lastseen;
246         unsigned int v_flags;
247         char v_seen[SIZ];
248         char v_answered[SIZ];
249         int v_view;
250 } visit;
251
252 #define V_FORGET        1       /* User has zapped this room        */
253 #define V_LOCKOUT       2       /* User is locked out of this room  */
254 #define V_ACCESS        4       /* Access is granted to this room   */
255
256
257 /* Supplementary data for a message on disk
258  * These are kept separate from the message itself for one of two reasons:
259  * 1. Either their values may change at some point after initial save, or
260  * 2. They are merely caches of data which exist somewhere else, for speed.
261  */
262 struct MetaData {
263         long meta_msgnum;               /* Message number in *local* message base */
264         int meta_refcount;              /* Number of rooms pointing to this msg */
265         char meta_content_type[64];     /* Cached MIME content-type */
266         long meta_rfc822_length;        /* Cache of RFC822-translated msg length */
267         char mimetype[64];              /* if we were able to guess the mimetype for the data */ 
268 };
269
270 /* Calls to AdjRefCount() are queued and deferred, so the user doesn't
271  * have to wait for various disk-intensive operations to complete synchronously.
272  * This is the record format.
273  */
274 struct arcq {
275         long arcq_msgnum;               /* Message number being adjusted */
276         int arcq_delta;                 /* Adjustment ( usually 1 or -1 ) */
277 };
278
279
280 /* 
281  * Serialization routines use this struct to return a pointer and a length
282  */
283 struct ser_ret {
284         size_t len;
285         unsigned char *ser;
286 };
287
288
289 /*
290  * The S_USETABLE database is used in several modules now, so we define its format here.
291  */
292 struct UseTable {
293         char ut_msgid[SIZ];
294         time_t ut_timestamp;
295 };
296
297
298
299 /* Preferred field order                                                        */
300 /*               **********                     Important fields                */
301 /*                         ***************      Semi-important fields           */
302 /*                                        *     Message text (MUST be last)     */
303 #define FORDER  "IPTAFONHRDBCEWJGKLQSVXZYUM"
304
305 #endif /* SERVER_H */