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