8 #define INLINE __inline__
15 #define OPENSSL_NO_KRB5 /* work around redhat b0rken ssl headers */
16 #include <openssl/ssl.h>
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
24 # include <sys/time.h>
31 * New format for a message in memory
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 unsigned int cm_flags; /* How to handle (NOT SAVED TO DISK) */
41 #define CTDLMESSAGE_MAGIC 0x159d
42 #define CM_SKIP_HOOKS 0x01 /* Don't run server-side handlers */
47 * Exit codes 101 through 109 are used for conditions in which
48 * we deliberately do NOT want the service to automatically
51 #define CTDLEXIT_CONFIG 101 /* Could not read citadel.config */
52 #define CTDLEXIT_CONTROL 102 /* Could not acquire lock */
53 #define CTDLEXIT_HOME 103 /* Citadel home directory not found */
54 #define CTDLEXIT_OOD 104 /* Out Of Date config - rerun setup */
55 #define CTDLEXIT_DB 105 /* Unable to initialize database */
56 #define CTDLEXIT_LIBCITADEL 106 /* Incorrect version of libcitadel */
62 * Here's the big one... the Citadel context structure.
64 * This structure keeps track of all information relating to a running
65 * session on the server. We keep one of these for each session thread.
69 struct CitContext *prev; /* Link to previous session in list */
70 struct CitContext *next; /* Link to next session in the list */
72 int state; /* thread state (see CON_ values below) */
73 int kill_me; /* Set to nonzero to flag for termination */
75 int cs_pid; /* session ID */
76 time_t lastcmd; /* time of last command executed */
77 time_t lastidle; /* For computing idle time */
79 char curr_user[USERNAME_SIZE]; /* name of current user */
80 int logged_in; /* logged in */
81 int internal_pgm; /* authenticated as internal program */
82 int nologin; /* not allowed to log in */
83 int is_local_socket; /* set to 1 if client is on unix domain sock */
84 int curr_view; /* The view type for the current user/room */
85 int is_master; /* Is this session logged in using the master user? */
87 char net_node[32] ;/* Is the client another Citadel server? */
88 time_t previous_login; /* Date/time of previous login */
89 char lastcmdname[5]; /* name of last command executed */
90 unsigned cs_flags; /* miscellaneous flags */
91 void (*h_command_function) (void) ; /* service command function */
92 void (*h_async_function) (void) ; /* do async msgs function */
93 void (*h_greeting_function) (void) ; /* service startup function */
94 int is_async; /* Nonzero if client accepts async msgs */
95 int async_waiting; /* Nonzero if there are async msgs waiting */
96 int input_waiting; /* Nonzero if there is client input waiting */
98 /* Client information */
99 int cs_clientdev; /* client developer ID */
100 int cs_clienttyp; /* client type code */
101 int cs_clientver; /* client version number */
102 char cs_clientname[32]; /* name of client software */
103 char cs_host[64]; /* host logged in from */
104 char cs_addr[64]; /* address logged in from */
106 /* The Internet type of thing */
107 char cs_inet_email[128]; /* Return address of outbound Internet mail */
108 char cs_inet_other_emails[1024]; /* User's other valid Internet email addresses */
109 char cs_inet_fn[128]; /* Friendly-name of outbound Internet mail */
111 FILE *download_fp; /* Fields relating to file transfer */
112 char download_desired_section[128];
115 char upl_path[PATH_MAX];
116 char upl_comment[256];
117 char upl_filedir[PATH_MAX];
121 struct ctdluser user; /* Database record buffers */
122 struct ctdlroom room;
124 /* Beginning of cryptography - session nonce */
125 char cs_nonce[NONCE_SIZE]; /* The nonce for this session's next auth transaction */
127 /* Redirect this session's output to a memory buffer? */
128 char *redirect_buffer; /* the buffer */
129 size_t redirect_len; /* length of data in buffer */
130 size_t redirect_alloc; /* length of allocated buffer */
137 char *output_buffer; /* hold output for one big dump */
140 /* A linked list of all instant messages sent to us. */
141 struct ExpressMessage *FirstExpressMessage;
142 int disable_exp; /* Set to 1 to disable incoming pages */
143 int newmail; /* Other sessions increment this */
145 /* Masqueraded values in the 'who is online' list */
146 char fake_username[USERNAME_SIZE];
147 char fake_hostname[64];
148 char fake_roomname[ROOMNAMELEN];
150 /* Preferred MIME formats */
151 char preferred_formats[256];
152 int msg4_dont_decode;
154 /* Dynamically allocated session data */
155 char *session_specific_data; /* Used by individual protocol modules */
156 struct cit_ical *CIT_ICAL; /* calendaring data */
157 struct ma_info *ma; /* multipart/alternative data */
158 const char* ServiceName; /**< whats our actual purpose? */
160 struct timeval client_expires_at; /** When this client will expire */
163 typedef struct CitContext t_context;
166 * Values for CitContext.state
168 * A session that is doing nothing is in CON_IDLE state. When activity
169 * is detected on the socket, it goes to CON_READY, indicating that it
170 * needs to have a worker thread bound to it. When a thread binds to
171 * the session, it goes to CON_EXECUTING and does its thing. When the
172 * transaction is finished, the thread sets it back to CON_IDLE and lets
176 CON_IDLE, /* This context is doing nothing */
177 CON_START, /* This context is starting up */
178 CON_READY, /* This context needs attention */
179 CON_EXECUTING /* This context is bound to a thread */
183 #define CS_STEALTH 1 /* stealth mode */
184 #define CS_CHAT 2 /* chat mode */
185 #define CS_POSTING 4 /* Posting */
187 struct CitContext *MyContext(void);
188 #define CC MyContext()
191 * This is the control record for the message base...
194 long MMhighest; /* highest message number in file */
195 unsigned MMflags; /* Global system flags */
196 long MMnextuser; /* highest user number on system */
197 long MMnextroom; /* highest room number on system */
198 int version; /* Server-hosted upgrade level */
199 int fulltext_wordbreaker; /* ID of wordbreaker in use */
200 long MMfulltext; /* highest message number indexed */
203 extern struct CitContext *ContextList;
204 extern int ScheduledShutdown;
205 extern struct CitControl CitControl;
207 struct ExpressMessage {
208 struct ExpressMessage *next;
209 time_t timestamp; /* When this message was sent */
210 unsigned flags; /* Special instructions */
211 char sender[256]; /* Name of sending user */
212 char sender_email[256]; /* Email or JID of sending user */
213 char *text; /* Message text (if applicable) */
216 #define EM_BROADCAST 1 /* Broadcast message */
217 #define EM_GO_AWAY 2 /* Server requests client log off */
218 #define EM_CHAT 4 /* Server requests client enter chat */
221 struct ChatLine *next;
225 char chat_username[USERNAME_SIZE];
226 char chat_room[ROOMNAMELEN];
230 * Various things we need to lock and unlock
273 * message transfer formats
276 MT_CITADEL, /* Citadel proprietary */
277 MT_RFC822, /* RFC822 */
278 MT_MIME, /* MIME-formatted message */
279 MT_DOWNLOAD, /* Download a component */
280 MT_SPEW_SECTION /* Download a component in a single operation */
284 * Message format types in the database
286 #define FMT_CITADEL 0 /* Citadel vari-format (proprietary) */
287 #define FMT_FIXED 1 /* Fixed format (proprietary) */
288 #define FMT_RFC822 4 /* Standard (headers are in M field) */
292 * Citadel DataBases (define one for each cdb we need to open)
295 CDB_MSGMAIN, /* message base */
296 CDB_USERS, /* user file */
297 CDB_ROOMS, /* room index */
298 CDB_FLOORTAB, /* floor index */
299 CDB_MSGLISTS, /* room message lists */
300 CDB_VISIT, /* user/room relationships */
301 CDB_DIRECTORY, /* address book directory */
302 CDB_USETABLE, /* network use table */
303 CDB_BIGMSGS, /* larger message bodies */
304 CDB_FULLTEXT, /* full text search index */
305 CDB_EUIDINDEX, /* locate msgs by EUID */
306 MAXCDB /* total number of CDB's defined */
316 * Event types can't be enum'ed, because they must remain consistent between
317 * builds (to allow for binary modules built somewhere else)
319 #define EVT_STOP 0 /* Session is terminating */
320 #define EVT_START 1 /* Session is starting */
321 #define EVT_LOGIN 2 /* A user is logging in */
322 #define EVT_NEWROOM 3 /* Changing rooms */
323 #define EVT_LOGOUT 4 /* A user is logging out */
324 #define EVT_SETPASS 5 /* Setting or changing password */
325 #define EVT_CMD 6 /* Called after each server command */
326 #define EVT_RWHO 7 /* An RWHO command is being executed */
327 #define EVT_ASYNC 8 /* Doing asynchronous messages */
328 #define EVT_STEALTH 9 /* Entering stealth mode */
329 #define EVT_UNSTEALTH 10 /* Exiting stealth mode */
331 #define EVT_TIMER 50 /* Timer events are called once per minute
332 and are not tied to any session */
333 #define EVT_HOUSE 51 /* as needed houskeeping stuff */
335 #define EVT_PURGEUSER 100 /* Deleting a user */
336 #define EVT_NEWUSER 102 /* Creating a user */
338 #define EVT_BEFOREREAD 200
339 #define EVT_BEFORESAVE 201
340 #define EVT_AFTERSAVE 202
341 #define EVT_SMTPSCAN 203 /* called before submitting a msg from SMTP */
342 /* Priority levels for paging functions (lower is better) */
344 XMSG_PRI_LOCAL, /* Other users on -this- server */
345 XMSG_PRI_REMOTE, /* Other users on a Citadel network (future) */
346 XMSG_PRI_FOREIGN, /* Contacts on foreign instant message hosts */
351 /* Defines the relationship of a user to a particular room */
357 unsigned int v_flags;
359 char v_answered[SIZ];
363 #define V_FORGET 1 /* User has zapped this room */
364 #define V_LOCKOUT 2 /* User is locked out of this room */
365 #define V_ACCESS 4 /* Access is granted to this room */
368 /* Supplementary data for a message on disk
369 * These are kept separate from the message itself for one of two reasons:
370 * 1. Either their values may change at some point after initial save, or
371 * 2. They are merely caches of data which exist somewhere else, for speed.
374 long meta_msgnum; /* Message number in *local* message base */
375 int meta_refcount; /* Number of rooms pointing to this msg */
376 char meta_content_type[64]; /* Cached MIME content-type */
377 long meta_rfc822_length; /* Cache of RFC822-translated msg length */
380 /* Calls to AdjRefCount() are queued and deferred, so the user doesn't
381 * have to wait for various disk-intensive operations to complete synchronously.
382 * This is the record format.
385 long arcq_msgnum; /* Message number being adjusted */
386 int arcq_delta; /* Adjustment ( usually 1 or -1 ) */
391 * Serialization routines use this struct to return a pointer and a length
400 * The S_USETABLE database is used in several modules now, so we define its format here.
409 /* Preferred field order */
410 /* ********** Important fields */
411 /* *************** Semi-important fields */
412 /* * Message text (MUST be last) */
413 #define FORDER "IPTAFONHRDBCEJGKLQSVWXZYUM"
415 #endif /* SERVER_H */