]> code.citadel.org Git - citadel.git/blob - citadel/server/server.h
Removed S_ mutex types no longer in use
[citadel.git] / citadel / server / server.h
1 /* 
2  * Main declarations file for the Citadel server
3  *
4  * Copyright (c) 1987-2023 by the citadel.org team
5  *
6  * This program is open source software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 3.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #ifndef SERVER_H
16 #define SERVER_H
17
18 #ifdef __GNUC__
19 #define INLINE __inline__
20 #else
21 #define INLINE
22 #endif
23
24 #include "citadel.h"
25 #ifdef HAVE_OPENSSL
26 #define OPENSSL_NO_KRB5         /* work around redhat b0rken ssl headers */
27 #include <openssl/ssl.h>
28 #endif
29
30 /*
31  * New format for a message in memory
32  */
33 struct CtdlMessage {
34         int cm_magic;                   /* Self-check (NOT SAVED TO DISK) */
35         char cm_anon_type;              /* Anonymous or author-visible */
36         char cm_format_type;            /* Format type */
37         char *cm_fields[256];           /* Data fields */
38         long cm_lengths[256];           /* size of datafields */
39         unsigned int cm_flags;          /* How to handle (NOT SAVED TO DISK) */
40 };
41
42 #define CTDLMESSAGE_MAGIC               0x159d
43 #define CM_SKIP_HOOKS   0x01            /* Don't run server-side handlers */
44
45
46 /* Data structure returned by validate_recipients() */
47 struct recptypes {
48         int recptypes_magic;
49         int num_local;
50         int num_internet;
51         int num_room;
52         int num_error;
53         char *errormsg;
54         char *recp_local;
55         char *recp_internet;
56         char *recp_room;
57         char *recp_orgroom;
58         char *display_recp;
59         char *bounce_to;
60         char *envelope_from;
61         char *sending_room;
62 };
63
64 #define RECPTYPES_MAGIC 0xfeeb
65
66 #define CTDLEXIT_SHUTDOWN       0       // Normal shutdown; do NOT auto-restart
67
68 /*
69  * Exit codes 101 through 109 are used for conditions in which
70  * we deliberately do NOT want the service to automatically
71  * restart.
72  */
73 #define CTDLEXIT_CONFIG         101     // Could not read system configuration
74 #define CTDLEXIT_HOME           103     // Citadel home directory not found
75 #define CTDLEXIT_DB             105     // Unable to initialize database
76 #define CTDLEXIT_LIBCITADEL     106     // Incorrect version of libcitadel
77 #define CTDL_EXIT_UNSUP_AUTH    107     // Unsupported auth mode configured
78 #define CTDLEXIT_UNUSER         108     // Could not determine uid to run as
79 #define CTDLEXIT_CRYPTO         109     // Problem initializing SSL or TLS
80
81 /*
82  * Reasons why a session would be terminated (set CC->kill_me to these values)
83  */
84 enum {
85         KILLME_NOT,
86         KILLME_UNKNOWN,
87         KILLME_CLIENT_LOGGED_OUT,
88         KILLME_IDLE,
89         KILLME_CLIENT_DISCONNECTED,
90         KILLME_AUTHFAILED,
91         KILLME_SERVER_SHUTTING_DOWN,
92         KILLME_MAX_SESSIONS_EXCEEDED,
93         KILLME_ADMIN_TERMINATE,
94         KILLME_SELECT_INTERRUPTED,
95         KILLME_SELECT_FAILED,
96         KILLME_WRITE_FAILED,
97         KILLME_SIMULATION_WORKER,
98         KILLME_NOLOGIN,
99         KILLME_NO_CRYPTO,
100         KILLME_READSTRING_FAILED,
101         KILLME_MALLOC_FAILED,
102         KILLME_QUOTA,
103         KILLME_READ_FAILED,
104         KILLME_SPAMMER,
105         KILLME_XML_PARSER
106 };
107
108
109 #define CS_STEALTH      1       /* stealth mode */
110 #define CS_CHAT         2       /* chat mode */
111 #define CS_POSTING      4       /* Posting */
112
113 extern int ScheduledShutdown;
114 extern uid_t ctdluid;
115 extern int sanity_diag_mode;
116
117 struct ExpressMessage {
118         struct ExpressMessage *next;
119         time_t timestamp;       /* When this message was sent */
120         unsigned flags;         /* Special instructions */
121         char sender[256];       /* Name of sending user */
122         char sender_email[256]; /* Email or JID of sending user */
123         char *text;             /* Message text (if applicable) */
124 };
125
126 #define EM_BROADCAST    1       /* Broadcast message */
127 #define EM_GO_AWAY      2       /* Server requests client log off */
128 #define EM_CHAT         4       /* Server requests client enter chat */
129
130 /*
131  * Various things we need to lock and unlock
132  */
133 enum {
134         S_USERS,
135         S_ROOMS,
136         S_SESSION_TABLE,
137         S_FLOORTAB,
138         S_CHATQUEUE,
139         S_CONTROL,
140         S_SUPPMSGMAIN,
141         S_CONFIG,
142         S_HOUSEKEEPING,
143         S_NETCONFIGS,
144         S_FLOORCACHE,
145         S_ATBF,
146         S_JOURNAL_QUEUE,
147         S_CHKPWD,
148         S_XMPP_QUEUE,
149         S_SINGLE_USER,
150         S_IM_LOGS,
151         S_OPENSSL,
152         MAX_SEMAPHORES
153 };
154
155
156 /*
157  * message transfer formats
158  */
159 enum {
160         MT_CITADEL,             /* Citadel proprietary */
161         MT_RFC822,              /* RFC822 */
162         MT_MIME,                /* MIME-formatted message */
163         MT_DOWNLOAD,            /* Download a component */
164         MT_SPEW_SECTION         /* Download a component in a single operation */
165 };
166
167 /*
168  * Message format types in the database
169  */
170 #define FMT_CITADEL     0       /* Citadel vari-format (proprietary) */
171 #define FMT_FIXED       1       /* Fixed format (proprietary)        */
172 #define FMT_RFC822      4       /* Standard (headers are in M field) */
173
174
175 /*
176  * Citadel DataBases (define one for each cdb we need to open)
177  */
178 enum {
179         CDB_MSGMAIN,            /* message base                  */
180         CDB_USERS,              /* user file                     */
181         CDB_ROOMS,              /* room index                    */
182         CDB_FLOORTAB,           /* floor index                   */
183         CDB_MSGLISTS,           /* room message lists            */
184         CDB_VISIT,              /* user/room relationships       */
185         CDB_DIRECTORY,          /* address book directory        */
186         CDB_USETABLE,           /* network use table             */
187         CDB_BIGMSGS,            /* larger message bodies         */
188         CDB_FULLTEXT,           /* full text search index        */
189         CDB_EUIDINDEX,          /* locate msgs by EUID           */
190         CDB_USERSBYNUMBER,      /* index of users by number      */
191         CDB_EXTAUTH,            /* associates OpenIDs with users */
192         CDB_CONFIG,             /* system configuration database */
193         MAXCDB                  /* total number of CDB's defined */
194 };
195
196 struct cdbdata {
197         size_t len;
198         char *ptr;
199 };
200
201
202 /*
203  * Event types can't be enum'ed, because they must remain consistent between
204  * builds (to allow for binary modules built somewhere else)
205  */
206 #define EVT_STOP        0       /* Session is terminating */
207 #define EVT_START       1       /* Session is starting */
208 #define EVT_LOGIN       2       /* A user is logging in */
209 #define EVT_NEWROOM     3       /* Changing rooms */
210 #define EVT_LOGOUT      4       /* A user is logging out */
211 #define EVT_SETPASS     5       /* Setting or changing password */
212 #define EVT_CMD         6       /* Called after each server command */
213 #define EVT_RWHO        7       /* An RWHO command is being executed */
214 #define EVT_ASYNC       8       /* Doing asynchronous messages */
215 #define EVT_STEALTH     9       /* Entering stealth mode */
216 #define EVT_UNSTEALTH   10      /* Exiting stealth mode */
217
218 #define EVT_TIMER       50      /* Timer events are called once per minute
219                                    and are not tied to any session */
220 #define EVT_HOUSE       51      /* as needed houskeeping stuff */
221 #define EVT_SHUTDOWN    52      /* Server is shutting down */
222
223 #define EVT_PURGEUSER   100     /* Deleting a user */
224 #define EVT_NEWUSER     102     /* Creating a user */
225
226 #define EVT_BEFORESAVE  201
227 #define EVT_AFTERSAVE   202
228 #define EVT_SMTPSCAN    203     /* called before submitting a msg from SMTP */
229 #define EVT_AFTERUSRMBOXSAVE 204 /* called afte a message was saved into a users inbox */
230 /* Priority levels for paging functions (lower is better) */
231 enum {
232         XMSG_PRI_LOCAL,         /* Other users on -this- server */
233         XMSG_PRI_REMOTE,        /* Other users on a Citadel network (future) */
234         XMSG_PRI_FOREIGN,       /* Contacts on foreign instant message hosts */
235         MAX_XMSG_PRI
236 };
237
238
239 /* Defines the relationship of a user to a particular room */
240 typedef struct __visit {
241         long v_roomnum;
242         long v_roomgen;
243         long v_usernum;
244         long v_lastseen;
245         unsigned int v_flags;
246         char v_seen[SIZ];
247         char v_answered[SIZ];
248         int v_view;
249 } visit;
250
251 #define V_FORGET        1       /* User has zapped this room        */
252 #define V_LOCKOUT       2       /* User is locked out of this room  */
253 #define V_ACCESS        4       /* Access is granted to this room   */
254
255
256 /* Supplementary data for a message on disk
257  * These are kept separate from the message itself for one of two reasons:
258  * 1. Either their values may change at some point after initial save, or
259  * 2. They are merely caches of data which exist somewhere else, for speed.
260  * DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w
261  */
262 struct MetaData {
263         long meta_msgnum;               /* Message number in *local* message base */
264         int meta_refcount;              /* Number of rooms pointing to this msg */
265         char meta_content_type[64];     /* Cached MIME content-type */
266         long meta_rfc822_length;        /* Cache of RFC822-translated msg length */
267 };
268
269
270 /* Calls to AdjRefCount() are queued and deferred, so the user doesn't
271  * have to wait for various disk-intensive operations to complete synchronously.
272  * This is the record format.
273  */
274 struct arcq {
275         long arcq_msgnum;               /* Message number being adjusted */
276         int arcq_delta;                 /* Adjustment ( usually 1 or -1 ) */
277 };
278
279
280 /*
281  * Serialization routines use this struct to return a pointer and a length
282  */
283 struct ser_ret {
284         size_t len;
285         unsigned char *ser;
286 };
287
288
289 /*
290  * The S_USETABLE database is used in several modules now, so we define its format here.
291  */
292 struct UseTable {
293         char ut_msgid[SIZ];
294         time_t ut_timestamp;
295 };
296
297
298 /*
299  * These one-byte field headers are found in the Citadel message store.
300  */
301 typedef enum _MsgField {
302         eAuthor       = 'A',
303         eBig_message  = 'B',
304         eExclusiveID  = 'E',
305         erFc822Addr   = 'F',
306         emessageId    = 'I',
307         eJournal      = 'J',
308         eReplyTo      = 'K',
309         eListID       = 'L',
310         eMesageText   = 'M',
311         eOriginalRoom = 'O',
312         eMessagePath  = 'P',
313         eRecipient    = 'R',
314         eTimestamp    = 'T',
315         eMsgSubject   = 'U',
316         eenVelopeTo   = 'V',
317         eWeferences   = 'W',
318         eCarbonCopY   = 'Y',
319         eErrorMsg     = '0',
320         eSuppressIdx  = '1',
321         eExtnotify    = '2',
322         eVltMsgNum    = '3'
323 } eMsgField;
324
325 #endif /* SERVER_H */