]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn-func.c
use new buffer API
[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.7 2005/07/07 18:39:45 fw 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 )
190                 return array_bytes(&My_Connections[Idx].zip.wbuf);
191         else
192 #endif
193         return array_bytes(&My_Connections[Idx].wbuf);
194 } /* Conn_SendQ */
195
196
197 GLOBAL long
198 Conn_SendMsg( CONN_ID Idx )
199 {
200         /* Anzahl gesendeter Nachrichten liefern */
201
202         assert( Idx > NONE );
203         return My_Connections[Idx].msg_out;
204 } /* Conn_SendMsg */
205
206
207 GLOBAL long
208 Conn_SendBytes( CONN_ID Idx )
209 {
210         /* Anzahl gesendeter Bytes (unkomprimiert) liefern */
211
212         assert( Idx > NONE );
213         return My_Connections[Idx].bytes_out;
214 } /* Conn_SendBytes */
215
216
217 GLOBAL int
218 Conn_RecvQ( CONN_ID Idx )
219 {
220         /* Laenge der Daten im Lesebuffer liefern */
221
222         assert( Idx > NONE );
223 #ifdef ZLIB
224         if( My_Connections[Idx].options & CONN_ZIP )
225                 return array_bytes(&My_Connections[Idx].zip.rbuf);
226         else
227 #endif
228         return array_bytes(&My_Connections[Idx].rbuf);
229 } /* Conn_RecvQ */
230
231
232 GLOBAL long
233 Conn_RecvMsg( CONN_ID Idx )
234 {
235         /* Anzahl empfangener Nachrichten liefern */
236
237         assert( Idx > NONE );
238         return My_Connections[Idx].msg_in;
239 } /* Conn_RecvMsg */
240
241
242 GLOBAL long
243 Conn_RecvBytes( CONN_ID Idx )
244 {
245         /* Anzahl empfangener Bytes (unkomprimiert) liefern */
246
247         assert( Idx > NONE );
248         return My_Connections[Idx].bytes_in;
249 } /* Conn_RecvBytes */
250
251
252 GLOBAL void
253 Conn_ResetWCounter( void )
254 {
255         WCounter = 0;
256 } /* Conn_ResetWCounter */
257
258
259 GLOBAL long
260 Conn_WCounter( void )
261 {
262         return WCounter;
263 } /* Conn_WCounter */
264
265
266 /* -eof- */