]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn-func.c
Add debug code to Conn_SetPenalty().
[ngircd-alex.git] / src / ngircd / conn-func.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
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 2 of the License, or
8  * (at your option) any later version.
9  * Please read the file COPYING, README and AUTHORS for more information.
10  *
11  * Connection management: Global functions
12  */
13
14
15 #define CONN_MODULE
16
17 #include "portab.h"
18
19 static char UNUSED id[] = "$Id: conn-func.c,v 1.8 2005/09/04 23:38:32 alex Exp $";
20
21 #include "imp.h"
22 #include <assert.h>
23 #include <log.h>
24
25 #include "conn.h"
26 #include "client.h"
27
28 #include "exp.h"
29 #include "conn-func.h"
30
31
32 GLOBAL void
33 Conn_UpdateIdle( CONN_ID Idx )
34 {
35         /* Idle-Timer zuruecksetzen */
36
37         assert( Idx > NONE );
38         My_Connections[Idx].lastprivmsg = time( NULL );
39 }
40
41
42 GLOBAL time_t
43 Conn_GetIdle( CONN_ID Idx )
44 {
45         /* Idle-Time einer Verbindung liefern (in Sekunden) */
46
47         assert( Idx > NONE );
48         return time( NULL ) - My_Connections[Idx].lastprivmsg;
49 } /* Conn_GetIdle */
50
51
52 GLOBAL time_t
53 Conn_LastPing( CONN_ID Idx )
54 {
55         /* Zeitpunkt des letzten PING liefern */
56
57         assert( Idx > NONE );
58         return My_Connections[Idx].lastping;
59 } /* Conn_LastPing */
60
61
62 GLOBAL void
63 Conn_SetPenalty( CONN_ID Idx, time_t Seconds )
64 {
65         /* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen;
66          * waehrend dieser Zeit wird der entsprechende Socket vom Server
67          * bei Lese-Operationen komplett ignoriert. Der Delay kann mit
68          * dieser Funktion nur erhoeht, nicht aber verringert werden. */
69         
70         time_t t;
71         
72         assert( Idx > NONE );
73         assert( Seconds >= 0 );
74
75         t = time( NULL ) + Seconds;
76         if (t > My_Connections[Idx].delaytime)
77                 My_Connections[Idx].delaytime = t;
78
79 #ifdef DEBUG
80         Log(LOG_DEBUG, "Add penalty time on connection %d: %ld second(s).",
81                         Idx, (long)Seconds);
82 #endif
83 } /* Conn_SetPenalty */
84
85
86 GLOBAL void
87 Conn_ResetPenalty( CONN_ID Idx )
88 {
89         assert( Idx > NONE );
90         My_Connections[Idx].delaytime = 0;
91 } /* Conn_ResetPenalty */
92
93
94 GLOBAL void
95 Conn_ClearFlags( void )
96 {
97         /* Alle Connection auf "nicht-markiert" setzen */
98
99         CONN_ID i;
100
101         for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
102 } /* Conn_ClearFlags */
103
104
105 GLOBAL int
106 Conn_Flag( CONN_ID Idx )
107 {
108         /* Ist eine Connection markiert (true) oder nicht? */
109
110         assert( Idx > NONE );
111         return My_Connections[Idx].flag;
112 } /* Conn_Flag */
113
114
115 GLOBAL void
116 Conn_SetFlag( CONN_ID Idx, int Flag )
117 {
118         /* Connection markieren */
119
120         assert( Idx > NONE );
121         My_Connections[Idx].flag = Flag;
122 } /* Conn_SetFlag */
123
124
125 GLOBAL CONN_ID
126 Conn_First( void )
127 {
128         /* Connection-Struktur der ersten Verbindung liefern;
129          * Ist keine Verbindung vorhanden, wird NONE geliefert. */
130
131         CONN_ID i;
132         
133         for( i = 0; i < Pool_Size; i++ )
134         {
135                 if( My_Connections[i].sock != NONE ) return i;
136         }
137         return NONE;
138 } /* Conn_First */
139
140
141 GLOBAL CONN_ID
142 Conn_Next( CONN_ID Idx )
143 {
144         /* Naechste Verbindungs-Struktur liefern; existiert keine
145          * weitere, so wird NONE geliefert. */
146
147         CONN_ID i = NONE;
148
149         assert( Idx > NONE );
150         
151         for( i = Idx + 1; i < Pool_Size; i++ )
152         {
153                 if( My_Connections[i].sock != NONE ) return i;
154         }
155         return NONE;
156 } /* Conn_Next */
157
158
159 GLOBAL int
160 Conn_Options( CONN_ID Idx )
161 {
162         assert( Idx > NONE );
163         return My_Connections[Idx].options;
164 } /* Conn_Options */
165
166
167 /**
168  * Get the start time of the connection.
169  * The result is the start time in seconds since 1970-01-01, as reported
170  * by the C function time(NULL).
171  */
172 GLOBAL time_t
173 Conn_StartTime( CONN_ID Idx )
174 {
175         CLIENT *c;
176
177         assert(Idx > NONE);
178
179         /* Search client structure for this link ... */
180         c = Client_GetFromConn(Idx);
181         if(c != NULL)
182                 return Client_StartTime(c);
183
184         return 0;
185 } /* Conn_StartTime */
186
187
188 GLOBAL int
189 Conn_SendQ( CONN_ID Idx )
190 {
191         /* Laenge der Daten im Schreibbuffer liefern */
192
193         assert( Idx > NONE );
194 #ifdef ZLIB
195         if( My_Connections[Idx].options & CONN_ZIP )
196                 return array_bytes(&My_Connections[Idx].zip.wbuf);
197         else
198 #endif
199         return array_bytes(&My_Connections[Idx].wbuf);
200 } /* Conn_SendQ */
201
202
203 GLOBAL long
204 Conn_SendMsg( CONN_ID Idx )
205 {
206         /* Anzahl gesendeter Nachrichten liefern */
207
208         assert( Idx > NONE );
209         return My_Connections[Idx].msg_out;
210 } /* Conn_SendMsg */
211
212
213 GLOBAL long
214 Conn_SendBytes( CONN_ID Idx )
215 {
216         /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
217
218         assert( Idx > NONE );
219         return My_Connections[Idx].bytes_out;
220 } /* Conn_SendBytes */
221
222
223 GLOBAL int
224 Conn_RecvQ( CONN_ID Idx )
225 {
226         /* Laenge der Daten im Lesebuffer liefern */
227
228         assert( Idx > NONE );
229 #ifdef ZLIB
230         if( My_Connections[Idx].options & CONN_ZIP )
231                 return array_bytes(&My_Connections[Idx].zip.rbuf);
232         else
233 #endif
234         return array_bytes(&My_Connections[Idx].rbuf);
235 } /* Conn_RecvQ */
236
237
238 GLOBAL long
239 Conn_RecvMsg( CONN_ID Idx )
240 {
241         /* Anzahl empfangener Nachrichten liefern */
242
243         assert( Idx > NONE );
244         return My_Connections[Idx].msg_in;
245 } /* Conn_RecvMsg */
246
247
248 GLOBAL long
249 Conn_RecvBytes( CONN_ID Idx )
250 {
251         /* Anzahl empfangener Bytes (unkomprimiert) liefern */
252
253         assert( Idx > NONE );
254         return My_Connections[Idx].bytes_in;
255 } /* Conn_RecvBytes */
256
257
258 GLOBAL void
259 Conn_ResetWCounter( void )
260 {
261         WCounter = 0;
262 } /* Conn_ResetWCounter */
263
264
265 GLOBAL long
266 Conn_WCounter( void )
267 {
268         return WCounter;
269 } /* Conn_WCounter */
270
271
272 /* -eof- */