comparison mcabber/src/events.c @ 1598:a087125d8fc8

Replace libjabber with loudmouth
author franky
date Sun, 11 Oct 2009 15:38:32 +0200
parents 366ef500c522
children dcd5d4c75199
comparison
equal deleted inserted replaced
1597:4f59a414217e 1598:a087125d8fc8
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA 19 * USA
20 */ 20 */
21 21
22 #include <glib.h> 22 #include <glib.h>
23 #include <string.h>
23 #include "events.h" 24 #include "events.h"
24 #include "logprint.h" 25 #include "logprint.h"
25 26
26 static GSList *evs_list; // Events list 27 static GSList *evs_list; // Events list
27 28
52 if (timeout) 53 if (timeout)
53 new_evs->ts_expire = now_t + timeout; 54 new_evs->ts_expire = now_t + timeout;
54 new_evs->type = type; 55 new_evs->type = type;
55 new_evs->id = stridn; 56 new_evs->id = stridn;
56 57
58 if(!g_slist_length(evs_list))
59 g_timeout_add_seconds(20, evs_check_timeout, NULL);
57 evs_list = g_slist_append(evs_list, new_evs); 60 evs_list = g_slist_append(evs_list, new_evs);
58 return new_evs; 61 return new_evs;
59 } 62 }
60 63
61 int evs_del(const char *evid) 64 int evs_del(const char *evid)
70 if (!strcmp(evid, i->id)) 73 if (!strcmp(evid, i->id))
71 break; 74 break;
72 } 75 }
73 if (p) { 76 if (p) {
74 g_free(i->id); 77 g_free(i->id);
75 if (i->xmldata) xmlnode_free(i->xmldata);
76 g_free(i->data); 78 g_free(i->data);
77 g_free(i->desc); 79 g_free(i->desc);
78 g_free(i); 80 g_free(i);
79 evs_list = g_slist_remove(evs_list, p->data); 81 evs_list = g_slist_remove(evs_list, p->data);
80 return 0; // Ok, deleted 82 return 0; // Ok, deleted
114 116
115 evs_del(evid); 117 evs_del(evid);
116 return 0; 118 return 0;
117 } 119 }
118 120
119 void evs_check_timeout(time_t now_t) 121 gboolean evs_check_timeout()
120 { 122 {
123 time_t now_t;
121 GSList *p; 124 GSList *p;
122 eviqs *i; 125 eviqs *i;
123 126
127 time(&now_t);
124 p = evs_list; 128 p = evs_list;
129 if (!p)
130 return FALSE;
125 while (p) { 131 while (p) {
126 i = p->data; 132 i = p->data;
127 // We must get next IQ eviqs element now because the current one 133 // We must get next IQ eviqs element now because the current one
128 // could be freed. 134 // could be freed.
129 p = g_slist_next(p); 135 p = g_slist_next(p);
131 if ((!i->ts_expire && now_t > i->ts_create + EVS_MAX_TIMEOUT) || 137 if ((!i->ts_expire && now_t > i->ts_create + EVS_MAX_TIMEOUT) ||
132 (i->ts_expire && now_t > i->ts_expire)) { 138 (i->ts_expire && now_t > i->ts_expire)) {
133 evs_callback(i->id, EVS_CONTEXT_TIMEOUT); 139 evs_callback(i->id, EVS_CONTEXT_TIMEOUT);
134 } 140 }
135 } 141 }
142 return TRUE;
136 } 143 }
137 144
138 void evs_display_list(void) 145 void evs_display_list(void)
139 { 146 {
140 GSList *p; 147 GSList *p;