]> code.citadel.org Git - citadel.git/blob - citadel/server/server.h
move stuff around
[citadel.git] / citadel / server / server.h
1 // Data types for the Citadel Server
2 //
3 // Copyright (c) 1987-2023 by the citadel.org team
4 //
5 // This program is open source software.  Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
7
8 #ifndef SERVER_H
9 #define SERVER_H
10
11 #ifdef __GNUC__
12 #define INLINE __inline__
13 #else
14 #define INLINE
15 #endif
16
17 #include "citadel_defs.h"
18 #ifdef HAVE_OPENSSL
19 #define OPENSSL_NO_KRB5                 // work around redhat b0rken ssl headers
20 #include <openssl/ssl.h>
21 #endif
22
23 // New format for a message in memory
24 struct CtdlMessage {
25         int cm_magic;                   // Self-check (NOT SAVED TO DISK)
26         char cm_anon_type;              // Anonymous or author-visible
27         char cm_format_type;            // Format type
28         char *cm_fields[256];           // Data fields
29         long cm_lengths[256];           // size of datafields
30         unsigned int cm_flags;          // How to handle (NOT SAVED TO DISK)
31 };
32
33
34 // Data structure returned by validate_recipients()
35 struct recptypes {
36         int recptypes_magic;
37         int num_local;
38         int num_internet;
39         int num_room;
40         int num_error;
41         char *errormsg;
42         char *recp_local;
43         char *recp_internet;
44         char *recp_room;
45         char *recp_orgroom;
46         char *display_recp;
47         char *bounce_to;
48         char *envelope_from;
49         char *sending_room;
50 };
51
52 #define RECPTYPES_MAGIC 0xfeeb
53
54 #define CTDLEXIT_SHUTDOWN       0       // Normal shutdown; do NOT auto-restart
55
56 // Exit codes 101 through 109 are used for conditions in which
57 // we deliberately do NOT want the service to automatically
58 // restart.
59 #define CTDLEXIT_CONFIG         101     // Could not read system configuration
60 #define CTDLEXIT_HOME           103     // Citadel home directory not found
61 #define CTDLEXIT_DB             105     // Unable to initialize database
62 #define CTDLEXIT_LIBCITADEL     106     // Incorrect version of libcitadel
63 #define CTDL_EXIT_UNSUP_AUTH    107     // Unsupported auth mode configured
64 #define CTDLEXIT_UNUSER         108     // Could not determine uid to run as
65 #define CTDLEXIT_CRYPTO         109     // Problem initializing SSL or TLS
66
67 // Any other exit is likely to be from an unexpected abort (segfault etc)
68 // and we want to try restarting.
69
70
71
72 // Reasons why a session would be terminated (set CC->kill_me to these values)
73 enum {
74         KILLME_NOT,
75         KILLME_UNKNOWN,
76         KILLME_CLIENT_LOGGED_OUT,
77         KILLME_IDLE,
78         KILLME_CLIENT_DISCONNECTED,
79         KILLME_AUTHFAILED,
80         KILLME_SERVER_SHUTTING_DOWN,
81         KILLME_MAX_SESSIONS_EXCEEDED,
82         KILLME_ADMIN_TERMINATE,
83         KILLME_SELECT_INTERRUPTED,
84         KILLME_SELECT_FAILED,
85         KILLME_WRITE_FAILED,
86         KILLME_SIMULATION_WORKER,
87         KILLME_NOLOGIN,
88         KILLME_NO_CRYPTO,
89         KILLME_READSTRING_FAILED,
90         KILLME_MALLOC_FAILED,
91         KILLME_QUOTA,
92         KILLME_READ_FAILED,
93         KILLME_SPAMMER,
94         KILLME_XML_PARSER
95 };
96
97
98 #define CS_STEALTH      1       // stealth mode
99 #define CS_CHAT         2       // chat mode
100 #define CS_POSTING      4       // posting
101
102 extern int ScheduledShutdown;
103 extern uid_t ctdluid;
104 extern int sanity_diag_mode;
105
106 struct ExpressMessage {
107         struct ExpressMessage *next;
108         time_t timestamp;       // When this message was sent
109         unsigned flags;         // Special instructions
110         char sender[256];       // Name of sending user
111         char sender_email[256]; // Email or JID of sending user
112         char *text;             // Message text (if applicable)
113 };
114
115 #define EM_BROADCAST    1       // Broadcast message
116 #define EM_GO_AWAY      2       // Server requests client log off
117 #define EM_CHAT         4       // Server requests client enter chat
118
119 // Various things we need to lock and unlock
120 enum {
121         S_USERS,
122         S_ROOMS,
123         S_SESSION_TABLE,
124         S_FLOORTAB,
125         S_CHATQUEUE,
126         S_CONTROL,
127         S_SUPPMSGMAIN,
128         S_CONFIG,
129         S_HOUSEKEEPING,
130         S_NETCONFIGS,
131         S_FLOORCACHE,
132         S_ATBF,
133         S_JOURNAL_QUEUE,
134         S_CHKPWD,
135         S_XMPP_QUEUE,
136         S_SINGLE_USER,
137         S_IM_LOGS,
138         S_OPENSSL,
139         S_SMTPQUEUE,
140         MAX_SEMAPHORES
141 };
142
143
144 // message transfer formats
145 enum {
146         MT_CITADEL,             // Citadel proprietary
147         MT_RFC822,              // RFC822
148         MT_MIME,                // MIME-formatted message
149         MT_DOWNLOAD,            // Download a component
150         MT_SPEW_SECTION         // Download a component in a single operation
151 };
152
153 // Message format types in the database
154 #define FMT_CITADEL     0       // Citadel vari-format (proprietary)
155 #define FMT_FIXED       1       // Fixed format (proprietary)
156 #define FMT_RFC822      4       // Standard (headers are in M field)
157
158
159 // citadel database tables (define one for each cdb we need to open)
160 enum {
161         CDB_MSGMAIN,            // message base
162         CDB_USERS,              // user file
163         CDB_ROOMS,              // room index
164         CDB_FLOORTAB,           // floor index
165         CDB_MSGLISTS,           // room message lists
166         CDB_VISIT,              // user/room relationships
167         CDB_DIRECTORY,          // address book directory
168         CDB_USETABLE,           // network use table
169         CDB_BIGMSGS,            // larger message bodies
170         CDB_FULLTEXT,           // full text search index
171         CDB_EUIDINDEX,          // locate msgs by EUID
172         CDB_USERSBYNUMBER,      // index of users by number
173         CDB_EXTAUTH,            // associates OpenIDs with users
174         CDB_CONFIG,             // system configuration database
175         MAXCDB                  // total number of CDB's defined
176 };
177
178 struct cdbdata {
179         size_t len;
180         char *ptr;
181 };
182
183
184 // Event types for hooks
185 enum {
186         EVT_STOP,               // Session is terminating
187         EVT_START,              // Session is starting
188         EVT_LOGIN,              // A user is logging in
189         EVT_NEWROOM,            // Changing rooms
190         EVT_LOGOUT,             // A user is logging out
191         EVT_SETPASS,            // Setting or changing password
192         EVT_CMD,                // Called after each server command
193         EVT_RWHO,               // An RWHO command is being executed
194         EVT_ASYNC,              // Doing asynchronous messages
195         EVT_STEALTH,            // Entering stealth mode
196         EVT_UNSTEALTH,          // Exiting stealth mode
197         EVT_TIMER,              // Timer events are called once per minute and are not tied to any session
198         EVT_HOUSE,              // as needed houskeeping stuff
199         EVT_SHUTDOWN,           // Server is shutting down
200         EVT_PURGEUSER,          // Deleting a user
201         EVT_NEWUSER,            // Creating a user
202         EVT_BEFORESAVE,
203         EVT_AFTERSAVE,
204         EVT_SMTPSCAN,           // called before submitting a msg from SMTP
205         EVT_AFTERUSRMBOXSAVE    // called afte a message was saved into a users inbox
206 };
207
208
209 /* Priority levels for paging functions (lower is better) */
210 enum {
211         XMSG_PRI_LOCAL,         // Other users on -this- server
212         XMSG_PRI_REMOTE,        // Other users on a Citadel network
213         XMSG_PRI_FOREIGN,       // Contacts on foreign instant message hosts
214         MAX_XMSG_PRI
215 };
216
217
218 // Defines the relationship of a user to a particular room
219 typedef struct __visit {
220         long v_roomnum;
221         long v_roomgen;
222         long v_usernum;
223         long v_lastseen;
224         unsigned int v_flags;
225         char v_seen[SIZ];
226         char v_answered[SIZ];
227         int v_view;
228 } visit;
229
230 #define V_FORGET        1       // User has zapped this room
231 #define V_LOCKOUT       2       // User is locked out of this room
232 #define V_ACCESS        4       // Access is granted to this room
233
234
235 // Supplementary data for a message on disk
236 // These are kept separate from the message itself for one of two reasons:
237 // 1. Either their values may change at some point after initial save, or
238 // 2. They are merely caches of data which exist somewhere else, for speed.
239 // DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w
240 struct MetaData {
241         long meta_msgnum;               // Message number in *local* message base
242         int meta_refcount;              // Number of rooms pointing to this msg
243         char meta_content_type[64];     // Cached MIME content-type
244         long meta_rfc822_length;        // Cache of RFC822-translated msg length
245 };
246
247
248 // Calls to AdjRefCount() are queued and deferred, so the user doesn't
249 // have to wait for various disk-intensive operations to complete synchronously.
250 // This is the record format.
251 struct arcq {
252         long arcq_msgnum;               // Message number being adjusted
253         int arcq_delta;                 // Adjustment ( usually 1 or -1 )
254 };
255
256
257 // Serialization routines use this struct to return a pointer and a length
258 struct ser_ret {
259         size_t len;
260         unsigned char *ser;
261 };
262
263
264 // The S_USETABLE database is used in several modules now, so we define its format here.
265 struct UseTable {
266         char ut_msgid[SIZ];
267         time_t ut_timestamp;
268 };
269
270
271 // These one-byte field headers are found in the Citadel message store.
272 typedef enum _MsgField {
273         eAuthor       = 'A',
274         eBig_message  = 'B',
275         eExclusiveID  = 'E',
276         erFc822Addr   = 'F',
277         emessageId    = 'I',
278         eJournal      = 'J',
279         eReplyTo      = 'K',
280         eListID       = 'L',
281         eMesageText   = 'M',
282         eOriginalRoom = 'O',
283         eMessagePath  = 'P',
284         eRecipient    = 'R',
285         eTimestamp    = 'T',
286         eMsgSubject   = 'U',
287         eenVelopeTo   = 'V',
288         eWeferences   = 'W',
289         eCarbonCopY   = 'Y',
290         eErrorMsg     = '0',
291         eSuppressIdx  = '1',
292         eExtnotify    = '2',
293         eVltMsgNum    = '3'
294 } eMsgField;
295
296
297 // User records.
298 typedef struct ctdluser ctdluser;
299 struct ctdluser {                       // User record
300         int version;                    // Citadel version which created this record
301         uid_t uid;                      // Associate with a unix account?
302         char password[32];              // password
303         unsigned flags;                 // See US_ flags below
304         long timescalled;               // Total number of logins
305         long posted;                    // Number of messages ever submitted
306         cit_uint8_t axlevel;            // Access level
307         long usernum;                   // User number (never recycled)
308         time_t lastcall;                // Date/time of most recent login
309         int USuserpurge;                // Purge time (in days) for user
310         char fullname[64];              // Display name (primary identifier)
311         long msgnum_bio;                // msgnum of user's profile (bio)
312         long msgnum_pic;                // msgnum of user's avatar (photo)
313         char emailaddrs[512];           // Internet email addresses
314         long msgnum_inboxrules;         // msgnum of user's inbox filtering rules
315         long lastproc_inboxrules;       // msgnum of last message filtered
316 };
317
318
319 // Message expiration policy stuff
320 typedef struct ExpirePolicy ExpirePolicy;
321 struct ExpirePolicy {
322         int expire_mode;
323         int expire_value;
324 };
325
326 #define EXPIRE_NEXTLEVEL        0       // Inherit expiration policy
327 #define EXPIRE_MANUAL           1       // Don't expire messages at all
328 #define EXPIRE_NUMMSGS          2       // Keep only latest n messages
329 #define EXPIRE_AGE              3       // Expire messages after n days
330
331 // Room records.
332 struct ctdlroom {
333         char QRname[ROOMNAMELEN];       // Name of room
334         char QRpasswd[10];              // Only valid if it's a private rm
335         long QRroomaide;                // User number of room aide
336         long QRhighest;                 // Highest message NUMBER in room
337         time_t QRgen;                   // Generation number of room
338         unsigned QRflags;               // See flag values below
339         char QRdirname[15];             // Directory name, if applicable
340         long msgnum_info;               // msgnum of room banner (info file)
341         char QRfloor;                   // Which floor this room is on
342         time_t QRmtime;                 // Date/time of last post
343         struct ExpirePolicy QRep;       // Message expiration policy
344         long QRnumber;                  // Globally unique room number
345         char QRorder;                   // Sort key for room listing order
346         unsigned QRflags2;              // Additional flags
347         int QRdefaultview;              // How to display the contents
348         long msgnum_pic;                // msgnum of room picture or icon
349 };
350
351 // Private rooms are always flagged with QR_PRIVATE.  If neither QR_PASSWORDED
352 // or QR_GUESSNAME is set, then it is invitation-only.  Passworded rooms are
353 // flagged with both QR_PRIVATE and QR_PASSWORDED while guess-name rooms are
354 // flagged with both QR_PRIVATE and QR_GUESSNAME.  NEVER set all three flags.
355
356 // Floor record.  The floor number is implicit in its location in the file.
357 struct floor {
358         unsigned short f_flags;         // flags
359         char f_name[256];               // name of floor
360         int f_ref_count;                // reference count
361         struct ExpirePolicy f_ep;       // default expiration policy
362 };
363
364
365
366 #endif // SERVER_H