2 * IRC - Internet Relay Chat, ircd/jupe.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Finland
5 * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 1, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include "ircd_alloc.h"
28 #include "ircd_reply.h"
29 #include "ircd_string.h"
39 #include "sys.h" /* FALSE bleah */
43 static struct Jupe *GlobalJupeList = 0;
46 make_jupe(char *server, char *reason, time_t expire, time_t lastmod,
51 ajupe = (struct Jupe*) MyMalloc(sizeof(struct Jupe)); /* alloc memory */
54 DupString(ajupe->ju_server, server); /* copy vital information */
55 DupString(ajupe->ju_reason, reason);
56 ajupe->ju_expire = expire;
57 ajupe->ju_lastmod = lastmod;
58 ajupe->ju_flags = flags; /* set jupe flags */
60 ajupe->ju_next = GlobalJupeList; /* link it into the list */
61 ajupe->ju_prev_p = &GlobalJupeList;
63 GlobalJupeList->ju_prev_p = &ajupe->ju_next;
64 GlobalJupeList = ajupe;
70 do_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe)
74 if (!JupeIsActive(jupe)) /* no action to be taken on inactive jupes */
77 acptr = FindServer(jupe->ju_server);
79 /* server isn't online or isn't local or is me */
80 if (!acptr || !MyConnect(acptr) || IsMe(acptr))
83 return exit_client_msg(cptr, acptr, &me, "Juped: %s", jupe->ju_reason);
87 propagate_jupe(struct Client *cptr, struct Client *sptr, struct Jupe *jupe)
89 if (JupeIsLocal(jupe)) /* don't propagate local jupes */
92 sendcmdto_serv_butone(cptr, CMD_JUPE, sptr, "* %c%s %Tu %Tu :%s",
93 JupeIsActive(jupe) ? '+' : '-', jupe->ju_server,
94 jupe->ju_expire - CurrentTime, jupe->ju_lastmod,
99 jupe_add(struct Client *cptr, struct Client *sptr, char *server, char *reason,
100 time_t expire, time_t lastmod, unsigned int flags)
108 * You cannot set a negative (or zero) expire time, nor can you set an
109 * expiration time for greater than JUPE_MAX_EXPIRE.
111 if (expire <= 0 || expire > JUPE_MAX_EXPIRE) {
112 if (!IsServer(cptr) && MyConnect(cptr))
113 send_error_to_client(cptr, ERR_BADEXPIRE, expire);
117 expire += CurrentTime; /* convert from lifetime to timestamp */
119 /* Inform ops and log it */
120 sendto_op_mask(SNO_NETWORK, "%s adding %sJUPE for %s, expiring at "
122 IsServer(sptr) ? sptr->name : sptr->user->server->name,
123 flags & JUPE_LOCAL ? "local " : "", server,
124 expire + TSoffset, reason);
128 write_log(JPATH, TIME_T_FMT " %s adding %sJUPE for %s, expiring at "
129 TIME_T_FMT ": %s\n", TStime(), sptr->name,
130 flags & JUPE_LOCAL ? "local " : "", server, expire + TSoffset,
133 write_log(JPATH, TIME_T_FMT, " %s!%s@%s adding %sJUPE for %s, expiring at "
134 TIME_T_FMT ": %s\n", TStime(), sptr->name, sptr->user->username,
135 sptr->user->host, flags & JUPE_LOCAL ? "local " : "", server,
136 expire + TSoffset, reason);
140 ajupe = make_jupe(server, reason, expire, lastmod, flags);
142 propagate_jupe(cptr, sptr, ajupe);
144 return do_jupe(cptr, sptr, ajupe); /* remove server if necessary */
148 jupe_activate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe,
149 time_t lastmod, unsigned int flags)
152 assert(!JupeIsLocal(jupe));
154 jupe->ju_flags |= JUPE_ACTIVE;
156 if (jupe->ju_lastmod >= lastmod) /* force lastmod to increase */
159 jupe->ju_lastmod = lastmod;
161 /* Inform ops and log it */
162 sendto_op_mask(SNO_NETWORK, "%s activating JUPE for %s, expiring at "
164 IsServer(sptr) ? sptr->name : sptr->user->server->name,
165 jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
169 write_log(JPATH, TIME_T_FMT " %s activating JUPE for %s, expiring at "
170 TIME_T_FMT ": %s\n", TStime(), sptr->name, jupe->ju_server,
171 jupe->ju_expire + TSoffset, jupe->ju_reason);
173 write_log(JPATH, TIME_T_FMT, " %s!%s@%s activating JUPE for %s, "
174 "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
175 sptr->user->username, sptr->user->host, jupe->ju_server,
176 jupe->ju_expire + TSoffset, jupe->ju_reason);
179 propagate_jupe(cptr, sptr, jupe);
181 return do_jupe(cptr, sptr, jupe);
185 jupe_deactivate(struct Client *cptr, struct Client *sptr, struct Jupe *jupe,
186 time_t lastmod, unsigned int flags)
190 if (!JupeIsLocal(jupe)) {
191 jupe->ju_flags &= ~JUPE_ACTIVE;
193 if (jupe->ju_lastmod >= lastmod) /* force lastmod to increase */
196 jupe->ju_lastmod = lastmod;
199 /* Inform ops and log it */
200 sendto_op_mask(SNO_NETWORK, "%s %s JUPE for %s, expiring at " TIME_T_FMT
202 IsServer(sptr) ? sptr->name : sptr->user->server->name,
203 JupeIsLocal(jupe) ? "removing local" : "deactivating",
204 jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
208 write_log(JPATH, TIME_T_FMT " %s %s JUPE for %s, expiring at " TIME_T_FMT
209 ": %s\n", TStime(), sptr->name,
210 JupeIsLocal(jupe) ? "removing local" : "deactivating",
211 jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
213 write_log(JPATH, TIME_T_FMT, " %s!%s@%s %s JUPE for %s, "
214 "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
215 sptr->user->username, sptr->user->host,
216 JupeIsLocal(jupe) ? "removing local" : "deactivating",
217 jupe->ju_server, jupe->ju_expire + TSoffset, jupe->ju_reason);
220 if (JupeIsLocal(jupe))
223 propagate_jupe(cptr, sptr, jupe);
229 jupe_find(char *server)
234 for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
235 sjupe = jupe->ju_next;
237 if (jupe->ju_expire <= CurrentTime) /* expire any that need expiring */
239 else if (0 == ircd_strcmp(server, jupe->ju_server)) /* found it yet? */
247 jupe_free(struct Jupe* jupe)
251 *jupe->ju_prev_p = jupe->ju_next; /* squeeze this jupe out */
253 jupe->ju_next->ju_prev_p = jupe->ju_prev_p;
255 MyFree(jupe->ju_server); /* and free up the memory */
256 MyFree(jupe->ju_reason);
261 jupe_burst(struct Client *cptr)
266 for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
267 sjupe = jupe->ju_next;
269 if (jupe->ju_expire <= CurrentTime) /* expire any that need expiring */
271 else if (!JupeIsLocal(jupe)) /* forward global jupes */
272 sendcmdto_one(cptr, CMD_JUPE, &me, "* %c%s %Tu %Tu :%s",
273 JupeIsActive(jupe) ? '+' : '-', jupe->ju_server,
274 jupe->ju_expire - CurrentTime, jupe->ju_lastmod,
280 jupe_resend(struct Client *cptr, struct Jupe *jupe)
282 if (JupeIsLocal(jupe)) /* don't propagate local jupes */
285 sendcmdto_one(cptr, CMD_JUPE, &me, "* %c%s %Tu %Tu :%s",
286 JupeIsActive(jupe) ? '+' : '-', jupe->ju_server,
287 jupe->ju_expire - CurrentTime, jupe->ju_lastmod,
294 jupe_list(struct Client *sptr, char *server)
300 if (!(jupe = jupe_find(server))) /* no such jupe */
301 return send_error_to_client(sptr, ERR_NOSUCHJUPE, server);
303 /* send jupe information along */
304 sendto_one(sptr, rpl_str(RPL_JUPELIST), me.name, sptr->name,
305 jupe->ju_server, jupe->ju_expire + TSoffset,
306 JupeIsLocal(jupe) ? me.name : "*",
307 JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason);
309 for (jupe = GlobalJupeList; jupe; jupe = sjupe) { /* go through jupes */
310 sjupe = jupe->ju_next;
312 if (jupe->ju_expire <= CurrentTime) /* expire any that need expiring */
314 else /* send jupe information along */
315 sendto_one(sptr, rpl_str(RPL_JUPELIST), me.name, sptr->name,
316 jupe->ju_server, jupe->ju_expire + TSoffset,
317 JupeIsLocal(jupe) ? me.name : "*",
318 JupeIsActive(jupe) ? '+' : '-', jupe->ju_reason);
322 /* end of jupe information */
323 sendto_one(sptr, rpl_str(RPL_ENDOFJUPELIST), me.name, sptr->name);