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