citadel
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)  

context.h
Go to the documentation of this file.
1
2#ifndef CONTEXT_H
3#define CONTEXT_H
4
5#include <stdarg.h>
6#include "sysdep.h"
7#include "server.h"
8#include "sysdep_decls.h"
9#include "threads.h"
10
11
12/*
13 * Values for CitContext.state
14 *
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
20 * it go.
21 */
22typedef 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 */
30
31#ifndef __CIT_CONTEXT__
32#define __CIT_CONTEXT__
33typedef struct CitContext CitContext;
34#endif
35
36/*
37 * This structure keeps track of all information relating to a running
38 * session on the server. We keep one of these for each session.
39 */
40struct CitContext {
41 CitContext *prev; /* Link to previous session in list */
42 CitContext *next; /* Link to next session in the list */
43
44 int cs_pid; /* session ID */
45 int dont_term; /* for special activities like artv so we don't get killed */
46 double created; /* time of birth */
47 time_t lastcmd; /* time of last command executed */
48 time_t lastidle; /* For computing idle time */
49 CCState state; /* thread state (see CON_ values below) */
50 int kill_me; /* Set to nonzero to flag for termination */
51
52 IOBuffer SendBuf, /* Our write Buffer */
53 RecvBuf, /* Our block buffered read buffer */
54 SBuf; /* Our block buffered read buffer for clients */
55
56 StrBuf *MigrateBuf; /* Our block buffered read buffer */
57 StrBuf *sMigrateBuf; /* Our block buffered read buffer */
58
60 int is_local_client; /* set to 1 if client is running on the same host */
61 /* Redirect this session's output to a memory buffer? */
62 StrBuf *redirect_buffer; /* the buffer */
64#ifdef HAVE_OPENSSL
65 SSL *ssl;
66 int redirect_ssl;
67#endif
68
69 char curr_user[USERNAME_SIZE]; /* name of current user */
70 int logged_in; /* logged in? */
71 int internal_pgm; /* authenticated as internal program? */
72 int nologin; /* not allowed to log in */
73 int curr_view; /* The view type for the current user/room */
74
75 time_t previous_login; /* Date/time of previous login */
76 char lastcmdname[5]; /* name of last command executed */
77 unsigned cs_flags; /* miscellaneous flags */
78 int is_async; /* Nonzero if client accepts async msgs */
79 int async_waiting; /* Nonzero if there are async msgs waiting */
80 int input_waiting; /* Nonzero if there is client input waiting */
81 int can_receive_im; /* Session is capable of receiving instant messages */
82
83 /* Client information */
84 int cs_clientdev; /* client developer ID */
85 int cs_clienttyp; /* client type code */
86 int cs_clientver; /* client version number */
87 char cs_clientinfo[256];/* if its a unix domain socket, some info for logging. */
88 uid_t cs_UDSclientUID; /* the uid of the client when talking via UDS */
89 char cs_clientname[32]; /* name of client software */
90 char cs_host[64]; /* host logged in from */
91 char cs_addr[64]; /* address logged in from */
92
93 /* The Internet type of thing */
94 char cs_principal_id[256]; /* User principal identity for XMPP, ActivityPub, etc. */
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 */
98
99 FILE *download_fp; /* Fields relating to file transfer */
103 char upl_file[256];
104 char upl_path[PATH_MAX];
105 char upl_comment[256];
106 char upl_filedir[PATH_MAX];
107 char upl_mimetype[64];
108
109 struct ctdluser user; /* Database record buffers */
111
112 /* A linked list of all instant messages sent to us. */
114 int disable_exp; /* Set to 1 to disable incoming pages */
115 int newmail; /* Other sessions increment this */
116
117 /* Preferred MIME formats */
120
121 /* Dynamically allocated session data */
122 void *session_specific_data; /* Used by individual protocol modules */
123 struct cit_ical *CIT_ICAL; /* calendaring data */
124 struct ma_info *ma; /* multipart/alternative data */
125 const char *ServiceName; /* readable purpose of this session */
127 void *openid_data; /* Data stored by the OpenID module */
128 char *ldap_dn; /* DN of user when using AUTHMODE_LDAP */
129
130 void (*h_command_function) (void) ; /* service command function */
131 void (*h_async_function) (void) ; /* do async msgs function */
132 void (*h_greeting_function) (void) ; /* greeting function for session startup */
133
134 long *cached_msglist; /* results of the previous CtdlForEachMessage() */
136
137 char vcard_updated_by_ldap; /* !0 iff ldap changed the vcard, treat as aide update */
138};
139
140#define CC MyContext()
141
142extern pthread_key_t MyConKey; /* TSD key for MyContext() */
143extern int num_sessions;
144extern CitContext masterCC;
145extern CitContext *ContextList;
146
147CitContext *MyContext (void);
148void RemoveContext (struct CitContext *);
150void context_cleanup(void);
151void kill_session (int session_to_kill);
152void InitializeMasterCC(void);
153void dead_session_purge(int force);
154void set_async_waiting(struct CitContext *ccptr);
155
157
158/* forcibly close and flush fd's on shutdown */
159void terminate_all_sessions(void);
160
161/* Deprecated, user CtdlBumpNewMailCounter() instead */
162void BumpNewMailCounter(long) __attribute__ ((deprecated));
163
164void terminate_idle_sessions(void);
165int CtdlTerminateOtherSession (int session_num);
166/* bits returned by CtdlTerminateOtherSession */
167#define TERM_FOUND 0x01
168#define TERM_ALLOWED 0x02
169#define TERM_KILLED 0x03
170#define TERM_NOTALLOWED -1
171
172/*
173 * Bind a thread to a context. (It's inline merely to speed things up.)
174 */
175static INLINE void become_session(CitContext *which_con) {
176 pthread_setspecific(MyConKey, (void *)which_con );
177}
178
179#endif /* CONTEXT_H */
#define USERNAME_SIZE
Definition: citadel.h:57
void terminate_all_sessions(void)
Definition: context.c:252
void terminate_idle_sessions(void)
Definition: context.c:215
int num_sessions
Definition: context.c:24
void InitializeMasterCC(void)
Definition: context.c:691
CitContext * MyContext(void)
Definition: context.c:201
CitContext * ContextList
Definition: context.c:22
CitContext masterCC
Definition: context.c:21
void kill_session(int session_to_kill)
CitContext * CreateNewContext(void)
Definition: context.c:336
enum __CCState CCState
pthread_key_t MyConKey
Definition: context.c:20
static void become_session(CitContext *which_con)
Definition: context.h:175
int CtdlTerminateOtherSession(int session_num)
Definition: context.c:81
void set_async_waiting(struct CitContext *ccptr)
Definition: context.c:704
void dead_session_purge(int force)
Definition: context.c:631
void context_cleanup(void)
Definition: context.c:592
CitContext * CloneContext(CitContext *CloneMe)
Definition: context.c:385
void BumpNewMailCounter(long)
Definition: context.c:125
void RemoveContext(struct CitContext *)
Definition: context.c:278
__CCState
Definition: context.h:22
@ CON_READY
Definition: context.h:26
@ CON_SYS
Definition: context.h:28
@ CON_IDLE
Definition: context.h:23
@ CON_EXECUTING
Definition: context.h:27
@ CON_GREETING
Definition: context.h:24
@ CON_STARTING
Definition: context.h:25
#define INLINE
Definition: server.h:21
int cs_pid
Definition: context.h:44
char upl_mimetype[64]
Definition: context.h:107
int curr_view
Definition: context.h:73
int logged_in
Definition: context.h:70
char preferred_formats[256]
Definition: context.h:118
StrBuf * MigrateBuf
Definition: context.h:56
char cs_inet_other_emails[1024]
Definition: context.h:96
char lastcmdname[5]
Definition: context.h:76
char upl_path[PATH_MAX]
Definition: context.h:104
long tcp_port
Definition: context.h:126
int cs_clienttyp
Definition: context.h:85
int cs_clientdev
Definition: context.h:84
char cs_clientname[32]
Definition: context.h:89
FILE * download_fp
Definition: context.h:99
char cs_inet_fn[128]
Definition: context.h:97
StrBuf * StatusMessage
Definition: context.h:63
int is_async
Definition: context.h:78
struct ctdluser user
Definition: context.h:109
time_t lastidle
Definition: context.h:48
int newmail
Definition: context.h:115
struct cit_ical * CIT_ICAL
Definition: context.h:123
const char * ServiceName
Definition: context.h:125
CitContext * next
Definition: context.h:42
unsigned cs_flags
Definition: context.h:77
char download_desired_section[128]
Definition: context.h:101
int nologin
Definition: context.h:72
CitContext * prev
Definition: context.h:41
char curr_user[64]
Definition: context.h:69
void * session_specific_data
Definition: context.h:122
char upl_file[256]
Definition: context.h:103
IOBuffer SBuf
Definition: context.h:54
char cs_addr[64]
Definition: context.h:91
void * openid_data
Definition: context.h:127
int can_receive_im
Definition: context.h:81
StrBuf * sMigrateBuf
Definition: context.h:57
FILE * upload_fp
Definition: context.h:102
int cs_clientver
Definition: context.h:86
struct ExpressMessage * FirstExpressMessage
Definition: context.h:113
int kill_me
Definition: context.h:50
CCState state
Definition: context.h:49
int cached_num_msgs
Definition: context.h:135
char cs_principal_id[256]
Definition: context.h:94
int disable_exp
Definition: context.h:114
struct ma_info * ma
Definition: context.h:124
void(* h_greeting_function)(void)
Definition: context.h:132
int is_local_client
Definition: context.h:60
void(* h_command_function)(void)
Definition: context.h:130
time_t lastcmd
Definition: context.h:47
StrBuf * redirect_buffer
Definition: context.h:62
int async_waiting
Definition: context.h:79
char cs_inet_email[128]
Definition: context.h:95
char upl_comment[256]
Definition: context.h:105
IOBuffer SendBuf
Definition: context.h:52
char * ldap_dn
Definition: context.h:128
int dont_term
Definition: context.h:45
time_t previous_login
Definition: context.h:75
size_t download_fp_total
Definition: context.h:100
char cs_host[64]
Definition: context.h:90
char vcard_updated_by_ldap
Definition: context.h:137
void(* h_async_function)(void)
Definition: context.h:131
long * cached_msglist
Definition: context.h:134
int msg4_dont_decode
Definition: context.h:119
uid_t cs_UDSclientUID
Definition: context.h:88
int client_socket
Definition: context.h:59
char upl_filedir[PATH_MAX]
Definition: context.h:106
double created
Definition: context.h:46
int input_waiting
Definition: context.h:80
IOBuffer RecvBuf
Definition: context.h:53
int internal_pgm
Definition: context.h:71
struct ctdlroom room
Definition: context.h:110
char cs_clientinfo[256]
Definition: context.h:87