ekg2
ekg/sessions.h
Idź do dokumentacji tego pliku.
00001 /* $Id$ */
00002 
00003 /*
00004  *  (C) Copyright 2003 Wojtek Kaniewski <wojtekka@irc.pl>
00005  *                2004 Piotr Kupisiewicz <deli@rzepaknet.us>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License Version 2 as
00009  *  published by the Free Software Foundation.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __EKG_SESSIONS_H
00022 #define __EKG_SESSIONS_H
00023 
00024 #include <time.h>
00025 #include "dynstuff.h"
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 /* --NOTE--
00032  * When modifying status_t, remember to update status tables in stuff.c!
00033  */
00034 
00039 typedef enum {
00040         EKG_STATUS_NULL         = 0x00, /* special value */
00041 
00042         /* These statuses should be considered as no-delivery */
00043         EKG_STATUS_ERROR,               /* used in Jabber */
00044         EKG_STATUS_BLOCKED,             /* used in GG */
00045 
00046         /* These statuses should be considered as 'not sure' */
00047         EKG_STATUS_UNKNOWN,                     /* used in Jabber */
00048         EKG_STATUS_NA,                          /* universal */
00049 
00050         /* These should be considered as 'probably available' */
00051         EKG_STATUS_INVISIBLE,           /* GG; hard to prioritize... */
00052         EKG_STATUS_DND,                 /* Jabber */
00053         EKG_STATUS_GONE,                /* ICQ */
00054         EKG_STATUS_XA,                  /* Jabber */
00055         EKG_STATUS_AWAY,                /* universal */
00056 
00057         /* These should be considered as 'sure available' */
00058         EKG_STATUS_AVAIL,               /* universal */
00059         EKG_STATUS_FFC,                 /* Jabber */
00060 
00061         EKG_STATUS_LAST,
00062                 /* XXX: autostatuses are going to be rewritten and then below will be removed */
00063         /* These are special statuses, which are to be used only with dedicated functions */
00064         EKG_STATUS_AUTOAWAY     = 0x80, /* putting in auto-away */
00065         EKG_STATUS_AUTOXA,              /* putting in auto-xa */
00066         EKG_STATUS_AUTOBACK             /* returning to previous status */
00067 } status_t;
00068 
00069 /* Few words about statuses:
00070  *
00071  * All of the enum statuses are proritity-sorted. I mean, if we want to determine, which of the two given statuses is more
00072  * important, we just do standard arithmetic comparation (e.g. (status1 > status2)). The statuses are also divided into few
00073  * functional groups.
00074  *
00075  * EKG_STATUS_NULL is just declared for fun. It can be used locally (e.g. in functions, where status can be set conditionally,
00076  * 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
00077  * probably treated like unknown status. I even don't think anyone would use that long name, instead of putting 0.
00078  *
00079  * The next two statuses, blocked and error, represent situations, in which messages sent to user probably won't be delivered.
00080  * They both aren't currently treated specially by core, but this may change in future. If You want to check, if given status
00081  * belongs to that group, you should use EKG_STATUS_IS_NODELIVERY.
00082  *
00083  * 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
00084  * delivered or queued. EKG_STATUS_UNKNOWN would probably be the lowest prioritized of these statuses, so it is used as a mark
00085  * 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
00086  * (combined with above) is identified by macro EKG_STATUS_IS_NA.
00087  *
00088  * Next status, EKG_STATUS_INVISIBLE, is very problematic. It means that user has sent us an N/A status, but some magic says
00089  * 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
00090  * 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
00091  * available' than EKG_STATUS_NA, so it's put after it. But this _can change_.
00092  *
00093  * Status described above starts the third group of statuses, aways. These are statuses, which say that user is connected with
00094  * server, and messages are delivered directly to him/her, but he/she is probably AFK, busy or like that. All those statuses
00095  * are grouped by macro EKG_STATUS_IS_AWAY.
00096  *
00097  * And the last formal group is available-statuses. The first of them, most traditional 'available', is a mark for this
00098  * and above group. The macro is EKG_STATUS_IS_AVAIL.
00099  *
00100  * The real last group is designed for special use only. Currently, there are only statuses for setting and disabling auto-away
00101  * mode in EKG2. These three can be passed only to session_status_set(), and aren't recognized by everything else.
00102  */
00103 
00104 #define EKG_STATUS_IS_NODELIVERY(x)     (x < EKG_STATUS_UNKNOWN)
00105 #define EKG_STATUS_IS_NA(x)             (x <= EKG_STATUS_NA)
00106 #define EKG_STATUS_IS_AWAY(x)           ((x > EKG_STATUS_NA) && (x < EKG_STATUS_AVAIL))
00107 #define EKG_STATUS_IS_AVAIL(x)          (x >= EKG_STATUS_AVAIL)
00108 
00109 typedef struct session_param {
00110         struct session_param *next;
00111 
00112         char *key;                      /* nazwa parametru */
00113         char *value;                    /* wartość parametru */
00114 } session_param_t;
00115 
00119 typedef struct ekg_session {
00120         struct ekg_session      *next;
00121 
00122 /* public: */
00123         void            *plugin;                
00124         char            *uid;                   
00125         char            *alias;                 
00126         void            *priv;                  
00127         struct userlist *userlist;              
00129 /* private: */
00130         status_t        status;                 
00131         char            *descr;                 
00132         char            *password;              
00134         unsigned int    connected       : 1;    
00135         unsigned int    connecting      : 2;    
00136         unsigned int    autoaway        : 1;    
00138         time_t          activity;               
00139         time_t          last_conn;              
00141         int             global_vars_count;
00142         char            **values;
00143         session_param_t *local_vars;
00144         
00145 /* new auto-away */
00146         status_t        last_status;            
00147         char            *last_descr;            
00149 #ifdef HAVE_FLOCK /* XXX: -D for docs? */
00150         int             lock_fd;                
00151 #endif
00152 } session_t;
00153 
00154 #ifndef EKG2_WIN32_NOFUNCTION
00155 extern session_t *sessions;
00156 
00157 extern session_t *session_current;
00158 
00159 session_t *session_find(const char *uid);
00160 session_t *session_find_ptr(session_t *s);
00161 
00162 int session_is_var(session_t *s, const char *key);
00163 
00164 const char *session_uid_get(session_t *s);
00165 
00166 const char *session_alias_get(session_t *s);
00167 int session_alias_set(session_t *s, const char *alias);
00168 
00169 int session_status_get(session_t *s);
00170 #define session_status_get_n(a) session_status_get(session_find(a))
00171 int session_status_set(session_t *s, status_t status);
00172 
00173 const char *session_descr_get(session_t *s);
00174 int session_descr_set(session_t *s, const char *descr);
00175 
00176 const char *session_password_get(session_t *s);
00177 int session_password_set(session_t *s, const char *password);
00178 
00179 void *session_private_get(session_t *s);
00180 int session_private_set(session_t *s, void *priv);
00181 
00182 int session_connected_get(session_t *s);
00183 int session_connected_set(session_t *s, int connected);
00184 
00185 const char *session_get(session_t *s, const char *key);
00186 int session_int_get(session_t *s, const char *key);
00187 int session_set(session_t *s, const char *key, const char *value);
00188 int session_int_set(session_t *s, const char *key, int value);
00189 
00190 const char *session_format(session_t *s);
00191 #define session_format_n(a) session_format(session_find(a))
00192 
00193 /* alias or uid - formatted */
00194 const char *session_name(session_t *s);
00195 
00196 /* alias or uid - not formatted */
00197 #define session_alias_uid(a) (a->alias) ? a->alias : a->uid
00198 #define session_alias_uid_n(a) session_alias_uid(session_find(a))
00199 
00200 int session_check(session_t *s, int need_private, const char *protocol);
00201 
00202 int session_unidle(session_t *s);
00203 
00204 session_t *session_add(const char *uid);
00205 int session_remove(const char *uid);
00206 
00207 int session_read(const char *filename);
00208 int session_write();
00209 
00210 void sessions_free();
00211 
00212 void session_help(session_t *s, const char *name);
00213 #endif
00214 
00215 #ifdef __cplusplus
00216 }
00217 #endif
00218 
00219 #endif /* __EKG_SESSIONS_H */
00220 
00221 /*
00222  * Local Variables:
00223  * mode: c
00224  * c-file-style: "k&r"
00225  * c-basic-offset: 8
00226  * indent-tabs-mode: t
00227  * End:
00228  */
 All Struktury Danych Pliki Funkcje Zmienne Definicje typów Wyliczenia Wartości wyliczeń Definicje