]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/conn.h
8ce5654da2c294dd5e4b014119f827600c4e9c49
[ngircd-alex.git] / src / ngircd / conn.h
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001-2010 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
12
13 #ifndef __conn_h__
14 #define __conn_h__
15
16 /**
17  * @file
18  * Connection management (header)
19  */
20
21 #include <time.h>                       /* for time_t, see below */
22
23 /*
24  * connection state flags. this is a bitmask -- all values must
25  * be unique and a power of two.
26  *
27  * If you introduce new ones in between, make sure to adjust all
28  * remaining ones.
29  */
30 #define CONN_ISCLOSING          1       /* Conn_Close() already called */
31 #define CONN_ISCONNECTING       2       /* connect() in progress */
32 #define CONN_RFC1459            4       /* RFC 1459 compatibility mode */
33 #ifdef ZLIB
34 #define CONN_ZIP                8       /* zlib compressed link */
35 #endif
36
37 #include "conf-ssl.h"
38
39 #ifdef SSL_SUPPORT
40 #define CONN_SSL_CONNECT        16      /* wait for ssl connect to finish */
41 #define CONN_SSL                32      /* this connection is SSL encrypted */
42 #define CONN_SSL_WANT_WRITE     64      /* SSL/TLS library needs to write protocol data */
43 #define CONN_SSL_WANT_READ      128     /* SSL/TLS library needs to read protocol data */
44 #define CONN_SSL_FLAGS_ALL      (CONN_SSL_CONNECT|CONN_SSL|CONN_SSL_WANT_WRITE|CONN_SSL_WANT_READ)
45 #endif
46 typedef long CONN_ID;
47
48 #include "client.h"
49 #include "proc.h"
50
51 #ifdef CONN_MODULE
52
53 #include "defines.h"
54 #include "array.h"
55 #include "tool.h"
56 #include "ng_ipaddr.h"
57
58 #ifdef ZLIB
59 #include <zlib.h>
60 typedef struct _ZipData
61 {
62         z_stream in;                    /* "Handle" for input stream */
63         z_stream out;                   /* "Handle" for output stream */
64         array rbuf;                     /* Read buffer (compressed) */
65         array wbuf;                     /* Write buffer (uncompressed) */
66         long bytes_in, bytes_out;       /* Counter for statistics (uncompressed!) */
67 } ZIPDATA;
68 #endif /* ZLIB */
69
70 typedef struct _Connection
71 {
72         int sock;                       /* Socket handle */
73         ng_ipaddr_t addr;               /* Client address */
74         PROC_STAT proc_stat;            /* Status of resolver process */
75         char host[HOST_LEN];            /* Hostname */
76         array rbuf;                     /* Read buffer */
77         array wbuf;                     /* Write buffer */
78         time_t signon;                  /* Signon ("connect") time */
79         time_t lastdata;                /* Last activity */
80         time_t lastping;                /* Last PING */
81         time_t lastprivmsg;             /* Last PRIVMSG */
82         time_t delaytime;               /* Ignore link ("penalty") */
83         long bytes_in, bytes_out;       /* Received and sent bytes */
84         long msg_in, msg_out;           /* Received and sent IRC messages */
85         int flag;                       /* Flag (see "irc-write" module) */
86         UINT16 options;                 /* Link options / connection state */
87         UINT16 bps;                     /* bytes processed within last second */
88         CLIENT *client;                 /* pointer to client structure */
89 #ifdef ZLIB
90         ZIPDATA zip;                    /* Compression information */
91 #endif  /* ZLIB */
92 #ifdef SSL_SUPPORT
93         struct ConnSSL_State ssl_state; /* SSL/GNUTLS state information */
94 #endif
95 } CONNECTION;
96
97 GLOBAL CONNECTION *My_Connections;
98 GLOBAL CONN_ID Pool_Size;
99 GLOBAL long WCounter;
100
101 #endif /* CONN_MODULE */
102
103
104 GLOBAL void Conn_Init PARAMS((void ));
105 GLOBAL void Conn_Exit PARAMS(( void ));
106
107 GLOBAL void Conn_CloseAllSockets PARAMS((void));
108
109 GLOBAL unsigned int Conn_InitListeners PARAMS(( void ));
110 GLOBAL void Conn_ExitListeners PARAMS(( void ));
111
112 GLOBAL void Conn_Handler PARAMS(( void ));
113
114 GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, const char *Format, ... ));
115
116 GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient ));
117
118 GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
119
120 GLOBAL CONN_ID Conn_GetFromProc PARAMS((int fd));
121 GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
122 GLOBAL PROC_STAT* Conn_GetProcStat PARAMS((CONN_ID i));
123 #ifdef SSL_SUPPORT
124 GLOBAL bool Conn_GetCipherInfo PARAMS((CONN_ID Idx, char *buf, size_t len));
125 GLOBAL bool Conn_UsesSSL PARAMS((CONN_ID Idx));
126 #else
127 static inline bool
128 Conn_UsesSSL(UNUSED CONN_ID Idx)
129 { return false; }
130 #endif
131
132 GLOBAL long Conn_Count PARAMS((void));
133 GLOBAL long Conn_CountMax PARAMS((void));
134 GLOBAL long Conn_CountAccepted PARAMS((void));
135
136 #ifdef DEBUG
137 GLOBAL void Conn_DebugDump PARAMS((void));
138 #endif
139
140 #endif
141
142
143 /* -eof- */