]>
jfr.im git - irc/quakenet/snircd.git/blob - ircd/destruct_event.c
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.
20 * @brief Implementation of timed channel destruction events.
21 * @version $Id: destruct_event.c,v 1.4 2004/12/11 05:13:44 klmitch Exp $
25 #include "channel.h" /* destruct_channel */
27 #include "ircd_alloc.h"
29 #include "ircd_events.h"
34 /* #include <assert.h> -- Now using assert in ircd_log.h */
37 /** Structure describing a destruction event. */
38 struct DestructEvent
{
39 struct DestructEvent
* next_event
; /**< Next event in the queue. */
40 struct DestructEvent
* prev_event
; /**< Previous event in the queue. */
41 time_t expires
; /**< When the destruction should happen. */
42 struct Channel
* chptr
; /**< Channel to destroy. */
45 /** Head of short-delay destruction events. */
46 static struct DestructEvent
* minute_list_top
;
47 /** Tail of short-delay destruction events. */
48 static struct DestructEvent
* minute_list_bottom
;
49 /** Head of long-delay destruction events. */
50 static struct DestructEvent
* days_list_top
;
51 /** Tail of long-delay destruction events. */
52 static struct DestructEvent
* days_list_bottom
;
54 /** Schedule a short-delay destruction event for \a chptr.
55 * @param[in] chptr Channel to destroy.
57 void schedule_destruct_event_1m(struct Channel
* chptr
)
59 struct DestructEvent
* new_event
;
61 /* Ignore request when we already have a destruct request */
62 if (chptr
->destruct_event
)
65 /* Create a new destruct event and add it at the top of the list. */
66 new_event
= (struct DestructEvent
*)MyMalloc(sizeof(struct DestructEvent
));
67 new_event
->expires
= TStime() + 60; /* 1 minute from now */
68 new_event
->next_event
= NULL
;
69 new_event
->prev_event
= minute_list_top
;
70 new_event
->chptr
= chptr
;
73 minute_list_top
->next_event
= new_event
;
74 minute_list_top
= new_event
;
75 if (!minute_list_bottom
)
76 minute_list_bottom
= new_event
;
78 chptr
->destruct_event
= new_event
;
81 /** Schedule a long-delay destruction event for \a chptr.
82 * @param[in] chptr Channel to destroy.
84 void schedule_destruct_event_48h(struct Channel
* chptr
)
86 struct DestructEvent
* new_event
;
88 /* Ignore request when we already have a destruct request */
89 if (chptr
->destruct_event
)
92 /* Create a new destruct event and add it at the top of the list. */
93 new_event
= (struct DestructEvent
*)MyMalloc(sizeof(struct DestructEvent
));
94 new_event
->expires
= TStime() + 172800; /* 48 hours from now */
95 new_event
->next_event
= NULL
;
96 new_event
->prev_event
= days_list_top
;
97 new_event
->chptr
= chptr
;
100 days_list_top
->next_event
= new_event
;
101 days_list_top
= new_event
;
102 if (!days_list_bottom
)
103 days_list_bottom
= new_event
;
105 chptr
->destruct_event
= new_event
;
108 /** Unlink a destruction event for a channel.
109 * @param[in] chptr Channel that is being destroyed early.
111 void remove_destruct_event(struct Channel
* chptr
)
113 struct DestructEvent
* event
= chptr
->destruct_event
;
115 assert(event
!= NULL
);
118 if (event
->prev_event
)
119 event
->prev_event
->next_event
= event
->next_event
;
120 if (event
->next_event
)
121 event
->next_event
->prev_event
= event
->prev_event
;
123 /* correct top and bottom pointers */
124 if (days_list_top
== event
)
125 days_list_top
= event
->prev_event
;
126 if (minute_list_top
== event
)
127 minute_list_top
= event
->prev_event
;
128 if (days_list_bottom
== event
)
129 days_list_bottom
= event
->next_event
;
130 if (minute_list_bottom
== event
)
131 minute_list_bottom
= event
->next_event
;
136 chptr
->destruct_event
= NULL
;
139 /** Execute expired channel destruction events.
140 * @param[in] ev Expired timer event (ignored).
142 void exec_expired_destruct_events(struct Event
* ev
)
145 struct DestructEvent
** list_bottom
;
146 for(list_bottom
= &minute_list_bottom
; i
< 2; ++i
, list_bottom
= &days_list_bottom
)
148 while (*list_bottom
&& TStime() >= (*list_bottom
)->expires
)
150 struct Channel
* chptr
= (*list_bottom
)->chptr
;
151 /* Send DESTRUCT message */
152 sendcmdto_serv_butone(&me
, CMD_DESTRUCT
, 0, "%s %Tu", chptr
->chname
, chptr
->creationtime
);
153 remove_destruct_event(chptr
);
154 destruct_channel(chptr
);