2001-12-12 18:18:38 +01:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
2010-04-23 23:25:34 +02:00
|
|
|
* Copyright (c)2001-2010 Alexander Barton <alex@barton.de>
|
2001-12-12 18:18:38 +01:00
|
|
|
*
|
2002-12-12 13:23:43 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
* Please read the file COPYING, README and AUTHORS for more information.
|
2001-12-12 18:18:38 +01:00
|
|
|
*
|
2002-12-12 13:23:43 +01:00
|
|
|
* Connection management (header)
|
2001-12-12 18:18:38 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef __conn_h__
|
|
|
|
#define __conn_h__
|
|
|
|
|
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
#include <time.h> /* for time_t, see below */
|
2002-11-27 00:06:51 +01:00
|
|
|
|
2009-02-04 23:01:53 +01:00
|
|
|
/*
|
|
|
|
* connection state flags. this is a bitmask -- all values must
|
|
|
|
* be unique and a power of two.
|
|
|
|
*
|
|
|
|
* If you introduce new ones in between, make sure to adjust all
|
|
|
|
* remaining ones.
|
|
|
|
*/
|
2005-07-31 00:53:16 +02:00
|
|
|
#define CONN_ISCLOSING 1 /* Conn_Close() already called */
|
|
|
|
#define CONN_ISCONNECTING 2 /* connect() in progress */
|
2008-08-13 16:52:35 +02:00
|
|
|
#define CONN_RFC1459 4 /* RFC 1459 compatibility mode */
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef ZLIB
|
2008-08-13 16:52:35 +02:00
|
|
|
#define CONN_ZIP 8 /* zlib compressed link */
|
2002-11-27 00:06:51 +01:00
|
|
|
#endif
|
2002-02-23 01:03:54 +01:00
|
|
|
|
2008-09-13 15:10:32 +02:00
|
|
|
#include "conf-ssl.h"
|
2002-02-23 01:03:54 +01:00
|
|
|
|
2008-09-13 15:10:32 +02:00
|
|
|
#ifdef SSL_SUPPORT
|
2009-02-04 23:01:53 +01:00
|
|
|
#define CONN_SSL_CONNECT 16 /* wait for ssl connect to finish */
|
|
|
|
#define CONN_SSL 32 /* this connection is SSL encrypted */
|
|
|
|
#define CONN_SSL_WANT_WRITE 64 /* SSL/TLS library needs to write protocol data */
|
|
|
|
#define CONN_SSL_WANT_READ 128 /* SSL/TLS library needs to read protocol data */
|
2009-02-04 23:23:12 +01:00
|
|
|
#define CONN_SSL_FLAGS_ALL (CONN_SSL_CONNECT|CONN_SSL|CONN_SSL_WANT_WRITE|CONN_SSL_WANT_READ)
|
2008-09-13 15:10:32 +02:00
|
|
|
#endif
|
2009-09-11 22:52:12 +02:00
|
|
|
typedef long CONN_ID;
|
2001-12-14 09:15:45 +01:00
|
|
|
|
2006-04-23 12:37:27 +02:00
|
|
|
#include "client.h"
|
2002-01-02 03:44:36 +01:00
|
|
|
|
2002-12-30 18:14:59 +01:00
|
|
|
#ifdef CONN_MODULE
|
2002-12-30 17:07:23 +01:00
|
|
|
|
|
|
|
#include "defines.h"
|
|
|
|
#include "resolve.h"
|
2005-07-07 20:45:33 +02:00
|
|
|
#include "array.h"
|
2008-02-26 23:50:35 +01:00
|
|
|
#include "tool.h"
|
|
|
|
#include "ng_ipaddr.h"
|
2002-12-30 17:07:23 +01:00
|
|
|
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef ZLIB
|
2002-12-30 17:07:23 +01:00
|
|
|
#include <zlib.h>
|
|
|
|
typedef struct _ZipData
|
|
|
|
{
|
|
|
|
z_stream in; /* "Handle" for input stream */
|
|
|
|
z_stream out; /* "Handle" for output stream */
|
2005-07-07 20:45:33 +02:00
|
|
|
array rbuf; /* Read buffer (compressed) */
|
|
|
|
array wbuf; /* Write buffer (uncompressed) */
|
2005-03-19 19:43:48 +01:00
|
|
|
long bytes_in, bytes_out; /* Counter for statistics (uncompressed!) */
|
2002-12-30 17:07:23 +01:00
|
|
|
} ZIPDATA;
|
2003-12-26 16:55:07 +01:00
|
|
|
#endif /* ZLIB */
|
2002-12-30 17:07:23 +01:00
|
|
|
|
|
|
|
typedef struct _Connection
|
|
|
|
{
|
2005-03-19 19:43:48 +01:00
|
|
|
int sock; /* Socket handle */
|
2008-02-26 23:50:35 +01:00
|
|
|
ng_ipaddr_t addr; /* Client address */
|
2005-09-12 21:10:20 +02:00
|
|
|
RES_STAT res_stat; /* Status of resolver process */
|
2005-03-19 19:43:48 +01:00
|
|
|
char host[HOST_LEN]; /* Hostname */
|
2005-07-07 20:45:33 +02:00
|
|
|
array rbuf; /* Read buffer */
|
|
|
|
array wbuf; /* Write buffer */
|
2007-10-04 17:03:55 +02:00
|
|
|
time_t signon; /* Signon ("connect") time */
|
2002-12-30 17:07:23 +01:00
|
|
|
time_t lastdata; /* Last activity */
|
|
|
|
time_t lastping; /* Last PING */
|
|
|
|
time_t lastprivmsg; /* Last PRIVMSG */
|
|
|
|
time_t delaytime; /* Ignore link ("penalty") */
|
2005-04-18 23:08:31 +02:00
|
|
|
long bytes_in, bytes_out; /* Received and sent bytes */
|
|
|
|
long msg_in, msg_out; /* Received and sent IRC messages */
|
2005-03-19 19:43:48 +01:00
|
|
|
int flag; /* Flag (see "irc-write" module) */
|
2005-04-18 23:08:31 +02:00
|
|
|
UINT16 options; /* Link options / connection state */
|
2009-05-25 22:25:18 +02:00
|
|
|
UINT16 bps; /* bytes processed within last second */
|
2006-04-23 12:37:27 +02:00
|
|
|
CLIENT *client; /* pointer to client structure */
|
2003-12-26 16:55:07 +01:00
|
|
|
#ifdef ZLIB
|
2002-12-30 17:07:23 +01:00
|
|
|
ZIPDATA zip; /* Compression information */
|
2003-12-26 16:55:07 +01:00
|
|
|
#endif /* ZLIB */
|
2008-09-13 15:10:32 +02:00
|
|
|
#ifdef SSL_SUPPORT
|
2009-12-30 23:32:47 +01:00
|
|
|
struct ConnSSL_State ssl_state; /* SSL/GNUTLS state information */
|
2008-09-13 15:10:32 +02:00
|
|
|
#endif
|
2002-12-30 17:07:23 +01:00
|
|
|
} CONNECTION;
|
|
|
|
|
|
|
|
GLOBAL CONNECTION *My_Connections;
|
|
|
|
GLOBAL CONN_ID Pool_Size;
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL long WCounter;
|
2002-12-30 17:07:23 +01:00
|
|
|
|
2002-12-30 18:14:59 +01:00
|
|
|
#endif /* CONN_MODULE */
|
2002-12-30 17:07:23 +01:00
|
|
|
|
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void Conn_Init PARAMS((void ));
|
|
|
|
GLOBAL void Conn_Exit PARAMS(( void ));
|
2001-12-14 09:15:45 +01:00
|
|
|
|
2007-04-04 23:52:12 +02:00
|
|
|
GLOBAL unsigned int Conn_InitListeners PARAMS(( void ));
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void Conn_ExitListeners PARAMS(( void ));
|
2002-11-22 18:58:19 +01:00
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void Conn_Handler PARAMS(( void ));
|
2001-12-12 18:18:38 +01:00
|
|
|
|
2010-06-26 00:44:37 +02:00
|
|
|
GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, const char *Format, ... ));
|
2001-12-12 18:18:38 +01:00
|
|
|
|
2009-04-12 01:09:42 +02:00
|
|
|
GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient ));
|
2001-12-15 01:08:27 +01:00
|
|
|
|
2005-03-19 19:43:48 +01:00
|
|
|
GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
|
2002-05-27 15:09:26 +02:00
|
|
|
|
2006-04-23 12:37:27 +02:00
|
|
|
GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
|
2008-09-13 15:10:32 +02:00
|
|
|
#ifdef SSL_SUPPORT
|
|
|
|
GLOBAL bool Conn_GetCipherInfo PARAMS((CONN_ID Idx, char *buf, size_t len));
|
|
|
|
GLOBAL bool Conn_UsesSSL PARAMS((CONN_ID Idx));
|
|
|
|
#else
|
|
|
|
static inline bool Conn_UsesSSL(UNUSED CONN_ID Idx) { return false; }
|
|
|
|
#endif
|
2001-12-12 18:18:38 +01:00
|
|
|
|
2010-04-23 23:25:34 +02:00
|
|
|
GLOBAL long Conn_Count PARAMS((void));
|
|
|
|
GLOBAL long Conn_CountMax PARAMS((void));
|
|
|
|
GLOBAL long Conn_CountAccepted PARAMS((void));
|
|
|
|
|
2010-06-26 00:45:11 +02:00
|
|
|
#endif
|
|
|
|
|
2009-09-11 22:52:12 +02:00
|
|
|
|
2001-12-12 18:18:38 +01:00
|
|
|
/* -eof- */
|