2 * IRC - Internet Relay Chat, ircd/destruct_event.c
3 * Copyright (C) 2002 Carlo Wood <carlo@alinoe.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "channel.h" /* destruct_channel */
25 #include "ircd_alloc.h"
27 #include "ircd_events.h"
32 struct DestructEvent {
33 struct DestructEvent* next_event;
34 struct DestructEvent* prev_event;
36 struct Channel* chptr;
39 static struct DestructEvent* minute_list_top;
40 static struct DestructEvent* minute_list_bottom;
41 static struct DestructEvent* days_list_top;
42 static struct DestructEvent* days_list_bottom;
44 void schedule_destruct_event_1m(struct Channel* chptr)
46 struct DestructEvent* new_event;
48 /* Ignore request when we already have a destruct request */
49 if (chptr->destruct_event)
52 /* Create a new destruct event and add it at the top of the list. */
53 new_event = (struct DestructEvent*)MyMalloc(sizeof(struct DestructEvent));
54 new_event->expires = TStime() + 60; /* 1 minute from now */
55 new_event->next_event = NULL;
56 new_event->prev_event = minute_list_top;
57 new_event->chptr = chptr;
60 minute_list_top->next_event = new_event;
61 minute_list_top = new_event;
62 if (!minute_list_bottom)
63 minute_list_bottom = new_event;
65 chptr->destruct_event = new_event;
68 void schedule_destruct_event_48h(struct Channel* chptr)
70 struct DestructEvent* new_event;
72 /* Ignore request when we already have a destruct request */
73 if (chptr->destruct_event)
76 /* Create a new destruct event and add it at the top of the list. */
77 new_event = (struct DestructEvent*)MyMalloc(sizeof(struct DestructEvent));
78 new_event->expires = TStime() + 172800; /* 48 hours from now */
79 new_event->next_event = NULL;
80 new_event->prev_event = days_list_top;
81 new_event->chptr = chptr;
84 days_list_top->next_event = new_event;
85 days_list_top = new_event;
86 if (!days_list_bottom)
87 days_list_bottom = new_event;
89 chptr->destruct_event = new_event;
92 void remove_destruct_event(struct Channel* chptr)
94 struct DestructEvent* event = chptr->destruct_event;
96 assert(event != NULL);
99 if (event->prev_event)
100 event->prev_event->next_event = event->next_event;
101 if (event->next_event)
102 event->next_event->prev_event = event->prev_event;
104 /* correct top and bottom pointers */
105 if (days_list_top == event)
106 days_list_top = event->prev_event;
107 if (minute_list_top == event)
108 minute_list_top = event->prev_event;
109 if (days_list_bottom == event)
110 days_list_bottom = event->next_event;
111 if (minute_list_bottom == event)
112 minute_list_bottom = event->next_event;
117 chptr->destruct_event = NULL;
120 void exec_expired_destruct_events(struct Event* ev)
123 struct DestructEvent** list_bottom;
124 for(list_bottom = &minute_list_bottom; i < 2; ++i, list_bottom = &days_list_bottom)
126 while (*list_bottom && TStime() >= (*list_bottom)->expires)
128 struct Channel* chptr = (*list_bottom)->chptr;
129 remove_destruct_event(chptr);
130 destruct_channel(chptr);