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