conn.h 4.1 KB

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