PageRenderTime 58ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/znc-0.097-r2182/znc-msvc/znc.h

https://gitlab.com/BGCX261/znc-msvc-svn-to-git
C Header | 194 lines | 144 code | 22 blank | 28 comment | 4 complexity | 4a7922e7a79fde1ca40bc499ed81f48c MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (C) 2004-2010 See the AUTHORS file for details.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published
  6. * by the Free Software Foundation.
  7. */
  8. #ifndef _ZNC_H
  9. #define _ZNC_H
  10. #include "main.h"
  11. #include "Client.h"
  12. #include "FileUtils.h"
  13. #include "Modules.h"
  14. #include "Socket.h"
  15. #include <map>
  16. using std::map;
  17. class CListener;
  18. class CUser;
  19. class CConnectUserTimer;
  20. class ZNC_API CZNC {
  21. public:
  22. CZNC();
  23. ~CZNC();
  24. enum ConfigState {
  25. ECONFIG_NOTHING,
  26. ECONFIG_NEED_REHASH,
  27. ECONFIG_NEED_WRITE
  28. };
  29. void DeleteUsers();
  30. void LoopDoMaintenance();
  31. #ifdef _WIN32
  32. void Loop(bool* bLoop);
  33. #else
  34. void Loop();
  35. #endif
  36. bool WriteISpoof(CUser* pUser);
  37. void ReleaseISpoof();
  38. bool WritePidFile(int iPid);
  39. bool DeletePidFile();
  40. bool WaitForChildLock();
  41. bool IsHostAllowed(const CString& sHostMask) const;
  42. // This returns false if there are too many anonymous connections from this ip
  43. bool AllowConnectionFrom(const CString& sIP) const;
  44. void InitDirs(const CString& sArgvPath, const CString& sDataDir);
  45. bool OnBoot();
  46. CString ExpandConfigPath(const CString& sConfigFile, bool bAllowMkDir = true);
  47. bool WriteNewConfig(const CString& sConfigFile);
  48. bool WriteConfig();
  49. bool ParseConfig(const CString& sConfig);
  50. bool RehashConfig(CString& sError);
  51. static CString GetVersion();
  52. static CString GetTag(bool bIncludeVersion = true);
  53. CString GetUptime() const;
  54. static double GetCoreVersion();
  55. void ClearBindHosts();
  56. bool AddBindHost(const CString& sHost);
  57. bool RemBindHost(const CString& sHost);
  58. void Broadcast(const CString& sMessage, bool bAdminOnly = false,
  59. CUser* pSkipUser = NULL, CClient* pSkipClient = NULL);
  60. void AddBytesRead(unsigned long long u) { m_uBytesRead += u; }
  61. void AddBytesWritten(unsigned long long u) { m_uBytesWritten += u; }
  62. unsigned long long BytesRead() const { return m_uBytesRead; }
  63. unsigned long long BytesWritten() const { return m_uBytesWritten; }
  64. // Traffic fun
  65. typedef std::pair<unsigned long long, unsigned long long> TrafficStatsPair;
  66. typedef std::map<CString, TrafficStatsPair> TrafficStatsMap;
  67. // Returns a map which maps user names to <traffic in, traffic out>
  68. // while also providing the traffic of all users together, traffic which
  69. // couldn't be accounted to any particular user and the total traffic
  70. // generated through ZNC.
  71. TrafficStatsMap GetTrafficStats(TrafficStatsPair &Users,
  72. TrafficStatsPair &ZNC, TrafficStatsPair &Total);
  73. // Authenticate a user.
  74. // The result is passed back via callbacks to CAuthBase.
  75. // CSmartPtr handles freeing this pointer!
  76. void AuthUser(CSmartPtr<CAuthBase> AuthClass);
  77. // Setters
  78. void SetConfigState(enum ConfigState e) { m_eConfigState = e; }
  79. void SetSkinName(const CString& s) { m_sSkinName = s; }
  80. void SetStatusPrefix(const CString& s) { m_sStatusPrefix = (s.empty()) ? "*" : s; }
  81. void SetISpoofFile(const CString& s) { m_sISpoofFile = s; }
  82. void SetISpoofFormat(const CString& s) { m_sISpoofFormat = (s.empty()) ? "global { reply \"%\" }" : s; }
  83. void SetMaxBufferSize(size_t i) { m_uiMaxBufferSize = i; }
  84. // !Setters
  85. // Getters
  86. enum ConfigState GetConfigState() const { return m_eConfigState; }
  87. CSockManager& GetManager() { return m_Manager; }
  88. const CSockManager& GetManager() const { return m_Manager; }
  89. CGlobalModules& GetModules() { return *m_pModules; }
  90. size_t FilterUncommonModules(set<CModInfo>& ssModules);
  91. CString GetSkinName() const { return m_sSkinName; }
  92. const CString& GetStatusPrefix() const { return m_sStatusPrefix; }
  93. const CString& GetCurPath() const { if (!CFile::Exists(m_sCurPath)) { CDir::MakeDir(m_sCurPath); } return m_sCurPath; }
  94. const CString& GetHomePath() const { if (!CFile::Exists(m_sHomePath)) { CDir::MakeDir(m_sHomePath); } return m_sHomePath; }
  95. const CString& GetZNCPath() const { if (!CFile::Exists(m_sZNCPath)) { CDir::MakeDir(m_sZNCPath); } return m_sZNCPath; }
  96. CString GetConfPath(bool bAllowMkDir = true) const;
  97. CString GetUserPath() const;
  98. CString GetModPath() const;
  99. CString GetPemLocation() const { return m_sSSLCertFile; }
  100. const CString& GetConfigFile() const { return m_sConfigFile; }
  101. bool WritePemFile();
  102. const CString& GetISpoofFile() const { return m_sISpoofFile; }
  103. const CString& GetISpoofFormat() const { return m_sISpoofFormat; }
  104. const VCString& GetBindHosts() const { return m_vsBindHosts; }
  105. const vector<CListener*>& GetListeners() const { return m_vpListeners; }
  106. time_t TimeStarted() const { return m_TimeStarted; }
  107. size_t GetMaxBufferSize() const { return m_uiMaxBufferSize; }
  108. // !Getters
  109. // Static allocator
  110. static CZNC& Get();
  111. static void _Reset();
  112. void HookOutput(outputHook fHook);
  113. CUser* FindUser(const CString& sUsername);
  114. CModule* FindModule(const CString& sModName, const CString& sUsername);
  115. CModule* FindModule(const CString& sModName, CUser* pUser);
  116. bool DeleteUser(const CString& sUsername);
  117. bool AddUser(CUser* pUser, CString& sErrorRet);
  118. const map<CString,CUser*> & GetUserMap() const { return(m_msUsers); }
  119. // Listener yummy
  120. CListener* FindListener(u_short uPort, const CString& BindHost, EAddrType eAddr);
  121. bool AddListener(CListener*);
  122. bool DelListener(CListener*);
  123. // Message of the Day
  124. void SetMotd(const CString& sMessage) { ClearMotd(); AddMotd(sMessage); }
  125. void AddMotd(const CString& sMessage) { if (!sMessage.empty()) { m_vsMotd.push_back(sMessage); } }
  126. void ClearMotd() { m_vsMotd.clear(); }
  127. const VCString& GetMotd() const { return m_vsMotd; }
  128. // !MOTD
  129. // Create a CIRCSocket. Return false if user cant connect
  130. bool ConnectUser(CUser *pUser);
  131. // This creates a CConnectUserTimer if we haven't got one yet
  132. void EnableConnectUser();
  133. void DisableConnectUser();
  134. // Never call this unless you are CConnectUserTimer::~CConnectUserTimer()
  135. void LeakConnectUser(CConnectUserTimer *pTimer);
  136. private:
  137. CFile* InitPidFile();
  138. bool DoRehash(CString& sError);
  139. // Returns true if something was done
  140. bool HandleUserDeletion();
  141. protected:
  142. time_t m_TimeStarted;
  143. enum ConfigState m_eConfigState;
  144. vector<CListener*> m_vpListeners;
  145. map<CString,CUser*> m_msUsers;
  146. map<CString,CUser*> m_msDelUsers;
  147. CSockManager m_Manager;
  148. CString m_sCurPath;
  149. CString m_sHomePath;
  150. CString m_sZNCPath;
  151. CString m_sConfigFile;
  152. CString m_sSkinName;
  153. CString m_sStatusPrefix;
  154. CString m_sISpoofFile;
  155. CString m_sOrigISpoof;
  156. CString m_sISpoofFormat;
  157. CString m_sPidFile;
  158. CString m_sSSLCertFile;
  159. VCString m_vsBindHosts;
  160. VCString m_vsMotd;
  161. CFile m_LockFile;
  162. CFile* m_pISpoofLockFile;
  163. unsigned int m_uiConnectDelay;
  164. unsigned int m_uiAnonIPLimit;
  165. size_t m_uiMaxBufferSize;
  166. CGlobalModules* m_pModules;
  167. unsigned long long m_uBytesRead;
  168. unsigned long long m_uBytesWritten;
  169. CConnectUserTimer *m_pConnectUserTimer;
  170. TCacheMap<CString> m_sConnectThrottle;
  171. };
  172. #endif // !_ZNC_H