Release version 997 generated by do-release.sh
[citadel.git] / citadel / server / citadel_defs.h
1 // Preprocessor definitions 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 // The program is distributed without any warranty, expressed or implied.
8
9 #ifndef CITADEL_DEFS_H
10 #define CITADEL_DEFS_H
11
12 // Suppress these compiler warnings
13 #pragma GCC diagnostic ignored "-Wcast-qual"
14 #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"         // this doesn't work on FreeBSD
15 #pragma GCC diagnostic ignored "-Wformat-truncation"            // nor does this
16 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
17
18 #include "sysdep.h"
19 #include <limits.h>
20 #include "sysconfig.h"
21 #include "typesize.h"
22 #include "ipcdef.h"
23
24 #define REV_LEVEL 997           // This version
25 #define REV_MIN         591     // Oldest compatible database
26 #define EXPORT_REV_MIN  931     // Oldest compatible export files
27 #define LIBCITADEL_MIN  951     // Minimum required version of libcitadel
28 #define SERVER_TYPE     0       // zero for stock Citadel; other developers please obtain SERVER_TYPE codes for your implementations
29
30 #define TRACE   syslog(LOG_DEBUG, "\033[7m  Checkpoint: %p : %s : %d  \033[0m", CC, __FILE__, __LINE__)
31
32 #ifndef LONG_MAX
33 #define LONG_MAX 2147483647L
34 #endif
35
36 // hat tip to https://stackoverflow.com/questions/5459868/concatenate-int-to-string-using-c-preprocessor
37 #define STR_HELPER(x) #x
38 #define STR(x) STR_HELPER(x)
39 #define CITADEL "Citadel Server " STR(REV_LEVEL)
40
41 #ifdef LIBCITADEL_VERSION_NUMBER
42 #if LIBCITADEL_VERSION_NUMBER < LIBCITADEL_MIN
43 #error libcitadel is too old.  Please upgrade it before continuing.
44 #endif
45 #endif
46
47 // This is the user name and password for the default administrator account
48 // that is created when Citadel Server is started with an empty database.
49 #define DEFAULT_ADMIN_USERNAME  "admin"
50 #define DEFAULT_ADMIN_PASSWORD  "citadel"
51
52 // Various length constants
53 #define ROOMNAMELEN     128             // The size of a roomname string
54 #define USERNAME_SIZE   64              // The size of a username string
55
56 // Bits which may appear in MMflags.
57 #define MM_VALID        4               // New users need validating
58
59 // Miscellaneous
60 #define MES_NORMAL      65              // Normal message
61 #define MES_ANONONLY    66              // "****" header
62 #define MES_ANONOPT     67              // "Anonymous" header
63
64 // Values used internally for function call returns, etc.
65 #define NEWREGISTER     0               // new user to register
66 #define REREGISTER      1               // existing user reregistering
67
68 // number of items which may be handled by the CONF command
69 #define NUM_CONFIGS 71
70
71 // Authentication modes
72 #define AUTHMODE_NATIVE         0       // Native (self-contained or "black box")
73 #define AUTHMODE_HOST           1       // Authenticate against the host OS user database
74 #define AUTHMODE_LDAP           2       // Authenticate using LDAP server with POSIX schema
75 #define AUTHMODE_LDAP_AD        3       // Authenticate using LDAP server with Active Directory schema
76
77 // Found in struct CtdlMessage
78 #define CTDLMESSAGE_MAGIC       0x159d
79 #define CM_SKIP_HOOKS           0x01    // Don't run server-side handlers
80
81 // Floors
82 #define F_INUSE                 1       // floor is in use
83
84 // Found in struct expirepolicy
85 #define EXPIRE_NEXTLEVEL        0       // Inherit expiration policy
86 #define EXPIRE_MANUAL           1       // Don't expire messages at all
87 #define EXPIRE_NUMMSGS          2       // Keep only latest n messages
88 #define EXPIRE_AGE              3       // Expire messages after n days
89
90 #define RECPTYPES_MAGIC         0xfeeb
91
92 #define CTDLEXIT_SHUTDOWN       0       // Normal shutdown; do NOT auto-restart
93
94 // Exit codes 101-109  are used for conditions in which we
95 // deliberately do NOT want the service to automatically restart.
96 #define CTDLEXIT_CONFIG         101     // Could not read system configuration
97 #define CTDLEXIT_SANITY         102     // Internal sanity check failed
98 #define CTDLEXIT_HOME           103     // Citadel home directory not found
99 #define CTDLEXIT_DB             105     // Unable to initialize database
100 #define CTDLEXIT_LIBCITADEL     106     // Incorrect version of libcitadel
101 #define CTDL_EXIT_UNSUP_AUTH    107     // Unsupported auth mode configured
102 #define CTDLEXIT_UNUSER         108     // Could not determine uid to run as
103 #define CTDLEXIT_CRYPTO         109     // Problem initializing SSL or TLS
104
105 // Other exit codes are probably ok to try starting the server again.
106 #define CTDLEXIT_REDIRECT       110     // Redirect buffer failure
107 #define CTDLEXIT_CHKPWD         111     // chkpwd daemon failed
108 #define CTDLEXIT_THREAD         112     // Problem setting up multithreading
109 #define CTDLEXIT_BAD_MAGIC      113     // internet_addressing() magic number is wrong
110
111 // Any other exit is likely to be from an unexpected abort (segfault etc) and we want to try restarting.
112
113
114 // Reasons why a session would be terminated (set CC->kill_me to these values)
115 enum {
116         KILLME_NOT,
117         KILLME_UNKNOWN,
118         KILLME_CLIENT_LOGGED_OUT,
119         KILLME_IDLE,
120         KILLME_CLIENT_DISCONNECTED,
121         KILLME_AUTHFAILED,
122         KILLME_SERVER_SHUTTING_DOWN,
123         KILLME_MAX_SESSIONS_EXCEEDED,
124         KILLME_ADMIN_TERMINATE,
125         KILLME_SELECT_INTERRUPTED,
126         KILLME_SELECT_FAILED,
127         KILLME_WRITE_FAILED,
128         KILLME_SIMULATION_WORKER,
129         KILLME_NOLOGIN,
130         KILLME_NO_CRYPTO,
131         KILLME_READSTRING_FAILED,
132         KILLME_MALLOC_FAILED,
133         KILLME_QUOTA,
134         KILLME_READ_FAILED,
135         KILLME_SPAMMER,
136         KILLME_XML_PARSER
137 };
138
139
140 // Flags that may appear in the "who is online" list
141 #define CS_STEALTH      1       // stealth mode
142 #define CS_CHAT         2       // chat mode
143 #define CS_POSTING      4       // posting
144
145
146 // Flags that may appear in an instant message
147 #define EM_BROADCAST    1       // Broadcast message
148 #define EM_GO_AWAY      2       // Server requests client log off
149 #define EM_CHAT         4       // Server requests client enter chat
150
151
152 // Various things we need to lock and unlock
153 enum {
154         S_USERS,
155         S_ROOMS,
156         S_SESSION_TABLE,
157         S_FLOORTAB,
158         S_CHATQUEUE,
159         S_CONTROL,
160         S_SUPPMSGMAIN,
161         S_CONFIG,
162         S_HOUSEKEEPING,
163         S_NETCONFIGS,
164         S_FLOORCACHE,
165         S_ATBF,
166         S_JOURNAL_QUEUE,
167         S_CHKPWD,
168         S_XMPP_QUEUE,
169         S_SINGLE_USER,
170         S_IM_LOGS,
171         S_OPENSSL,
172         S_SMTPQUEUE,
173         S_INDEXER,
174         MAX_SEMAPHORES
175 };
176
177
178 // message transfer formats
179 enum {
180         MT_CITADEL,             // Citadel proprietary
181         MT_RFC822,              // RFC822
182         MT_MIME,                // MIME-formatted message
183         MT_DOWNLOAD,            // Download a component
184         MT_SPEW_SECTION         // Download a component in a single operation
185 };
186
187
188 // Message format types in the database
189 #define FMT_CITADEL     0       // Citadel vari-format (proprietary)
190 #define FMT_FIXED       1       // Fixed format (proprietary)
191 #define FMT_RFC822      4       // Standard (headers are in M field)
192
193
194 // citadel database tables (define one for each cdb we need to open)
195 enum {
196         CDB_MSGMAIN,            // message base
197         CDB_USERS,              // user file
198         CDB_ROOMS,              // room index
199         CDB_FLOORTAB,           // floor index
200         CDB_MSGLISTS,           // room message lists
201         CDB_VISIT,              // user/room relationships
202         CDB_DIRECTORY,          // address book directory
203         CDB_USETABLE,           // network use table
204         CDB_BIGMSGS,            // larger message bodies
205         CDB_FULLTEXT,           // full text search index
206         CDB_EUIDINDEX,          // locate msgs by EUID
207         CDB_USERSBYNUMBER,      // index of users by number
208         CDB_UNUSED1,            // this used to be the EXTAUTH table but is no longer used
209         CDB_CONFIG,             // system configuration database
210         MAXCDB                  // total number of CDB's defined
211 };
212
213
214 // Event types for hooks
215 enum {
216         EVT_STOP,               // Session is terminating
217         EVT_START,              // Session is starting
218         EVT_LOGIN,              // A user is logging in
219         EVT_NEWROOM,            // Changing rooms
220         EVT_LOGOUT,             // A user is logging out
221         EVT_SETPASS,            // Setting or changing password
222         EVT_CMD,                // Called after each server command
223         EVT_RWHO,               // An RWHO command is being executed
224         EVT_ASYNC,              // Doing asynchronous messages
225         EVT_STEALTH,            // Entering stealth mode
226         EVT_UNSTEALTH,          // Exiting stealth mode
227         EVT_TIMER,              // Timer events are called once per minute and are not tied to any session
228         EVT_HOUSE,              // as needed houskeeping stuff
229         EVT_SHUTDOWN,           // Server is shutting down
230         EVT_PURGEUSER,          // Deleting a user
231         EVT_NEWUSER,            // Creating a user
232         EVT_BEFORESAVE,
233         EVT_AFTERSAVE,
234         EVT_SMTPSCAN,           // called before submitting a msg from SMTP
235         EVT_AFTERUSRMBOXSAVE    // called afte a message was saved into a users inbox
236 };
237
238
239 // Priority levels for paging functions (lower is better)
240 enum {
241         XMSG_PRI_LOCAL,         // Other users on -this- server
242         XMSG_PRI_REMOTE,        // Other users on a Citadel network
243         XMSG_PRI_FOREIGN,       // Contacts on foreign instant message hosts
244         MAX_XMSG_PRI
245 };
246
247
248 // Flags that may appear in a 'struct visit'
249 #define V_FORGET        1       // User has zapped this room
250 #define V_LOCKOUT       2       // User is locked out of this room
251 #define V_ACCESS        4       // Access is granted to this room
252
253
254 // These one-byte field headers are found in the Citadel message store.
255 typedef enum _MsgField {
256         eAuthor       = 'A',
257         eBig_message  = 'B',
258         eExclusiveID  = 'E',
259         erFc822Addr   = 'F',
260         emessageId    = 'I',
261         eJournal      = 'J',
262         eReplyTo      = 'K',
263         eListID       = 'L',
264         eMessageText   = 'M',
265         eOriginalRoom = 'O',
266         eMessagePath  = 'P',
267         eRecipient    = 'R',
268         eTimestamp    = 'T',
269         eMsgSubject   = 'U',
270         eenVelopeTo   = 'V',
271         eWeferences   = 'W',
272         eCarbonCopY   = 'Y',
273         eErrorMsg     = '0',
274         eSuppressIdx  = '1',
275         eExtnotify    = '2',
276         eVltMsgNum    = '3'
277 } eMsgField;
278
279
280 // Private rooms are always flagged with QR_PRIVATE.  If neither QR_PASSWORDED
281 // or QR_GUESSNAME is set, then it is invitation-only.  Passworded rooms are
282 // flagged with both QR_PRIVATE and QR_PASSWORDED while guess-name rooms are
283 // flagged with both QR_PRIVATE and QR_GUESSNAME.  NEVER set all three flags.
284
285
286 #endif // CITADEL_DEFS_H