ekg2
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje Grupay Strony
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 /* Few words about statuses:
70  *
71  * All of the enum statuses are proritity-sorted. I mean, if we want to determine, which of the two given statuses is more
72  * important, we just do standard arithmetic comparation (e.g. (status1 > status2)). The statuses are also divided into few
73  * functional groups.
74  *
75  * EKG_STATUS_NULL is just declared for fun. It can be used locally (e.g. in functions, where status can be set conditionally,
76  * 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
77  * probably treated like unknown status. I even don't think anyone would use that long name, instead of putting 0.
78  *
79  * The next two statuses, blocked and error, represent situations, in which messages sent to user probably won't be delivered.
80  * They both aren't currently treated specially by core, but this may change in future. If You want to check, if given status
81  * belongs to that group, you should use EKG_STATUS_IS_NODELIVERY.
82  *
83  * 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
84  * delivered or queued. EKG_STATUS_UNKNOWN would probably be the lowest prioritized of these statuses, so it is used as a mark
85  * 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
86  * (combined with above) is identified by macro EKG_STATUS_IS_NA.
87  *
88  * Next status, EKG_STATUS_INVISIBLE, is very problematic. It means that user has sent us an N/A status, but some magic says
89  * 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
90  * 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
91  * available' than EKG_STATUS_NA, so it's put after it. But this _can change_.
92  *
93  * Status described above starts the third group of statuses, aways. These are statuses, which say that user is connected with
94  * server, and messages are delivered directly to him/her, but he/she is probably AFK, busy or like that. All those statuses
95  * are grouped by macro EKG_STATUS_IS_AWAY.
96  *
97  * And the last formal group is available-statuses. The first of them, most traditional 'available', is a mark for this
98  * and above group. The macro is EKG_STATUS_IS_AVAIL.
99  *
100  * The real last group is designed for special use only. Currently, there are only statuses for setting and disabling auto-away
101  * mode in EKG2. These three can be passed only to session_status_set(), and aren't recognized by everything else.
102  */
103 
104 #define EKG_STATUS_IS_NODELIVERY(x) (x < EKG_STATUS_UNKNOWN)
105 #define EKG_STATUS_IS_NA(x) (x <= EKG_STATUS_NA)
106 #define EKG_STATUS_IS_AWAY(x) ((x > EKG_STATUS_NA) && (x < EKG_STATUS_AVAIL))
107 #define EKG_STATUS_IS_AVAIL(x) (x >= EKG_STATUS_AVAIL)
108 
109 typedef struct session_param {
111 
112  char *key; /* nazwa parametru */
113  char *value; /* wartość parametru */
115 
119 typedef struct ekg_session {
120  struct ekg_session *next;
121 
122 /* public: */
123  void *plugin;
124  char *uid;
125  char *alias;
126  void *priv;
127  struct userlist *userlist;
129 /* private: */
131  char *descr;
132  char *password;
134  unsigned int connected : 1;
135  unsigned int connecting : 2;
136  unsigned int autoaway : 1;
138  time_t activity;
139  time_t last_conn;
142  char **values;
144 
145 /* new auto-away */
147  char *last_descr;
149 #ifdef HAVE_FLOCK /* XXX: -D for docs? */
150  int lock_fd;
151 #endif
152 } session_t;
153 
154 #ifndef EKG2_WIN32_NOFUNCTION
155 extern session_t *sessions;
156 
157 extern session_t *session_current;
158 
159 session_t *session_find(const char *uid);
161 
162 int session_is_var(session_t *s, const char *key);
163 
164 const char *session_uid_get(session_t *s);
165 
166 const char *session_alias_get(session_t *s);
167 int session_alias_set(session_t *s, const char *alias);
168 
170 #define session_status_get_n(a) session_status_get(session_find(a))
172 
173 const char *session_descr_get(session_t *s);
174 int session_descr_set(session_t *s, const char *descr);
175 
176 const char *session_password_get(session_t *s);
177 int session_password_set(session_t *s, const char *password);
178 
180 int session_private_set(session_t *s, void *priv);
181 
183 int session_connected_set(session_t *s, int connected);
184 
185 const char *session_get(session_t *s, const char *key);
186 int session_int_get(session_t *s, const char *key);
187 int session_set(session_t *s, const char *key, const char *value);
188 int session_int_set(session_t *s, const char *key, int value);
189 
190 const char *session_format(session_t *s);
191 #define session_format_n(a) session_format(session_find(a))
192 
193 /* alias or uid - formatted */
194 const char *session_name(session_t *s);
195 
196 /* alias or uid - not formatted */
197 #define session_alias_uid(a) (a->alias) ? a->alias : a->uid
198 #define session_alias_uid_n(a) session_alias_uid(session_find(a))
199 
200 int session_check(session_t *s, int need_private, const char *protocol);
201 
202 int session_unidle(session_t *s);
203 
204 session_t *session_add(const char *uid);
205 int session_remove(const char *uid);
206 
207 int session_read(const char *filename);
208 int session_write();
209 
210 void sessions_free();
211 
212 void session_help(session_t *s, const char *name);
213 #endif
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 
219 #endif /* __EKG_SESSIONS_H */
220 
221 /*
222  * Local Variables:
223  * mode: c
224  * c-file-style: "k&r"
225  * c-basic-offset: 8
226  * indent-tabs-mode: t
227  * End:
228  */