citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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