2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2014 Alexander Barton (alex@barton.de) and Contributors.
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
29 #include "conn-func.h"
32 * Update "idle timestamp", the time of the last visible user action
33 * (e. g. like sending messages, joining or leaving channels).
35 * @param Idx Connection index.
38 Conn_UpdateIdle(CONN_ID Idx)
41 My_Connections[Idx].lastprivmsg = time(NULL);
45 * Update "ping timestamp", the time of the last outgoing PING request.
47 * @param Idx Connection index.
50 Conn_UpdatePing(CONN_ID Idx)
53 My_Connections[Idx].lastping = time(NULL);
57 * Get signon time of a connection.
60 Conn_GetSignon(CONN_ID Idx)
63 return My_Connections[Idx].signon;
67 Conn_GetIdle( CONN_ID Idx )
69 /* Return Idle-Timer of a connetion */
71 return time( NULL ) - My_Connections[Idx].lastprivmsg;
75 Conn_LastPing( CONN_ID Idx )
78 return My_Connections[Idx].lastping;
82 * Add "penalty time" for a connection.
84 * During the "penalty time" the socket is ignored completely, no new data
85 * is read. This function only increases the penalty, it is not possible to
86 * decrease the penalty time.
88 * @param Idex Connection index.
89 * @param Seconds Seconds to add.
90 * @see Conn_ResetPenalty
93 Conn_SetPenalty(CONN_ID Idx, time_t Seconds)
101 if (My_Connections[Idx].delaytime < t)
102 My_Connections[Idx].delaytime = t;
104 My_Connections[Idx].delaytime += Seconds;
108 "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
109 Idx, (long)Seconds, Seconds != 1 ? "s" : "",
110 My_Connections[Idx].delaytime - t,
111 My_Connections[Idx].delaytime - t != 1 ? "s" : "");
113 } /* Conn_SetPenalty */
116 Conn_ClearFlags( void )
120 for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0;
121 } /* Conn_ClearFlags */
124 Conn_Flag( CONN_ID Idx )
126 assert( Idx > NONE );
127 return My_Connections[Idx].flag;
131 Conn_SetFlag( CONN_ID Idx, int Flag )
133 assert( Idx > NONE );
134 My_Connections[Idx].flag = Flag;
142 for( i = 0; i < Pool_Size; i++ )
144 if( My_Connections[i].sock != NONE ) return i;
150 Conn_Next( CONN_ID Idx )
154 assert( Idx > NONE );
156 for( i = Idx + 1; i < Pool_Size; i++ )
158 if( My_Connections[i].sock != NONE ) return i;
164 Conn_Options( CONN_ID Idx )
166 assert( Idx > NONE );
167 return My_Connections[Idx].options;
171 * Set connection option.
174 Conn_SetOption(CONN_ID Idx, int Option)
177 Conn_OPTION_ADD(&My_Connections[Idx], Option);
178 } /* Conn_SetOption */
181 * Get the start time of the connection.
182 * The result is the start time in seconds since 1970-01-01, as reported
183 * by the C function time(NULL).
186 Conn_StartTime( CONN_ID Idx )
192 /* Search client structure for this link ... */
193 c = Conn_GetClient(Idx);
195 return Client_StartTime(c);
198 } /* Conn_StartTime */
201 * return number of bytes queued for writing
204 Conn_SendQ( CONN_ID Idx )
206 assert( Idx > NONE );
208 if( My_Connections[Idx].options & CONN_ZIP )
209 return array_bytes(&My_Connections[Idx].zip.wbuf);
212 return array_bytes(&My_Connections[Idx].wbuf);
216 * return number of messages sent on this connection so far
219 Conn_SendMsg( CONN_ID Idx )
222 assert( Idx > NONE );
223 return My_Connections[Idx].msg_out;
227 * return number of (uncompressed) bytes sent
228 * on this connection so far
231 Conn_SendBytes( CONN_ID Idx )
233 assert( Idx > NONE );
234 return My_Connections[Idx].bytes_out;
235 } /* Conn_SendBytes */
238 * return number of bytes pending in read buffer
241 Conn_RecvQ( CONN_ID Idx )
243 assert( Idx > NONE );
245 if( My_Connections[Idx].options & CONN_ZIP )
246 return array_bytes(&My_Connections[Idx].zip.rbuf);
249 return array_bytes(&My_Connections[Idx].rbuf);
253 * return number of messages received on this connection so far
256 Conn_RecvMsg( CONN_ID Idx )
258 assert( Idx > NONE );
259 return My_Connections[Idx].msg_in;
263 * return number of (uncompressed) bytes received on this
267 Conn_RecvBytes( CONN_ID Idx )
269 assert( Idx > NONE );
270 return My_Connections[Idx].bytes_in;
271 } /* Conn_RecvBytes */
274 * Return the remote IP address of this connection as string.
277 Conn_IPA(CONN_ID Idx)
280 return ng_ipaddr_tostr(&My_Connections[Idx].addr);
284 Conn_ResetWCounter( void )
287 } /* Conn_ResetWCounter */
290 Conn_WCounter( void )
293 } /* Conn_WCounter */