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