conn.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #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 int 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 ICONV
  48. # include <iconv.h>
  49. #endif
  50. #ifdef ZLIB
  51. #include <zlib.h>
  52. typedef struct _ZipData
  53. {
  54. z_stream in; /* "Handle" for input stream */
  55. z_stream out; /* "Handle" for output stream */
  56. array rbuf; /* Read buffer (compressed) */
  57. array wbuf; /* Write buffer (uncompressed) */
  58. long bytes_in, bytes_out; /* Counter for statistics (uncompressed!) */
  59. } ZIPDATA;
  60. #endif /* ZLIB */
  61. typedef struct _Connection
  62. {
  63. int sock; /* Socket handle */
  64. ng_ipaddr_t addr; /* Client address */
  65. PROC_STAT proc_stat; /* Status of resolver process */
  66. char host[HOST_LEN]; /* Hostname */
  67. char *pwd; /* password received of the client */
  68. array rbuf; /* Read buffer */
  69. array wbuf; /* Write buffer */
  70. time_t signon; /* Signon ("connect") time */
  71. time_t lastdata; /* Last activity */
  72. time_t lastping; /* Last PING */
  73. time_t lastprivmsg; /* Last PRIVMSG */
  74. time_t delaytime; /* Ignore link ("penalty") */
  75. long bytes_in, bytes_out; /* Received and sent bytes */
  76. long msg_in, msg_out; /* Received and sent IRC messages */
  77. int flag; /* Flag (see "irc-write" module) */
  78. UINT16 options; /* Link options / connection state */
  79. UINT16 bps; /* bytes processed within last second */
  80. CLIENT *client; /* pointer to client structure */
  81. #ifdef ZLIB
  82. ZIPDATA zip; /* Compression information */
  83. #endif /* ZLIB */
  84. #ifdef SSL_SUPPORT
  85. struct ConnSSL_State ssl_state; /* SSL/GNUTLS state information */
  86. #endif
  87. #ifndef STRICT_RFC
  88. long auth_ping; /** PING response expected on login */
  89. #endif
  90. #ifdef ICONV
  91. iconv_t iconv_from; /** iconv: convert from client to server */
  92. iconv_t iconv_to; /** iconv: convert from server to client */
  93. #endif
  94. } CONNECTION;
  95. GLOBAL CONNECTION *My_Connections;
  96. GLOBAL CONN_ID Pool_Size;
  97. GLOBAL long WCounter;
  98. #define CONNECTION2ID(x) (long)(x - My_Connections)
  99. #endif /* CONN_MODULE */
  100. GLOBAL void Conn_Init PARAMS((void ));
  101. GLOBAL void Conn_Exit PARAMS(( void ));
  102. GLOBAL void Conn_CloseAllSockets PARAMS((int ExceptOf));
  103. GLOBAL unsigned int Conn_InitListeners PARAMS(( void ));
  104. GLOBAL void Conn_ExitListeners PARAMS(( void ));
  105. GLOBAL void Conn_StartLogin PARAMS((CONN_ID Idx));
  106. GLOBAL void Conn_Handler PARAMS(( void ));
  107. GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, const char *Format, ... ));
  108. GLOBAL char* Conn_Password PARAMS(( CONN_ID Idx ));
  109. GLOBAL void Conn_SetPassword PARAMS(( CONN_ID Idx, const char *Pwd ));
  110. GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient ));
  111. GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
  112. GLOBAL CONN_ID Conn_GetFromProc PARAMS((int fd));
  113. GLOBAL CLIENT* Conn_GetClient PARAMS((CONN_ID i));
  114. GLOBAL PROC_STAT* Conn_GetProcStat PARAMS((CONN_ID i));
  115. #ifdef SSL_SUPPORT
  116. GLOBAL bool Conn_GetCipherInfo PARAMS((CONN_ID Idx, char *buf, size_t len));
  117. GLOBAL bool Conn_UsesSSL PARAMS((CONN_ID Idx));
  118. #else
  119. static inline bool
  120. Conn_UsesSSL(UNUSED CONN_ID Idx)
  121. { return false; }
  122. #endif
  123. GLOBAL const char *Conn_GetIPAInfo PARAMS((CONN_ID Idx));
  124. GLOBAL long Conn_Count PARAMS((void));
  125. GLOBAL long Conn_CountMax PARAMS((void));
  126. GLOBAL long Conn_CountAccepted PARAMS((void));
  127. #ifndef STRICT_RFC
  128. GLOBAL long Conn_GetAuthPing PARAMS((CONN_ID Idx));
  129. GLOBAL void Conn_SetAuthPing PARAMS((CONN_ID Idx, long ID));
  130. #endif
  131. #ifdef DEBUG
  132. GLOBAL void Conn_DebugDump PARAMS((void));
  133. #endif
  134. #endif
  135. /* -eof- */