8 #include "sysdep_decls.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
20 typedef 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__
31 typedef 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.
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
58 StrBuf *StatusMessage;
62 char curr_user[USERNAME_SIZE]; // name of current user
63 int logged_in; // logged in?
64 int internal_pgm; // authenticated as internal program?
65 int nologin; // not allowed to log in
66 int curr_view; // The view type for the current user/room
68 time_t previous_login; // Date/time of previous login
69 char lastcmdname[5]; // name of last command executed
70 unsigned cs_flags; // miscellaneous flags
71 int is_async; // Nonzero if client accepts async msgs
72 int async_waiting; // Nonzero if there are async msgs waiting
73 int input_waiting; // Nonzero if there is client input waiting
74 int can_receive_im; // Session is capable of receiving instant messages
77 char cs_clientinfo[256];// if its a unix domain socket, some info for logging.
78 uid_t cs_UDSclientUID; // the uid of the client when talking via UDS
79 char cs_clientname[32]; // name of client software
80 char cs_host[64]; // host logged in from
81 char cs_addr[64]; // address logged in from
83 // The Internet type of thing
84 char cs_principal_id[256]; // User principal identity for XMPP, ActivityPub, etc.
85 char cs_inet_email[128]; // Return address of outbound Internet mail
86 char cs_inet_other_emails[1024]; // User's other valid Internet email addresses
87 char cs_inet_fn[128]; // Friendly-name of outbound Internet mail
89 FILE *download_fp; // Fields relating to file transfer
90 size_t download_fp_total;
91 char download_desired_section[128];
94 char upl_path[PATH_MAX];
95 char upl_comment[256];
96 char upl_filedir[PATH_MAX];
97 char upl_mimetype[64];
99 struct ctdluser user; // Database record buffers
100 struct ctdlroom room;
102 // A linked list of all instant messages sent to us.
103 struct ExpressMessage *FirstExpressMessage;
104 int disable_exp; // Set to 1 to disable incoming pages
105 int newmail; // Other sessions increment this
107 // Preferred MIME formats
108 char preferred_formats[256];
109 int msg4_dont_decode;
111 // Dynamically allocated session data
112 void *session_specific_data; // Used by individual protocol modules
113 struct cit_ical *CIT_ICAL; // calendaring data
114 struct ma_info *ma; // multipart/alternative data
115 const char *ServiceName; // readable purpose of this session
117 char *ldap_dn; // DN of user when using AUTHMODE_LDAP
119 void (*h_command_function) (void) ; // service command function
120 void (*h_async_function) (void) ; // do async msgs function
121 void (*h_greeting_function) (void) ; // greeting function for session startup
123 long *cached_msglist; // results of the previous CtdlForEachMessage()
126 char vcard_updated_by_ldap; // !0 iff ldap changed the vcard, treat as aide update
129 #define CC MyContext()
131 extern pthread_key_t MyConKey; // TSD key for MyContext()
132 extern int num_sessions;
133 extern CitContext masterCC;
134 extern CitContext *ContextList;
136 CitContext *MyContext (void);
137 void RemoveContext (struct CitContext *);
138 CitContext *CreateNewContext (void);
139 void context_cleanup(void);
140 void kill_session (int session_to_kill);
141 void InitializeMasterCC(void);
142 void dead_session_purge(int force);
143 void set_async_waiting(struct CitContext *ccptr);
145 CitContext *CloneContext(CitContext *CloneMe);
147 // forcibly close and flush fd's on shutdown
148 void terminate_all_sessions(void);
150 void terminate_idle_sessions(void);
151 int CtdlTerminateOtherSession (int session_num);
152 // bits returned by CtdlTerminateOtherSession
153 #define TERM_FOUND 0x01
154 #define TERM_ALLOWED 0x02
155 #define TERM_KILLED 0x03
156 #define TERM_NOTALLOWED -1
158 // Bind a thread to a context. (It's inline merely to speed things up.)
159 static INLINE void become_session(CitContext *which_con) {
160 pthread_setspecific(MyConKey, (void *)which_con );