]> jfr.im git - irc/quakenet/snircd-patchqueue.git/blob - split.patch
split.patch placed a server = parv[1]; in the wrong place causing a core upon parsing...
[irc/quakenet/snircd-patchqueue.git] / split.patch
1 work in progress
2 Add split functionality into ircd
3 Add /split command
4 Add /stats S/split (make /STATS s/S case sensitive, s spoofhosts)
5 Add feature SPLIT
6 Add split.c split.h m_split.c
7
8 NOTE: feature SPLIT is default enabled as that is just easier when working on this patch.
9
10 diff -r 3ab25cd90c2e doc/api/log.txt
11 --- a/doc/api/log.txt Tue Jan 27 20:50:02 2009 +0100
12 +++ b/doc/api/log.txt Tue Jan 27 21:14:37 2009 +0100
13 @@ -41,7 +41,7 @@
14
15 <enum>
16 enum LogSys {
17 - LS_SYSTEM, LS_CONFIG, LS_OPERMODE, LS_GLINE, LS_JUPE, LS_WHO, LS_NETWORK,
18 + LS_SYSTEM, LS_CONFIG, LS_OPERMODE, LS_GLINE, LS_JUPE, LS_SPLIT, LS_WHO, LS_NETWORK,
19 LS_OPERKILL, LS_SERVKILL, LS_USER, LS_OPER, LS_RESOLVER, LS_SOCKET,
20 LS_DEBUG, LS_OLDLOG,
21 LS_LAST_SYSTEM
22 diff -r 3ab25cd90c2e include/handlers.h
23 --- a/include/handlers.h Tue Jan 27 20:50:02 2009 +0100
24 +++ b/include/handlers.h Tue Jan 27 21:14:37 2009 +0100
25 @@ -139,6 +139,7 @@
26 extern int m_registered(struct Client*, struct Client*, int, char*[]);
27 extern int m_sethost(struct Client*, struct Client*, int, char*[]);
28 extern int m_silence(struct Client*, struct Client*, int, char*[]);
29 +extern int m_split(struct Client*, struct Client*, int, char*[]);
30 extern int m_stats(struct Client*, struct Client*, int, char*[]);
31 extern int m_time(struct Client*, struct Client*, int, char*[]);
32 extern int m_topic(struct Client*, struct Client*, int, char*[]);
33 @@ -179,6 +180,7 @@
34 extern int mo_rping(struct Client*, struct Client*, int, char*[]);
35 extern int mo_set(struct Client*, struct Client*, int, char*[]);
36 extern int mo_settime(struct Client*, struct Client*, int, char*[]);
37 +extern int mo_split(struct Client*, struct Client*, int, char*[]);
38 extern int mo_squit(struct Client*, struct Client*, int, char*[]);
39 extern int mo_stats(struct Client*, struct Client*, int, char*[]);
40 extern int mo_trace(struct Client*, struct Client*, int, char*[]);
41 @@ -234,6 +236,7 @@
42 extern int ms_sethost(struct Client*, struct Client*, int, char*[]);
43 extern int ms_settime(struct Client*, struct Client*, int, char*[]);
44 extern int ms_silence(struct Client*, struct Client*, int, char*[]);
45 +extern int ms_split(struct Client*, struct Client*, int, char*[]);
46 extern int ms_squit(struct Client*, struct Client*, int, char*[]);
47 extern int ms_stats(struct Client*, struct Client*, int, char*[]);
48 extern int ms_topic(struct Client*, struct Client*, int, char*[]);
49 diff -r 3ab25cd90c2e include/ircd_features.h
50 --- a/include/ircd_features.h Tue Jan 27 20:50:02 2009 +0100
51 +++ b/include/ircd_features.h Tue Jan 27 21:14:37 2009 +0100
52 @@ -112,6 +112,10 @@
53 FEAT_SETHOST_USER,
54 FEAT_SETHOST_AUTO,
55
56 + /* SPLIT */
57 + FEAT_SPLIT,
58 + FEAT_SPLIT_AUTO_EXPIRE,
59 +
60 /* HEAD_IN_SAND Features */
61 FEAT_HIS_SNOTICES,
62 FEAT_HIS_SNOTICES_OPER_ONLY,
63 @@ -139,6 +143,7 @@
64 FEAT_HIS_STATS_q,
65 FEAT_HIS_STATS_R,
66 FEAT_HIS_STATS_r,
67 + FEAT_HIS_STATS_S,
68 FEAT_HIS_STATS_s,
69 FEAT_HIS_STATS_t,
70 FEAT_HIS_STATS_T,
71 diff -r 3ab25cd90c2e include/ircd_log.h
72 --- a/include/ircd_log.h Tue Jan 27 20:50:02 2009 +0100
73 +++ b/include/ircd_log.h Tue Jan 27 21:14:37 2009 +0100
74 @@ -55,6 +55,7 @@
75 LS_OPERMODE, /**< Uses of OPMODE, CLEARMODE< etc. */
76 LS_GLINE, /**< Adding, (de-)activating or removing GLINEs. */
77 LS_JUPE, /**< Adding, (de-)activating or removing JUPEs. */
78 + LS_SPLIT, /**< Adding, (de-)activating or removing SPLITs. */
79 LS_WHO, /**< Use of extended WHO privileges. */
80 LS_NETWORK, /**< New server connections. */
81 LS_OPERKILL, /**< Kills by IRC operators. */
82 diff -r 3ab25cd90c2e include/msg.h
83 --- a/include/msg.h Tue Jan 27 20:50:02 2009 +0100
84 +++ b/include/msg.h Tue Jan 27 21:14:37 2009 +0100
85 @@ -336,6 +336,10 @@
86 #define TOK_JUPE "JU"
87 #define CMD_JUPE MSG_JUPE, TOK_JUPE
88
89 +#define MSG_SPLIT "SPLIT" /* SPLIT */
90 +#define TOK_SPLIT "SP"
91 +#define CMD_SPLIT MSG_SPLIT, TOK_SPLIT
92 +
93 #define MSG_OPMODE "OPMODE" /* OPMO */
94 #define TOK_OPMODE "OM"
95 #define CMD_OPMODE MSG_OPMODE, TOK_OPMODE
96 diff -r 3ab25cd90c2e include/numeric.h
97 --- a/include/numeric.h Tue Jan 27 20:50:02 2009 +0100
98 +++ b/include/numeric.h Tue Jan 27 21:14:37 2009 +0100
99 @@ -118,6 +118,7 @@
100 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
101 #define RPL_STATSWELCOME 227 /* QuakeNet extension */
102 #define RPL_STATSQLINE 228 /* Undernet extension */
103 +#define RPL_STATSSPLIT 229 /* QuakeNet extension */
104 #define RPL_STATSHEADER 230 /* QuakeNet extension */
105
106 /* RPL_SERVICEINFO 231 unused */
107 @@ -179,6 +180,8 @@
108 #define RPL_STATSDLINE 275 /* Undernet extension */
109 #define RPL_STATSRLINE 276 /* Undernet extension */
110
111 +#define RPL_SPLITLIST 278 /* QuakeNet extension */
112 +#define RPL_ENDOFSPLITLIST 279 /* QuakeNet extension */
113 #define RPL_GLIST 280 /* Undernet extension */
114 #define RPL_ENDOFGLIST 281 /* Undernet extension */
115 #define RPL_JUPELIST 282 /* Undernet extension - jupe -Kev */
116 @@ -449,6 +452,7 @@
117
118 #define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
119
120 +#define ERR_NOSUCHSPLIT 510 /* QuakeNet extension */
121 #define ERR_SILELISTFULL 511 /* Undernet extension */
122 /* ERR_NOTIFYFULL 512 aircd */
123 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
124 diff -r 3ab25cd90c2e include/split.h
125 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
126 +++ b/include/split.h Tue Jan 27 21:14:37 2009 +0100
127 @@ -0,0 +1,106 @@
128 +#ifndef INCLUDED_split_h
129 +#define INCLUDED_split_h
130 +/*
131 + * IRC - Internet Relay Chat, include/split.h
132 + * Copyright (C) 1990 Jarkko Oikarinen and
133 + * University of Oulu, Computing Center
134 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
135 + *
136 + * This program is free software; you can redistribute it and/or modify
137 + * it under the terms of the GNU General Public License as published by
138 + * the Free Software Foundation; either version 2, or (at your option)
139 + * any later version.
140 + *
141 + * This program is distributed in the hope that it will be useful,
142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144 + * GNU General Public License for more details.
145 + *
146 + * You should have received a copy of the GNU General Public License
147 + * along with this program; if not, write to the Free Software
148 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
149 + */
150 +/** @file
151 + * @brief Interface and declarations for split server handling.
152 + * @version $Id: jupe.h 1208 2004-10-03 14:12:35Z entrope $
153 + */
154 +#ifndef INCLUDED_sys_types_h
155 +#include <sys/types.h>
156 +#define INCLUDED_sys_types_h
157 +#endif
158 +
159 +
160 +struct Client;
161 +struct StatDesc;
162 +
163 +#define SPLIT_MAX_EXPIRE 2419200 /**< Maximum split expiration time (4 weeks). */
164 +
165 +/* Describes a SPLIT server entry. */
166 +struct Split {
167 + struct Split* sp_next; /**< Pointer to next Split. */
168 + struct Split** sp_prev_p; /**< Pointer to previous next pointer. */
169 + char* sp_server; /**< Name of server. */
170 + char* sp_reason; /**< Reason. */
171 + time_t sp_creation; /**< TODO: Creation time. What are we using this for then? */
172 + time_t sp_expire; /**< Expiration time. */
173 + time_t sp_lastmod; /**< Last modification time. */
174 + time_t sp_lifetime; /**< Life time. */
175 + unsigned int sp_flags; /**< Status flags. */
176 +};
177 +
178 +/** Split state flags. */
179 +#define SPLIT_ACTIVE 0x01 /**< Split is active. */
180 +#define SPLIT_REMOVING 0x02 /**< Split is being force removed (instead of deactivated). */
181 +#define SPLIT_BURST 0x04 /**< Split is for a server that is in progress of linking,
182 + and will be destroyed at the end of burst */
183 +
184 +/* Actions to perform on a SPLIT. */
185 +enum SplitAction {
186 + SPLIT_ACTIVATE, /**< SPLIT should be activated. */
187 + SPLIT_DEACTIVATE, /**< SPLIT should be deactivated. */
188 + SPLIT_MODIFY, /**< SPLIT should be modified. */
189 + SPLIT_REMOVE /**< SPLIT should be removed. */
190 +};
191 +
192 +/* Split update flags. */
193 +#define SPLIT_EXPIRE 0x01 /**< Expiration time update. */
194 +#define SPLIT_LIFETIME 0x02 /**< Record lifetime update. */
195 +#define SPLIT_REASON 0x04 /**< Reason update. */
196 +#define SPLIT_CREATION 0x08 /**< TODO: Creation time update - unused. */
197 +#define SPLIT_MODIFY 0x10 /**< No state change. */
198 +
199 +/* mask for Split update flags. */
200 +#define SPLIT_UPDATE (SPLIT_EXPIRE | SPLIT_CREATION | SPLIT_LIFETIME | SPLIT_REASON)
201 +
202 +/* test whether a split entry is active. */
203 +#define SplitIsActive(s) ((s)->sp_flags & SPLIT_ACTIVE)
204 +/* test whether a split entry is marked for forced removal. */
205 +#define SplitIsRemoving(s) ((s)->sp_flags & SPLIT_REMOVING)
206 +/* test whether a split entry is part of a netmerge. */
207 +#define SplitIsBurst(s) ((s)->sp_flags & SPLIT_BURST)
208 +
209 +extern int split_add(struct Client *cptr, struct Client *sptr,
210 + char *server, const char *reason,
211 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
212 + unsigned int flags);
213 +extern int split_modify(struct Client *cptr, struct Client *sptr,
214 + struct Split *split, enum SplitAction action, const char *reason,
215 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
216 + unsigned int flags);
217 +extern int split_remove(struct Client *cptr, struct Client *sptr,
218 + struct Split *split, const char *reason);
219 +
220 +extern struct Split* split_find(char *server);
221 +extern void split_free(struct Split *split);
222 +extern int split_expire(struct Split* split);
223 +extern void split_burst(struct Client *cptr);
224 +extern int split_resend(struct Client *cptr, struct Split *split);
225 +extern int split_list(struct Client *sptr, char *server);
226 +extern void split_newserver(struct Client *acptr);
227 +extern int split_netmerge(struct Client *sptr);
228 +extern int split_netbreak(struct Client *victim, const char *reason);
229 +extern void split_conf();
230 +extern void split_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
231 +extern int split_memory_count(size_t *sp_size);
232 +
233 +#endif /* INCLUDED_split_h */
234 diff -r 3ab25cd90c2e ircd/Makefile.in
235 --- a/ircd/Makefile.in Tue Jan 27 20:50:02 2009 +0100
236 +++ b/ircd/Makefile.in Tue Jan 27 21:14:37 2009 +0100
237 @@ -173,6 +173,7 @@
238 m_sethost.c \
239 m_settime.c \
240 m_silence.c \
241 + m_split.c \
242 m_squit.c \
243 m_stats.c \
244 m_time.c \
245 @@ -213,6 +214,7 @@
246 s_stats.c \
247 s_user.c \
248 send.c \
249 + split.c \
250 uping.c \
251 userload.c \
252 welcome.c \
253 @@ -1054,6 +1056,15 @@
254 ../include/ircd_chattr.h ../include/list.h ../include/msg.h \
255 ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
256 ../include/send.h ../include/struct.h
257 +m_split.o: m_split.c ../config.h ../include/client.h ../include/ircd_defs.h \
258 + ../include/dbuf.h ../include/msgq.h ../include/ircd_events.h \
259 + ../config.h ../include/ircd_handler.h ../include/res.h \
260 + ../include/capab.h ../include/split.h ../include/hash.h \
261 + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \
262 + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \
263 + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
264 + ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \
265 + ../include/client.h ../include/s_misc.h ../include/send.h
266 m_squit.o: m_squit.c ../config.h ../include/client.h \
267 ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \
268 ../include/ircd_events.h ../config.h ../include/ircd_handler.h \
269 @@ -1332,6 +1343,7 @@
270 ../include/msgq.h ../include/numeric.h ../include/numnicks.h \
271 ../include/res.h ../include/s_bsd.h ../include/s_conf.h \
272 ../include/s_user.h ../include/s_stats.h ../include/send.h \
273 + ../include/split.h \
274 ../include/struct.h ../include/sys.h ../include/whowas.h
275 s_err.o: s_err.c ../config.h ../include/numeric.h ../include/ircd_log.h \
276 ../include/s_debug.h ../config.h ../include/ircd_defs.h
277 @@ -1417,6 +1429,16 @@
278 ../include/msg.h ../include/numnicks.h ../include/parse.h \
279 ../include/s_bsd.h ../include/s_debug.h ../include/s_misc.h \
280 ../include/s_user.h ../include/struct.h ../include/sys.h
281 +split.o: split.c ../config.h ../include/split.h ../include/client.h \
282 + ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \
283 + ../include/ircd_events.h ../config.h ../include/ircd_handler.h \
284 + ../include/res.h ../include/capab.h ../include/hash.h ../include/ircd.h \
285 + ../include/struct.h ../include/ircd_alloc.h ../include/ircd_features.h \
286 + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \
287 + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
288 + ../include/numeric.h ../include/numnicks.h ../include/s_bsd.h \
289 + ../include/s_misc.h ../include/send.h ../include/struct.h \
290 + ../include/sys.h
291 uping.o: uping.c ../config.h ../include/uping.h ../include/ircd_defs.h \
292 ../include/ircd_events.h ../config.h ../include/res.h \
293 ../include/client.h ../include/dbuf.h ../include/msgq.h \
294 diff -r 3ab25cd90c2e ircd/ircd.c
295 --- a/ircd/ircd.c Tue Jan 27 20:50:02 2009 +0100
296 +++ b/ircd/ircd.c Tue Jan 27 21:14:37 2009 +0100
297 @@ -55,6 +55,7 @@
298 #include "s_misc.h"
299 #include "s_stats.h"
300 #include "send.h"
301 +#include "split.h"
302 #include "sys.h"
303 #include "uping.h"
304 #include "userload.h"
305 @@ -763,6 +764,9 @@
306 Debug((DEBUG_NOTICE, "Server ready..."));
307 log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");
308
309 + /* create SPLITs */
310 + split_conf();
311 +
312 event_loop();
313
314 return 0;
315 diff -r 3ab25cd90c2e ircd/ircd_features.c
316 --- a/ircd/ircd_features.c Tue Jan 27 20:50:02 2009 +0100
317 +++ b/ircd/ircd_features.c Tue Jan 27 21:14:37 2009 +0100
318 @@ -366,6 +366,10 @@
319 F_B(SETHOST_USER, 0, 0, 0),
320 F_B(SETHOST_AUTO, 0, 0, 0),
321
322 + /* SPLIT */
323 + F_B(SPLIT, 0, 1, 0),
324 + F_I(SPLIT_AUTO_EXPIRE, 0, 604800, 0),
325 +
326 /* HEAD_IN_SAND Features */
327 F_B(HIS_SNOTICES, 0, 1, 0),
328 F_B(HIS_SNOTICES_OPER_ONLY, 0, 1, 0),
329 @@ -393,6 +397,7 @@
330 F_B(HIS_STATS_q, 0, 1, 0),
331 F_B(HIS_STATS_R, 0, 1, 0),
332 F_B(HIS_STATS_r, 0, 1, 0),
333 + F_B(HIS_STATS_S, 0, 1, 0),
334 F_B(HIS_STATS_s, 0, 1, 0),
335 F_B(HIS_STATS_t, 0, 1, 0),
336 F_B(HIS_STATS_T, 0, 1, 0),
337 diff -r 3ab25cd90c2e ircd/ircd_log.c
338 --- a/ircd/ircd_log.c Tue Jan 27 20:50:02 2009 +0100
339 +++ b/ircd/ircd_log.c Tue Jan 27 21:14:37 2009 +0100
340 @@ -154,6 +154,7 @@
341 S(OPERMODE, -1, SNO_HACK4),
342 S(GLINE, -1, SNO_GLINE),
343 S(JUPE, -1, SNO_NETWORK),
344 + S(SPLIT, -1, SNO_NETWORK),
345 S(WHO, -1, 0),
346 S(NETWORK, -1, SNO_NETWORK),
347 S(OPERKILL, -1, 0),
348 diff -r 3ab25cd90c2e ircd/m_endburst.c
349 --- a/ircd/m_endburst.c Tue Jan 27 20:50:02 2009 +0100
350 +++ b/ircd/m_endburst.c Tue Jan 27 21:14:37 2009 +0100
351 @@ -85,6 +85,7 @@
352 #include "client.h"
353 #include "hash.h"
354 #include "ircd.h"
355 +#include "ircd_features.h"
356 #include "ircd_log.h"
357 #include "ircd_reply.h"
358 #include "ircd_string.h"
359 @@ -92,6 +93,7 @@
360 #include "numeric.h"
361 #include "numnicks.h"
362 #include "send.h"
363 +#include "split.h"
364
365 /* #include <assert.h> -- Now using assert in ircd_log.h */
366
367 @@ -125,6 +127,7 @@
368 int ms_end_of_burst(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
369 {
370 struct Channel *chan, *next_chan;
371 + int split;
372
373 assert(0 != cptr);
374 assert(0 != sptr);
375 @@ -135,6 +138,10 @@
376 dump_map(sptr, "*", 0, report_new_links, 0);
377 sendto_opmask_butone(0, SNO_NETWORK, "Completed net.burst from %C.",
378 sptr);
379 + /* cleanup SPLITs, but only bother ops when FEAT_SPLIT is enabled. */
380 + split = split_netmerge(sptr);
381 + if (feature_bool(FEAT_SPLIT))
382 + sendto_opmask_butone(0, SNO_NETWORK, "Removed %d SPLIT entries.", split);
383 if (MyConnect(sptr))
384 sendcmdto_one(&me, CMD_END_OF_BURST_ACK, sptr, "");
385
386 diff -r 3ab25cd90c2e ircd/m_reburst.c
387 --- a/ircd/m_reburst.c Tue Jan 27 20:50:02 2009 +0100
388 +++ b/ircd/m_reburst.c Tue Jan 27 21:14:37 2009 +0100
389 @@ -102,6 +102,7 @@
390 #include "ircd_snprintf.h"
391 #include "gline.h"
392 #include "jupe.h"
393 +#include "split.h"
394
395 /* #include <assert.h> -- Now using assert in ircd_log.h */
396 #include <stdlib.h>
397 @@ -130,6 +131,10 @@
398 case 'J':
399 jupe_burst(sptr);
400 break;
401 + case 's':
402 + case 'S':
403 + split_burst(sptr);
404 + break;
405 default:
406 break;
407 }
408 diff -r 3ab25cd90c2e ircd/m_server.c
409 --- a/ircd/m_server.c Tue Jan 27 20:50:02 2009 +0100
410 +++ b/ircd/m_server.c Tue Jan 27 21:14:37 2009 +0100
411 @@ -47,6 +47,7 @@
412 #include "s_misc.h"
413 #include "s_serv.h"
414 #include "send.h"
415 +#include "split.h"
416 #include "userload.h"
417
418 /* #include <assert.h> -- Now using assert in ircd_log.h */
419 @@ -764,6 +765,9 @@
420 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s",
421 cli_name(sptr), cli_name(acptr));
422 }
423 + /* new server - mark SPLIT for this server */
424 + split_newserver(acptr);
425 +
426 /*
427 * Old sendto_serv_but_one() call removed because we now need to send
428 * different names to different servers (domain name matching).
429 diff -r 3ab25cd90c2e ircd/m_split.c
430 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
431 +++ b/ircd/m_split.c Tue Jan 27 21:14:37 2009 +0100
432 @@ -0,0 +1,378 @@
433 +/*
434 + * IRC - Internet Relay Chat, ircd/m_split.c
435 + * Copyright (C) 1990 Jarkko Oikarinen and
436 + * University of Oulu, Computing Center
437 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
438 + *
439 + * See file AUTHORS in IRC package for additional names of
440 + * the programmers.
441 + *
442 + * This program is free software; you can redistribute it and/or modify
443 + * it under the terms of the GNU General Public License as published by
444 + * the Free Software Foundation; either version 1, or (at your option)
445 + * any later version.
446 + *
447 + * This program is distributed in the hope that it will be useful,
448 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
449 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
450 + * GNU General Public License for more details.
451 + *
452 + * You should have received a copy of the GNU General Public License
453 + * along with this program; if not, write to the Free Software
454 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
455 + *
456 + * $Id: m_split.c 1737 2006-12-19 05:20:48Z entrope $
457 + */
458 +
459 +/*
460 + * m_functions execute protocol messages on this server:
461 + *
462 + * cptr is always NON-NULL, pointing to a *LOCAL* client
463 + * structure (with an open socket connected!). This
464 + * identifies the physical socket where the message
465 + * originated (or which caused the m_function to be
466 + * executed--some m_functions may call others...).
467 + *
468 + * sptr is the source of the message, defined by the
469 + * prefix part of the message if present. If not
470 + * or prefix not found, then sptr==cptr.
471 + *
472 + * (!IsServer(cptr)) => (cptr == sptr), because
473 + * prefixes are taken *only* from servers...
474 + *
475 + * (IsServer(cptr))
476 + * (sptr == cptr) => the message didn't
477 + * have the prefix.
478 + *
479 + * (sptr != cptr && IsServer(sptr) means
480 + * the prefix specified servername. (?)
481 + *
482 + * (sptr != cptr && !IsServer(sptr) means
483 + * that message originated from a remote
484 + * user (not local).
485 + *
486 + * combining
487 + *
488 + * (!IsServer(sptr)) means that, sptr can safely
489 + * taken as defining the target structure of the
490 + * message in this server.
491 + *
492 + * *Always* true (if 'parse' and others are working correct):
493 + *
494 + * 1) sptr->from == cptr (note: cptr->from == cptr)
495 + *
496 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
497 + * *cannot* be a local connection, unless it's
498 + * actually cptr!). [MyConnect(x) should probably
499 + * be defined as (x == x->from) --msa ]
500 + *
501 + * parc number of variable parameter strings (if zero,
502 + * parv is allowed to be NULL)
503 + *
504 + * parv a NULL terminated list of parameter pointers,
505 + *
506 + * parv[0], sender (prefix string), if not present
507 + * this points to an empty string.
508 + * parv[1]...parv[parc-1]
509 + * pointers to additional parameters
510 + * parv[parc] == NULL, *always*
511 + *
512 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
513 + * non-NULL pointers.
514 + */
515 +#include "config.h"
516 +
517 +#include "client.h"
518 +#include "split.h"
519 +#include "hash.h"
520 +#include "ircd.h"
521 +#include "ircd_features.h"
522 +#include "ircd_log.h"
523 +#include "ircd_reply.h"
524 +#include "ircd_string.h"
525 +#include "match.h"
526 +#include "msg.h"
527 +#include "numeric.h"
528 +#include "numnicks.h"
529 +#include "s_conf.h"
530 +#include "s_debug.h"
531 +#include "s_misc.h"
532 +#include "send.h"
533 +
534 +/* #include <assert.h> -- Now using assert in ircd_log.h */
535 +#include <stdlib.h>
536 +#include <string.h>
537 +
538 +/*
539 + * ms_split - server message handler
540 + *
541 + * parv[0] = Send prefix
542 + * parv[1] = (+|-)<server name>
543 + * parv[2] = Creation time
544 + * parv[3] = Expiration time
545 + * parv[4] = Last modification time
546 + * parv[5] = Life time
547 + * parv[6] = Comment
548 + *
549 + */
550 +int ms_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
551 +{
552 + struct Client *acptr = 0;
553 + struct Split *asplit = 0;
554 + unsigned int flags = 0;
555 + enum SplitAction action = SPLIT_MODIFY;
556 + time_t creation = 0, expire = 0, lastmod = 0, lifetime = 0;
557 + char *server;
558 + const char *reason = "No reason";
559 +
560 + /* reason is optional - for lazy services, we always send it */
561 + if (parc < 5)
562 + return need_more_params(sptr, "SPLIT");
563 +
564 + /* server param */
565 + server = parv[1];
566 +
567 + if (*server == '!') {
568 + server++;
569 + action = SPLIT_REMOVE; /* removing entry */
570 + }
571 +
572 + switch (*server) { /* handle + and - */
573 + case '+': /* activate the split entry */
574 + if (action != SPLIT_REMOVE)
575 + action = SPLIT_ACTIVATE;
576 + server++;
577 + break;
578 +
579 + case '-': /* deactivate the entry */
580 + if (action != SPLIT_REMOVE)
581 + action = SPLIT_DEACTIVATE;
582 + server++;
583 + break;
584 + }
585 +
586 + /* Next, try to find the split entry... */
587 + asplit = split_find(server);
588 +
589 + /* We now have all the pieces to tell us what we've got; let's put
590 + * it all together and convert the rest of the arguments.
591 + */
592 +
593 + /* can't modify a split entry that doesn't exist, so remap to activate */
594 + if (!asplit && action == SPLIT_MODIFY)
595 + action = SPLIT_ACTIVATE;
596 +
597 + /* set all flags for modification */
598 + if (asplit && action != SPLIT_REMOVE)
599 + flags = SPLIT_UPDATE;
600 +
601 + /* set the things we need */
602 + creation = atoi(parv[2]);
603 + expire = atoi(parv[3]);
604 + lastmod = atoi(parv[4]);
605 + lifetime = atoi(parv[5]);
606 + /* got a reason too */
607 + if (parc < 6)
608 + reason = parv[parc - 1];
609 +
610 + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; "
611 + "server %s, action %s, creation %Tu, expire %Tu, "
612 + "lastmod %Tu, lifetime %Tu, reason: %s; split %s!", server,
613 + action == SPLIT_REMOVE ? "!-" :
614 + (action == SPLIT_ACTIVATE ? "+" :
615 + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")),
616 + creation, expire, lastmod, lifetime, reason,
617 + asplit ? "EXISTS" : "does not exist"));
618 +
619 + /* OK, at this point, we have converted all available parameters.
620 + * Let's actually do the action!
621 + */
622 + if (asplit) {
623 + if (action == SPLIT_REMOVE)
624 + return split_remove(cptr, sptr, asplit, reason);
625 + return split_modify(cptr, sptr, asplit, action, reason, creation, expire,
626 + lastmod, lifetime, flags);
627 + }
628 +
629 + /* desynch or cross - we do not have it so we cannot remove it */
630 + /* TODO: manually propagate the message ?
631 + * ..but if we do not have it, can our downlinks have it?
632 + * they could if my oper force removed it earlier, and then my downlinks linked
633 + * no, then they would have bursted it again to us.. argh
634 + */
635 + if (!asplit && action == SPLIT_REMOVE)
636 + return 0;
637 +
638 + assert(action != SPLIT_MODIFY);
639 + assert(action != SPLIT_REMOVE);
640 +
641 + /* only give one flag when needed - SPLIT_ACTIVE */
642 + return split_add(cptr, sptr, server, reason, creation, expire, lastmod, lifetime,
643 + (flags & SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0);
644 +}
645 +
646 +
647 +/*
648 + * mo_split - oper message handler
649 + *
650 + * Local listing: 1 or 2 params
651 + * parv[0] = Send prefix
652 + * parv[1] = [Server or mask to match]
653 + *
654 + * Add or modify entry: 3, 4 or 5 params (3 is * then)
655 + * parv[0] = Send prefix
656 + * parv[1] = [+|-]<server name>
657 + * parv[2] = [Expiration offset] (required for new)
658 + * parv[3] = [Comment] (required for new)
659 + *
660 + */
661 +int mo_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
662 +{
663 + struct Client *acptr = 0;
664 + struct Split *asplit = 0;
665 + unsigned int flags = 0;
666 + enum SplitAction action = SPLIT_MODIFY;
667 + time_t expire = 0, lastmod = TStime(), creation = TStime();
668 + char *server = parv[1], *end;
669 + const char *reason = NULL;
670 +
671 + /* listing */
672 + if (parc < 2) {
673 + if (!HasPriv(sptr, PRIV_ROUTEINFO))
674 + return send_reply(sptr, ERR_NOPRIVILEGES);
675 + else
676 + return split_list(sptr, 0);
677 + }
678 +
679 + /* force removal */
680 + if (*server == '!') {
681 + server++;
682 + action = SPLIT_REMOVE;
683 + }
684 +
685 + switch (*server) { /* handle + and - */
686 + case '+': /* activate the split entry */
687 + if (action != SPLIT_REMOVE)
688 + action = SPLIT_ACTIVATE;
689 + server++;
690 + break;
691 +
692 + case '-': /* deactivate the split entry */
693 + if (action != SPLIT_REMOVE)
694 + action = SPLIT_DEACTIVATE;
695 + server++;
696 + break;
697 + }
698 +
699 + /* user wants listing */
700 + if (action == SPLIT_MODIFY && parc == 2)
701 + return split_list(sptr, server);
702 +
703 + /* if we have an expire, this must be it */
704 + if (parc > 2)
705 + expire = strtol(parv[2], &end, 10); /* and the expiration */
706 +
707 + /* got reason and expire */
708 + if (parc > 3) {
709 + flags |= SPLIT_EXPIRE;
710 + flags |= SPLIT_REASON;
711 + }
712 + /* got reason or expire */
713 + else if (parc > 2) {
714 + if (*end != '\0')
715 + flags |= SPLIT_REASON;
716 + else
717 + flags |= SPLIT_EXPIRE;
718 + }
719 +
720 + /* set reason */
721 + if (flags & SPLIT_REASON) {
722 + reason = parv[parc - 1];
723 + if (reason[0] == '\0') /* reason is empty */
724 + flags &= ~SPLIT_REASON;
725 + }
726 +
727 + /* bad expire */
728 + if (flags & SPLIT_EXPIRE && *end != '\0')
729 + return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE, "%s :Bad expire time", parv[2]);
730 +
731 + /* require a reason for forced removal */
732 + if (!(flags & SPLIT_REASON) && action == SPLIT_REMOVE)
733 + return need_more_params(sptr, "SPLIT");
734 +
735 + /* we got expire */
736 + if (flags & SPLIT_EXPIRE) {
737 + if (expire == 0) /* dummy value 0 given, no change to expire */
738 + flags &= ~SPLIT_EXPIRE;
739 + else /* turn expire into timestamp */
740 + expire += TStime();
741 + }
742 +
743 + /* check feature and privs */
744 + if (!feature_bool(FEAT_SPLIT)) /* TODO: but allow force removal? */
745 + return send_reply(sptr, ERR_DISABLED, "SPLIT");
746 + else if (!HasPriv(sptr, PRIV_SERVERINFO)) /* TODO: create PRIV_SPLIT - need help there */
747 + return send_reply(sptr, ERR_NOPRIVILEGES);
748 +
749 + /* find the split */
750 + asplit = split_find(server);
751 +
752 + /* We now have all the pieces to tell us what we've got; let's put
753 + * it all together and convert the rest of the arguments.
754 + */
755 +
756 + /* SPLIT not found and thus we cannot:
757 + * remove SPLIT we do not have
758 + * add new SPLIT without expire and reason
759 + */
760 + if (!asplit &&
761 + ((action == SPLIT_REMOVE) ||
762 + (action == SPLIT_ACTIVATE && !reason) ||
763 + (action == SPLIT_DEACTIVATE && !reason) ||
764 + (action == SPLIT_MODIFY && !reason)))
765 + return send_reply(sptr, ERR_NOSUCHSPLIT, server);
766 +
767 + /* can't modify a split entry that doesn't exist, so remap to activate */
768 + if (!asplit && action == SPLIT_MODIFY)
769 + action = SPLIT_ACTIVATE;
770 +
771 + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; "
772 + "server %s, action %s, expire %Tu, "
773 + "reason: %s; split %s! (fields present: %s %s)", server,
774 + action == SPLIT_REMOVE ? "!-" :
775 + (action == SPLIT_ACTIVATE ? "+" :
776 + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")),
777 + expire, reason, asplit ? "EXISTS" : "does not exist",
778 + flags & SPLIT_EXPIRE ? "expire" : "",
779 + flags & SPLIT_REASON ? "reason" : ""));
780 +
781 + if (asplit) { /* modifying an existing SPLIT */
782 + if (action == SPLIT_REMOVE)
783 + return split_remove(cptr, sptr, asplit, reason);
784 + return split_modify(cptr, sptr, asplit, action, reason,
785 + asplit->sp_creation, expire, lastmod, asplit->sp_lifetime, flags);
786 + }
787 +
788 + assert(action != SPLIT_MODIFY);
789 + assert(action != SPLIT_REMOVE);
790 +
791 + /* create a new SPLIT */
792 + return split_add(cptr, sptr, server, reason,
793 + creation, expire, lastmod, expire,
794 + flags | ((action == SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0));
795 +}
796 +
797 +/*
798 + * m_split - user message handler
799 + *
800 + * parv[0] = Send prefix
801 + * parv[1] = [<server name>]
802 + *
803 + */
804 +int m_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
805 +{
806 + if (parc < 2)
807 + return split_list(sptr, 0);
808 +
809 + return split_list(sptr, parv[1]);
810 +}
811 diff -r 3ab25cd90c2e ircd/parse.c
812 --- a/ircd/parse.c Tue Jan 27 20:50:02 2009 +0100
813 +++ b/ircd/parse.c Tue Jan 27 21:14:37 2009 +0100
814 @@ -505,6 +505,13 @@
815 /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
816 { m_unregistered, m_not_oper, ms_jupe, mo_jupe, m_ignore, mh_jupe }
817 },
818 + {
819 + MSG_SPLIT,
820 + TOK_SPLIT,
821 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
822 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
823 + { m_unregistered, m_not_oper, ms_split, mo_split, m_ignore, mh_nohelp }
824 + },
825 {
826 MSG_OPMODE,
827 TOK_OPMODE,
828 diff -r 3ab25cd90c2e ircd/s_conf.c
829 --- a/ircd/s_conf.c Tue Jan 27 20:50:02 2009 +0100
830 +++ b/ircd/s_conf.c Tue Jan 27 21:14:37 2009 +0100
831 @@ -53,6 +53,7 @@
832 #include "s_debug.h"
833 #include "s_misc.h"
834 #include "send.h"
835 +#include "split.h"
836 #include "struct.h"
837 #include "sys.h"
838
839 @@ -1005,6 +1006,7 @@
840 }
841
842 attach_conf_uworld(&me);
843 + split_conf();
844
845 return ret;
846 }
847 diff -r 3ab25cd90c2e ircd/s_debug.c
848 --- a/ircd/s_debug.c Tue Jan 27 20:50:02 2009 +0100
849 +++ b/ircd/s_debug.c Tue Jan 27 21:14:37 2009 +0100
850 @@ -48,6 +48,7 @@
851 #include "s_user.h"
852 #include "s_stats.h"
853 #include "send.h"
854 +#include "split.h"
855 #include "struct.h"
856 #include "sys.h"
857 #include "welcome.h"
858 @@ -233,6 +234,7 @@
859 wwa = 0, /* whowas aways */
860 gl = 0, /* glines */
861 ju = 0, /* jupes */
862 + sp = 0, /* split entries */
863 we = 0; /* welcome messages */
864
865 size_t chm = 0, /* memory used by channels */
866 @@ -246,6 +248,7 @@
867 wwm = 0, /* whowas array memory used */
868 glm = 0, /* memory used by glines */
869 jum = 0, /* memory used by jupes */
870 + spm = 0, /* memory used by split entries */
871 wem = 0, /* memory used by welcome messages */
872 com = 0, /* memory used by conf lines */
873 dbufs_allocated = 0, /* memory used by dbufs */
874 @@ -351,10 +354,11 @@
875
876 gl = gline_memory_count(&glm);
877 ju = jupe_memory_count(&jum);
878 + sp = split_memory_count(&spm);
879 we = welcome_memory_count(&wem);
880 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
881 - ":Glines %d(%zu) Jupes %d(%zu) WelcomeMessages %d(%zu)",
882 - gl, glm, ju, jum, we, wem);
883 + ":Glines %d(%zu) Jupes %d(%zu) Splits %d(%zu) WelcomeMessages %d(%zu)",
884 + gl, glm, ju, jum, sp, spm, we, wem);
885
886 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
887 ":Hash: client %d(%zu), chan is the same", HASHSIZE,
888 diff -r 3ab25cd90c2e ircd/s_err.c
889 --- a/ircd/s_err.c Tue Jan 27 20:50:02 2009 +0100
890 +++ b/ircd/s_err.c Tue Jan 27 21:14:37 2009 +0100
891 @@ -490,7 +490,7 @@
892 /* 228 */
893 { RPL_STATSQLINE, "Q %s :%s", "228" },
894 /* 229 */
895 - { 0 },
896 + { RPL_STATSSPLIT, "S %s %d %d %d %d %c :%s", "229" },
897 /* 230 */
898 { RPL_STATSHEADER, 0, "230" },
899 /* 231 */
900 @@ -588,9 +588,9 @@
901 /* 277 */
902 { 0 },
903 /* 278 */
904 - { 0 },
905 + { RPL_SPLITLIST, "%s %Tu %Tu %Tu %Tu %c :%s", "278" },
906 /* 279 */
907 - { 0 },
908 + { RPL_ENDOFSPLITLIST, ":End of Split List", "279" },
909 /* 280 */
910 { RPL_GLIST, "%s%s%s%s%s %Tu %Tu %Tu %s %s%s%c :%s", "280" },
911 /* 281 */
912 @@ -1052,7 +1052,7 @@
913 /* 509 */
914 { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
915 /* 510 */
916 - { 0 },
917 + { ERR_NOSUCHSPLIT, "%s :No such split", "510" },
918 /* 511 */
919 { ERR_SILELISTFULL, "%s :Your silence list is full", "511" },
920 /* 512 */
921 diff -r 3ab25cd90c2e ircd/s_misc.c
922 --- a/ircd/s_misc.c Tue Jan 27 20:50:02 2009 +0100
923 +++ b/ircd/s_misc.c Tue Jan 27 21:14:37 2009 +0100
924 @@ -53,6 +53,7 @@
925 #include "s_stats.h"
926 #include "s_user.h"
927 #include "send.h"
928 +#include "split.h"
929 #include "struct.h"
930 #include "sys.h"
931 #include "uping.h"
932 @@ -391,6 +392,7 @@
933 time_t on_for;
934
935 char comment1[HOSTLEN + HOSTLEN + 2];
936 + char splitreason[BUFSIZE];
937 assert(killer);
938 if (MyConnect(victim))
939 {
940 @@ -497,6 +499,15 @@
941 sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)",
942 cli_serv(victim)->up, victim, comment);
943 dump_map(victim, "*", 0, report_lost_links, 0);
944 + if (feature_bool(FEAT_SPLIT)) {
945 + /* TODO: remote & local SQUIT ? servername oper is on? */
946 + ircd_snprintf(0, splitreason, sizeof(splitreason),
947 + "Net break: %C %C (%s%s%s%s)", cli_serv(victim)->up, victim,
948 + IsUser(killer) ? "SQUIT by " : "", IsUser(killer) ? cli_name(killer) : "",
949 + IsUser(killer) ? ": " : "", comment);
950 + sendto_opmask_butone(0, SNO_NETWORK, "Created %d SPLIT entries.",
951 + split_netbreak(victim, splitreason));
952 + }
953 }
954
955 /*
956 diff -r 3ab25cd90c2e ircd/s_serv.c
957 --- a/ircd/s_serv.c Tue Jan 27 20:50:02 2009 +0100
958 +++ b/ircd/s_serv.c Tue Jan 27 21:14:37 2009 +0100
959 @@ -54,6 +54,7 @@
960 #include "s_misc.h"
961 #include "s_user.h"
962 #include "send.h"
963 +#include "split.h"
964 #include "struct.h"
965 #include "sys.h"
966 #include "userload.h"
967 @@ -197,6 +198,7 @@
968 */
969 gline_burst(cptr);
970 jupe_burst(cptr);
971 + split_burst(cptr);
972 welcome_burst(cptr);
973
974 /*
975 diff -r 3ab25cd90c2e ircd/s_stats.c
976 --- a/ircd/s_stats.c Tue Jan 27 20:50:02 2009 +0100
977 +++ b/ircd/s_stats.c Tue Jan 27 21:14:37 2009 +0100
978 @@ -52,6 +52,7 @@
979 #include "s_stats.h"
980 #include "s_user.h"
981 #include "send.h"
982 +#include "split.h"
983 #include "struct.h"
984 #include "userload.h"
985 #include "welcome.h"
986 @@ -669,7 +670,10 @@
987 send_usage, 0,
988 "System resource usage (Debug only)." },
989 #endif
990 - { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_s,
991 + { 'S', "splits", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_S,
992 + split_stats, 0,
993 + "Server SPLITs information."},
994 + { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_s,
995 stats_sline, 0,
996 "Spoofed hosts information." },
997 { 'T', "motds", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_T,
998 diff -r 3ab25cd90c2e ircd/split.c
999 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1000 +++ b/ircd/split.c Tue Jan 27 21:14:37 2009 +0100
1001 @@ -0,0 +1,786 @@
1002 +/*
1003 + * IRC - Internet Relay Chat, ircd/split.c
1004 + * Copyright (C) 1990 Jarkko Oikarinen and
1005 + * University of Oulu, Finland
1006 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
1007 + *
1008 + * This program is free software; you can redistribute it and/or modify
1009 + * it under the terms of the GNU General Public License as published by
1010 + * the Free Software Foundation; either version 1, or (at your option)
1011 + * any later version.
1012 + *
1013 + * This program is distributed in the hope that it will be useful,
1014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1016 + * GNU General Public License for more details.
1017 + *
1018 + * You should have received a copy of the GNU General Public License
1019 + * along with this program; if not, write to the Free Software
1020 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1021 + */
1022 +/** @file
1023 + * @brief Implementation of split server handling functions.
1024 + * @version $Id: split.c 1633 2006-03-25 03:46:56Z entrope $
1025 + */
1026 +#include "config.h"
1027 +
1028 +#include "split.h"
1029 +#include "client.h"
1030 +#include "hash.h"
1031 +#include "ircd.h"
1032 +#include "ircd_alloc.h"
1033 +#include "ircd_features.h"
1034 +#include "ircd_log.h"
1035 +#include "ircd_reply.h"
1036 +#include "ircd_string.h"
1037 +#include "list.h"
1038 +#include "match.h"
1039 +#include "msg.h"
1040 +#include "numeric.h"
1041 +#include "numnicks.h"
1042 +#include "s_conf.h"
1043 +#include "s_bsd.h"
1044 +#include "s_debug.h"
1045 +#include "s_misc.h"
1046 +#include "send.h"
1047 +#include "struct.h"
1048 +#include "sys.h" /* FALSE bleah */
1049 +
1050 +/* #include <assert.h> -- Now using assert in ircd_log.h */
1051 +#include <string.h>
1052 +
1053 +/** List of split entries. */
1054 +static struct Split *GlobalSplitList = 0;
1055 +
1056 +/** Allocate a new Split entry with the given parameters.
1057 + * @param[in] server Server name for split entry.
1058 + * @param[in] reason Reason for the split entry.
1059 + * @param[in] creation Creation time for split entry.
1060 + * @param[in] expire Expiration time for split entry.
1061 + * @param[in] lastmod Last modification time for split entry.
1062 + * @param[in] lifetime Life time for split entry.
1063 + * @param[in] flags Flags to set for the split entry.
1064 + */
1065 +static struct Split *
1066 +split_make(char *server, const char *reason,
1067 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1068 + unsigned int flags)
1069 +{
1070 + struct Split *asplit;
1071 +
1072 + asplit = (struct Split*) MyMalloc(sizeof(struct Split)); /* alloc memory */
1073 + assert(0 != asplit);
1074 +
1075 + memset(asplit, 0, sizeof(*asplit));
1076 + /* TODO: some limit for servername length? HOSTLEN? */
1077 + DupString(asplit->sp_server, server); /* copy vital information */
1078 + /* TODO: some limit for reason length? QUITLEN TOPICLEN? */
1079 + /* TODO: prefix the reason here with the opername/ID? */
1080 + DupString(asplit->sp_reason, reason);
1081 + /* TODO: what we use creation for and do we need it? */
1082 + asplit->sp_creation = creation;
1083 + asplit->sp_expire = expire;
1084 + /* TODO: are we using nettime etc.? CurrentTime is used. */
1085 + /* TODO: TStime() is CurrentTime + TSoffset */
1086 + asplit->sp_lastmod = lastmod;
1087 + asplit->sp_lifetime = lifetime;
1088 + asplit->sp_flags = flags & SPLIT_ACTIVE; /* set split flags */
1089 +
1090 + asplit->sp_next = GlobalSplitList; /* link it into the list */
1091 + asplit->sp_prev_p = &GlobalSplitList;
1092 + if (GlobalSplitList)
1093 + GlobalSplitList->sp_prev_p = &asplit->sp_next;
1094 + GlobalSplitList = asplit;
1095 +
1096 + return asplit;
1097 +}
1098 +
1099 +/** Forward a split entry to another server.
1100 + * @param[in] cptr Local client that sent us the split entry.
1101 + * @param[in] sptr Originator of the split entry.
1102 + * @param[in] split Split entry to forward.
1103 + * @param[in] reason Reason to send upstream (used by split_remove)
1104 + */
1105 +static void
1106 +split_propagate(struct Client *cptr, struct Client *sptr,
1107 + struct Split *split, const char *reason)
1108 +{
1109 + sendcmdto_serv_butone(sptr, CMD_SPLIT, cptr, "%s%c%s %Tu %Tu %Tu %Tu :%s",
1110 + SplitIsRemoving(split) ? "!" : "",
1111 + SplitIsActive(split) && !SplitIsRemoving(split) ? '+' : '-', /* always !- not !+ */
1112 + split->sp_server, split->sp_creation, split->sp_expire,
1113 + split->sp_lastmod, split->sp_lifetime,
1114 + /* TODO: does reason ? reason : split->sp_reason work too? */
1115 + reason != NULL ? reason : split->sp_reason);
1116 +}
1117 +
1118 +/** Add a new server split entry.
1119 + * @param[in] cptr Local client that sent us the split entry.
1120 + * @param[in] sptr Originator of the split entry.
1121 + * @param[in] server Server name to split entry.
1122 + * @param[in] reason Reason for the split entry.
1123 + * @param[in] expire Expiration timestamp.
1124 + * @param[in] lastmod Last modification timestamp.
1125 + * @param[in] flags Flags to set on the split entry.
1126 + * @return Zero
1127 + */
1128 +int
1129 +split_add(struct Client *cptr, struct Client *sptr, char *server, const char *reason,
1130 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1131 + unsigned int flags)
1132 +{
1133 +
1134 + struct Split *asplit;
1135 + struct Client *acptr;
1136 + char noreason[BUFSIZE];
1137 +
1138 + assert(0 != cptr);
1139 + assert(0 != sptr);
1140 + assert(0 != server);
1141 + assert(0 != reason);
1142 +
1143 + Debug((DEBUG_DEBUG, "split_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu, %Tu, "
1144 + "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), server, reason,
1145 + creation, expire, lastmod, lifetime, flags));
1146 +
1147 + /* not adding SPLIT for server that is linked
1148 + * if sptr is my user throw error
1149 + * otherwise ignore - SERVER and SPLIT messages can cross,
1150 + * or a server is bursting and it will see our end and destroy the SPLITs
1151 + */
1152 + if ((acptr = FindServer(server))) {
1153 + if (MyUser(sptr))
1154 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1155 + "%C :Cannot add SPLIT %s - server is linked.", sptr, server);
1156 + return 0;
1157 + }
1158 +
1159 + /*
1160 + * You cannot set a negative (or zero) duration, nor can you set an
1161 + * duration greater than SPLIT_MAX_EXPIRE.
1162 + */
1163 + if (expire - TStime() <= 0 || expire - TStime() > SPLIT_MAX_EXPIRE) {
1164 + /* TODO: cptr or sptr here? */
1165 + if (MyUser(sptr))
1166 + return send_reply(cptr, ERR_BADEXPIRE, expire - TStime());
1167 + if (lifetime <= TStime()) /* no point going further */
1168 + /* CHECK: sptr may have the wrong idea about the nettime?
1169 + * or we could be wrong?
1170 + * perhaps raise some sort of warning to ops
1171 + */
1172 + return 0;
1173 + }
1174 +
1175 + /* empty reason */
1176 + if (reason[0] == '\0')
1177 + ircd_snprintf(0, noreason, sizeof(noreason), "%C gave no reason.", sptr);
1178 +
1179 + /* TODO: add opername */
1180 + /* inform ops and log it */
1181 + sendto_opmask_butone(0, SNO_NETWORK, "%s adding%sSPLIT for %s, expiring at %Tu: %s",
1182 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1183 + cli_name(sptr) : cli_name((cli_user(sptr))->server),
1184 + !(flags & SPLIT_ACTIVE) ? " deactivated " : " ",
1185 + server, expire, reason[0] == '\0' ? noreason : reason);
1186 +
1187 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1188 + "%#C adding%sSPLIT for %s, expiring at %Tu: %s",
1189 + sptr, !(flags & SPLIT_ACTIVE) ? " deactivated " : " ",
1190 + server, expire, reason[0] == '\0' ? noreason : reason);
1191 +
1192 + /* make the split entry */
1193 + asplit = split_make(server, reason[0] == '\0' ? noreason : reason,
1194 + creation, expire, lastmod, lifetime, flags);
1195 +
1196 + assert(asplit);
1197 +
1198 + /* and propagate it */
1199 + split_propagate(cptr, sptr, asplit, NULL);
1200 +
1201 + return 0;
1202 +}
1203 +
1204 +
1205 +/** Modify a split entry.
1206 + * @param[in] cptr Client that sent us the split modification.
1207 + * @param[in] sptr Client that originated the split modification.
1208 + * @param[in] split Split entry being modified.
1209 + * @param[in] action Resultant status of the G-line.
1210 + * @param[in] reason Reason.
1211 + * @param[in] expire Expiration time.
1212 + * @param[in] lastmod Last modification time.
1213 + * @param[in] lifetime Lifetime.
1214 + * @param[in] flags Bitwise combination of SPLIT_* flags.
1215 + * @return Zero.
1216 + */
1217 +int
1218 +split_modify(struct Client *cptr, struct Client *sptr, struct Split *split,
1219 + enum SplitAction action, const char *reason,
1220 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1221 + unsigned int flags)
1222 +{
1223 + struct Client* acptr;
1224 + char buf[BUFSIZE];
1225 + int pos = 0;
1226 +
1227 + assert(0 != cptr);
1228 + assert(0 != sptr);
1229 + assert(0 != split);
1230 +
1231 + Debug((DEBUG_DEBUG, "split_modify(cptr \"%s\", sptr \"%s\", split \"%s\", reason \"%s\","
1232 + " action %d, creation %Tu, expire %Tu, lastmod %Tu, lifetime %Tu, flags 0x%04x)",
1233 + cli_name(cptr), cli_name(sptr), split->sp_server, reason, action,
1234 + creation, expire, lastmod, lifetime, flags));
1235 +
1236 + /* not modifying SPLIT for server that is linked
1237 + * if sptr is my user throw error
1238 + * otherwise ignore - SERVER and SPLIT messages can cross.
1239 + *
1240 + * note: we cleanup SPLIT entries at end of burst,
1241 + * and not when a server is introduced.
1242 + * so between net junction and end of burst,
1243 + * we can get SPLITs for a linked server.
1244 + * also more than one server can be bursting at a time.
1245 + */
1246 + if ((acptr = FindServer(split->sp_server))) {
1247 + if (MyUser(sptr))
1248 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1249 + "%C :Cannot modify SPLIT %s - server is linked.", sptr, split->sp_server);
1250 + /* SPLIT is not for a server part of a netmerge */
1251 + if (!SplitIsBurst(split))
1252 + split_free(split); /* and free it */
1253 + return 0;
1254 + }
1255 +
1256 + /* check lastmod */
1257 + if (split->sp_lastmod > lastmod) { /* we have a more recent version */
1258 + if (IsBurstOrBurstAck(cptr)) /* middle of a burst, it will resync on its own */
1259 + return 0;
1260 + return split_resend(cptr, split); /* resync the server */
1261 + } else if (split->sp_lastmod == lastmod) /* same version */
1262 + return 0;
1263 +
1264 + /* there is a change of some sort */
1265 + /* check out the expiration time */
1266 + if (flags & SPLIT_EXPIRE) {
1267 + if (expire != split->sp_expire) {
1268 + /* bad expiration time */
1269 + if (MyUser(sptr) && (expire < TStime() || expire - TStime() > SPLIT_MAX_EXPIRE))
1270 + return send_reply(sptr, ERR_BADEXPIRE, expire - TStime());
1271 + /* expire timestamp is in the past, so remap to deactivate */
1272 + if (expire < TStime() && action == SPLIT_ACTIVATE)
1273 + action = SPLIT_DEACTIVATE;
1274 + } else
1275 + flags &= ~SPLIT_EXPIRE;
1276 + }
1277 +
1278 + /* Next, check out lifetime */
1279 + if (!(flags & SPLIT_LIFETIME) || !lifetime)
1280 + lifetime = split->sp_lifetime; /* use Split lifetime */
1281 +
1282 + lifetime = IRCD_MAX(lifetime, expire); /* set lifetime to the max */
1283 +
1284 + /* now that we have the correct lifetime, check it */
1285 + if (lifetime - TStime() <= 0) /* no point in going further */
1286 + return 0;
1287 +
1288 + /* OK, let's see which is greater... */
1289 + if (lifetime > split->sp_lifetime)
1290 + flags |= SPLIT_LIFETIME; /* have to update lifetime */
1291 + else {
1292 + flags &= ~SPLIT_LIFETIME; /* no change to lifetime */
1293 + lifetime = 0;
1294 + }
1295 +
1296 + /* Finally, let's see if the reason needs to be updated */
1297 + if ((flags & SPLIT_REASON) && (reason[0] == '\0' || !ircd_strcmp(split->sp_reason, reason)))
1298 + flags &= ~SPLIT_REASON; /* no changes to the reason */
1299 +
1300 + /* OK, now let's take a look at the action... */
1301 + if ((action == SPLIT_ACTIVATE && SplitIsActive(split)) ||
1302 + (action == SPLIT_DEACTIVATE && !SplitIsActive(split)) ||
1303 + /* can't activate an expired split entry */
1304 + (IRCD_MAX(split->sp_expire, expire) <= TStime()))
1305 + action = SPLIT_MODIFY; /* no activity state modifications */
1306 +
1307 + Debug((DEBUG_DEBUG, "About to perform changes; flags 0x%04x, action %s",
1308 + flags, action == SPLIT_ACTIVATE ? "SPLIT_ACTIVATE" :
1309 + (action == SPLIT_DEACTIVATE ? "SPLIT_DEACTIVATE" :
1310 + (action == SPLIT_MODIFY ? "SPLIT_MODIFY" : "<UNKNOWN>"))));
1311 +
1312 + /* If there are no changes to perform, do no changes */
1313 + if (!(flags & SPLIT_UPDATE) && action == SPLIT_MODIFY) {
1314 + if (MyUser(sptr))
1315 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1316 + "%C :Cannot modify SPLIT %s - nothing to change.", sptr, split->sp_server);
1317 + return 0;
1318 + }
1319 +
1320 + /* Start by updating lastmod, if indicated... */
1321 + split->sp_lastmod = lastmod;
1322 +
1323 + /* Then move on to activity status changes... */
1324 + switch (action) {
1325 + case SPLIT_ACTIVATE: /* activating split entry */
1326 + split->sp_flags |= SPLIT_ACTIVE; /* make it active... */
1327 + pos += ircd_snprintf(0, buf, sizeof(buf), " activating SPLIT");
1328 + break;
1329 +
1330 + case SPLIT_DEACTIVATE: /* deactivating split entry */
1331 + split->sp_flags &= ~SPLIT_ACTIVE; /* make it inactive... */
1332 + pos += ircd_snprintf(0, buf, sizeof(buf), " deactivating SPLIT");
1333 + break;
1334 +
1335 + case SPLIT_MODIFY: /* no change to activity status */
1336 + break;
1337 + }
1338 +
1339 + /* TODO: Handle creation changes... */
1340 +
1341 + /* Handle expiration changes... */
1342 + if (flags & SPLIT_EXPIRE) {
1343 + split->sp_expire = expire; /* save new expiration time */
1344 + if (pos < BUFSIZE)
1345 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1346 + "%s%s changing expiration time to %Tu",
1347 + pos ? ";" : "",
1348 + pos && !(flags & (SPLIT_LIFETIME | SPLIT_REASON)) ?
1349 + " and" : "", expire);
1350 + }
1351 +
1352 + /* Next, handle lifetime changes... */
1353 + if (flags & SPLIT_LIFETIME) {
1354 + split->sp_lifetime = lifetime; /* save new lifetime */
1355 + if (pos < BUFSIZE)
1356 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1357 + "%s%s extending record lifetime to %Tu",
1358 + pos ? ";" : "", pos && !(flags & SPLIT_REASON) ?
1359 + " and" : "", lifetime);
1360 + }
1361 +
1362 + /* Now, handle reason changes... */
1363 + if (flags & SPLIT_REASON) {
1364 + MyFree(split->sp_reason); /* release old reason */
1365 + DupString(split->sp_reason, reason); /* store new reason */
1366 + if (pos < BUFSIZE)
1367 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1368 + "%s%s changing reason to \"%s\"",
1369 + pos ? ";" : "", pos ? " and" : "", reason);
1370 + }
1371 +
1372 + /* TODO: add opername */
1373 + /* All right, inform ops... */
1374 + sendto_opmask_butone(0, SNO_NETWORK, "%s modifying SPLIT for %s:%s",
1375 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1376 + cli_name(sptr) : cli_name((cli_user(sptr))->server),
1377 + split->sp_server, buf);
1378 +
1379 + /* and log the change */
1380 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1381 + "%#C modifying SPLIT for %s:%s",
1382 + sptr, split->sp_server, buf);
1383 +
1384 + /* and propagate it */
1385 + split_propagate(cptr, sptr, split, NULL);
1386 +
1387 + return 0;
1388 +}
1389 +
1390 +
1391 +/** Remove a split entry.
1392 + * @param[in] cptr Local client that sent us the split entry.
1393 + * @param[in] sptr Originator of the split entry.
1394 + * @param[in] split Split entry to remove.
1395 + * @param[in] reason Reason for removing this split entry.
1396 + * @return Zero.
1397 + */
1398 +int
1399 +split_remove(struct Client *cptr, struct Client *sptr, struct Split *split, const char *reason)
1400 +{
1401 + unsigned int saveflags = 0;
1402 +
1403 + assert(0 != split);
1404 + assert(NULL != cptr);
1405 + assert(NULL != sptr);
1406 +
1407 + Debug((DEBUG_DEBUG, "split_remove(\"%s\", \"%s\", \"%s\", \"%s\")",
1408 + cli_name(cptr), cli_name(sptr), split->sp_server, reason));
1409 +
1410 + /* deactivate entry and mark it for removal (used in split_propagate) */
1411 + split->sp_flags |= SPLIT_REMOVING;
1412 + split->sp_flags &= ~SPLIT_ACTIVE;
1413 +
1414 + /* TODO: add opername? */
1415 + /* inform ops and log it */
1416 + sendto_opmask_butone(0, SNO_NETWORK, "%s removing SPLIT for %s, expiring at %Tu: %s (%s)",
1417 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1418 + cli_name(sptr) : cli_name((cli_user(sptr))->server),
1419 + split->sp_server, split->sp_expire, split->sp_reason, reason);
1420 +
1421 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1422 + "%#C removing SPLIT for %s, expiring at %Tu: %s (%s)",
1423 + sptr, split->sp_server, split->sp_expire, split->sp_reason, reason);
1424 +
1425 + /* propagate it */
1426 + split_propagate(cptr, sptr, split, reason);
1427 +
1428 + /* destroy it */
1429 + split_free(split);
1430 +
1431 + return 0;
1432 +}
1433 +
1434 +
1435 +/** Find a split entry by name.
1436 + * @param[in] server Split entry name to search for.
1437 + * @return Matching split entry (or NULL if none match).
1438 + */
1439 +struct Split *
1440 +split_find(char *server)
1441 +{
1442 + struct Split* split;
1443 + struct Split* ssplit;
1444 +
1445 + for (split = GlobalSplitList; split; split = ssplit) { /* go through splits */
1446 + ssplit = split->sp_next;
1447 +
1448 + if (split_expire(split)) /* expire any that need expiring */
1449 + split_free(split);
1450 + else if (0 == ircd_strcmp(server, split->sp_server)) /* found it yet? */
1451 + return split;
1452 + }
1453 + /* TODO: we return 0 not NULL? */
1454 + return 0;
1455 +}
1456 +
1457 +/** Unlink and free an unused split entry.
1458 + * @param[in] split Server split entry to free.
1459 + */
1460 +void
1461 +split_free(struct Split* split)
1462 +{
1463 + /* TODO: use 0 or NULL ? */
1464 + assert(0 != split);
1465 +
1466 + *split->sp_prev_p = split->sp_next; /* squeeze this split entry out */
1467 + if (split->sp_next)
1468 + split->sp_next->sp_prev_p = split->sp_prev_p;
1469 +
1470 + /* CHECK: the other fields in this struct are destroyed with MyFree() call? */
1471 + MyFree(split->sp_server); /* and free up the memory */
1472 + MyFree(split->sp_reason);
1473 + MyFree(split);
1474 +}
1475 +
1476 +
1477 +/** Check whether a split entry has past its life time.
1478 + * when entry is active and past expire time, but not life time, deactivate it
1479 + * @param[in] split Server split entry to check.
1480 + * @return 1 when entry can be free'd, 0 otherwise.
1481 + */
1482 +int
1483 +split_expire(struct Split* split)
1484 +{
1485 + assert(0 != split);
1486 +
1487 + /* TODO: also check if the server in SPLIT entry is linked atm? */
1488 + /* past lifetime */
1489 + if (split->sp_lifetime <= TStime())
1490 + return 1;
1491 +
1492 + /* past expire time, deactivate entry if it is active */
1493 + if ((split->sp_expire <= TStime()) && SplitIsActive(split))
1494 + split->sp_flags &= ~SPLIT_ACTIVE;
1495 +
1496 + return 0;
1497 +}
1498 +
1499 +/** Send the full list of split entries to \a cptr.
1500 + * @param[in] cptr Local server to send split entries to.
1501 + */
1502 +void
1503 +split_burst(struct Client *cptr)
1504 +{
1505 + struct Split *split;
1506 + struct Split *ssplit;
1507 +
1508 + assert(NULL != cptr);
1509 +
1510 + for (split = GlobalSplitList; split; split = ssplit) { /* go through splits */
1511 + ssplit = split->sp_next;
1512 +
1513 + /* expire any that need expiring */
1514 + if (split_expire(split))
1515 + split_free(split);
1516 + /* if we have an entry for cptr, dont send it - but do not free here yet
1517 + * free it at end of burst, to get the correct count for SPLITs removed.
1518 + */
1519 + else if (ircd_strcmp(split->sp_server, cli_name(cptr)) == 0)
1520 + continue;
1521 + else
1522 + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s",
1523 + SplitIsActive(split) ? '+' : '-', split->sp_server,
1524 + split->sp_creation, split->sp_expire,
1525 + split->sp_lastmod, split->sp_lifetime,
1526 + split->sp_reason);
1527 + }
1528 +}
1529 +
1530 +/** Forward a split to another server.
1531 + * @param[in] cptr Server to send split entries to.
1532 + * @param[in] split Split to forward.
1533 + * @return Zero.
1534 + */
1535 +int
1536 +split_resend(struct Client *cptr, struct Split *split)
1537 +{
1538 + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s",
1539 + SplitIsActive(split) ? '+' : '-', split->sp_server,
1540 + split->sp_creation, split->sp_expire,
1541 + split->sp_lastmod, split->sp_lifetime,
1542 + split->sp_reason);
1543 +
1544 + return 0;
1545 +}
1546 +
1547 +/** Send a split entry (or a list of split entries) to a server.
1548 + * @param[in] sptr Client searching for split entries.
1549 + * @param[in] server Name of split entry to search for (if NULL, list all).
1550 + * @return Zero.
1551 + */
1552 +int
1553 +split_list(struct Client *sptr, char *server)
1554 +{
1555 + struct Split *split;
1556 + int count = 0;
1557 +
1558 + assert(NULL != sptr);
1559 +
1560 + /* go through SPLITs */
1561 + for (split = GlobalSplitList; split; split = split->sp_next) {
1562 + if (split_expire(split)) { /* expire any that need expiring */
1563 + split_free(split);
1564 + continue;
1565 + }
1566 + if (server && match(server, split->sp_server))
1567 + continue;
1568 + count++;
1569 + send_reply(sptr, RPL_SPLITLIST, split->sp_server,
1570 + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime,
1571 + SplitIsActive(split) ? '+' : '-', split->sp_reason);
1572 + }
1573 +
1574 + /* server given and nothing found */
1575 + if (server && !count)
1576 + return send_reply(sptr, ERR_NOSUCHSPLIT, server);
1577 +
1578 + /* end of splitlist information */
1579 + return send_reply(sptr, RPL_ENDOFSPLITLIST);
1580 +}
1581 +
1582 +
1583 +/** Mark SPLIT for new server with SPLIT_BURST
1584 + * @param[in] acptr Server introduced to the network
1585 + */
1586 +void
1587 +split_newserver(struct Client *acptr)
1588 +{
1589 + struct Split *split;
1590 +
1591 + assert(NULL != acptr);
1592 +
1593 + Debug((DEBUG_DEBUG, "split_newserver(\"%s\")", cli_name(acptr)));
1594 +
1595 + /* mark the SPLIT with SPLIT_BURST
1596 + * so we know this SPLIT is marked for removal already
1597 + * but not remove it just yet to get the correct count
1598 + * of SPLITs removed at the end of burst.
1599 + * also we need the SPLIT in case the net breaks again
1600 + * before end of burst?
1601 + */
1602 + if ((split = split_find(cli_name(acptr))))
1603 + split->sp_flags |= SPLIT_BURST;
1604 + return;
1605 +}
1606 +
1607 +
1608 +/** Auto destroy SPLITs for servers gained in a netmerge
1609 + * @param[in] sptr Server that has linked to the network
1610 + * @return Number of destroyed SPLITs
1611 + */
1612 +int
1613 +split_netmerge(struct Client *sptr)
1614 +{
1615 + struct DLink *lp;
1616 + struct Split *split;
1617 + int count = 0;
1618 +
1619 + assert(NULL != sptr);
1620 +
1621 + Debug((DEBUG_DEBUG, "split_netmerge(\"%s\")", cli_name(sptr)));
1622 +
1623 + /* find the SPLIT for this server */
1624 + if ((split = split_find(cli_name(sptr)))) {
1625 + split_free(split);
1626 + count++;
1627 + }
1628 +
1629 + /* go over its downlinks */
1630 + for (lp = cli_serv(sptr)->down; lp; lp = lp->next)
1631 + count += split_netmerge(lp->value.cptr);
1632 + return count;
1633 +}
1634 +
1635 +
1636 +/** Auto create SPLITs for servers lost in a netbreak
1637 + * @param[in] victim Server that lost link to network
1638 + * @param[in] reason Reason to add to SPLITs
1639 + * @return Number of created SPLITs
1640 + */
1641 +int
1642 +split_netbreak(struct Client *victim, const char *reason)
1643 +{
1644 + struct DLink *lp;
1645 + struct Split *split;
1646 + int count = 0;
1647 + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE),
1648 + lastmod = TStime(), lifetime = expire;
1649 + unsigned int flags = SPLIT_ACTIVE;
1650 +
1651 + assert(NULL != victim);
1652 +
1653 + Debug((DEBUG_DEBUG, "split_netbreak(\"%s\", \"%s\")", cli_name(victim), reason));
1654 +
1655 + /* bad auto expire value */
1656 + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0)
1657 + return 0;
1658 +
1659 + /* TODO: what if we do have a SPLIT for this server?
1660 + * we remove splits in end of burst
1661 + * and if the netbreaks again before that
1662 + * free the SPLIT and create a new one?
1663 + * or simply update lastmod/lifetime/reason but leave the status?
1664 + */
1665 + /* find the SPLIT for this server */
1666 + if (!(split = split_find(cli_name(victim)))) {
1667 + split_make(cli_name(victim), reason, creation, expire, lastmod, lifetime, flags);
1668 + count++;
1669 + } else
1670 + split->sp_flags &= SPLIT_BURST; /* clear the burst flag for it */
1671 +
1672 + /* go over its downlinks */
1673 + for (lp = cli_serv(victim)->down; lp; lp = lp->next)
1674 + count += split_netbreak(lp->value.cptr, reason);
1675 + return count;
1676 +}
1677 +
1678 +
1679 +/** Auto create SPLITs for servers we have a Connect Block for
1680 + *
1681 + */
1682 +void
1683 +split_conf()
1684 +{
1685 + struct ConfItem *conf;
1686 + struct Client *server;
1687 + struct Split *split;
1688 + struct Split *asplit;
1689 + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE),
1690 + lastmod = TStime(), lifetime = expire;
1691 + unsigned int flags = SPLIT_ACTIVE;
1692 + char reason[BUFSIZE];
1693 +
1694 + Debug((DEBUG_DEBUG, "split_conf()"));
1695 +
1696 + /* we are not set to generate SPLITs */
1697 + if (!feature_bool(FEAT_SPLIT))
1698 + return;
1699 +
1700 + /* TODO: log this problem? */
1701 + /* bad auto expire value */
1702 + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0)
1703 + return;
1704 +
1705 + ircd_snprintf(0, reason, sizeof(reason),
1706 + "Generated upon loading conf file on %C", &me);
1707 +
1708 + /* go over the conf contents */
1709 + for (conf = GlobalConfList; conf; conf = conf->next) {
1710 + /* not a Connect Block */
1711 + if (CONF_SERVER != conf->status)
1712 + continue;
1713 + /* server is linked */
1714 + if (server = FindServer(conf->name))
1715 + continue;
1716 + /* we have a SPLIT for this server already */
1717 + if (split = split_find(conf->name))
1718 + continue;
1719 + /* TODO: use SNO_OLDSNO here?
1720 + * just like nickcollisions on local users go there?
1721 + * or at least change the source / message format?
1722 + * /REHASH goes to SNO_OLDSNO? so this too?
1723 + * if oper did rehash, add his name here?
1724 + */
1725 + /* inform ops and log it */
1726 + sendto_opmask_butone(0, SNO_NETWORK, "%C adding SPLIT for %s, expiring at %Tu: %s",
1727 + &me, conf->name, expire, reason);
1728 +
1729 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1730 + "%C adding SPLIT for %s, expiring at %Tu: %s",
1731 + &me, conf->name, expire, reason);
1732 +
1733 + /* make the split entry */
1734 + asplit = split_make(conf->name, reason, creation, expire, lastmod, lifetime, flags);
1735 +
1736 + assert(asplit);
1737 +
1738 + /* and propagate it */
1739 + split_propagate(&me, &me, asplit, NULL);
1740 + }
1741 +}
1742 +
1743 +
1744 +/** Statistics callback to list SPLITs.
1745 + * @param[in] sptr Client requesting statistics.
1746 + * @param[in] sd Stats descriptor for request (ignored).
1747 + * @param[in] param Extra parameter from user (ignored).
1748 + */
1749 +void
1750 +split_stats(struct Client *sptr, const struct StatDesc *sd,
1751 + char *param)
1752 +{
1753 + struct Split *split;
1754 +
1755 + /* send header so the client knows what we are showing */
1756 + send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER,
1757 + "S Server Creation Expire Lastmod Lifetime Status :Reason");
1758 +
1759 + for (split = GlobalSplitList; split; split = split->sp_next) {
1760 + if (param && match(param, split->sp_server))
1761 + continue;
1762 + send_reply(sptr, RPL_STATSSPLIT, split->sp_server,
1763 + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime,
1764 + SplitIsActive(split) ? '+' : '-', split->sp_reason);
1765 + }
1766 +}
1767 +
1768 +
1769 +/** Count split entries and memory used by them.
1770 + * @param[out] sp_size Receives total number of bytes allocated for split entries.
1771 + * @return Number of split entries currently allocated.
1772 + */
1773 +int
1774 +split_memory_count(size_t *sp_size)
1775 +{
1776 + struct Split *split;
1777 + unsigned int sp = 0;
1778 +
1779 + for (split = GlobalSplitList; split; split = split->sp_next) {
1780 + sp++;
1781 + *sp_size += sizeof(struct Split);
1782 + *sp_size += split->sp_server ? (strlen(split->sp_server) + 1) : 0;
1783 + *sp_size += split->sp_reason ? (strlen(split->sp_reason) + 1) : 0;
1784 + }
1785 + return sp;
1786 +}
1787 +