--- a/mcabber/src/events.c Mon Mar 13 19:25:55 2006 +0100
+++ b/mcabber/src/events.c Mon Mar 13 23:41:29 2006 +0100
@@ -25,6 +25,7 @@
static GSList *evs_list; // Events list
+static eviqs *evs_find(const char *evid);
// evs_new(type, timeout)
// Create an events structure.
@@ -33,10 +34,17 @@
static guint evs_idn;
eviqs *new_evs;
time_t now_t;
+ char *stridn;
if (!++evs_idn)
evs_idn = 1;
- /* TODO: check for wrapping, we shouldn't reuse ids */
+ /* Check for wrapping, we shouldn't reuse ids */
+ stridn = g_strdup_printf("%d", evs_idn);
+ if (evs_find(stridn)) {
+ g_free(stridn);
+ // We could try another id but for now giving up should be fine...
+ return NULL;
+ }
new_evs = g_new0(eviqs, 1);
time(&now_t);
@@ -44,7 +52,7 @@
if (timeout)
new_evs->ts_expire = now_t + timeout;
new_evs->type = type;
- new_evs->id = g_strdup_printf("%d", evs_idn);
+ new_evs->id = stridn;
evs_list = g_slist_append(evs_list, new_evs);
return new_evs;
--- a/mcabber/src/jabglue.c Mon Mar 13 19:25:55 2006 +0100
+++ b/mcabber/src/jabglue.c Mon Mar 13 23:41:29 2006 +0100
@@ -1502,10 +1502,13 @@
// Create a new event item
evn = evs_new(EVS_TYPE_SUBSCRIPTION, EVS_MAX_TIMEOUT);
- evn->callback = &evscallback_subcription;
- evn->data = g_strdup(r);
-
- buf = g_strdup_printf("Please use /event %s accept|reject", evn->id);
+ if (evn) {
+ evn->callback = &evscallback_subcription;
+ evn->data = g_strdup(r);
+ buf = g_strdup_printf("Please use /event %s accept|reject", evn->id);
+ } else {
+ buf = g_strdup_printf("Unable to create a new event!");
+ }
scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO);
scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
g_free(buf);