]> code.citadel.org Git - citadel.git/blob - citadel/server/server.h
server.h began style c leanup
[citadel.git] / citadel / server / server.h
1 // Main declarations file 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.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 #define CTDLMESSAGE_MAGIC               0x159d
34 #define CM_SKIP_HOOKS   0x01            // Don't run server-side handlers
35
36
37 // Data structure returned by validate_recipients()
38 struct recptypes {
39         int recptypes_magic;
40         int num_local;
41         int num_internet;
42         int num_room;
43         int num_error;
44         char *errormsg;
45         char *recp_local;
46         char *recp_internet;
47         char *recp_room;
48         char *recp_orgroom;
49         char *display_recp;
50         char *bounce_to;
51         char *envelope_from;
52         char *sending_room;
53 };
54
55 #define RECPTYPES_MAGIC 0xfeeb
56
57 #define CTDLEXIT_SHUTDOWN       0       // Normal shutdown; do NOT auto-restart
58
59 // Exit codes 101 through 109 are used for conditions in which
60 // we deliberately do NOT want the service to automatically
61 // restart.
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
69
70 // Reasons why a session would be terminated (set CC->kill_me to these values)
71 enum {
72         KILLME_NOT,
73         KILLME_UNKNOWN,
74         KILLME_CLIENT_LOGGED_OUT,
75         KILLME_IDLE,
76         KILLME_CLIENT_DISCONNECTED,
77         KILLME_AUTHFAILED,
78         KILLME_SERVER_SHUTTING_DOWN,
79         KILLME_MAX_SESSIONS_EXCEEDED,
80         KILLME_ADMIN_TERMINATE,
81         KILLME_SELECT_INTERRUPTED,
82         KILLME_SELECT_FAILED,
83         KILLME_WRITE_FAILED,
84         KILLME_SIMULATION_WORKER,
85         KILLME_NOLOGIN,
86         KILLME_NO_CRYPTO,
87         KILLME_READSTRING_FAILED,
88         KILLME_MALLOC_FAILED,
89         KILLME_QUOTA,
90         KILLME_READ_FAILED,
91         KILLME_SPAMMER,
92         KILLME_XML_PARSER
93 };
94
95
96 #define CS_STEALTH      1       // stealth mode
97 #define CS_CHAT         2       // chat mode
98 #define CS_POSTING      4       // posting
99
100 extern int ScheduledShutdown;
101 extern uid_t ctdluid;
102 extern int sanity_diag_mode;
103
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)
111 };
112
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
116
117 // Various things we need to lock and unlock
118 enum {
119         S_USERS,
120         S_ROOMS,
121         S_SESSION_TABLE,
122         S_FLOORTAB,
123         S_CHATQUEUE,
124         S_CONTROL,
125         S_SUPPMSGMAIN,
126         S_CONFIG,
127         S_HOUSEKEEPING,
128         S_NETCONFIGS,
129         S_FLOORCACHE,
130         S_ATBF,
131         S_JOURNAL_QUEUE,
132         S_CHKPWD,
133         S_XMPP_QUEUE,
134         S_SINGLE_USER,
135         S_IM_LOGS,
136         S_OPENSSL,
137         S_SMTPQUEUE,
138         MAX_SEMAPHORES
139 };
140
141
142 // message transfer formats
143 enum {
144         MT_CITADEL,             // Citadel proprietary
145         MT_RFC822,              // RFC822
146         MT_MIME,                // MIME-formatted message
147         MT_DOWNLOAD,            // Download a component
148         MT_SPEW_SECTION         // Download a component in a single operation
149 };
150
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)
155
156
157 // citadel database tables (define one for each cdb we need to open)
158 enum {
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
174 };
175
176 struct cdbdata {
177         size_t len;
178         char *ptr;
179 };
180
181
182 /*
183  * Event types can't be enum'ed, because they must remain consistent between
184  * builds (to allow for binary modules built somewhere else)
185  */
186 #define EVT_STOP        0       /* Session is terminating */
187 #define EVT_START       1       /* Session is starting */
188 #define EVT_LOGIN       2       /* A user is logging in */
189 #define EVT_NEWROOM     3       /* Changing rooms */
190 #define EVT_LOGOUT      4       /* A user is logging out */
191 #define EVT_SETPASS     5       /* Setting or changing password */
192 #define EVT_CMD         6       /* Called after each server command */
193 #define EVT_RWHO        7       /* An RWHO command is being executed */
194 #define EVT_ASYNC       8       /* Doing asynchronous messages */
195 #define EVT_STEALTH     9       /* Entering stealth mode */
196 #define EVT_UNSTEALTH   10      /* Exiting stealth mode */
197
198 #define EVT_TIMER       50      /* Timer events are called once per minute
199                                    and are not tied to any session */
200 #define EVT_HOUSE       51      /* as needed houskeeping stuff */
201 #define EVT_SHUTDOWN    52      /* Server is shutting down */
202
203 #define EVT_PURGEUSER   100     /* Deleting a user */
204 #define EVT_NEWUSER     102     /* Creating a user */
205
206 #define EVT_BEFORESAVE  201
207 #define EVT_AFTERSAVE   202
208 #define EVT_SMTPSCAN    203     /* called before submitting a msg from SMTP */
209 #define EVT_AFTERUSRMBOXSAVE 204 /* called afte a message was saved into a users inbox */
210 /* Priority levels for paging functions (lower is better) */
211 enum {
212         XMSG_PRI_LOCAL,         /* Other users on -this- server */
213         XMSG_PRI_REMOTE,        /* Other users on a Citadel network (future) */
214         XMSG_PRI_FOREIGN,       /* Contacts on foreign instant message hosts */
215         MAX_XMSG_PRI
216 };
217
218
219 // Defines the relationship of a user to a particular room
220 typedef struct __visit {
221         long v_roomnum;
222         long v_roomgen;
223         long v_usernum;
224         long v_lastseen;
225         unsigned int v_flags;
226         char v_seen[SIZ];
227         char v_answered[SIZ];
228         int v_view;
229 } visit;
230
231 #define V_FORGET        1       // User has zapped this room
232 #define V_LOCKOUT       2       // User is locked out of this room
233 #define V_ACCESS        4       // Access is granted to this room
234
235
236 /* Supplementary data for a message on disk
237  * These are kept separate from the message itself for one of two reasons:
238  * 1. Either their values may change at some point after initial save, or
239  * 2. They are merely caches of data which exist somewhere else, for speed.
240  * DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w
241  */
242 struct MetaData {
243         long meta_msgnum;               /* Message number in *local* message base */
244         int meta_refcount;              /* Number of rooms pointing to this msg */
245         char meta_content_type[64];     /* Cached MIME content-type */
246         long meta_rfc822_length;        /* Cache of RFC822-translated msg length */
247 };
248
249
250 // Calls to AdjRefCount() are queued and deferred, so the user doesn't
251 // have to wait for various disk-intensive operations to complete synchronously.
252 // This is the record format.
253 struct arcq {
254         long arcq_msgnum;               // Message number being adjusted
255         int arcq_delta;                 // Adjustment ( usually 1 or -1 )
256 };
257
258
259 // Serialization routines use this struct to return a pointer and a length
260 struct ser_ret {
261         size_t len;
262         unsigned char *ser;
263 };
264
265
266 // The S_USETABLE database is used in several modules now, so we define its format here.
267 struct UseTable {
268         char ut_msgid[SIZ];
269         time_t ut_timestamp;
270 };
271
272
273 // These one-byte field headers are found in the Citadel message store.
274 typedef enum _MsgField {
275         eAuthor       = 'A',
276         eBig_message  = 'B',
277         eExclusiveID  = 'E',
278         erFc822Addr   = 'F',
279         emessageId    = 'I',
280         eJournal      = 'J',
281         eReplyTo      = 'K',
282         eListID       = 'L',
283         eMesageText   = 'M',
284         eOriginalRoom = 'O',
285         eMessagePath  = 'P',
286         eRecipient    = 'R',
287         eTimestamp    = 'T',
288         eMsgSubject   = 'U',
289         eenVelopeTo   = 'V',
290         eWeferences   = 'W',
291         eCarbonCopY   = 'Y',
292         eErrorMsg     = '0',
293         eSuppressIdx  = '1',
294         eExtnotify    = '2',
295         eVltMsgNum    = '3'
296 } eMsgField;
297
298 #endif // SERVER_H