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)  

No Matches
Go to the documentation of this file.
2#ifndef CONTEXT_H
3#define CONTEXT_H
5#include <stdarg.h>
6#include "sysdep.h"
7#include "server.h"
8#include "sysdep_decls.h"
9#include "threads.h"
12// Values for CitContext.state
14// A session that is doing nothing is in CON_IDLE state. When activity
15// is detected on the socket, it goes to CON_READY, indicating that it
16// needs to have a worker thread bound to it. When a thread binds to
17// the session, it goes to CON_EXECUTING and does its thing. When the
18// transaction is finished, the thread sets it back to CON_IDLE and lets
19// it go.
20typedef enum __CCState {
21 CON_IDLE, // This context is doing nothing
22 CON_GREETING, // This context needs to output its greeting
23 CON_STARTING, // This context is outputting its greeting
24 CON_READY, // This context needs attention
25 CON_EXECUTING, // This context is bound to a thread
26 CON_SYS // This is a system context and mustn't be purged
29#ifndef __CIT_CONTEXT__
30#define __CIT_CONTEXT__
31typedef struct CitContext CitContext;
34// This structure keeps track of all information relating to a running
35// session on the server. We keep one of these for each session.
36struct CitContext {
37 CitContext *prev; // Link to previous session in list
38 CitContext *next; // Link to next session in the list
40 int cs_pid; // session ID
41 double created; // time of birth
42 time_t lastcmd; // time of last command executed
43 time_t lastidle; // For computing idle time
44 CCState state; // thread state (see CON_ values below)
45 int kill_me; // Set to nonzero to flag for termination
47 IOBuffer SendBuf, // Our write Buffer
48 RecvBuf, // Our block buffered read buffer
49 SBuf; // Our block buffered read buffer for clients
51 StrBuf *MigrateBuf; // Our block buffered read buffer
52 StrBuf *sMigrateBuf; // Our block buffered read buffer
55 int is_local_client; // set to 1 if client is running on the same host
56 // Redirect this session's output to a memory buffer?
57 StrBuf *redirect_buffer; // the buffer
60 SSL *ssl;
61 int redirect_ssl;
64 char curr_user[USERNAME_SIZE]; // name of current user
65 int logged_in; // logged in?
66 int internal_pgm; // authenticated as internal program?
67 int nologin; // not allowed to log in
68 int curr_view; // The view type for the current user/room
70 time_t previous_login; // Date/time of previous login
71 char lastcmdname[5]; // name of last command executed
72 unsigned cs_flags; // miscellaneous flags
73 int is_async; // Nonzero if client accepts async msgs
74 int async_waiting; // Nonzero if there are async msgs waiting
75 int input_waiting; // Nonzero if there is client input waiting
76 int can_receive_im; // Session is capable of receiving instant messages
78 // Client information
79 char cs_clientinfo[256];// if its a unix domain socket, some info for logging.
80 uid_t cs_UDSclientUID; // the uid of the client when talking via UDS
81 char cs_clientname[32]; // name of client software
82 char cs_host[64]; // host logged in from
83 char cs_addr[64]; // address logged in from
85 // The Internet type of thing
86 char cs_principal_id[256]; // User principal identity for XMPP, ActivityPub, etc.
87 char cs_inet_email[128]; // Return address of outbound Internet mail
88 char cs_inet_other_emails[1024]; // User's other valid Internet email addresses
89 char cs_inet_fn[128]; // Friendly-name of outbound Internet mail
91 FILE *download_fp; // Fields relating to file transfer
94 FILE *upload_fp;
95 char upl_file[256];
96 char upl_path[PATH_MAX];
97 char upl_comment[256];
98 char upl_filedir[PATH_MAX];
99 char upl_mimetype[64];
101 struct ctdluser user; // Database record buffers
104 // A linked list of all instant messages sent to us.
106 int disable_exp; // Set to 1 to disable incoming pages
107 int newmail; // Other sessions increment this
109 // Preferred MIME formats
113 // Dynamically allocated session data
114 void *session_specific_data; // Used by individual protocol modules
115 struct cit_ical *CIT_ICAL; // calendaring data
116 struct ma_info *ma; // multipart/alternative data
117 const char *ServiceName; // readable purpose of this session
119 char *ldap_dn; // DN of user when using AUTHMODE_LDAP
121 void (*h_command_function) (void) ; // service command function
122 void (*h_async_function) (void) ; // do async msgs function
123 void (*h_greeting_function) (void) ; // greeting function for session startup
125 long *cached_msglist; // results of the previous CtdlForEachMessage()
128 char vcard_updated_by_ldap; // !0 iff ldap changed the vcard, treat as aide update
131#define CC MyContext()
133extern pthread_key_t MyConKey; // TSD key for MyContext()
134extern int num_sessions;
135extern CitContext masterCC;
136extern CitContext *ContextList;
138CitContext *MyContext (void);
139void RemoveContext (struct CitContext *);
141void context_cleanup(void);
142void kill_session (int session_to_kill);
143void InitializeMasterCC(void);
144void dead_session_purge(int force);
145void set_async_waiting(struct CitContext *ccptr);
149// forcibly close and flush fd's on shutdown
150void terminate_all_sessions(void);
152void terminate_idle_sessions(void);
153int CtdlTerminateOtherSession (int session_num);
154// bits returned by CtdlTerminateOtherSession
155#define TERM_FOUND 0x01
156#define TERM_ALLOWED 0x02
157#define TERM_KILLED 0x03
158#define TERM_NOTALLOWED -1
160// Bind a thread to a context. (It's inline merely to speed things up.)
161static INLINE void become_session(CitContext *which_con) {
162 pthread_setspecific(MyConKey, (void *)which_con );
165#endif // CONTEXT_H
void terminate_all_sessions(void)
Definition context.c:207
void terminate_idle_sessions(void)
Definition context.c:182
int num_sessions
Definition context.c:21
void InitializeMasterCC(void)
Definition context.c:548
CitContext * MyContext(void)
Definition context.c:172
CitContext * ContextList
Definition context.c:20
CitContext masterCC
Definition context.c:19
void kill_session(int session_to_kill)
CitContext * CreateNewContext(void)
Definition context.c:269
enum __CCState CCState
pthread_key_t MyConKey
Definition context.c:18
int CtdlTerminateOtherSession(int session_num)
Definition context.c:71
void set_async_waiting(struct CitContext *ccptr)
Definition context.c:556
void dead_session_purge(int force)
Definition context.c:492
void context_cleanup(void)
Definition context.c:462
static INLINE void become_session(CitContext *which_con)
Definition context.h:161
CitContext * CloneContext(CitContext *CloneMe)
Definition context.c:305
void RemoveContext(struct CitContext *)
Definition context.c:228
Definition context.h:20
Definition context.h:24
Definition context.h:26
Definition context.h:21
Definition context.h:25
Definition context.h:22
Definition context.h:23
#define INLINE
Definition server.h:14
int cs_pid
Definition context.h:40
char upl_mimetype[64]
Definition context.h:99
int curr_view
Definition context.h:68
int logged_in
Definition context.h:65
char preferred_formats[256]
Definition context.h:110
StrBuf * MigrateBuf
Definition context.h:51
char cs_inet_other_emails[1024]
Definition context.h:88
char lastcmdname[5]
Definition context.h:71
char upl_path[PATH_MAX]
Definition context.h:96
long tcp_port
Definition context.h:118
char cs_clientname[32]
Definition context.h:81
FILE * download_fp
Definition context.h:91
char cs_inet_fn[128]
Definition context.h:89
StrBuf * StatusMessage
Definition context.h:58
int is_async
Definition context.h:73
struct ctdluser user
Definition context.h:101
time_t lastidle
Definition context.h:43
int newmail
Definition context.h:107
struct cit_ical * CIT_ICAL
Definition context.h:115
const char * ServiceName
Definition context.h:117
CitContext * next
Definition context.h:38
unsigned cs_flags
Definition context.h:72
char download_desired_section[128]
Definition context.h:93
int nologin
Definition context.h:67
CitContext * prev
Definition context.h:37
char curr_user[64]
Definition context.h:64
void * session_specific_data
Definition context.h:114
char upl_file[256]
Definition context.h:95
IOBuffer SBuf
Definition context.h:49
char cs_addr[64]
Definition context.h:83
int can_receive_im
Definition context.h:76
StrBuf * sMigrateBuf
Definition context.h:52
FILE * upload_fp
Definition context.h:94
struct ExpressMessage * FirstExpressMessage
Definition context.h:105
int kill_me
Definition context.h:45
CCState state
Definition context.h:44
int cached_num_msgs
Definition context.h:126
char cs_principal_id[256]
Definition context.h:86
int disable_exp
Definition context.h:106
struct ma_info * ma
Definition context.h:116
void(* h_greeting_function)(void)
Definition context.h:123
int is_local_client
Definition context.h:55
void(* h_command_function)(void)
Definition context.h:121
time_t lastcmd
Definition context.h:42
StrBuf * redirect_buffer
Definition context.h:57
int async_waiting
Definition context.h:74
char cs_inet_email[128]
Definition context.h:87
char upl_comment[256]
Definition context.h:97
IOBuffer SendBuf
Definition context.h:47
char * ldap_dn
Definition context.h:119
time_t previous_login
Definition context.h:70
size_t download_fp_total
Definition context.h:92
char cs_host[64]
Definition context.h:82
char vcard_updated_by_ldap
Definition context.h:128
void(* h_async_function)(void)
Definition context.h:122
long * cached_msglist
Definition context.h:125
int msg4_dont_decode
Definition context.h:111
uid_t cs_UDSclientUID
Definition context.h:80
int client_socket
Definition context.h:54
char upl_filedir[PATH_MAX]
Definition context.h:98
double created
Definition context.h:41
int input_waiting
Definition context.h:75
IOBuffer RecvBuf
Definition context.h:48
int internal_pgm
Definition context.h:66
struct ctdlroom room
Definition context.h:102
char cs_clientinfo[256]
Definition context.h:79