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