-// Main declarations file for the Citadel server
+// Data types for the Citadel Server
//
-// Copyright (c) 1987-2023 by the citadel.org team
+// Copyright (c) 1987-2024 by the citadel.org team
//
// This program is open source software. Use, duplication, or disclosure
// is subject to the terms of the GNU General Public License, version 3.
#define INLINE
#endif
-#include "citadel.h"
+#include "citadel_defs.h"
#ifdef HAVE_OPENSSL
#define OPENSSL_NO_KRB5 // work around redhat b0rken ssl headers
#include <openssl/ssl.h>
#endif
+
// New format for a message in memory
struct CtdlMessage {
int cm_magic; // Self-check (NOT SAVED TO DISK)
unsigned int cm_flags; // How to handle (NOT SAVED TO DISK)
};
-#define CTDLMESSAGE_MAGIC 0x159d
-#define CM_SKIP_HOOKS 0x01 // Don't run server-side handlers
-
// Data structure returned by validate_recipients()
struct recptypes {
char *sending_room;
};
-#define RECPTYPES_MAGIC 0xfeeb
-
-#define CTDLEXIT_SHUTDOWN 0 // Normal shutdown; do NOT auto-restart
-
-// Exit codes 101 through 109 are used for conditions in which
-// we deliberately do NOT want the service to automatically
-// restart.
-#define CTDLEXIT_CONFIG 101 // Could not read system configuration
-#define CTDLEXIT_HOME 103 // Citadel home directory not found
-#define CTDLEXIT_DB 105 // Unable to initialize database
-#define CTDLEXIT_LIBCITADEL 106 // Incorrect version of libcitadel
-#define CTDL_EXIT_UNSUP_AUTH 107 // Unsupported auth mode configured
-#define CTDLEXIT_UNUSER 108 // Could not determine uid to run as
-#define CTDLEXIT_CRYPTO 109 // Problem initializing SSL or TLS
-
-// Any other exit is likely to be from an unexpected abort (segfault etc)
-// and we want to try restarting.
-
-
-
-// Reasons why a session would be terminated (set CC->kill_me to these values)
-enum {
- KILLME_NOT,
- KILLME_UNKNOWN,
- KILLME_CLIENT_LOGGED_OUT,
- KILLME_IDLE,
- KILLME_CLIENT_DISCONNECTED,
- KILLME_AUTHFAILED,
- KILLME_SERVER_SHUTTING_DOWN,
- KILLME_MAX_SESSIONS_EXCEEDED,
- KILLME_ADMIN_TERMINATE,
- KILLME_SELECT_INTERRUPTED,
- KILLME_SELECT_FAILED,
- KILLME_WRITE_FAILED,
- KILLME_SIMULATION_WORKER,
- KILLME_NOLOGIN,
- KILLME_NO_CRYPTO,
- KILLME_READSTRING_FAILED,
- KILLME_MALLOC_FAILED,
- KILLME_QUOTA,
- KILLME_READ_FAILED,
- KILLME_SPAMMER,
- KILLME_XML_PARSER
-};
-
-
-#define CS_STEALTH 1 // stealth mode
-#define CS_CHAT 2 // chat mode
-#define CS_POSTING 4 // posting
-
extern int ScheduledShutdown;
extern uid_t ctdluid;
extern int sanity_diag_mode;
+
+// Instant message in transit on the system (not used in the database)
struct ExpressMessage {
struct ExpressMessage *next;
time_t timestamp; // When this message was sent
char *text; // Message text (if applicable)
};
-#define EM_BROADCAST 1 // Broadcast message
-#define EM_GO_AWAY 2 // Server requests client log off
-#define EM_CHAT 4 // Server requests client enter chat
-
-// Various things we need to lock and unlock
-enum {
- S_USERS,
- S_ROOMS,
- S_SESSION_TABLE,
- S_FLOORTAB,
- S_CHATQUEUE,
- S_CONTROL,
- S_SUPPMSGMAIN,
- S_CONFIG,
- S_HOUSEKEEPING,
- S_NETCONFIGS,
- S_FLOORCACHE,
- S_ATBF,
- S_JOURNAL_QUEUE,
- S_CHKPWD,
- S_XMPP_QUEUE,
- S_SINGLE_USER,
- S_IM_LOGS,
- S_OPENSSL,
- S_SMTPQUEUE,
- MAX_SEMAPHORES
-};
-
-
-// message transfer formats
-enum {
- MT_CITADEL, // Citadel proprietary
- MT_RFC822, // RFC822
- MT_MIME, // MIME-formatted message
- MT_DOWNLOAD, // Download a component
- MT_SPEW_SECTION // Download a component in a single operation
-};
-
-// Message format types in the database
-#define FMT_CITADEL 0 // Citadel vari-format (proprietary)
-#define FMT_FIXED 1 // Fixed format (proprietary)
-#define FMT_RFC822 4 // Standard (headers are in M field)
-
-
-// citadel database tables (define one for each cdb we need to open)
-enum {
- CDB_MSGMAIN, // message base
- CDB_USERS, // user file
- CDB_ROOMS, // room index
- CDB_FLOORTAB, // floor index
- CDB_MSGLISTS, // room message lists
- CDB_VISIT, // user/room relationships
- CDB_DIRECTORY, // address book directory
- CDB_USETABLE, // network use table
- CDB_BIGMSGS, // larger message bodies
- CDB_FULLTEXT, // full text search index
- CDB_EUIDINDEX, // locate msgs by EUID
- CDB_USERSBYNUMBER, // index of users by number
- CDB_EXTAUTH, // associates OpenIDs with users
- CDB_CONFIG, // system configuration database
- MAXCDB // total number of CDB's defined
-};
+// Row being stored or fetched in the database
struct cdbdata {
- size_t len;
- char *ptr;
+ size_t len; // size of datum pointed to by ptr
+ char *ptr; // datum
};
-// Event types for hooks
-enum {
- EVT_STOP, // Session is terminating
- EVT_START, // Session is starting
- EVT_LOGIN, // A user is logging in
- EVT_NEWROOM, // Changing rooms
- EVT_LOGOUT, // A user is logging out
- EVT_SETPASS, // Setting or changing password
- EVT_CMD, // Called after each server command
- EVT_RWHO, // An RWHO command is being executed
- EVT_ASYNC, // Doing asynchronous messages
- EVT_STEALTH, // Entering stealth mode
- EVT_UNSTEALTH, // Exiting stealth mode
- EVT_TIMER, // Timer events are called once per minute and are not tied to any session
- EVT_HOUSE, // as needed houskeeping stuff
- EVT_SHUTDOWN, // Server is shutting down
- EVT_PURGEUSER, // Deleting a user
- EVT_NEWUSER, // Creating a user
- EVT_BEFORESAVE,
- EVT_AFTERSAVE,
- EVT_SMTPSCAN, // called before submitting a msg from SMTP
- EVT_AFTERUSRMBOXSAVE // called afte a message was saved into a users inbox
-};
-
-
-/* Priority levels for paging functions (lower is better) */
-enum {
- XMSG_PRI_LOCAL, // Other users on -this- server
- XMSG_PRI_REMOTE, // Other users on a Citadel network
- XMSG_PRI_FOREIGN, // Contacts on foreign instant message hosts
- MAX_XMSG_PRI
+// Row being fetched from the database, both key and value are returned
+struct cdbkeyval {
+ struct cdbdata key; // size and pointer to key
+ struct cdbdata val; // size and pointer to value
};
// Defines the relationship of a user to a particular room
-typedef struct __visit {
- long v_roomnum;
- long v_roomgen;
- long v_usernum;
+// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
+// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
+struct visit {
+ long v_roomnum; //
+ long v_roomgen; // The first three fields , sizeof(long)*3 , are the index format.
+ long v_usernum; //
long v_lastseen;
- unsigned int v_flags;
+ unsigned v_flags;
char v_seen[SIZ];
char v_answered[SIZ];
int v_view;
-} visit;
+};
-#define V_FORGET 1 // User has zapped this room
-#define V_LOCKOUT 2 // User is locked out of this room
-#define V_ACCESS 4 // Access is granted to this room
+
+// This is the db index format for "visit" records, which describe the relationship between one user and one room.
+struct visit_index {
+ long iRoomID;
+ long iRoomGen;
+ long iUserID;
+};
// Supplementary data for a message on disk
// 1. Either their values may change at some point after initial save, or
// 2. They are merely caches of data which exist somewhere else, for speed.
// DO NOT PUT BIG DATA IN HERE ... we need this struct to be tiny for lots of quick r/w
+// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
+// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
struct MetaData {
long meta_msgnum; // Message number in *local* message base
int meta_refcount; // Number of rooms pointing to this msg
};
-// Serialization routines use this struct to return a pointer and a length
-struct ser_ret {
- size_t len;
- unsigned char *ser;
-};
-
-
// The S_USETABLE database is used in several modules now, so we define its format here.
struct UseTable {
- char ut_msgid[SIZ];
- time_t ut_timestamp;
+ int hash;
+ time_t timestamp;
};
-// These one-byte field headers are found in the Citadel message store.
-typedef enum _MsgField {
- eAuthor = 'A',
- eBig_message = 'B',
- eExclusiveID = 'E',
- erFc822Addr = 'F',
- emessageId = 'I',
- eJournal = 'J',
- eReplyTo = 'K',
- eListID = 'L',
- eMesageText = 'M',
- eOriginalRoom = 'O',
- eMessagePath = 'P',
- eRecipient = 'R',
- eTimestamp = 'T',
- eMsgSubject = 'U',
- eenVelopeTo = 'V',
- eWeferences = 'W',
- eCarbonCopY = 'Y',
- eErrorMsg = '0',
- eSuppressIdx = '1',
- eExtnotify = '2',
- eVltMsgNum = '3'
-} eMsgField;
-
-
// User records.
+// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
+// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
typedef struct ctdluser ctdluser;
struct ctdluser { // User record
int version; // Citadel version which created this record
uid_t uid; // Associate with a unix account?
char password[32]; // password
unsigned flags; // See US_ flags below
- long timescalled; // Total number of logins
- long posted; // Number of messages ever submitted
+ long unused1;
+ long unused2;
cit_uint8_t axlevel; // Access level
long usernum; // User number (never recycled)
time_t lastcall; // Date/time of most recent login
};
+// Message expiration policy stuff
+// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
+// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
+typedef struct ExpirePolicy ExpirePolicy;
+struct ExpirePolicy {
+ int expire_mode;
+ int expire_value;
+};
+
+
// Room records.
+// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
+// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
struct ctdlroom {
char QRname[ROOMNAMELEN]; // Name of room
char QRpasswd[10]; // Only valid if it's a private rm
long msgnum_pic; // msgnum of room picture or icon
};
-// Private rooms are always flagged with QR_PRIVATE. If neither QR_PASSWORDED
-// or QR_GUESSNAME is set, then it is invitation-only. Passworded rooms are
-// flagged with both QR_PRIVATE and QR_PASSWORDED while guess-name rooms are
-// flagged with both QR_PRIVATE and QR_GUESSNAME. NEVER set all three flags.
+
+// Floor record. The floor number is implicit in its location in the file.
+// NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
+// NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
+struct floor {
+ unsigned short f_flags; // flags
+ char f_name[256]; // name of floor
+ int f_ref_count; // reference count
+ struct ExpirePolicy f_ep; // default expiration policy
+};
+
+
+// Database records beginning with this magic number are assumed to
+// be compressed. In the event that a database record actually begins with
+// this magic number, we *must* compress it whether we want to or not,
+// because the fetch function will try to uncompress it anyway.
+//
+// (No need to #ifdef this stuff; it compiles ok even if zlib is not present
+// and doesn't declare anything so it won't bloat the code)
+#define COMPRESS_MAGIC 0xc0ffeeee
+
+struct CtdlCompressHeader {
+ int magic;
+ size_t uncompressed_len;
+ size_t compressed_len;
+};
#endif // SERVER_H