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