]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn-func.c
Modified Conn_StartTime() to use information of the CLIENT structure.
[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.6 2005/06/12 16:32:17 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 ) My_Connections[Idx].delaytime = t;
77 } /* Conn_SetPenalty */
78
79
80 GLOBAL void
81 Conn_ResetPenalty( CONN_ID Idx )
82 {
83         assert( Idx > NONE );
84         My_Connections[Idx].delaytime = 0;
85 } /* Conn_ResetPenalty */
86
87
88 GLOBAL void
89 Conn_ClearFlags( void )
90 {
91         /* Alle Connection auf "nicht-markiert" setzen */
92
93         CONN_ID i;
94
95         for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
96 } /* Conn_ClearFlags */
97
98
99 GLOBAL int
100 Conn_Flag( CONN_ID Idx )
101 {
102         /* Ist eine Connection markiert (true) oder nicht? */
103
104         assert( Idx > NONE );
105         return My_Connections[Idx].flag;
106 } /* Conn_Flag */
107
108
109 GLOBAL void
110 Conn_SetFlag( CONN_ID Idx, int Flag )
111 {
112         /* Connection markieren */
113
114         assert( Idx > NONE );
115         My_Connections[Idx].flag = Flag;
116 } /* Conn_SetFlag */
117
118
119 GLOBAL CONN_ID
120 Conn_First( void )
121 {
122         /* Connection-Struktur der ersten Verbindung liefern;
123          * Ist keine Verbindung vorhanden, wird NONE geliefert. */
124
125         CONN_ID i;
126         
127         for( i = 0; i < Pool_Size; i++ )
128         {
129                 if( My_Connections[i].sock != NONE ) return i;
130         }
131         return NONE;
132 } /* Conn_First */
133
134
135 GLOBAL CONN_ID
136 Conn_Next( CONN_ID Idx )
137 {
138         /* Naechste Verbindungs-Struktur liefern; existiert keine
139          * weitere, so wird NONE geliefert. */
140
141         CONN_ID i = NONE;
142
143         assert( Idx > NONE );
144         
145         for( i = Idx + 1; i < Pool_Size; i++ )
146         {
147                 if( My_Connections[i].sock != NONE ) return i;
148         }
149         return NONE;
150 } /* Conn_Next */
151
152
153 GLOBAL int
154 Conn_Options( CONN_ID Idx )
155 {
156         assert( Idx > NONE );
157         return My_Connections[Idx].options;
158 } /* Conn_Options */
159
160
161 /**
162  * Get the start time of the connection.
163  * The result is the start time in seconds since 1970-01-01, as reported
164  * by the C function time(NULL).
165  */
166 GLOBAL time_t
167 Conn_StartTime( CONN_ID Idx )
168 {
169         CLIENT *c;
170
171         assert(Idx > NONE);
172
173         /* Search client structure for this link ... */
174         c = Client_GetFromConn(Idx);
175         if(c != NULL)
176                 return Client_StartTime(c);
177
178         return 0;
179 } /* Conn_StartTime */
180
181
182 GLOBAL int
183 Conn_SendQ( CONN_ID Idx )
184 {
185         /* Laenge der Daten im Schreibbuffer liefern */
186
187         assert( Idx > NONE );
188 #ifdef ZLIB
189         if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.wdatalen;
190         else
191 #endif
192         return My_Connections[Idx].wdatalen;
193 } /* Conn_SendQ */
194
195
196 GLOBAL long
197 Conn_SendMsg( CONN_ID Idx )
198 {
199         /* Anzahl gesendeter Nachrichten liefern */
200
201         assert( Idx > NONE );
202         return My_Connections[Idx].msg_out;
203 } /* Conn_SendMsg */
204
205
206 GLOBAL long
207 Conn_SendBytes( CONN_ID Idx )
208 {
209         /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
210
211         assert( Idx > NONE );
212         return My_Connections[Idx].bytes_out;
213 } /* Conn_SendBytes */
214
215
216 GLOBAL int
217 Conn_RecvQ( CONN_ID Idx )
218 {
219         /* Laenge der Daten im Lesebuffer liefern */
220
221         assert( Idx > NONE );
222 #ifdef ZLIB
223         if( My_Connections[Idx].options & CONN_ZIP ) return My_Connections[Idx].zip.rdatalen;
224         else
225 #endif
226         return My_Connections[Idx].rdatalen;
227 } /* Conn_RecvQ */
228
229
230 GLOBAL long
231 Conn_RecvMsg( CONN_ID Idx )
232 {
233         /* Anzahl empfangener Nachrichten liefern */
234
235         assert( Idx > NONE );
236         return My_Connections[Idx].msg_in;
237 } /* Conn_RecvMsg */
238
239
240 GLOBAL long
241 Conn_RecvBytes( CONN_ID Idx )
242 {
243         /* Anzahl empfangener Bytes (unkomprimiert) liefern */
244
245         assert( Idx > NONE );
246         return My_Connections[Idx].bytes_in;
247 } /* Conn_RecvBytes */
248
249
250 GLOBAL void
251 Conn_ResetWCounter( void )
252 {
253         WCounter = 0;
254 } /* Conn_ResetWCounter */
255
256
257 GLOBAL long
258 Conn_WCounter( void )
259 {
260         return WCounter;
261 } /* Conn_WCounter */
262
263
264 /* -eof- */