8 #include "sysdep_decls.h"
13 * Values for CitContext.state
15 * A session that is doing nothing is in CON_IDLE state. When activity
16 * is detected on the socket, it goes to CON_READY, indicating that it
17 * needs to have a worker thread bound to it. When a thread binds to
18 * the session, it goes to CON_EXECUTING and does its thing. When the
19 * transaction is finished, the thread sets it back to CON_IDLE and lets
22 typedef enum __CCState {
23 CON_IDLE, /* This context is doing nothing */
24 CON_GREETING, /* This context needs to output its greeting */
25 CON_STARTING, /* This context is outputting its greeting */
26 CON_READY, /* This context needs attention */
27 CON_EXECUTING, /* This context is bound to a thread */
28 CON_SYS /* This is a system context and mustn't be purged */
33 * Here's the big one... the Citadel context structure.
35 * This structure keeps track of all information relating to a running
36 * session on the server. We keep one of these for each session thread.
40 struct CitContext *prev; /* Link to previous session in list */
41 struct CitContext *next; /* Link to next session in the list */
43 int cs_pid; /* session ID */
44 int dont_term; /* for special activities like artv so we don't get killed */
45 double created; /* time of birth */
46 time_t lastcmd; /* time of last command executed */
47 time_t lastidle; /* For computing idle time */
48 CCState state; /* thread state (see CON_ values below) */
49 int kill_me; /* Set to nonzero to flag for termination */
51 IOBuffer SendBuf, /* Our write Buffer */
52 RecvBuf, /* Our block buffered read buffer */
53 SBuf; /* Our block buffered read buffer for clients */
55 StrBuf *MigrateBuf; /* Our block buffered read buffer */
56 StrBuf *sMigrateBuf; /* Our block buffered read buffer */
59 int is_local_socket; /* set to 1 if client is on unix domain sock */
60 /* Redirect this session's output to a memory buffer? */
61 StrBuf *redirect_buffer; /* the buffer */
62 StrBuf *StatusMessage;
68 char curr_user[USERNAME_SIZE]; /* name of current user */
69 int logged_in; /* logged in */
70 int internal_pgm; /* authenticated as internal program */
71 int nologin; /* not allowed to log in */
72 int curr_view; /* The view type for the current user/room */
73 int is_master; /* Is this session logged in using the master user? */
75 char net_node[32] ;/* Is the client another Citadel server? */
76 time_t previous_login; /* Date/time of previous login */
77 char lastcmdname[5]; /* name of last command executed */
78 unsigned cs_flags; /* miscellaneous flags */
79 int is_async; /* Nonzero if client accepts async msgs */
80 int async_waiting; /* Nonzero if there are async msgs waiting */
81 int input_waiting; /* Nonzero if there is client input waiting */
82 int can_receive_im; /* Session is capable of receiving instant messages */
84 /* Client information */
85 int cs_clientdev; /* client developer ID */
86 int cs_clienttyp; /* client type code */
87 int cs_clientver; /* client version number */
88 char cs_clientinfo[256];/* if its a unix domain socket, some info for logging. */
89 uid_t cs_UDSclientUID; /* the uid of the client when talking via UDS */
90 char cs_clientname[32]; /* name of client software */
91 char cs_host[64]; /* host logged in from */
92 char cs_addr[64]; /* address logged in from */
94 /* The Internet type of thing */
95 char cs_inet_email[128]; /* Return address of outbound Internet mail */
96 char cs_inet_other_emails[1024]; /* User's other valid Internet email addresses */
97 char cs_inet_fn[128]; /* Friendly-name of outbound Internet mail */
99 FILE *download_fp; /* Fields relating to file transfer */
100 size_t download_fp_total;
101 char download_desired_section[128];
104 char upl_path[PATH_MAX];
105 char upl_comment[256];
106 char upl_filedir[PATH_MAX];
107 char upl_mimetype[64];
111 struct ctdluser user; /* Database record buffers */
112 struct ctdlroom room;
114 /* A linked list of all instant messages sent to us. */
115 struct ExpressMessage *FirstExpressMessage;
116 int disable_exp; /* Set to 1 to disable incoming pages */
117 int newmail; /* Other sessions increment this */
119 /* Masqueraded values in the 'who is online' list */
120 char fake_username[USERNAME_SIZE];
121 char fake_hostname[64];
122 char fake_roomname[ROOMNAMELEN];
124 /* Preferred MIME formats */
125 char preferred_formats[256];
126 int msg4_dont_decode;
128 /* Dynamically allocated session data */
129 char *session_specific_data; /* Used by individual protocol modules */
130 struct cit_ical *CIT_ICAL; /* calendaring data */
131 struct ma_info *ma; /* multipart/alternative data */
132 const char *ServiceName; /* readable purpose of this session */
134 void *openid_data; /* Data stored by the OpenID module */
135 char *ldap_dn; /* DN of user when using AUTHMODE_LDAP */
137 void (*h_command_function) (void) ; /* service command function */
138 void (*h_async_function) (void) ; /* do async msgs function */
139 void (*h_greeting_function) (void) ; /* greeting function for session startup */
141 long *cached_msglist; /* results of the previous CtdlForEachMessage() */
145 typedef struct CitContext CitContext;
148 #define CC MyContext()
151 extern pthread_key_t MyConKey; /* TSD key for MyContext() */
152 extern int num_sessions;
153 extern CitContext masterCC;
154 extern CitContext *ContextList;
156 CitContext *MyContext (void);
157 void RemoveContext (struct CitContext *);
158 CitContext *CreateNewContext (void);
159 void context_cleanup(void);
160 void kill_session (int session_to_kill);
161 void InitializeMasterCC(void);
162 void dead_session_purge(int force);
163 void set_async_waiting(struct CitContext *ccptr);
165 CitContext *CloneContext(CitContext *CloneMe);
167 /* forcibly close and flush fd's on shutdown */
168 void terminate_all_sessions(void);
170 /* Deprecated, user CtdlBumpNewMailCounter() instead */
171 void BumpNewMailCounter(long) __attribute__ ((deprecated));
173 void terminate_idle_sessions(void);
174 int CtdlTerminateOtherSession (int session_num);
175 /* bits returned by CtdlTerminateOtherSession */
176 #define TERM_FOUND 0x01
177 #define TERM_ALLOWED 0x02
178 #define TERM_KILLED 0x03
179 #define TERM_NOTALLOWED -1
182 * Bind a thread to a context. (It's inline merely to speed things up.)
184 static INLINE void become_session(CitContext *which_con) {
186 pid_t tid = syscall(SYS_gettid);
188 pthread_setspecific(MyConKey, (void *)which_con );
190 syslog(LOG_DEBUG, "[%d]: Now doing %s\n",
192 ((which_con != NULL) && (which_con->ServiceName != NULL)) ?
193 which_con->ServiceName:"");
199 /* typedef void (*CtdlDbgFunction) (const int); */
201 extern int DebugSession;
202 #define CONDBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (DebugSession != 0))
204 #define CON_syslog(LEVEL, FORMAT, ...) \
205 CONDBGLOG(LEVEL) syslog(LEVEL, \
206 "Context: " FORMAT, __VA_ARGS__)
208 #define CONM_syslog(LEVEL, FORMAT) \
209 CONDBGLOG(LEVEL) syslog(LEVEL, \
213 #endif /* CONTEXT_H */