ekg2  GIT master
sessions.h
Idź do dokumentacji tego pliku.
1 /* $Id$ */
2 
3 /*
4  * (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl>
5  * 2004 Piotr Kupisiewicz <deli@rzepaknet.us>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License Version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 
21 #ifndef __EKG_SESSIONS_H
22 #define __EKG_SESSIONS_H
23 
24 #include <time.h>
25 #include "dynstuff.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 
31 /* --NOTE--
32  * When modifying status_t, remember to update status tables in stuff.c!
33  */
34 
39 typedef enum {
40  EKG_STATUS_NULL = 0x00, /* special value */
41 
42  /* These statuses should be considered as no-delivery */
43  EKG_STATUS_ERROR, /* used in Jabber */
44  EKG_STATUS_BLOCKED, /* used in GG */
45 
46  /* These statuses should be considered as 'not sure' */
47  EKG_STATUS_UNKNOWN, /* used in Jabber */
48  EKG_STATUS_NA, /* universal */
49 
50  /* These should be considered as 'probably available' */
51  EKG_STATUS_INVISIBLE, /* GG; hard to prioritize... */
52  EKG_STATUS_DND, /* Jabber */
53  EKG_STATUS_GONE, /* ICQ */
54  EKG_STATUS_XA, /* Jabber */
55  EKG_STATUS_AWAY, /* universal */
56 
57  /* These should be considered as 'sure available' */
58  EKG_STATUS_AVAIL, /* universal */
59  EKG_STATUS_FFC, /* Jabber */
60 
62  /* XXX: autostatuses are going to be rewritten and then below will be removed */
63  /* These are special statuses, which are to be used only with dedicated functions */
64  EKG_STATUS_AUTOAWAY = 0x80, /* putting in auto-away */
65  EKG_STATUS_AUTOXA, /* putting in auto-xa */
66  EKG_STATUS_AUTOBACK /* returning to previous status */
67 } status_t;
68 
69 typedef enum {
73  _EKG_CHATSTATE_NOT = 1 << 10,
76 } chatstates_t;
77 /* Few words about statuses:
78  *
79  * All of the enum statuses are proritity-sorted. I mean, if we want to determine, which of the two given statuses is more
80  * important, we just do standard arithmetic comparation (e.g. (status1 > status2)). The statuses are also divided into few
81  * functional groups.
82  *
83  * EKG_STATUS_NULL is just declared for fun. It can be used locally (e.g. in functions, where status can be set conditionally,
84  * to see if some condition was true), but it can't be passed to core. None of the core functions recognizes it, so it will be
85  * probably treated like unknown status. I even don't think anyone would use that long name, instead of putting 0.
86  *
87  * The next two statuses, blocked and error, represent situations, in which messages sent to user probably won't be delivered.
88  * They both aren't currently treated specially by core, but this may change in future. If You want to check, if given status
89  * belongs to that group, you should use EKG_STATUS_IS_NODELIVERY.
90  *
91  * Then, we've got two kinds of N/A. Both of them mean the user may be unavailable at the moment, but the messages will be
92  * delivered or queued. EKG_STATUS_UNKNOWN would probably be the lowest prioritized of these statuses, so it is used as a mark
93  * for above group, and EKG_STATUS_NA would be the highest one, so it is used as a mark for all N/A statuses. This group
94  * (combined with above) is identified by macro EKG_STATUS_IS_NA.
95  *
96  * Next status, EKG_STATUS_INVISIBLE, is very problematic. It means that user has sent us an N/A status, but some magic says
97  * it is available although. It's hard to say, if it's an N/A status, or more 'deep kind of away' (often invisible is used
98  * when someone goes AFK for a long time). I don't think it should be used as some kind of mark, and also shouldn't be 'less
99  * available' than EKG_STATUS_NA, so it's put after it. But this _can change_.
100  *
101  * Status described above starts the third group of statuses, aways. These are statuses, which say that user is connected with
102  * server, and messages are delivered directly to him/her, but he/she is probably AFK, busy or like that. All those statuses
103  * are grouped by macro EKG_STATUS_IS_AWAY.
104  *
105  * And the last formal group is available-statuses. The first of them, most traditional 'available', is a mark for this
106  * and above group. The macro is EKG_STATUS_IS_AVAIL.
107  *
108  * The real last group is designed for special use only. Currently, there are only statuses for setting and disabling auto-away
109  * mode in EKG2. These three can be passed only to session_status_set(), and aren't recognized by everything else.
110  */
111 
112 #define EKG_STATUS_IS_NODELIVERY(x) (x < EKG_STATUS_UNKNOWN)
113 #define EKG_STATUS_IS_NA(x) (x <= EKG_STATUS_NA)
114 #define EKG_STATUS_IS_AWAY(x) ((x > EKG_STATUS_NA) && (x < EKG_STATUS_AVAIL))
115 #define EKG_STATUS_IS_AVAIL(x) (x >= EKG_STATUS_AVAIL)
116 
117 typedef struct session_param {
119 
120  char *key; /* nazwa parametru */
121  char *value; /* wartość parametru */
123 
127 typedef struct ekg_session {
128  struct ekg_session *next;
129 
130 /* public: */
131  void *plugin;
132  char *uid;
133  char *alias;
134  void *priv;
135  struct userlist *userlist;
137 /* private: */
138  status_t status;
139  char *descr;
140  char *password;
142  unsigned int connected : 1;
143  unsigned int connecting : 2;
144  unsigned int autoaway : 1;
146  time_t activity;
147  time_t last_conn;
150  char **values;
152 
153 /* new auto-away */
154  status_t last_status;
155  char *last_descr;
157 #ifdef HAVE_FLOCK /* XXX: -D for docs? */
158  int lock_fd;
159 #endif
160 } session_t;
161 
162 #ifndef EKG2_WIN32_NOFUNCTION
163 extern session_t *sessions;
164 
165 extern session_t *session_current;
166 
167 session_t *session_find(const char *uid);
169 
170 int session_is_var(session_t *s, const char *key);
171 
172 const char *session_uid_get(session_t *s);
173 
174 const char *session_alias_get(session_t *s);
175 int session_alias_set(session_t *s, const char *alias);
176 
178 #define session_status_get_n(a) session_status_get(session_find(a))
179 int session_status_set(session_t *s, status_t status);
180 
181 const char *session_descr_get(session_t *s);
182 int session_descr_set(session_t *s, const char *descr);
183 
184 const char *session_password_get(session_t *s);
185 int session_password_set(session_t *s, const char *password);
186 
188 int session_private_set(session_t *s, void *priv);
189 
191 int session_connected_set(session_t *s, int connected);
192 
193 const char *session_get(session_t *s, const char *key);
194 int session_int_get(session_t *s, const char *key);
195 int session_set(session_t *s, const char *key, const char *value);
196 int session_int_set(session_t *s, const char *key, int value);
197 
198 const char *session_format(session_t *s);
199 #define session_format_n(a) session_format(session_find(a))
200 
201 /* alias or uid - formatted */
202 const char *session_name(session_t *s);
203 
204 /* alias or uid - not formatted */
205 #define session_alias_uid(a) (a->alias) ? a->alias : a->uid
206 #define session_alias_uid_n(a) session_alias_uid(session_find(a))
207 
208 int session_check(session_t *s, int need_private, const char *protocol);
209 
211 
212 session_t *session_add(const char *uid);
213 int session_remove(const char *uid);
214 
215 int session_read(const gchar *plugin_name) G_GNUC_INTERNAL;
216 void session_write();
217 
218 void sessions_free();
219 
220 void session_help(session_t *s, const char *name);
221 #endif
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* __EKG_SESSIONS_H */
228 
229 /*
230  * Local Variables:
231  * mode: c
232  * c-file-style: "k&r"
233  * c-basic-offset: 8
234  * indent-tabs-mode: t
235  * End:
236  */
void sessions_free()
Definition: sessions.c:1470
const char * uid
Definition: userlist.h:57
int session_read(const gchar *plugin_name) G_GNUC_INTERNAL
Definition: sessions.c:801
status_t last_status
Definition: sessions.h:154
char * uid
Definition: sessions.h:132
Definition: sessions.h:127
const char * session_uid_get(session_t *s)
Definition: sessions.c:496
int session_alias_set(session_t *s, const char *alias)
Definition: sessions.c:482
int session_set(session_t *s, const char *key, const char *value)
Definition: sessions.c:697
struct session_param session_param_t
Definition: sessions.h:52
chatstates_t
Definition: sessions.h:69
void * priv
Definition: sessions.h:134
unsigned int connected
Definition: sessions.h:142
struct ekg_session * next
Definition: sessions.h:128
Definition: sessions.h:43
Definition: sessions.h:53
Definition: sessions.h:73
char * alias
Definition: sessions.h:133
session_t * sessions
Definition: sessions.c:36
Definition: sessions.h:40
void session_help(session_t *s, const char *name)
Definition: sessions.c:1518
char * password
Definition: sessions.h:140
Definition: sessions.h:47
status_t status
Definition: sessions.h:138
Definition: sessions.h:75
Definition: sessions.h:61
int session_int_set(session_t *s, const char *key, int value)
Definition: sessions.c:791
Definition: sessions.h:65
int session_connected_set(session_t *s, int connected)
Definition: sessions.c:486
Definition: sessions.h:70
int session_remove(const char *uid)
Definition: sessions.c:243
Definition: sessions.h:55
char * descr
Definition: userlist.h:64
const char * session_format(session_t *s)
Definition: sessions.c:937
const char * session_password_get(session_t *s)
Definition: sessions.c:442
status_t
Definition: sessions.h:39
int session_check(session_t *s, int need_private, const char *protocol)
Definition: sessions.c:972
status_t status
Definition: userlist.h:63
char * value
Definition: sessions.h:121
int global_vars_count
Definition: sessions.h:149
int session_connected_get(session_t *s)
Definition: sessions.c:484
int session_int_get(session_t *s, const char *key)
Definition: sessions.c:661
session_param_t * local_vars
Definition: sessions.h:151
session_t * session_find(const char *uid)
Definition: sessions.c:88
void session_write()
Definition: sessions.c:877
void * priv
Definition: userlist.h:72
int session_status_set(session_t *s, status_t status)
Definition: sessions.c:298
struct ekg_session session_t
Definition: userlist.h:54
int session_is_var(session_t *s, const char *key)
Definition: sessions.c:675
time_t last_conn
Definition: sessions.h:147
time_t activity
Definition: sessions.h:146
const char * session_get(session_t *s, const char *key)
Definition: sessions.c:613
char ** values
Definition: sessions.h:150
int session_private_set(session_t *s, void *priv)
Definition: sessions.c:483
const char * name
Definition: remote.c:88
void * plugin
Definition: sessions.h:131
Definition: sessions.h:64
session_t * session_current
Definition: sessions.c:48
Definition: sessions.h:54
void * session_private_get(session_t *s)
Definition: sessions.c:483
session_t * session_find_ptr(session_t *s)
Definition: sessions.c:65
Definition: sessions.h:51
const char * session_descr_get(session_t *s)
Definition: sessions.c:464
Definition: sessions.h:66
Definition: sessions.h:71
struct userlist * userlist
Definition: sessions.h:135
Definition: sessions.h:74
char * key
Definition: sessions.h:120
char * last_descr
Definition: sessions.h:155
Definition: sessions.h:59
struct session_param * next
Definition: sessions.h:118
Definition: sessions.h:58
Definition: sessions.h:72
unsigned int connecting
Definition: sessions.h:143
#define s
const char * session_name(session_t *s)
Definition: sessions.c:998
Definition: sessions.h:44
int session_password_set(session_t *s, const char *password)
Definition: sessions.c:417
Definition: sessions.h:48
unsigned int autoaway
Definition: sessions.h:144
Definition: stuff.h:61
int session_unidle(session_t *s)
Definition: sessions.c:1020
session_t * session_add(const char *uid)
Definition: sessions.c:121
Definition: sessions.h:117
int session_descr_set(session_t *s, const char *descr)
Definition: sessions.c:466
const char * session_alias_get(session_t *s)
Definition: sessions.c:482
char * descr
Definition: sessions.h:139
int session_status_get(session_t *s)
Definition: sessions.c:296