2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2011 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.
17 * Connection management (header)
20 #include <time.h> /* for time_t, see below */
23 * connection state flags. this is a bitmask -- all values must
24 * be unique and a power of two.
26 * If you introduce new ones in between, make sure to adjust all
29 #define CONN_ISCLOSING 1 /* Conn_Close() already called */
30 #define CONN_ISCONNECTING 2 /* connect() in progress */
31 #define CONN_RFC1459 4 /* RFC 1459 compatibility mode */
33 #define CONN_ZIP 8 /* zlib compressed link */
39 #define CONN_SSL_CONNECT 16 /* wait for ssl connect to finish */
40 #define CONN_SSL 32 /* this connection is SSL encrypted */
41 #define CONN_SSL_WANT_WRITE 64 /* SSL/TLS library needs to write protocol data */
42 #define CONN_SSL_WANT_READ 128 /* SSL/TLS library needs to read protocol data */
43 #define CONN_SSL_PEERCERT_OK 256 /* peer presented a valid certificate (used to check inbound server auth */
44 #define CONN_SSL_COMPRESSION 512 /* SSL/TLS link is compressed */
45 #define CONN_SSL_FLAGS_ALL (CONN_SSL_CONNECT|CONN_SSL|CONN_SSL_WANT_WRITE|CONN_SSL_WANT_READ|CONN_SSL_PEERCERT_OK|CONN_SSL_COMPRESSION)
57 #include "ng_ipaddr.h"
65 typedef struct _ZipData
67 z_stream in; /* "Handle" for input stream */
68 z_stream out; /* "Handle" for output stream */
69 array rbuf; /* Read buffer (compressed) */
70 array wbuf; /* Write buffer (uncompressed) */
71 long bytes_in, bytes_out; /* Counter for statistics (uncompressed!) */
75 typedef struct _Connection
77 int sock; /* Socket handle */
78 ng_ipaddr_t addr; /* Client address */
79 PROC_STAT proc_stat; /* Status of resolver process */
80 char host[HOST_LEN]; /* Hostname */
81 char *pwd; /* password received of the client */
82 array rbuf; /* Read buffer */
83 array wbuf; /* Write buffer */
84 time_t signon; /* Signon ("connect") time */
85 time_t lastdata; /* Last activity */
86 time_t lastping; /* Last PING */
87 time_t lastprivmsg; /* Last PRIVMSG */
88 time_t delaytime; /* Ignore link ("penalty") */
89 long bytes_in, bytes_out; /* Received and sent bytes */
90 long msg_in, msg_out; /* Received and sent IRC messages */
91 int flag; /* Flag (see "irc-write" module) */
92 UINT16 options; /* Link options / connection state */
93 UINT16 bps; /* bytes processed within last second */
94 CLIENT *client; /* pointer to client structure */
96 ZIPDATA zip; /* Compression information */
99 struct ConnSSL_State ssl_state; /* SSL/GNUTLS state information */
102 long auth_ping; /** PING response expected on login */
105 iconv_t iconv_from; /** iconv: convert from client to server */
106 iconv_t iconv_to; /** iconv: convert from server to client */
110 GLOBAL CONNECTION *My_Connections;
111 GLOBAL CONN_ID Pool_Size;
112 GLOBAL long WCounter;
114 #define CONNECTION2ID(x) (long)(x - My_Connections)
116 #endif /* CONN_MODULE */
119 GLOBAL void Conn_Init PARAMS((void ));
120 GLOBAL void Conn_Exit PARAMS(( void ));
122 GLOBAL void Conn_CloseAllSockets PARAMS((int ExceptOf));
124 GLOBAL unsigned int Conn_InitListeners PARAMS(( void ));
125 GLOBAL void Conn_ExitListeners PARAMS(( void ));
127 GLOBAL void Conn_StartLogin PARAMS((CONN_ID Idx));
129 GLOBAL void Conn_Handler PARAMS(( void ));
131 GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, const char *Format, ... ));
133 GLOBAL char* Conn_Password PARAMS(( CONN_ID Idx ));
134 GLOBAL void Conn_SetPassword PARAMS(( CONN_ID Idx, const char *Pwd ));
136 GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient ));
138 GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
140 GLOBAL CONN_ID Conn_GetFromProc PARAMS((int fd));
141 GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
142 GLOBAL PROC_STAT* Conn_GetProcStat PARAMS((CONN_ID i));
144 GLOBAL char *Conn_GetCertFp PARAMS((CONN_ID Idx));
145 GLOBAL bool Conn_SetCertFp PARAMS((CONN_ID Idx, const char *fingerprint));
146 GLOBAL bool Conn_UsesSSL PARAMS((CONN_ID Idx));
148 GLOBAL const char* Conn_BuildProtoID PARAMS((CONN_ID i));
150 GLOBAL bool Conn_GetCipherInfo PARAMS((CONN_ID Idx, char *buf, size_t len));
153 GLOBAL const char *Conn_GetIPAInfo PARAMS((CONN_ID Idx));
155 GLOBAL long Conn_Count PARAMS((void));
156 GLOBAL long Conn_CountMax PARAMS((void));
157 GLOBAL long Conn_CountAccepted PARAMS((void));
160 GLOBAL long Conn_GetAuthPing PARAMS((CONN_ID Idx));
161 GLOBAL void Conn_SetAuthPing PARAMS((CONN_ID Idx, long ID));
165 GLOBAL void Conn_DebugDump PARAMS((void));