Back to index

citadel  8.12
server.h
Go to the documentation of this file.
00001 
00002 
00003 #ifndef SERVER_H
00004 #define SERVER_H
00005 
00006 #ifdef __GNUC__
00007 #define INLINE __inline__
00008 #else
00009 #define INLINE
00010 #endif
00011 
00012 #include "citadel.h"
00013 #ifdef HAVE_OPENSSL
00014 #define OPENSSL_NO_KRB5            /* work around redhat b0rken ssl headers */
00015 #include <openssl/ssl.h>
00016 #endif
00017 
00018 /*
00019  * New format for a message in memory
00020  */
00021 struct CtdlMessage {
00022        int cm_magic;               /* Self-check (NOT SAVED TO DISK) */
00023        char cm_anon_type;          /* Anonymous or author-visible */
00024        char cm_format_type;        /* Format type */
00025        char *cm_fields[256];              /* Data fields */
00026        unsigned int cm_flags;             /* How to handle (NOT SAVED TO DISK) */
00027 };
00028 
00029 #define       CTDLMESSAGE_MAGIC           0x159d
00030 #define       CM_SKIP_HOOKS 0x01          /* Don't run server-side handlers */
00031 
00032 
00033 
00034 #define CTDLEXIT_SHUTDOWN   0      /* Normal shutdown; do NOT auto-restart */
00035 
00036 /*
00037  * Exit codes 101 through 109 are used for conditions in which
00038  * we deliberately do NOT want the service to automatically
00039  * restart.
00040  */
00041 #define CTDLEXIT_CONFIG            101    /* Could not read citadel.config */
00042 #define CTDLEXIT_CONTROL    102    /* Could not acquire lock */
00043 #define CTDLEXIT_HOME              103    /* Citadel home directory not found */
00044 #define CTDLEXIT_OOD        104    /* Out Of Date config - rerun setup */
00045 #define CTDLEXIT_DB         105    /* Unable to initialize database */
00046 #define CTDLEXIT_LIBCITADEL 106    /* Incorrect version of libcitadel */
00047 #define CTDL_EXIT_UNSUP_AUTH       107    /* Unsupported auth mode configured */
00048 
00049 /*
00050  * Reasons why a session would be terminated (set CC->kill_me to these values)
00051  */
00052 enum {
00053        KILLME_NOT,
00054        KILLME_UNKNOWN,
00055        KILLME_CLIENT_LOGGED_OUT,
00056        KILLME_IDLE,
00057        KILLME_CLIENT_DISCONNECTED,
00058        KILLME_AUTHFAILED,
00059        KILLME_SERVER_SHUTTING_DOWN,
00060        KILLME_MAX_SESSIONS_EXCEEDED,
00061        KILLME_ADMIN_TERMINATE,
00062        KILLME_SELECT_INTERRUPTED,
00063        KILLME_SELECT_FAILED,
00064        KILLME_WRITE_FAILED,
00065        KILLME_SIMULATION_WORKER,
00066        KILLME_NOLOGIN,
00067        KILLME_NO_CRYPTO,
00068        KILLME_READSTRING_FAILED,
00069        KILLME_MALLOC_FAILED,
00070        KILLME_QUOTA,
00071        KILLME_READ_FAILED,
00072        KILLME_ILLEGAL_MANAGESIEVE_COMMAND,
00073        KILLME_SPAMMER,
00074        KILLME_XML_PARSER
00075 };
00076 
00077 
00078 #define CS_STEALTH   1      /* stealth mode */
00079 #define CS_CHAT             2      /* chat mode */
00080 #define CS_POSTING   4      /* Posting */
00081 
00082 
00083 /*
00084  * This is the control record for the message base... 
00085  */
00086 struct CitControl {
00087        long MMhighest;                    /* highest message number in file   */
00088        unsigned MMflags;           /* Global system flags              */
00089        long MMnextuser;            /* highest user number on system    */
00090        long MMnextroom;            /* highest room number on system    */
00091        int version;                /* Server-hosted upgrade level      */
00092        int fulltext_wordbreaker;   /* ID of wordbreaker in use         */
00093        long MMfulltext;            /* highest message number indexed   */
00094        int MMdbversion;            /* Version of Berkeley DB used on previous server run */
00095 };
00096 
00097 extern int ScheduledShutdown;
00098 extern struct CitControl CitControl;
00099 
00100 struct ExpressMessage {
00101        struct ExpressMessage *next;
00102        time_t timestamp;    /* When this message was sent */
00103        unsigned flags;             /* Special instructions */
00104        char sender[256];    /* Name of sending user */
00105        char sender_email[256];     /* Email or JID of sending user */
00106        char *text;          /* Message text (if applicable) */
00107 };
00108 
00109 #define EM_BROADCAST 1      /* Broadcast message */
00110 #define EM_GO_AWAY   2      /* Server requests client log off */
00111 #define EM_CHAT             4      /* Server requests client enter chat */
00112 
00113 /*
00114  * Various things we need to lock and unlock
00115  */
00116 enum {
00117        S_USERS,
00118        S_ROOMS,
00119        S_SESSION_TABLE,
00120        S_FLOORTAB,
00121        S_CHATQUEUE,
00122        S_CONTROL,
00123        S_NETDB,
00124        S_SUPPMSGMAIN,
00125        S_CONFIG,
00126        S_HOUSEKEEPING,
00127        S_NTTLIST,
00128        S_DIRECTORY,
00129        S_NETCONFIGS,
00130        S_PUBLIC_CLIENTS,
00131        S_FLOORCACHE,
00132        S_ATBF,
00133        S_JOURNAL_QUEUE,
00134        S_RPLIST,
00135        S_SIEVELIST,
00136        S_CHKPWD,
00137        S_LOG,
00138        S_NETSPOOL,
00139        S_XMPP_QUEUE,
00140        S_SCHEDULE_LIST,
00141        S_SINGLE_USER,
00142        S_LDAP,
00143        S_IM_LOGS,
00144        MAX_SEMAPHORES
00145 };
00146 
00147 
00148 /*
00149  * Upload types
00150  */
00151 #define UPL_FILE     0
00152 #define UPL_NET             1
00153 #define UPL_IMAGE    2
00154 
00155 
00156 /*
00157  * message transfer formats
00158  */
00159 enum {
00160        MT_CITADEL,          /* Citadel proprietary */
00161        MT_RFC822,           /* RFC822 */
00162        MT_MIME,             /* MIME-formatted message */
00163        MT_DOWNLOAD,         /* Download a component */
00164        MT_SPEW_SECTION             /* Download a component in a single operation */
00165 };
00166 
00167 /*
00168  * Message format types in the database
00169  */
00170 #define       FMT_CITADEL   0      /* Citadel vari-format (proprietary) */
00171 #define FMT_FIXED    1      /* Fixed format (proprietary)        */
00172 #define FMT_RFC822   4      /* Standard (headers are in M field) */
00173 
00174 
00175 /*
00176  * Citadel DataBases (define one for each cdb we need to open)
00177  */
00178 enum {
00179        CDB_MSGMAIN,         /* message base                  */
00180        CDB_USERS,           /* user file                     */
00181        CDB_ROOMS,           /* room index                    */
00182        CDB_FLOORTAB,        /* floor index                   */
00183        CDB_MSGLISTS,        /* room message lists            */
00184        CDB_VISIT,           /* user/room relationships       */
00185        CDB_DIRECTORY,              /* address book directory        */
00186        CDB_USETABLE,        /* network use table             */
00187        CDB_BIGMSGS,         /* larger message bodies         */
00188        CDB_FULLTEXT,        /* full text search index        */
00189        CDB_EUIDINDEX,              /* locate msgs by EUID           */
00190        CDB_USERSBYNUMBER,   /* index of users by number      */
00191        CDB_OPENID,          /* associates OpenIDs with users */
00192        MAXCDB               /* total number of CDB's defined */
00193 };
00194 
00195 struct cdbdata {
00196        size_t len;
00197        char *ptr;
00198 };
00199 
00200 
00201 /* 
00202  * Event types can't be enum'ed, because they must remain consistent between
00203  * builds (to allow for binary modules built somewhere else)
00204  */
00205 #define EVT_STOP     0      /* Session is terminating */
00206 #define EVT_START    1      /* Session is starting */
00207 #define EVT_LOGIN    2      /* A user is logging in */
00208 #define EVT_NEWROOM  3      /* Changing rooms */
00209 #define EVT_LOGOUT   4      /* A user is logging out */
00210 #define EVT_SETPASS  5      /* Setting or changing password */
00211 #define EVT_CMD             6      /* Called after each server command */
00212 #define EVT_RWHO     7      /* An RWHO command is being executed */
00213 #define EVT_ASYNC    8      /* Doing asynchronous messages */
00214 #define EVT_STEALTH  9      /* Entering stealth mode */
00215 #define EVT_UNSTEALTH       10     /* Exiting stealth mode */
00216 
00217 #define EVT_TIMER    50     /* Timer events are called once per minute
00218                                and are not tied to any session */
00219 #define EVT_HOUSE    51     /* as needed houskeeping stuff */
00220 #define EVT_SHUTDOWN 52     /* Server is shutting down */
00221 
00222 #define EVT_PURGEUSER       100    /* Deleting a user */
00223 #define EVT_NEWUSER  102    /* Creating a user */
00224 
00225 #define EVT_BEFOREREAD      200
00226 #define EVT_BEFORESAVE      201
00227 #define EVT_AFTERSAVE       202
00228 #define EVT_SMTPSCAN 203    /* called before submitting a msg from SMTP */
00229 /* Priority levels for paging functions (lower is better) */
00230 enum {
00231        XMSG_PRI_LOCAL,             /* Other users on -this- server */
00232        XMSG_PRI_REMOTE,     /* Other users on a Citadel network (future) */
00233        XMSG_PRI_FOREIGN,    /* Contacts on foreign instant message hosts */
00234        MAX_XMSG_PRI
00235 };
00236 
00237 
00238 /* Defines the relationship of a user to a particular room */
00239 typedef struct __visit {
00240        long v_roomnum;
00241        long v_roomgen;
00242        long v_usernum;
00243        long v_lastseen;
00244        unsigned int v_flags;
00245        char v_seen[SIZ];
00246        char v_answered[SIZ];
00247        int v_view;
00248 } visit;
00249 
00250 #define V_FORGET     1      /* User has zapped this room        */
00251 #define V_LOCKOUT    2      /* User is locked out of this room  */
00252 #define V_ACCESS     4      /* Access is granted to this room   */
00253 
00254 
00255 /* Supplementary data for a message on disk
00256  * These are kept separate from the message itself for one of two reasons:
00257  * 1. Either their values may change at some point after initial save, or
00258  * 2. They are merely caches of data which exist somewhere else, for speed.
00259  */
00260 struct MetaData {
00261        long meta_msgnum;           /* Message number in *local* message base */
00262        int meta_refcount;          /* Number of rooms pointing to this msg */
00263        char meta_content_type[64]; /* Cached MIME content-type */
00264        long meta_rfc822_length;    /* Cache of RFC822-translated msg length */
00265        char mimetype[64];              /* if we were able to guess the mimetype for the data */ 
00266 };
00267 
00268 /* Calls to AdjRefCount() are queued and deferred, so the user doesn't
00269  * have to wait for various disk-intensive operations to complete synchronously.
00270  * This is the record format.
00271  */
00272 struct arcq {
00273        long arcq_msgnum;           /* Message number being adjusted */
00274        int arcq_delta;                    /* Adjustment ( usually 1 or -1 ) */
00275 };
00276 
00277 
00278 /* 
00279  * Serialization routines use this struct to return a pointer and a length
00280  */
00281 struct ser_ret {
00282         size_t len;
00283         unsigned char *ser;
00284 };
00285 
00286 
00287 /*
00288  * The S_USETABLE database is used in several modules now, so we define its format here.
00289  */
00290 struct UseTable {
00291        char ut_msgid[SIZ];
00292        time_t ut_timestamp;
00293 };
00294 
00295 
00296 
00297 /* Preferred field order                                              */
00298 /*               **********               Important fields            */
00299 /*                         ***************       Semi-important fields              */
00300 /*                                        *      Message text (MUST be last) */
00301 #define FORDER       "IPTAFONHRDBCEWJGKLQSVXZYUM"
00302 
00303 #endif /* SERVER_H */