ZNC  trunk
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
modperl/module.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004-2014 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 #pragma once
18 
19 #include <EXTERN.h>
20 #include <perl.h>
21 #include <XSUB.h>
22 
23 #include <znc/Modules.h>
24 
25 #if HAVE_VISIBILITY
26 #pragma GCC visibility push(default)
27 #endif
28 class CPerlModule : public CModule {
29  SV* m_perlObj;
30  VWebSubPages* _GetSubPages();
31 public:
32  CPerlModule(CUser* pUser, CIRCNetwork* pNetwork, const CString& sModName, const CString& sDataPath,
33  SV* perlObj)
34  : CModule(NULL, pUser, pNetwork, sModName, sDataPath) {
35  m_perlObj = newSVsv(perlObj);
36  }
37  SV* GetPerlObj() {
38  return sv_2mortal(newSVsv(m_perlObj));
39  }
40 
41  virtual bool OnBoot();
42  virtual bool WebRequiresLogin();
43  virtual bool WebRequiresAdmin();
44  virtual CString GetWebMenuTitle();
45  virtual bool OnWebPreRequest(CWebSock& WebSock, const CString& sPageName);
46  virtual bool OnWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl);
47  virtual VWebSubPages& GetSubPages();
48  virtual void OnPreRehash();
49  virtual void OnPostRehash();
50  virtual void OnIRCDisconnected();
51  virtual void OnIRCConnected();
52  virtual EModRet OnIRCConnecting(CIRCSock *pIRCSock);
53  virtual void OnIRCConnectionError(CIRCSock *pIRCSock);
54  virtual EModRet OnIRCRegistration(CString& sPass, CString& sNick, CString& sIdent, CString& sRealName);
55  virtual EModRet OnBroadcast(CString& sMessage);
56  virtual void OnChanPermission2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, unsigned char uMode, bool bAdded, bool bNoChange);
57  virtual void OnOp2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
58  virtual void OnDeop2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
59  virtual void OnVoice2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
60  virtual void OnDevoice2(const CNick* pOpNick, const CNick& Nick, CChan& Channel, bool bNoChange);
61  virtual void OnMode2(const CNick* pOpNick, CChan& Channel, char uMode, const CString& sArg, bool bAdded, bool bNoChange);
62  virtual void OnRawMode2(const CNick* pOpNick, CChan& Channel, const CString& sModes, const CString& sArgs);
63  virtual EModRet OnRaw(CString& sLine);
64  virtual EModRet OnStatusCommand(CString& sCommand);
65  virtual void OnModCommand(const CString& sCommand);
66  virtual void OnModNotice(const CString& sMessage);
67  virtual void OnModCTCP(const CString& sMessage);
68  virtual void OnQuit(const CNick& Nick, const CString& sMessage, const std::vector<CChan*>& vChans);
69  virtual void OnNick(const CNick& Nick, const CString& sNewNick, const std::vector<CChan*>& vChans);
70  virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& Channel, const CString& sMessage);
71  virtual void OnJoin(const CNick& Nick, CChan& Channel);
72  virtual void OnPart(const CNick& Nick, CChan& Channel, const CString& sMessage);
73  virtual EModRet OnChanBufferStarting(CChan& Chan, CClient& Client);
74  virtual EModRet OnChanBufferEnding(CChan& Chan, CClient& Client);
75  virtual EModRet OnChanBufferPlayLine(CChan& Chan, CClient& Client, CString& sLine);
76  virtual EModRet OnPrivBufferPlayLine(CClient& Client, CString& sLine);
77  virtual void OnClientLogin();
78  virtual void OnClientDisconnect();
79  virtual EModRet OnUserRaw(CString& sLine);
80  virtual EModRet OnUserCTCPReply(CString& sTarget, CString& sMessage);
81  virtual EModRet OnUserCTCP(CString& sTarget, CString& sMessage);
82  virtual EModRet OnUserAction(CString& sTarget, CString& sMessage);
83  virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage);
84  virtual EModRet OnUserNotice(CString& sTarget, CString& sMessage);
85  virtual EModRet OnUserJoin(CString& sChannel, CString& sKey);
86  virtual EModRet OnUserPart(CString& sChannel, CString& sMessage);
87  virtual EModRet OnUserTopic(CString& sChannel, CString& sTopic);
88  virtual EModRet OnUserTopicRequest(CString& sChannel);
89  virtual EModRet OnCTCPReply(CNick& Nick, CString& sMessage);
90  virtual EModRet OnPrivCTCP(CNick& Nick, CString& sMessage);
91  virtual EModRet OnChanCTCP(CNick& Nick, CChan& Channel, CString& sMessage);
92  virtual EModRet OnPrivAction(CNick& Nick, CString& sMessage);
93  virtual EModRet OnChanAction(CNick& Nick, CChan& Channel, CString& sMessage);
94  virtual EModRet OnPrivMsg(CNick& Nick, CString& sMessage);
95  virtual EModRet OnChanMsg(CNick& Nick, CChan& Channel, CString& sMessage);
96  virtual EModRet OnPrivNotice(CNick& Nick, CString& sMessage);
97  virtual EModRet OnChanNotice(CNick& Nick, CChan& Channel, CString& sMessage);
98  virtual EModRet OnTopic(CNick& Nick, CChan& Channel, CString& sTopic);
99  virtual bool OnServerCapAvailable(const CString& sCap);
100  virtual void OnServerCapResult(const CString& sCap, bool bSuccess);
101  virtual EModRet OnTimerAutoJoin(CChan& Channel);
102  virtual bool OnEmbeddedWebRequest(CWebSock&, const CString&, CTemplate&);
103  virtual EModRet OnAddNetwork(CIRCNetwork& Network, CString& sErrorRet);
104  virtual EModRet OnDeleteNetwork(CIRCNetwork& Network);
105  virtual EModRet OnSendToClient(CString& sLine, CClient& Client);
106  virtual EModRet OnSendToIRC(CString& sLine);
107 };
108 
109 static inline CPerlModule* AsPerlModule(CModule* p) {
110  return dynamic_cast<CPerlModule*>(p);
111 }
112 
117 };
118 
119 class CPerlTimer : public CTimer {
120  SV* m_perlObj;
121 public:
122  CPerlTimer(CPerlModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription, SV* perlObj)
123  : CTimer (pModule, uInterval, uCycles, sLabel, sDescription), m_perlObj(newSVsv(perlObj)) {
124  pModule->AddTimer(this);
125  }
126  virtual void RunJob();
127  SV* GetPerlObj() {
128  return sv_2mortal(newSVsv(m_perlObj));
129  }
130  ~CPerlTimer();
131 };
132 
133 inline CPerlTimer* CreatePerlTimer(CPerlModule* pModule, unsigned int uInterval, unsigned int uCycles,
134  const CString& sLabel, const CString& sDescription, SV* perlObj) {
135  return new CPerlTimer(pModule, uInterval, uCycles, sLabel, sDescription, perlObj);
136 }
137 
138 class CPerlSocket : public CSocket {
139  SV* m_perlObj;
140 public:
141  CPerlSocket(CPerlModule* pModule, SV* perlObj) : CSocket(pModule), m_perlObj(newSVsv(perlObj)) {}
142  SV* GetPerlObj() {
143  return sv_2mortal(newSVsv(m_perlObj));
144  }
145  ~CPerlSocket();
146  virtual void Connected();
147  virtual void Disconnected();
148  virtual void Timeout();
149  virtual void ConnectionRefused();
150  virtual void ReadData(const char *data, size_t len);
151  virtual void ReadLine(const CString& sLine);
152  virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort);
153 };
154 
155 inline CPerlSocket* CreatePerlSocket(CPerlModule* pModule, SV* perlObj) {
156  return new CPerlSocket(pModule, perlObj);
157 }
158 
159 inline bool HaveIPv6() {
160 #ifdef HAVE_IPV6
161  return true;
162 #endif
163  return false;
164 }
165 
166 inline bool HaveSSL() {
167 #ifdef HAVE_LIBSSL
168  return true;
169 #endif
170  return false;
171 }
172 
173 inline bool HaveCharset() {
174 #ifdef HAVE_ICU
175  return true;
176 #endif
177  return false;
178 }
179 
180 inline int _GetSOMAXCONN() {
181  return SOMAXCONN;
182 }
183 
184 inline int GetVersionMajor() {
185  return VERSION_MAJOR;
186 }
187 
188 inline int GetVersionMinor() {
189  return VERSION_MINOR;
190 }
191 
192 inline double GetVersion() {
193  return VERSION;
194 }
195 
197  return ZNC_VERSION_EXTRA;
198 }
199 #if HAVE_VISIBILITY
200 #pragma GCC visibility pop
201 #endif
virtual void OnRawMode2(const CNick *pOpNick, CChan &Channel, const CString &sModes, const CString &sArgs)
Called on any channel mode change.
const char * ZNC_VERSION_EXTRA
Definition: User.h:37
virtual bool OnEmbeddedWebRequest(CWebSock &, const CString &, CTemplate &)
Using this hook, module can embed web stuff directly to different places.
SV * GetPerlObj()
Definition: modperl/module.h:37
CPerlTimer(CPerlModule *pModule, unsigned int uInterval, unsigned int uCycles, const CString &sLabel, const CString &sDescription, SV *perlObj)
Definition: modperl/module.h:122
virtual void OnPostRehash()
This module hook is called after a successful rehash.
#define VERSION
Definition: version.h:8
virtual void OnMode2(const CNick *pOpNick, CChan &Channel, char uMode, const CString &sArg, bool bAdded, bool bNoChange)
Called on an individual channel mode change.
virtual void OnModCommand(const CString &sCommand)
Called when a command to your module is sent, e.g.
virtual void OnChanPermission2(const CNick *pOpNick, const CNick &Nick, CChan &Channel, unsigned char uMode, bool bAdded, bool bNoChange)
This module hook is called when a user mode on a channel changes.
virtual EModRet OnUserTopic(CString &sChannel, CString &sTopic)
This module hook is called when a user wants to change a channel topic.
virtual EModRet OnUserJoin(CString &sChannel, CString &sKey)
This hooks is called when a user sends a JOIN message.
virtual void OnJoin(const CNick &Nick, CChan &Channel)
Called when a nick joins a channel.
bool HaveSSL()
Definition: modperl/module.h:166
virtual EModRet OnUserRaw(CString &sLine)
This module hook is called when a client sends a raw traffic line to ZNC.
double GetVersion()
Definition: modperl/module.h:192
virtual void RunJob()
this is the method you should override
virtual void OnIRCConnected()
This module hook is called after a successful login to IRC.
virtual bool OnWebPreRequest(CWebSock &WebSock, const CString &sPageName)
For WebMods: Called before the list of registered SubPages will be checked.
virtual EModRet OnUserMsg(CString &sTarget, CString &sMessage)
This module hook is called when a user sends a normal IRC message.
Definition: Client.h:84
virtual EModRet OnUserAction(CString &sTarget, CString &sMessage)
Called when a client sends a CTCP ACTION request (&quot;/me&quot;).
Definition: modperl/module.h:28
virtual void OnKick(const CNick &OpNick, const CString &sKickedNick, CChan &Channel, const CString &sMessage)
Called when a nick is kicked from a channel.
virtual CString GetWebMenuTitle()
Return the title of the module&#39;s section in the web interface&#39;s side bar.
bool HaveIPv6()
Definition: modperl/module.h:159
virtual void ReadData(const char *data, size_t len)
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
CPerlSocket * CreatePerlSocket(CPerlModule *pModule, SV *perlObj)
Definition: modperl/module.h:155
virtual EModRet OnUserCTCP(CString &sTarget, CString &sMessage)
This module hook is called when a client sends a CTCP request.
virtual EModRet OnTopic(CNick &Nick, CChan &Channel, CString &sTopic)
Called when we receive a channel topic change from IRC.
Definition: Nick.h:29
virtual VWebSubPages & GetSubPages()
Returns a list of all registered SubPages.
virtual bool WebRequiresAdmin()
Return true if this module should only be usable for admins on the web.
virtual bool OnBoot()
This module hook is called during ZNC startup.
std::vector< TWebSubPage > VWebSubPages
Definition: WebModules.h:31
virtual bool WebRequiresLogin()
Modules which can only be used with an active user session have to return true here.
Definition: modperl/module.h:119
virtual void OnOp2(const CNick *pOpNick, const CNick &Nick, CChan &Channel, bool bNoChange)
Called when a nick is opped on a channel.
CPerlSocket(CPerlModule *pModule, SV *perlObj)
Definition: modperl/module.h:141
Base Csock implementation to be used by modules.
Definition: Socket.h:164
Definition: modperl/module.h:114
virtual EModRet OnChanCTCP(CNick &Nick, CChan &Channel, CString &sMessage)
Called when we receive a channel CTCP request from IRC.
virtual EModRet OnUserPart(CString &sChannel, CString &sMessage)
This hooks is called when a user sends a PART message.
virtual void OnClientDisconnect()
Called when a client disconnected from ZNC.
Definition: modperl/module.h:116
Definition: Modules.h:135
virtual void OnModCTCP(const CString &sMessage)
Called when your module nick was sent a CTCP message.
CPerlModule(CUser *pUser, CIRCNetwork *pNetwork, const CString &sModName, const CString &sDataPath, SV *perlObj)
Definition: modperl/module.h:32
virtual void OnPreRehash()
Called just before znc.conf is rehashed.
CString GetVersionExtra()
Definition: modperl/module.h:196
virtual void OnModNotice(const CString &sMessage)
Called when a your module nick was sent a notice.
virtual EModRet OnSendToIRC(CString &sLine)
Called when ZNC sends a raw traffic line to the IRC server.
bool AddTimer(CTimer *pTimer)
virtual EModRet OnUserNotice(CString &sTarget, CString &sMessage)
This module hook is called when a user sends a notice message.
virtual EModRet OnUserTopicRequest(CString &sChannel)
This hook is called when a user requests a channel&#39;s topic.
virtual bool OnServerCapAvailable(const CString &sCap)
Called for every CAP received via CAP LS from server.
virtual void OnClientLogin()
Called when a client successfully logged in to ZNC.
virtual EModRet OnPrivCTCP(CNick &Nick, CString &sMessage)
Called when we receive a private CTCP request from IRC.
Basic socket class.
Definition: Csocket.h:537
Definition: Template.h:117
virtual void OnQuit(const CNick &Nick, const CString &sMessage, const std::vector< CChan * > &vChans)
Called when a nick quit from IRC.
Definition: IRCNetwork.h:36
virtual EModRet OnCTCPReply(CNick &Nick, CString &sMessage)
Called when we receive a CTCP reply from IRC.
String class that is used inside ZNC.
Definition: ZNCString.h:67
virtual EModRet OnSendToClient(CString &sLine, CClient &Client)
Called when ZNC sends a raw traffic line to a client.
virtual EModRet OnStatusCommand(CString &sCommand)
Called when a command to *status is sent.
virtual void ReadLine(const CString &sLine)
EModRet
This enum is just used for return from module hooks.
Definition: Modules.h:332
virtual EModRet OnChanBufferStarting(CChan &Chan, CClient &Client)
Called before a channel buffer is played back to a client.
The base class for your own ZNC modules.
Definition: Modules.h:322
#define VERSION_MINOR
Definition: version.h:6
virtual EModRet OnBroadcast(CString &sMessage)
This module hook is called when a message is broadcasted to all users.
virtual EModRet OnPrivBufferPlayLine(CClient &Client, CString &sLine)
Called when a line from the query buffer is played back.
virtual EModRet OnDeleteNetwork(CIRCNetwork &Network)
This module hook is called when a network is deleted.
Definition: WebModules.h:111
virtual EModRet OnPrivMsg(CNick &Nick, CString &sMessage)
Called when we receive a private message from IRC.
virtual void OnNick(const CNick &Nick, const CString &sNewNick, const std::vector< CChan * > &vChans)
Called when a nickname change occurs.
virtual EModRet OnIRCConnecting(CIRCSock *pIRCSock)
This module hook is called just before ZNC tries to establish a connection to an IRC server...
virtual EModRet OnUserCTCPReply(CString &sTarget, CString &sMessage)
This module hook is called when a client sends a CTCP reply.
int _GetSOMAXCONN()
Definition: modperl/module.h:180
virtual void Connected()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
virtual void OnIRCDisconnected()
This module hook is called when a user gets disconnected from IRC.
virtual EModRet OnPrivNotice(CNick &Nick, CString &sMessage)
Called when we receive a private notice.
SV * GetPerlObj()
Definition: modperl/module.h:127
virtual void OnIRCConnectionError(CIRCSock *pIRCSock)
This module hook is called when a CIRCSock fails to connect or a module returned HALTCORE from OnIRCC...
Definition: modperl/module.h:115
bool HaveCharset()
Definition: modperl/module.h:173
CPerlTimer * CreatePerlTimer(CPerlModule *pModule, unsigned int uInterval, unsigned int uCycles, const CString &sLabel, const CString &sDescription, SV *perlObj)
Definition: modperl/module.h:133
ELoadPerlMod
Definition: modperl/module.h:113
virtual void OnVoice2(const CNick *pOpNick, const CNick &Nick, CChan &Channel, bool bNoChange)
Called when a nick is voiced on a channel.
virtual void OnServerCapResult(const CString &sCap, bool bSuccess)
Called for every CAP accepted or rejected by server (with CAP ACK or CAP NAK after our CAP REQ)...
virtual EModRet OnChanNotice(CNick &Nick, CChan &Channel, CString &sMessage)
Called when we receive a channel notice.
virtual Csock * GetSockObj(const CString &sHost, unsigned short uPort)
int GetVersionMinor()
Definition: modperl/module.h:188
virtual void Disconnected()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
virtual EModRet OnChanBufferPlayLine(CChan &Chan, CClient &Client, CString &sLine)
Called when for each line during a channel&#39;s buffer play back.
int GetVersionMajor()
Definition: modperl/module.h:184
virtual EModRet OnRaw(CString &sLine)
Called on any raw IRC line received from the IRC server.
virtual EModRet OnChanMsg(CNick &Nick, CChan &Channel, CString &sMessage)
Called when we receive a channel message from IRC.
virtual EModRet OnChanAction(CNick &Nick, CChan &Channel, CString &sMessage)
Called when we receive a channel CTCP ACTION (&quot;/me&quot; in a channel) from IRC.
virtual EModRet OnIRCRegistration(CString &sPass, CString &sNick, CString &sIdent, CString &sRealName)
This module hook is called before loging in to the IRC server.
virtual void ConnectionRefused()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
virtual EModRet OnTimerAutoJoin(CChan &Channel)
This module hook is called just before ZNC tries to join a channel by itself because it&#39;s in the conf...
virtual EModRet OnPrivAction(CNick &Nick, CString &sMessage)
Called when we receive a private CTCP ACTION (&quot;/me&quot; in query) from IRC.
virtual bool OnWebRequest(CWebSock &WebSock, const CString &sPageName, CTemplate &Tmpl)
If OnWebPreRequest returned false, and the RequiresAdmin/IsAdmin check has been passed, this method will be called with the page name.
Definition: IRCSock.h:33
virtual void OnDevoice2(const CNick *pOpNick, const CNick &Nick, CChan &Channel, bool bNoChange)
Called when a nick is devoiced on a channel.
Definition: Chan.h:34
Definition: modperl/module.h:138
SV * GetPerlObj()
Definition: modperl/module.h:142
virtual void Timeout()
Override these functions for an easy interface when using the Socket Manager Don&#39;t bother using these...
virtual EModRet OnAddNetwork(CIRCNetwork &Network, CString &sErrorRet)
This module hook is called when a network is being added.
virtual void OnPart(const CNick &Nick, CChan &Channel, const CString &sMessage)
Called when a nick parts a channel.
virtual void OnDeop2(const CNick *pOpNick, const CNick &Nick, CChan &Channel, bool bNoChange)
Called when a nick is deopped on a channel.
#define VERSION_MAJOR
Definition: version.h:5
virtual EModRet OnChanBufferEnding(CChan &Chan, CClient &Client)
Called after a channel buffer was played back to a client.