/src/znc/include/znc/Modules.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) 2004-2026 ZNC, see the NOTICE file for details. |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #ifndef ZNC_MODULES_H |
18 | | #define ZNC_MODULES_H |
19 | | |
20 | | #include <znc/zncconfig.h> |
21 | | #include <znc/WebModules.h> |
22 | | #include <znc/Utils.h> |
23 | | #include <znc/Threads.h> |
24 | | #include <znc/Message.h> |
25 | | #include <znc/main.h> |
26 | | #include <znc/Translation.h> |
27 | | #include <functional> |
28 | | #include <memory> |
29 | | #include <set> |
30 | | #include <queue> |
31 | | #include <sys/time.h> |
32 | | |
33 | | // Forward Declarations |
34 | | class CAuthBase; |
35 | | class CChan; |
36 | | class CQuery; |
37 | | class CIRCNetwork; |
38 | | class CClient; |
39 | | class CWebSock; |
40 | | class CTemplate; |
41 | | class CIRCSock; |
42 | | class CModule; |
43 | | class CModInfo; |
44 | | // !Forward Declarations |
45 | | |
46 | | #ifdef REQUIRESSL |
47 | | #ifndef HAVE_LIBSSL |
48 | | #error - |
49 | | #error - |
50 | | #error This module only works when ZNC is compiled with OpenSSL support |
51 | | #error - |
52 | | #error - |
53 | | #endif |
54 | | #endif |
55 | | |
56 | | #ifdef BUILD_WITH_CMAKE |
57 | | #include <znc/znc_export_lib_export.h> |
58 | | #elif HAVE_VISIBILITY |
59 | | #define ZNC_EXPORT_LIB_EXPORT __attribute__((__visibility__("default"))) |
60 | | #else |
61 | | #define ZNC_EXPORT_LIB_EXPORT |
62 | | #endif |
63 | | |
64 | | /** C-style entry point to the module. |
65 | | * |
66 | | * First, core compares C strings with version and compilation options of core |
67 | | * and module. If they match, assume that C++ classes have the same layout and |
68 | | * proceed to filling CModInfo. |
69 | | * |
70 | | * Most parts of version-extra is explicitly not compared, otherwise all |
71 | | * modules need to be rebuilt for every commit, which is more cumbersome for |
72 | | * ZNC developers. However, the part set by user (e.g. +deb1), is compared. |
73 | | * |
74 | | * If this struct ever changes, the first field (pcVersion) must stay the same. |
75 | | * Otherwise, name of ZNCModuleEntry function must also change. Other fields |
76 | | * can change at will. |
77 | | * |
78 | | * Modules shouldn't care about this struct, it's all managed by ...MODULEDEFS |
79 | | * macro. |
80 | | */ |
81 | | struct CModuleEntry { |
82 | | const char* pcVersion; |
83 | | const char* pcVersionExtra; |
84 | | const char* pcCompileOptions; |
85 | | void (*fpFillModInfo)(CModInfo&); |
86 | | }; |
87 | | |
88 | | #define MODCOMMONDEFS(CLASS, DESCRIPTION, TYPE) \ |
89 | | static void FillModInfo(CModInfo& Info) { \ |
90 | | auto t_s = [&](const CString& sEnglish, \ |
91 | | const CString& sContext = "") { \ |
92 | | return sEnglish.empty() ? "" : Info.t_s(sEnglish, sContext); \ |
93 | | }; \ |
94 | | t_s(CString()); /* Don't warn about unused t_s */ \ |
95 | | Info.SetDescription(DESCRIPTION); \ |
96 | | Info.SetDefaultType(TYPE); \ |
97 | | Info.AddType(TYPE); \ |
98 | | Info.SetLoader(TModLoad<CLASS>); \ |
99 | | TModInfo<CLASS>(Info); \ |
100 | | } \ |
101 | | extern "C" { \ |
102 | | /* A global variable leads to ODR violation when several modules are \ |
103 | | * loaded. But a static variable inside a function works. */ \ |
104 | | ZNC_EXPORT_LIB_EXPORT const CModuleEntry* ZNCModuleEntry(); \ |
105 | | ZNC_EXPORT_LIB_EXPORT const CModuleEntry* ZNCModuleEntry() { \ |
106 | | static const CModuleEntry ThisModule = {VERSION_STR, VERSION_EXTRA, \ |
107 | | ZNC_COMPILE_OPTIONS_STRING, \ |
108 | | FillModInfo}; \ |
109 | | return &ThisModule; \ |
110 | | } \ |
111 | | } |
112 | | |
113 | | /** Instead of writing a constructor, you should call this macro. It accepts all |
114 | | * the necessary arguments and passes them on to CModule's constructor. You |
115 | | * should assume that there are no arguments to the constructor. |
116 | | * |
117 | | * Usage: |
118 | | * \code |
119 | | * class MyModule : public CModule { |
120 | | * MODCONSTRUCTOR(MyModule) { |
121 | | * // Your own constructor's code here |
122 | | * } |
123 | | * } |
124 | | * \endcode |
125 | | * |
126 | | * @param CLASS The name of your module's class. |
127 | | */ |
128 | | #define MODCONSTRUCTOR(CLASS) \ |
129 | | CLASS(ModHandle pDLL, CUser* pUser, CIRCNetwork* pNetwork, \ |
130 | | const CString& sModName, const CString& sModPath, \ |
131 | | CModInfo::EModuleType eType) \ |
132 | | : CModule(pDLL, pUser, pNetwork, sModName, sModPath, eType) |
133 | | |
134 | | // User Module Macros |
135 | | /** This works exactly like MODULEDEFS, but for user modules. */ |
136 | | #define USERMODULEDEFS(CLASS, DESCRIPTION) \ |
137 | | MODCOMMONDEFS(CLASS, DESCRIPTION, CModInfo::UserModule) |
138 | | // !User Module Macros |
139 | | |
140 | | // Global Module Macros |
141 | | /** This works exactly like MODULEDEFS, but for global modules. */ |
142 | | #define GLOBALMODULEDEFS(CLASS, DESCRIPTION) \ |
143 | | MODCOMMONDEFS(CLASS, DESCRIPTION, CModInfo::GlobalModule) |
144 | | // !Global Module Macros |
145 | | |
146 | | // Network Module Macros |
147 | | /** This works exactly like MODULEDEFS, but for network modules. */ |
148 | | #define NETWORKMODULEDEFS(CLASS, DESCRIPTION) \ |
149 | | MODCOMMONDEFS(CLASS, DESCRIPTION, CModInfo::NetworkModule) |
150 | | // !Network Module Macros |
151 | | |
152 | | /** At the end of your source file, you must call this macro in global context. |
153 | | * It defines some static functions which ZNC needs to load this module. |
154 | | * By default the module will be a network module. |
155 | | * @param CLASS The name of your module's class. |
156 | | * @param DESCRIPTION A short description of your module. |
157 | | */ |
158 | | #define MODULEDEFS(CLASS, DESCRIPTION) NETWORKMODULEDEFS(CLASS, DESCRIPTION) |
159 | | |
160 | | // Forward Declarations |
161 | | class CZNC; |
162 | | class CUser; |
163 | | class CNick; |
164 | | class CChan; |
165 | | class CModule; |
166 | | class CFPTimer; |
167 | | class CSockManager; |
168 | | // !Forward Declarations |
169 | | |
170 | | class CCapability { |
171 | | public: |
172 | | virtual ~CCapability() = default; |
173 | 0 | virtual void OnServerChangedSupport(CIRCNetwork* pNetwork, bool bState) {} |
174 | 0 | virtual void OnClientChangedSupport(CClient* pClient, bool bState) {} |
175 | | |
176 | 0 | CModule* GetModule() { return m_pModule; } |
177 | 0 | void SetModule(CModule* p) { m_pModule = p; } |
178 | | |
179 | | protected: |
180 | | CModule* m_pModule = nullptr; |
181 | | }; |
182 | | |
183 | | class CTimer : public CCron { |
184 | | public: |
185 | | CTimer(CModule* pModule, unsigned int uInterval, unsigned int uCycles, |
186 | | const CString& sLabel, const CString& sDescription); |
187 | | |
188 | | virtual ~CTimer(); |
189 | | |
190 | | CTimer(const CTimer&) = delete; |
191 | | CTimer& operator=(const CTimer&) = delete; |
192 | | |
193 | | // Setters |
194 | | void SetModule(CModule* p); |
195 | | void SetDescription(const CString& s); |
196 | | // !Setters |
197 | | |
198 | | // Getters |
199 | | CModule* GetModule() const; |
200 | | const CString& GetDescription() const; |
201 | | // !Getters |
202 | | private: |
203 | | protected: |
204 | | CModule* m_pModule; |
205 | | CString m_sDescription; |
206 | | }; |
207 | | |
208 | | typedef void (*FPTimer_t)(CModule*, CFPTimer*); |
209 | | |
210 | | class CFPTimer : public CTimer { |
211 | | public: |
212 | | CFPTimer(CModule* pModule, unsigned int uInterval, unsigned int uCycles, |
213 | | const CString& sLabel, const CString& sDescription) |
214 | 0 | : CTimer(pModule, uInterval, uCycles, sLabel, sDescription), |
215 | 0 | m_pFBCallback(nullptr) {} |
216 | | |
217 | 0 | virtual ~CFPTimer() {} |
218 | | |
219 | 0 | void SetFPCallback(FPTimer_t p) { m_pFBCallback = p; } |
220 | | |
221 | | protected: |
222 | 0 | void RunJob() override { |
223 | 0 | if (m_pFBCallback) { |
224 | 0 | m_pFBCallback(m_pModule, this); |
225 | 0 | } |
226 | 0 | } |
227 | | |
228 | | private: |
229 | | FPTimer_t m_pFBCallback; |
230 | | }; |
231 | | |
232 | | #ifdef HAVE_PTHREAD |
233 | | /// A CJob version which can be safely used in modules. The job will be |
234 | | /// cancelled when the module is unloaded. |
235 | | class CModuleJob : public CJob { |
236 | | public: |
237 | | CModuleJob(CModule* pModule, const CString& sName, const CString& sDesc) |
238 | 0 | : CJob(), m_pModule(pModule), m_sName(sName), m_sDescription(sDesc) {} |
239 | | virtual ~CModuleJob(); |
240 | | |
241 | | CModuleJob(const CModuleJob&) = delete; |
242 | | CModuleJob& operator=(const CModuleJob&) = delete; |
243 | | |
244 | | // Getters |
245 | 0 | CModule* GetModule() const { return m_pModule; } |
246 | 0 | const CString& GetName() const { return m_sName; } |
247 | 0 | const CString& GetDescription() const { return m_sDescription; } |
248 | | // !Getters |
249 | | |
250 | | protected: |
251 | | CModule* m_pModule; |
252 | | const CString m_sName; |
253 | | const CString m_sDescription; |
254 | | }; |
255 | | #endif |
256 | | |
257 | | typedef void* ModHandle; |
258 | | |
259 | | class CModInfo { |
260 | | public: |
261 | | typedef enum { GlobalModule, UserModule, NetworkModule } EModuleType; |
262 | | |
263 | | typedef CModule* (*ModLoader)(ModHandle p, CUser* pUser, |
264 | | CIRCNetwork* pNetwork, |
265 | | const CString& sModName, |
266 | | const CString& sModPath, EModuleType eType); |
267 | | |
268 | 0 | CModInfo() : CModInfo("", "", NetworkModule) {} |
269 | | CModInfo(const CString& sName, const CString& sPath, EModuleType eType) |
270 | 0 | : m_seType(), |
271 | 0 | m_eDefaultType(eType), |
272 | 0 | m_sName(sName), |
273 | 0 | m_sPath(sPath), |
274 | 0 | m_sDescription(""), |
275 | 0 | m_sWikiPage(""), |
276 | 0 | m_sArgsHelpText(""), |
277 | 0 | m_bHasArgs(false), |
278 | 0 | m_fLoader(nullptr) {} |
279 | 0 | ~CModInfo() {} |
280 | | |
281 | 0 | bool operator<(const CModInfo& Info) const { |
282 | 0 | return (GetName() < Info.GetName()); |
283 | 0 | } |
284 | | |
285 | 0 | bool SupportsType(EModuleType eType) const { |
286 | 0 | return m_seType.find(eType) != m_seType.end(); |
287 | 0 | } |
288 | | |
289 | 0 | void AddType(EModuleType eType) { m_seType.insert(eType); } |
290 | | |
291 | 0 | static CString ModuleTypeToString(EModuleType eType) { |
292 | 0 | switch (eType) { |
293 | 0 | case GlobalModule: |
294 | 0 | return "Global"; |
295 | 0 | case UserModule: |
296 | 0 | return "User"; |
297 | 0 | case NetworkModule: |
298 | 0 | return "Network"; |
299 | 0 | default: |
300 | 0 | return "UNKNOWN"; |
301 | 0 | } |
302 | 0 | } |
303 | | |
304 | | // Getters |
305 | 0 | const CString& GetName() const { return m_sName; } |
306 | 0 | const CString& GetPath() const { return m_sPath; } |
307 | 0 | const CString& GetDescription() const { return m_sDescription; } |
308 | 0 | const CString& GetWikiPage() const { return m_sWikiPage; } |
309 | 0 | const CString& GetArgsHelpText() const { return m_sArgsHelpText; } |
310 | 0 | bool GetHasArgs() const { return m_bHasArgs; } |
311 | 0 | ModLoader GetLoader() const { return m_fLoader; } |
312 | 0 | EModuleType GetDefaultType() const { return m_eDefaultType; } |
313 | | // !Getters |
314 | | |
315 | | // Setters |
316 | 0 | void SetName(const CString& s) { m_sName = s; } |
317 | 0 | void SetPath(const CString& s) { m_sPath = s; } |
318 | 0 | void SetDescription(const CString& s) { m_sDescription = s; } |
319 | 0 | void SetWikiPage(const CString& s) { m_sWikiPage = s; } |
320 | 0 | void SetArgsHelpText(const CString& s) { m_sArgsHelpText = s; } |
321 | 0 | void SetHasArgs(bool b = false) { m_bHasArgs = b; } |
322 | 0 | void SetLoader(ModLoader fLoader) { m_fLoader = fLoader; } |
323 | 0 | void SetDefaultType(EModuleType eType) { m_eDefaultType = eType; } |
324 | | // !Setters |
325 | | |
326 | | CString t_s(const CString& sEnglish, const CString& sContext = "") const; |
327 | | |
328 | | private: |
329 | | protected: |
330 | | std::set<EModuleType> m_seType; |
331 | | EModuleType m_eDefaultType; |
332 | | CString m_sName; |
333 | | CString m_sPath; |
334 | | CString m_sDescription; |
335 | | CString m_sWikiPage; |
336 | | CString m_sArgsHelpText; |
337 | | bool m_bHasArgs; |
338 | | ModLoader m_fLoader; |
339 | | }; |
340 | | |
341 | | template <class M> |
342 | | void TModInfo(CModInfo& Info) {} |
343 | | |
344 | | template <class M> |
345 | | CModule* TModLoad(ModHandle p, CUser* pUser, CIRCNetwork* pNetwork, |
346 | | const CString& sModName, const CString& sModPath, |
347 | | CModInfo::EModuleType eType) { |
348 | | return new M(p, pUser, pNetwork, sModName, sModPath, eType); |
349 | | } |
350 | | |
351 | | /** A helper class for handling commands in modules. */ |
352 | | class CModCommand : private CCoreTranslationMixin { |
353 | | public: |
354 | | /// Type for the callback function that handles the actual command. |
355 | | typedef void (CModule::*ModCmdFunc)(const CString& sLine); |
356 | | typedef std::function<void(const CString& sLine)> CmdFunc; |
357 | | |
358 | | /// Default constructor, needed so that this can be saved in a std::map. |
359 | | CModCommand(); |
360 | | |
361 | | /** Construct a new CModCommand. |
362 | | * @param sCmd The name of the command. |
363 | | * @param func The command's callback function. |
364 | | * @param sArgs Help text describing the arguments to this command. |
365 | | * @param sDesc Help text describing what this command does. |
366 | | */ |
367 | | CModCommand(const CString& sCmd, CModule* pMod, ModCmdFunc func, |
368 | | const CString& sArgs, const CString& sDesc); |
369 | | CModCommand(const CString& sCmd, CmdFunc func, |
370 | | const COptionalTranslation& Args, |
371 | | const COptionalTranslation& Desc); |
372 | | |
373 | | /** Copy constructor, needed so that this can be saved in a std::map. |
374 | | * @param other Object to copy from. |
375 | | */ |
376 | | CModCommand(const CModCommand& other) = default; |
377 | | |
378 | | /** Assignment operator, needed so that this can be saved in a std::map. |
379 | | * @param other Object to copy from. |
380 | | */ |
381 | 0 | CModCommand& operator=(const CModCommand& other) = default; |
382 | | |
383 | | /** Initialize a CTable so that it can be used with AddHelp(). |
384 | | * @param Table The instance of CTable to initialize. |
385 | | */ |
386 | | static void InitHelp(CTable& Table); |
387 | | |
388 | | /** Add this command to the CTable instance. |
389 | | * @param Table Instance of CTable to which this should be added. |
390 | | * @warning The Table should be initialized via InitHelp(). |
391 | | */ |
392 | | void AddHelp(CTable& Table) const; |
393 | | |
394 | 0 | const CString& GetCommand() const { return m_sCmd; } |
395 | 0 | CmdFunc GetFunction() const { return m_pFunc; } |
396 | 0 | CString GetArgs() const { return m_Args.Resolve(); } |
397 | 0 | CString GetDescription() const { return m_Desc.Resolve(); } |
398 | | |
399 | 0 | void Call(const CString& sLine) const { m_pFunc(sLine); } |
400 | | |
401 | | private: |
402 | | CString m_sCmd; |
403 | | CmdFunc m_pFunc; |
404 | | COptionalTranslation m_Args; |
405 | | COptionalTranslation m_Desc; |
406 | | }; |
407 | | |
408 | | /** The base class for your own ZNC modules. |
409 | | * |
410 | | * If you want to write a module for ZNC, you will have to implement a class |
411 | | * which inherits from this class. You should override some of the "On*" |
412 | | * functions in this class. These function will then be called by ZNC when the |
413 | | * associated event happens. |
414 | | * |
415 | | * If such a module hook is called with a non-const reference to e.g. a |
416 | | * CString, then it is free to modify that argument to influence ZNC's |
417 | | * behavior. |
418 | | * |
419 | | * @see MODCONSTRUCTOR and MODULEDEFS |
420 | | */ |
421 | | class CModule { |
422 | | public: |
423 | | CModule( |
424 | | ModHandle pDLL, CUser* pUser, CIRCNetwork* pNetwork, |
425 | | const CString& sModName, const CString& sDataDir, |
426 | | CModInfo::EModuleType eType = |
427 | | CModInfo::NetworkModule); // TODO: remove default value in ZNC 2.x |
428 | | virtual ~CModule(); |
429 | | |
430 | | CModule(const CModule&) = delete; |
431 | | CModule& operator=(const CModule&) = delete; |
432 | | |
433 | | /** This enum is just used for return from module hooks. Based on this |
434 | | * return, ZNC then decides what to do with the event which caused the |
435 | | * module hook. |
436 | | */ |
437 | | typedef enum { |
438 | | /** ZNC will continue event processing normally. This is what |
439 | | * you should return normally. |
440 | | */ |
441 | | CONTINUE = 1, |
442 | | /** This is the same as both CModule::HALTMODS and |
443 | | * CModule::HALTCORE together. |
444 | | */ |
445 | | HALT = 2, |
446 | | /** Stop sending this even to other modules which were not |
447 | | * called yet. Internally, the event is handled normally. |
448 | | */ |
449 | | HALTMODS = 3, |
450 | | /** Continue calling other modules. When done, ignore the event |
451 | | * in the ZNC core. (For most module hooks this means that a |
452 | | * given event won't be forwarded to the connected users) |
453 | | */ |
454 | | HALTCORE = 4 |
455 | | } EModRet; |
456 | | |
457 | | typedef enum { |
458 | | /** Your module can throw this enum at any given time. When this |
459 | | * is thrown, the module will be unloaded. |
460 | | */ |
461 | | UNLOAD |
462 | | } EModException; |
463 | | |
464 | | void SetUser(CUser* pUser); |
465 | | void SetNetwork(CIRCNetwork* pNetwork); |
466 | | void SetClient(CClient* pClient); |
467 | | |
468 | | /** This function throws CModule::UNLOAD which causes this module to be unloaded. |
469 | | */ |
470 | 0 | void Unload() { throw UNLOAD; } |
471 | | |
472 | | /** This module hook is called when a module is loaded |
473 | | * @param sArgsi The arguments for the modules. |
474 | | * @param sMessage A message that may be displayed to the user after |
475 | | * loading the module. Useful for returning error messages. |
476 | | * @return true if the module loaded successfully, else false. |
477 | | */ |
478 | | virtual bool OnLoad(const CString& sArgsi, CString& sMessage); |
479 | | /** This module hook is called during ZNC startup. Only modules loaded |
480 | | * from znc.conf get this call. |
481 | | * @return false to abort ZNC startup. |
482 | | */ |
483 | | virtual bool OnBoot(); |
484 | | |
485 | | /** Modules which can only be used with an active user session have to return true here. |
486 | | * @return false for modules that can do stuff for non-logged in web users as well. |
487 | | */ |
488 | 0 | virtual bool WebRequiresLogin() { return true; } |
489 | | /** Return true if this module should only be usable for admins on the web. |
490 | | * @return false if normal users can use this module's web pages as well. |
491 | | */ |
492 | 0 | virtual bool WebRequiresAdmin() { return false; } |
493 | | /** Return the title of the module's section in the web interface's side bar. |
494 | | * @return The Title. |
495 | | */ |
496 | 0 | virtual CString GetWebMenuTitle() { return ""; } |
497 | | virtual CString GetWebPath(); |
498 | | virtual CString GetWebFilesPath(); |
499 | | /** For WebMods: Called before the list of registered SubPages will be checked. |
500 | | * Important: If you return true, you need to take care of calling WebSock.Close! |
501 | | * This allows for stuff like returning non-templated data, long-polling and other fun. |
502 | | * @param WebSock The active request. |
503 | | * @param sPageName The name of the page that has been requested. |
504 | | * @return true if you handled the page request or false if the name is to be checked |
505 | | * against the list of registered SubPages and their permission settings. |
506 | | */ |
507 | | virtual bool OnWebPreRequest(CWebSock& WebSock, const CString& sPageName); |
508 | | /** If OnWebPreRequest returned false, and the RequiresAdmin/IsAdmin check has been passed, |
509 | | * this method will be called with the page name. It will also be called for pages that |
510 | | * have NOT been specifically registered with AddSubPage. |
511 | | * @param WebSock The active request. |
512 | | * @param sPageName The name of the page that has been requested. |
513 | | * @param Tmpl The active template. You can add variables, loops and stuff to it. |
514 | | * @return You MUST return true if you want the template to be evaluated and sent to the browser. |
515 | | * Return false if you called Redirect() or PrintErrorPage(). If you didn't, a 404 page will be sent. |
516 | | */ |
517 | | virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, |
518 | | CTemplate& Tmpl); |
519 | | /** If ValidateWebRequestCSRFCheck returned false, a CSRF error will be printed. |
520 | | * @param WebSock The active request. |
521 | | * @param sPageName The name of the page that has been requested. |
522 | | * @return You MUST return true if the CSRF token is valid. |
523 | | */ |
524 | | virtual bool ValidateWebRequestCSRFCheck(CWebSock& WebSock, const CString& sPageName); |
525 | | /** Registers a sub page for the sidebar. |
526 | | * @param spSubPage The SubPage instance. |
527 | | */ |
528 | 0 | virtual void AddSubPage(TWebSubPage spSubPage) { |
529 | 0 | m_vSubPages.push_back(spSubPage); |
530 | 0 | } |
531 | | /** Removes all registered (AddSubPage'd) SubPages. |
532 | | */ |
533 | 0 | virtual void ClearSubPages() { m_vSubPages.clear(); } |
534 | | /** Returns a list of all registered SubPages. Don't mess with it too much. |
535 | | * @return The List. |
536 | | */ |
537 | 0 | virtual VWebSubPages& GetSubPages() { return m_vSubPages; } |
538 | | /** Using this hook, module can embed web stuff directly to different places. |
539 | | * This method is called whenever embededded modules I/O happens. |
540 | | * Name of used .tmpl file (if any) is up to caller. |
541 | | * @param WebSock Socket for web connection, don't do bad things with it. |
542 | | * @param sPageName Describes the place where web stuff is embedded to. |
543 | | * @param Tmpl Template. Depending on context, you can do various stuff with it. |
544 | | * @return If you don't need to embed web stuff to the specified place, just return false. |
545 | | * Exact meaning of return value is up to caller, and depends on context. |
546 | | */ |
547 | | virtual bool OnEmbeddedWebRequest(CWebSock& WebSock, |
548 | | const CString& sPageName, |
549 | | CTemplate& Tmpl); |
550 | | |
551 | | /** Called just before znc.conf is rehashed */ |
552 | | virtual void OnPreRehash(); |
553 | | /** This module hook is called after a <em>successful</em> rehash. */ |
554 | | virtual void OnPostRehash(); |
555 | | /** This module hook is called when a user gets disconnected from IRC. */ |
556 | | virtual void OnIRCDisconnected(); |
557 | | /** This module hook is called after a successful login to IRC. */ |
558 | | virtual void OnIRCConnected(); |
559 | | /** This module hook is called just before ZNC tries to establish a |
560 | | * connection to an IRC server. |
561 | | * @param pIRCSock The socket that will be used for the connection. |
562 | | * @return See CModule::EModRet. |
563 | | */ |
564 | | virtual EModRet OnIRCConnecting(CIRCSock* pIRCSock); |
565 | | /** This module hook is called when a CIRCSock fails to connect or |
566 | | * a module returned HALTCORE from OnIRCConnecting. |
567 | | * @param pIRCSock The socket that failed to connect. |
568 | | */ |
569 | | virtual void OnIRCConnectionError(CIRCSock* pIRCSock); |
570 | | /** This module hook is called before loging in to the IRC server. The |
571 | | * low-level connection is established at this point, but SSL |
572 | | * handshakes didn't necessarily finish yet. |
573 | | * @param sPass The server password that will be used. |
574 | | * @param sNick The nick that will be used. |
575 | | * @param sIdent The protocol identity that will be used. This is not |
576 | | * the ident string that is transferred via e.g. oidentd! |
577 | | * @param sRealName The real name that will be used. |
578 | | * @return See CModule::EModRet. |
579 | | */ |
580 | | virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, |
581 | | CString& sIdent, CString& sRealName); |
582 | | /** This module hook is called when a message is broadcasted to all users. |
583 | | * @param sMessage The message that is broadcasted. |
584 | | * @return see CModule::EModRet |
585 | | */ |
586 | | virtual EModRet OnBroadcast(CString& sMessage); |
587 | | |
588 | | /** This module hook is called when a user mode on a channel changes. |
589 | | * @param pOpNick The nick who sent the mode change, or nullptr if set by server. |
590 | | * @param Nick The nick whose channel mode changes. |
591 | | * @param Channel The channel on which the user mode is changed. |
592 | | * @param cMode The mode character that is changed, e.g. '@' for op. |
593 | | * @param bAdded True if the mode is added, else false. |
594 | | * @param bNoChange true if this mode change doesn't change anything |
595 | | * because the nick already had this permission. |
596 | | * @see CIRCSock::GetModeType() for converting uMode into a mode (e.g. |
597 | | * 'o' for op). |
598 | | */ |
599 | | virtual void OnChanPermission3(const CNick* pOpNick, const CNick& Nick, |
600 | | CChan& Channel, char cMode, |
601 | | bool bAdded, bool bNoChange); |
602 | | /// @deprecated. Use OnChanPermission3. |
603 | | virtual void OnChanPermission2(const CNick* pOpNick, const CNick& Nick, |
604 | | CChan& Channel, unsigned char uMode, |
605 | | bool bAdded, bool bNoChange); |
606 | | /// @deprecated. Use OnChanPermission3. |
607 | | virtual void OnChanPermission(const CNick& OpNick, const CNick& Nick, |
608 | | CChan& Channel, unsigned char uMode, |
609 | | bool bAdded, bool bNoChange); |
610 | | /** Called when a nick is opped on a channel */ |
611 | | virtual void OnOp2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, |
612 | | bool bNoChange); |
613 | | virtual void OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
614 | | bool bNoChange); |
615 | | /** Called when a nick is deopped on a channel */ |
616 | | virtual void OnDeop2(const CNick* pOpNick, const CNick& Nick, |
617 | | CChan& Channel, bool bNoChange); |
618 | | virtual void OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
619 | | bool bNoChange); |
620 | | /** Called when a nick is voiced on a channel */ |
621 | | virtual void OnVoice2(const CNick* pOpNick, const CNick& Nick, |
622 | | CChan& Channel, bool bNoChange); |
623 | | virtual void OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
624 | | bool bNoChange); |
625 | | /** Called when a nick is devoiced on a channel */ |
626 | | virtual void OnDevoice2(const CNick* pOpNick, const CNick& Nick, |
627 | | CChan& Channel, bool bNoChange); |
628 | | virtual void OnDevoice(const CNick& OpNick, const CNick& Nick, |
629 | | CChan& Channel, bool bNoChange); |
630 | | /** Called on an individual channel mode change. |
631 | | * @param pOpNick The nick who changes the channel mode, or nullptr if set by server. |
632 | | * @param Channel The channel whose mode is changed. |
633 | | * @param uMode The mode character that is changed. |
634 | | * @param sArg The argument to the mode character, if any. |
635 | | * @param bAdded True if this mode is added ("+"), else false. |
636 | | * @param bNoChange True if this mode was already effective before. |
637 | | */ |
638 | | virtual void OnMode2(const CNick* pOpNick, CChan& Channel, char uMode, |
639 | | const CString& sArg, bool bAdded, bool bNoChange); |
640 | | virtual void OnMode(const CNick& OpNick, CChan& Channel, char uMode, |
641 | | const CString& sArg, bool bAdded, bool bNoChange); |
642 | | /** Called on any channel mode change. This is called before the more |
643 | | * detailed mode hooks like e.g. OnOp() and OnMode(). |
644 | | * @param pOpNick The nick who changes the channel mode, or nullptr if set by server. |
645 | | * @param Channel The channel whose mode is changed. |
646 | | * @param sModes The raw mode change, e.g. "+s-io". |
647 | | * @param sArgs All arguments to the mode change from sModes. |
648 | | */ |
649 | | virtual void OnRawMode2(const CNick* pOpNick, CChan& Channel, |
650 | | const CString& sModes, const CString& sArgs); |
651 | | virtual void OnRawMode(const CNick& OpNick, CChan& Channel, |
652 | | const CString& sModes, const CString& sArgs); |
653 | | |
654 | | /** Called on any raw IRC line received from the <em>IRC server</em>. |
655 | | * @param sLine The line read from the server. |
656 | | * @note The line does not include message tags. Use OnRawMessage() to access them. |
657 | | * @return See CModule::EModRet. |
658 | | */ |
659 | | virtual EModRet OnRaw(CString& sLine); |
660 | | /** Called on any raw message received from the <em>IRC server</em>. |
661 | | * @since 1.7.0 |
662 | | * @param Message The received message. |
663 | | * @return See CModule::EModRet. |
664 | | */ |
665 | | virtual EModRet OnRawMessage(CMessage& Message); |
666 | | |
667 | | /** Called when a numeric message is received from the <em>IRC server</em>. |
668 | | * @since 1.7.0 |
669 | | * @param Message The received message. |
670 | | * @return See CModule::EModRet. |
671 | | */ |
672 | | virtual EModRet OnNumericMessage(CNumericMessage& Message); |
673 | | |
674 | | /** Called when a command to *status is sent. |
675 | | * @param sCommand The command sent. |
676 | | * @return See CModule::EModRet. |
677 | | */ |
678 | | virtual EModRet OnStatusCommand(CString& sCommand); |
679 | | /** Called when a command to your module is sent, e.g. query to *modname. |
680 | | * @param sCommand The command that was sent. |
681 | | */ |
682 | | virtual void OnModCommand(const CString& sCommand); |
683 | | /** This is similar to OnModCommand(), but it is only called if |
684 | | * HandleCommand didn't find any that wants to handle this. This is only |
685 | | * called if HandleCommand() is called, which practically means that |
686 | | * this is only called if you don't overload OnModCommand(). |
687 | | * @param sCommand The command that was sent. |
688 | | */ |
689 | | virtual void OnUnknownModCommand(const CString& sCommand); |
690 | | /** Called when a your module nick was sent a notice. |
691 | | * @param sMessage The message which was sent. |
692 | | */ |
693 | | virtual void OnModNotice(const CString& sMessage); |
694 | | /** Called when your module nick was sent a CTCP message. OnModCommand() |
695 | | * won't be called for this message. |
696 | | * @param sMessage The message which was sent. |
697 | | */ |
698 | | virtual void OnModCTCP(const CString& sMessage); |
699 | | |
700 | | /** Called when a nick quit from IRC. |
701 | | * @since 1.7.0 |
702 | | * @param Message The quit message. |
703 | | * @param vChans List of channels which you and nick share. |
704 | | */ |
705 | | virtual void OnQuitMessage(CQuitMessage& Message, |
706 | | const std::vector<CChan*>& vChans); |
707 | | /// @deprecated Use OnQuitMessage() instead. |
708 | | virtual void OnQuit(const CNick& Nick, const CString& sMessage, |
709 | | const std::vector<CChan*>& vChans); |
710 | | |
711 | | /** Called when a nickname change occurs. |
712 | | * @since 1.7.0 |
713 | | * @param Message The nick message. |
714 | | * @param vChans Channels which we and nick share. |
715 | | */ |
716 | | virtual void OnNickMessage(CNickMessage& Message, |
717 | | const std::vector<CChan*>& vChans); |
718 | | /// @deprecated Use OnNickMessage() instead. |
719 | | virtual void OnNick(const CNick& Nick, const CString& sNewNick, |
720 | | const std::vector<CChan*>& vChans); |
721 | | |
722 | | /** Called when a nick is kicked from a channel. |
723 | | * @since 1.7.0 |
724 | | * @param Message The kick message. |
725 | | */ |
726 | | virtual void OnKickMessage(CKickMessage& Message); |
727 | | /// @deprecated Use OnKickMessage() instead. |
728 | | virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, |
729 | | CChan& Channel, const CString& sMessage); |
730 | | |
731 | | /** This module hook is called just before ZNC tries to join an IRC channel. |
732 | | * @param Chan The channel which is about to get joined. |
733 | | * @return See CModule::EModRet. |
734 | | */ |
735 | | virtual EModRet OnJoining(CChan& Channel); |
736 | | |
737 | | /** Called when a nick joins a channel. |
738 | | * @since 1.7.0 |
739 | | * @param Message The join message. |
740 | | */ |
741 | | virtual void OnJoinMessage(CJoinMessage& Message); |
742 | | /// @deprecated Use OnJoinMessage() instead. |
743 | | virtual void OnJoin(const CNick& Nick, CChan& Channel); |
744 | | |
745 | | /** Called when a nick parts a channel. |
746 | | * @since 1.7.0 |
747 | | * @param Message The part message. |
748 | | */ |
749 | | virtual void OnPartMessage(CPartMessage& Message); |
750 | | /// @deprecated Use OnPartMessage() instead. |
751 | | virtual void OnPart(const CNick& Nick, CChan& Channel, |
752 | | const CString& sMessage); |
753 | | |
754 | | /** Called when a user is invited to a channel. |
755 | | * That includes the case of `invite-notify`. |
756 | | * @since 1.10.0 |
757 | | * @param Message The message. |
758 | | */ |
759 | | virtual EModRet OnInviteMessage(CInviteMessage& Message); |
760 | | /** Called when user is invited into a channel. |
761 | | * @note even in case of `invite-notify` this is only called for "you" |
762 | | * being invited, as this function has no way to tell you whom is |
763 | | * invited instead. |
764 | | * @param Nick The nick who invited you. |
765 | | * @param sChan The channel the user got invited into |
766 | | * @return See CModule::EModRet. |
767 | | */ |
768 | | virtual EModRet OnInvite(const CNick& Nick, const CString& sChan); |
769 | | |
770 | | /** Called before a channel buffer is played back to a client. |
771 | | * @param Chan The channel which will be played back. |
772 | | * @param Client The client the buffer will be played back to. |
773 | | * @return See CModule::EModRet. |
774 | | */ |
775 | | virtual EModRet OnChanBufferStarting(CChan& Chan, CClient& Client); |
776 | | /** Called after a channel buffer was played back to a client. |
777 | | * @param Chan The channel which was played back. |
778 | | * @param Client The client the buffer was played back to. |
779 | | * @return See CModule::EModRet. |
780 | | */ |
781 | | virtual EModRet OnChanBufferEnding(CChan& Chan, CClient& Client); |
782 | | |
783 | | /** Called for each message during a channel's buffer play back. |
784 | | * @since 1.7.0 |
785 | | * @param Message The playback message. |
786 | | * @return See CModule::EModRet. |
787 | | */ |
788 | | virtual EModRet OnChanBufferPlayMessage(CMessage& Message); |
789 | | /// @deprecated Use OnChanBufferPlayMessage() instead. |
790 | | virtual EModRet OnChanBufferPlayLine2(CChan& Chan, CClient& Client, |
791 | | CString& sLine, const timeval& tv); |
792 | | /// @deprecated Use OnChanBufferPlayMessage() instead. |
793 | | virtual EModRet OnChanBufferPlayLine(CChan& Chan, CClient& Client, |
794 | | CString& sLine); |
795 | | |
796 | | /** Called before a query buffer is played back to a client. |
797 | | * @since 1.7.0 |
798 | | * @param Query The query which will be played back. |
799 | | * @param Client The client the buffer will be played back to. |
800 | | * @return See CModule::EModRet. |
801 | | */ |
802 | | virtual EModRet OnPrivBufferStarting(CQuery& Query, CClient& Client); |
803 | | /** Called after a query buffer was played back to a client. |
804 | | * @since 1.7.0 |
805 | | * @param Query The query which was played back. |
806 | | * @param Client The client the buffer was played back to. |
807 | | * @return See CModule::EModRet. |
808 | | */ |
809 | | virtual EModRet OnPrivBufferEnding(CQuery& Query, CClient& Client); |
810 | | |
811 | | /** Called for each message during a query's buffer play back. |
812 | | * @since 1.7.0 |
813 | | * @param Message The playback message. |
814 | | * @return See CModule::EModRet. |
815 | | */ |
816 | | virtual EModRet OnPrivBufferPlayMessage(CMessage& Message); |
817 | | /// @deprecated Use OnPrivBufferPlayMessage() instead. |
818 | | virtual EModRet OnPrivBufferPlayLine2(CClient& Client, CString& sLine, |
819 | | const timeval& tv); |
820 | | /// @deprecated Use OnPrivBufferPlayMessage() instead. |
821 | | virtual EModRet OnPrivBufferPlayLine(CClient& Client, CString& sLine); |
822 | | |
823 | | /** Called when a client successfully logged in to ZNC. */ |
824 | | virtual void OnClientLogin(); |
825 | | /** Called when a client disconnected from ZNC. */ |
826 | | virtual void OnClientDisconnect(); |
827 | | |
828 | | /** This module hook is called when a client sends a raw traffic line to ZNC. |
829 | | * @param sLine The raw traffic line sent. |
830 | | * @return See CModule::EModRet. |
831 | | */ |
832 | | virtual EModRet OnUserRaw(CString& sLine); |
833 | | /** This module hook is called when a client sends any message to ZNC. |
834 | | * @since 1.7.0 |
835 | | * @param Message The message sent. |
836 | | * @return See CModule::EModRet. |
837 | | */ |
838 | | virtual EModRet OnUserRawMessage(CMessage& Message); |
839 | | |
840 | | /** This module hook is called when a client sends a CTCP reply. |
841 | | * @since 1.7.0 |
842 | | * @param Message The CTCP reply message. |
843 | | * @return See CModule::EModRet. |
844 | | */ |
845 | | virtual EModRet OnUserCTCPReplyMessage(CCTCPMessage& Message); |
846 | | /// @deprecated Use OnUserCTCPReplyMessage() instead. |
847 | | virtual EModRet OnUserCTCPReply(CString& sTarget, CString& sMessage); |
848 | | |
849 | | /** This module hook is called when a client sends a CTCP request. |
850 | | * @since 1.7.0 |
851 | | * @param Message The CTCP request message. |
852 | | * @return See CModule::EModRet. |
853 | | * @note This is not called for CTCP ACTION messages, use |
854 | | * CModule::OnUserActionMessage() instead. |
855 | | */ |
856 | | virtual EModRet OnUserCTCPMessage(CCTCPMessage& Message); |
857 | | /// @deprecated Use OnUserCTCPMessage() instead. |
858 | | virtual EModRet OnUserCTCP(CString& sTarget, CString& sMessage); |
859 | | |
860 | | /** Called when a client sends a CTCP ACTION request ("/me"). |
861 | | * @since 1.7.0 |
862 | | * @param Message The action message. |
863 | | * @return See CModule::EModRet. |
864 | | * @note CModule::OnUserCTCPMessage() will not be called for this message. |
865 | | */ |
866 | | virtual EModRet OnUserActionMessage(CActionMessage& Message); |
867 | | /// @deprecated Use OnUserActionMessage() instead. |
868 | | virtual EModRet OnUserAction(CString& sTarget, CString& sMessage); |
869 | | |
870 | | /** This module hook is called when a user sends a PRIVMSG message. |
871 | | * @since 1.7.0 |
872 | | * @param Message The message which was sent. |
873 | | * @return See CModule::EModRet. |
874 | | */ |
875 | | virtual EModRet OnUserTextMessage(CTextMessage& Message); |
876 | | /// @deprecated Use OnUserTextMessage() instead. |
877 | | virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage); |
878 | | |
879 | | /** This module hook is called when a user sends a NOTICE message. |
880 | | * @since 1.7.0 |
881 | | * @param Message The message which was sent. |
882 | | * @return See CModule::EModRet. |
883 | | */ |
884 | | virtual EModRet OnUserNoticeMessage(CNoticeMessage& Message); |
885 | | /// @deprecated Use OnUserNoticeMessage() instead. |
886 | | virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage); |
887 | | |
888 | | /** This hooks is called when a user sends a JOIN message. |
889 | | * @since 1.7.0 |
890 | | * @param Message The join message. |
891 | | * @return See CModule::EModRet. |
892 | | */ |
893 | | virtual EModRet OnUserJoinMessage(CJoinMessage& Message); |
894 | | /// @deprecated Use OnUserJoinMessage() instead. |
895 | | virtual EModRet OnUserJoin(CString& sChannel, CString& sKey); |
896 | | |
897 | | /** This hooks is called when a user sends a PART message. |
898 | | * @since 1.7.0 |
899 | | * @param Message The part message. |
900 | | * @return See CModule::EModRet. |
901 | | */ |
902 | | virtual EModRet OnUserPartMessage(CPartMessage& Message); |
903 | | /// @deprecated Use OnUserPartMessage() instead. |
904 | | virtual EModRet OnUserPart(CString& sChannel, CString& sMessage); |
905 | | |
906 | | /** This module hook is called when a user wants to change a channel topic. |
907 | | * @since 1.7.0 |
908 | | * @param Message The topic message. |
909 | | * @return See CModule::EModRet. |
910 | | */ |
911 | | virtual EModRet OnUserTopicMessage(CTopicMessage& Message); |
912 | | /// @deprecated Use OnUserTopicMessage() instead. |
913 | | virtual EModRet OnUserTopic(CString& sChannel, CString& sTopic); |
914 | | |
915 | | /** This hook is called when a user requests a channel's topic. |
916 | | * @param sChannel The channel for which the request is. |
917 | | * @return See CModule::EModRet. |
918 | | */ |
919 | | virtual EModRet OnUserTopicRequest(CString& sChannel); |
920 | | |
921 | | /** This module hook is called when a client quits ZNC. |
922 | | * @since 1.7.0 |
923 | | * @param Message The quit message the client sent. |
924 | | * @return See CModule::EModRet. |
925 | | */ |
926 | | virtual EModRet OnUserQuitMessage(CQuitMessage& Message); |
927 | | /// @deprecated Use OnUserQuitMessage() instead. |
928 | | virtual EModRet OnUserQuit(CString& sMessage); |
929 | | |
930 | | /** Called when we receive a CTCP reply <em>from IRC</em>. |
931 | | * @since 1.7.0 |
932 | | * @param Message The CTCP reply message. |
933 | | * @return See CModule::EModRet. |
934 | | */ |
935 | | virtual EModRet OnCTCPReplyMessage(CCTCPMessage& Message); |
936 | | /// @deprecated Use OnCTCPReplyMessage() instead. |
937 | | virtual EModRet OnCTCPReply(CNick& Nick, CString& sMessage); |
938 | | |
939 | | /** Called when we receive a private CTCP request <em>from IRC</em>. |
940 | | * @since 1.7.0 |
941 | | * @param Message The CTCP request message. |
942 | | * @return See CModule::EModRet. |
943 | | */ |
944 | | virtual EModRet OnPrivCTCPMessage(CCTCPMessage& Message); |
945 | | /// @deprecated Use OnPrivCTCPMessage() instead. |
946 | | virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage); |
947 | | |
948 | | /** Called when we receive a channel CTCP request <em>from IRC</em>. |
949 | | * @since 1.7.0 |
950 | | * @param Message The CTCP request message. |
951 | | * @return See CModule::EModRet. |
952 | | */ |
953 | | virtual EModRet OnChanCTCPMessage(CCTCPMessage& Message); |
954 | | /// @deprecated Use OnChanCTCPMessage() instead. |
955 | | virtual EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage); |
956 | | |
957 | | /** Called when we receive a private CTCP ACTION ("/me" in query) <em>from IRC</em>. |
958 | | * @since 1.7.0 |
959 | | * @param Message The action message |
960 | | * @return See CModule::EModRet. |
961 | | */ |
962 | | virtual EModRet OnPrivActionMessage(CActionMessage& Message); |
963 | | /// @deprecated Use OnPrivActionMessage() instead. |
964 | | virtual EModRet OnPrivAction(CNick& Nick, CString& sMessage); |
965 | | |
966 | | /** Called when we receive a channel CTCP ACTION ("/me" in a channel) <em>from IRC</em>. |
967 | | * @since 1.7.0 |
968 | | * @param Message The action message |
969 | | * @return See CModule::EModRet. |
970 | | */ |
971 | | virtual EModRet OnChanActionMessage(CActionMessage& Message); |
972 | | /// @deprecated Use OnChanActionMessage() instead. |
973 | | virtual EModRet OnChanAction(CNick& Nick, CChan& Channel, |
974 | | CString& sMessage); |
975 | | |
976 | | /** Called when we receive a private PRIVMSG message <em>from IRC</em>. |
977 | | * @since 1.7.0 |
978 | | * @param Message The private message. |
979 | | * @return See CModule::EModRet. |
980 | | */ |
981 | | virtual EModRet OnPrivTextMessage(CTextMessage& Message); |
982 | | /// @deprecated Use OnPrivTextMessage() instead. |
983 | | virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage); |
984 | | |
985 | | /** Called when we receive a channel PRIVMSG message <em>from IRC</em>. |
986 | | * @since 1.7.0 |
987 | | * @param Message The channel message. |
988 | | * @return See CModule::EModRet. |
989 | | */ |
990 | | virtual EModRet OnChanTextMessage(CTextMessage& Message); |
991 | | /// @deprecated Use OnChanTextMessage() instead. |
992 | | virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage); |
993 | | |
994 | | /** Called when we receive a private NOTICE message <em>from IRC</em>. |
995 | | * @since 1.7.0 |
996 | | * @param Message The notice message. |
997 | | * @return See CModule::EModRet. |
998 | | */ |
999 | | virtual EModRet OnPrivNoticeMessage(CNoticeMessage& Message); |
1000 | | /// @deprecated Use OnPrivNoticeMessage() instead. |
1001 | | virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage); |
1002 | | |
1003 | | /** Called when we receive a channel NOTICE message <em>from IRC</em>. |
1004 | | * @since 1.7.0 |
1005 | | * @param Message The notice message. |
1006 | | * @return See CModule::EModRet. |
1007 | | */ |
1008 | | virtual EModRet OnChanNoticeMessage(CNoticeMessage& Message); |
1009 | | /// @deprecated Use OnChanNoticeMessage() instead. |
1010 | | virtual EModRet OnChanNotice(CNick& Nick, CChan& Channel, |
1011 | | CString& sMessage); |
1012 | | |
1013 | | /** Called when we receive a channel topic change <em>from IRC</em>. |
1014 | | * @since 1.7.0 |
1015 | | * @param Message The topic message. |
1016 | | * @return See CModule::EModRet. |
1017 | | */ |
1018 | | virtual EModRet OnTopicMessage(CTopicMessage& Message); |
1019 | | /// @deprecated Use OnTopicMessage() instead. |
1020 | | virtual EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic); |
1021 | | |
1022 | | /** Called for every CAP received via CAP LS from server. |
1023 | | * If you need to also advertise the cap to clients, use |
1024 | | * AddServerDependentCapability() instead. |
1025 | | * @param sCap capability supported by server. |
1026 | | * @return true if your module supports this CAP and |
1027 | | * needs to turn it on with CAP REQ. |
1028 | | */ |
1029 | | virtual bool OnServerCapAvailable(const CString& sCap); |
1030 | | /** Called for every CAP received via CAP LS from server. |
1031 | | * By default just calls OnServerCapAvailable() without sValue, so |
1032 | | * overriding one of the two is enough. |
1033 | | * If you need to also advertise the cap to clients, use |
1034 | | * AddServerDependentCapability() instead. |
1035 | | * @param sCap capability name supported by server. |
1036 | | * @param sValue value. |
1037 | | * @return true if your module supports this CAP and |
1038 | | * needs to turn it on with CAP REQ. |
1039 | | */ |
1040 | | virtual bool OnServerCap302Available(const CString& sCap, const CString& sValue); |
1041 | | /** Called for every CAP accepted or rejected by server |
1042 | | * (with CAP ACK or CAP NAK after our CAP REQ). |
1043 | | * If you need to also advertise the cap to clients, use |
1044 | | * AddServerDependentCapability() instead. |
1045 | | * @param sCap capability accepted/rejected by server. |
1046 | | * @param bSuccess true if capability was accepted, false if rejected. |
1047 | | */ |
1048 | | virtual void OnServerCapResult(const CString& sCap, bool bSuccess); |
1049 | | |
1050 | | /** This module hook is called just before ZNC tries to join a channel |
1051 | | * by itself because it's in the config but wasn't joined yet. |
1052 | | * @param Channel The channel which will be joined. |
1053 | | * @return See CModule::EModRet. |
1054 | | */ |
1055 | | virtual EModRet OnTimerAutoJoin(CChan& Channel); |
1056 | | |
1057 | | /** This module hook is called when a network is being added. |
1058 | | * @param Network The new IRC network. |
1059 | | * @param sErrorRet A message that may be displayed to the user if |
1060 | | * the module stops adding the network. |
1061 | | * @return See CModule::EModRet. |
1062 | | */ |
1063 | | virtual EModRet OnAddNetwork(CIRCNetwork& Network, CString& sErrorRet); |
1064 | | /** This module hook is called when a network is deleted. |
1065 | | * @param Network The IRC network which is going to be deleted. |
1066 | | * @return See CModule::EModRet. |
1067 | | */ |
1068 | | virtual EModRet OnDeleteNetwork(CIRCNetwork& Network); |
1069 | | |
1070 | | /** Called immediately before ZNC sends a raw traffic line to a client. |
1071 | | * @since 1.7.0 |
1072 | | * @param Message The message being sent to the client. |
1073 | | * @warning Calling PutUser() from within this hook leads to infinite recursion. |
1074 | | * @return See CModule::EModRet. |
1075 | | */ |
1076 | | virtual EModRet OnSendToClientMessage(CMessage& Message); |
1077 | | /// @deprecated Use OnSendToClientMessage() instead. |
1078 | | virtual EModRet OnSendToClient(CString& sLine, CClient& Client); |
1079 | | |
1080 | | /** Called immediately before ZNC sends a raw traffic line to the IRC server. |
1081 | | * @since 1.7.0 |
1082 | | * @param Message The message being sent to the IRC server. |
1083 | | * @warning Calling PutIRC() from within this hook leads to infinite recursion. |
1084 | | * @return See CModule::EModRet. |
1085 | | */ |
1086 | | virtual EModRet OnSendToIRCMessage(CMessage& Message); |
1087 | | /// @deprecated Use OnSendToIRCMessage() instead. |
1088 | | virtual EModRet OnSendToIRC(CString& sLine); |
1089 | | |
1090 | | /** This module hook is called when a user sends a TAGMSG message. |
1091 | | * @since 1.10.0 |
1092 | | * @param Message The message which was sent. |
1093 | | * @return See CModule::EModRet. |
1094 | | */ |
1095 | | virtual EModRet OnUserTagMessage(CTargetMessage& Message); |
1096 | | /** Called when we receive a channel TAGMSG message <em>from IRC</em>. |
1097 | | * @since 1.10.0 |
1098 | | * @param Message The channel message. |
1099 | | * @return See CModule::EModRet. |
1100 | | */ |
1101 | | virtual EModRet OnChanTagMessage(CTargetMessage& Message); |
1102 | | /** Called when we receive a private TAGMSG message <em>from IRC</em>. |
1103 | | * @since 1.10.0 |
1104 | | * @param Message The message. |
1105 | | * @return See CModule::EModRet. |
1106 | | */ |
1107 | | virtual EModRet OnPrivTagMessage(CTargetMessage& Message); |
1108 | | |
1109 | 0 | ModHandle GetDLL() { return m_pDLL; } |
1110 | | |
1111 | | /** This function sends a given IRC line to the IRC server, if we |
1112 | | * are connected to one. Else this line is discarded. |
1113 | | * @param sLine The line which should be sent. |
1114 | | * @return true if the line was queued for sending. |
1115 | | */ |
1116 | | virtual bool PutIRC(const CString& sLine); |
1117 | | /** This function sends a given IRC message to the IRC server, if we |
1118 | | * are connected to one. Else this message is discarded. |
1119 | | * @param Message The message which should be sent. |
1120 | | * @return true if the message was queued for sending. |
1121 | | */ |
1122 | | virtual bool PutIRC(const CMessage& Message); |
1123 | | /** This function sends a given raw IRC line to a client. |
1124 | | * If we are in a module hook which is called for a specific client, |
1125 | | * only that client will get the line, else all connected clients will |
1126 | | * receive this line. |
1127 | | * @param sLine The line which should be sent. |
1128 | | * @return true if the line was sent to at least one client. |
1129 | | */ |
1130 | | virtual bool PutUser(const CString& sLine); |
1131 | | /** This function generates a query from *status. If we are in a module |
1132 | | * hook for a specific client, only that client gets this message, else |
1133 | | * all connected clients will receive it. |
1134 | | * @param sLine The message which should be sent from *status. |
1135 | | * @return true if the line was sent to at least one client. |
1136 | | */ |
1137 | | virtual bool PutStatus(const CString& sLine); |
1138 | | /** This function sends a query from your module nick. If we are in a |
1139 | | * module hook for a specific client, only that client gets this |
1140 | | * message, else all connected clients will receive it. |
1141 | | * @param sLine The message which should be sent. |
1142 | | * @return true if the line was sent to at least one client. |
1143 | | */ |
1144 | | virtual bool PutModule(const CString& sLine); |
1145 | | /** This function calls CModule::PutModule(const CString&, const |
1146 | | * CString&, const CString&) for each line in the table. |
1147 | | * @param table The table which should be send. |
1148 | | * @return The number of lines sent. |
1149 | | */ |
1150 | | virtual unsigned int PutModule(const CTable& table); |
1151 | | /** Send a notice from your module nick. If we are in a module hook for |
1152 | | * a specific client, only that client gets this notice, else all |
1153 | | * clients will receive it. |
1154 | | * @param sLine The line which should be sent. |
1155 | | * @return true if the line was sent to at least one client. |
1156 | | */ |
1157 | | virtual bool PutModNotice(const CString& sLine); |
1158 | | |
1159 | | /** @returns The name of the module. */ |
1160 | 0 | const CString& GetModName() const { return m_sModName; } |
1161 | | |
1162 | | /** @returns The nick of the module. This is just the module name |
1163 | | * prefixed by the status prefix. |
1164 | | */ |
1165 | | CString GetModNick() const; |
1166 | | |
1167 | | /** Get the module's data dir. |
1168 | | * Modules can be accompanied by static data, e.g. skins for webadmin. |
1169 | | * These function will return the path to that data. |
1170 | | */ |
1171 | 0 | const CString& GetModDataDir() const { return m_sDataDir; } |
1172 | | |
1173 | | // Timer stuff |
1174 | | bool AddTimer(CTimer* pTimer); |
1175 | | bool AddTimer(FPTimer_t pFBCallback, const CString& sLabel, u_int uInterval, |
1176 | | u_int uCycles = 0, const CString& sDescription = ""); |
1177 | | bool RemTimer(CTimer* pTimer); |
1178 | | bool RemTimer(const CString& sLabel); |
1179 | | bool UnlinkTimer(CTimer* pTimer); |
1180 | | CTimer* FindTimer(const CString& sLabel); |
1181 | 0 | std::set<CTimer*>::const_iterator BeginTimers() const { |
1182 | 0 | return m_sTimers.begin(); |
1183 | 0 | } |
1184 | 0 | std::set<CTimer*>::const_iterator EndTimers() const { |
1185 | 0 | return m_sTimers.end(); |
1186 | 0 | } |
1187 | | virtual void ListTimers(); |
1188 | | // !Timer stuff |
1189 | | |
1190 | | // Socket stuff |
1191 | | bool AddSocket(CSocket* pSocket); |
1192 | | bool RemSocket(CSocket* pSocket); |
1193 | | bool RemSocket(const CString& sSockName); |
1194 | | bool UnlinkSocket(CSocket* pSocket); |
1195 | | CSocket* FindSocket(const CString& sSockName); |
1196 | 0 | std::set<CSocket*>::const_iterator BeginSockets() const { |
1197 | 0 | return m_sSockets.begin(); |
1198 | 0 | } |
1199 | 0 | std::set<CSocket*>::const_iterator EndSockets() const { |
1200 | 0 | return m_sSockets.end(); |
1201 | 0 | } |
1202 | | virtual void ListSockets(); |
1203 | | // !Socket stuff |
1204 | | |
1205 | | #ifdef HAVE_PTHREAD |
1206 | | // Job stuff |
1207 | | void AddJob(CModuleJob* pJob); |
1208 | | void CancelJob(CModuleJob* pJob); |
1209 | | bool CancelJob(const CString& sJobName); |
1210 | | void CancelJobs(const std::set<CModuleJob*>& sJobs); |
1211 | | bool UnlinkJob(CModuleJob* pJob); |
1212 | | // !Job stuff |
1213 | | #endif |
1214 | | |
1215 | | // Command stuff |
1216 | | /// Register the "Help" command. |
1217 | | void AddHelpCommand(); |
1218 | | /// @return True if the command was successfully added. |
1219 | | bool AddCommand(const CModCommand& Command); |
1220 | | /// @return True if the command was successfully added. |
1221 | | /// @deprecated Use the variant with COptionalTranslation. |
1222 | | bool AddCommand(const CString& sCmd, CModCommand::ModCmdFunc func, |
1223 | | const CString& sArgs = "", const CString& sDesc = ""); |
1224 | | /// @param dDesc Either a string "", or the result of t_d() |
1225 | | /// @return True if the command was successfully added. |
1226 | | bool AddCommand(const CString& sCmd, const COptionalTranslation& Args, |
1227 | | const COptionalTranslation& Desc, |
1228 | | std::function<void(const CString& sLine)> func); |
1229 | | /// @return True if the command was successfully removed. |
1230 | | bool RemCommand(const CString& sCmd); |
1231 | | /// @return The CModCommand instance or nullptr if none was found. |
1232 | | const CModCommand* FindCommand(const CString& sCmd) const; |
1233 | | /** This function tries to dispatch the given command via the correct |
1234 | | * instance of CModCommand. Before this can be called, commands have to |
1235 | | * be added via AddCommand(). If no matching commands are found then |
1236 | | * OnUnknownModCommand will be called. |
1237 | | * @param sLine The command line to handle. |
1238 | | * @return True if something was done, else false. |
1239 | | */ |
1240 | | bool HandleCommand(const CString& sLine); |
1241 | | /** Send a description of all registered commands via PutModule(). |
1242 | | * @param sLine The help command that is being asked for. |
1243 | | */ |
1244 | | void HandleHelpCommand(const CString& sLine = ""); |
1245 | | // !Command stuff |
1246 | | |
1247 | | bool LoadRegistry(); |
1248 | | bool SaveRegistry() const; |
1249 | | bool MoveRegistry(const CString& sPath); |
1250 | | bool SetNV(const CString& sName, const CString& sValue, |
1251 | | bool bWriteToDisk = true); |
1252 | | CString GetNV(const CString& sName) const; |
1253 | 0 | bool HasNV(const CString& sName) const { |
1254 | 0 | return m_mssRegistry.find(sName) != m_mssRegistry.end(); |
1255 | 0 | } |
1256 | | bool DelNV(const CString& sName, bool bWriteToDisk = true); |
1257 | 0 | MCString::iterator FindNV(const CString& sName) { |
1258 | 0 | return m_mssRegistry.find(sName); |
1259 | 0 | } |
1260 | 0 | MCString::iterator EndNV() { return m_mssRegistry.end(); } |
1261 | 0 | MCString::iterator BeginNV() { return m_mssRegistry.begin(); } |
1262 | 0 | void DelNV(MCString::iterator it) { m_mssRegistry.erase(it); } |
1263 | | bool ClearNV(bool bWriteToDisk = true); |
1264 | | |
1265 | | const CString& GetSavePath() const; |
1266 | | CString ExpandString(const CString& sStr) const; |
1267 | | CString& ExpandString(const CString& sStr, CString& sRet) const; |
1268 | | |
1269 | | // Setters |
1270 | 0 | void SetType(CModInfo::EModuleType eType) { m_eType = eType; } |
1271 | 0 | void SetDescription(const CString& s) { m_sDescription = s; } |
1272 | 0 | void SetModPath(const CString& s) { m_sModPath = s; } |
1273 | 0 | void SetArgs(const CString& s) { m_sArgs = s; } |
1274 | | // !Setters |
1275 | | |
1276 | | // Getters |
1277 | 0 | CModInfo::EModuleType GetType() const { return m_eType; } |
1278 | 0 | const CString& GetDescription() const { return m_sDescription; } |
1279 | 0 | const CString& GetArgs() const { return m_sArgs; } |
1280 | 0 | const CString& GetModPath() const { return m_sModPath; } |
1281 | | |
1282 | | /** @returns For user modules this returns the user for which this |
1283 | | * module was loaded. For global modules this returns nullptr, |
1284 | | * except when we are in a user-specific module hook in which |
1285 | | * case this is the user pointer. |
1286 | | */ |
1287 | 0 | CUser* GetUser() const { return m_pUser; } |
1288 | | /** @returns nullptr except when we are in a network-specific module hook in |
1289 | | * which case this is the network for which the hook is called. |
1290 | | */ |
1291 | 0 | CIRCNetwork* GetNetwork() const { return m_pNetwork; } |
1292 | | /** @returns nullptr except when we are in a client-specific module hook in |
1293 | | * which case this is the client for which the hook is called. |
1294 | | */ |
1295 | 0 | CClient* GetClient() const { return m_pClient; } |
1296 | 0 | CSockManager* GetManager() const { return m_pManager; } |
1297 | | // !Getters |
1298 | | |
1299 | | // Global Modules |
1300 | | /** This module hook is called when a user is being added. |
1301 | | * @param User The user which will be added. |
1302 | | * @param sErrorRet A message that may be displayed to the user if |
1303 | | * the module stops adding the user. |
1304 | | * @return See CModule::EModRet. |
1305 | | */ |
1306 | | virtual EModRet OnAddUser(CUser& User, CString& sErrorRet); |
1307 | | /** This module hook is called when a user is deleted. |
1308 | | * @param User The user which will be deleted. |
1309 | | * @return See CModule::EModRet. |
1310 | | */ |
1311 | | virtual EModRet OnDeleteUser(CUser& User); |
1312 | | /** This module hook is called when there is an incoming connection on |
1313 | | * any of ZNC's listening sockets. |
1314 | | * @param pSock The incoming client socket. |
1315 | | * @param sHost The IP the client is connecting from. |
1316 | | * @param uPort The port the client is connecting from. |
1317 | | */ |
1318 | | virtual void OnClientConnect(CZNCSock* pSock, const CString& sHost, |
1319 | | unsigned short uPort); |
1320 | | /** This module hook is called when a client tries to login. If your |
1321 | | * module wants to handle the login attempt, it must return |
1322 | | * CModule::EModRet::HALT; |
1323 | | * @param Auth The necessary authentication info for this login attempt. |
1324 | | * @return See CModule::EModRet. |
1325 | | */ |
1326 | | virtual EModRet OnLoginAttempt(std::shared_ptr<CAuthBase> Auth); |
1327 | | /** Called after a client login was rejected. |
1328 | | * @param sUsername The username that tried to log in. |
1329 | | * @param sRemoteIP The IP address from which the client tried to login. |
1330 | | */ |
1331 | | virtual void OnFailedLogin(const CString& sUsername, |
1332 | | const CString& sRemoteIP); |
1333 | | /** This function behaves like CModule::OnUserRaw(), but is also called |
1334 | | * before the client successfully logged in to ZNC. You should always |
1335 | | * prefer to use CModule::OnUserRaw() if possible. |
1336 | | * @param pClient The client which send this line. |
1337 | | * @param sLine The raw traffic line which the client sent. |
1338 | | */ |
1339 | | virtual EModRet OnUnknownUserRaw(CClient* pClient, CString& sLine); |
1340 | | virtual EModRet OnUnknownUserRawMessage(CMessage& Message); |
1341 | | |
1342 | | /** Called after login, and also during JumpNetwork. */ |
1343 | | virtual void OnClientAttached(); |
1344 | | /** Called upon disconnect, and also during JumpNetwork. */ |
1345 | | virtual void OnClientDetached(); |
1346 | | |
1347 | | #ifndef SWIG |
1348 | | /** Simple API to support client capabilities which depend on server to support that capability. |
1349 | | * It is built on top of other CAP related API, but removes boilerplate, |
1350 | | * and handles some tricky cases related to cap-notify and JumpNetwork. To |
1351 | | * use, create a subclass of CCapability, and pass to this function; it |
1352 | | * will automatically set the module pointer, then call the callbacks to |
1353 | | * notify you when server and client accepted support of the capability, or |
1354 | | * stopped supporting it. Note that it's not a strict toggle: e.g. |
1355 | | * sometimes client will disable the cap even when it was already disabled |
1356 | | * for that client. |
1357 | | * For perl and python modules, this function accepts 3 parameters: |
1358 | | * name, server callback, client callback; signatures of the callbacks are |
1359 | | * the same as of the virtual functions you'd implement in C++. |
1360 | | */ |
1361 | | void AddServerDependentCapability(const CString& sName, std::unique_ptr<CCapability> pCap); |
1362 | | #endif |
1363 | | |
1364 | | /** Called when a client told us CAP LS. Use ssCaps.insert("cap-name") |
1365 | | * for announcing capabilities which your module supports. |
1366 | | * If you need to adverite the cap to clients only when it's also supported |
1367 | | * by the server, use AddServerDependentCapability() instead. |
1368 | | * @param pClient The client which requested the list. |
1369 | | * @param ssCaps set of caps which will be sent to client. |
1370 | | */ |
1371 | | virtual void OnClientCapLs(CClient* pClient, SCString& ssCaps); |
1372 | | /** Called only to check if your module supports turning on/off named capability. |
1373 | | * @param pClient The client which wants to enable/disable a capability. |
1374 | | * @param sCap name of capability. |
1375 | | * @param bState On or off, depending on which case is interesting for client. |
1376 | | * @return true if your module supports this capability in the specified state. |
1377 | | */ |
1378 | | virtual bool IsClientCapSupported(CClient* pClient, const CString& sCap, |
1379 | | bool bState); |
1380 | | /** Called when we actually need to turn a capability on or off for a client. |
1381 | | * If you need to adverite the cap to clients only when it's also supported |
1382 | | * by the server, use AddServerDependentCapability() instead. |
1383 | | * If implementing a custom capability, make sure to call |
1384 | | * pClient->SetTagSupport("tag-name", bState) for each tag that the |
1385 | | * capability provides. |
1386 | | * @param pClient The client which requested the capability. |
1387 | | * @param sCap name of wanted capability. |
1388 | | * @param bState On or off, depending on which case client needs. |
1389 | | * @see CClient::SetTagSupport() |
1390 | | */ |
1391 | | virtual void OnClientCapRequest(CClient* pClient, const CString& sCap, |
1392 | | bool bState); |
1393 | | |
1394 | | /** Called when a client requests SASL authentication. Use ssMechanisms.insert("MECHANISM") |
1395 | | * for announcing SASL mechanisms which your module supports. |
1396 | | * @param ssMechanisms The set of supported SASL mechanisms to append to. |
1397 | | * @since 1.10.0 |
1398 | | */ |
1399 | | virtual void OnClientGetSASLMechanisms(SCString& ssMechanisms); |
1400 | | /** Called when a client has selected a SASL mechanism for SASL authentication. |
1401 | | * If implementing a SASL authentication mechanism, set sResponse to |
1402 | | * specify an initial challenge message to send to the client. Otherwise, an |
1403 | | * empty response will be sent. To avoid sending any immediate response, |
1404 | | * return HALT; in that case the module should schedule calling |
1405 | | * GetClient()->SendSASLChallenge() with the initial response: in IRC SASL, |
1406 | | * server always responds first. |
1407 | | * @param sMechanism The SASL mechanism selected by the client. |
1408 | | * @param sResponse The optional value of an initial SASL challenge message |
1409 | | * to send to the client. |
1410 | | * @since 1.10.0 |
1411 | | */ |
1412 | | virtual EModRet OnClientSASLServerInitialChallenge( |
1413 | | const CString& sMechanism, CString& sResponse); |
1414 | | /** Called when a client is sending us a SASL message after the mechanism was selected. |
1415 | | * If implementing a SASL authentication mechanism, check the passed |
1416 | | * credentials, then either request more data by sending a challenge in |
1417 | | * GetClient()->SendSASLChallenge(), or reject authentication by calling |
1418 | | * GetClient()->RefuseSASLLogin(), or accept it by calling |
1419 | | * GetClient()->AcceptSASLLogin(). |
1420 | | * At some point before accepting the login, you should call |
1421 | | * GetClient()->ParseUser(authz-id) to let it know the network name to |
1422 | | * attach to and the client id. |
1423 | | * @param sMechanism The SASL mechanism selected by the client. |
1424 | | * @param sMessage The SASL opaque value/credentials sent by the client, |
1425 | | * after debase64ing and concatenating if it was split. |
1426 | | * @since 1.10.0 |
1427 | | */ |
1428 | | virtual EModRet OnClientSASLAuthenticate(const CString& sMechanism, |
1429 | | const CString& sMessage); |
1430 | | /** Called when a client sent '*' to abort SASL, or aborted it for another reason. |
1431 | | * @since 1.10.0 |
1432 | | */ |
1433 | | virtual void OnClientSASLAborted(); |
1434 | | |
1435 | | /** Called when a module is going to be loaded. |
1436 | | * @param sModName name of the module. |
1437 | | * @param eType wanted type of the module (user/global). |
1438 | | * @param sArgs arguments of the module. |
1439 | | * @param[out] bSuccess the module was loaded successfully |
1440 | | * as result of this module hook? |
1441 | | * @param[out] sRetMsg text about loading of the module. |
1442 | | * @return See CModule::EModRet. |
1443 | | */ |
1444 | | virtual EModRet OnModuleLoading(const CString& sModName, |
1445 | | const CString& sArgs, |
1446 | | CModInfo::EModuleType eType, bool& bSuccess, |
1447 | | CString& sRetMsg); |
1448 | | /** Called when a module is going to be unloaded. |
1449 | | * @param pModule the module. |
1450 | | * @param[out] bSuccess the module was unloaded successfully |
1451 | | * as result of this module hook? |
1452 | | * @param[out] sRetMsg text about unloading of the module. |
1453 | | * @return See CModule::EModRet. |
1454 | | */ |
1455 | | virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, |
1456 | | CString& sRetMsg); |
1457 | | /** Called when info about a module is needed. |
1458 | | * @param[out] ModInfo put result here, if your module knows it. |
1459 | | * @param sModule name of the module. |
1460 | | * @param bSuccess this module provided info about the module. |
1461 | | * @param sRetMsg text describing possible issues. |
1462 | | * @return See CModule::EModRet. |
1463 | | */ |
1464 | | virtual EModRet OnGetModInfo(CModInfo& ModInfo, const CString& sModule, |
1465 | | bool& bSuccess, CString& sRetMsg); |
1466 | | /** Called when list of available mods is requested. |
1467 | | * @param ssMods put new modules here. |
1468 | | * @param bGlobal true if global modules are needed. |
1469 | | */ |
1470 | | virtual void OnGetAvailableMods(std::set<CModInfo>& ssMods, |
1471 | | CModInfo::EModuleType eType); |
1472 | | // !Global Modules |
1473 | | |
1474 | | #ifndef SWIG |
1475 | | // Translation |
1476 | | CString t_s(const CString& sEnglish, const CString& sContext = "") const; |
1477 | | CInlineFormatMessage t_f(const CString& sEnglish, |
1478 | | const CString& sContext = "") const; |
1479 | | CInlineFormatMessage t_p(const CString& sEnglish, const CString& sEnglishes, |
1480 | | int iNum, const CString& sContext = "") const; |
1481 | | CDelayedTranslation t_d(const CString& sEnglish, |
1482 | | const CString& sContext = "") const; |
1483 | | #endif |
1484 | | |
1485 | | // Default implementations of several callbacks to make |
1486 | | // AddServerDependentCapability work in modpython/modperl. |
1487 | | // Don't worry about existence of these functions. |
1488 | | bool InternalServerDependentCapsOnServerCap302Available( |
1489 | | const CString& sCap, const CString& sValue); |
1490 | | void InternalServerDependentCapsOnServerCapResult(const CString& sCap, |
1491 | | bool bSuccess); |
1492 | | void InternalServerDependentCapsOnClientCapLs(CClient* pClient, |
1493 | | SCString& ssCaps); |
1494 | | bool InternalServerDependentCapsIsClientCapSupported(CClient* pClient, |
1495 | | const CString& sCap, |
1496 | | bool bState); |
1497 | | void InternalServerDependentCapsOnClientCapRequest(CClient* pClient, |
1498 | | const CString& sCap, |
1499 | | bool bState); |
1500 | | void InternalServerDependentCapsOnClientAttached(); |
1501 | | void InternalServerDependentCapsOnClientDetached(); |
1502 | | void InternalServerDependentCapsOnIRCConnected(); |
1503 | | void InternalServerDependentCapsOnIRCDisconnected(); |
1504 | | |
1505 | | protected: |
1506 | | CModInfo::EModuleType m_eType; |
1507 | | CString m_sDescription; |
1508 | | std::set<CTimer*> m_sTimers; |
1509 | | std::set<CSocket*> m_sSockets; |
1510 | | #ifdef HAVE_PTHREAD |
1511 | | std::set<CModuleJob*> m_sJobs; |
1512 | | #endif |
1513 | | ModHandle m_pDLL; |
1514 | | CSockManager* m_pManager; |
1515 | | CUser* m_pUser; |
1516 | | CIRCNetwork* m_pNetwork; |
1517 | | CClient* m_pClient; |
1518 | | CString m_sModName; |
1519 | | CString m_sDataDir; |
1520 | | CString m_sSavePath; |
1521 | | CString m_sArgs; |
1522 | | CString m_sModPath; |
1523 | | CTranslationDomainRefHolder m_Translation; |
1524 | | std::map<CString, std::unique_ptr<CCapability>> m_mServerDependentCaps; |
1525 | | |
1526 | | private: |
1527 | | MCString |
1528 | | m_mssRegistry; //!< way to save name/value pairs. Note there is no encryption involved in this |
1529 | | VWebSubPages m_vSubPages; |
1530 | | std::map<CString, CModCommand> m_mCommands; |
1531 | | }; |
1532 | | |
1533 | | class CModules : public std::vector<CModule*>, private CCoreTranslationMixin { |
1534 | | public: |
1535 | | CModules(); |
1536 | | ~CModules(); |
1537 | | |
1538 | | CModules(const CModules&) = default; |
1539 | | CModules& operator=(const CModules&) = default; |
1540 | | |
1541 | 0 | void SetUser(CUser* pUser) { m_pUser = pUser; } |
1542 | 0 | void SetNetwork(CIRCNetwork* pNetwork) { m_pNetwork = pNetwork; } |
1543 | 0 | void SetClient(CClient* pClient) { m_pClient = pClient; } |
1544 | 0 | CUser* GetUser() const { return m_pUser; } |
1545 | 0 | CIRCNetwork* GetNetwork() const { return m_pNetwork; } |
1546 | 0 | CClient* GetClient() const { return m_pClient; } |
1547 | | |
1548 | | void UnloadAll(); |
1549 | | |
1550 | | bool OnBoot(); |
1551 | | bool OnPreRehash(); |
1552 | | bool OnPostRehash(); |
1553 | | bool OnIRCDisconnected(); |
1554 | | bool OnIRCConnected(); |
1555 | | bool OnIRCConnecting(CIRCSock* pIRCSock); |
1556 | | bool OnIRCConnectionError(CIRCSock* pIRCSock); |
1557 | | bool OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, |
1558 | | CString& sRealName); |
1559 | | bool OnBroadcast(CString& sMessage); |
1560 | | |
1561 | | bool OnChanPermission3(const CNick* pOpNick, const CNick& Nick, |
1562 | | CChan& Channel, char cMode, bool bAdded, |
1563 | | bool bNoChange); |
1564 | | bool OnChanPermission2(const CNick* pOpNick, const CNick& Nick, |
1565 | | CChan& Channel, unsigned char uMode, bool bAdded, |
1566 | | bool bNoChange); |
1567 | | bool OnChanPermission(const CNick& OpNick, const CNick& Nick, |
1568 | | CChan& Channel, unsigned char uMode, bool bAdded, |
1569 | | bool bNoChange); |
1570 | | bool OnOp2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, |
1571 | | bool bNoChange); |
1572 | | bool OnOp(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
1573 | | bool bNoChange); |
1574 | | bool OnDeop2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, |
1575 | | bool bNoChange); |
1576 | | bool OnDeop(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
1577 | | bool bNoChange); |
1578 | | bool OnVoice2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, |
1579 | | bool bNoChange); |
1580 | | bool OnVoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
1581 | | bool bNoChange); |
1582 | | bool OnDevoice2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, |
1583 | | bool bNoChange); |
1584 | | bool OnDevoice(const CNick& OpNick, const CNick& Nick, CChan& Channel, |
1585 | | bool bNoChange); |
1586 | | bool OnRawMode2(const CNick* pOpNick, CChan& Channel, const CString& sModes, |
1587 | | const CString& sArgs); |
1588 | | bool OnRawMode(const CNick& OpNick, CChan& Channel, const CString& sModes, |
1589 | | const CString& sArgs); |
1590 | | bool OnMode2(const CNick* pOpNick, CChan& Channel, char uMode, |
1591 | | const CString& sArg, bool bAdded, bool bNoChange); |
1592 | | bool OnMode(const CNick& OpNick, CChan& Channel, char uMode, |
1593 | | const CString& sArg, bool bAdded, bool bNoChange); |
1594 | | |
1595 | | bool OnRaw(CString& sLine); |
1596 | | bool OnRawMessage(CMessage& Message); |
1597 | | bool OnNumericMessage(CNumericMessage& Message); |
1598 | | |
1599 | | bool OnStatusCommand(CString& sCommand); |
1600 | | bool OnModCommand(const CString& sCommand); |
1601 | | bool OnModNotice(const CString& sMessage); |
1602 | | bool OnModCTCP(const CString& sMessage); |
1603 | | |
1604 | | bool OnQuit(const CNick& Nick, const CString& sMessage, |
1605 | | const std::vector<CChan*>& vChans); |
1606 | | bool OnQuitMessage(CQuitMessage& Message, |
1607 | | const std::vector<CChan*>& vChans); |
1608 | | bool OnNick(const CNick& Nick, const CString& sNewNick, |
1609 | | const std::vector<CChan*>& vChans); |
1610 | | bool OnNickMessage(CNickMessage& Message, |
1611 | | const std::vector<CChan*>& vChans); |
1612 | | bool OnKick(const CNick& Nick, const CString& sOpNick, CChan& Channel, |
1613 | | const CString& sMessage); |
1614 | | bool OnKickMessage(CKickMessage& Message); |
1615 | | bool OnJoining(CChan& Channel); |
1616 | | bool OnJoin(const CNick& Nick, CChan& Channel); |
1617 | | bool OnJoinMessage(CJoinMessage& Message); |
1618 | | bool OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage); |
1619 | | bool OnPartMessage(CPartMessage& Message); |
1620 | | bool OnInvite(const CNick& Nick, const CString& sChan); |
1621 | | bool OnInviteMessage(CInviteMessage& Message); |
1622 | | |
1623 | | bool OnChanBufferStarting(CChan& Chan, CClient& Client); |
1624 | | bool OnChanBufferEnding(CChan& Chan, CClient& Client); |
1625 | | bool OnChanBufferPlayLine2(CChan& Chan, CClient& Client, CString& sLine, |
1626 | | const timeval& tv); |
1627 | | bool OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine); |
1628 | | bool OnPrivBufferStarting(CQuery& Query, CClient& Client); |
1629 | | bool OnPrivBufferEnding(CQuery& Query, CClient& Client); |
1630 | | bool OnPrivBufferPlayLine2(CClient& Client, CString& sLine, |
1631 | | const timeval& tv); |
1632 | | bool OnPrivBufferPlayLine(CClient& Client, CString& sLine); |
1633 | | bool OnChanBufferPlayMessage(CMessage& Message); |
1634 | | bool OnPrivBufferPlayMessage(CMessage& Message); |
1635 | | |
1636 | | bool OnClientLogin(); |
1637 | | bool OnClientDisconnect(); |
1638 | | bool OnUserRaw(CString& sLine); |
1639 | | bool OnUserRawMessage(CMessage& Message); |
1640 | | bool OnUserCTCPReply(CString& sTarget, CString& sMessage); |
1641 | | bool OnUserCTCPReplyMessage(CCTCPMessage& Message); |
1642 | | bool OnUserCTCP(CString& sTarget, CString& sMessage); |
1643 | | bool OnUserCTCPMessage(CCTCPMessage& Message); |
1644 | | bool OnUserAction(CString& sTarget, CString& sMessage); |
1645 | | bool OnUserActionMessage(CActionMessage& Message); |
1646 | | bool OnUserMsg(CString& sTarget, CString& sMessage); |
1647 | | bool OnUserTextMessage(CTextMessage& Message); |
1648 | | bool OnUserNotice(CString& sTarget, CString& sMessage); |
1649 | | bool OnUserNoticeMessage(CNoticeMessage& Message); |
1650 | | bool OnUserJoin(CString& sChannel, CString& sKey); |
1651 | | bool OnUserJoinMessage(CJoinMessage& Message); |
1652 | | bool OnUserPart(CString& sChannel, CString& sMessage); |
1653 | | bool OnUserPartMessage(CPartMessage& Message); |
1654 | | bool OnUserTopic(CString& sChannel, CString& sTopic); |
1655 | | bool OnUserTopicMessage(CTopicMessage& Message); |
1656 | | bool OnUserTopicRequest(CString& sChannel); |
1657 | | bool OnUserQuit(CString& sMessage); |
1658 | | bool OnUserQuitMessage(CQuitMessage& Message); |
1659 | | bool OnUserTagMessage(CTargetMessage& Message); |
1660 | | bool OnChanTagMessage(CTargetMessage& Message); |
1661 | | bool OnPrivTagMessage(CTargetMessage& Message); |
1662 | | |
1663 | | bool OnCTCPReply(CNick& Nick, CString& sMessage); |
1664 | | bool OnCTCPReplyMessage(CCTCPMessage& Message); |
1665 | | bool OnPrivCTCP(CNick& Nick, CString& sMessage); |
1666 | | bool OnPrivCTCPMessage(CCTCPMessage& Message); |
1667 | | bool OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage); |
1668 | | bool OnChanCTCPMessage(CCTCPMessage& Message); |
1669 | | bool OnPrivAction(CNick& Nick, CString& sMessage); |
1670 | | bool OnPrivActionMessage(CActionMessage& Message); |
1671 | | bool OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage); |
1672 | | bool OnChanActionMessage(CActionMessage& Message); |
1673 | | bool OnPrivMsg(CNick& Nick, CString& sMessage); |
1674 | | bool OnPrivTextMessage(CTextMessage& Message); |
1675 | | bool OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage); |
1676 | | bool OnChanTextMessage(CTextMessage& Message); |
1677 | | bool OnPrivNotice(CNick& Nick, CString& sMessage); |
1678 | | bool OnPrivNoticeMessage(CNoticeMessage& Message); |
1679 | | bool OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage); |
1680 | | bool OnChanNoticeMessage(CNoticeMessage& Message); |
1681 | | bool OnTopic(CNick& Nick, CChan& Channel, CString& sTopic); |
1682 | | bool OnTopicMessage(CTopicMessage& Message); |
1683 | | bool OnTimerAutoJoin(CChan& Channel); |
1684 | | |
1685 | | bool OnAddNetwork(CIRCNetwork& Network, CString& sErrorRet); |
1686 | | bool OnDeleteNetwork(CIRCNetwork& Network); |
1687 | | |
1688 | | bool OnSendToClient(CString& sLine, CClient& Client); |
1689 | | bool OnSendToClientMessage(CMessage& Message); |
1690 | | bool OnSendToIRC(CString& sLine); |
1691 | | bool OnSendToIRCMessage(CMessage& Message); |
1692 | | bool OnClientAttached(); |
1693 | | bool OnClientDetached(); |
1694 | | |
1695 | | bool OnServerCapAvailable(const CString& sCap, const CString& sValue); |
1696 | | bool OnServerCapResult(const CString& sCap, bool bSuccess); |
1697 | | |
1698 | | CModule* FindModule(const CString& sModule) const; |
1699 | | bool LoadModule(const CString& sModule, const CString& sArgs, |
1700 | | CModInfo::EModuleType eType, CUser* pUser, |
1701 | | CIRCNetwork* pNetwork, CString& sRetMsg); |
1702 | | bool UnloadModule(const CString& sModule); |
1703 | | bool UnloadModule(const CString& sModule, CString& sRetMsg); |
1704 | | bool ReloadModule(const CString& sModule, const CString& sArgs, |
1705 | | CUser* pUser, CIRCNetwork* pNetwork, CString& sRetMsg); |
1706 | | |
1707 | | static bool GetModInfo(CModInfo& ModInfo, const CString& sModule, |
1708 | | CString& sRetMsg); |
1709 | | static bool GetModPathInfo(CModInfo& ModInfo, const CString& sModule, |
1710 | | const CString& sModPath, CString& sRetMsg); |
1711 | | static void GetAvailableMods( |
1712 | | std::set<CModInfo>& ssMods, |
1713 | | CModInfo::EModuleType eType = CModInfo::UserModule); |
1714 | | static void GetDefaultMods( |
1715 | | std::set<CModInfo>& ssMods, |
1716 | | CModInfo::EModuleType eType = CModInfo::UserModule); |
1717 | | |
1718 | | // This returns the path to the .so and to the data dir |
1719 | | // which is where static data (webadmin skins) are saved |
1720 | | static bool FindModPath(const CString& sModule, CString& sModPath, |
1721 | | CString& sDataPath); |
1722 | | // Return a list of <module dir, data dir> pairs for directories in |
1723 | | // which modules can be found. |
1724 | | typedef std::queue<std::pair<CString, CString>> ModDirList; |
1725 | | static ModDirList GetModDirs(); |
1726 | | |
1727 | | // Global Modules |
1728 | | bool OnAddUser(CUser& User, CString& sErrorRet); |
1729 | | bool OnDeleteUser(CUser& User); |
1730 | | bool OnClientConnect(CZNCSock* pSock, const CString& sHost, |
1731 | | unsigned short uPort); |
1732 | | bool OnLoginAttempt(std::shared_ptr<CAuthBase> Auth); |
1733 | | bool OnFailedLogin(const CString& sUsername, const CString& sRemoteIP); |
1734 | | bool OnUnknownUserRaw(CClient* pClient, CString& sLine); |
1735 | | bool OnUnknownUserRawMessage(CMessage& Message); |
1736 | | bool OnClientCapLs(CClient* pClient, SCString& ssCaps); |
1737 | | bool IsClientCapSupported(CClient* pClient, const CString& sCap, |
1738 | | bool bState); |
1739 | | bool OnClientCapRequest(CClient* pClient, const CString& sCap, bool bState); |
1740 | | |
1741 | | bool OnClientGetSASLMechanisms(SCString& ssMechanisms); |
1742 | | bool OnClientSASLAborted(); |
1743 | | bool OnClientSASLServerInitialChallenge(const CString& sMechanism, |
1744 | | CString& sResponse); |
1745 | | bool OnClientSASLAuthenticate(const CString& sMechanism, |
1746 | | const CString& sBuffer); |
1747 | | |
1748 | | bool OnModuleLoading(const CString& sModName, const CString& sArgs, |
1749 | | CModInfo::EModuleType eType, bool& bSuccess, |
1750 | | CString& sRetMsg); |
1751 | | bool OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg); |
1752 | | bool OnGetModInfo(CModInfo& ModInfo, const CString& sModule, bool& bSuccess, |
1753 | | CString& sRetMsg); |
1754 | | bool OnGetAvailableMods(std::set<CModInfo>& ssMods, |
1755 | | CModInfo::EModuleType eType); |
1756 | | // !Global Modules |
1757 | | |
1758 | | private: |
1759 | | static ModHandle OpenModule(const CString& sModule, const CString& sModPath, |
1760 | | CModInfo& Info, CString& sRetMsg); |
1761 | | static bool ValidateModuleName(const CString& sModule, CString& sRetMsg); |
1762 | | |
1763 | | protected: |
1764 | | CUser* m_pUser; |
1765 | | CIRCNetwork* m_pNetwork; |
1766 | | CClient* m_pClient; |
1767 | | }; |
1768 | | |
1769 | | #endif // !ZNC_MODULES_H |