Moved BumpNewMailCounter() into context.c because it manipulates contexts.
[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         int is_async;           /* Nonzero if client accepts async msgs */
47         int async_waiting;      /* Nonzero if there are async msgs waiting */
48         int input_waiting;      /* Nonzero if there is client input waiting */
49         int can_receive_im;     /* Session is capable of receiving instant messages */
50
51         /* Client information */
52         int cs_clientdev;       /* client developer ID */
53         int cs_clienttyp;       /* client type code */
54         int cs_clientver;       /* client version number */
55         uid_t cs_UDSclientUID;  /* the uid of the client when talking via UDS */
56         char cs_clientname[32]; /* name of client software */
57         char cs_host[64];       /* host logged in from */
58         char cs_addr[64];       /* address logged in from */
59
60         /* The Internet type of thing */
61         char cs_inet_email[128];                /* Return address of outbound Internet mail */
62         char cs_inet_other_emails[1024];        /* User's other valid Internet email addresses */
63         char cs_inet_fn[128];                   /* Friendly-name of outbound Internet mail */
64
65         FILE *download_fp;      /* Fields relating to file transfer */
66         char download_desired_section[128];
67         FILE *upload_fp;
68         char upl_file[256];
69         char upl_path[PATH_MAX];
70         char upl_comment[256];
71         char upl_filedir[PATH_MAX];
72         char upl_mimetype[64];
73         char dl_is_net;
74         char upload_type;
75
76         struct ctdluser user;   /* Database record buffers */
77         struct ctdlroom room;
78
79         /* Beginning of cryptography - session nonce */
80         char cs_nonce[NONCE_SIZE];      /* The nonce for this session's next auth transaction */
81
82         /* Redirect this session's output to a memory buffer? */
83         char *redirect_buffer;          /* the buffer */
84         size_t redirect_len;            /* length of data in buffer */
85         size_t redirect_alloc;          /* length of allocated buffer */
86 #ifdef HAVE_OPENSSL
87         SSL *ssl;
88         int redirect_ssl;
89 #endif
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
114 typedef struct CitContext CitContext;
115
116 /*
117  * Values for CitContext.state
118  * 
119  * A session that is doing nothing is in CON_IDLE state.  When activity
120  * is detected on the socket, it goes to CON_READY, indicating that it
121  * needs to have a worker thread bound to it.  When a thread binds to
122  * the session, it goes to CON_EXECUTING and does its thing.  When the
123  * transaction is finished, the thread sets it back to CON_IDLE and lets
124  * it go.
125  */
126 enum {
127         CON_IDLE,               /* This context is doing nothing */
128         CON_READY,              /* This context needs attention */
129         CON_EXECUTING           /* This context is bound to a thread */
130 };
131
132 #define CC MyContext()
133
134
135 extern citthread_key_t MyConKey;                        /* TSD key for MyContext() */
136 extern int num_sessions;
137 extern CitContext masterCC;
138 extern CitContext *ContextList;
139
140 CitContext *MyContext (void);
141 void RemoveContext (struct CitContext *);
142 CitContext *CreateNewContext (void);
143 void context_cleanup(void);
144 void kill_session (int session_to_kill);
145 INLINE void become_session(struct CitContext *which_con);
146 void InitializeMasterCC(void);
147 void dead_session_purge(int force);
148
149 /* Deprecated, user CtdlBumpNewMailCounter() instead */
150 void BumpNewMailCounter(long) __attribute__ ((deprecated));
151
152
153 #endif /* CONTEXT_H */