]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn-func.c
Only log "IDENT ... no result" when IDENT was looked up
[ngircd-alex.git] / src / ngircd / conn-func.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2008 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
12 #define CONN_MODULE
13
14 #include "portab.h"
15
16 /**
17  * @file
18  * Connection management: Global functions
19  */
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 /**
34  * Update "idle timestamp", the time of the last visible user action
35  * (e. g. like sending messages, joining or leaving channels).
36  *
37  * @param Idx Connection index.
38  */
39 GLOBAL void
40 Conn_UpdateIdle(CONN_ID Idx)
41 {
42         assert(Idx > NONE);
43         My_Connections[Idx].lastprivmsg = time(NULL);
44 }
45
46 /**
47  * Update "ping timestamp", the time of the last outgoing PING request.
48  *
49  * @param Idx Connection index.
50  */
51 GLOBAL void
52 Conn_UpdatePing(CONN_ID Idx)
53 {
54         assert(Idx > NONE);
55         My_Connections[Idx].lastping = time(NULL);
56 }
57
58 /*
59  * Get signon time of a connection.
60  */
61 GLOBAL time_t
62 Conn_GetSignon(CONN_ID Idx)
63 {
64         assert(Idx > NONE);
65         return My_Connections[Idx].signon;
66 }
67
68 GLOBAL time_t
69 Conn_GetIdle( CONN_ID Idx )
70 {
71         /* Return Idle-Timer of a connetion */
72         assert( Idx > NONE );
73         return time( NULL ) - My_Connections[Idx].lastprivmsg;
74 } /* Conn_GetIdle */
75
76
77 GLOBAL time_t
78 Conn_LastPing( CONN_ID Idx )
79 {
80         assert( Idx > NONE );
81         return My_Connections[Idx].lastping;
82 } /* Conn_LastPing */
83
84
85 /**
86  * Add "penalty time" for a connection.
87  *
88  * During the "penalty time" the socket is ignored completely, no new data
89  * is read. This function only increases the penalty, it is not possible to
90  * decrease the penalty time.
91  *
92  * @param Idex Connection index.
93  * @param Seconds Seconds to add.
94  * @see Conn_ResetPenalty
95  */
96 GLOBAL void
97 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
98 {
99         time_t t;
100
101         assert(Idx > NONE);
102         assert(Seconds >= 0);
103
104         t = time(NULL);
105         if (My_Connections[Idx].delaytime < t)
106                 My_Connections[Idx].delaytime = t;
107
108         My_Connections[Idx].delaytime += Seconds;
109
110 #ifdef DEBUG
111         Log(LOG_DEBUG,
112             "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
113             Idx, (long)Seconds, Seconds != 1 ? "s" : "",
114             My_Connections[Idx].delaytime - t,
115             My_Connections[Idx].delaytime - t != 1 ? "s" : "");
116 #endif
117 } /* Conn_SetPenalty */
118
119
120 GLOBAL void
121 Conn_ClearFlags( void )
122 {
123         CONN_ID i;
124
125         for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
126 } /* Conn_ClearFlags */
127
128
129 GLOBAL int
130 Conn_Flag( CONN_ID Idx )
131 {
132         assert( Idx > NONE );
133         return My_Connections[Idx].flag;
134 } /* Conn_Flag */
135
136
137 GLOBAL void
138 Conn_SetFlag( CONN_ID Idx, int Flag )
139 {
140         assert( Idx > NONE );
141         My_Connections[Idx].flag = Flag;
142 } /* Conn_SetFlag */
143
144
145 GLOBAL CONN_ID
146 Conn_First( void )
147 {
148         CONN_ID i;
149         
150         for( i = 0; i < Pool_Size; i++ )
151         {
152                 if( My_Connections[i].sock != NONE ) return i;
153         }
154         return NONE;
155 } /* Conn_First */
156
157
158 GLOBAL CONN_ID
159 Conn_Next( CONN_ID Idx )
160 {
161         CONN_ID i = NONE;
162
163         assert( Idx > NONE );
164         
165         for( i = Idx + 1; i < Pool_Size; i++ )
166         {
167                 if( My_Connections[i].sock != NONE ) return i;
168         }
169         return NONE;
170 } /* Conn_Next */
171
172
173 GLOBAL UINT16
174 Conn_Options( CONN_ID Idx )
175 {
176         assert( Idx > NONE );
177         return My_Connections[Idx].options;
178 } /* Conn_Options */
179
180
181 /**
182  * Set connection option.
183  */
184 GLOBAL void
185 Conn_SetOption(CONN_ID Idx, int Option)
186 {
187         assert(Idx > NONE);
188         Conn_OPTION_ADD(&My_Connections[Idx], Option);
189 } /* Conn_SetOption */
190
191
192 /**
193  * Get the start time of the connection.
194  * The result is the start time in seconds since 1970-01-01, as reported
195  * by the C function time(NULL).
196  */
197 GLOBAL time_t
198 Conn_StartTime( CONN_ID Idx )
199 {
200         CLIENT *c;
201
202         assert(Idx > NONE);
203
204         /* Search client structure for this link ... */
205         c = Conn_GetClient(Idx);
206         if(c != NULL)
207                 return Client_StartTime(c);
208
209         return 0;
210 } /* Conn_StartTime */
211
212 /**
213  * return number of bytes queued for writing
214  */
215 GLOBAL size_t
216 Conn_SendQ( CONN_ID Idx )
217 {
218         assert( Idx > NONE );
219 #ifdef ZLIB
220         if( My_Connections[Idx].options & CONN_ZIP )
221                 return array_bytes(&My_Connections[Idx].zip.wbuf);
222         else
223 #endif
224         return array_bytes(&My_Connections[Idx].wbuf);
225 } /* Conn_SendQ */
226
227
228 /**
229  * return number of messages sent on this connection so far
230  */
231 GLOBAL long
232 Conn_SendMsg( CONN_ID Idx )
233 {
234
235         assert( Idx > NONE );
236         return My_Connections[Idx].msg_out;
237 } /* Conn_SendMsg */
238
239
240 /**
241  * return number of (uncompressed) bytes sent
242  * on this connection so far
243  */
244 GLOBAL long
245 Conn_SendBytes( CONN_ID Idx )
246 {
247         assert( Idx > NONE );
248         return My_Connections[Idx].bytes_out;
249 } /* Conn_SendBytes */
250
251
252 /**
253  * return number of bytes pending in read buffer
254  */
255 GLOBAL size_t
256 Conn_RecvQ( CONN_ID Idx )
257 {
258         assert( Idx > NONE );
259 #ifdef ZLIB
260         if( My_Connections[Idx].options & CONN_ZIP )
261                 return array_bytes(&My_Connections[Idx].zip.rbuf);
262         else
263 #endif
264         return array_bytes(&My_Connections[Idx].rbuf);
265 } /* Conn_RecvQ */
266
267
268 /**
269  * return number of messages received on this connection so far
270  */
271 GLOBAL long
272 Conn_RecvMsg( CONN_ID Idx )
273 {
274         assert( Idx > NONE );
275         return My_Connections[Idx].msg_in;
276 } /* Conn_RecvMsg */
277
278
279 /**
280  * return number of (uncompressed) bytes received on this
281  * connection so far
282  */
283 GLOBAL long
284 Conn_RecvBytes( CONN_ID Idx )
285 {
286         assert( Idx > NONE );
287         return My_Connections[Idx].bytes_in;
288 } /* Conn_RecvBytes */
289
290 /**
291  * Return the remote IP address of this connection as string.
292  */
293 GLOBAL const char *
294 Conn_IPA(CONN_ID Idx)
295 {
296         assert (Idx > NONE);
297         return ng_ipaddr_tostr(&My_Connections[Idx].addr);
298 }
299
300
301 GLOBAL void
302 Conn_ResetWCounter( void )
303 {
304         WCounter = 0;
305 } /* Conn_ResetWCounter */
306
307
308 GLOBAL long
309 Conn_WCounter( void )
310 {
311         return WCounter;
312 } /* Conn_WCounter */
313
314
315 /* -eof- */