1 // Main declarations file 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__
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)
33 #define CTDLMESSAGE_MAGIC 0x159d
34 #define CM_SKIP_HOOKS 0x01 // Don't run server-side handlers
37 // Data structure returned by validate_recipients()
55 #define RECPTYPES_MAGIC 0xfeeb
57 #define CTDLEXIT_SHUTDOWN 0 // Normal shutdown; do NOT auto-restart
59 // Exit codes 101 through 109 are used for conditions in which
60 // we deliberately do NOT want the service to automatically
62 #define CTDLEXIT_CONFIG 101 // Could not read system configuration
63 #define CTDLEXIT_HOME 103 // Citadel home directory not found
64 #define CTDLEXIT_DB 105 // Unable to initialize database
65 #define CTDLEXIT_LIBCITADEL 106 // Incorrect version of libcitadel
66 #define CTDL_EXIT_UNSUP_AUTH 107 // Unsupported auth mode configured
67 #define CTDLEXIT_UNUSER 108 // Could not determine uid to run as
68 #define CTDLEXIT_CRYPTO 109 // Problem initializing SSL or TLS
70 // Reasons why a session would be terminated (set CC->kill_me to these values)
74 KILLME_CLIENT_LOGGED_OUT,
76 KILLME_CLIENT_DISCONNECTED,
78 KILLME_SERVER_SHUTTING_DOWN,
79 KILLME_MAX_SESSIONS_EXCEEDED,
80 KILLME_ADMIN_TERMINATE,
81 KILLME_SELECT_INTERRUPTED,
84 KILLME_SIMULATION_WORKER,
87 KILLME_READSTRING_FAILED,
96 #define CS_STEALTH 1 // stealth mode
97 #define CS_CHAT 2 // chat mode
98 #define CS_POSTING 4 // posting
100 extern int ScheduledShutdown;
101 extern uid_t ctdluid;
102 extern int sanity_diag_mode;
104 struct ExpressMessage {
105 struct ExpressMessage *next;
106 time_t timestamp; // When this message was sent
107 unsigned flags; // Special instructions
108 char sender[256]; // Name of sending user
109 char sender_email[256]; // Email or JID of sending user
110 char *text; // Message text (if applicable)
113 #define EM_BROADCAST 1 // Broadcast message
114 #define EM_GO_AWAY 2 // Server requests client log off
115 #define EM_CHAT 4 // Server requests client enter chat
117 // Various things we need to lock and unlock
142 // message transfer formats
144 MT_CITADEL, // Citadel proprietary
146 MT_MIME, // MIME-formatted message
147 MT_DOWNLOAD, // Download a component
148 MT_SPEW_SECTION // Download a component in a single operation
151 // Message format types in the database
152 #define FMT_CITADEL 0 // Citadel vari-format (proprietary)
153 #define FMT_FIXED 1 // Fixed format (proprietary)
154 #define FMT_RFC822 4 // Standard (headers are in M field)
157 // citadel database tables (define one for each cdb we need to open)
159 CDB_MSGMAIN, // message base
160 CDB_USERS, // user file
161 CDB_ROOMS, // room index
162 CDB_FLOORTAB, // floor index
163 CDB_MSGLISTS, // room message lists
164 CDB_VISIT, // user/room relationships
165 CDB_DIRECTORY, // address book directory
166 CDB_USETABLE, // network use table
167 CDB_BIGMSGS, // larger message bodies
168 CDB_FULLTEXT, // full text search index
169 CDB_EUIDINDEX, // locate msgs by EUID
170 CDB_USERSBYNUMBER, // index of users by number
171 CDB_EXTAUTH, // associates OpenIDs with users
172 CDB_CONFIG, // system configuration database
173 MAXCDB // total number of CDB's defined
182 // Event types for hooks
184 EVT_STOP , // Session is terminating
185 EVT_START , // Session is starting
186 EVT_LOGIN , // A user is logging in
187 EVT_NEWROOM , // Changing rooms
188 EVT_LOGOUT , // A user is logging out
189 EVT_SETPASS , // Setting or changing password
190 EVT_CMD , // Called after each server command
191 EVT_RWHO , // An RWHO command is being executed
192 EVT_ASYNC , // Doing asynchronous messages
193 EVT_STEALTH , // Entering stealth mode
194 EVT_UNSTEALTH , // Exiting stealth mode
195 EVT_TIMER , // Timer events are called once per minute and are not tied to any session
196 EVT_HOUSE , // as needed houskeeping stuff
197 EVT_SHUTDOWN , // Server is shutting down
198 EVT_PURGEUSER , // Deleting a user
199 EVT_NEWUSER , // Creating a user
202 EVT_SMTPSCAN , // called before submitting a msg from SMTP
203 EVT_AFTERUSRMBOXSAVE // called afte a message was saved into a users inbox
207 /* Priority levels for paging functions (lower is better) */
209 XMSG_PRI_LOCAL, /* Other users on -this- server */
210 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
211 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
216 // Defines the relationship of a user to a particular room
217 typedef struct __visit {
222 unsigned int v_flags;
224 char v_answered[SIZ];
228 #define V_FORGET 1 // User has zapped this room
229 #define V_LOCKOUT 2 // User is locked out of this room
230 #define V_ACCESS 4 // Access is granted to this room
233 /* Supplementary data for a message on disk
234 * These are kept separate from the message itself for one of two reasons:
235 * 1. Either their values may change at some point after initial save, or
236 * 2. They are merely caches of data which exist somewhere else, for speed.
237 * DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w
240 long meta_msgnum; /* Message number in *local* message base */
241 int meta_refcount; /* Number of rooms pointing to this msg */
242 char meta_content_type[64]; /* Cached MIME content-type */
243 long meta_rfc822_length; /* Cache of RFC822-translated msg length */
247 // Calls to AdjRefCount() are queued and deferred, so the user doesn't
248 // have to wait for various disk-intensive operations to complete synchronously.
249 // This is the record format.
251 long arcq_msgnum; // Message number being adjusted
252 int arcq_delta; // Adjustment ( usually 1 or -1 )
256 // Serialization routines use this struct to return a pointer and a length
263 // The S_USETABLE database is used in several modules now, so we define its format here.
270 // These one-byte field headers are found in the Citadel message store.
271 typedef enum _MsgField {