2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
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.
18 * Connection management: Global functions
30 #include "conn-func.h"
34 * Update "idle timestamp", the time of the last visible user action
35 * (e. g. like sending messages, joining or leaving channels).
37 * @param Idx Connection index.
40 Conn_UpdateIdle(CONN_ID Idx)
43 My_Connections[Idx].lastprivmsg = time(NULL);
48 * Get signon time of a connection.
51 Conn_GetSignon(CONN_ID Idx)
54 return My_Connections[Idx].signon;
58 Conn_GetIdle( CONN_ID Idx )
60 /* Return Idle-Timer of a connetion */
62 return time( NULL ) - My_Connections[Idx].lastprivmsg;
67 Conn_LastPing( CONN_ID Idx )
70 return My_Connections[Idx].lastping;
75 * Add "penalty time" for a connection.
77 * During the "penalty time" the socket is ignored completely, no new data
78 * is read. This function only increases the penalty, it is not possible to
79 * decrease the penalty time.
81 * @param Idex Connection index.
82 * @param Seconds Seconds to add.
83 * @see Conn_ResetPenalty
86 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
94 if (My_Connections[Idx].delaytime < t)
95 My_Connections[Idx].delaytime = t;
97 My_Connections[Idx].delaytime += Seconds;
101 "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
102 Idx, (long)Seconds, Seconds != 1 ? "s" : "",
103 My_Connections[Idx].delaytime - t,
104 My_Connections[Idx].delaytime - t != 1 ? "s" : "");
106 } /* Conn_SetPenalty */
110 * Reset the "penalty time" for one connection.
112 * @param Idx Connection index.
113 * @see Conn_SetPenalty
116 Conn_ResetPenalty(CONN_ID Idx)
120 My_Connections[Idx].delaytime = 0;
122 Log(LOG_DEBUG, "Penalty time on connection %d has been reset.");
124 } /* Conn_ResetPenalty */
128 Conn_ClearFlags( void )
132 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
133 } /* Conn_ClearFlags */
137 Conn_Flag( CONN_ID Idx )
139 assert( Idx > NONE );
140 return My_Connections[Idx].flag;
145 Conn_SetFlag( CONN_ID Idx, int Flag )
147 /* Connection markieren */
149 assert( Idx > NONE );
150 My_Connections[Idx].flag = Flag;
157 /* Connection-Struktur der ersten Verbindung liefern;
158 * Ist keine Verbindung vorhanden, wird NONE geliefert. */
162 for( i = 0; i < Pool_Size; i++ )
164 if( My_Connections[i].sock != NONE ) return i;
171 Conn_Next( CONN_ID Idx )
173 /* Naechste Verbindungs-Struktur liefern; existiert keine
174 * weitere, so wird NONE geliefert. */
178 assert( Idx > NONE );
180 for( i = Idx + 1; i < Pool_Size; i++ )
182 if( My_Connections[i].sock != NONE ) return i;
189 Conn_Options( CONN_ID Idx )
191 assert( Idx > NONE );
192 return My_Connections[Idx].options;
197 * Set connection option.
200 Conn_SetOption(CONN_ID Idx, int Option)
203 Conn_OPTION_ADD(&My_Connections[Idx], Option);
204 } /* Conn_SetOption */
208 * Get the start time of the connection.
209 * The result is the start time in seconds since 1970-01-01, as reported
210 * by the C function time(NULL).
213 Conn_StartTime( CONN_ID Idx )
219 /* Search client structure for this link ... */
220 c = Conn_GetClient(Idx);
222 return Client_StartTime(c);
225 } /* Conn_StartTime */
228 * return number of bytes queued for writing
231 Conn_SendQ( CONN_ID Idx )
233 assert( Idx > NONE );
235 if( My_Connections[Idx].options & CONN_ZIP )
236 return array_bytes(&My_Connections[Idx].zip.wbuf);
239 return array_bytes(&My_Connections[Idx].wbuf);
244 * return number of messages sent on this connection so far
247 Conn_SendMsg( CONN_ID Idx )
250 assert( Idx > NONE );
251 return My_Connections[Idx].msg_out;
256 * return number of (uncompressed) bytes sent
257 * on this connection so far
260 Conn_SendBytes( CONN_ID Idx )
262 assert( Idx > NONE );
263 return My_Connections[Idx].bytes_out;
264 } /* Conn_SendBytes */
268 * return number of bytes pending in read buffer
271 Conn_RecvQ( CONN_ID Idx )
273 assert( Idx > NONE );
275 if( My_Connections[Idx].options & CONN_ZIP )
276 return array_bytes(&My_Connections[Idx].zip.rbuf);
279 return array_bytes(&My_Connections[Idx].rbuf);
284 * return number of messages received on this connection so far
287 Conn_RecvMsg( CONN_ID Idx )
289 assert( Idx > NONE );
290 return My_Connections[Idx].msg_in;
295 * return number of (uncompressed) bytes received on this
299 Conn_RecvBytes( CONN_ID Idx )
301 assert( Idx > NONE );
302 return My_Connections[Idx].bytes_in;
303 } /* Conn_RecvBytes */
306 * Return the remote IP address of this connection as string.
309 Conn_IPA(CONN_ID Idx)
312 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
317 Conn_ResetWCounter( void )
320 } /* Conn_ResetWCounter */
324 Conn_WCounter( void )
327 } /* Conn_WCounter */