]> code.citadel.org Git - citadel.git/blob - citadel/context.h
.debs: export the cflags
[citadel.git] / citadel / context.h
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  * Here's the big one... the Citadel context structure.
14  *
15  * This structure keeps track of all information relating to a running 
16  * session on the server.  We keep one of these for each session thread.
17  *
18  */
19 struct CitContext {
20         struct CitContext *prev;        /* Link to previous session in list */
21         struct CitContext *next;        /* Link to next session in the list */
22
23         int cs_pid;             /* session ID */
24         int dont_term;          /* for special activities like artv so we don't get killed */
25         time_t lastcmd;         /* time of last command executed */
26         time_t lastidle;        /* For computing idle time */
27         int state;              /* thread state (see CON_ values below) */
28         int kill_me;            /* Set to nonzero to flag for termination */
29
30         const char *Pos;        /* Our read position inside of the ReadBuf */
31         StrBuf *ReadBuf;        /* Our block buffered read buffer */
32         StrBuf *MigrateBuf;     /* Our block buffered read buffer */
33         const char *sPos;       /* Our read position inside of the ReadBuf */
34         StrBuf *sReadBuf;       /* Our block buffered read buffer */
35         StrBuf *sMigrateBuf;    /* Our block buffered read buffer */
36         int client_socket;
37         int is_local_socket;    /* set to 1 if client is on unix domain sock */
38         /* Redirect this session's output to a memory buffer? */
39         StrBuf *redirect_buffer;                /* the buffer */
40 #ifdef HAVE_OPENSSL
41         SSL *ssl;
42         int redirect_ssl;
43 #endif
44
45         char curr_user[USERNAME_SIZE];  /* name of current user */
46         int logged_in;          /* logged in */
47         int internal_pgm;       /* authenticated as internal program */
48         int nologin;            /* not allowed to log in */
49         int curr_view;          /* The view type for the current user/room */
50         int is_master;          /* Is this session logged in using the master user? */
51
52         char net_node[32]       ;/* Is the client another Citadel server? */
53         time_t previous_login;  /* Date/time of previous login */
54         char lastcmdname[5];    /* name of last command executed */
55         unsigned cs_flags;      /* miscellaneous flags */
56         int is_async;           /* Nonzero if client accepts async msgs */
57         int async_waiting;      /* Nonzero if there are async msgs waiting */
58         int input_waiting;      /* Nonzero if there is client input waiting */
59         int can_receive_im;     /* Session is capable of receiving instant messages */
60
61         /* Client information */
62         int cs_clientdev;       /* client developer ID */
63         int cs_clienttyp;       /* client type code */
64         int cs_clientver;       /* client version number */
65         char cs_clientinfo[256];/* if its a unix domain socket, some info for logging. */
66         uid_t cs_UDSclientUID;  /* the uid of the client when talking via UDS */
67         char cs_clientname[32]; /* name of client software */
68         char cs_host[64];       /* host logged in from */
69         char cs_addr[64];       /* address logged in from */
70
71         /* The Internet type of thing */
72         char cs_inet_email[128];                /* Return address of outbound Internet mail */
73         char cs_inet_other_emails[1024];        /* User's other valid Internet email addresses */
74         char cs_inet_fn[128];                   /* Friendly-name of outbound Internet mail */
75
76         FILE *download_fp;      /* Fields relating to file transfer */
77         size_t download_fp_total;
78         char download_desired_section[128];
79         FILE *upload_fp;
80         char upl_file[256];
81         char upl_path[PATH_MAX];
82         char upl_comment[256];
83         char upl_filedir[PATH_MAX];
84         char upl_mimetype[64];
85         char dl_is_net;
86         char upload_type;
87
88         struct ctdluser user;   /* Database record buffers */
89         struct ctdlroom room;
90
91         /* A linked list of all instant messages sent to us. */
92         struct ExpressMessage *FirstExpressMessage;
93         int disable_exp;        /* Set to 1 to disable incoming pages */
94         int newmail;            /* Other sessions increment this */
95
96         /* Masqueraded values in the 'who is online' list */
97         char fake_username[USERNAME_SIZE];
98         char fake_hostname[64];
99         char fake_roomname[ROOMNAMELEN];
100
101         /* Preferred MIME formats */
102         char preferred_formats[256];
103         int msg4_dont_decode;
104
105         /* Dynamically allocated session data */
106         char *session_specific_data;            /* Used by individual protocol modules */
107         struct cit_ical *CIT_ICAL;              /* calendaring data */
108         struct ma_info *ma;                     /* multipart/alternative data */
109         const char *ServiceName;                /* readable purpose of this session */
110         void *openid_data;                      /* Data stored by the OpenID module */
111         char *ldap_dn;                          /* DN of user when using AUTHMODE_LDAP */
112
113         void (*h_command_function) (void) ;     /* service command function */
114         void (*h_async_function) (void) ;       /* do async msgs function */
115         void (*h_greeting_function) (void) ;    /* greeting function for session startup */
116
117         long *cached_msglist;                   /* results of the previous CtdlForEachMessage() */
118         int cached_num_msgs;
119 };
120
121 typedef struct CitContext CitContext;
122
123 /*
124  * Values for CitContext.state
125  * 
126  * A session that is doing nothing is in CON_IDLE state.  When activity
127  * is detected on the socket, it goes to CON_READY, indicating that it
128  * needs to have a worker thread bound to it.  When a thread binds to
129  * the session, it goes to CON_EXECUTING and does its thing.  When the
130  * transaction is finished, the thread sets it back to CON_IDLE and lets
131  * it go.
132  */
133 enum {
134         CON_IDLE,               /* This context is doing nothing */
135         CON_GREETING,           /* This context needs to output its greeting */
136         CON_STARTING,           /* This context is outputting its greeting */
137         CON_READY,              /* This context needs attention */
138         CON_EXECUTING           /* This context is bound to a thread */
139 };
140
141 #define CC MyContext()
142
143
144 extern pthread_key_t MyConKey;                  /* TSD key for MyContext() */
145 extern int num_sessions;
146 extern CitContext masterCC;
147 extern CitContext *ContextList;
148
149 CitContext *MyContext (void);
150 void RemoveContext (struct CitContext *);
151 CitContext *CreateNewContext (void);
152 void context_cleanup(void);
153 void kill_session (int session_to_kill);
154 void InitializeMasterCC(void);
155 void dead_session_purge(int force);
156 void set_async_waiting(struct CitContext *ccptr);
157
158 /* forcibly close and flush fd's on shutdown */
159 void terminate_all_sessions(void);
160
161 /* Deprecated, user CtdlBumpNewMailCounter() instead */
162 void BumpNewMailCounter(long) __attribute__ ((deprecated));
163
164 void terminate_idle_sessions(void);
165 int 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  */
175 static INLINE void become_session(CitContext *which_con) {
176 /*
177         pid_t tid = syscall(SYS_gettid);
178 */
179         pthread_setspecific(MyConKey, (void *)which_con );
180 /*
181         syslog(LOG_DEBUG, "[%d]: Now doing %s\n", 
182                       (int) tid, 
183                       ((which_con != NULL) && (which_con->ServiceName != NULL)) ? 
184                       which_con->ServiceName:"");
185 */
186 }
187
188
189 #endif /* CONTEXT_H */