2 * IRC - Internet Relay Chat, ircd/m_jupe.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
5 * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
7 * See file AUTHORS in IRC package for additional names of
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 1, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * m_functions execute protocol messages on this server:
30 * cptr is always NON-NULL, pointing to a *LOCAL* client
31 * structure (with an open socket connected!). This
32 * identifies the physical socket where the message
33 * originated (or which caused the m_function to be
34 * executed--some m_functions may call others...).
36 * sptr is the source of the message, defined by the
37 * prefix part of the message if present. If not
38 * or prefix not found, then sptr==cptr.
40 * (!IsServer(cptr)) => (cptr == sptr), because
41 * prefixes are taken *only* from servers...
44 * (sptr == cptr) => the message didn't
47 * (sptr != cptr && IsServer(sptr) means
48 * the prefix specified servername. (?)
50 * (sptr != cptr && !IsServer(sptr) means
51 * that message originated from a remote
56 * (!IsServer(sptr)) means that, sptr can safely
57 * taken as defining the target structure of the
58 * message in this server.
60 * *Always* true (if 'parse' and others are working correct):
62 * 1) sptr->from == cptr (note: cptr->from == cptr)
64 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
65 * *cannot* be a local connection, unless it's
66 * actually cptr!). [MyConnect(x) should probably
67 * be defined as (x == x->from) --msa ]
69 * parc number of variable parameter strings (if zero,
70 * parv is allowed to be NULL)
72 * parv a NULL terminated list of parameter pointers,
74 * parv[0], sender (prefix string), if not present
75 * this points to an empty string.
76 * parv[1]...parv[parc-1]
77 * pointers to additional parameters
78 * parv[parc] == NULL, *always*
80 * note: it is guaranteed that parv[0]..parv[parc-1] are all
87 * No need to include handlers.h here the signatures must match
88 * and we don't need to force a rebuild of all the handlers everytime
89 * we add a new one to the list. --Bleep
97 #include "ircd_features.h"
98 #include "ircd_reply.h"
99 #include "ircd_string.h"
103 #include "numnicks.h"
114 * ms_jupe - server message handler
116 * parv[0] = Send prefix
120 * parv[1] = Target: server numeric or *
121 * parv[2] = (+|-)<server name>
122 * parv[3] = Expiration offset
123 * parv[4] = Last modification time
127 int ms_jupe(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
129 struct Client *acptr = 0;
131 unsigned int flags = 0;
132 time_t expire_off, lastmod;
133 char *server = parv[2], *target = parv[1], *reason = parv[5];
136 return need_more_params(sptr, "JUPE");
138 if (!(target[0] == '*' && target[1] == '\0')) {
139 if (!(acptr = FindNServer(target)))
140 return 0; /* no such server */
142 if (!IsMe(acptr)) { /* manually propagate, since we don't set it */
143 sendcmdto_one(sptr, CMD_JUPE, acptr, "%s %s %s %s :%s", target, server,
144 parv[3], parv[4], reason);
153 else if (*server == '+') {
154 flags |= JUPE_ACTIVE;
158 expire_off = atoi(parv[3]);
159 lastmod = atoi(parv[4]);
161 ajupe = jupe_find(server);
164 if (JupeIsLocal(ajupe) && !(flags & JUPE_LOCAL)) /* global over local */
166 else if (JupeLastMod(ajupe) < lastmod) { /* new modification */
167 if (flags & JUPE_ACTIVE)
168 return jupe_activate(cptr, sptr, ajupe, lastmod, flags);
170 return jupe_deactivate(cptr, sptr, ajupe, lastmod, flags);
171 } else if (JupeLastMod(ajupe) == lastmod || IsBurstOrBurstAck(cptr))
174 return jupe_resend(cptr, ajupe); /* other server desynched WRT jupes */
177 return jupe_add(cptr, sptr, server, reason, expire_off, lastmod, flags);
181 * mo_jupe - oper message handler
183 * parv[0] = Send prefix
184 * parv[1] = [[+|-]<server name>]
186 * Local (to me) style:
188 * parv[2] = [Expiration offset]
189 * parv[3] = [Comment]
191 * Global (or remote local) style:
194 * parv[3] = [Expiration offset]
195 * parv[4] = [Comment]
198 int mo_jupe(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
200 struct Client *acptr = 0;
202 unsigned int flags = 0;
204 char *server = parv[1], *target = 0, *reason;
207 return jupe_list(sptr, 0);
209 if (*server == '+') {
210 flags |= JUPE_ACTIVE;
212 } else if (*server == '-')
215 return jupe_list(sptr, server);
217 if (!feature_bool(FEAT_CONFIG_OPERCMDS))
218 return send_reply(sptr, ERR_DISABLED, "JUPE");
221 expire_off = atoi(parv[2]);
224 } else if (parc > 4) {
226 expire_off = atoi(parv[3]);
229 return need_more_params(sptr, "JUPE");
232 if (!(target[0] == '*' && target[1] == '\0')) {
233 if (!(acptr = find_match_server(target)))
234 return send_reply(sptr, ERR_NOSUCHSERVER, target);
236 if (!IsMe(acptr)) { /* manually propagate, since we don't set it */
237 if (!HasPriv(sptr, PRIV_GLINE))
238 return send_reply(sptr, ERR_NOPRIVILEGES);
240 sendcmdto_one(sptr, CMD_JUPE, acptr, "%C %c%s %s %Tu :%s", acptr,
241 flags & JUPE_ACTIVE ? '+' : '-', server, parv[3],
244 } else if (!HasPriv(sptr, PRIV_LOCAL_GLINE))
245 return send_reply(sptr, ERR_NOPRIVILEGES);
248 } else if (!HasPriv(sptr, PRIV_GLINE))
249 return send_reply(sptr, ERR_NOPRIVILEGES);
252 ajupe = jupe_find(server);
255 if (JupeIsLocal(ajupe) && !(flags & JUPE_LOCAL)) /* global over local */
258 if (flags & JUPE_ACTIVE)
259 return jupe_activate(cptr, sptr, ajupe, TStime(), flags);
261 return jupe_deactivate(cptr, sptr, ajupe, TStime(), flags);
265 return jupe_add(cptr, sptr, server, reason, expire_off, TStime(), flags);
269 * m_jupe - user message handler
271 * parv[0] = Send prefix
275 * parv[1] = [<server name>]
278 int m_jupe(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
281 return jupe_list(sptr, 0);
283 return jupe_list(sptr, parv[1]);