1 // Data types for the Citadel Server
3 // Copyright (c) 1987-2023 by the citadel.org team
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.
12 #define INLINE __inline__
17 #include "citadel_defs.h"
19 #define OPENSSL_NO_KRB5 // work around redhat b0rken ssl headers
20 #include <openssl/ssl.h>
23 // New format for a message in memory
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)
34 // Data structure returned by validate_recipients()
52 #define RECPTYPES_MAGIC 0xfeeb
54 #define CTDLEXIT_SHUTDOWN 0 // Normal shutdown; do NOT auto-restart
56 // Exit codes 101 through 109 are used for conditions in which
57 // we deliberately do NOT want the service to automatically
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
67 // Any other exit is likely to be from an unexpected abort (segfault etc)
68 // and we want to try restarting.
72 // Reasons why a session would be terminated (set CC->kill_me to these values)
76 KILLME_CLIENT_LOGGED_OUT,
78 KILLME_CLIENT_DISCONNECTED,
80 KILLME_SERVER_SHUTTING_DOWN,
81 KILLME_MAX_SESSIONS_EXCEEDED,
82 KILLME_ADMIN_TERMINATE,
83 KILLME_SELECT_INTERRUPTED,
86 KILLME_SIMULATION_WORKER,
89 KILLME_READSTRING_FAILED,
98 #define CS_STEALTH 1 // stealth mode
99 #define CS_CHAT 2 // chat mode
100 #define CS_POSTING 4 // posting
102 extern int ScheduledShutdown;
103 extern uid_t ctdluid;
104 extern int sanity_diag_mode;
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)
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
119 // Various things we need to lock and unlock
144 // message transfer formats
146 MT_CITADEL, // Citadel proprietary
148 MT_MIME, // MIME-formatted message
149 MT_DOWNLOAD, // Download a component
150 MT_SPEW_SECTION // Download a component in a single operation
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)
159 // citadel database tables (define one for each cdb we need to open)
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
184 // Event types for hooks
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
204 EVT_SMTPSCAN, // called before submitting a msg from SMTP
205 EVT_AFTERUSRMBOXSAVE // called afte a message was saved into a users inbox
209 /* Priority levels for paging functions (lower is better) */
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
218 // Defines the relationship of a user to a particular room
219 typedef struct __visit {
224 unsigned int v_flags;
226 char v_answered[SIZ];
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
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
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
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.
252 long arcq_msgnum; // Message number being adjusted
253 int arcq_delta; // Adjustment ( usually 1 or -1 )
257 // Serialization routines use this struct to return a pointer and a length
264 // The S_USETABLE database is used in several modules now, so we define its format here.
271 // These one-byte field headers are found in the Citadel message store.
272 typedef enum _MsgField {
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
319 // Message expiration policy stuff
320 typedef struct ExpirePolicy ExpirePolicy;
321 struct ExpirePolicy {
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
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
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.
356 // Floor record. The floor number is implicit in its location in the file.
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