conn.h 4.3 KB

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