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