Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / client.c
1 /*
2  * IRC - Internet Relay Chat, ircd/client.c
3  * Copyright (C) 1990 Darren Reed
4  *
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)
8  * any later version.
9  *
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.
14  *
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.
18  *
19  * $Id$
20  */
21 #include "client.h"
22 #include "class.h"
23 #include "ircd.h"
24 #include "ircd_reply.h"
25 #include "list.h"
26 #include "numeric.h"
27 #include "s_conf.h"
28 #include "s_debug.h"
29 #include "send.h"
30 #include "struct.h"
31
32 #include <assert.h>
33
34 #define BAD_PING                ((unsigned int)-2)
35
36 /*
37  * client_get_ping
38  * returns shortest ping time in attached server or client conf
39  * classes or PINGFREQUENCY
40  */
41 int client_get_ping(const struct Client* acptr)
42 {
43   int     ping = 0;
44   struct ConfItem* aconf;
45   struct SLink*    link;
46
47   for (link = cli_confs(acptr); link; link = link->next) {
48     aconf = link->value.aconf;
49     if (aconf->status & (CONF_CLIENT | CONF_SERVER)) {
50       int tmp = get_conf_ping(aconf);
51       if (0 < tmp && (ping > tmp || !ping))
52         ping = tmp;
53     }
54   }
55   if (0 == ping)
56     ping = PINGFREQUENCY;
57
58   Debug((DEBUG_DEBUG, "Client %s Ping %d", cli_name(acptr), ping));
59   return ping;
60 }
61
62 /*
63  * client_drop_sendq
64  * removes the client's connection from the list of connections with
65  * queued data
66  */
67 void client_drop_sendq(struct Connection* con)
68 {
69   if (con_prev_p(con)) { /* on the queued data list... */
70     if (con_next(con))
71       con_prev_p(con_next(con)) = con_prev_p(con);
72     *(con_prev_p(con)) = con_next(con);
73
74     con_next(con) = 0;
75     con_prev_p(con) = 0;
76   }
77 }
78
79 /*
80  * client_add_sendq
81  * adds the client's connection to the list of connections with
82  * queued data
83  */
84 void client_add_sendq(struct Connection* con, struct Connection** con_p)
85 {
86   if (!con_prev_p(con)) { /* not on the queued data list yet... */
87     con_prev_p(con) = con_p;
88     con_next(con) = *con_p;
89
90     if (*con_p)
91       con_prev_p(*con_p) = &(con_next(con));
92     *con_p = con;
93   }
94 }