Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001-2008 by 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 * Connection management (header)
12 */
15 #ifndef __conn_h__
16 #define __conn_h__
19 #include <time.h> /* for time_t, see below */
22 #define CONN_ISCLOSING 1 /* Conn_Close() already called */
23 #define CONN_ISCONNECTING 2 /* connect() in progress */
24 #define CONN_RFC1459 4 /* RFC 1459 compatibility mode */
25 #ifdef ZLIB
26 #define CONN_ZIP 8 /* zlib compressed link */
27 #endif
29 #include "conf-ssl.h"
31 #ifdef SSL_SUPPORT
32 #define CONN_SSL_CONNECT 8 /* wait for ssl connect to finish */
33 #define CONN_SSL 16 /* this connection is SSL encrypted */
34 #define CONN_SSL_WANT_WRITE 32 /* SSL/TLS library needs to write protocol data */
35 #define CONN_SSL_WANT_READ 64 /* SSL/TLS library needs to read protocol data */
36 #endif
37 typedef int CONN_ID;
39 #include "client.h"
41 #ifdef CONN_MODULE
43 #include "defines.h"
44 #include "resolve.h"
45 #include "array.h"
46 #include "tool.h"
47 #include "ng_ipaddr.h"
49 #ifdef ZLIB
50 #include <zlib.h>
51 typedef struct _ZipData
52 {
53 z_stream in; /* "Handle" for input stream */
54 z_stream out; /* "Handle" for output stream */
55 array rbuf; /* Read buffer (compressed) */
56 array wbuf; /* Write buffer (uncompressed) */
57 long bytes_in, bytes_out; /* Counter for statistics (uncompressed!) */
58 } ZIPDATA;
59 #endif /* ZLIB */
61 typedef struct _Connection
62 {
63 int sock; /* Socket handle */
64 ng_ipaddr_t addr; /* Client address */
65 RES_STAT res_stat; /* Status of resolver process */
66 char host[HOST_LEN]; /* Hostname */
67 array rbuf; /* Read buffer */
68 array wbuf; /* Write buffer */
69 time_t signon; /* Signon ("connect") time */
70 time_t lastdata; /* Last activity */
71 time_t lastping; /* Last PING */
72 time_t lastprivmsg; /* Last PRIVMSG */
73 time_t delaytime; /* Ignore link ("penalty") */
74 long bytes_in, bytes_out; /* Received and sent bytes */
75 long msg_in, msg_out; /* Received and sent IRC messages */
76 int flag; /* Flag (see "irc-write" module) */
77 UINT16 options; /* Link options / connection state */
78 CLIENT *client; /* pointer to client structure */
79 #ifdef ZLIB
80 ZIPDATA zip; /* Compression information */
81 #endif /* ZLIB */
82 #ifdef SSL_SUPPORT
83 struct ConnSSL_State ssl_state; /* SSL/GNUTLS state information */
84 #endif
85 } CONNECTION;
87 GLOBAL CONNECTION *My_Connections;
88 GLOBAL CONN_ID Pool_Size;
89 GLOBAL long WCounter;
91 #endif /* CONN_MODULE */
94 GLOBAL void Conn_Init PARAMS((void ));
95 GLOBAL void Conn_Exit PARAMS(( void ));
97 GLOBAL unsigned int Conn_InitListeners PARAMS(( void ));
98 GLOBAL void Conn_ExitListeners PARAMS(( void ));
100 GLOBAL void Conn_Handler PARAMS(( void ));
102 GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, char *Format, ... ));
104 GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient ));
106 GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
108 GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
109 #ifdef SSL_SUPPORT
110 GLOBAL bool Conn_GetCipherInfo PARAMS((CONN_ID Idx, char *buf, size_t len));
111 GLOBAL bool Conn_UsesSSL PARAMS((CONN_ID Idx));
112 #else
113 static inline bool Conn_UsesSSL(UNUSED CONN_ID Idx) { return false; }
114 #endif
115 #endif
117 /* -eof- */