f58a9c3f1d7715ec6eebb070dab51eca07bb6a3d
[citadel.git] / citadel / server / server.h
1 // Data types 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_defs.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
24 // New format for a message in memory
25 struct CtdlMessage {
26         int cm_magic;                   // Self-check (NOT SAVED TO DISK)
27         char cm_anon_type;              // Anonymous or author-visible
28         char cm_format_type;            // Format type
29         char *cm_fields[256];           // Data fields
30         long cm_lengths[256];           // size of datafields
31         unsigned int cm_flags;          // How to handle (NOT SAVED TO DISK)
32 };
33
34
35 // Data structure returned by validate_recipients()
36 struct recptypes {
37         int recptypes_magic;
38         int num_local;
39         int num_internet;
40         int num_room;
41         int num_error;
42         char *errormsg;
43         char *recp_local;
44         char *recp_internet;
45         char *recp_room;
46         char *recp_orgroom;
47         char *display_recp;
48         char *bounce_to;
49         char *envelope_from;
50         char *sending_room;
51 };
52
53 extern int ScheduledShutdown;
54 extern uid_t ctdluid;
55 extern int sanity_diag_mode;
56
57
58 // Instant message in transit on the system (not used in the database)
59 struct ExpressMessage {
60         struct ExpressMessage *next;
61         time_t timestamp;       // When this message was sent
62         unsigned flags;         // Special instructions
63         char sender[256];       // Name of sending user
64         char sender_email[256]; // Email or JID of sending user
65         char *text;             // Message text (if applicable)
66 };
67
68
69 // Row being stored or fetched in the database
70 struct cdbdata {
71         size_t len;                     // size of datum pointed to by ptr
72         char *ptr;                      // datum
73 };
74
75
76 // Row being fetched from the database, both key and value are returned
77 struct cdbkeyval {
78         struct cdbdata key;             // size and pointer to key
79         struct cdbdata val;             // size and pointer to value
80 };
81
82
83 // Defines the relationship of a user to a particular room
84 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
85 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
86 struct visit {
87         long v_roomnum;         //
88         long v_roomgen;         // The first three fields , sizeof(long)*3 , are the index format.
89         long v_usernum;         //
90         long v_lastseen;
91         unsigned v_flags;
92         char v_seen[SIZ];
93         char v_answered[SIZ];
94         int v_view;
95 };
96
97
98 // This is the db index format for "visit" records, which describe the relationship between one user and one room.
99 struct visit_index {
100         long iRoomID;
101         long iRoomGen;
102         long iUserID;
103 };
104
105
106 // Supplementary data for a message on disk
107 // These are kept separate from the message itself for one of two reasons:
108 // 1. Either their values may change at some point after initial save, or
109 // 2. They are merely caches of data which exist somewhere else, for speed.
110 // DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w
111 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
112 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
113 struct MetaData {
114         long meta_msgnum;               // Message number in *local* message base
115         int meta_refcount;              // Number of rooms pointing to this msg
116         char meta_content_type[64];     // Cached MIME content-type
117         long meta_rfc822_length;        // Cache of RFC822-translated msg length
118 };
119
120
121 // Calls to AdjRefCount() are queued and deferred, so the user doesn't
122 // have to wait for various disk-intensive operations to complete synchronously.
123 // This is the record format.
124 struct arcq {
125         long arcq_msgnum;               // Message number being adjusted
126         int arcq_delta;                 // Adjustment ( usually 1 or -1 )
127 };
128
129
130 // Serialization routines use this struct to return a pointer and a length
131 struct ser_ret {
132         size_t len;
133         unsigned char *ser;
134 };
135
136
137 // The S_USETABLE database is used in several modules now, so we define its format here.
138 struct UseTable {
139         int hash;
140         time_t timestamp;
141 };
142
143
144 // User records.
145 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
146 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
147 typedef struct ctdluser ctdluser;
148 struct ctdluser {                       // User record
149         int version;                    // Citadel version which created this record
150         uid_t uid;                      // Associate with a unix account?
151         char password[32];              // password
152         unsigned flags;                 // See US_ flags below
153         long unused1;
154         long unused2;
155         cit_uint8_t axlevel;            // Access level
156         long usernum;                   // User number (never recycled)
157         time_t lastcall;                // Date/time of most recent login
158         int USuserpurge;                // Purge time (in days) for user
159         char fullname[64];              // Display name (primary identifier)
160         long msgnum_bio;                // msgnum of user's profile (bio)
161         long msgnum_pic;                // msgnum of user's avatar (photo)
162         char emailaddrs[512];           // Internet email addresses
163         long msgnum_inboxrules;         // msgnum of user's inbox filtering rules
164         long lastproc_inboxrules;       // msgnum of last message filtered
165 };
166
167
168 // Message expiration policy stuff
169 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
170 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
171 typedef struct ExpirePolicy ExpirePolicy;
172 struct ExpirePolicy {
173         int expire_mode;
174         int expire_value;
175 };
176
177
178 // Room records.
179 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
180 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
181 struct ctdlroom {
182         char QRname[ROOMNAMELEN];       // Name of room
183         char QRpasswd[10];              // Only valid if it's a private rm
184         long QRroomaide;                // User number of room aide
185         long QRhighest;                 // Highest message NUMBER in room
186         time_t QRgen;                   // Generation number of room
187         unsigned QRflags;               // See flag values below
188         char QRdirname[15];             // Directory name, if applicable
189         long msgnum_info;               // msgnum of room banner (info file)
190         char QRfloor;                   // Which floor this room is on
191         time_t QRmtime;                 // Date/time of last post
192         struct ExpirePolicy QRep;       // Message expiration policy
193         long QRnumber;                  // Globally unique room number
194         char QRorder;                   // Sort key for room listing order
195         unsigned QRflags2;              // Additional flags
196         int QRdefaultview;              // How to display the contents
197         long msgnum_pic;                // msgnum of room picture or icon
198 };
199
200
201 // Floor record.  The floor number is implicit in its location in the file.
202 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
203 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
204 struct floor {
205         unsigned short f_flags;         // flags
206         char f_name[256];               // name of floor
207         int f_ref_count;                // reference count
208         struct ExpirePolicy f_ep;       // default expiration policy
209 };
210
211
212 // Database records beginning with this magic number are assumed to
213 // be compressed.  In the event that a database record actually begins with
214 // this magic number, we *must* compress it whether we want to or not,
215 // because the fetch function will try to uncompress it anyway.
216 // 
217 // (No need to #ifdef this stuff; it compiles ok even if zlib is not present
218 // and doesn't declare anything so it won't bloat the code)
219 #define COMPRESS_MAGIC  0xc0ffeeee
220
221 struct CtdlCompressHeader {
222         int magic;
223         size_t uncompressed_len;
224         size_t compressed_len;
225 };
226
227
228 #endif // SERVER_H